09-09-2008 2:47 PM
Hello Experts,
Iu2019m trying to create a PO through u2018BAPI_PO_CREATE1u2019. Iu2019ve gathered all the structure and fields which this bapi needs to create PO. When I call this BAPI in my report program the whole code get execute but I never get any message which tells me that a PO has been created in the system. Can somebody please tell me what is wrong with my code OR am I missing something in it.
For reference here is my code.
===========================================================
REPORT zad_bapi_po_create .
Constant Declaration for BAPI *****************
Data: l_bsart like mepo_topline-bsart value 'NB',
l_bsart1 like mepo_topline-bsart value 'ZNB'.
Constants: c_ekorg like mepo1222-ekorg value 'POMR',
c_ekgrp like mepo1222-ekgrp value 'PG1',
c_bukrs like ekko-bukrs value 'SBPL',
c_x value 'X'.
Internal table Declaration for BAPI *****************
Data:begin of i_tab occurs 0,
verkf like ekko-verkf,
verkf1 like ekko-verkf,
lifnr like ekko-lifnr,
werks like ekpo-werks,
ebelp1 like ekpo-ebelp,
matnr like ekpo-matnr,
idnlf like ekpo-idnlf,
menge(16),
bprme like ekpo-bprme,
lewed like ekpo-lewed,
netpr(13),
currkey(5),
ebeln like eord-ebeln,
ebelp like eord-ebeln,
verkf2 like ekko-verkf,
kalsk like lfm1-kalsk,
bsart like mepo_topline-bsart,
lifnr1 like ekko-lifnr,
flag(1),
pstyp like ekpo-pstyp,
end of i_tab.
Data Declaration for BAPI *****************
DATA: BEGIN OF pohead OCCURS 10.
INCLUDE STRUCTURE bapimepoheader.
DATA: END OF pohead.
DATA: BEGIN OF poheadx OCCURS 10.
INCLUDE STRUCTURE bapimepoheaderx.
DATA: END OF poheadx.
*EXPPURCHASEORDER
DATA: BEGIN OF ponum.
INCLUDE STRUCTURE bapimepoheader.
DATA: END OF ponum.
DATA: BEGIN OF poitem OCCURS 100.
INCLUDE STRUCTURE bapimepoitem.
DATA: END OF poitem.
DATA: BEGIN OF poitemx OCCURS 100.
INCLUDE STRUCTURE bapimepoitemx.
DATA: END OF poitemx.
DATA: BEGIN OF poitemsch OCCURS 100.
INCLUDE STRUCTURE bapimeposchedule.
DATA: END OF poitemsch.
DATA: BEGIN OF poitemschx OCCURS 100.
INCLUDE STRUCTURE bapimeposchedulx.
DATA: END OF poitemschx.
DATA: BEGIN OF errmsg OCCURS 10.
INCLUDE STRUCTURE bapiret2.
DATA: END OF errmsg.
DATA : errflag.
START-OF-SELECTION.
refresh pohead.
refresh poheadx.
clear pohead.
refresh poitem.
refresh poitemx.
pohead-DOC_type = i_tab-bsart.
pohead-vendor = i_tab-lifnr.
pohead-purch_org = c_ekorg.
pohead-creat_date = sy-DATUM.
pohead-pur_group = c_ekgrp.
pohead-comp_code = c_bukrs.
pohead-sales_pers = i_tab-verkf2.
pohead-doc_Date = sy-datum.
pohead-langu = sy-langu.
pohead-currency = 'USDN'.
pohead-item_intvl = ''.
append pohead.
poheadx-doc_type = c_x.
poheadx-vendor = c_x.
poheadx-purch_org = c_x.
poheadx-pur_group = c_x.
poheadx-comp_code = c_x.
poheadx-sales_pers = c_x.
poheadx-item_intvl = c_x.
poheadx-doc_date = c_x.
poheadx-currency = c_x.
poheadx-langu = c_x.
append poheadx.
refresh poitem.
clear poitem.
refresh poitemsch.
clear poitemsch.
refresh poitemschx.
clear poitemschx.
poitem-po_item = '0010'.
poitem-material = '40-210'.
poitem-quantity = '1'.
poitem-po_unit = 'ST'.
poitem-net_price = '1'.
poitem-no_rounding = 'X'.
poitem-plant = '1200'.
poitem-info_upd = ''.
poitem-item_cat = '0'.
poitem-vend_mat = ''.
append poitem.
clear poitemx.
poitemx-po_item = '0010'.
poitemx-MATERIAL = c_x.
poitemx-QUANTITY = c_x.
poitemx-PO_UNIT = c_x.
poitemx-NET_PRICE = c_x.
poitemx-NO_ROUNDING = c_x.
poitemx-PLANT = c_x.
poitemx-GR_TO_DATE = c_x.
poitemx-INFO_UPD = c_x.
poitemx-tax_code = c_x.
poitemx-item_cat = c_x.
POITEMx-ACCTASSCAT = c_x.
poitemx-AGREEMENT = 'X'.
poitemx-AGMT_ITEM = 'X'.
poitemx-VEND_MAT = c_x.
append poitemx.
poitemsch-po_item = '0010'.
poitemsch-sched_line = '0001'.
poitemsch-delivery_date = sy-datum.
poitemsch-quantity = '1'.
append poitemsch.
poitemschx-po_item = '0010'.
poitemschx-sched_line = '0001'.
poitemschx-po_itemx = c_x.
poitemschx-delivery_Date = c_x.
poitemschx-quantity = c_x.
append poitemschx.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = pohead
POHEADERX = poheadx
POADDRVENDOR =
TESTRUN =
MEMORY_UNCOMPLETE =
MEMORY_COMPLETE =
POEXPIMPHEADER =
POEXPIMPHEADERX =
VERSIONS =
NO_MESSAGING =
NO_MESSAGE_REQ =
NO_AUTHORITY =
NO_PRICE_FROM_PO =
IMPORTING
EXPPURCHASEORDER =
EXPHEADER = ponum
EXPPOEXPIMPHEADER =
TABLES
RETURN = errmsg
POITEM = poitem
POITEMX = poitemx
POADDRDELIVERY =
POSCHEDULE = poitemsch
POSCHEDULEX = poitemschx
POACCOUNT =
POACCOUNTPROFITSEGMENT =
POACCOUNTX =
POCONDHEADER =
POCONDHEADERX =
POCOND =
POCONDX =
POLIMITS =
POCONTRACTLIMITS =
POSERVICES =
POSRVACCESSVALUES =
POSERVICESTEXT =
EXTENSIONIN =
EXTENSIONOUT =
POEXPIMPITEM =
POEXPIMPITEMX =
POTEXTHEADER =
POTEXTITEM =
ALLVERSIONS =
POPARTNER =
.
if sy-subrc eq 0.
write:/ 'PO Created successfully!!!'.
else.
write:/ 'Error Occured during PO Creation'.
endif.
===========================================================
Thanks,
09-09-2008 2:57 PM
Bapi's do not set sy-subrc. The only way to check if it was succesfull is to loop into the return table for error messages:
You have to use BAPI_TRANSACTION_COMMIT after calling BAPI_PO_CREATE1:
READ TABLE errmsg TRANSPORTING NO FIELDS
WITH KEY type = c_e.
IF NOT sy-subrc IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = c_x.
ENDIF.
09-09-2008 2:57 PM
Bapi's do not set sy-subrc. The only way to check if it was succesfull is to loop into the return table for error messages:
You have to use BAPI_TRANSACTION_COMMIT after calling BAPI_PO_CREATE1:
READ TABLE errmsg TRANSPORTING NO FIELDS
WITH KEY type = c_e.
IF NOT sy-subrc IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = c_x.
ENDIF.