Skip to Content
0
Apr 20, 2014 at 06:30 AM

Create Purchase Order With bapi_po_create1

918 Views

Hi, I Am Creating Purchase Order With bapi_po_create1. However I am getting some error..

1. type : E

id : BAPI

number : 001

description : no instance of object type purchaseorder has been created , External reference

2 type : E

id : MEPO

number : 000

description : Puchase Order Still Contain Faulty items.

3 type : E

id : Me

number : 082

description : Material Group 0001c Not Defined (please check Your input)

4. type : E

id : v1

number : 302

description : SD document not in databse or has been archived.

I also tried To Create PO Through ME21N , With Similar Type of Data. There is not Problem in That.

**************************************************************Code************************************************************

TABLES: bapimepoheader,

bapimepoheaderx,

bapimepoitem,

bapimepoitemx,

bapimeposchedule,

bapimeposchedulx,

bapimepoaccount,

bapimepoaccountx,

bapiret2.

TYPES: BEGIN OF ty_porder,

doc_type TYPE bapimepoheader-doc_type,

vendor TYPE bapimepoheader-vendor,

creat_date TYPE bapimepoheader-creat_date,

purch_org TYPE bapimepoheader-purch_org,

pur_group TYPE bapimepoheader-pur_group,

comp_code TYPE bapimepoheader-comp_code,

po_item TYPE bapimepoitem-po_item,

acctasscat TYPE bapimepoitem-acctasscat,

short_text TYPE bapimepoitem-short_text,

quantity TYPE bapimepoitem-quantity,

po_unit TYPE bapimepoitem-po_unit,

del_datcat_ext TYPE bapimeposchedule-del_datcat_ext,

delivery_date TYPE bapimeposchedule-delivery_date,

net_price TYPE bapimepoitem-net_price,

price_unit TYPE bapimepoitem-price_unit,

orderpr_un TYPE bapimepoitem-orderpr_un,

matl_group TYPE bapimepoitem-matl_group,

plant TYPE bapimepoitem-plant,

gl_account TYPE bapimepoaccount-gl_account,

sd_doc TYPE bapimepoaccount-sd_doc,

itm_number TYPE bapimepoaccount-itm_number,

END OF ty_porder.

**--------------------------------------------------------------------------------------

DATA: it_porder TYPE TABLE OF ty_porder,

wa_porder TYPE ty_porder,

it_item TYPE TABLE OF bapimepoitem WITH HEADER LINE,

it_itemx TYPE TABLE OF bapimepoitemx WITH HEADER LINE,

it_shed TYPE TABLE OF bapimeposchedule WITH HEADER LINE,

it_shedx TYPE TABLE OF bapimeposchedulx WITH HEADER LINE,

it_acct TYPE TABLE OF bapimepoaccount WITH HEADER LINE,

it_acctx TYPE TABLE OF bapimepoaccountx WITH HEADER LINE,

it_return type table of bapiret2 with header line,

wa_return type bapiret2,

po_number TYPE bapimepoheader-po_number.

DATA: p_file TYPE rlgrap-filename VALUE 'C:\porder.txt'.

**----------------------------------------------------------------------------------------

CALL FUNCTION 'UPLOAD'

EXPORTING

filename = p_file

filetype = 'DAT'

TABLES

data_tab = it_porder

EXCEPTIONS

conversion_error = 1

invalid_table_width = 2

invalid_type = 3

no_batch = 4

unknown_error = 5

gui_refuse_filetransfer = 6

OTHERS = 7

.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

*----------------------------------------------------------------------------------------

LOOP AT it_porder INTO wa_porder.

CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'

EXPORTING

input = wa_porder-po_unit

* LANGUAGE = SY-LANGU

IMPORTING

output = wa_porder-po_unit

* EXCEPTIONS

* UNIT_NOT_FOUND = 1

* OTHERS = 2

.

IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

***-----------------------------------------------------------------------------------------

CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'

EXPORTING

input = wa_porder-orderpr_un

* LANGUAGE = SY-LANGU

IMPORTING

output = wa_porder-orderpr_un

.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = wa_porder-vendor

IMPORTING

OUTPUT = wa_porder-vendor.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = wa_porder-matl_group

IMPORTING

OUTPUT = wa_porder-matl_group.

bapimepoheader-doc_type = wa_porder-doc_type.

bapimepoheader-vendor = wa_porder-vendor.

bapimepoheader-creat_date = wa_porder-creat_date.

bapimepoheader-purch_org = wa_porder-purch_org.

bapimepoheader-pur_group = wa_porder-pur_group.

bapimepoheader-comp_code = wa_porder-comp_code.

* bapimepoheader-LANGU = 'E'.

* bapimepoheader-LANGU_iso = 'EN'.

bapimepoheader-CURRENCY = 'EUR'.

bapimepoheaderx-doc_type = 'X'.

bapimepoheaderx-vendor = 'X'.

bapimepoheaderx-creat_date = 'X'.

bapimepoheaderx-purch_org = 'X'.

bapimepoheaderx-pur_group = 'X'.

bapimepoheaderx-comp_code = 'X'.

* bapimepoheaderx-LANGU = 'X'.

* bapimepoheaderx-LANGU_iso = 'X'.

bapimepoheaderx-CURRENCY = 'X'.

it_item-po_item = wa_porder-po_item.

it_item-acctasscat = wa_porder-acctasscat.

it_item-short_text = wa_porder-short_text.

it_item-quantity = wa_porder-quantity.

it_item-po_unit = wa_porder-po_unit.

it_itemx-po_item = wa_porder-po_item.

it_itemx-po_itemx = 'X'.

it_itemx-acctasscat = 'X'.

it_itemx-short_text = 'X'.

it_itemx-quantity = 'X'.

it_itemx-po_unit = 'X'.

it_shed-po_item = wa_porder-po_item.

it_shed-del_datcat_ext = wa_porder-del_datcat_ext.

it_shed-delivery_date = wa_porder-delivery_date.

it_shedx-po_item = wa_porder-po_item.

it_shedx-po_itemx = 'X'.

it_shedx-del_datcat_ext = 'X'.

it_shedx-delivery_date = 'X'.

it_item-net_price = wa_porder-net_price.

it_item-price_unit = wa_porder-price_unit.

it_item-orderpr_un = wa_porder-orderpr_un.

it_item-matl_group = wa_porder-matl_group.

it_item-plant = wa_porder-plant.

it_itemx-net_price = 'X'.

it_itemx-price_unit = 'X'.

it_itemx-orderpr_un = 'X'.

it_itemx-matl_group = 'X'.

it_itemx-plant = 'X'.

it_acct-po_item = wa_porder-po_item.

it_acct-gl_account = wa_porder-gl_account.

it_acct-sd_doc = wa_porder-sd_doc.

it_acct-itm_number = wa_porder-itm_number.

it_acctx-po_item = wa_porder-po_item.

it_acctx-gl_account = 'X'.

it_acctx-sd_doc = 'X'.

it_acctx-itm_number = 'X'.

APPEND it_item.

APPEND it_itemx.

APPEND it_acct.

APPEND it_acctx.

APPEND it_shed.

APPEND it_shedx.

CALL FUNCTION 'BAPI_PO_CREATE1'

EXPORTING

poheader = bapimepoheader

poheaderx = bapimepoheaderx

* POADDRVENDOR =

* TESTRUN =

* MEMORY_UNCOMPLETE =

* MEMORY_COMPLETE =

* POEXPIMPHEADER =

* POEXPIMPHEADERX =

* VERSIONS =

* NO_MESSAGING =

* NO_MESSAGE_REQ =

* NO_AUTHORITY =

* NO_PRICE_FROM_PO =

IMPORTING

exppurchaseorder = po_number

* EXPHEADER =

* EXPPOEXPIMPHEADER =

TABLES

return = it_return

poitem = it_item

poitemx = it_itemx

* POADDRDELIVERY =

poschedule = it_shed

poschedulex = it_shedx

poaccount = it_acct

* POACCOUNTPROFITSEGMENT =

poaccountx = it_acctx

* POCONDHEADER =

* POCONDHEADERX =

* POCOND =

* POCONDX =

* POLIMITS =

* POCONTRACTLIMITS =

* POSERVICES =

* POSRVACCESSVALUES =

* POSERVICESTEXT =

* EXTENSIONIN =

* EXTENSIONOUT =

* POEXPIMPITEM =

* POEXPIMPITEMX =

* POTEXTHEADER =

* POTEXTITEM =

* ALLVERSIONS =

* POPARTNER =

* POCOMPONENTS =

* POCOMPONENTSX =

* POSHIPPING =

* POSHIPPINGX =

* POSHIPPINGEXP =

.

IF sy-subrc = 0.

WRITE:/ po_number.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

* EXPORTING

* WAIT =

* IMPORTING

* RETURN =

.

ELSE.

WRITE:/ 'roll back'.

CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'

* IMPORTING

* RETURN =

.

ENDIF.

loop at it_return into wa_return.

WRITE:/ wa_return-TYPE,wa_return-id,wa_return-number,wa_return-message.

endloop.

ENDLOOP.

*****************************************************************************Input file********************************************************

NB 1007 20.04.2014 1000 003 1000 111 M Moter_bike1 20 Pc D 23.04.2014 600000 1 Pc 0001c 1000 86200 5143 10