REPORT z_datainit_me51n .
TABLES:eban.
DATA: BEGIN OF itab OCCURS 0,
NO(5),
bnfpo LIKE eban-bnfpo,
bsart LIKE eban-bsart,
matnr LIKE eban-matnr,
lgort LIKE eban-lgort,
menge LIKE eban-menge,
bednr LIKE eban-bednr,
lfdat LIKE eban-lfdat,
TX(132),
END OF itab.
DATA :
prheader LIKE TABLE OF bapimereqheader WITH HEADER LINE,
prheaderx LIKE TABLE OF bapimereqheaderx WITH HEADER LINE,
PRITEMEXP LIKE TABLE OF BAPIMEREQITEM WITH HEADER LINE,
return LIKE TABLE OF bapiret2 WITH HEADER LINE,
pritem LIKE TABLE OF bapimereqitemimp WITH HEADER LINE,
pritemx LIKE TABLE OF bapimereqitemx WITH HEADER LINE,
PRITEMTEXT LIKE TABLE OF BAPIMEREQITEMTEXT WITH HEADER LINE.
DATA auxfilename LIKE rlgrap-filename.
CALL FUNCTION 'UPLOAD'
EXPORTING
filename = 'C:PRCREATE.TXT'
filetype = 'DAT'
IMPORTING
act_filename = auxfilename
TABLES
data_tab = itab.
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 ITAB .
prheader-pr_type = itab-bsart.
APPEND prheader.
CLEAR prheader.
prheaderx-pr_type = 'X'.
APPEND prheaderx.
CLEAR prheaderx.
pritem-preq_item = itab-bnfpo.
pritem-material = itab-matnr.
pritem-plant = '0100'.
pritem-store_loc = itab-lgort.
pritem-quantity = itab-menge.
pritem-trackingno = itab-bednr.
pritem-deliv_date = itab-lfdat.
APPEND pritem.
CLEAR pritem.
pritemx-PREQ_ITEM = itab-bnfpo.
pritemx-preq_itemX = 'X'.
pritemx-material = 'X'.
pritemx-plant = 'X'.
pritemx-store_loc = 'X'.
pritemx-quantity = 'X'.
pritemx-trackingno = 'X'.
pritemx-deliv_date = 'X'.
pritemx-SHORT_TEXT = 'X'.
APPEND pritemx.
CLEAR pritemx.
PRITEMTEXT-PREQ_ITEM = itab-BNFPO.
PRITEMTEXT-TEXT_ID = 'B01'.
PRITEMTEXT-TEXT_LINE = ITAB-TX.
append PRITEMTEXT.
CLEAR PRITEMTEXT.
ENDLOOP.
CALL FUNCTION 'BAPI_PR_CREATE'
* EXPORTING
* VERSIONS =
* SKIP_ITEMS_WITH_ERROR =
* TESTRUN =
* IMPORTING
* PRNUMBER =
TABLES
RETURN = RETURN
pritem = PRITEM
PRITEMX = PRITEMX
* PRITEMEXP = PRITEMEXP
* PRITEMSOURCE =
* PRACCOUNT =
* PRACCOUNTPROITSEGMENT =
* PRACCOUNTX =
* PRADDRDELIVERY =
PRITEMTEXT = PRITEMTEXT
* PRHEADERTEXT =
* PRLIMITS =
* PRCONTRACTLIMITS =
* PRSERVICES =
* PRSRVACCESSVALUES =
* PRSERVICESTEXT =
* EXTENSIONIN =
* EXTENSIONOUT =
* ALLVERSIONS =
CHANGING
PRHEADER = PRHEADER
PRHEADERX = PRHEADERX .
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
REFRESH PRITEM.
REFRESH prheader.
REFRESH prheaderx.
REFRESH PRITEMX.
REFRESH PRITEMTEXT.