Здравствуйте, уважаемые коллеги!
Вот был вопрос о загрузке остатков через BAPI, я додел программу и выставляю для всеобщего использования.
================================
* BAPI TO Upload Inventory Data
*
* GMCODE Table T158G - 01 - MB01 - Goods Receipts for Purchase Order
* 02 - MB31 - Goods Receipts for Prod Order
* 03 - MB1A - Goods Issue
* 04 - MB1B - Transfer Posting
* 05 - MB1C - Enter Other Goods Receipt
* 06 - MB11
*
* Domain: KZBEW - Movement Indicator
* Goods movement w/o reference
* B - Goods movement for purchase order
* F - Goods movement for production order
* L - Goods movement for delivery note
* K - Goods movement for kanban requirement (WM - internal only)
* O - Subsequent adjustment of "material-provided" consumption
* W - Subsequent adjustment of proportion/product unit material
*
report zbapi_goodsmovement.
tables mara.
parameters: p-file like rlgrap-filename default
'c:\sapdata\TEST.txt'.
parameters: e-file like rlgrap-filename default
'c:\sapdata\gdsmvterror.txt'.
parameters: xpost like sy-datum default sy-datum.
data: begin of gmhead.
include structure bapi2017_gm_head_01.
data: end of gmhead.
data: begin of gmcode.
include structure bapi2017_gm_code.
data: end of gmcode.
data: begin of mthead.
include structure bapi2017_gm_head_ret.
data: end of mthead.
data: begin of itab occurs 100.
include structure bapi2017_gm_item_create.
data: end of itab.
data: begin of errmsg occurs 10.
include structure bapiret2.
data: end of errmsg.
data: wmenge like iseg-menge,
errflag.
data: begin of pcitab occurs 100,
doc_date(8), "Document Date
post_date(8), "Posting Date
material(18), "Material Number
plant(4), "Plant
lgort(4), "Склад
summa(13), "Сумма
qty(13), "Quantity
charg(10), "Партия
upd_sta(1), "Для статистики
end of pcitab.
data: p_meins like mara-meins.
data: i like mara-matkl.
data: j like mara-matkl.
call function 'WS_UPLOAD'
exporting
filename = p-file
filetype = 'DAT'
* IMPORTING
* FILELENGTH =
tables
data_tab = pcitab
* EXCEPTIONS
* FILE_OPEN_ERROR = 1
* FILE_READ_ERROR = 2
* NO_BATCH = 3
* GUI_REFUSE_FILETRANSFER = 4
* INVALID_TYPE = 5
* OTHERS = 6
.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
exit.
endif.
gmhead-pstng_date = sy-datum.
gmhead-doc_date = sy-datum.
gmhead-pr_uname = sy-uname.
gmcode-gm_code = '05'. "05 - MB1C - Goods Receipts for Purchase Order
gmhead-header_txt = 'Stock Upload with 561 mvt'.
loop at pcitab.
select single meins into p_meins from mara where matnr = pcitab-material
.
itab-mvt_ind = ' '.
itab-move_type = '561'.
itab-plant = pcitab-plant.
itab-material = pcitab-material.
itab-entry_qnt = pcitab-qty.
itab-batch = pcitab-charg.
itab-entry_uom = p_meins.
itab-stge_loc = pcitab-lgort.
itab-amount_lc = pcitab-summa.
append itab.
endloop.
loop at itab.
write:/ itab-material, itab-plant, itab-stge_loc,
itab-move_type, itab-entry_qnt, itab-entry_uom,
itab-amount_lc, itab-batch.
endloop.
call function 'BAPI_GOODSMVT_CREATE'
exporting
goodsmvt_header = gmhead
goodsmvt_code = gmcode
* TESTRUN = ' '
* IMPORTING
goodsmvt_headret = mthead
* MATERIALDOCUMENT =
* MATDOCUMENTYEAR =
tables
goodsmvt_item = itab
* GOODSMVT_SERIALNUMBER =
return = errmsg
.
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 = 'X'.
commit work and wait.
if sy-subrc ne 0.
write:/ 'Error in updating'.
exit.
else.
write:/ mthead-mat_doc, mthead-doc_year.
perform upd_sta.
endif.
endif.
commit work.
*---------------------------------------------------------------------*
* FORM UPD_STA *
*---------------------------------------------------------------------*
* Выставляем в pcitab X если запись в файле содержит ошибки *
* и не может быть загружена *
*---------------------------------------------------------------------*
form upd_sta.
i = 1. "Индексы таблицы pcitab
j = 1. "Индексы таблицы errmsg
read table errmsg index j.
loop at pcitab.
if errmsg-row = i.
pcitab-upd_sta = 'X'.
modify pcitab.
j = j + 1.
read table errmsg index j.
endif.
i = i + 1.
endloop.
call function 'WS_DOWNLOAD'
exporting
filename = e-file
filetype = 'DAT'
* IMPORTING
* FILELENGTH =
tables
data_tab = pcitab
* EXCEPTIONS
* FILE_OPEN_ERROR = 1
* FILE_READ_ERROR = 2
* NO_BATCH = 3
* GUI_REFUSE_FILETRANSFER = 4
* INVALID_TYPE = 5
* OTHERS = 6
.
write:/.
write:/ 'Ошибки загрузки'.
loop at pcitab.
if pcitab-upd_sta = 'X'.
write:/ pcitab-doc_date, pcitab-post_date, pcitab-material,
pcitab-plant, pcitab-lgort, pcitab-summa,
pcitab-qty, pcitab-charg, pcitab-upd_sta.
endif.
endloop.
endform.
*--- End of Program
|
|