Change sales order using BAPI_SALESORDER_CHANGE

Hi i want to add a new line item to the existing sales order using BAPI_SALESORDER_CHANGE
but when i am trying it is giving
'Schedule line 0001 for item 000020 does not exist ' error..
please help me..

*********I wanted to add an new line item.***.. this is my code..********
LOOP AT gt_input3 INTO st_input3.
*Finding Max No of line Items
    IF fl_set IS INITIAL.
      READ TABLE gt_vbap INTO st_vbap WITH KEY vbeln = st_input3-vbeln.
      IF sy-subrc EQ 0.
        lv_posnr = st_vbap-posnr.
        fl_set = 'X'.
      ENDIF.
    ENDIF.
*Populate Item details
    lv_posnr = lv_posnr + 10.
    lv_vbeln = st_input3-vbeln.
    lv_order_header_inx-updateflag = 'U'.
    st_order_item_in-itm_number = lv_posnr.
    st_order_item_in-material  = st_input3-matnr.
    st_order_item_in-target_qty = st_input3-imv_qty.
    st_order_item_in-plant = st_input3-werks.
    st_order_item_in-store_loc = st_input3-lgort.
   st_order_item_in-store_loc = st_input3-lgort.
    APPEND st_order_item_in TO lt_order_item_in.
*Populate item updation Details
    st_order_item_inx-itm_number = lv_posnr.
    st_order_item_inx-updateflag = 'U'.
    st_order_item_inx-material = 'X'.
    st_order_item_inx-plant = 'X'.
    st_order_item_inx-store_loc = 'X'.
    st_order_item_inx-target_qty = 'X'.
    APPEND st_order_item_inx TO lt_order_item_inx.
*Populate the Schedule Lines
    st_schedule_lines-itm_number = lv_posnr.
    st_schedule_lines-sched_line = '0001'.
    st_schedule_lines-req_qty = st_input3-imv_qty.
    APPEND st_schedule_lines TO lt_schedule_lines.
*Populate the update details of schedule lines
    st_schedule_linesx-itm_number = lv_posnr.
    st_schedule_linesx-sched_line = '0001'.
    st_schedule_linesx-req_qty = 'X'.
    st_schedule_linesx-updateflag = 'U'.
    APPEND st_schedule_linesx TO lt_schedule_linesx.
       AT END OF vbeln.
*Call BAPI Sales order change
      CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
        EXPORTING
          salesdocument    = lv_vbeln
          order_header_inx = lv_order_header_inx
        TABLES
          return           = lt_return
          order_item_in    = lt_order_item_in
          order_item_inx   = lt_order_item_inx
          schedule_lines   = lt_schedule_lines
          schedule_linesx  = lt_schedule_linesx.
*Save Sales Order
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait = 'X'.
      CLEAR lv_posnr.
      READ  TABLE lt_return INTO st_return WITH KEY type = 'E'.
      st_ipfile_err3-message = st_return-message.
*Error Log
      LOOP AT gt_temp3 INTO st_temp3.
        IF st_ipfile_err3-message IS NOT INITIAL.
          MOVE st_temp3-record TO st_ipfile_err3-record.
          IF fl_set1 IS INITIAL.
            APPEND st_temp_err TO gt_ipfile_err3.
            fl_set1 = 'X'.
          ENDIF.
          APPEND st_ipfile_err3 TO gt_ipfile_err3.
        ELSE.
          APPEND st_temp3 TO gt_audit3.
        ENDIF.
        CLEAR : st_temp3,
                st_temp_err,
                st_ipfile_err3,
                fl_set.
      ENDLOOP.
      REFRESH : gt_zrman,

Similar Messages

  • Problem while changing Sales order using 'BAPI_SALESORDER_CHANGE'

    Hi all,
    Below is my code to update delivery block value:
    FORM call_bapi_salesorder_change .
    DATA:  iv_bapi_view  LIKE order_view.
    DATA: gt_sales_doc TYPE STANDARD TABLE OF sales_key, " Document Numbers to Be Selected
            gt_items TYPE STANDARD TABLE OF bapisdit. " Order Item Data for Document Numbers
    *************************************************************8
    DATA:order_headers_out LIKE bapisdhd OCCURS 0 WITH HEADER LINE.
    DATA:order_header_inx LIKE bapisdh1x.
      DATA: lv_salesdocument LIKE bapivbeln-vbeln.
      data: lv_matnr(10) type c.
      DATA:
    gt_schdule TYPE STANDARD TABLE OF bapischdl, " for gl date & load date
    gt_schdulex TYPE STANDARD TABLE OF bapischdlx, " for partner role and partner function.
            gt_return TYPE STANDARD TABLE OF bapiret2,
            gt_itemin TYPE STANDARD TABLE OF bapisditm,
            gt_iteminx TYPE STANDARD TABLE OF bapisditmx ,
            gt_bapisdh1 TYPE STANDARD TABLE OF  bapisdh1.
      DATA:gs_head_bapi TYPE bapisdh1x,
           gs_schdule TYPE bapischdl,
           gs_schdulex TYPE bapischdlx,
           gs_return TYPE bapiret2,
           gs_itemin TYPE bapisditm,
           gs_iteminx TYPE bapisditmx,
           gs_bapisdh1 TYPE bapisdh1.
      CLEAR : gt_schdule,gt_schdulex,gs_return.
      REFRESH gt_return.
      gs_head_bapi-updateflag = 'U'.
    SORT gt_final BY vbeln.
    CLEAR gs_vbep.
    REFRESH gt_vbep[].
      CLEAR gs_final.
      LOOP AT gt_final1 INTO gs_final.
        gs_itemin-itm_number = gs_final-posnr.
    *move gs_final-matnr to lv_matnr."qx94162
       gs_itemin-material = gs_final-matnr.
        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
          EXPORTING
            input  = gs_final-matnr
          IMPORTING
            output = gs_final-matnr.
       CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = lv_matnr
        IMPORTING
         output = lv_matnr.
       gs_itemin-material = lv_matnr.
        gs_itemin-material = gs_final-matnr.
        gs_iteminx-itm_number = gs_final-posnr.
        gs_iteminx-updateflag = 'U'.""changed to I
        gs_iteminx-material = 'X'.
        " gs_schdule-req_dlv_bl = gs_final-lifsp. " Delivery block
        gs_schdule-itm_number = gs_final-posnr.
        gs_schdulex-itm_number = gs_final-posnr.
        gs_schdule-sched_line = '0001'.
        gs_schdulex-sched_line = '0001'.
       MOVE gs_final-lifsp to gs_schdule-req_dlv_bl.
        gs_schdule-req_dlv_bl = gs_final-lifsp.
        gs_schdulex-req_dlv_bl = 'X'. " Delivery block
        gs_schdulex-updateflag = 'U'.
        gs_bapisdh1-sales_org = gs_final-vkorg.
        APPEND gs_schdule TO gt_schdule.
        APPEND gs_schdulex TO gt_schdulex.
        APPEND gs_itemin TO gt_itemin.
        APPEND gs_iteminx TO gt_iteminx.
       Append gs_BAPISDH1 to gt_BAPISDH1.
        lv_salesdocument = gs_final-vbeln.
        CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
          EXPORTING
            salesdocument               = lv_salesdocument     
           ORDER_HEADER_IN             = gs_BAPISDH1
            order_header_inx            = gs_head_bapi         
      SIMULATION                  =
      BEHAVE_WHEN_ERROR           = ' '
      INT_NUMBER_ASSIGNMENT       = ' '
      LOGIC_SWITCH                =
      NO_STATUS_BUF_INIT          = ' '
          TABLES
            return                      = gt_return            
       order_item_in               =    gt_itemin
       order_item_inx              = gt_iteminx
      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                = gt_schdule           
          schedule_linesx               = gt_schdulex          
      ORDER_TEXT                  =
      ORDER_KEYS                  =
      CONDITIONS_IN               =
      CONDITIONS_INX              =
      EXTENSIONIN                 =
      NFMETALLITMS                =
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
        REFRESH: gt_schdule, gt_schdulex, gt_itemin , gt_iteminx.
        LOOP AT gt_return INTO gs_return.
          WRITE / gs_return-message .
        ENDLOOP .
      ENDLOOP.
    ENDFORM.                    " CALL_BAPI_SALESORDER_CHANGE
    When I am using material value as 18342 using CONVERSION_EXIT_ALPHA_OUTPUT:
    ORDER_HEADER_IN has been processed successfully
    Material  is not defined for sales org.A101,  distr.chan.00,  language DE
    Error in ITEM_IN 000030
    SCHEDULE_IN has been processed successfully
    The sales document is not yet complete: Edit data
    Sales document 5010000715 was not changed
    and when I am using CONVERSION_EXIT_ALPHA_INPUT (000000000000018342)or  while debuging when I am changing value to  0018342 :
    I am getting below dump:
    Runtime Errors         DATA_LENGTH_0
    Exception              CX_SY_RANGE_OUT_OF_BOUNDS
    Date and Time          21.10.2010 07:22:17
    Information on where terminated
         Termination occurred in the ABAP program "SAPLVBAK" - in
          "MAP_VBAP_TO_BAPISDIT".
         The main program was "RS_TESTFRAME_CALL ".
         In the source code you have the termination point in line 168
         of the (Include) program "LVBAK001".
         The termination is caused because exception "CX_SY_RANGE_OUT_OF_BOUNDS"
          occurred in
         procedure "MAP_VBAP_TO_BAPISDIT" "(FORM)", but it was neither handled local
          nor declared
         in the RAISING clause of its signature.
         The procedure is in program "SAPLVBAK "; its source code begins in line
         99 of the (Include program "LVBAK001 ".
    The same dump I am getting while executing this above BAPI from SE37 tcode with the same test data.
    but I am able to change it though Va02 tcode.
    Edited by: Arora26 on Oct 21, 2010 7:58 AM

    Hi,
    have you searched for OSS notes? The note 1137897 looks like related to your problem. It mentions different BAPI but I assume that both BAPI reuse same routines and therefore it might solve your problem as well.
    Cheers

  • Change Sales order using BAPI

    When trying to change a Sales order using BAPI_SALESORDER_CHANGE, I am getting the following error.
    SD document 15704 is not in the database or has been archived.
    Please let me know what could be the problem

    you have the error message, which is self explanatory.
    SD document 15704 is not in the database or has been archived.
    if you knat that the sales document indeed exists, and the  message is deceiving, then check why are yopu gettign that. maybe you didn;t provide the order# will leading zeros, or you are tryingto change an order immediately after creating, in which case DB commit might not be completed.

  • Update ship-to partner in sales order using BAPI_SALESORDER_CHANGE

    Dear all,
    We are trying to update the ship-to partner in a sales order using BAPI_SALESORDER_CHANGE. This is working correctly for most of our orders, so we do fill the BAPI correctly. However for some of our orders on item level a different payer is specified than on header level. However in that case the BAPI will not update the ship-to partner, but given an error message VPD 034 u2018The document must contain the same credit control areas for all payersu2019. Debugging already learned that actually the message is given not because of different credit control areas, but due to the fact that the payers and therefore the credit customers are different (although in the same credit control areas). For this reason we can not update the ship-to party of a large number of our sales orders with this BAPI. Actually we have 2 questions:
    ·         Has somebody experienced the same issue and did you manage to solve it somehow, so the BAPI could be used for this purpose of updating partner data?
    ·         Do you know other ways of updating the partners or partner address of an existing sales order in the background?
    Thanks in advance for your assistance.
    Regards,
    Satish.

    It was caused by standard SAP.

  • Create / Change Sales Order using BAPI - Populating Enhanced Fields

    Hi,
    I am using BAPI: BAPI_SALESORDER_CHANGE to change the Sales Order and want to update the Enhanced Screen Field (Screen Exit Fields) in the Sales Order. Where to populate these enhanced screen fields in the BAPI Structure?
    Appreciate Your Help!.
    Thanks,
    Kannan

    Hi,
    MV45AFZZ   BAPI_SALESORDER_CHANGE
    Regards,
    Padmam.

  • Change sales orders using ORDCHG Message type

    Hi,
    I am trying to test the changing of quantity on sales order items using message type ORDCHG and process code ORDC. In segment E1EDP01 the action code is set to 002 - item changes. However when the IDoc is posted a new line is created in the order rather than the existing one being changed. The action code in the header is set to 003 - one or more items changed. Does anybody know how to control the change of quantity for an existing item?
    Many Thanks
    Caroline

    Hi,
    Try to populate Logical message code 'CHG' in the EDIDC-MESCOD while you are creating the IDoc.
    If a message code has been entered in the (inbound) partner profiles, the external system must fill the field during IDoc inbound processing.
    Regards,
    Yogesh

  • Remove Reason For Rejection From Sales Order Using BAPI_SALESORDER_CHANGE

    Hi
    I have a sales order and would like to remove the rejection reason.
    I am trying to use BAPI_SALESORDER_CHANGE with the following code:
    (0000xxxxxxx  is my material #. i just removed the actual #).
    MOVE: '0000050106' TO SALESDOCUMENT.
    MOVE: 'U' TO T_HEADER_INX-UPDATEFLAG.
    MOVE:                        30 to t_order_item_in-ITM_NUMBER,
                                      ' ' to t_order_item_in-REASON_REJ,
          '0000000000xxxxxxxx' to t_order_item_in-material.
    APPEND t_order_item_in.
    MOVE: 'U' TO t_order_item_inx-updateflag.
    MOVE: 'X' to t_order_item_inx-REASON_REJ,
               'X' TO t_order_item_inx-material.
    CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
      EXPORTING
        salesdocument              = SALESDOCUMENT
        order_header_inx           = T_HEADER_INX
      tables
        RETURN                     = T_RETURN
        ORDER_ITEM_IN              = T_ORDER_ITEM_IN
        ORDER_ITEM_INX             = T_ORDER_ITEM_INX
    WAIT UP TO 5 SECONDS.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      WAIT          = 'X'
    IMPORTING
       RETURN        = t_return
    WAIT UP TO 5 SECONDS.
    can anybody help?
    the BAPI returns success messages saying the item was processed successfully but the reason code is still there.
    However, if i pass in any other reason code like 02 or 06, it works!.
    thanks.

    Thanks for your help. =)
    I also realized that I forgot to add the SO Item # into the T_ORDER_ITEM_INX-ITM_NUMBER fields.
    But now it works.

  • Update sales order using BAPI_SALESORDER_CHANGE --- URGENT!!!!

    Hello,
    <b> I want to update Batch, Pricing date, Header text & Item text using BAPI_SALESORDER_CHANGE.</b>
    But i am not able to do it.
    i have written a code, but it's still not updating:
    PARAMETERS: p_vbeln LIKE vbak-vbeln.
    TYPES: BEGIN OF t_return.
            INCLUDE STRUCTURE bapiret2.
    TYPES: END OF t_return.
    TYPES: BEGIN OF t_order_item_in.
            INCLUDE STRUCTURE bapisditm.
    TYPES: END OF t_order_item_in.
    TYPES: BEGIN OF t_order_item_inx.
            INCLUDE STRUCTURE bapisditmx.
    TYPES: END OF t_order_item_inx.
    TYPES: BEGIN OF t_schedule_lines.
            INCLUDE STRUCTURE bapischdl.
    TYPES: END OF t_schedule_lines.
    TYPES: BEGIN OF t_schedule_linesx.
            INCLUDE STRUCTURE bapischdlx.
    TYPES: END OF t_schedule_linesx.
    TYPES: BEGIN OF t_order_text.
            INCLUDE STRUCTURE bapisdtext.
    TYPES: END OF t_order_text.
    DATA: l_vbeln              LIKE          bapivbeln-vbeln,
          i_order_header_inx   LIKE          bapisdh1x,
          i_order_header_in    LIKE          bapisdh1,
          i_return             TYPE TABLE OF t_return,
          i_order_item_in      TYPE TABLE OF t_order_item_in,
          wa_order_item_in     LIKE LINE  OF i_order_item_in,
          i_order_item_inx     TYPE TABLE OF t_order_item_inx,
          wa_order_item_inx    LIKE LINE  OF i_order_item_inx,
          i_schedule_lines     TYPE TABLE OF t_schedule_lines,
          wa_schedule_lines    LIKE LINE  OF i_schedule_lines,
          i_schedule_linesx    TYPE TABLE OF t_schedule_linesx,
          wa_schedule_linesx   LIKE LINE  OF i_schedule_linesx,
          i_order_text         TYPE TABLE OF t_order_text,
          wa_order_text        LIKE LINE  OF i_order_text,
          w_return             LIKE          bapiret2,
          l_date               TYPE char10.
    CLEAR l_vbeln.
    l_vbeln = p_vbeln.
              UPDATE REJECTION REASON IN SALES ORDER                *
    *WRITE sy-datum TO l_date.
    i_order_header_inx-updateflag = 'U'.
    REFRESH i_order_item_in.
    CLEAR wa_order_item_in.
    wa_order_item_in-itm_number = '000010'.
    wa_order_item_in-batch = '2007450027'.
    wa_order_item_in-price_date = sy-datum.
    wa_order_item_in-reason_rej = '00'.
    APPEND wa_order_item_in TO i_order_item_in.
    REFRESH i_order_item_inx.
    CLEAR wa_order_item_inx.
    wa_order_item_inx-itm_number = '000010'.
    wa_order_item_inx-updateflag = 'U'.
    wa_order_item_in-batch = 'X'.
    wa_order_item_in-price_date = 'X'.
    wa_order_item_inx-reason_rej = 'X'.
    APPEND wa_order_item_inx TO i_order_item_inx.
    *wa_order_text-doc_number = l_vbeln.
    **wa_order_text-TDOBJECT = 'EHSWA_MAN'.
    ***wa_order_text-text_id = '0001'.
    **wa_order_text-TDTEXT = 'Header Texts'.
    *wa_order_text-text_line = 'SYNGENTA HEADER'.
    ***wa_order_text-function = 'U'.
    wa_order_text-doc_number = l_vbeln.
    wa_order_text-itm_number = '000010'.
    *wa_order_text-TDOBJECT = 'EBAN'.
    wa_order_text-text_id = '0001'.
    *wa_order_text-TDTEXT = 'Item text'.
    wa_order_text-text_line = 'SYNGENTA TEXT'.
    wa_order_text-function = '004'.
    APPEND wa_order_text TO i_order_text.
    CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
      EXPORTING
        salesdocument               = l_vbeln
      ORDER_HEADER_IN             =
        order_header_inx            = i_order_header_inx
      SIMULATION                  =
      BEHAVE_WHEN_ERROR           = ' '
      INT_NUMBER_ASSIGNMENT       = ' '
      LOGIC_SWITCH                =
      NO_STATUS_BUF_INIT          = ' '
      TABLES
        return                      = i_return
        order_item_in               = i_order_item_in
        order_item_inx              = i_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_schedule_lines
       schedule_linesx             = i_schedule_linesx
       order_text                  = i_order_text
      ORDER_KEYS                  =
      CONDITIONS_IN               =
      CONDITIONS_INX              =
      EXTENSIONIN                 =
    IF sy-subrc = 0.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait   = 'X'
        IMPORTING
          return = w_return.
    ENDIF.
    Please help out.
    Please send the code of it.
    Thanks in advance...

    START-OF-SELECTION.
    Get Blocked Orders
      PERFORM sub_select_orders.
      PERFORM order_reason_for_reject.
      END-OF-SELECTION.
    Display output
      PERFORM sub_display_output.
    *&      Form  sub_select_orders
          text
    FORM sub_select_orders .
      SELECT a~vbeln
             a~erdat
             a~erzet
             a~auart
             b~posnr
             FROM ( vbak as A
             INNER JOIN VBAP AS B
             on Bvbeln = AVBELN )
             INTO TABLE i_order_data
             WHERE a~vbeln IN s_ordno  AND
                   A~auart IN s_auart  AND
                   A~erdat IN s_orddt  AND
                   A~vkorg IN s_vkorg  AND
                   A~vtweg IN s_vtweg  AND
                   A~spart IN s_spart .
      IF sy-subrc NE 0.
        MESSAGE i001.
      No data selected
        LEAVE LIST-PROCESSING.
      ENDIF.
    ENDFORM.                    " sub_get_blocked_orders
    *&      Form  order_reason_for_reject
          text
    -->  p1        text
    <--  p2        text
    FORM order_reason_for_reject .
      LOOP AT i_order_data INTO w_order_data.
        w_output-vbeln = w_order_data-vbeln.
        w_ordhdrx-updateflag = c_update.
    Update Order Reason for rejection .
        w_orditem-ITM_NUMBER = w_order_data-posnr.
        w_orditem-reason_rej = p_abgru.
        append w_orditem to i_orditem .
        w_orditemx-ITM_NUMBER = w_order_data-posnr.
        w_orditemx-updateflag = c_update.
        w_orditemx-reason_rej = 'X'.
        append w_orditemx to i_orditemx .
        At end of vbeln .
        w_output-vbeln = w_order_data-vbeln .
          CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
            EXPORTING
              salesdocument    = w_order_data-vbeln
              order_header_in  = w_ordhdr
              order_header_inx = w_ordhdrx
            TABLES
              ORDER_ITEM_IN    = i_orditem
              ORDER_ITEM_INX   = i_orditemx
              return           = i_bapiret.
          READ TABLE i_bapiret WITH KEY type = c_error
                               TRANSPORTING NO FIELDS.
          IF sy-subrc EQ '0'.
            move 'Order Reason for rejection update Failed' to
            w_output-message .
          ELSE.
            CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
              EXPORTING
                wait   = c_check
              IMPORTING
                 return = i_return.
          move 'Order Reason for rejection update successful' to
          w_output-message .
         endif .
         refresh :i_orditemx , i_orditem .
        Endat .
        APPEND w_output TO i_output.
        CLEAR w_output.
      endloop .
    ENDFORM.                    " order_reason_for_reject

  • To delete sales order using BAPI_SALESORDER_CHANGE

    HI ,
           I am using BAPI_SALESORDER_CHANGE to delete a bulk of order lines for an order.But the issue is...the entries are deleted in VBEP and VBUP tables for all the order lines where in VBAP only few order lines are deleted.This is happening repeatedly.
    I am passing data like this...
        CLEAR: l_vbap_inx.
        l_vbap_inx-itm_number            =  t_vbap-posnr.  " will have value
        l_vbap_inx-updateflag            = 'D'.
        APPEND l_vbap_inx.
        CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
             EXPORTING
                  salesdocument    = i_vbeln                   "will have order number
                  order_header_inx = l_vbak_inx            " will be paased with values 'U'
                  order_header_in  = header                 "will not hold any value
                  simulation       = i_simulate                  "space
             TABLES
                  return           = l_return
                  order_item_in    = l_vbap                   "bulk of order lines with 'D' flag
                  order_item_inx   = l_vbap_inx
                  extensionin      = l_vbap_ext.
    can you please suggest on this......
    Thanks in advance.

    HI ,
    Can any one of you please suggest me to amend the below given code which is used to  delete bulk of order lines from VBAP table.presently it is deleting first few order lines from VBAP and all order lines from VBEP and VBUP tables.when i execute the same program for second time  first left out order lines are getting deleted again.So..can any one please check the below code and suggest me something on this.
        REFRESH: l_return, l_vbap, l_vbap_inx, l_vbap_ext.
      IF xorder_delete = 'X'.
        l_vbak_inx-updateflag = 'D'.
    Even though all the order lines are to be deleted, the delete complete
    order flag says don't delete the header data
        IF i_cleanup = space.
          l_vbak_inx-updateflag = 'U'.
          PERFORM validate_line_count TABLES l_vbap_ext         "iw150709
                                       USING i_vbeln.           "iw150709
        ENDIF.
      ELSE.
        l_vbak_inx-updateflag = 'U'.
        PERFORM validate_line_count TABLES l_vbap_ext           "iw150709
                                     USING i_vbeln.             "iw150709
      ENDIF.
      LOOP AT t_vbap WHERE delete = 'X'.
        CLEAR: l_vbap.
        l_vbap-itm_number                =  t_vbap-posnr.
        APPEND l_vbap.
        CLEAR: l_vbap_inx.
        l_vbap_inx-itm_number            =  t_vbap-posnr.
        l_vbap_inx-updateflag            = 'D'.
        APPEND l_vbap_inx.
        CLEAR: l_vbap_ext, l_extension_vbapx.
        l_vbap_ext-structure             = 'BAPE_VBAPX'.
        l_extension_vbapx-vbeln          =  i_vbeln.
        l_extension_vbapx-posnr          =  t_vbap-posnr.
        l_extension_vbapx-zzco_reason    = 'X'.
        l_vbap_ext+30                    =  l_extension_vbapx.
        APPEND l_vbap_ext.
        CLEAR: l_vbap_ext, l_extension_vbap.
        l_vbap_ext-structure             = 'BAPE_VBAP'.
        l_extension_vbap-vbeln           =  i_vbeln.
        l_extension_vbap-posnr           =  t_vbap-posnr.
        l_extension_vbap-zzco_reason     =  i_reason.
        l_vbap_ext+30                    =  l_extension_vbap.
        APPEND l_vbap_ext.
      ENDLOOP.
    Only call BAPI if NOT in test mode.
      IF i_simulate = space.
        CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
             EXPORTING
                  salesdocument    = i_vbeln
                  order_header_inx = l_vbak_inx
                  order_header_in  = header
                  simulation       = i_simulate
             TABLES
                  return           = l_return
                  order_item_in    = l_vbap
                  order_item_inx   = l_vbap_inx
                  extensionin      = l_vbap_ext.
      ENDIF.
      LOOP AT l_return WHERE type = 'E' OR type = 'A'.
        MOVE-CORRESPONDING l_return TO t_messages.
        t_messages-field = 'VBELN'.
        APPEND t_messages.
      ENDLOOP.
    No ERRORs
      IF sy-subrc <> 0.
        IF i_simulate = space.
          CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
               IMPORTING
                    return = l_return.
    Edited by: manj1325 on Apr 9, 2010 8:19 AM

  • Change sales order values from Inbound Idoc

    Hi all,
         In my scenario i have to change sales document automatically(Workflow) by getting the values from the inbound idoc ordchg (one more thing i dont want to create another sales document). Is there is any function module? please tell me how to do this.
    Regards,
    Adithan S.

    Hi Adithan;
       You can read the IDoc information using the function IDOC_READ_COMPLETELY as demonstrated in the example below:
    DATA: int_edidd TYPE STANDARD TABLE OF edidd WITH HEADER LINE,
           wf_docnum type edidc-docnum.
    MOVE: 'IDOC_NUMBER' to wf_docnum.
    CLEAR int_edidd.
    REFRESH int_edidd.
    CALL FUNCTION 'IDOC_READ_COMPLETELY'
         EXPORTING
              document_number         = wf_docnum
         TABLES
              int_edidd               = int_edidd
         EXCEPTIONS
               document_not_exist      = 1
               document_number_invalid = 2
               OTHERS                  = 3.
       After that call, you can loop through int_edidd to get at the segment information you need.
       You can update the sales order using BAPI_SALESORDER_CHANGE.  Below is an example of updating line 10 of a sales order with a new material number.
    DATA: l_vbeln LIKE bapivbeln-vbeln,
          so_headx TYPE bapisdh1x,
          change_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
          so_item_in TYPE bapisditm OCCURS 0 WITH HEADER LINE,
          so_item_inx TYPE bapisditmx OCCURS 0 WITH HEADER LINE.
    MOVE 'U' TO so_headx-updateflag.
    MOVE <insert sales order number here> to l_vbeln.
    MOVE:  '00010' TO so_item_in-itm_number,
           'MATERIAL_NUMBER' TO so_item_in-material.
    APPEND so_item_in.
    MOVE: '00010' TO so_item_inx-itm_number,
          'U' TO so_item_inx-updateflag,
          'X' TO so_item_inx-material.
    APPEND so_item_inx.
    CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
         EXPORTING
              salesdocument    = l_vbeln
              order_header_inx = so_headx
         TABLES
              return           = change_return
              order_item_in    = so_item_in
              order_item_inx   = so_item_inx.
    Cheers,
    John

  • End User Transaction for Mass Change Sales Orders

    Hello,
    Transaction MASS can be used to change sales orders using object type BUS2032, however, end users are not allowed access to MASS.
    In most other cases, the object types can be accessed by individual transactions, for example, MEMASSPO for BUS2012 and XD99 for KNA1.
    But I cannot seem to find a similar transaction for object type BUS2032, does anyone know whether one exists or how to create such a shortcut.
    Thanks,
    Jake.

    Hi
    See SAP Note 483303 - BUS2032: Only sales orders of category VBAK-VBTYP = 'C'
    Regards
    Eduardo

  • Delete Sales order through BAPI_SALESORDER_CHANGE

    Hoi folks,..
      Can we delete the entire Sales order using BAPI_SALESORDER_CHANGE.  If yes, pls let me know the process?
    Thx

    HI,
    You can try to pass 'D' in the update flag of the header Structure.
    ie.. ORDER_HEADER_INX-UPDATEFLAG = 'D'
    and SALESDOCUMENT = 'The SO# to be deleted'.
    Hope this helps.
    Gary

  • Outbound idoc process for sales order using message control

    Hi All,
        I am changing sales order using VA02 , while saving sales number IDOC is creating but I am unable to see the data filling into segments. I think idoc is triggaring in background.
      Can you please tell how I can see the data filling in to segments
    Thanks in advance,
    SN

    keep the break point in the program RSNAST00
    at this particular code.
    perform (tnapr-ronam) in program (tnapr-pgnam) using returncode
                                                             us_screen
                                                             if found.
    and also Activate update Debugging , before pressing the save button in VA02.

  • Change of open sales order : using BAPI

    Hi
       this  is ravi
                      can any one help me on this  topic
            1)change of open sales order  using BAPI .With appropriate reason( like header level reason)
                       thanks & regards

    hI,
        chk this FM BAPI_SALESORDER_PROXY_UPLOAD how the FM BAPI_SALESORDER_CHANGE was used
    Check this code,
    REPORT Z_SALES_ORDER_CHANGE
    NO STANDARD PAGE HEADING
    LINE-SIZE 132
    LINE-COUNT 65(0)
    MESSAGE-ID ZZ.
    TABLES: VBAP.
    DATA:
    V_FILEIN(90) TYPE C,
    V_RECIN TYPE I,
    V_RECVBAP TYPE I,
    V_RECORDER TYPE I,
    V_VBELN LIKE VBAP-VBELN,
    ORDERHEADERINX LIKE BAPISDH1X.
    DATA: BEGIN OF I_ORDERS OCCURS 0,
    VBELN LIKE VBAK-VBELN,
    POSNR LIKE VBAP-POSNR,
    BRGEW(18) TYPE C,
    VOLUM(18) TYPE C,
    END OF I_ORDERS.
    DATA: BEGIN OF I_OUTPUT OCCURS 0,
    VBELN LIKE VBAK-VBELN,
    POSNR LIKE VBAP-POSNR,
    GEWEI LIKE VBAP-GEWEI,
    BRGEW LIKE VBAP-BRGEW,
    VOLUM LIKE VBAP-VOLUM,
    CKWGT TYPE C,
    CKVOL TYPE C,
    END OF I_OUTPUT.
    DATA: BEGIN OF ORDERITEMIN OCCURS 0.
    INCLUDE STRUCTURE BAPISDITM.
    DATA: END OF ORDERITEMIN.
    DATA: BEGIN OF ORDERITEMINX OCCURS 0.
    INCLUDE STRUCTURE BAPISDITMX.
    DATA: END OF ORDERITEMINX.
    DATA: BEGIN OF RETURN OCCURS 0.
    INCLUDE STRUCTURE BAPIRET2.
    DATA: END OF RETURN.
    DATA: BEGIN OF BAPIRETURN OCCURS 0.
    INCLUDE STRUCTURE BAPIRET2.
    DATA: END OF BAPIRETURN.
    PARAMETERS:
    P_PATH(45) TYPE C DEFAULT '/usr/users/ftpsapom/' LOWER CASE,
    P_FNAME(32) TYPE C DEFAULT '/sweetjo.txt' LOWER CASE.
    START-OF-SELECTION.
    CONCATENATE PATH AND FILE NAME INTO ONE VARIABLE
    CONCATENATE P_PATH P_FNAME INTO V_FILEIN.
    OPEN DATASET
    IF V_FILEIN IS INITIAL.
    MESSAGE E002 WITH 'FILE' V_FILEIN 'DOES NOT CONTAIN ANY DATA!'.
    ELSE.
    OPEN DATASET V_FILEIN
    FOR INPUT
    IN TEXT MODE.
    IF SY-SUBRC = 0.
    READ DATASET
    DO.
    READ DATASET V_FILEIN INTO I_ORDERS.
    IF SY-SUBRC = 0.
    APPEND I_ORDERS.
    ELSE.
    EXIT.
    ENDIF.
    ENDDO.
    CLOSE DATASET
    CLOSE DATASET V_FILEIN.
    IF SY-SUBRC <> 0.
    MESSAGE E002 WITH 'ERROR - CLOSING' V_FILEIN.
    ENDIF.
    ELSE.
    MESSAGE E002 WITH 'ERROR - COULD NOT OPEN' V_FILEIN.
    ENDIF.
    ENDIF.
    SORT AND REMOVE DUPLICATES FROM I_ORDERS
    SORT I_ORDERS BY VBELN POSNR.
    DELETE ADJACENT DUPLICATES FROM I_ORDERS.
    POPULATE I_OUTPUT
    LOOP AT I_ORDERS.
    SHIFT I_ORDERS-POSNR LEFT DELETING LEADING SPACE.
    CONCATENATE '0' I_ORDERS-POSNR INTO I_ORDERS-POSNR.
    SELECT SINGLE BRGEW VOLUM
    FROM VBAP
    INTO (VBAP-BRGEW, VBAP-VOLUM)
    WHERE VBELN = I_ORDERS-VBELN
    AND POSNR = I_ORDERS-POSNR.
    IF SY-SUBRC = 0.
    IF VBAP-BRGEW = 0.
    I_OUTPUT-CKWGT = 'X'.
    ENDIF.
    IF VBAP-VOLUM = 0.
    I_OUTPUT-CKVOL = 'X'.
    ENDIF.
    I_OUTPUT-VBELN = I_ORDERS-VBELN.
    I_OUTPUT-POSNR = I_ORDERS-POSNR.
    I_OUTPUT-GEWEI = 'ST'.
    I_OUTPUT-BRGEW = I_ORDERS-BRGEW.
    I_OUTPUT-VOLUM = I_ORDERS-VOLUM.
    APPEND I_OUTPUT.
    CLEAR: I_OUTPUT.
    ENDIF.
    V_RECIN = V_RECIN + 1.
    ENDLOOP.
    POPULATE BAPI DATA AND RUN BAPI
    CLEAR: ORDERHEADERINX, ORDERITEMIN, ORDERITEMINX,
    RETURN, BAPIRETURN.
    REFRESH: ORDERITEMIN, ORDERITEMINX, RETURN, BAPIRETURN.
    ORDERHEADERINX-UPDATEFLAG = 'U'.
    LOOP AT I_OUTPUT WHERE CKWGT = 'X' OR CKVOL = 'X'.
    V_RECVBAP = V_RECVBAP + 1.
    IF I_OUTPUT-VBELN <> V_VBELN AND SY-TABIX <> 1.
    V_RECORDER = V_RECORDER + 1.
    CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
    EXPORTING
    SALESDOCUMENT = V_VBELN
    ORDER_HEADER_INX = ORDERHEADERINX
    TABLES
    RETURN = RETURN
    ORDER_ITEM_IN = ORDERITEMIN
    ORDER_ITEM_INX = ORDERITEMINX.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
    WAIT = 'X'
    IMPORTING
    RETURN = BAPIRETURN.
    WRITE OUT RETURN
    LOOP AT RETURN.
    WRITE: / RETURN.
    ENDLOOP.
    WRITE: / BAPIRETURN.
    SKIP.
    CLEAR: ORDERITEMIN, ORDERITEMINX,
    RETURN, BAPIRETURN.
    REFRESH: ORDERITEMIN, ORDERITEMINX, RETURN, BAPIRETURN.
    ENDIF.
    ORDERITEMIN-ITM_NUMBER = I_OUTPUT-POSNR.
    ORDERITEMIN-UNTOF_WGHT = I_OUTPUT-GEWEI.
    IF NOT I_OUTPUT-CKWGT IS INITIAL.
    ORDERITEMIN-GROSS_WGHT = I_OUTPUT-BRGEW.
    ORDERITEMINX-GROSS_WGHT = 'X'.
    ENDIF.
    IF NOT I_OUTPUT-CKVOL IS INITIAL.
    ORDERITEMIN-VOLUME = I_OUTPUT-VOLUM.
    ORDERITEMINX-VOLUME = 'X'.
    ENDIF.
    APPEND ORDERITEMIN.
    ORDERITEMINX-ITM_NUMBER = I_OUTPUT-POSNR.
    ORDERITEMINX-UNTOF_WGHT = 'X'.
    ORDERITEMINX-UPDATEFLAG = 'U'.
    APPEND ORDERITEMINX.
    V_VBELN = I_OUTPUT-VBELN.
    ENDLOOP.
    RUN BAPI ON LAST ORDER
    IF NOT ORDERITEMIN IS INITIAL.
    V_RECORDER = V_RECORDER + 1.
    CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
    EXPORTING
    SALESDOCUMENT = V_VBELN
    ORDER_HEADER_INX = ORDERHEADERINX
    TABLES
    RETURN = RETURN
    ORDER_ITEM_IN = ORDERITEMIN
    ORDER_ITEM_INX = ORDERITEMINX.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
    WAIT = 'X'
    IMPORTING
    RETURN = BAPIRETURN.
    WRITE OUT RETURN
    LOOP AT RETURN.
    WRITE: / RETURN.
    ENDLOOP.
    WRITE: / BAPIRETURN.
    SKIP.
    ENDIF.
    WRITE OUT RECORD COUNT FROM FILE
    WRITE: / 'RECORD COUNT FROM FILE ', V_RECIN.
    SKIP.
    WRITE OUT RECORD COUNT FROM FILE
    WRITE: / 'RECORD COUNT OF LINES TO CHANGE ', V_RECVBAP.
    SKIP.
    WRITE OUT RECORD COUNT FROM FILE
    WRITE: / 'RECORD COUNT OF ORDERS TO CHANGE ', V_RECORDER.
    SKIP.
    TOP OF PAGE
    TOP-OF-PAGE.
    WRITE:/1(5) TEXT-H01, 6(8) SY-DATUM MM/DD/YY,
    100(8) TEXT-H02, 126(8) SY-PAGNO.
    WRITE:/1(5) TEXT-H03, 6(8) SY-UZEIT USING EDIT MASK '__:__:__',
    20(77) TEXT-H04,
    100(8) TEXT-H05, 108(25) SY-REPID.
    WRITE:/1(6) TEXT-H06, 8(12) SY-UNAME,
    20(4) TEXT-H07, 25(32) SY-HOST,
    100(13) TEXT-H08, 121(8) SY-SYSID,
    129 '/', 130(3) SY-MANDT.
    ULINE.
    SKIP
    <b>Reward points</b>
    Regards

  • How to Change a Sales Order using BAPI

    Hi All
    How can we change the sales document using BAPI as the requirement is
    --> First we create a Sales order using a BAPI.
    --> If the sales order is changed then we get the changed order information alonge with the old order data in a CSV file.
    here i have the problem that we are uncertain which fields will be changed some times we may get the item changes or some times we may get the quantity changed information and some times the condition type may be changed . So how to handle this ?
    Thanks,
    Chindam

    Hi,
    try this
    DATA: IT_MESSAGE TYPE STANDARD TABLE OF BAPIRET2,
          WA_VBELN TYPE BAPIVBELN-VBELN.
    DATA: WA_BAPIHEAD TYPE BAPISDH1,
          WA_BAPIHEADX TYPE BAPISDH1X,
          WA_HEADDATA TYPE BAPISDH1.
    DATA: I_BAPIITEM TYPE STANDARD TABLE OF BAPISDITM,
          WA_BAPIITEM TYPE BAPISDITM,
            WA_DATA TYPE BAPISDITM,
          I_BAPIITEMX TYPE STANDARD TABLE OF BAPISDITMX,
          WA_BAPIITEMX TYPE BAPISDITMX.
    CHANGE ITEM DATA
    WA_BAPIITEM-ITM_NUMBER =WA_DATA-ITM_NUMBER.
    WA_BAPIITEM-REASON_REJ = WA_DATA-REASON_REJ. "(REASON FOR REJECTION)
    WA_BAPIITEMX-ITM_NUMBER = WA_DATA-ITM_NUMBER. "(ITEM NUMBER)
    WA_BAPIITEMX-UPDATEFLAG = 'X'.
    WA_BAPIITEMX-REASON_REJ = 'X'.
    APPEND WA_BAPIITEM TO I_BAPIITEM.
    APPEND WA_BAPIITEMX TO I_BAPIITEMX.
    TO CHANGE HEADER DATA
    WA_BAPIHEADX-UPDATEFLAG = 'U'.
    WA_BAPIHEADX-DLV_BLOCK = 'X'.
    WA_BAPIHEAD-SALES_ORG = WA_HEADDATA-SALES_ORG. "(COMPANY CODE)
    WA_BAPIHEAD-DLV_BLOCK = WA_HEADDATA-DLV_BLOCK. "(DELIVERY BLOCK)
    WA_VBELN = '0000000168'.
    CALL BAPI AND PASS THE VALUE
    CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
       EXPORTING
         SALESDOCUMENT               = WA_VBELN " (SALES AND DOCUMENT NO)
        ORDER_HEADER_IN             = WA_BAPIHEAD
         ORDER_HEADER_INX           = WA_BAPIHEADX
       TABLES
         RETURN                     = IT_MESSAGE
        ORDER_ITEM_IN               = I_BAPIITEM
        ORDER_ITEM_INX              = I_BAPIITEMX
    CLEAR IT_MESSAGE.

Maybe you are looking for

  • Why is my macbook running slow?

    Hardware Information:           MacBook Pro (13-inch, Mid 2012)           MacBook Pro - model: MacBookPro9,2           1 2.5 GHz Intel Core i5 CPU: 2 cores           4 GB RAM Video Information:           Intel HD Graphics 4000 - VRAM: 1024 MB System

  • No option in project info window for code signing Provising profile.

    Dear Developer forum, I have one issue wth my application regarding provisional Profile. I have installed Distribution certificate.After that I have entered all information regarding distribution provisional profile in program portal I have got provi

  • HT4098 i was charged for an itune i didn't purchase

    I was charged for an itune that I didn't purchase, how do I go about getting a refund? How do I keep this from happening again, this is the second time its happened.

  • Users created in ABAP tool cannot login to Portal

    Hello, I have created a user in abap and assigned them the role SAP_J2EE_ADMIN but cannot login into Portal (Message: User authentication failed) with that user. If I login to portal as J2EE_ADMIN and search for that user I get "No element found." Is

  • Snow Leopard Updates Not Working

    I go to the Software update, it finds the various updates required for my mac, firmware, itunes n all that. I say, install and restart.  A few pop ups open telling me to have at least 25% battery and my computer is going to restart, I confirm them al