Skip to Content
avatar image
Former Member

How to use BAPI_SALESORDER_CHANGE to update custom fields in VBAP

Hi All,

I have added the following two custom fields in VBAK and VBAP tables and i'm trying to use BAPI_SALESORDER_CHANGE to update these custom fields. I have added these fieilds to structures BAPE_VBAP, BAPE_VBAPX, VBAPKOM and VBAPKOMX, BAPE_VBAK, BAPE_VBAKX, VBAKKOM and VBAKKOMX.

When i call the BAPI from my program, it updates the custom fields at header level as well as VBAK table. However, the custom fields at line item level or VBAP table do not get updated. Below is a code snippet from the program. Can anyone please help me with this issue?

ZZACKSTAT TYPE C

ZZACKDATE TYPE DATS


                    ls_ord-updateflag = lc_u.
                    ls_ext-structure = lc_bape_vbak.
                    ls_ext-valuepart1+0(10) = ls_vbak-vbeln.
                    ls_ext-valuepart4+139(1) = lc_3.
                    ls_ext-valuepart4+140(8) = sy-datum.
                    APPEND ls_ext TO lt_ext.
                    CLEAR:ls_ext.
                    ls_ext-structure = lc_bape_vbakx.
                    ls_ext-valuepart1+0(10) = ls_vbak-vbeln.
                    ls_ext-valuepart1+44(1) = lc_x.
                    ls_ext-valuepart1+45(1) = lc_x.
                    APPEND ls_ext TO lt_ext.
                    CLEAR:ls_ext.

                    LOOP AT lt_vbap INTO ls_vbap WHERE vbeln = ls_vbak-vbeln.
                      ls_ext-structure = lc_bape_vbap.
                      ls_ext-valuepart1+0(10) = ls_vbap-vbeln.
                      ls_ext-valuepart1+10(6) = ls_vbap-posnr.
                      ls_ext-valuepart4+227(1) = lc_3.
                      ls_ext-valuepart4+228(8) = sy-datum.

                      APPEND ls_ext TO lt_ext.
                      CLEAR:ls_ext.
                      ls_ext-structure = lc_bape_vbapx.
                      ls_ext-valuepart1+0(10) = ls_vbap-vbeln.
                      ls_ext-valuepart1+10(6) = ls_vbap-posnr.
                      ls_ext-valuepart1+50(1) = lc_x.    
                      ls_ext-valuepart1+51(1) = lc_x.    
                      APPEND ls_ext TO lt_ext.
                      CLEAR:ls_ext.
                      ls_item-itm_number =  ls_vbap-posnr.
                      APPEND ls_item TO lt_item.
                      CLEAR: ls_item.

                      ls_itemx-itm_number = ls_vbap-posnr.
                      ls_itemx-updateflag = lc_u.
                      APPEND ls_itemx TO lt_itemx.
                      CLEAR: ls_itemx, ls_vbap.
                    ENDLOOP.

                    CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
                      EXPORTING
                        salesdocument    = ls_vbak-vbeln
                        order_header_inx = ls_ord
                      TABLES
                        return           = lt_ret
                        order_item_in    = lt_item
                        order_item_inx   = lt_itemx
                        extensionin      = lt_ext.

                    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Jul 31, 2013 at 07:32 AM

    Hello Satbir,

    Please check this and see if you r missing anything while adding the custom fields in the tables.

    http://scn.sap.com/people/kevin.wilson2/blog/2009/09/30/updating-custom-fields-on-vbap-and-vbak-using-bapisalesordercreatefromdat2

    Thanks.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 30, 2013 at 09:16 PM

    Hi Satbir,

    Code structuring looks fine, can you please tell why you are not passing lc_3 and sy-datum in valuepart1 itself?. All values should be passed starting from value part1 and individual fields maximum size be considered which you have already done. Also show how you have appended fields in BAPE_VBAP and BAPE_VBAPX.

    BR.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 31, 2013 at 07:44 AM

    Hi,

    Please check your UPDATE FLAG = 'X'., It should be checked while updating data from bapi...

    BR

    Add comment
    10|10000 characters needed characters exceeded

  • Jul 31, 2013 at 09:24 AM

    You should not code those relative moves to VALUEPARTxx, but fill the actual structure and move it to BAPIPAREX structure.

    In Unicode system, you will be required to use either ASSIGN CASTING or some tool like  cl_abap_container_utilities=>fill_container_c to map the data.

    CLEAR: ls_bapiparex.
    ls_bapiparex-structure = 'BAPI_TE_ZZZZZZ'.
    CALL METHOD cl_abap_container_utilities=>fill_container_c
       EXPORTING
         im_value     = ls_bapi_te_zzzzzz
       IMPORTING
         ex_container = ls_bapiparex+30
       EXCEPTIONS
         OTHERS       = 0.

    Do it for structure and update flag, e.g. BAPE_VBAP and BAPE_VBAPX

    NB: When a BAPI extension use checkboxes structures, ALWAYS give the same name and same number of fields in both structure BAPE_ZZZZ and BAPE_ZZZZX.

    Regards,

    Raymond

    Add comment
    10|10000 characters needed characters exceeded