How to delete header condtion line of sales order by BAPI

Hi,
I want to delete the condtion line of sales order header using BAPI "BAPI_SALESORDER_CHANGE",
it is work well in item level condition type, but it is not work for header condition type. show error message "missing item number" since of pass item number "000000" for header condition line.
Below is reference source code, thanks in advance.
*& Report  ZTEST_BAPI_SO_DELETECONDLINE
*& Sample program to call BAPI_SALESODRER_CHANGE to
*& delete condition line of so line item
REPORT  ZTEST_BAPI_SO_DELETECONDLINE.
***--- Structures for create BAPI
DATA: SALESDOCUMENT LIKE BAPIVBELN-VBELN.
DATA: ORDER_HEADER_INX LIKE BAPISDH1X,
      BEHAVE_WHEN_ERROR LIKE BAPIFLAG-BAPIFLAG,
      SIMULATION LIKE BAPIFLAG-BAPIFLAG.
DATA: BEGIN OF ORDER_ITEM_IN OCCURS 2.
        INCLUDE STRUCTURE BAPISDITM.
DATA: END OF ORDER_ITEM_IN.
DATA: BEGIN OF ORDER_ITEM_INX OCCURS 2.
        INCLUDE STRUCTURE BAPISDITMX.
DATA: END OF ORDER_ITEM_INX.
DATA: BEGIN OF SCHEDULE_LINES OCCURS 2.
        INCLUDE STRUCTURE BAPISCHDL.
DATA: END OF SCHEDULE_LINES.
DATA: BEGIN OF SCHEDULE_LINESX OCCURS 2.
        INCLUDE STRUCTURE BAPISCHDLX.
DATA: END OF SCHEDULE_LINESX.
DATA: BEGIN OF ORDER_CFGS_REF OCCURS 2.
        INCLUDE STRUCTURE BAPICUCFG.
DATA: END OF ORDER_CFGS_REF.
DATA: BEGIN OF ORDER_CFGS_INST OCCURS 2.
        INCLUDE STRUCTURE BAPICUINS.
DATA: END OF ORDER_CFGS_INST.
DATA: BEGIN OF ORDER_CFGS_VALUE OCCURS 2.
        INCLUDE STRUCTURE BAPICUVAL.
DATA: END OF ORDER_CFGS_VALUE.
DATA: BEGIN OF CONDITIONS_IN OCCURS 2.
        INCLUDE STRUCTURE BAPICOND.
DATA: END OF CONDITIONS_IN.
DATA: BEGIN OF CONDITIONS_INX OCCURS 2.
        INCLUDE STRUCTURE BAPICONDX.
DATA: END OF CONDITIONS_INX.
DATA: BEGIN OF EXTENSIONIN OCCURS 2.
        INCLUDE STRUCTURE BAPIPAREX.
DATA: END OF EXTENSIONIN.
DATA: BEGIN OF RETURN OCCURS 2.
        INCLUDE STRUCTURE BAPIRET2.
DATA: END OF RETURN.
DATA: TMP_POSNR  LIKE VBAP-POSNR,
      L_KNUMV    LIKE VBAK-KNUMV,
      L_KSCHL    LIKE KONV-KSCHL,
      L_STUNR    LIKE KONV-STUNR,
      L_ZAEHK    LIKE KONV-ZAEHK.
***--- Selection
PARAMETERS: P_VBELN LIKE VBAK-VBELN OBLIGATORY MEMORY ID AUN DEFAULT '7000510', "'0001007443', " SO
            P_POSNR LIKE VBAP-POSNR OBLIGATORY DEFAULT '000000' , " so item
            P_CONDN LIKE  KONV-KSCHL  DEFAULT 'ZOSP',    " condition type
            P_CONDI LIKE  KONV-ZAEHK  DEFAULT '01',      " Condition item number
            P_TEST  AS CHECKBOX DEFAULT 'X'.             " test mode
  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
      INPUT         = P_VBELN
    IMPORTING
      OUTPUT        = P_VBELN.
  CLEAR: L_KNUMV.
  SELECT SINGLE KNUMV INTO L_KNUMV
  FROM VBAK
  WHERE VBELN  = P_VBELN.
  IF SY-SUBRC = 0.
    CLEAR: L_KSCHL,L_ZAEHK,L_STUNR.
    SELECT SINGLE KSCHL ZAEHK STUNR INTO (L_KSCHL, L_ZAEHK, L_STUNR)
    FROM KONV
    WHERE KNUMV = L_KNUMV
      AND KPOSN = P_POSNR
      AND ZAEHK = P_CONDI
      AND KSCHL = P_CONDN.
    IF SY-SUBRC <> 0.
      WRITE:/ 'Condition type or condition item is not exist.'.
      EXIT.
    ENDIF.
  ELSE.
    WRITE:/ 'Sales order number is not exist'.
    EXIT.
  ENDIF.
IF L_ZAEHK IS INITIAL.
      WRITE:/ 'Condition type or condition item is not exist.'.
      EXIT.
ENDIF.
SALESDOCUMENT = P_VBELN.     " Sales order number
ORDER_HEADER_INX-UPDATEFLAG = 'U'.   "U = change sales order
***Item Data
ORDER_ITEM_IN-ITM_NUMBER = P_POSNR.
APPEND ORDER_ITEM_IN.
ORDER_ITEM_INX-UPDATEFLAG = 'U'.   "I = add, U= update, D=delete
ORDER_ITEM_INX-ITM_NUMBER = P_POSNR.
APPEND ORDER_ITEM_INX.
***--- Begin delete a condition line
***--- Make sure to use update flag 'D'. Here I = add, U= update, D=delete
CLEAR: CONDITIONS_IN,CONDITIONS_INX.
REFRESH: CONDITIONS_IN,CONDITIONS_INX.
CONDITIONS_IN-ITM_NUMBER = P_POSNR.
CONDITIONS_IN-COND_ST_NO = L_STUNR.
CONDITIONS_IN-COND_COUNT = L_ZAEHK.
CONDITIONS_IN-COND_TYPE  = L_KSCHL.
APPEND CONDITIONS_IN.
CONDITIONS_INX-UPDATEFLAG = 'D'.
CONDITIONS_INX-ITM_NUMBER  = P_POSNR.
CONDITIONS_INX-COND_ST_NO  = L_STUNR.
CONDITIONS_INX-COND_COUNT  = L_ZAEHK.
CONDITIONS_INX-COND_TYPE   = L_KSCHL.
APPEND CONDITIONS_INX.
***--- End delete a condition line
BEHAVE_WHEN_ERROR = 'P'.
SIMULATION = P_TEST.   " Test mode or not
"=== call BAPI
CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
  EXPORTING
    SALESDOCUMENT               = SALESDOCUMENT
    ORDER_HEADER_INX            = ORDER_HEADER_INX
    LOGIC_SWITCH                = '    U'
  TABLES
    RETURN                      = RETURN
    ORDER_ITEM_IN               = ORDER_ITEM_IN
    ORDER_ITEM_INX              = ORDER_ITEM_INX
    CONDITIONS_IN               = CONDITIONS_IN
    CONDITIONS_INX              = CONDITIONS_INX .
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
WRITE: / 'Return code =', SY-SUBRC.
SKIP 1.
LOOP AT RETURN.
  WRITE: / RETURN-MESSAGE.
ENDLOOP.
Edited by: hank jiang on May 21, 2010 5:07 AM
Edited by: hank jiang on May 21, 2010 5:25 AM
Edited by: hank jiang on May 21, 2010 5:27 AM

SALESDOCUMENT = P_VBELN.     "Sales order number
ORDER_HEADER_INX-UPDATEFLAG = 'U'.   "U = change sales order
ORDER_ITEM_IN-ITM_NUMBER = P_POSNR.
APPEND ORDER_ITEM_IN.
ORDER_ITEM_INX-UPDATEFLAG = 'U'.   "I = add, U= update, D=delete
ORDER_ITEM_INX-ITM_NUMBER = P_POSNR.
APPEND ORDER_ITEM_INX.
"Begin delete a condition line
"Make sure to use update flag 'D'. Here I = add, U= update, D=delete
CLEAR: CONDITIONS_IN,CONDITIONS_INX.
REFRESH: CONDITIONS_IN,CONDITIONS_INX.
CONDITIONS_IN-ITM_NUMBER = P_POSNR.
CONDITIONS_IN-COND_ST_NO = L_STUNR.
CONDITIONS_IN-COND_COUNT = L_ZAEHK.
CONDITIONS_IN-COND_TYPE  = L_KSCHL.
APPEND CONDITIONS_IN.
CONDITIONS_INX-UPDATEFLAG = 'D'.
CONDITIONS_INX-ITM_NUMBER  = P_POSNR.
CONDITIONS_INX-COND_ST_NO  = L_STUNR.
CONDITIONS_INX-COND_COUNT  = L_ZAEHK.
CONDITIONS_INX-COND_TYPE   = L_KSCHL.
APPEND CONDITIONS_INX.
"End delete a condition line
BEHAVE_WHEN_ERROR = 'P'.
SIMULATION = P_TEST.   " Test mode or not
"=== call BAPI
CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
  EXPORTING
    SALESDOCUMENT               = SALESDOCUMENT
    ORDER_HEADER_INX            = ORDER_HEADER_INX
    LOGIC_SWITCH                = '    U'
  TABLES
    RETURN                      = RETURN
    ORDER_ITEM_IN               = ORDER_ITEM_IN
    ORDER_ITEM_INX              = ORDER_ITEM_INX
    CONDITIONS_IN               = CONDITIONS_IN
    CONDITIONS_INX              = CONDITIONS_INX .
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
WRITE: / 'Return code =', SY-SUBRC.
SKIP 1.
LOOP AT RETURN.
  WRITE: / RETURN-MESSAGE.
ENDLOOP.

Similar Messages

  • How to insert new schedule line in Sales order using BAPI

    Hi All,
    I am using the below code to add a new line in the schedules line of a existing sales order.But i am not getting the extra line after running the report.
    Kindly guide me in how to achieve this.
    thanks and regards
    shilpa
    REPORT  Z_VA32_EDI1.
    data: v_vbeln type BAPIVBELN-VBELN,
          wa_order_header type BAPISDH1X,
          i_sch_line type standard table of BAPISCHDL with header line,
          i_sch  type standard table of BAPISCHDLX with header line,
          i_return type standard table of BAPIRET2 with header line.
    v_vbeln = '0030001227'.
    wa_order_header-UPDATEFLAG = 'U'.
    i_sch-ITM_NUMBER = '000010'.
    i_sch-UPDATEFLAG  = 'I'.
    i_sch-REQ_DATE  = 'X'.
    i_sch-REL_TYPE = 'X'.
    i_sch-PLAN_SCHED_TYPE = 'X'.
    i_sch-REQ_QTY     = 'X'.
    append i_Sch.
    i_sch_line-ITM_NUMBER = '000010'.
    i_sch_line-REQ_DATE  = '20080127'.
    i_sch_line-REL_TYPE = '2'.
    i_sch_line-PLAN_SCHED_TYPE = '2'.
    i_sch_line-REQ_QTY     = '65'.
    append i_Sch_line.
    CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
      EXPORTING
        salesdocument               = v_vbeln
      ORDER_HEADER_IN             =
        order_header_inx            = wa_order_header
      SIMULATION                  =
      BEHAVE_WHEN_ERROR           = ' '
      INT_NUMBER_ASSIGNMENT       = ' '
      LOGIC_SWITCH                =
      NO_STATUS_BUF_INIT          = ' '
      tables
        return                      = i_Return
      ORDER_ITEM_IN               =
      ORDER_ITEM_INX              =
      PARTNERS                    =
      PARTNERCHANGES              =
      PARTNERADDRESSES            =
      ORDER_CFGS_REF              =
      ORDER_CFGS_INST             =
      ORDER_CFGS_PART_OF          =
      ORDER_CFGS_VALUE            =
      ORDER_CFGS_BLOB             =
      ORDER_CFGS_VK               =
      ORDER_CFGS_REFINST          =
       SCHEDULE_LINES              = i_sch_line[]
       SCHEDULE_LINESX             = i_sch[]
      ORDER_TEXT                  =
      ORDER_KEYS                  =
      CONDITIONS_IN               =
      CONDITIONS_INX              =
      EXTENSIONIN                 =
      NFMETALLITMS                =
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
    wait = 'X'.
    write: 'Done'.

    hi,
    pass the values 'x' to the bellow structure for all the fields that u want use and provide the item no ,schedule line no.
    SCHEDULE_LINESX

  • How to restrict header text changes in sales order level

    Dear Experts,
    how to restrict header text changes in sales order level change mode
    thanks

    Hello Chandu,
    how to restrict header text changes in sales order level change mode
    In order to restrict changes to Sales Order Header Text, the appropriate User Exit would be USEREXIT_MOVE_FIELD_TO_TVCOM_H. With the help of ABAPer, you can include the simple logic on the basis of Header Text type such that whenever any changes are incurred on the Sales Order header text, updates would be prevented.
    Please try out this approach and let us know your latest observation on this issue.
    Regards,
    Sarthak

  • How to change header status of a sales order

    Hi people,
    can anybody suggest me a FM for changing sales order header status (say from partailly complete to completed).
    Regards,
    Sandy

    Use this FM SD_SALES_HEADER_MAINTAIN.
    <b><REMOVED BY MODERATOR></b>
    Regards.
    Message was edited by:
            Alvaro Tejada Galindo

  • Create a schedule line in sales order using Bapi

    Hi Guys,
    Here the requirement is automating the process of creating the schedule lines using Bapi.
    I am using the bapi BAPI_SALESORDER_CHANGE for the same.
    I could able to create a schedule line but the problem is,its not updating the CONFIRMED QUANTITY and COMMITTED  QUANTITY on
    sales order schedule line tab,its updating ORDER QUANTITY and ROUNDED QUANTITY.
    the structures and tables parameters i have updated are:
    IMPORT PARAMETERS: SALESDOCUMENT,ORDER_HEADER_INX-UPDATEFLAG= 'U'(change sales order).
    TABLES:SCHEDULE_LINES(ITM_NUMBER,REQ_DATE,REQ_QTY,DLV_DATE)
                   SCHEDULE_LINESX(ITM_NUMBER,UPDATEFLAG='I',REQ_DATE,REQ_QTY,DLV_DATE).
    Please help me out if i need to fill up any other parameters or anything am missing out here.
    Would appreciate your help.
    Thanks in Advance
    Ramu

    Dear Ramu ,
    Any solution to this Issue i have the same Requirement and faceing the very same problem.
    Thanks in advance for reply .
    Thanks alot.
    regards
    Prashant Singh

  • How to delete string or line from unix file(dataset) of application server

    Hi  All,
    After transfer workarea information or all records into dataset(unix file). When I see the file in application server automatically the last line is shown a blank line. I am not passing any blank line.
    I have tried for single record than also the file generates the last line(2nd line) also a blank line.
    When I m reading the dataset, it is not reading the last blank line but why it is showing the last blank line?
    How to delete string or line from unix file(dataset) of application server?
    Please give your comments to resolve this.
    Thanks
    Tirumula Rao Chinni

    Hi Rio,
    I faced similar kind of issue working with files on UNIX platform.
    The line is a line feed to remove it use
    DATA : lv_carr_linefd TYPE abap_cr_lf VALUE cl_abap_char_utilities=>cr_lf. 
      DATA : lv_carr_return TYPE char1,                                   
             lv_line_feed   TYPE char1.                                          
      lv_line_feed   = lv_carr_linefd(1).
      lv_carr_return = lv_carr_linefd+1(1).
    Note: IMP: The character in ' ' is not space but is a special
    character set by pressing ALT and +255 simultaneosly
      REPLACE ALL OCCURRENCES OF lv_line_feed IN l_string WITH ' '.
      REPLACE ALL OCCURRENCES OF lv_carr_return IN l_string WITH ' '.

  • How to delete the specified line in file?

    How to delete the specified line in file? In case of deleting a specified line in a file, how to do?
    Line 1
    Line 2
    Line 3
    Line 4
    Line 5
    The case is a file including the above content. Now I wanna to delete the "Line 3" and how to realize the action in Java?

    An alternative solution can be :
    import java.io.LineNumberReader;
    import java.io.IOException;
    import java.io.File;
    import java.io.FileReader;
    import java.io.BufferedWriter;
    import java.io.FileWriter;
    import java.io.PrintWriter;
    public class LineDeleter {
    public static void main(String args[]){
    try {
    //suppose you want to delete line 3
         int lineToBeDeleted = 3;
         File f = new File("line.txt");
         long fileSize = f.length();
    //Wrap the FileReader with a LineNumberReader. It will help you
    //identify the lines.
    LineNumberReader lnr = new LineNumberReader( new FileReader(f));
    //Wrap the FileWriter object with BufferedWriter object. Create it with the buffersize
    //equal to the file size.
         BufferedWriter bw = new BufferedWriter(new FileWriter(new File("line1.txt")),(int)fileSize);
    //Wrap BufferedWriter object with PrintWriter so that it allows you
    //to print line by line
    PrintWriter pw = new PrintWriter(bw);
         String s=null;
         while ( (s=lnr.readLine())!=null ){
              System.out.println(s);
              int lineNumber = lnr.getLineNumber();
    //match the line number
              if(! (lineNumber==lineToBeDeleted)){
                   pw.println(s);
              pw.flush();
              lnr.close();
              pw.close();
         catch(Exception e){System.out.println(e);}
    If you want you can rename the line1.txt to the original file name.
    I hope this helps.Good luck!!!!!!

  • How to deactivate schedule line in sales order

    hi friends,
    how can i deactivate the schedule line in sales order so that we can deliver the sales order after the schedule date. i can uderstand that system is not allowing before schedule date. but what if i want to deliver after that.
    Thanks in advance.
    Regards,
    Solomon

    hi,
    this is to inform you that,
    here you need to switch off:
    schedule lines allowed
    in schedule lines control data - remove or un check - availability/TOR
    In SPRO - Availability Check settings.
    but i have a question here:
    what is the business logic.
    do you want to do the same with all the sales orders or not.
    please update the forum
    then answer will be different
    balajia

  • How to delete a whole line in cmd prompt in Linux

    Hi all,
    How to delete a whole line in cmd prompt in Linux using short key?
    ex: [oracle@host1 ~]$ cd /u01/app/oracle/product/11.2.0/dbhome_1/
    Thanks

    yes ctrl+ak or ctrl+eu both are better. if you look from that perspective, go end and delete will be the same job too. (ctrl+eu) (but for me in such a command line, for example cding in to the directories ,the cursor will be at the end of the line %99 of the time :) )
    about ctrl-t,
    Drag the character before the cursor forward over the character at the cursor, moving the cursor forward as well. If the insertion point is at the end of the line, then this transposes the last two characters of the line.
    for ex:
    misspelled command date -> daet -> ctrl+t -> date
    or
    misspelled command $APPPL_TO -> place the cursor on third P press ctrl+t repeateadly till the P will come to the end -> APPL_TOP

  • How to delete the horiz line of addresses beneath the address bar

    How to delete the horiz line of addresses beneath the address window. They are not affected by the "delete recent sites" tool.

    Do you mean the tab bar?
    See [[Tabbed browsing]]

  • How to create the sales order using BAPI's ....?

    Hi Guru's,
    could you please provide how to create the sales order using BAPI's .....i need step by step process and please provide the details from scratch....basically  i don't have basic knowledge on this....please provide required inputs ....:)
    thanks in advance
    Srinivas......

    Hi Guru's thanks for your inouts and your valuble time...
    please find the program logic below...
    *& Report  ZAREPAS30
    REPORT  zarepas30.
    DATA : gs_vbeln                   TYPE  vbak-vbeln,
           gs_order_header_in         TYPE  bapisdhd1,
           gs_order_header_inx        TYPE  bapisdhd1x,
           gt_order_items_in          TYPE  STANDARD TABLE OF bapisditm,
           gwa_itab1                  TYPE  bapisditm,
           gt_order_items_inx         TYPE  STANDARD TABLE OF bapisditmx,
           gwa_itab2                  TYPE  bapisditmx,
           gt_order_partners          TYPE  STANDARD TABLE OF bapiparnr,
           gwa_itab3                  TYPE  bapiparnr,
           gt_return                  TYPE  STANDARD TABLE OF bapiret2,
           gwa_itab4                  TYPE  bapiret2.
    Sales document type
      PARAMETERS: p_auart TYPE auart OBLIGATORY.
    Sales organization
      PARAMETERS: p_vkorg TYPE vkorg OBLIGATORY.
    Distribution channel
      PARAMETERS: p_vtweg TYPE vtweg OBLIGATORY.
    Division.
      PARAMETERS: p_spart TYPE spart OBLIGATORY.
    Requested Delivery Date
      PARAMETERS: p_edatu  TYPE edatu OBLIGATORY.
    Sold-to
      PARAMETERS: p_sold  TYPE kunnr OBLIGATORY.
    Ship-to
      PARAMETERS: p_ship  TYPE kunnr OBLIGATORY.
    Material
      PARAMETERS: p_matnr TYPE matnr   OBLIGATORY.
    Quantity.
      PARAMETERS: p_menge TYPE kwmeng  OBLIGATORY.
    Plant
      PARAMETERS: p_plant TYPE werks_d OBLIGATORY.
    Start-of-selection.
      START-OF-SELECTION.
    Header data
    Sales document type
      gs_order_header_in-doc_type = p_auart.
      gs_order_header_inx-doc_type = 'X'.
    Sales organization
      gs_order_header_in-sales_org = p_vkorg.
      gs_order_header_inx-sales_org = 'X'.
    Distribution channel
      gs_order_header_in-distr_chan  = p_vtweg.
      gs_order_header_inx-distr_chan = 'X'.
    Division
      gs_order_header_in-division = p_spart.
      gs_order_header_inx-division = 'X'.
    Reguested Delivery Date
      gs_order_header_in-req_date_h = p_edatu.
      gs_order_header_inx-req_date_h = 'X'.
      gs_order_header_inx-updateflag = 'I'.
    Partner data
    Sold to
      gwa_itab3-partn_role = 'AG'.
      gwa_itab3-partn_numb = p_sold.
      APPEND gwa_itab3 TO  gt_order_partners .
    ship to
      gwa_itab3-partn_role = 'WE'.
      gwa_itab3-partn_numb = p_ship.
      APPEND gwa_itab3 TO  gt_order_partners .
    ITEM DATA
      gwa_itab2-updateflag = 'I'.
    Line item number.
      gwa_itab1-itm_number = '000010'.
      gwa_itab2-itm_number = 'X'.
    Material
      gwa_itab1-material = p_matnr.
      gwa_itab2-material = 'X'.
    Plant
      gwa_itab1-plant    = p_plant.
      gwa_itab2-plant   = 'X'.
    Quantity
      gwa_itab1-target_qty = p_menge.
      gwa_itab2-target_qty = 'X'.
      APPEND gwa_itab1 TO gt_order_items_in.
      APPEND gwa_itab2 TO gt_order_items_inx.
    Line item number.
      gwa_itab1-itm_number = '000020'.
      gwa_itab2-itm_number = 'X'.
    Material
      gwa_itab1-material = p_matnr.
      gwa_itab2-material = 'X'.
    Plant
      gwa_itab1-plant    = p_plant.
      gwa_itab2-plant   = 'X'.
    Quantity
      gwa_itab1-target_qty = p_menge.
      gwa_itab2-target_qty = 'X'.
      APPEND gwa_itab1 TO gt_order_items_in.
      APPEND gwa_itab2 TO gt_order_items_inx.
    CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
      EXPORTING
        order_header_in               = gs_order_header_in
        ORDER_HEADER_INX              = gs_order_header_inx
      IMPORTING
        SALESDOCUMENT                 = gs_vbeln
      tables
        RETURN                        = gt_return
        ORDER_ITEMS_IN                = gt_order_items_in
        ORDER_ITEMS_INX               = gt_order_items_inx
        order_partners                = gt_order_partners.
    Check the return table.
      LOOP AT gt_return into gwa_itab4 WHERE type = 'E' OR type = 'A'.
        EXIT.
      ENDLOOP.
      IF sy-subrc = 0.
        WRITE: / 'Error occured while creating sales order '.
      ELSE.
    Commit the work.
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
        WRITE: / 'Document ', gs_vbeln, ' created'.
      ENDIF.

  • How to create sales order using BAPI.

    Hi all,
    I am trying to create sales order using standard BAPI
    "BAPI_SALESORDER_CREATEFROMDAT2". But, even I had entered all mandatory fields, I am unable to create sales order sucessfully.
    I had gone through the documentaion of this BAPI and entered these fields.
    These are the mandatory fields that which I had tried to create,
    ORDER_HEADER_IN :
    DOC_TYPE Sales document type
    SALES_ORG Sales organization
    DISTR_CHAN Distribution channel
    DIVISION Division
    ORDER_PARTNERS..:
    PARTN_ROLE Partner role, SP sold-to party
    PARTN_NUMB Customer number
    ORDER_ITEMS_IN..:
    MATERIAL Material number
    Do we have anymore fields to give as inputs? I am getting this error message as below :
    Msg: Personal number 00007176 does not exit.
    But, I am not giving any personal number manually. This personal number was having connection with partner role field,
    I had reffered this from the VBPA (Sales Document: Partner Table). Now, please suggest me how to solve this?
    Can anyone tell me how to solve this problem and create sales order sucessfully.
    Thanks in advance,
    Surender Batlanki.

    hi surendra ,
    chech with below code.
    REPORT z_bapi_salesorder_create.
    Parameters
    Sales document type
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 2(20) v_text FOR FIELD p_auart.
    PARAMETERS: p_auart TYPE auart OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    Sales organization
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 2(20) v_text1 FOR FIELD p_vkorg.
    PARAMETERS: p_vkorg TYPE vkorg OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    Distribution channel
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 2(20) v_text2 FOR FIELD p_vtweg.
    PARAMETERS: p_vtweg TYPE vtweg OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    Division.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 2(20) v_text3 FOR FIELD p_spart.
    PARAMETERS: p_spart TYPE spart OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    SKIP 1.
    Sold-to
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 2(20) v_text4 FOR FIELD p_sold.
    PARAMETERS: p_sold  TYPE kunnr OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    Ship-to
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 2(20) v_text5 FOR FIELD p_ship.
    PARAMETERS: p_ship  TYPE kunnr OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    SKIP 1.
    Material
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 2(20) v_text6 FOR FIELD p_matnr.
    PARAMETERS: p_matnr TYPE matnr   OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    Quantity.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 2(20) v_text7 FOR FIELD p_menge.
    PARAMETERS: p_menge TYPE kwmeng  OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    Plant
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 2(20) v_text9 FOR FIELD p_plant.
    PARAMETERS: p_plant TYPE werks_d OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    Data declarations.
    DATA: v_vbeln            LIKE vbak-vbeln.
    DATA: header             LIKE bapisdhead1.
    DATA: headerx            LIKE bapisdhead1x.
    DATA: item               LIKE bapisditem  OCCURS 0 WITH HEADER LINE.
    DATA: itemx              LIKE bapisditemx OCCURS 0 WITH HEADER LINE.
    DATA: partner            LIKE bapipartnr  OCCURS 0 WITH HEADER LINE.
    DATA: return             LIKE bapiret2    OCCURS 0 WITH HEADER LINE.
    DATA: lt_schedules_inx   TYPE STANDARD TABLE OF bapischdlx
                             WITH HEADER LINE.
    DATA: lt_schedules_in    TYPE STANDARD TABLE OF bapischdl
                             WITH HEADER LINE.
    Initialization.
    INITIALIZATION.
    v_text   = 'Order type'.
    v_text1  = 'Sales Org'.
    v_text2  = 'Distribution channel'.
    v_text3  = 'Division'.
    v_text4  = 'Sold-to'.
    v_text5  = 'Ship-to'.
    v_text6  = 'Material'.
    v_text7  = 'Quantity'.
    v_text9  = 'Plant'.
    Start-of-selection.
    START-OF-SELECTION.
    Header data
    Sales document type
      header-doc_type = p_auart.
      headerx-doc_type = 'X'.
    Sales organization
      header-sales_org = p_vkorg.
      headerx-sales_org = 'X'.
    Distribution channel
      header-distr_chan  = p_vtweg.
      headerx-distr_chan = 'X'.
    Division
      header-division = p_spart.
      headerx-division = 'X'.
      headerx-updateflag = 'I'.
    Partner data
    Sold to
      partner-partn_role = 'AG'.
      partner-partn_numb = p_sold.
      APPEND partner.
    Ship to
      partner-partn_role = 'WE'.
      partner-partn_numb = p_ship.
      APPEND partner.
    ITEM DATA
      itemx-updateflag = 'I'.
    Line item number.
      item-itm_number = '000010'.
      itemx-itm_number = 'X'.
    Material
      item-material = p_matnr.
      itemx-material = 'X'.
    Plant
      item-plant    = p_plant.
      itemx-plant   = 'X'.
    Quantity
      item-target_qty = p_menge.
      itemx-target_qty = 'X'.
      APPEND item.
      APPEND itemx.
      Fill schedule lines
      lt_schedules_in-itm_number = '000010'.
      lt_schedules_in-sched_line = '0001'.
      lt_schedules_in-req_qty    = p_menge.
      APPEND lt_schedules_in.
      Fill schedule line flags
      lt_schedules_inx-itm_number  = '000010'.
      lt_schedules_inx-sched_line  = '0001'.
      lt_schedules_inx-updateflag  = 'X'.
      lt_schedules_inx-req_qty     = 'X'.
      APPEND lt_schedules_inx.
    Call the BAPI to create the sales order.
      CALL FUNCTION 'BAPI_SALESDOCU_CREATEFROMDATA1'
           EXPORTING
                sales_header_in     = header
                sales_header_inx    = headerx
           IMPORTING
                salesdocument_ex    = v_vbeln
           TABLES
                return              = return
                sales_items_in      = item
                sales_items_inx     = itemx
                sales_schedules_in  = lt_schedules_in
                sales_schedules_inx = lt_schedules_inx
                sales_partners      = partner.
    Check the return table.
      LOOP AT return WHERE type = 'E' OR type = 'A'.
        EXIT.
      ENDLOOP.
      IF sy-subrc = 0.
        WRITE: / 'Error in creating document'.
      ELSE.
    Commit the work.
        COMMIT WORK AND WAIT.
        WRITE: / 'Document ', v_vbeln, ' created'.
      ENDIF.
    let us know if you have any qauistions.
    ~linganna

  • Item's SH is not change after Header's SH change(Sales Order).

    Hi All,
    Would like to have such requirement as below.
    SH = Ship To Party
    Process Flow
    Quotation(SH=A) > Sales Order(SH=B) > Delivery Order(SH=A instead of B) due to Sales Order Item Level SH is use SH=A that copy from Quotation which not use the one been changed in sales order header SH.
    Problems : How change Item SH together when Header SH changed in Sales Order.  Existing solution is more to verification usage that require ABAP development. Is that any other method which is more efficiency.
    Thank you very much.
    Link :
    Ship To Party in Delivery Order's Behaviour
    Item Ship to party as per Header Ship to party

    Hi All,
    Case Closed. Solution as below. That previously using 002. Thank you.

  • How to syatem determine delivery date in sales order

    hi sap gurus
    how to syatem determine delivery date in sales order
    Thanks and regards
    ram

    Hi Friend,
    There are many things which determines the delivery dates.
    01. PICK TIME+ PACK TIME +LOADING TIME
    02. LEAD TIME in days (VOV8)
    03. Shipping point
    04. Scheduling line
    05. Kind of availblity check
    06. If the above things are maintained as blank then the current date will be the delivery date
    However whether it must be proposed by the system or not is determined by one check box there find in VOV8 in requesteed delivery date determination tab.

  • Tree OOPS ALV - Need to display header & items of the sales order in oops

    HI,
        I need to display some of the header fields of the sales order & items in the oops alv, could you please let me know how to achieve this. I know FM - 'REUSE_ALV_HIERSEQ_LIST_DISPLAY' but how to achieve this through oops alv.
    Thanks

    it is not possible with that function in OO .
    you can try with class cl_salv_hierseq_table
    Just check this Rich's article
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b0f03986-046c-2910-a5aa-e5364e96ea2c
    if you don't want that then you may have to use ALV tree.

Maybe you are looking for

  • When playing dvds on my Macbook my TV states "mode not supported"  Any ideas?

    When playing DVD's on my Macbook my TV states "mode not supported". Any ideas?

  • Monitor "no input signal"

    When I turn on the computer and the monitor, the monitor does not recognize a signal from the computer.  I have tried restarting the monitor and the computer, unplugging all cables including the power cables and reconnecting, I re-seated the graphics

  • Applications missing from EAS and can't see designated HBR on forms in workspace

    Hi! Just finished patching our EPM system; 11.1.2.1.600: Oracle Hyperion EPM Workspace, HSS and Planning, fusion edition. 11.1.2.1.103: EAS After installing the patches the systems were up and running and everything was just fine until yesterday arou

  • Giving my iPad to my Mom........

    I want to give my iPad to my mother and get a bigger one. I know a restart will erase my stuff in the iPad, but what about iTunes when she first plugs it into her computer? She won't get my iTunes library or Apple account will she? How do I reregiste

  • Cannot install WinXP on Satellite Pro A200 - No HDD

    Hi, Please can someone help me. I've just brought 52 Satellite Pro A200 laptops. They come with Vista pre-installed, but I want to wipe them and install Windows XP. However I have a big problem - when I put my XP CD in and boot from it and click Ente