You are on page 1of 7

Bapi extension

extensionin --> used for passing data to additional fields through


BAPI

extensionout --> used for reading data related to additional


fields through BAPI

Example: Create Purchase order using standard bapi


‘BAPI_PO_CREATE1’ without considering ‘EXTENSIONIN’ parameter

REPORT Z1030BAPI11.

* prepare PO header data


data wa_poheader type BAPIMEPOHEADER.
wa_poheader-COMP_CODE = '1000'.
wa_poheader-DOC_TYPE = 'NB'.
wa_poheader-VENDOR = '0000001000'.
wa_poheader-PURCH_ORG = '1000'.
wa_poheader-PUR_GROUP = '001'.

* set indicators for PO header data fields


data wa_poheaderx type BAPIMEPOHEADERX.
wa_poheaderx-COMP_CODE = 'X'.
wa_poheaderx-DOC_TYPE = 'X'.
wa_poheaderx-VENDOR = 'X'.
wa_poheaderx-PURCH_ORG = 'X'.
wa_poheaderx-PUR_GROUP = 'X'.

* Prepare PO Item data


data : t_poitems type table of BAPIMEPOITEM,
wa_poitems type BAPIMEPOITEM.

clear wa_poitems.
wa_poitems-PO_ITEM = '00001'.
wa_poitems-MATERIAL = '100-100'.
wa_poitems-PLANT = '1000'.
wa_poitems-STGE_LOC = '0001'.
wa_poitems-QUANTITY = '15.000'.
append wa_poitems to t_poitems.

* Set indicators PO Item data


data : t_poitemsx type table of BAPIMEPOITEMX,
wa_poitemsx type BAPIMEPOITEMX.

clear wa_poitemsx.
wa_poitemsx-PO_ITEM = '00001'.
wa_poitemsx-MATERIAL = 'X'.
wa_poitemsx-PLANT = 'X'.
wa_poitemsx-STGE_LOC = 'X'.
wa_poitemsx-QUANTITY = 'X'.
append wa_poitemsx to t_poitemsx.

data v_ponum type BAPIMEPOHEADER-PO_NUMBER.

data : t_return type table of BAPIRET2,


wa_return type BAPIRET2.

CALL FUNCTION 'BAPI_PO_CREATE1'


EXPORTING
POHEADER = wa_poheader
POHEADERX = wa_poheaderx
IMPORTING
EXPPURCHASEORDER = v_ponum
TABLES
RETURN = t_return
POITEM = t_poitems
POITEMX = t_poitemsx.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

write :/ 'Generated PO number is ',v_ponum.

format color 3.
loop at t_return into wa_return.
write :/ 'Type .....',wa_return-type,
/ 'Message ...',wa_return-message.
endloop.

Example: Create Purchase order using standard bapi


‘BAPI_PO_CREATE1’ considering ‘EXTENSIONIN’ parameter

Procedure:

1. Add the customer specific fields in the header table

Header table: EKKO

Include structure: CI_EKKODB

Custom Fields:

zzcompname zcompname char 20

zzcompaddr zcompaddr char 20


2. Add the customer specific fields in the DEPENDENT structure
‘BAPI_TE_MEPOHEADERX’ as update flag fields.

Program:

REPORT Z1030BAPI13.

* prepare PO header data


data wa_poheader type BAPIMEPOHEADER.
wa_poheader-COMP_CODE = '1000'.
wa_poheader-DOC_TYPE = 'NB'.
wa_poheader-VENDOR = '0000001000'.
wa_poheader-PURCH_ORG = '1000'.
wa_poheader-PUR_GROUP = '001'.

* set indicators for PO header data fields


data wa_poheaderx type BAPIMEPOHEADERX.
wa_poheaderx-COMP_CODE = 'X'.
wa_poheaderx-DOC_TYPE = 'X'.
wa_poheaderx-VENDOR = 'X'.
wa_poheaderx-PURCH_ORG = 'X'.
wa_poheaderx-PUR_GROUP = 'X'.
* Prepare PO Item data
data : t_poitems type table of BAPIMEPOITEM,
wa_poitems type BAPIMEPOITEM.

clear wa_poitems.
wa_poitems-PO_ITEM = '00001'.
wa_poitems-MATERIAL = '100-100'.
wa_poitems-PLANT = '1000'.
wa_poitems-STGE_LOC = '0001'.
wa_poitems-QUANTITY = '15.000'.
append wa_poitems to t_poitems.

* Set indicators PO Item data


data : t_poitemsx type table of BAPIMEPOITEMX,
wa_poitemsx type BAPIMEPOITEMX.

clear wa_poitemsx.
wa_poitemsx-PO_ITEM = '00001'.
wa_poitemsx-MATERIAL = 'X'.
wa_poitemsx-PLANT = 'X'.
wa_poitemsx-STGE_LOC = 'X'.
wa_poitemsx-QUANTITY = 'X'.
append wa_poitemsx to t_poitemsx.

data v_ponum type BAPIMEPOHEADER-PO_NUMBER.

data : t_return type table of BAPIRET2,


wa_return type BAPIRET2.

* Prepare data for customer specific fields


data : t_extin type table of BAPIPAREX,
wa_extin type BAPIPAREX.

data wa_mepoheader type BAPI_TE_MEPOHEADER.


clear wa_mepoheader.
wa_mepoheader-zzcompname = 'ABC Technologies'.
wa_mepoheader-zzcompaddr = 'Hyderabad'.

clear wa_extin.
wa_extin-structure = 'BAPI_TE_MEPOHEADER'.
wa_extin-valuepart1 = wa_mepoheader.
append wa_extin to t_extin.

data wa_mepoheaderx type BAPI_TE_MEPOHEADERX.


clear wa_mepoheaderx.
wa_mepoheaderx-zzcompname = 'X'.
wa_mepoheaderx-zzcompaddr = 'X'.

clear wa_extin.
wa_extin-structure = 'BAPI_TE_MEPOHEADERX'.
wa_extin-valuepart1 = wa_mepoheaderx.
append wa_extin to t_extin.

CALL FUNCTION 'BAPI_PO_CREATE1'


EXPORTING
POHEADER = wa_poheader
POHEADERX = wa_poheaderx
IMPORTING
EXPPURCHASEORDER = v_ponum
TABLES
RETURN = t_return
POITEM = t_poitems
POITEMX = t_poitemsx
EXTENSIONIN = t_extin.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

write :/ 'Generated PO number is ',v_ponum.

format color 3.
loop at t_return into wa_return.
write :/ 'Type .....',wa_return-type,
/ 'Message ...',wa_return-message.
endloop.

Example: Display Purchase order using standard bapi


‘BAPI_PO_GETDETAIL1’ without considering ‘EXTENSIONOUT’
parameter

REPORT Z1030BAPI14.

data v_ponum type BAPIMEPOHEADER-PO_NUMBER value '4500017953'.

data wa_poheader type BAPIMEPOHEADER.

data : t_return type table of BAPIRET2,


wa_return type BAPIRET2.

CALL FUNCTION 'BAPI_PO_GETDETAIL1'


EXPORTING
PURCHASEORDER = v_ponum
IMPORTING
POHEADER = wa_poheader
TABLES
RETURN = t_return.

format color 3.
write :/ 'BAPI Execution status ...'.
loop at t_return into wa_return.
write :/ 'Type :',wa_return-type,
/ 'Message :',wa_return-message.
endloop.
format color off.

uline.
format color 7.
write :/ 'PO Header data...'.
write :/ 'Po Number :',wa_poheader-po_number,
/ 'Company Code :',wa_poheader-comp_code,
/ 'Document Type :',wa_poheader-doc_type.
format color off.

Example: Display Purchase order using standard bapi


‘BAPI_PO_GETDETAIL1’ considering ‘EXTENSIONOUT’ parameter

REPORT Z1030BAPI15.

data v_ponum type BAPIMEPOHEADER-PO_NUMBER value '4500017953'.

data wa_poheader type BAPIMEPOHEADER.

data : t_return type table of BAPIRET2,


wa_return type BAPIRET2.

data : t_extout type table of BAPIPAREX,


wa_extout type BAPIPAREX.

CALL FUNCTION 'BAPI_PO_GETDETAIL1'


EXPORTING
PURCHASEORDER = v_ponum
IMPORTING
POHEADER = wa_poheader
TABLES
RETURN = t_return
EXTENSIONOUT = t_extout.

format color 3.
write :/ 'BAPI Execution status ...'.
loop at t_return into wa_return.
write :/ 'Type :',wa_return-type,
/ 'Message :',wa_return-message.
endloop.
format color off.

uline.
format color 7.
write :/ 'PO Header data...'.
write :/ 'Po Number :',wa_poheader-po_number,
/ 'Company Code :',wa_poheader-comp_code,
/ 'Document Type :',wa_poheader-doc_type.
format color off.
uline.
format color 2.
data wa_po_te_header type bapi_te_mepoheader.
write :/ 'Customer specific fields added in PO Header data...'.
*loop at t_extout into wa_extout where structure = 'BAPI_TE_MEPOHEADER
'..
* wa_po_te_header = wa_extout-valuepart1.
*endloop. "(or)

clear wa_extout.
read table t_extout into wa_extout with key structure = 'BAPI_TE_MEPOH
EADER'.
if sy-subrc eq 0.
wa_po_te_header = wa_extout-valuepart1.
write :/ 'Competitor name :',wa_po_te_header-zzcompname,
/ 'Competitor addr :',wa_po_te_header-zzcompaddr.
endif.

You might also like