Friday, June 17, 2005

Create a purchase order with configuration using the BAPI

This took some time to figure out how to setup. It may be useful.

call function 'BAPI_CFG_CREATE'
exporting
object_id = 'MYMATCODE'
root_type = 'MARA'
root_name = 'MYMATCODE'
plant = 'MYPLANT'
importing
cfg_handle = l_handle
root_instance = l_instance
exceptions
error = 1
others = 2.


l_characts_vals-atnam = 'WIDTH'.
l_characts_vals-atwtb = '500'.

append l_characts_vals to it_characts_vals.

call function 'BAPI_CFGINST_CHARCS_VALS_SET'
exporting
object_id = 'MYMATCODE'
instance = l_instance
tables
characts_vals = it_characts_vals
characts_vals_err = it_characts_vals_err.

call function 'CE_C_SET_CBASE'.

...
l_poitem-int_obj_no = l_handle.
...

call function 'BAPI_PO_CREATE1'
exporting
poheader = l_poheader
poheaderx = l_poheaderx
importing
expheader = l_expheader
exppurchaseorder = l_exppurchaseorder
tables
poitem = lt_poitem
poitemx = lt_poitemx
poschedule = lt_poschedule
poschedulex = lt_poschedulex
return = lt_return.


call function 'BAPI_TRANSACTION_COMMIT'.

Labels: