Skip to Content
avatar image
Former Member

BAPI_SALESORDER_CHANGE to change quantity

Hi,

I use the BAPI BAPI_SALESORDER_CHANGE to change the quantity of items. BAPI returns these messages :

ORDER_HEADER_IN has been processed successfully

ITEM_IN has been processed successfully

Returns 61665291 has been saved

After that I call the BAPI_TRANSACTION_COMMIT to commit process.

But sales order doesn't change. I can see in tcode va03.

What can I do to change correctly?

Source Code :

order_header_inxc-updateflag = 'U'.

order_items_in-itm_number = itab-posnr.

order_items_inx-itm_number = itab-posnr.

order_items_inx-target_qty = 'X'.

order_items_in-target_qty = my_value.

order_items_inx-updateflag = 'U'.

APPEND order_items_in.

APPEND order_items_inx.

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'

EXPORTING

salesdocument = my_vbeln

order_header_in = order_header_inc

order_header_inx = order_header_inxc

TABLES

order_item_in = order_items_in

order_item_inx = order_items_inx

return = return3.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • avatar image
    Former Member
    Feb 06, 2009 at 03:44 AM

    Hi

    you need to change the item quantity from the schedule line layer. try to fill two more parameters of the BAPI: SCHEDULE_LINES and SCHEDULE_LINESX.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 06, 2009 at 03:54 AM

    You need to update req_qty field for the line item in the schedule lines also.

    ls_schedule_lines_x-itm_number = '000010'.

    ls_schedule_lines_x-sched_line = '0003'.

    ls_schedule_lines_x-updateflag = 'U'.

    ls_schedule_lines_x-req_qty = 'X'.

    Hope this helps...

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 06, 2009 at 03:58 AM

    hi

    plz refer to this thread

    bapisalesorderchange-doesnt-change-quantity

    hope this helps

    regards

    Aakash Banga

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 23, 2013 at 02:05 PM

    hello Hulya Cetin,

    Help me out of this issue I had writeen following program the quantity and netprice are  updating in internal  vbap table and it is showing message data is saved and the sales order number is not updating in va03 tcode  plz check this program

    REPORT NO STANDARD PAGE HEADING.
    TYPE-POOLS : slis.
    ********************************************DECLARATION OF STRUCTUR**************************************************************************
    TYPES: BEGIN OF ty_vbap,
           vbeln TYPE vbeln_va,
           posnr type posnr_va,
           matnr TYPE matnr,
           werks TYPE werks_ext,
           kwmeng TYPE kwmeng,
           zieme TYPE dzieme,
           netwr TYPE netwr_ap,
           waerk TYPE waerk,
           netpr TYPE netpr,
           flag(1),       "to change any output parameters in o/p screen
          END OF ty_vbap.

    *TYPES : BEGIN OF ty_vbap2,
    *       kwmeng TYPE kwmeng,
    *       netwr TYPE netwr_ap,
    *       netpr TYPE netpr,
    *  END OF ty_vbap2.
                                         "ITM_NUMBER  POSNR_VA ,SCHED_LINE ETENR, REQ_DATE    EDATU
      types: begin of ty_vbep,
            vbeln type vbeln_va,        "Sales Document
            posnr type posnr_va,         "Sales Document Item
            ETENR type ETENR,            "Delivery Schedule Line Number
            EDATU type EDATU,            "Schedule line date
            BMENG type BMENG,            "Confirmed Quantity
            CMENG  type CMENG,           "Corrected quantity in sales unit
            BNFPO type BNFPO,            "Item Number of Purchase Requisition
            AUFNR type AUFNR,           "Order Number
        end of ty_vbep.
    **********************************************************************************************************************************************
    ***************************************INTENAL TABLE AND WORK AREA DCLARATION*******************************************************************************************************
    DATA : it_vbap TYPE TABLE OF ty_vbap,
           wa_vbap TYPE ty_vbap,
           v1 TYPE vbap-vbeln,                       "selection screen vbeln
    *       IT1 TYPE TABLE OF VBAP,
    *       WA1 TYPE VBAP,
    *
    *     it_vbap2 TYPE TABLE OF ty_vbap2,
    *     wa_vbap2 TYPE ty_vbap2,
         it_vbep type table of ty_vbep,
          wa_vbep type ty_vbep.
    *        kwmeng type vbap-kwmeng."seLECTION SCREEN VBELN
    DATA :itf TYPE slis_t_fieldcat_alv,
          waf TYPE slis_fieldcat_alv,
          was TYPE slis_fieldcat_alv.


    DATA : wa_head TYPE bapisdh1,
          wa_headx TYPE bapisdh1x,
          wa_return TYPE bapiret2,
          it_return TYPE STANDARD TABLE OF bapiret2,
          wa_item TYPE bapisditm,
          it_item TYPE STANDARD TABLE OF bapisditm,
          wa_itemx TYPE bapisditmx,
          it_itemx TYPE STANDARD TABLE OF bapisditmx,
          wa_schd TYPE bapischdl,
          it_schd TYPE STANDARD TABLE OF bapischdl,
          wa_schdx TYPE bapischdlx,
          it_schdx TYPE STANDARD TABLE OF bapischdlx.


    TYPES : BEGIN OF TY_V.
            INCLUDE STRUCTURE vbap.
            TYPES flag(1).
            TYPES: END OF ty_v.


    DATA: IT_V TYPE TABLE OF ty_v,
          WA_V TYPE ty_v.

    *types: begin of ty_v1.
    *        include structure vbep.
    *        types flag(1).
    *        types : end of ty_v1.
    *data : it1_v type table of ty_v1,
    *      wa_v1 type ty_v1.

    ********************************************************************************************************************************************************
    ************************************SELECTION SCREEN DECLARATION********************************************************************************************************************
    SELECTION-SCREEN BEGIN OF BLOCK a1 WITH FRAME TITLE text-001.
    SELECT-OPTIONS sales   FOR v1  NO-EXTENSION NO INTERVALS  .
    *SELECT-OPTIONS quantity   FOR kwmeng  NO-EXTENSION NO INTERVALS OBLIGATORY.

    PARAMETERS:display  RADIOBUTTON GROUP g1,
               edit  RADIOBUTTON GROUP g1.
    SELECTION-SCREEN END OF BLOCK a1.
    ********************************************************************************************************************************************************

    AT SELECTION-SCREEN.
      IF sales IS  NOT INITIAL.
        SELECT  SINGLE vbeln FROM VBAP INTO WA_V WHERE vbeln IN sales  .
        IF sy-subrc NE 0.
          MESSAGE 'invalid entrty' TYPE 'E'.
        ENDIF.
      ELSE .
        MESSAGE 'invalid entrty' TYPE 'E'.
      ENDIF.
    *****************************************************************************************************************
    START-OF-SELECTION.
    *IF NOT SALES IS INITIAL.
    *  SELECT  * FROM zmat_azh INTO TABLE it_vbap WHERE vbeln IN sales  .
    SELECT  VBELN POSNR MATNR KWMENG ZIEME NETWR WAERK WERKS NETPR FROM VBAP  into CORRESPONDING FIELDS OF TABLE  it_V WHERE vbeln IN sales  .
    select vbeln posnr  etenr EDATU BMENG CMENG BNFPO  AUFNR from vbep INTO TABLE it_vbep
                                                             FOR ALL ENTRIES IN IT_V
                                                             where vbeln = IT_V-VBELN.
    *  ENDIF.

    ***********************************START OF SUBROUTINE*********************************************************************************************************************

      IF display = 'X'.

        PERFORM azhar USING '1' 'MATNR' 'Material Number' ' '.
        PERFORM azhar USING '2' 'VBELN' 'Sales and Distribution Document Number' ' ' .
        PERFORM azhar USING '3' 'WERKS' 'Plant (Own or External)' ' '.
        PERFORM azhar USING '4' 'KWMENG' 'Cumulative Order Quantity in Sales Units' ' ' .
        PERFORM azhar USING '5' 'ZIEME' 'Target quantity UoM' ' '.
        PERFORM azhar USING '6' 'NETWR' 'Net Value in Document Currency' ' ' .
        PERFORM azhar USING '7' 'WAERK' 'SD Document Currency' ' '.
        PERFORM azhar USING '8' 'NETPR' 'Net price' ' '.

        CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING

            i_callback_program                = sy-cprog
           i_grid_title                      = 'SALES ORDER DETAILS'
            it_fieldcat                       = itf
    *
           TABLES
             t_outtab                          = it_v
          EXCEPTIONS
            program_error                     = 1
            OTHERS                            = 2
                   .

      ELSE.
        PERFORM azhar1 USING '1' 'MATNR' 'Material Number' ' '.
        PERFORM azhar1 USING '2' 'VBELN' 'Sales and Distribution Document Number' ' ' .
        PERFORM azhar1 USING '3' 'WERKS' 'Plant (Own or External)' ' '.
        PERFORM azhar1 USING '4' 'KWMENG' 'Cumulative Order Quantity in Sales Units' 'X' .
        PERFORM azhar1 USING '5' 'ZIEME' 'Target quantity UoM' ' '.
        PERFORM azhar1 USING '6' 'NETWR' 'Net Value in Document Currency' ' ' .
        PERFORM azhar1 USING '7' 'WAERK' 'SD Document Currency' ' '.
        PERFORM azhar1 USING '8' 'NETPR' 'Net price' ' '.

        PERFORM edit.
      ENDIF.



    *&---------------------------------------------------------------------*
    *&      Form  AZHAR
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->VALUE      text
    *      -->(P_0103)   text
    *      -->VALUE      text
    *      -->(P_0104)   text
    *      -->VALUE      text
    *      -->(P_0105)   text
    *      -->VALUE      text
    *      -->(P_0106)   text
    *----------------------------------------------------------------------*
    FORM azhar  USING    value(p_0103)
                         value(p_0104)
                         value(p_0105)
                         value(p_0106).
      waf-col_pos = p_0103.
      waf-fieldname = p_0104.
      waf-seltext_l = p_0105.
      waf-edit      = p_0106.
      APPEND waf TO itf.
      CLEAR waf.
    ENDFORM.                    "AZHAR

    *&---------------------------------------------------------------------*
    *&      Form  AZHAR1
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->VALUE      text
    *      -->(P_0107)   text
    *      -->VALUE      text
    *      -->(P_0108)   text
    *      -->VALUE      text
    *      -->(P_0109)   text
    *      -->VALUE      text
    *      -->(P_0110)   text
    *----------------------------------------------------------------------*
    FORM azhar1  USING    value(p_0107)
                         value(p_0108)
                         value(p_0109)
                         value(p_0110).
      was-col_pos = p_0107.
      was-fieldname = p_0108.
      was-seltext_l = p_0109.
      was-edit      = p_0110.
      APPEND was TO itf.
      CLEAR was.
    ENDFORM.                    "AZHAR1

    *&---------------------------------------------------------------------*
    *&      Form  EDIT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    FORM edit.
      DATA:   is_layout TYPE  slis_layout_alv,
          exit_user TYPE slis_exit_by_user.



      is_layout-box_fieldname = 'FLAG'.

      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

      EXPORTING

         i_callback_program                = sy-cprog
         i_callback_pf_status_set          = 'ZPF'
         i_callback_user_command           = 'ZFORM1'
         i_structure_name                  = 'ZMAT_AZH'
         i_grid_title                      = 'SALES ORDER DETAILS'
         is_layout                         = is_layout "          DECLARED
         it_fieldcat                       = itf
         i_save                            = 'X'

    *   IMPORTING
    *     ES_EXIT_CAUSED_BY_USER            = EXIT_USER
        TABLES
          t_outtab                          = it_v.
      IF sy-subrc <> 0.
      ENDIF.
    ENDFORM.                    "EDIT

    *&---------------------------------------------------------------------*
    *&      Form  ZPF
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM zpf USING it_extab TYPE slis_t_extab.
      SET PF-STATUS 'PF_STATUS' EXCLUDING it_extab.
    ENDFORM.                    " ZPF
    *--------------------------------------------------------------------*
    *&      Form  ZFORM1
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM zform1 USING v_ucomm TYPE sy-ucomm
                      v_selfld TYPE slis_selfield.
      DATA ref1 TYPE REF TO cl_gui_alv_grid.

      CASE v_ucomm.
        WHEN 'CHANGE'.
          CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' "ADD
          IMPORTING "AAAA
                e_grid = ref1."AAAAAAAAAA
          CALL METHOD ref1->check_changed_data."AA
    *    READ TABLE IT_VBAP INTO WA_VBAP INDEX V_SELFLD-TABINDEX.
    *    IF SY-SUBRC = 0.
          LOOP AT it_v INTO wa_v WHERE flag = 'X'.
    *      WA_VBAP-KWMENG = V_SELFLD-VALUE.
            wa_v-netwr = wa_v-netpr * wa_v-kwmeng.
            MODIFY  TABLE it_v FROM wa_v ."TRANSPORTING KWMENG NETWR.

          ENDLOOP.


          PERFORM edit.
          v_selfld-refresh = 'X'.
          v_selfld-exit = 'X'.
          " ZFORM1
        WHEN 'SAVE'.

    *MODIFY vbap FROM TABLE  IT_VBAP.
    *
    *if sy-subrc = 0.
    *  MESSAGE 'data saved' TYPE 'S'.
    *  ENDIF.

          LOOP AT it_v INTO wa_v.
            read table it_vbep  into wa_vbep with key vbeln = wa_v-vbeln.
            wa_head-collect_no = wa_vBEP-vbeln.
            wa_headx-updateflag = 'U'.
            WA_ITEM-ITM_NUMBER = WA_VBEP-POSNR.
            wa_item-ref_doc = wa_vBEP-vbeln.
            wa_item-material = wa_v-matnr.
            wa_item-target_qty = wa_v-kwmeng.
            wa_item-target_qu  = wa_v-zieme.                "ITM_NUMBER  POSNR_VA ,SCHED_LINE ETENR, REQ_DATE    EDATU

            APPEND wa_item TO it_item.
            CLEAR wa_item.

            wa_itemx-updateflag = 'U'.
            WA_ITEM-ITM_NUMBER = 'X'.
            wa_item-ref_doc = 'X'.
            wa_itemx-material ='X'.
            wa_itemx-target_qty = 'X'.
            wa_item-target_qu  = 'X'.
            APPEND wa_itemx TO it_itemx.
            CLEAR wa_itemx.

            wa_schd-sched_line = wa_vbep-etenr .
            wa_schd-req_qty = wa_V-kwmeng.
            APPEND wa_schd TO it_schd.
            CLEAR wa_schd.

            wa_schdx-updateflag = 'U'.
            wa_schdx-sched_line = 'X'.
            wa_schdx-req_qty = 'X'.
            APPEND wa_schdx TO it_schdx.
            CLEAR wa_schdx.

          ENDLOOP.
          PERFORM bapi.
    **

        WHEN 'PRINT'.
          CALL FUNCTION '/1BCDWB/SF00000533'
            TABLES
              it_vbap = it_v.

      ENDCASE.

    ENDFORM.                    "ZFORM1
    *&---------------------------------------------------------------------*
    *&      Form  BAPI
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*


    FORM bapi .


      CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
        EXPORTING
          salesdocument         = wa_vbep-vbeln
          order_header_in       = wa_head
          order_header_inx      = wa_headx
    *     SIMULATION            =
    *     BEHAVE_WHEN_ERROR     = ' '
    *     INT_NUMBER_ASSIGNMENT = ' '
    *     LOGIC_SWITCH          =
    *     NO_STATUS_BUF_INIT    = ' '
        TABLES
          return                = it_return
          order_item_in         = it_item
          order_item_inx        = it_itemx
    *     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        = it_schd
          schedule_linesx       = it_schdx
    *     ORDER_TEXT            =
    *     ORDER_KEYS            =
    *     CONDITIONS_IN         =
    *     CONDITIONS_INX        =
    *     EXTENSIONIN           =

        .

    if sy-subrc = 0.
      MESSAGE 'data saved' TYPE 'S'.
      ENDIF.

      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
       EXPORTING
         wait          = 'X'
    * IMPORTING
    *   RETURN        = IT_RETURN
                .

    ENDFORM.    " BAPI

    Add comment
    10|10000 characters needed characters exceeded