Updating custom fields on VBAP and VBAK using a BAPI call
User Rating: / 3 PoorBest
Written by Kevin Wilson
Wednesday, 30 September 2009
If you have custom ZZ fields on VBAP and VBAK then you can update these fields using the standard BAPI to create or change the order and update these fields. A lot has been spoken about this but nowhere does it spell out the pitfalls and give you an end-to-end procedure on how to do it. I even found some "SAP Experts - Ask a question" on Search SAP give a complete wrong answer!!! So here is the correct way to do it.
To do so you first need to ensure that the following 5 tables are in synch.
1) VBAP: In your append structure you specify your ZZFIELD with the data type as needed
2) BAPE_VBAP: In the append structure here also add the ZZFIELD with the data type as needed with limitations. No decimals. Try and stick to char characters
3) BAPE_VBAPX: In the append structure add the field ZZFIELD of type BAPIUPDATE
(NOTE: (2) and (3) must have the same number of fields in the same order)
4) VBAPKOZ: In the append structure here also add the ZZFIELD with the data type as needed with limitations. No decimals. Try and stick to char characters
5) VBAPKOZX: In the append structure add the field ZZFIELD of type BAPIUPDATE
(NOTE: (4) and (5) must have the same number of fields in the same order)
Similarly do for VBAK, BAPE_VBAK, BAPE_VBAKX, VBAKKOZ and VBAKKOZX.
Next we get to the code to fill in the structure EXTENSIONIN I will demonstrate how to call the create sales order BAPI with custom fields.
* Local definitions DATA: wa_extensionin TYPE bapiparex, wa_bape_vbap TYPE bape_vbap, wa_bape_vbapx TYPE bape_vbapx, wa_bape_vbak TYPE bape_vbak, wa_bape_vbakx TYPE bape_vbakx, lv_posnr TYPE posnr.
* Then the call to the BAPI CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2' EXPORTING order_header_in = ls_order_header_in order_header_inx = ls_order_header_inx IMPORTING salesdocument = lv_salesdocument TABLES return = lt_ret2 order_items_in = lt_order_items_in order_items_inx = lt_order_items_inx order_partners = lt_order_partners order_keys = lt_order_keys extensionin = lt_extensionin.
Note: If you have a need to force a different Business Object type or wish to see the extension return fields then use the function SD_SALESDOCUMENT_CREATE instead.
There were quite a few documents and help pointing out how to do this but none putting it all together in one document and setting you on your way. You can say that no more. Enjoy!!!