‎2013 Jun 28 7:08 AM
Hii Experts,
DATA: poheader LIKE bapimepoheader,
poheaderx LIKE bapimepoheaderx,
poitem LIKE bapimepoitem OCCURS 0 WITH HEADER LINE,
poitemx LIKE bapimepoitemx OCCURS 0 WITH HEADER LINE,
return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
return2 LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
exppurchaseorder LIKE bapimepoheader-po_number,
expheader LIKE bapimepoheader OCCURS 0 WITH HEADER LINE,
exppoexpimpheader LIKE bapieikp OCCURS 0 WITH HEADER LINE,
poschedule LIKE bapimeposchedule OCCURS 0 WITH HEADER LINE,
poschedulex LIKE bapimeposchedulx OCCURS 0 WITH HEADER LINE.
types: begin of ty_item,
MATNR type MATNR,
MENGE type BSTMG,
NETPR type BPREI,
WERKS type EWERK,
LGORT type LGORT_D,
MWSKZ type MWSKZ,
end of ty_item.
data: it_item type standard table of ty_item,
wa_item type ty_item.
types: begin of ty_head,
BSART type ESART,
LIFNR type ELIFN,
BEDAT type EBDAT,
EKORG type EKORG,
EKGRP type BKGRP,
BUKRS type BUKRS,
mat like it_item,
end of ty_head.
data: it_head type standard table of ty_head,
wa_head type ty_head.
DATA : V_FNAME TYPE STRING.
PARAMETERS : P1_FNAME LIKE RLGRAP-FILENAME.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P1_FNAME.
CALL FUNCTION 'F4_FILENAME'
* EXPORTING
* PROGRAM_NAME = SYST-CPROG
* DYNPRO_NUMBER = SYST-DYNNR
* FIELD_NAME = ' '
IMPORTING
FILE_NAME = p1_Fname
.
START-OF-SELECTION.
Move p1_fname to v_fname.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = V_FNAME
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* VIRUS_SCAN_PROFILE =
* NO_AUTH_CHECK = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
DATA_TAB = it_head
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.
loop at it_head into wa_head.
*moving header data.
move wa_head-bsart to poheader-DOC_TYPE.
move wa_head-lifnr to poheader-VENDOR.
move wa_head-BEDAT to poheader-DOC_DATE.
move wa_head-EKORG to poheader-PURCH_ORG.
move wa_head-EKGRP to poheader-PUR_GROUP.
move wa_head-BUKRS to poheader-COMP_CODE.
poheaderx-DOC_TYPE = 'X'.
poheaderx-VENDOR = 'X'.
poheaderx-DOC_DATE = 'X'.
poheaderx-PURCH_ORG = 'X'.
poheaderx-PUR_GROUP = 'X'.
poheaderx-COMP_CODE = 'X'.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
POHEADER = poheader
POHEADERX = poheaderx
* POADDRVENDOR =
* TESTRUN =
* MEMORY_UNCOMPLETE =
* MEMORY_COMPLETE =
* POEXPIMPHEADER =
* POEXPIMPHEADERX =
* VERSIONS =
* NO_MESSAGING =
* NO_MESSAGE_REQ =
* NO_AUTHORITY =
* NO_PRICE_FROM_PO =
* PARK_COMPLETE =
* PARK_UNCOMPLETE =
* IMPORTING
* EXPPURCHASEORDER =
* EXPHEADER =
* EXPPOEXPIMPHEADER =
* TABLES
* RETURN =
* POITEM =
* POITEMX =
* POADDRDELIVERY =
* POSCHEDULE =
* POSCHEDULEX =
* POACCOUNT =
* POACCOUNTPROFITSEGMENT =
* POACCOUNTX =
* POCONDHEADER =
* POCONDHEADERX =
* POCOND =
* POCONDX =
* POLIMITS =
* POCONTRACTLIMITS =
* POSERVICES =
* POSRVACCESSVALUES =
* POSERVICESTEXT =
* EXTENSIONIN =
* EXTENSIONOUT =
* POEXPIMPITEM =
* POEXPIMPITEMX =
* POTEXTHEADER =
* POTEXTITEM =
* ALLVERSIONS =
* POPARTNER =
* POCOMPONENTS =
* POCOMPONENTSX =
* POSHIPPING =
* POSHIPPINGX =
* POSHIPPINGEXP =
* SERIALNUMBER =
* SERIALNUMBERX =
* INVPLANHEADER =
* INVPLANHEADERX =
* INVPLANITEM =
* INVPLANITEMX =
.
endloop.
But here i could not able to upload multiple line item. Please help me.
Thanks & Regards,
Srikanth.Y.
‎2013 Jun 28 9:05 AM
Hi Srikanth
You have to populate the following tabls for BAPI
TABLES
POITEM =
POITEMX =
Regards,
Venkat
‎2013 Jun 28 9:15 AM
Please give me logic for that. Normally i can able to pass that parameter for single record. But i want to pass multiple records.
‎2013 Jun 28 9:30 AM
Hi Srikanth
loop at it_group into wa_group. "Loop for header
CTR = 10.
PO_TEXTHEADER-TEXT_ID = 'F01'.
CONCATENATE wa_group-ebeln wa_group-ltext
INTO PO_TEXTHEADER-TEXT_LINE SEPARATED BY '-'.
APPEND PO_TEXTHEADER.
loop at it_datafeed into wa_datafeed where ebeln = wa_group-ebeln. "Loop for detail
"Create BAPI Records
perform bapi_header_records. "BAPI data creation
perform bapi_detail_records. "Bap detail record creation
endloop.
perform bapi_update.
refresh: PURITEM, PURITEMX, PO_HEADER, PO_HEADERX, PO_TEXTHEADER.
CONCATENATE '--- ' '---- ' INTO wa_return-message SEPARATED BY '---'.
append wa_return to it_return.
endloop.
form bapi_detail_records.
CTR2 = CTR.
CONCATENATE '00' CTR2 INTO CTR1.
PURITEM-PO_ITEM = CTR1.
PURITEM-MATERIAL = wa_datafeed-matnr.
PURITEM-PLANT = wa_datafeed-werks.
PURITEM-QUANTITY = wa_datafeed-menge.
PURITEM-NET_PRICE = wa_datafeed-netpr.
PURITEM-STGE_LOC = wa_datafeed-lgort.
APPEND PURITEM.
PURITEMX-PO_ITEM = CTR1.
PURITEMX-MATERIAL = 'X'.
PURITEMX-PLANT = 'X'.
PURITEMX-QUANTITY = 'X'.
PURITEMX-NET_PRICE = 'X'.
PURITEMX-STGE_LOC = 'X'.
APPEND BPITEMX.
CTR = CTR + 10.
endform.
Hope this will give you idea
Regards,
Venkat
‎2013 Jun 28 9:10 AM
Read BAPI documentation and fill item tables POITEM{X] for each record but header only when AT NEW triggered for fields used to build the header.
SORT itab BY headerfield1 lastheaderfield. " check their position in structure
LOOP AT itab.
AT NEW lastheaderfield.
" create header.
ENDAT.
" add item
AT END OF lastheaderfield.
" call bapi
" analyze return
" commit or rollback
ENDAT.
ENDLOOP.Regards,
Raymond
‎2013 Jun 28 12:53 PM
Hi,
To upload multiple line items, populate the poitem and poitemx parameters.
After uploading the data using GUI_UPLOAD, loop that and use control events to fill the header and item tables and pass those to function module BAPI_PO_CREATE1.
‎2013 Jun 28 1:03 PM
Try Below sample code.
DATA: wa_poheader TYPE bapimepoheader,
wa_poheaderx TYPE bapimepoheaderx,
t_poitem TYPE STANDARD TABLE OF bapimepoitem,
wa_poitem TYPE bapimepoitem,
t_poitemx TYPE STANDARD TABLE OF bapimepoitemx,
wa_poitemx TYPE bapimepoitemx,
t_return TYPE STANDARD TABLE OF bapiret2,
wa_return TYPE bapiret2,
t_fcat TYPE slis_t_fieldcat_alv,
wa_fcat TYPE slis_fieldcat_alv,
t_sort TYPE slis_t_sortinfo_alv,
wa_sort TYPE slis_sortinfo_alv.
wa_poheader-comp_code = "Company Code
wa_poheader-doc_type = "Document type
wa_poheader-vendor = "Vendor
wa_poheader-purch_org = "Purchase Organization
wa_poheader-pur_group = "Purchase Group
wa_poheaderx-comp_code = 'X'.
wa_poheaderx-doc_type = 'X'.
wa_poheaderx-vendor = 'X'.
wa_poheaderx-purch_org = 'X'.
wa_poheaderx-pur_group = 'X'.
wa_poitem-po_item = gv_item."item Number
wa_poitem-material = "Material Number
wa_poitem-plant = "plant
wa_poitem-stge_loc = "storage location
wa_poitem-quantity = 10.
wa_poitem-po_unit = 'EA'.
APPEND wa_poitem TO t_poitem.
CLEAR wa_poitem.
wa_poitem-po_itemx = 'X'
wa_poitem-materialx = 'X'
wa_poitem-stge_locx = 'X'
wa_poitem-quantityx = 'X'
wa_poitem-po_unitx = 'X'.
APPEND wa_poitemx TO t_poitemx.
CLEAR wa_poitemx.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = wa_poheader
poheaderx = wa_poheaderx
* POADDRVENDOR =
* TESTRUN =
* MEMORY_UNCOMPLETE =
* MEMORY_COMPLETE =
* POEXPIMPHEADER =
* POEXPIMPHEADERX =
* VERSIONS =
* NO_MESSAGING =
* NO_MESSAGE_REQ =
* NO_AUTHORITY =
* NO_PRICE_FROM_PO =
* PARK_COMPLETE =
* PARK_UNCOMPLETE =
IMPORTING
exppurchaseorder = gv_po
* EXPHEADER =
* EXPPOEXPIMPHEADER =
TABLES
return = t_return
poitem = t_poitem
poitemx = t_poitemx
* POADDRDELIVERY =
* POSCHEDULE =
* POSCHEDULEX =
* POACCOUNT =
* POACCOUNTPROFITSEGMENT =
* POACCOUNTX =
* POCONDHEADER =
* POCONDHEADERX =
* POCOND =
* POCONDX =
* POLIMITS =
* POCONTRACTLIMITS =
* POSERVICES =
* POSRVACCESSVALUES =
* POSERVICESTEXT =
* EXTENSIONIN =
* EXTENSIONOUT =
* POEXPIMPITEM =
* POEXPIMPITEMX =
* POTEXTHEADER =
* POTEXTITEM =
* ALLVERSIONS =
* POPARTNER =
* POCOMPONENTS =
* POCOMPONENTSX =
* POSHIPPING =
* POSHIPPINGX =
* POSHIPPINGEXP =
* SERIALNUMBER =
* SERIALNUMBERX =
* INVPLANHEADER =
* INVPLANHEADERX =
* INVPLANITEM =
* INVPLANITEMX =
.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
‎2013 Jun 28 1:03 PM
Hi Srikanth,
fill this parameters,
TABLES
* POITEM =
* POITEMX =.
while your filling the header details fil the item details for the respective PO and pass that details to the above parameters.
Try to use the following logic.
At new Po.
fill the header details.
end at.
at end of the po.
fill the item details.
endat.
Use this sample code.
DATA: BEGIN OF itab OCCURS 0,
doc_type(4),
suppl_plnt(4),
vendor(10),
purch_org(4),
pur_group(3),
comp_code(4),
vper_start(10),
vper_end(8),
po_item(5),
material(18),
quantity(16),
plant(4), stge_loc(4),
END OF itab.DATA: BEGIN OF it_log OCCURS 0, message(70) TYPE c, END OF it_log. DATA: w_type(4) TYPE c. CONSTANTS : c_x VALUE 'X'. DATA: gstest LIKE bapimepoheader. DATA: g_ebeln LIKE bapimepoheader-po_number. DATA: BEGIN OF g_bapimepoheader OCCURS 0. INCLUDE STRUCTURE bapimepoheader.DATA: END OF g_bapimepoheader. DATA: BEGIN OF g_bapimepoheaderx OCCURS 0. INCLUDE STRUCTURE bapimepoheaderx.DATA: END OF g_bapimepoheaderx. DATA: BEGIN OF g_bapimeposchedule OCCURS 0. INCLUDE STRUCTURE bapimeposchedule.DATA: END OF g_bapimeposchedule. DATA: BEGIN OF g_poschedulex OCCURS 0. INCLUDE STRUCTURE bapimeposchedulx.DATA: END OF g_poschedulex. DATA: BEGIN OF g_bapieikp OCCURS 0. INCLUDE STRUCTURE bapieikp.DATA: END OF g_bapieikp. DATA: BEGIN OF g_bapimepoitem OCCURS 0. INCLUDE STRUCTURE bapimepoitem.DATA: END OF g_bapimepoitem. DATA: BEGIN OF g_poitemx OCCURS 0. INCLUDE STRUCTURE bapimepoitemx.DATA: END OF g_poitemx. DATA: BEGIN OF g_bapiret2 OCCURS 0. INCLUDE STRUCTURE bapiret2.DATA: END OF g_bapiret2. DATA: it_itab LIKE itab OCCURS 0 WITH HEADER LINE. SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME TITLE text-100.PARAMETERS : p_file LIKE rlgrap-filename.SELECTION-SCREEN END OF BLOCK blk. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file. PERFORM file_selection. START-OF-SELECTION. PERFORM data_upload. PERFORM bapi_upload. PERFORM display. &----
*& Form file_selection&----
----
----
FORM file_selection. CALL FUNCTION 'WS_FILENAME_GET' EXPORTING def_filename = ' ' def_path = 'C:\' mask = ',.txt,.txt.' mode = 'O' title = 'Open a TXT(Tab delimited) file only' IMPORTING filename = p_file EXCEPTIONS inv_winsys = 1 no_batch = 2 selection_cancel = 3 selection_error = 4 OTHERS = 5. ENDFORM. " file_selection &----
*& Form data_upload&----
----
----
FORM data_upload . CALL FUNCTION 'WS_UPLOAD' EXPORTING filename = p_file filetype = 'DAT' TABLES data_tab = itab EXCEPTIONS conversion_error = 1 file_open_error = 2 file_read_error = 3 invalid_type = 4 no_batch = 5 unknown_error = 6 invalid_table_width = 7 gui_refuse_filetransfer = 8 customer_error = 9 no_authority = 10 OTHERS = 11. IF sy-subrc EQ 0 . WRITE:/ 'Program : ', sy-repid. WRITE:/ 'Filename: ', p_file. WRITE AT /1(144) sy-uline.
ENDIF. ENDFORM. " data_upload&----
*& Form bapi_upload&----
----
----
FORM bapi_upload . it_itab[] = itab[]. SORT itab BY vendor material. DELETE ADJACENT DUPLICATES FROM itab COMPARING vendor. LOOP AT itab. MOVE-CORRESPONDING itab TO g_bapimepoheader. w_type = itab-doc_type. IF itab-doc_type = 'ZTRM'. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = itab-vendor IMPORTING output = itab-vendor. g_bapimepoheader-vendor = itab-vendor. ENDIF. g_bapimepoheader-creat_date = sy-datum. g_bapimepoheader-created_by = sy-uname. APPEND g_bapimepoheader. g_bapimepoheaderx-comp_code = 'X'. g_bapimepoheaderx-vendor = 'X'. g_bapimepoheaderx-doc_type = 'X'. g_bapimepoheaderx-purch_org = 'X'. g_bapimepoheaderx-pur_group = 'X'. g_bapimepoheaderx-suppl_plnt = 'X'. g_bapimepoheaderx-vper_start = 'X'. g_bapimepoheaderx-vper_end = 'X'. APPEND g_bapimepoheaderx. IF itab-doc_type = 'ZTRM'. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = itab-vendor IMPORTING output = itab-vendor. ENDIF. LOOP AT it_itab WHERE vendor = itab-vendor. MOVE-CORRESPONDING it_itab TO g_bapimepoitem. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = it_itab-material IMPORTING output = it_itab-material. g_bapimepoitem-material = it_itab-material. APPEND g_bapimepoitem. MOVE-CORRESPONDING it_itab TO g_bapimeposchedule. APPEND g_bapimeposchedule. g_poitemx-po_item = it_itab-po_item. g_poitemx-po_itemx = 'X'.
g_poitemx-plant = 'X'. g_poitemx-stge_loc = 'X'.
g_poitemx-material = 'X'.
g_poitemx-quantity = 'X'.
APPEND g_poitemx. g_poschedulex-po_item = it_itab-po_item.
g_poschedulex-po_itemx = 'X'.
APPEND g_poschedulex. ENDLOOP. CALL FUNCTION 'BAPI_PO_CREATE1' EXPORTING poheader = g_bapimepoheader poheaderx = g_bapimepoheaderx
IMPORTING exppurchaseorder = g_ebeln
TABLES return = g_bapiret2 poitem = g_bapimepoitem poitemx = g_poitemx
poschedule = g_bapimeposchedule poschedulex = g_poschedulex
. IF NOT g_ebeln IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = ''.
IF w_type = 'ZTRM'. CONCATENATE 'LIS Trade Material created under the number' '-' g_ebeln INTO it_log-message. APPEND it_log. CLEAR it_log. ELSE. CONCATENATE 'LIS STO Plant-Plant created under the number' '-' g_ebeln INTO it_log-message. APPEND it_log. CLEAR it_log. ENDIF. CLEAR : it_itab,w_type,g_bapimepoitem,g_bapimepoheader, g_bapimepoheaderx,g_bapiret2,g_poitemx,g_bapimeposchedule, g_poschedulex. REFRESH : g_bapimepoitem,g_bapimepoheader,g_bapimepoheaderx, g_bapiret2,g_poitemx,g_bapimeposchedule,g_poschedulex. ENDIF. ENDLOOP.ENDFORM. " bapi_upload *----
&----
*& Form display&----
----
----
FORM display .
LOOP AT g_bapiret2.
WRITE 😕 g_bapiret2-message.
ENDLOOP.
LOOP AT it_log.
WRITE 😕 it_log-message.
ENDLOOP.
ENDFORM. " display
let me know if any issues.
Regards,
Gurunath
‎2013 Jun 28 1:31 PM
Hi Srikanth,
I also got this error.
Please Implement Note 1518346.
Hope this might solve your issue also.
Regards,
Anil.
‎2013 Jul 01 9:52 AM
See following example
LOOP AT i_data.
wa = i_data.
header-pmnttrms = 'V000'.
IF header-pur_group IS INITIAL.
header-pur_group = wa-ekgrp.
ENDIF.
IF header-purch_org IS INITIAL.
header-purch_org = wa-ekorg.
ENDIF.
AT NEW kostl.
SUM.
v_counter = v_counter + 10.
item-po_item = v_counter.
item-material = MATERIAL AS PAR YOUR INTERNAL TABLE
item-plant = PLANT
item-quantity = QUANITTY
item-net_price = NET PRICE
item-acctasscat = .
item-tax_code = .TAX CODE
item-order_reason = REASON
APPEND item.
CLEAR: item.
itemx-po_item = v_counter.
itemx-po_itemx = c_x.
itemx-material = c_x.
itemx-plant = c_x.
itemx-quantity = c_x.
itemx-net_price = c_x.
itemx-acctasscat = c_x.
itemx-tax_code = c_x.
itemx-order_reason = c_x.
APPEND itemx.
CLEAR: itemx.
ipoaccount-po_item = v_counter.
ipoaccount-costcenter = COSTCENTER
ipoaccount-gl_account = GL ACCOUNT
ipoaccount-serial_no = ITEM NO.
APPEND ipoaccount.
CLEAR ipoaccount.
ipoaccountx-po_item = v_counter.
ipoaccountx-costcenter = c_x.
ipoaccountx-gl_account = c_x.
APPEND ipoaccountx.
CLEAR ipoaccountx .
ipocond-itm_number = v_counter.
ipocond-cond_type = CONDITIN TYPE
ipocond-cond_st_no = COND. STNO
ipocond-cond_count =
ipocond-cond_value = VALUE
ipocond-currency = CURRENCY.
ipocond-cond_unit = UNIT.
ipocond-change_id =
APPEND ipocond.
CLEAR ipocond.
ipocondx-itm_number = c_x.
ipocondx-cond_type = c_x.
ipocondx-cond_st_no = c_x.
ipocondx-cond_count = c_x.
ipocondx-cond_value = c_x.
ipocondx-currency = c_x.
ipocondx-cond_unit = c_x.
ipocondx-change_id = c_x.
APPEND ipocondx.
CLEAR ipocondx.
ENDAT.
AT LAST.
header-comp_code =
header-doc_type =
header-vendor =
header-currency =
header-PMNTTRMS =
APPEND header.
headerx-comp_code = c_x.
headerx-doc_type = c_x.
headerx-vendor = c_x.
headerx-purch_org = c_x.
headerx-pur_group = c_x.
headerx-currency = c_x.
headerx-pmnttrms = c_x.
APPEND headerx.
IF p_run IS INITIAL.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
percentage = '20'
text = 'Process Is Running'.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = header
poheaderx = headerx
IMPORTING
exppurchaseorder = exppurchaseorder
TABLES
return = return[]
poitem = item[]
poitemx = itemx[]
poaccount = ipoaccount[]
poaccountx = ipoaccountx[]
pocond = ipocond[]
pocondx = ipocondx[].
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
percentage = '60'
text = 'Process Is Running'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.