2007 Feb 22 4:52 AM
Hai,
how to upload the purchase order when one PO has three line items,
another has 100 line items, and so on.
can i use BAPI_PO_Create FM for this ?
if it possible ,how to use ?
Thanks & regards,
Manikandan
2007 Feb 22 4:57 AM
Yes you can use this function module, you have to pass the line items in an internal table which has the structure same as bapistructures.
Hai,
how to upload the purchase order when one PO has three line items,
another has 100 line items, and so on.
can i use BAPI_PO_Create FM for this ?
if it possible ,how to use ?
Thanks & regards,
Manikandan
2007 Feb 22 4:57 AM
Yes you can use this function module, you have to pass the line items in an internal table which has the structure same as bapistructures.
2007 Feb 22 5:01 AM
Check the following ex:
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 errmsg occurs 10.
include structure bapiret2.
data: end of errmsg.
data : errflag.
START-OF-SELECTION.
PERFORM UPLOAD_DATA.
&----
*& Form UPLOAD_DATA
&----
text
----
--> p1 text
<-- p2 text
----
FORM UPLOAD_DATA .
data: p_fdir(200) type c .
p_fdir = gfile.
data: begin of it_filedir occurs 10.
include structure salfldir.
data: end of it_filedir.
Get Current Directory Listing for OUT Dir
call function 'RZL_READ_DIR_LOCAL'
EXPORTING
name = p_fdir
TABLES
file_tbl = it_filedir.
data: it_filedir1 like it_filedir occurs 0 with header line.
loop at it_filedir.
if it_filedir-name(4) = 'CPOR' or it_filedir-name(4) = 'cpor'.
move it_filedir-name to it_filedir1-name.
append it_filedir1.
endif.
endloop.
IF IT_FILEDIR1[] IS INITIAL.
STOP.
ENDIF.
REFRESH I_MSG1.
CLEAR I_MSG1.
loop at it_filedir1.
REFRESH I_TAB.
REFRESH I_TAB2.
REFRESH I_TAB1.
data: g_file(100) type c .
name = it_filedir1-name.
concatenate: gfile '\' name into g_file.
data : i_tab1(200).
OPEN DATASET g_file FOR INPUT IN TEXT MODE
ENCODING DEFAULT
IGNORING CONVERSION ERRORS.
IF SY-SUBRC EQ 0.
DO.
READ DATASET g_file INTO i_tab1.
if sy-subrc = 0.
split i_tab1 at ',' into i_tab-verkf i_tab-verkf1 i_tab-lifnr
i_tab-ebelp1 i_tab-werks
i_tab-matnr i_tab-idnlf
i_tab-menge i_tab-bprme i_tab-lewed i_tab-netpr.
else.
exit.
endif.
APPEND i_tab.
clear i_tab.
ENDDO.
ENDIF.
*************** error testing*******************
LOOP AT i_tab.
MOVE-CORRESPONDING i_tab TO etab1.
append etab1.
clear etab1.
ENDLOOP.
*************** end error testing*******************
DELETE DATASET g_file.
CLOSE DATASET g_file.
concatenate:
hfile '\' date1 '\' name into h_file.
OPEN DATASET h_file FOR OUTPUT IN TEXT MODE
ENCODING DEFAULT
IGNORING CONVERSION ERRORS.
IF SY-SUBRC EQ 0.
LOOP AT I_TAB.
CONCATENATE I_TAB-VERKF ',' I_TAB-VERKF1 ',' I_TAB-LIFNR ','
I_TAB-EBELP1 ',' I_TAB-WERKS ',' I_TAB-MATNR ','
I_TAB-IDNLF ',' I_TAB-MENGE ',' I_TAB-BPRME ','
I_TAB-LEWED ',' I_TAB-NETPR INTO I_TAB2.
TRANSFER i_tab2 TO h_file.
ENDLOOP.
ENDIF.
CLOSE DATASET h_file.
MOVE I_TAB[] TO I_TAB3[].
DELETE ADJACENT DUPLICATES FROM I_TAB COMPARING VERKF.
loop at i_tab.
refresh pohead.
refresh poheadx.
refresh poitem.
refresh poitemX.
pohead-DOC_TYPE = i_tab-bsart.
pohead-VENDOR = i_tab-lifnr.
pohead-PURCH_ORG = c_ekorg.
pohead-CREAT_DATE = i_tab-verkf1.
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.
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-doc_date = c_x.
poheadx-langu = c_x.
append poheadx.
loop at i_tab3 WHERE VERKF = I_TAB-VERKF.
poitem-PO_ITEM = i_tab3-ebelp1.
poitem-MATERIAL = i_tab3-MATNR.
poitem-QUANTITY = i_tab3-MENGE.
poitem-PO_UNIT = i_tab3-BPRME.
poitem-NET_PRICE = i_tab3-NETPR.
poitem-PLANT = i_tab3-WERKS.
poitem-GR_TO_DATE = i_tab3-LEWED.
poitem-tax_code = c_x.
poitem-item_cat = c_x.
*
POITEM-ACCTASSCAT = c_x.
poitem-AGREEMENT = i_tab3-ebeln.
poitem-AGMT_ITEM = i_tab3-ebelp1.
poitem-VEND_MAT = i_tab3-IDNLF.
append poitem.
poitemx-PO_ITEM = i_tab3-ebelp1.
poitemx-MATERIAL = c_x.
poitemx-QUANTITY = c_x.
poitemx-PO_UNIT = c_x.
poitemx-NET_PRICE = c_x.
poitemx-PLANT = c_x.
poitemx-GR_TO_DATE = 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.
endloop.
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 =
POSCHEDULEX =
POACCOUNT =
POACCOUNTPROFITSEGMENT =
POACCOUNTX =
POCONDHEADER =
POCONDHEADERX =
POCOND =
POCONDX =
POLIMITS =
POCONTRACTLIMITS =
POSERVICES =
POSRVACCESSVALUES =
POSERVICESTEXT =
EXTENSIONIN =
EXTENSIONOUT =
POEXPIMPITEM =
POEXPIMPITEMX =
POTEXTHEADER =
POTEXTITEM =
ALLVERSIONS =
POPARTNER =
.
clear errflag.
loop at errmsg.
if errmsg-type eq 'E'.
write:/'Error in function', errmsg-message.
errflag = 'X'.
else.
write:/ errmsg-message.
endif.
endloop.
if errflag is initial.
commit work and wait.
if sy-subrc ne 0.
write:/ 'Error in updating'.
exit.
else.
write:/ ponum-PO_NUMBER, ponum-comp_code.
endif.
endif.
endloop.
ENDFORM. " UPLOAD_DATA
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |