Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Proble in Creating Multiple Item PO using BAPI_PO_CREATE1

Former Member
0 Kudos

Hi All..

I am creating PO using BAPI_PO_CREATE1. I have successfully created with single line item but when i tried to create with multiple line items it gives me error in partners(vendors) which i have used in table POPARTNER.

One more thing, I have created using BAPI with same partner roles with single line item but it gives me error in 2 or more line items.

So, Can Anybody help me in this..

Regards,

Meet Gohel

meet_jg@yahoo.co.in

5 REPLIES 5

Former Member
0 Kudos

Hi Meet,

See this blog

/people/sap.user72/blog/2005/03/22/sample-code-to-create-purchase-order-using-bapi-in-r3

Also Search in <b>SDN with key - BAPI_PO_CREATE1</b>

Will get few more useful related Posts.

Refer sample code:

constants : c_x value 'X'.

data: del_date type sy-datum.

data: pohead type bapimepoheader.

data: poheadx type bapimepoheaderx.

data: exp_head type bapimepoheader.

data: return type table of bapiret2 with header line.

data: poitem type table of bapimepoitem with header line.

data: poitemx type table of bapimepoitemx with header line.

data: posched type table of bapimeposchedule with header line.

data: poschedx type table of bapimeposchedulx with header line.

data: ex_po_number type bapimepoheader-po_number.

parameters: p_matnr type ekpo-matnr.

parameters: p_werks type ekpo-werks.

parameters: p_lgort type ekpo-lgort.

parameters: p_menge type ekpo-menge.

parameters: p_lifnr type ekko-lifnr.

parameters: p_ekorg type ekko-ekorg.

parameters: p_ekgrp type ekko-ekgrp.

parameters: p_bukrs type ekko-bukrs.

  • Header Level Data

pohead-comp_code = p_bukrs.

pohead-doc_type = 'NB' .

pohead-creat_date = sy-datum .

pohead-vendor = p_lifnr.

pohead-purch_org = p_ekorg.

pohead-pur_group = p_ekgrp.

pohead-langu = sy-langu .

pohead-doc_date = sy-datum.

poheadx-comp_code = c_x.

poheadx-doc_type = c_x.

poheadx-creat_date = c_x.

poheadx-vendor = c_x.

poheadx-langu = c_x.

poheadx-purch_org = c_x.

poheadx-pur_group = c_x.

poheadx-doc_date = c_x.

  • Item Level Data

poitem-po_item = 1.

poitem-material = p_matnr.

poitem-plant = p_werks.

poitem-stge_loc = p_lgort.

poitem-quantity = p_menge.

append poitem.

poitemx-po_item = 1.

poitemx-po_itemx = c_x.

poitemx-material = c_x.

poitemx-plant = c_x .

poitemx-stge_loc = c_x .

poitemx-quantity = c_x .

poitemx-tax_code = c_x .

poitemx-item_cat = c_x .

poitemx-acctasscat = c_x .

append poitemx.

  • Schedule Line Level Data

posched-po_item = 1.

posched-sched_line = 1.

posched-del_datcat_ext = 'D'.

del_date = sy-datum + 1.

write del_date to posched-delivery_date.

posched-deliv_time = '000001'.

posched-quantity = p_menge.

append posched.

poschedx-po_item = 1.

poschedx-sched_line = 1.

poschedx-po_itemx = c_x.

poschedx-sched_linex = c_x.

poschedx-del_datcat_ext = c_x.

poschedx-delivery_date = c_x.

poschedx-quantity = c_x.

append poschedx.

call function 'BAPI_PO_CREATE1'

exporting

poheader = pohead

poheaderx = poheadx

testrun = ' '

importing

exppurchaseorder = ex_po_number

expheader = exp_head

tables

return = return

poitem = poitem

poitemx = poitemx

poschedule = posched

poschedulex = poschedx.

call function 'BAPI_TRANSACTION_COMMIT'

exporting

wait = 'X'.

if not ex_po_number is initial.

call function 'DEQUEUE_ALL'.

else.

call function 'DEQUEUE_ALL'.

  • message i036.

endif.

Reward points if this helps.

Manish

Former Member
0 Kudos

Hi,

sample code for your refrence

&----


*& Report ZBAPI_CREATE_PO *

*& *

&----


*& Program demonstrates the BAPI call to create Purchase Order *

*& Minimum required parameters are used are as per the current *

*& system configuration *

&----


REPORT ZBAPI_CREATE_PO .

&----


*DATA DECLARATION

CONSTANTS : C_X VALUE 'X'.

*Structures to hold PO header data

DATA : HEADER LIKE BAPIMEPOHEADER ,

HEADERX LIKE BAPIMEPOHEADERX .

*Internal Tables to hold PO ITEM DATA

DATA : ITEM LIKE BAPIMEPOITEM OCCURS 0 WITH HEADER LINE,

ITEMX LIKE BAPIMEPOITEMX OCCURS 0 WITH HEADER LINE,

*Internal table to hold messages from BAPI call

RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.

data : w_header(40) value 'PO Header'.

data : ws_langu like sy-langu.

*text-001 = 'PO Header' - define as text element

selection-screen begin of block b1 with frame title text-001.

parameters : company like header-comp_code default '2700' ,

doctyp like HEADER-DOC_TYPE default 'NB' ,

cdate like HEADER-CREAT_DATE default sy-datum ,

vendor like HEADER-VENDOR default '0010000023',

pur_org like HEADER-PURCH_ORG default '2700' ,

pur_grp like HEADER-PUR_GROUP default '001' .

selection-screen end of block b1.

selection-screen begin of block b2 with frame title text-002.

parameters : item_num like ITEM-PO_ITEM default '00001',

material like ITEM-MATERIAL default 'CRANE' ,

plant like ITEM-PLANT default '2700' ,

quantity like ITEM-QUANTITY default 100.

selection-screen end of block b2.

&----


START-OF-SELECTION.

&----


*DATA POPULATION

&----


ws_langu = sy-langu. "Language variable

*POPULATE HEADER DATA FOR PO

HEADER-COMP_CODE = company .

HEADER-DOC_TYPE = doctyp .

HEADER-CREAT_DATE = cdate .

HEADER-VENDOR = vendor .

HEADER-LANGU = ws_langu .

HEADER-PURCH_ORG = pur_org .

HEADER-PUR_GROUP = pur_grp .

&----


*POPULATE HEADER FLAG.

&----


HEADERX-comp_code = c_x.

HEADERX-doc_type = c_x.

HEADERX-creat_date = c_x.

HEADERX-vendor = c_x.

HEADERX-langu = c_x.

HEADERX-purch_org = c_x.

HEADERX-pur_group = c_x.

HEADERX-doc_date = c_x.

&----


*POPULATE ITEM DATA.

&----


ITEM-PO_ITEM = item_num.

ITEM-MATERIAL = material.

ITEM-PLANT = plant.

ITEM-QUANTITY = quantity.

APPEND ITEM.

&----


*POPULATE ITEM FLAG TABLE

&----


ITEMX-PO_ITEM = item_num.

ITEMX-MATERIAL = C_X.

ITEMX-PLANT = C_X .

ITEMX-STGE_LOC = C_X .

ITEMX-QUANTITY = C_X .

ITEMX-TAX_CODE = C_X .

ITEMX-ITEM_CAT = C_X .

ITEMX-ACCTASSCAT = C_X .

APPEND ITEMX.

&----


*BAPI CALL

&----


CALL FUNCTION 'BAPI_PO_CREATE1'

EXPORTING

POHEADER = HEADER

POHEADERX = HEADERX

  • POADDRVENDOR =

  • TESTRUN =

  • IMPORTING

  • EXPPURCHASEORDER =

  • EXPHEADER =

  • EXPPOEXPIMPHEADER =

TABLES

RETURN = RETURN

POITEM = ITEM

POITEMX = ITEMX.

&----


*Confirm the document creation by calling database COMMIT

&----


CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

WAIT = 'X'

  • IMPORTING

  • RETURN =

.

end-of-selection.

&----


*Output the messages returned from BAPI call

&----


LOOP AT RETURN.

WRITE / RETURN-MESSAGE.

ENDLOOP.

Regards

0 Kudos

Hi ..

Sorry to say that your code will not help me because i have already created PO using this BAPI but i am facing problem in 2 or more line items in single PO. Your code are for single line items, and i think it will not work in multiple line item.

So, please help me in this...

Regards,

Meet Gohel

Former Member
0 Kudos

Hi ,

U can use this code n check

&----


*& Report ZPOBAPITRIAL

*&

&----


*&

*&

&----


REPORT ZPOBAPITRIAL.

*DATA DECLARATION

CONSTANTS : C_X VALUE 'X'.

*Structures to hold PO header data

DATA : HEADER LIKE BAPIMEPOHEADER ,

HEADERX LIKE BAPIMEPOHEADERX .

*Internal Tables to hold PO ITEM DATA

DATA : ITEM LIKE BAPIMEPOITEM OCCURS 0 WITH HEADER LINE,

ITEMX LIKE BAPIMEPOITEMX OCCURS 0 WITH HEADER LINE,

*Internal table to hold messages from BAPI call

RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.

data : w_header(40) value 'PO Header'.

DATA : it_item type standard table of BAPIMEPOITEM.

DATA : wa_item like BAPIMEPOITEM occurs 0 with header line.

DATA : it_itemx type standard table of BAPIMEPOITEMX.

DATA : wa_itemx like BAPIMEPOITEMX occurs 0 with header line.

data : ws_langu like sy-langu.

*text-001 = 'PO Header' - define as text element

selection-screen begin of block b1 with frame title text-001.

parameters : company like header-comp_code default '0103' ,

doctyp like HEADER-DOC_TYPE default 'NB' ,

item_int like header-item_intvl default '10' ,

cdate like HEADER-CREAT_DATE default sy-datum ,

vendor like HEADER-VENDOR default '0000500001',

pmnttrms like header-pmnttrms default '0007' ,

pur_org like HEADER-PURCH_ORG default '9000' ,

pur_grp like HEADER-PUR_GROUP default '401' ,

currency like header-currency default 'INR' .

selection-screen end of block b1.

selection-screen begin of block b2 with frame title text-002.

parameters : item_num like ITEM-PO_ITEM default '10',

material like ITEM-MATERIAL default '000000000300000014' ,

plant like ITEM-PLANT default '7640' ,

quantity like ITEM-QUANTITY default 10.

selection-screen end of block b2.

&----


START-OF-SELECTION.

&----


*DATA POPULATION

&----


ws_langu = sy-langu. "Language variable

*POPULATE HEADER DATA FOR PO

HEADER-COMP_CODE = company .

HEADER-DOC_TYPE = doctyp .

*HEADER-CREAT_DATE = cdate .

header-item_intvl = item_int .

HEADER-VENDOR = vendor .

HEADER-LANGU = ws_langu .

header-pmnttrms = pmnttrms .

HEADER-PURCH_ORG = pur_org .

HEADER-PUR_GROUP = pur_grp .

header-currency = currency .

&----


*POPULATE HEADER FLAG.

&----


HEADERX-comp_code = c_x.

HEADERX-doc_type = c_x.

*HEADERX-creat_date = c_x.

headerx-item_intvl = c_x .

HEADERX-vendor = c_x.

HEADERX-langu = c_x.

headerx-pmnttrms = c_x .

HEADERX-purch_org = c_x.

HEADERX-pur_group = c_x.

*HEADERX-doc_date = c_x.

&----


*POPULATE ITEM DATA.

&----


wa_ITEM-PO_ITEM = item_num.

wa_ITEM-MATERIAL = material.

wa_ITEM-PLANT = plant.

wa_ITEM-QUANTITY = quantity.

append wa_item to it_item.

wa_ITEM-PO_ITEM = '20'.

wa_ITEM-MATERIAL = '000000000300000020'.

wa_ITEM-PLANT = plant.

wa_ITEM-QUANTITY = quantity.

append wa_item to it_item.

*APPEND ITEM.

&----


*POPULATE ITEM FLAG TABLE

&----


wa_ITEMX-PO_ITEM = item_num.

wa_itEMX-MATERIAL = C_X.

wa_ITEMX-PLANT = C_X .

wa_ITEMX-STGE_LOC = C_X .

wa_ITEMX-QUANTITY = C_X .

wa_ITEMX-TAX_CODE = C_X .

wa_ITEMX-ITEM_CAT = C_X .

wa_ITEMX-ACCTASSCAT = C_X .

append wa_itemx to it_itemx.

*APPEND ITEMX.

wa_ITEMX-PO_ITEM = '20'.

wa_itEMX-MATERIAL = C_X.

wa_ITEMX-PLANT = C_X .

wa_ITEMX-STGE_LOC = C_X .

wa_ITEMX-QUANTITY = C_X .

wa_ITEMX-TAX_CODE = C_X .

wa_ITEMX-ITEM_CAT = C_X .

wa_ITEMX-ACCTASSCAT = C_X .

append wa_itemx to it_itemx.

&----


*BAPI CALL

&----


CALL FUNCTION 'BAPI_PO_CREATE1'

EXPORTING

POHEADER = HEADER

POHEADERX = HEADERX

  • POADDRVENDOR =

  • TESTRUN =

  • IMPORTING

  • EXPPURCHASEORDER =

  • EXPHEADER =

  • EXPPOEXPIMPHEADER =

TABLES

RETURN = RETURN

POITEM = it_ITEM

POITEMX = it_ITEMX.

&----


*Confirm the document creation by calling database COMMIT

&----


*CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

  • EXPORTING

  • WAIT = 'X'

    • IMPORTING

    • RETURN =

.

end-of-selection.

&----


*Output the messages returned from BAPI call

&----


LOOP AT RETURN.

WRITE: /001 return-type,

/001 return-message.

ENDLOOP.

award points if helpfull

former_member186078
Active Participant
0 Kudos

Hi Gohel,

Can you please let us know what all the messages that are returned by the BAPI_PO_CREATE1 function module?

Thanks,

Adithya K