Professional Documents
Culture Documents
Custom BAPI Creation
Custom BAPI Creation
By Venkat
To create the custom BAPI, we need to follow this step-by-step procedure. The steps are
Step 1: To create BAPI structure, the structure name should start with the keyword ZBAPI. Here, Two BAPI structures are
created in this scenario .The name of these BAPI structures are ZBAPI_IMPORT and ZBAPI_TABLE.
Step 4: Now, define the Remote Enabled Function Module using T-Code SE37 starting with the ZBAPI . Provide the name of
the function module as ZBAPI_DEMO_SD. We must pass the Import and export parameters as value parameters.
Attribute Parameters:
Import Parameters:
Export Parameters:
Return parameter in the Export parameter contains the error messages. Here, we must create a parameter of type structure
BAPIRETURN either in Export Parameter or Table Parameter.
Table Parameters:
Source Parameter:
Step5: Place this Function Module in to BOR using the T-code SWO1. Provide the name of the object and press create
button.
Now, Provide the created Custom Function Module name and click enter.
Our client had a requirement to create customer sales orders using BAPI function module
BAPI_SALESORDER_CREATEFROMDAT2 with using custom fields (ZZ* or YY* fields) which are appended on VBAP table
with using append structure.
We can easily create sales order with using standard fields via BAPI but as per requirement we need to use extension of
BAPI_SALESORDER_CREATEFROMDAT2 for 13 customize fields.
Append ZAVBAP structure in VBAP table with 13 customize fields. Fields must begin with ZZ* or YY* naming .
In BAPI_SALESORDER_CREATEFROMDAT2 we need to use EXTENSIONIN parameter for BAPI extension
You can use this parameter to transfer user-specific enhancements to a BAPI. The customer has to complete the
EXTENSION structure and the system automatically continues processing it. If you have not defined any user-specific fields,
then you can transfer a blank EXTENSIONIN structure. You can use also this extension VBAK, VBAP, VBEP tables.
Because the BAPIs work with checkboxes, you must also define a customize structure (ZABAPE_VBAPX) checkbox for the
customer structure. It should be structured like this
Define these customer structures in the structures VBAPKOZ and VBAPKOZX using INCLUDE or APPEND.
Add the customer structures to the BAPE_VBAP and BAPE_VBAPX BAPI structures using the APPEND technique.
Adjust the following structures for customer enhancements to table VBAP:
a) VBAPKOZ
b) VBAPKOZX
c) BAPE_VBAP
d) BAPE_VBAPX
If you need to use custom fields for VBAK you must adjust the following structures for customer enhancements to table VBAK:
a) VBAKKOZ
b) VBAKKOZX
c) BAPE_VBAK
d) BAPE_VBAKX
If you need to use custom fields for VBEP you must adjust the following structures for customer enhancements to table VBEP:
a) VBEPKOZ
b) VBEPKOZX
c) BAPE_VBEP
d) BAPE_VBEPX
Generally, the data should be added to the BAPI interface in the internal communication structures (VBAKKOM, and so on).
There, you can process the data in the SD tables (VBAK, and so on).
If the EXTENSIONIN parameter contains customer data, you must complete at least the key fields in the relevant standard
parameters.
This is a simple ABAP code how to use extension table with BAPI
ls_order_header_in-doc_type = 'Z001'.
ls_order_header_in-sales_org = '1000'.
ls_order_header_in-distr_chan = '20'.
ls_order_header_in-division = '01'.
ls_order_header_in-sales_off = '0010'.
ls_order_header_in-purch_no_c = '10000001'.
ls_order_header_inx-updateflag = 'I'.
ls_order_header_inx-doc_type = 'X'.
ls_order_header_inx-sales_org = 'X'.
ls_order_header_inx-distr_chan = 'X'.
ls_order_header_inx-division = 'X'.
ls_order_header_inx-sales_off = 'X'.
ls_order_header_inx-purch_no_c = 'X'.
lt_partners-partn_role = 'AG'.
lt_partners-partn_numb = '0000004000'.
append lt_partners.
lt_items_in-itm_number = '000010'.
lt_items_in-material = '000000000300000040'.
lt_items_in-sales_unit = 'ST'.
append lt_items_in.
lt_items_inx-itm_number = '000010'.
lt_items_inx-material = 'X'.
lt_items_inx-sales_unit = 'X'.
append lt_items_inx.
lt_schedules_in-itm_number = '000010'.
lt_schedules_in-sched_line = '0001'.
lt_schedules_in-req_qty = 1000.
lt_schedules_in-req_date = sy-datum.
append lt_schedules_in.
lt_schedules_inx-itm_number = '000010'.
lt_schedules_inx-sched_line = '0001'.
lt_schedules_inx-req_qty = 'X'.
lt_schedules_inx-req_date = 'X'.
append lt_schedules_inx.
lwa_bape_vbap-vbeln = space.
lwa_bape_vbap-posnr = '000010'.
lwa_bape_vbap-zztuketf = 0.
lwa_bape_vbap-zztukets = 0.
lwa_bape_vbap-zzklt1 = '45GRAM'.
lwa_bape_vbap-zzsyf1 = 16.
lwa_bape_vbap-zzklt2 = '49GRAM'.
lwa_bape_vbap-zzsyf2 = 0.
lwa_bape_vbap-zzklt3 = '52GRAM'.
lwa_bape_vbap-zzsyf3 = 0.
lwa_bape_vbap-zz45g = space.
lwa_bape_vbap-zz49g = space.
lwa_bape_vbap-zzsbs = 8.
lwa_bape_vbap-zztss = 8.
lwa_bape_vbap-zzrss = 16.
lwa_bape_vbapx-vbeln = space.
lwa_bape_vbapx-posnr = wa_outtab-posnr.
lwa_bape_vbapx-zztuketf = space.
lwa_bape_vbapx-zztukets = space.
lwa_bape_vbapx-zzklt1 = 'X'.
lwa_bape_vbapx-zzsyf1 = 'X'.
lwa_bape_vbapx-zzklt2 = 'X'.
lwa_bape_vbapx-zzsyf2 = 'X'.
lwa_bape_vbapx-zzklt3 = 'X'.
lwa_bape_vbapx-zzsyf3 = 'X'.
lwa_bape_vbapx-zz45g = 'X'.
lwa_bape_vbapx-zz49g = 'X'.
lwa_bape_vbapx-zzsbs = 'X'.
lwa_bape_vbapx-zztss = 'X'.
lwa_bape_vbapx-zzrss = 'X'.
clear lwa_extensionin.
clear lt_extensionin.