07-30-2008 7:11 AM
Hi Guru's,
Can anyone provide me sample code creating PO for multiple items ........?
Greeting's of th Day,
Ankit Singh Rathore.
07-30-2008 7:15 AM
Ankit,
***********************************************************************
************************************************************************
&---------------------------------------------------------------------
*& Report ZBAPI_CREATE_PO *
*& *
&---------------------------------------------------------------------
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.
data: V_EXPPURCHASEORDER like BAPIMEPOHEADER-PO_NUMBER.
*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 '1000' ,
doctyp like HEADER-DOC_TYPE default 'NB' ,
cdate like HEADER-CREAT_DATE default sy-datum ,
vendor like HEADER-VENDOR default 'RAJ',
pur_org like HEADER-PURCH_ORG default '0001' ,
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 '00020',
material like ITEM-MATERIAL default 'M-127' ,
plant like ITEM-PLANT default '0001' ,
quantity like ITEM-QUANTITY default 200.
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 = V_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 / v_EXPPURCHASEORDER.
*ENDLOOP.
for multiple line irems u have to loop line item
for each header item
check this link
http://www.sap-img.com/abap/sample-abap-code-on-bapi-po-change.htm
Amit.
07-31-2023 8:09 AM
for multiple line irems u have to loop line item
for each header item
check this link
http://www.sap-img.com/abap/sample-abap-code-on-bapi-po-change.htm
Can you attach anathor link beacuse this link does not valid
07-30-2008 7:24 AM
Hi Ankit,
for sample code refer to the link:
http://www.erpgenie.com/phpBB2/viewtopic.php?p=15364&sid=926d6f57dae219558bcc48ccf055dbeb
also refer to the link;
http://abap.wikiprog.com/wiki/BAPI_PO_CREATE1
With luck,
Pritam.
07-30-2008 8:03 AM
hi,
&----
*& Report ZMM_U_PURCHASEORDER
*&
&----
*&
*&
&----
REPORT zmm_u_purchase_order1 LINE-SIZE 132 MESSAGE-ID zmmbapi .
data : begin of bdcdata occurs 0.
include structure bdcdata.
data : end of bdcdata.
TYPES: BEGIN OF ty_source,
vendor(010),
doc_type(004),
*comp_code(004),
purch_org(004),
pur_group(030),
ref_1(012),
material(018),
plant(004),
quantity(013),
net_price(028),
delivery_date(010),
END OF ty_source,
BEGIN OF ty_header ,
*comp_code(004),
doc_type(004),
vendor(010),
purch_org(004),
pur_group(030),
ref_1(012),
END OF ty_header,
BEGIN OF ty_item,
vendor(010),
material(018),
plant(004),
quantity(013),
net_price(028),
delivery_date(010),
END OF ty_item.
DATA : V_EBELP(005).
DATA : item TYPE STANDARD TABLE OF ty_source WITH HEADER LINE.
DATA : msg(240) TYPE c, " Return Message
e_rec(8) TYPE c, " Error Records Counter
rec_no(8) TYPE c, " Records Number Indicator
s_rec(8) TYPE c, " Successful Records Counter
t_rec(8) TYPE c, " Total Records Counter
count(003) TYPE c VALUE 0.
DATA : wa_source TYPE ty_source,
wa_source1 TYPE ty_source,
wa_header TYPE ty_header,
wa_item TYPE ty_item.
data : begin of bdc_itab occurs 0.
include structure bdcdata.
data : end of bdc_itab.
data : t_source type standard table of ty_source with header line,
t_header type standard table of ty_header initial size 1,
t_item type standard table of ty_item initial size 1,
t_target type standard table of bdcdata initial size 1.
data : w_source type ty_source,
w_source1 type ty_source,
w_header type ty_header,
w_item type ty_item,
w_target type bdcdata,
*count type i,
count1 type n.
*&----
Variable Declaration
*&----
data: w_fname type string,
fnam(20),
date1(10),
i(2) type n,
v_count type i,
v_group type apqi-groupid.
*&
*&SELECTION SCREEN
&----
selection-screen : begin of block bl1 with frame title text-001.
parameters : file like rlgrap-filename obligatory .
selection-screen end of block bl1.
&----
*&
*&SELECTION SCREEN VALIDATIONS
&----
at selection-screen on value-request for file.
perform get_filename.
&---------------------------------------------------------------------
*&
*&START OF SELECTION
&----
start-of-selection.
perform get_data.
perform cal1.
&----
*& Form get_filename
&----
text
----
--> p1 text
<-- p2 text
----
form get_filename .
call function 'WS_FILENAME_GET'
exporting
def_filename = space
def_path = file
mask = ',.,..'
mode = 'N'
title = text-015
importing
filename = file
exceptions
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
others = 5.
endform. " get_filename
&----
*& Form get_data
&----
text
----
--> p1 text
<-- p2 text
----
form get_data .
if file is initial.
message i016(rp) with 'Please enter a file name'.
leave list-processing.
else.
w_fname = file.
endif.
call function 'GUI_UPLOAD'
exporting
filetype = 'ASC'
filename = w_fname
has_field_separator = 'X'
tables
data_tab = t_source
exceptions
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
others = 17.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endform. " get_data
&----
*& Form cal1
&----
text
----
--> p1 text
<-- p2 text
----
form cal1 .
loop at t_source into w_source.
w_source1 = w_source.
at new vendor.
w_header-vendor = w_sOURCe1-vendor.
w_header-doc_type = w_source1-doc_type.
w_header-purch_org = w_source1-purch_org.
w_header-pur_group = w_source1-pur_group.
w_header-ref_1 = w_source1-ref_1.
APPEND W_HEADER TO T_HEADER.
endat.
w_item-vendor = w_source1-vendor.
w_item-material = w_source1-material.
w_item-plant = w_source1-plant.
w_item-quantity = w_source1-quantity.
w_item-net_price = w_source1-net_price.
w_item-delivery_date = w_item-delivery_date.
append w_item to t_item.
clear :w_item,w_header.
endloop.
loop at t_header into w_header.
perform bdc_dynpro using 'SAPMM06E' '0100' 'X'.
perform bdc_field using 'BDC_CURSOR'
'EKKO-EKGRP'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'EKKO-LIFNR'
w_header-vendor.
perform bdc_field using 'RM06E-BSART'
w_header-doc_type.
*perform bdc_field using 'RM06E-BEDAT'
record-BEDAT_003.
perform bdc_field using 'EKKO-EKORG'
w_header-purch_org.
perform bdc_field using 'EKKO-EKGRP'
w_header-pur_group.
*perform bdc_field using 'RM06E-LPEIN'
record-LPEIN_006.
*perform bdc_dynpro using 'SAPMM06E' '0120' 'X'.
*perform bdc_field using 'BDC_CURSOR'
'RM06E-EEIND(01)'.
*
data : v(003) VALUE '19',
U(003).
I = 1.
V = 19..
U = V - 1.
LOOP AT T_ITEM INTO W_ITEM WHERE VENDOR = W_HEADER-VENDOR.
perform bdc_dynpro using 'SAPMM06E' '0120' 'X'.
*perform bdc_field using 'BDC_CURSOR'
'RM06E-EEIND(01)'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
AT NEW VENDOR.
count = 0.
endat.
count = count + 1.
**if count = U.
**CLEAR I.
**I = 2.
**CONCATENATE V '0' INTO V_EBELP.
***V_EBELP = '190'.
**perform bdc_dynpro using 'SAPMM06E' '0120' 'X'.
**perform bdc_field using 'BDC_CURSOR' 'RM06E-EBELP'.
**perform bdc_field using 'BDC_OKCODE' '/00'.
**PERFORM bdc_field using 'RM06E-EBELP' V_EBELP.
**V = COUNT + 18.
*ENDIF.
count1 = count1 + 1.
concatenate 'EKPO-EMATN(' i ')' into fnam.
perform bdc_field using fnam
w_item-material.
concatenate 'EKPO-MENGE(' i ')' into fnam.
perform bdc_field using fnam
w_item-quantity.
concatenate 'EKPO-NETPR(' i ')' into fnam.
perform bdc_field using fnam
w_item-net_price.
concatenate 'EKPO-WERKS(' i ')' into fnam.
perform bdc_field using fnam
w_item-PLANT.
perform bdc_dynpro using 'SAPMM06E' '0120' 'X'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
i = i + 1.
clear w_item.
endloop.
perform bdc_dynpro using 'SAPMM06E' '0120' 'X'.
perform bdc_field using 'BDC_CURSOR'
'RM06E-EBELP'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
CALL TRANSACTION 'ME21' USING bdcdata
mode 'A'.
clear bdcdata.
refresh bdcdata.
endloop.
endform. " cal1
----
FORM BDC_DYNPRO *
----
form bdc_dynpro using program dynpro dynbegin.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = dynbegin.
append bdcdata.
clear bdcdata.
endform. "BDC_DYNPRO
----
FORM BDC_FIELD *
----
form bdc_field using fnam fval.
clear bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
append bdcdata.
clear bdcdata.
endform. "BDC_FIELD
07-30-2008 8:06 AM
Hi Guy's,
This is all about for Single ITEMS only...........
Here I am looking for the Multile ITEMS.
Here my code is shown below just check it out ........
what can I do for multiple ITEMS......
&----
*& Report ZBAPI_PO_CREATE_ANKIT1
*&
&----
*&
*&
&----
REPORT ZBAPI_PO_CREATE_ANKIT1.
break-point.
*DATA DECLARATION
CONSTANTS : C_X VALUE 'X'.
*Structures to hold PO header data
DATA : HEADER LIKE BAPIMEPOHEADER ,
HEADERX LIKE BAPIMEPOHEADERX ,
POITEM LIKE BAPIMEPOITEM.
*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 : SCHEDULE LIKE BAPIMEPOSCHEDULE OCCURS 0 WITH HEADER LINE ,
SCHEDULEX LIKE BAPIMEPOSCHEDULEX OCCURS 0 WITH HEADER LINE .
*DATA : ACCOUNT LIKE BAPIMEPOACCOUNT,
ACCOUNTX LIKE BAPIMEPPACCOUNTX.
*DATA:
************************************************************
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' .
item_int LIKE HEADER-ITEM_INTVL,
pmnttrms like HEADER-PMNTTRMS ,
currency like HEADER-currency,
CREATEBY LIKE HEADER-CREATED_BY.
selection-screen end of block b1.
PARAMETERS : NO_MAT TYPE I .
DATA: ITAB LIKE ITEM OCCURS 0 WITH HEADER LINE.
DATA: WAITAB LIKE ITAB.
*selection-screen begin of block b2 with frame title text-002.
LOOP AT ITAB INTO WAITAB.
*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.
netprice like POITEM-NET_PRICE.
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.
netprice like POITEM-NET_PRICE.
WAITAB-PO_ITEM = ITEM_NUM.
WAITAB-MATERIAL = MATERIAL.
WAITAB-PLANT = PLANT .
WAITAB-QUANTITY = QUANTITY.
WAITAB-NET_PRICE = NETPRICE.
APPEND WAITAB TO ITAB.
ENDLOOP.
*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 .
HEADER-ITEM_INTVL = item_int .
HEADER-PMNTTRMs = PMNTTRMs .
HEADER-CURRENCY = CURRENCY.
HEADER-CREATED_BY = CREATEBY.
&----
*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.
HEADERX-ITEM_INTVL = C_X.
HEADERX-PMNTTRMS = C_X.
HEADERX-CURRENCY = C_X.
HEADERX-CREATED_BY = C_X.
&----
*POPULATE ITEM DATA.
&----
ITEM-PO_ITEM = itab-po_item.
ITEM-MATERIAL = itab-material.
ITEM-PLANT = itab-plant.
ITEM-QUANTITY = itab-quantity.
ITEM-NET_PRICE = itab-net_price.
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 .
ITEMX-NET_PRICE = C_X .
APPEND ITEMX.
&----
*BAPI CALL
&----
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
POHEADER = HEADER
POHEADERX = HEADERX
POADDRVENDOR =
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.
07-30-2008 8:13 AM
Ankit,
for multiple line items u have to loop line item
for each header item
07-30-2008 11:45 AM
Hi Expert's,
Still I am not able to create PO for multiple Items ........
Please help me out .