REPORT zppmm_mb1b.
TABLES:mseg,
mkpf,
rm07m,
t158b,
t001l,
msegk.
DATA: mat_doc LIKE bapi2017_gm_head_ret-mat_doc.
DATA:save_code LIKE sy-ucomm,
ok_code LIKE sy-ucomm,
loc_msg(50),
gmnga LIKE afru-gmnga,
mtsnr LIKE rm07m-mtsnr,
errflag..
DATA:BEGIN OF gt_afpo OCCURS 0.
INCLUDE STRUCTURE afpo.
DATA:END OF gt_afpo.
DATA:gmhead LIKE bapi2017_gm_head_01.
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.
INITIALIZATION.
t001l-lgort = '1051'.
mseg-lgort = '1050'.
mseg-werks = '1000'.
mkpf-bldat = sy-datum.
mkpf-budat = sy-datum.
t158b-bwart = '311'.
rm07m-sobkz = 'E'.
rm07m-werks = '1000'.
rm07m-lgort = '1050'.
mseg-erfme = 'PC'.
gmcode-gm_code = '04'. "MB1B
CALL SCREEN 100.
*&----------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&-----------------------------------------------------*
* text
*--------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'FOR0100'.
SET TITLEBAR '100'.
ENDMODULE. " STATUS_0100 OUTPUT
*&--------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&----------------------------------------------------*
* text
*-----------------------------------------------------*
MODULE user_command_0100 INPUT.
save_code = ok_code.
CLEAR ok_code.
CASE save_code.
WHEN 'SAVE'.
PERFORM form_save.
WHEN 'EXIT' OR 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'CLOSE' .
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&-----------------------------------------------------*
*& Form FORM_SAVE
*&-------------------------------------------------*
* text
*---------------------------------------------------------*
* --> p1 text
* <-- p2 text
*---------------------------------------------------*
FORM form_save .
IF mkpf-bldat = ''
OR mkpf-budat = ''
OR rm07m-mtsnr = ''
OR mseg-matnr = ''
OR mseg-lgort = ''
OR mseg-erfmg = ''
OR mseg-erfme = ''
OR t001l-lgort = ''
OR msegk-mat_kdauf = ''
OR msegk-mat_kdpos = ''.
MESSAGE i000(znyj13) WITH '信息不完整'.
RETURN.
ENDIF.
IF gmnga < mseg-erfmg.
MESSAGE i000(znyj13) WITH '移动数量应小于确认数量'.
mseg-erfmg = ''.
RETURN.
ENDIF.
gmhead-pstng_date = sy-datum."mkpf-bldat.
gmhead-doc_date = sy-datum."mkpf-budat.
gmhead-ref_doc_no = rm07m-mtsnr.
gmhead-pr_uname = sy-uname.
gmhead-header_txt = mkpf-bktxt.
* APPEND gmhead.
itab-material = mseg-matnr .
itab-plant = '1000'.
itab-stge_loc = mseg-lgort.
itab-move_type = t158b-bwart."rm07m-bwartwa.
itab-spec_stock = rm07m-sobkz.
itab-entry_qnt = mseg-erfmg.
itab-entry_uom = mseg-erfme.
* itab-batch = mseg-charg.
* itab-orderid = rm07m-mtsnr.
* itab-order_itno = msegk-mat_kdpos.
itab-move_mat = mseg-matnr.
itab-move_plant = '1000'.
itab-move_stloc = t001l-lgort .
itab-val_sales_ord = msegk-mat_kdauf.
itab-val_s_ord_item = msegk-mat_kdpos.
itab-nb_slips = 1.
APPEND itab.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = gmhead
goodsmvt_code = gmcode
IMPORTING
goodsmvt_headret = mthead
materialdocument = mat_doc
TABLES
goodsmvt_item = itab
return = errmsg.
LOOP AT errmsg.
CLEAR loc_msg.
CONCATENATE '过帐成功!' errmsg-message INTO loc_msg.
IF errmsg-type EQ 'E'.
MESSAGE errmsg-message TYPE 'E'.
errflag = 'X'.
ELSE.
MESSAGE loc_msg TYPE 'S'.
ENDIF.
ENDLOOP.
IF errflag IS INITIAL.
COMMIT WORK AND WAIT.
CLEAR loc_msg.
IF sy-subrc NE 0.
MESSAGE '过帐操作出现错误,请稍后重试!' TYPE 'E'.
EXIT.
ELSE.
CONCATENATE '物料凭证:' mat_doc '已成功创建!' INTO loc_msg.
MESSAGE i000(znyj13) WITH loc_msg.
gmhead-ref_doc_no = ''.
gmhead-header_txt = ''.
mseg-matnr = ''.
msegk-mat_kdauf = ''.
msegk-mat_kdpos = ''.
mseg-erfmg = ''.
rm07m-mtsnr = ''.
gmnga = ''.
mkpf-bktxt = ''.
ENDIF.
ELSE.
MESSAGE '这不是正确的发料单或者已经创建凭证!' TYPE 'E'.
ENDIF.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDFORM. " FORM_SAVE
*&-----------------------------------------------*
*& Module RM07M-MTSNR INPUT
*&----------------------------------------------*
* text
*------------------------------------------------*
MODULE rm07m-mtsnr INPUT.
CONCATENATE '0000' rm07m-mtsnr INTO mtsnr.
* SELECT SINGLE gmnga INTO gmnga FROM afru WHERE aufnr = rm07m-mtsnr.
IF sy-subrc = 0.
SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_afpo
FROM afpo
WHERE aufnr = mtsnr.
IF sy-subrc = 0.
READ TABLE gt_afpo INDEX 1.
msegk-mat_kdauf = gt_afpo-kdauf.
msegk-mat_kdpos = gt_afpo-kdpos.
mseg-matnr = gt_afpo-matnr.
gmnga = gt_afpo-wemng.
ENDIF.
ELSE.
CONCATENATE '订单: ' rm07m-mtsnr ' 不存在!' INTO loc_msg.
MESSAGE i000(znyj13) WITH loc_msg.
RETURN.
ENDIF.
ENDMODULE. " RM07M-MTSNR INPUT
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
*
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0100.
FIELD RM07M-MTSNR MODULE RM07M-MTSNR ON REQUEST.
* 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
阅读(7460) | 评论(0) | 转发(0) |