Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to use BAPI_SALESORDER_CHANGE to update custom fields in VBAP

Former Member
0 Kudos

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'.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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-usin...

Thanks.

8 REPLIES 8

Former Member
0 Kudos

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.

Former Member
0 Kudos

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-usin...

Thanks.

0 Kudos

Hi Ankit/Jaffer,

Thanks for your valuable inputs.

@Ankit - I'm not using valuepart1 because i have other custom fields in VBAP table and when i calculated the offset of the new fields with reference to BAPIPAREX structure, these fields fall in valuepart4 of BAPIPAREX.

The issue was that VBAPKOMX structure had fewer fields when compared to VBAPKOM. I debugged the BAPI and observed that standard code assigns custom fields from VBAPKOM to VBAP based on their position in the structure and hence VBAPKOM and VBAPKOMX should have the exact same fields in the same sequence.

Issue resolved.

0 Kudos

Hi Satbir,

Request you to close the thread.

BR.

0 Kudos

Thanks for the update Satbir. Nice to know ur issue is resolved.

Former Member
0 Kudos

Hi,

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

BR

raymond_giuseppi
Active Contributor
0 Kudos

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

daniel_cunha1
Participant
0 Kudos

Hi,

Exist same function module to edit unit measure in sales order (in se37)?

Best Regards