0% found this document useful (0 votes)
170 views

BAPI Enhancement

This document provides code samples for calling two SAP BAPI functions - BAPI_PO_CREATE1 to create a purchase order, and BAPI_SALESORDER_CREATEFROMDAT2 to create a sales order. It includes data declarations and sample data to pass to the functions. The code fills in header, item, schedule, and extension data and calls the BAPIs, then commits the transaction to save the new documents in the SAP system.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
170 views

BAPI Enhancement

This document provides code samples for calling two SAP BAPI functions - BAPI_PO_CREATE1 to create a purchase order, and BAPI_SALESORDER_CREATEFROMDAT2 to create a sales order. It includes data declarations and sample data to pass to the functions. The code fills in header, item, schedule, and extension data and calls the BAPIs, then commits the transaction to save the new documents in the SAP system.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

Figure 9 Code for calling BAPI_PO_CREATE1 BAPI

DATA: LS_BAPIMEPOHEADER like BAPIMEPOHEADER.


DATA: LS_BAPIMEPOHEADERX like BAPIMEPOHEADERX.
DATA: LS_POITEM like BAPIMEPOITEM.
DATA: LT_POITEM like table of BAPIMEPOITEM.
DATA: LS_POITEMX like BAPIMEPOITEMX.
DATA: LT_POITEMX like table of BAPIMEPOITEMX.
DATA: LS_POSCHEDULE like BAPIMEPOSCHEDULE.
DATA: LT_POSCHEDULE like table of BAPIMEPOSCHEDULE.
DATA: LS_POSCHEDULEX like BAPIMEPOSCHEDULX.
DATA: LT_POSCHEDULEX like table of BAPIMEPOSCHEDULX.
DATA: LS_POACCOUNT like BAPIMEPOACCOUNT.
DATA: LT_POACCOUNT like table of BAPIMEPOACCOUNT.
DATA: LS_POACCOUNTX like BAPIMEPOACCOUNTX.
DATA: LT_POACCOUNTX like table of BAPIMEPOACCOUNTX.
DATA: LS_POCOND like BAPIMEPOCOND.
DATA: LT_POCOND like table of BAPIMEPOCOND.
DATA: LS_POCONDX like BAPIMEPOCONDX.
DATA: LT_POCONDX like table of BAPIMEPOCONDX.
DATA: LS_EXTENSIONIN like BAPIPAREX.
DATA: LT_EXTENSIONIN like table of BAPIPAREX.
DATA: LS_BAPIRET2 like table of BAPIRET2.

*you fill purchase order data with sample values that allow
*creation of a purchase order on a standard IDES system
*but you can change those so they will reflect your
*sample purchase orders

*header segment

LS_BAPIMEPOHEADER-COMP_CODE = '1000'.
LS_BAPIMEPOHEADER-DOC_TYPE = 'NB'.
LS_BAPIMEPOHEADER-ITEM_INTVL = '00001'.
LS_BAPIMEPOHEADER-VENDOR = '0000000117'.
LS_BAPIMEPOHEADER-PURCH_ORG = '1000'.
LS_BAPIMEPOHEADER-PUR_GROUP = '025'.
LS_BAPIMEPOHEADER-CURRENCY = 'EUR'.

*for every segment you need to fill a BAPI checkbox segment


*so the BAPI will know which fields are filled/changed

LS_BAPIMEPOHEADERX-COMP_CODE = 'X'.
LS_BAPIMEPOHEADERX-DOC_TYPE = 'X'.
LS_BAPIMEPOHEADERX-ITEM_INTVL = 'X'.
LS_BAPIMEPOHEADERX-VENDOR = 'X'.
LS_BAPIMEPOHEADERX-PURCH_ORG = 'X'.
LS_BAPIMEPOHEADERX-PUR_GROUP = 'X'.

*item segment

LS_POITEM-PO_ITEM = '00001'.
LS_POITEM-MATERIAL = 'DPC1042'.
LS_POITEM-PLANT = '1000'.
LS_POITEM-QUANTITY = '15.000'.
LS_POITEM-BATCH = '0000343455'.
LS_POITEM-VENDRBATCH = '000000000002222'.

append LS_POITEM to LT_POITEM.


LS_POITEMX-PO_ITEM = '00001'.
LS_POITEMX-MATERIAL = 'X'.
LS_POITEMX-PLANT = 'X'.
LS_POITEMX-QUANTITY = 'X'.
LS_POITEMX-BATCH = 'X'.
LS_POITEMX-VENDRBATCH = 'X'.

append LS_POITEMX to LT_POITEMX.

*item schedule lines

LS_POSCHEDULE-PO_ITEM = '00001'.
LS_POSCHEDULE-SCHED_LINE = '0001'.
LS_POSCHEDULE-DELIVERY_DATE = '20.11.2008'.
LS_POSCHEDULE-QUANTITY ='15.000'.

append LS_POSCHEDULE to LT_POSCHEDULE.

LS_POSCHEDULEX-PO_ITEM = '00001'.
LS_POSCHEDULEX-SCHED_LINE = '0001'.
LS_POSCHEDULEX-PO_ITEMX = 'X'.
LS_POSCHEDULEX-SCHED_LINEX = 'X'.
LS_POSCHEDULEX-DELIVERY_DATE = 'X'.
LS_POSCHEDULEX-QUANTITY = 'X'.

append LS_POSCHEDULEX to LT_POSCHEDULEX.

*item account

LS_POACCOUNT-PO_ITEM = '00001'.
LS_POACCOUNT-SERIAL_NO = '01'.
LS_POACCOUNT-QUANTITY = '15.000'.

append LS_POACCOUNT to LT_POACCOUNT.

LS_POACCOUNTX-PO_ITEM = '00001'.
LS_POACCOUNTX-SERIAL_NO = '01'.
LS_POACCOUNTX-QUANTITY = 'X'.

append LS_POACCOUNTX to LT_POACCOUNTX.

*item conditions

LS_POCOND-ITM_NUMBER = '000001'.
LS_POCOND-COND_ST_NO = '001'.
LS_POCOND-CURRENCY = 'EUR'.
LS_POCOND-CURRENCY_ISO = 'EUR'.
LS_POCOND-COND_P_UNT = '1'.
LS_POCOND-CHANGE_ID = 'U'.

append LS_POCOND to LT_POCOND.

LS_POCONDX-ITM_NUMBER = '000001'.
LS_POCONDX-COND_ST_NO = '001'.
LS_POCONDX-ITM_NUMBERX = 'X'.
LS_POCONDX-CURRENCY = 'X'.

append LS_POCONDX to LT_POCONDX.

*extensions
*for header you need to put the name of the structure as BAPI_TE_MEPOHEADER
*and put the values in VALUEPART1
*as PO number ZZPZ since you dont know PO number as you are creating
*then you can give 10 spaces and then put the ZZPZ number

LS_EXTENSIONIN-STRUCTURE = 'BAPI_TE_MEPOHEADER'.
LS_EXTENSIONIN-VALUEPART1 = ' EXTREF007'.

append LS_EXTENSIONIN to LT_EXTENSIONIN.

*the same applies to the checkbox structure


*but instead of putting the value you just need to put
*an X to tell BAPI that this field will be used

LS_EXTENSIONIN-STRUCTURE = 'BAPI_TE_MEPOHEADERX'.
LS_EXTENSIONIN-VALUEPART1 = ' X'.

append LS_EXTENSIONIN to LT_EXTENSIONIN.

*for line you need to put the name of the structure as BAPI_TE_MEPOITEM
*and put the values in VALUEPART1 as
*line number PO number ZZBEDNR and again you can leave
*the PO number empty as you dont know it during creation

LS_EXTENSIONIN-STRUCTURE = 'BAPI_TE_MEPOITEM'.
LS_EXTENSIONIN-VALUEPART1 = '00001 007'.

append LS_EXTENSIONIN to LT_EXTENSIONIN.

*the same applies to the checkbox structure


*but instead of putting the value you jut need to put
*an X to tell BAPI that this field will be used

LS_EXTENSIONIN-STRUCTURE = 'BAPI_TE_MEPOITEMX'.
LS_EXTENSIONIN-VALUEPART1 = '00001 X'.

append LS_EXTENSIONIN to LT_EXTENSIONIN.

*BAPI call if you need to use some other tables to create a document
*you can do that just make sure structure LT_EXTENSIONIN will remain

CALL FUNCTION 'BAPI_PO_CREATE1'


EXPORTING
POHEADER = LS_BAPIMEPOHEADER
POHEADERX = LS_BAPIMEPOHEADERX
* POADDRVENDOR =
* TESTRUN =
* MEMORY_UNCOMPLETE =
* MEMORY_COMPLETE =
* POEXPIMPHEADER =
* POEXPIMPHEADERX =
* VERSIONS =
* NO_MESSAGING =
* NO_MESSAGE_REQ =
* NO_AUTHORITY =
* NO_PRICE_FROM_PO =
* IMPORTING
* EXPPURCHASEORDER =
* EXPHEADER =
* EXPPOEXPIMPHEADER =
TABLES
RETURN = LS_BAPIRET2
POITEM = LT_POITEM
POITEMX = LT_POITEMX
* POADDRDELIVERY =
POSCHEDULE = LT_POSCHEDULE
POSCHEDULEX = LT_POSCHEDULEX
POACCOUNT = LT_POACCOUNT
* POACCOUNTPROFITSEGMENT =
POACCOUNTX = LT_POACCOUNTX
* POCONDHEADER =
* POCONDHEADERX =
* POCOND =
* POCONDX =
* POLIMITS =
* POCONTRACTLIMITS =
* POSERVICES =
* POSRVACCESSVALUES =
* POSERVICESTEXT =
EXTENSIONIN = LT_EXTENSIONIN
* EXTENSIONOUT =
* POEXPIMPITEM =
* POEXPIMPITEMX =
* POTEXTHEADER =
* POTEXTITEM =
* ALLVERSIONS =
* POPARTNER =
* POCOMPONENTS =
* POCOMPONENTSX =
* POSHIPPING =
* POSHIPPINGX =
* POSHIPPINGEXP =
.

*if the call was successful, you can check it by looping


*LS_BAPIRET2 you need to call BAPI COMMIT function so that the
*purchase order will be saved if you dont add that you wont see
*a new document created in transaction ME23N

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'


EXPORTING
WAIT = 'X'
* IMPORTING
* RETURN =
.

Figure 12 Code for calling BAPI_SALESORDER_CREATEFROMDAT2 BAPI

DATA: LS_ORDER_HEADER_IN like BAPISDHD1.


DATA: LS_BAPIRET2 like table of BAPIRET2.
DATA: LV_SALESDOCUMENT LIKE BAPIVBELN-VBELN.
DATA: LS_ORDER_PARTNERS LIKE BAPIPARNR.
DATA: LT_ORDER_PARTNERS LIKE table of BAPIPARNR.
DATA: LS_ORDER_SCHEDULES_IN like BAPISCHDL.
DATA: LT_ORDER_SCHEDULES_IN like table of BAPISCHDL.
DATA: LS_ORDER_ITEMS_IN like BAPISDITM.
DATA: LT_ORDER_ITEMS_IN like table of BAPISDITM.
DATA: LS_EXTENSIONIN like BAPIPAREX.
DATA: LT_EXTENSIONIN like table of BAPIPAREX.
*you fill sales order data with sample values that allow
*creation of a sales order on a standard IDES system
*but you can change those so they will reflect your
*sample sales orders

*header data

LS_ORDER_HEADER_IN-DOC_TYPE = 'TA'.
LS_ORDER_HEADER_IN-SALES_ORG = '0001'.
LS_ORDER_HEADER_IN-DISTR_CHAN = '01'.
LS_ORDER_HEADER_IN-PURCH_DATE = sy-datum.
LS_ORDER_HEADER_IN-DIVISION = '01'.

*item data

LS_ORDER_ITEMS_IN-ITM_NUMBER = '000010'.
LS_ORDER_ITEMS_IN-material = '000000000000000385'.
LS_ORDER_ITEMS_IN-PLANT = '0001'.

append LS_ORDER_ITEMS_IN to LT_ORDER_ITEMS_IN.

*item schedule lines

LS_ORDER_SCHEDULES_IN-ITM_NUMBER = '000010'.
LS_ORDER_SCHEDULES_IN-REQ_QTY = '20'.

append LS_ORDER_SCHEDULES_IN to LT_ORDER_SCHEDULES_IN.

*partner data sold to party

LS_ORDER_PARTNERS-PARTN_ROLE = 'SP'.
LS_ORDER_PARTNERS-PARTN_NUMB = '0000000118'.

append LS_ORDER_PARTNERS to LT_ORDER_PARTNERS.

*partner data ship to party

LS_ORDER_PARTNERS-PARTN_ROLE = 'WE'.
LS_ORDER_PARTNERS-PARTN_NUMB = '0000000118'.

append LS_ORDER_PARTNERS to LT_ORDER_PARTNERS.

*extensions
*for header you need to put the name of the structure as BAPE_VBAP
*and put the values in VALUEPART1
*as SO number SO line ZZKOSTL since you dont know SO number as you are creating
*then you can give 10 spaces and then put the line number and then the ZZKOSTL number

LS_EXTENSIONIN-STRUCTURE = 'BAPE_VBAP'.
LS_EXTENSIONIN-VALUEPART1 = ' 0000109999'.

append LS_EXTENSIONIN to LT_EXTENSIONIN.

*the same applies to the checkbox structure


*but instead of putting the value you just need to put
*an X to tell BAPI that this field will be used

LS_EXTENSIONIN-STRUCTURE = 'BAPE_VBAPX'.
LS_EXTENSIONIN-VALUEPART1 = ' 000010X'.

append LS_EXTENSIONIN to LT_EXTENSIONIN.


*BAPI call if you need to use some other tables to create a document
*you can do that just make sure structure LT_EXTENSIONIN will remain

CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'


EXPORTING
* SALESDOCUMENTIN =
ORDER_HEADER_IN = LS_ORDER_HEADER_IN
* ORDER_HEADER_INX =
* SENDER =
* BINARY_RELATIONSHIPTYPE =
* INT_NUMBER_ASSIGNMENT =
* BEHAVE_WHEN_ERROR =
* LOGIC_SWITCH =
* TESTRUN =
* CONVERT =''
IMPORTING
SALESDOCUMENT = LV_SALESDOCUMENT
TABLES
RETURN = LS_BAPIRET2
ORDER_ITEMS_IN = LT_ORDER_ITEMS_IN
* ORDER_ITEMS_INX =
ORDER_PARTNERS = LT_ORDER_PARTNERS
ORDER_SCHEDULES_IN = LT_ORDER_SCHEDULES_IN
* ORDER_SCHEDULES_INX =
* ORDER_CONDITIONS_IN =
* ORDER_CONDITIONS_INX =
* ORDER_CFGS_REF =
* ORDER_CFGS_INST =
* ORDER_CFGS_PART_OF =
* ORDER_CFGS_VALUE =
* ORDER_CFGS_BLOB =
* ORDER_CFGS_VK =
* ORDER_CFGS_REFINST =
* ORDER_CCARD =
* ORDER_TEXT =
* ORDER_KEYS =
EXTENSIONIN = LT_EXTENSIONIN
* PARTNERADDRESSES =
.

*if the call was successful you can check it by looping


*LS_BAPIRET2 you need to call BAPI COMMIT function so that the
*sales order will be saved if you dont add that you wont see
*a new document created in transaction VA03

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'


EXPORTING
WAIT = 'X'
* IMPORTING
* RETURN =
.

You might also like