BAPI INTRODUCTION
BAPI :- Business Application programming Interface
Object oriented
stable interface
function interbally and externally etc..
BAPI is a function module which will be remote enabld
what is the diff b/w RFC and BAPI
concept is same but BAPI deals with business related through BOR but RFC not necesssarily hitting a BOR
BAPI won’t have exceptions
return table will be there – store outcome
structure BAPIRET2
we won’t get sy-subrc value that’s why
SW01 — Business Object repository
testrun = ‘x’ , it will not create a sales order in the system it will simulate the data and later we can confirm with the test run.
BAPI starts with BAPI_ you can find it by going to SE37 and search like that also
SW01 -> f4 -? information system
Hit on SAP application and u can search by modules
Green means BAPI are released and red means they are absolute now
have corresponding structure ending with X
this way SAP would come to know the details u r passing
If there are no error messages in It_return we will do a commit work
commit will be done through a BAPI called
BAPI_transaction_commit
passing parameter wait = ‘X’ means system takes it’s own time while doing the commit work so that everything is correctly placed
Here is a sample program to demonstrate it’s functionality
*&———————————————————————*
*& Report ZTEST_BAPI
*&
*&———————————————————————*
*&
*&
*&———————————————————————*
INCLUDE ZTEST_BAPI_TOP . ” global Data
* INCLUDE ZTEST_BAPI_O01 . ” PBO-Modules
* INCLUDE ZTEST_BAPI_I01 . ” PAI-Modules
INCLUDE ZTEST_BAPI_F01 . ” FORM-Routines
START-OF-SELECTION.
PERFORM get_data.
end-of-SELECTION.
PERFORM f_bapi_call.
*&———————————————————————*
*& Include ZTEST_BAPI_F01
*&———————————————————————*
*&———————————————————————*
*& Form GET_DATA
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM get_data .
wa_order_header_in–doc_type = ‘OR’.
wa_order_header_in–sales_org = ‘0001’.
wa_order_header_in–distr_chan = ’01’.
wa_order_header_in–division = ’01’.
wa_order_header_inx–doc_type = ‘x’.
wa_order_header_inx–sales_org = ‘x’.
wa_order_header_inx–distr_chan = ‘x’.
wa_order_header_inx–division = ‘x’.
wa_order_items_in–itm_number = ‘000010’.
wa_order_items_in–material = ‘WL001’.
wa_order_items_in–target_qty = ’10’.
wa_order_items_in–t_unit_iso = ‘EA’.
wa_order_items_in–item_categ = ‘TAN’.
APPEND wa_order_items_in TO it_order_items_in.
CLEAR : wa_order_items_in.
wa_order_items_inx–itm_number = ‘000010’.
wa_order_items_inx–material = ‘x’.
wa_order_items_inx–target_qty = ‘x’.
wa_order_items_inx–t_unit_iso = ‘x’.
wa_order_items_inx–item_categ = ‘x’.
APPEND wa_order_items_inx–itm_number TO it_order_items_inx.
CLEAR : wa_order_items_inx.
wa_order_partners–partn_role = ‘SH’.
wa_order_partners–partn_numb = ‘0000CUST01’.
* wa_order_partners-name = ‘Federal Mogul’.
* wa_order_partners-street = ‘shiv’.
* wa_order_partners-postl_code = ”.
* wa_order_partners-city = ‘Southfield’.
APPEND wa_order_partners TO it_order_partners.
CLEAR : wa_order_partners.
wa_order_partners–partn_role = ‘SP’.
wa_order_partners–partn_numb = ‘0000CUST01’.
APPEND wa_order_partners TO it_order_partners.
CLEAR : wa_order_partners.
ENDFORM. ” GET_DATA
*&———————————————————————*
*& Form F_BAPI_CALL
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM f_bapi_call .
BREAK-POINT.
CALL FUNCTION ‘BAPI_SALESORDER_CREATEFROMDAT2’
EXPORTING
* SALESDOCUMENTIN =
order_header_in = wa_order_header_in
ORDER_HEADER_INX = wa_order_header_inx
TESTRUN = ‘X’
CONVERT = ‘X’
IMPORTING
SALESDOCUMENT = v_vbeln
tables
RETURN = it_return
ORDER_ITEMS_IN = it_ORDER_ITEMS_IN
ORDER_ITEMS_INX = it_ORDER_ITEMS_INx
order_partners = it_order_partners
.
“If there are no error messages in It_return we will do a commit work
if NOT it_return is INITIAL.
READ TABLE it_return TRANSPORTING NO FIELDS with key type = ‘E’.
if not sy–subrc IS INITIAL.
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
EXPORTING
WAIT = ‘X’
* IMPORTING
* RETURN =
.
ENDIF.
ENDIF.
ENDFORM. ” F_BAPI_CALL
BAPI PART 2
We can create a BAPI , but we don’t create it
we don’t disturb BOR
Why we use BAPI transaction commit
maybe called from non-sap that’s why BAPI_transaction_commit is there
whatever you pass should be in sap internal format
if there is an enhabcement BAPI should take care of that
BAPI is using different standard structures and not the standard tables and structure which is already available beause we want to secure the data which is being passed from BAPI,since standard structures will be used in different situations in a real time environment there are chances that it may went to error so to avoid such a situation we use different standard structures in BAPI
note 143580
every BAPI will have a extension structure to map any custom fields
there maybe more than one extension structures or it may be done through exits and other ways as well
But when you will use these structures, you may need to update certain stuructures, that you need to google it or search in any of the notes if available
and then you need to append the custom field at the table level ( Additional data B in case of VA01 ) and in the structures you are going to pass value through the BAPI
if you have external number range for a sales order
you need to pass it explicitly
if u need to debug a pop up and it is asking for the key…u can debug it
just drag down the code the pop up debugger code on the dialog screen and then it will go to the debugger screen and then go to breakpoints-> breakpoint at -> breakpoint at function module
and give the following function moodule name
tadir_object_check
or else
go to TADIR ( whenever we register an object it gets’s stored in the table TADIR )
Below is how to pass custom fields to the BAPI :- please follow the below process ( Source : letusabap)
1. Go to VBAK : append a structure …add a field ( Test which is of MATNR type ).
2. Identify the VA01 screen to be modified ( screen no. 8309, Program SAPMV45A)
3. open SAPMV45A in SE80 – double click on screen 8309
4. change it : a pop-up appears : drag & drop the pop-up debugger notepad
5. put a break point on FM : TADIR_OBJECT_CHECK
6. modify the screen layout & drag drop the custom field from VBAK
7. Save & activate
8. refer the SAP note 143580
9. Append a new structure in BAPE_VBAK & VBAKKOZ with MATNR type field ( same filed like we have in VBAK, e.g. TEST )
10. Append a new structure in BAPE_VBAKX & VBAKKOZX with FLAG type field ( same field : TEST )
11. come to your SE38 code : pass the values in extension structure & append the same to extension internal table
12. Pass this to BAPI
13. Sales order : WA_EXT-valuepart0(10) will be blank in case of VA01 with internal no. range
14. will not be blank in case of external no. range & VA02
*&———————————————————————*
*& Report ZTEST_BAPI
*&
*&———————————————————————*
*&
*&
*&———————————————————————*
INCLUDE ZTEST_BAPI_TOP . ” global Data
* INCLUDE ZTEST_BAPI_O01 . ” PBO-Modules
* INCLUDE ZTEST_BAPI_I01 . ” PAI-Modules
INCLUDE ZTEST_BAPI_F01 . ” FORM-Routines
START-OF-SELECTION.
PERFORM get_data.
end-of-SELECTION.
PERFORM f_bapi_call.
*&———————————————————————*
*& Form F_BAPI_CALL
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM f_bapi_call .
BREAK-POINT.
CALL FUNCTION ‘BAPI_SALESORDER_CREATEFROMDAT2’
EXPORTING
* SALESDOCUMENTIN =
order_header_in = wa_order_header_in
ORDER_HEADER_INX = wa_order_header_inx
TESTRUN = ‘X’
CONVERT = ‘X’
IMPORTING
SALESDOCUMENT = v_vbeln
tables
RETURN = it_return
ORDER_ITEMS_IN = it_ORDER_ITEMS_IN
ORDER_ITEMS_INX = it_ORDER_ITEMS_INx
order_partners = it_order_partners
extensionin = it_ext.
.
“If there are no error messages in It_return we will do a commit work
if NOT it_return is INITIAL.
READ TABLE it_return TRANSPORTING NO FIELDS with key type = ‘E’.
if not sy–subrc IS INITIAL.
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
EXPORTING
WAIT = ‘X’
* IMPORTING
* RETURN =
.
ENDIF.
ENDIF.
ENDFORM. ” F_BAPI_CALL
*&———————————————————————*
*& Include ZTEST_BAPI_F01
*&———————————————————————*
*&———————————————————————*
*& Form GET_DATA
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM get_data .
wa_order_header_in–doc_type = ‘OR’.
wa_order_header_in–sales_org = ‘0001’.
wa_order_header_in–distr_chan = ’01’.
wa_order_header_in–division = ’01’.
wa_order_header_inx–doc_type = ‘x’.
wa_order_header_inx–sales_org = ‘x’.
wa_order_header_inx–distr_chan = ‘x’.
wa_order_header_inx–division = ‘x’.
wa_order_items_in–itm_number = ‘000010’.
wa_order_items_in–material = ‘WL001’.
wa_order_items_in–target_qty = ’10’.
wa_order_items_in–t_unit_iso = ‘EA’.
wa_order_items_in–item_categ = ‘TAN’.
APPEND wa_order_items_in TO it_order_items_in.
CLEAR : wa_order_items_in.
wa_order_items_inx–itm_number = ‘000010’.
wa_order_items_inx–material = ‘x’.
wa_order_items_inx–target_qty = ‘x’.
wa_order_items_inx–t_unit_iso = ‘x’.
wa_order_items_inx–item_categ = ‘x’.
APPEND wa_order_items_inx–itm_number TO it_order_items_inx.
CLEAR : wa_order_items_inx.
wa_order_partners–partn_role = ‘SH’.
wa_order_partners–partn_numb = ‘0000CUST01’.
* wa_order_partners-name = ‘Federal Mogul’.
* wa_order_partners-street = ‘shiv’.
* wa_order_partners-postl_code = ”.
* wa_order_partners-city = ‘Southfield’.
APPEND wa_order_partners TO it_order_partners.
CLEAR : wa_order_partners.
wa_order_partners–partn_role = ‘SP’.
wa_order_partners–partn_numb = ‘0000CUST01’.
APPEND wa_order_partners TO it_order_partners.
CLEAR : wa_order_partners.
wa_ext–structure = ‘BAPE_VBAK’.
* wa_ext-valuepart1+0(10) = ‘4000000001’.
wa_ext–valuepart1+10(18) = ‘BAPI_TEST’.
APPEND wa_ext to it_ext.
clear wa_ext.
wa_ext–structure = ‘BAPE_VBAKX’.
* wa_ext-valuepart1+0(10) = ‘4000000001’.
wa_ext–valuepart1+10(1) = ‘X’.
APPEND wa_ext to it_ext.
clear wa_ext.
wa_ext–structure = ‘VBAKKOZ’.
* wa_ext-valuepart1+0(10) = ‘4000000001’.
wa_ext–valuepart1+10(18) = ‘BAPI_TEST’.
APPEND wa_ext to it_ext.
clear wa_ext.
wa_ext–structure = ‘VBAKKOZX’.
* wa_ext-valuepart1+0(10) = ‘4000000001’.
wa_ext–valuepart1+10(1) = ‘X’.
APPEND wa_ext to it_ext.
clear wa_ext.
ENDFORM. ” GET_DATA
*&———————————————————————*
*& Form F_BAPI_CALL
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM f_bapi_call .
BREAK-POINT.
CALL FUNCTION ‘BAPI_SALESORDER_CREATEFROMDAT2’
EXPORTING
* SALESDOCUMENTIN =
order_header_in = wa_order_header_in
ORDER_HEADER_INX = wa_order_header_inx
TESTRUN = ‘X’
CONVERT = ‘X’
IMPORTING
SALESDOCUMENT = v_vbeln
tables
RETURN = it_return
ORDER_ITEMS_IN = it_ORDER_ITEMS_IN
ORDER_ITEMS_INX = it_ORDER_ITEMS_INx
order_partners = it_order_partners
extensionin = it_ext.
.
“If there are no error messages in It_return we will do a commit work
if NOT it_return is INITIAL.
READ TABLE it_return TRANSPORTING NO FIELDS with key type = ‘E’.
if not sy–subrc IS INITIAL.
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
EXPORTING
WAIT = ‘X’
* IMPORTING
* RETURN =
.
ENDIF.
ENDIF.
ENDFORM. ” F_BAPI_CALL
*&———————————————————————*
*& Include ZTEST_BAPI_TOP Report ZTEST_BAPI
*&
*&———————————————————————*
REPORT ztest_bapi.
DATA : v_vbeln TYPE bapivbeln–vbeln.
DATA : wa_order_header_in LIKE bapisdhd1,
wa_order_header_inx LIKE bapisdhd1x,
it_return TYPE TABLE OF bapiret2,
wa_return TYPE bapiret2,
it_order_items_in TYPE TABLE OF bapisditm,
wa_order_items_in TYPE bapisditm,
it_order_items_inx TYPE TABLE OF bapisditmx,
wa_order_items_inx TYPE bapisditmx,
it_order_partners TYPE TABLE OF bapiparnr,
wa_order_partners TYPE bapiparnr,
it_ext TYPE TABLE OF BAPIPAREX,
wa_ext TYPE BAPIPAREX.