MM物料库存转移(bapi)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
*&---------------------------------------------------------------------*
*& Report ztmm_e001
*& Report Name: MM 物料库存转移
*& Report Description: MM 物料库存转移
*& T-Code: zmme001
*&---------------------------------------------------------------------*
*& Created By: TTC Created On: 2021-11-15
*& Updated By: TTC Updated On: 2021-11-15
*&---------------------------------------------------------------------*
REPORT ztmm_e001.
TABLES: mkpf,mseg,mara,mska,mchb,ztmm_e001,vbap,rm07m,t158b,t001l,msegk. DATA: lv_bwart(5), "移动类型
lv_sobkz LIKE mseg-sobkz, "特殊库存
lv_bldat LIKE mkpf-bldat, "凭证中的凭证日期
lv_budat LIKE mkpf-budat, "凭证中的过帐日期
lv_werks LIKE mseg-werks, "工厂
lv_matnr LIKE mara-matnr, "物料号
lv_vbeln LIKE mska-vbeln, "销售单
lv_posnr LIKE mska-posnr, "销售项目
lv_vbeln_in LIKE mska-vbeln, "接收销售单
lv_posnr_in LIKE mska-posnr, "接收销售项目
LV_WERKS_IN LIKE mseg-werks, "接下班厂
rp1(1),
rp2(1).
*SELECTION-SCREEN BEGIN OF BLOCK bl WITH FRAME TITLE text-001.
*PARAMETERS: P1 TYPE C RADIOBUTTON GROUP GP1 USER-COMMAND UC01, * P2 TYPE C RADIOBUTTON GROUP GP1.
*SELECTION-SCREEN END OF BLOCK bl .
*功能码返回值
DATA: ok_code TYPE sy-ucomm,
save_ok TYPE sy-ucomm.
CONTROLS: ztmm_1001 TYPE TABLEVIEW USING SCREEN 1001,
ztmm_1002 TYPE TABLEVIEW USING SCREEN 1002,
ztmm_1003 TYPE TABLEVIEW USING SCREEN 1003,
ztmm_1004 TYPE TABLEVIEW USING SCREEN 1004.
DATA: lv_cols LIKE LINE OF ztmm_1001-cols,
lv_line TYPE i.
DATA: lo_grid TYPE REF TO cl_gui_alv_grid.
DATA:gt_ztmm_e001 TYPE ztmm_e001 OCCURS 0 WITH HEADER LINE. DATA:gt_ztmm_e002 TYPE ztmm_e001 OCCURS 0 WITH HEADER LINE. DATA:gt_ztmm_e003 TYPE ztmm_e001 OCCURS 0 WITH HEADER LINE. DATA:gt_ztmm_e004 TYPE ztmm_e001 OCCURS 0 WITH HEADER LINE.
TYPE-POOLS: slis, icon.
DATA: g_repid LIKE sy-repid,
gt_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv,
gt_event TYPE slis_t_event,
wa_event TYPE slis_alv_event,
gt_selfield TYPE slis_selfield OCCURS 0,
l_layout TYPE slis_layout_alv.
START-OF-SELECTION.
CALL SCREEN 1010.
"库存转移主窗口
INCLUDE ztmm_e001_status_1010o01.
INCLUDE ztmm_e001_user_command_1010i01.
* "411 移动类型
INCLUDE ztmm_e001_status_1001o01. "411-PBO INCLUDE ztmm_e001_user_command_1001i01. "411-BAI
* "412 移动类型
INCLUDE ztmm_e001_status_1002o01. "412-PBO INCLUDE ztmm_e001_user_command_1002i01. "412-PAI
* "413 移动类型
INCLUDE ztmm_e001_status_1003o01. "413-PBO INCLUDE ztmm_e001_user_command_1003i01. "413-PAI
* "301 移动类型
INCLUDE ztmm_e001_status_1004o01. "301-PBO
INCLUDE ztmm_e001_user_command_1004i01. "301-PAI
*&---------------------------------------------------------------------*
*& Form get_matnrdesc
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get_matnrdesc. "网络值描述
DATA: wa_j_3apghd TYPE SORTED TABLE OF j_3apghd
WITH UNIQUE KEY mandt j_3apgnr j_3avdat WITH HEADER LINE.
DATA: wa_j_3apgen TYPE SORTED TABLE OF j_3apgen
WITH UNIQUE KEY mandt j_3apgnr j_3avdat j_3akord1 j_3akord2 j_3akord3 WITH HEADER LINE.
DATA: wa_cawn TYPE SORTED TABLE OF cawn
WITH UNIQUE KEY mandt atinn atzhl adzhl WITH HEADER LINE.
DATA: wa_cawnt TYPE SORTED TABLE OF cawnt
WITH UNIQUE KEY mandt atinn atzhl spras adzhl WITH HEADER LINE.
DATA: BEGIN OF lt_j_3apgnr OCCURS 0,
j_3apgnr LIKE mara-j_3apgnr,
END OF lt_j_3apgnr.
DATA: BEGIN OF lt_charact OCCURS 0,
g_3abzd TYPE j_3apghd-j_3abzd1,
END OF lt_charact.
DATA: BEGIN OF lt_cawn OCCURS 0,
atinn TYPE cawn-atinn,
END OF lt_cawn.
DESCRIBE TABLE wa_j_3apghd LINES lv_line.
IF lv_line = 0.
LOOP AT gt_ztmm_e001.
lt_j_3apgnr-j_3apgnr = gt_ztmm_e001-j_3apgnr.
COLLECT lt_j_3apgnr.
ENDLOOP.
SORT lt_j_3apgnr.
SELECT * INTO CORRESPONDING FIELDS OF TABLE wa_j_3apghd FROM j_3apghd
FOR ALL ENTRIES IN lt_j_3apgnr WHERE j_3apgnr = lt_j_3apgnr-j_3apgnr.
SELECT * INTO CORRESPONDING FIELDS OF TABLE wa_j_3apgen FROM j_3apgen FOR ALL ENTRIES IN lt_j_3apgnr WHERE j_3apgnr = lt_j_3apgnr-j_3apgnr.
LOOP AT wa_j_3apghd.
CLEAR lt_charact.
lt_charact-g_3abzd = wa_j_3apghd-j_3abzd1.
COLLECT lt_charact.
CLEAR lt_charact.
lt_charact-g_3abzd = wa_j_3apghd-j_3abzd2.
COLLECT lt_charact.
ENDLOOP.
LOOP AT lt_charact.
lt_cawn-atinn = lt_charact-g_3abzd.
APPEND lt_cawn.
ENDLOOP.
SORT lt_cawn.
SELECT * INTO CORRESPONDING FIELDS OF TABLE wa_cawn FROM cawn
FOR ALL ENTRIES IN lt_cawn WHERE atinn = lt_cawn-atinn.
SELECT * INTO CORRESPONDING FIELDS OF TABLE wa_cawnt FROM cawnt FOR ALL ENTRIES IN lt_cawn WHERE atinn = lt_cawn-atinn.
ENDIF.
*****************************************************************
LOOP AT gt_ztmm_e001.
"网络值描述
DATA:g_3abzd1 TYPE string,
g_3abzd2 TYPE string,
g_color TYPE string,
g_size TYPE string,
g_atzhl1 TYPE string,
g_atzhl2 TYPE string,
g_desc1 TYPE string,
g_desc2 TYPE string.
CLEAR:g_3abzd1,g_3abzd2,g_color,g_size,g_atzhl1,g_atzhl2,g_desc1,g_desc2. "通过物料网格编号:取得维值1,维值2(内部特性号)
READ TABLE wa_j_3apghd WITH KEY mandt = sy-mandt
j_3apgnr = gt_ztmm_e001-j_3apgnr .
g_3abzd1 = wa_j_3apghd-j_3abzd1.
g_3abzd2 = wa_j_3apghd-j_3abzd2.
"通过网格值及物料网格编号:取得颜色及尺码
READ TABLE wa_j_3apgen WITH KEY mandt = sy-mandt j_3apgnr = gt_ztmm_e001-j_3apgnr
j_3akordx = gt_ztmm_e001-j_3asize.
g_color = wa_j_3apgen-j_3akord1.
g_size = wa_j_3apgen-j_3akord2.
"内部计数器值
READ TABLE wa_cawn WITH KEY mandt = sy-mandt
atinn = g_3abzd1
atwrt = g_color.
g_atzhl1 = wa_cawn-atzhl.
READ TABLE wa_cawn WITH KEY mandt = sy-mandt
atinn = g_3abzd2
atwrt = g_size.
g_atzhl2 = wa_cawn-atzhl.
"网络值描述
READ TABLE wa_cawnt WITH KEY mandt = sy-mandt
atinn = g_3abzd1
spras = 1
atzhl = g_atzhl1.
g_desc1 = wa_cawnt-atwtb.
READ TABLE wa_cawnt WITH KEY mandt = sy-mandt
atinn = g_3abzd2
spras = 1
atzhl = g_atzhl2.
g_desc2 = wa_cawnt-atwtb.
IF g_desc1 IS INITIAL AND g_desc2 IS INITIAL.
gt_ztmm_e001-j_3asize_dsc = ''.
ELSEIF g_desc2 IS INITIAL.
CONCATENATE g_desc1 '' INTO gt_ztmm_e001-j_3asize_dsc.
ELSE.
CONCATENATE g_desc1 '/' g_desc2 INTO gt_ztmm_e001-j_3asize_dsc. ENDIF.
MODIFY gt_ztmm_e001.
ENDLOOP.
FREE: wa_j_3apghd,wa_j_3apgen,wa_cawn,wa_cawnt.
ENDFORM. " matnrdesc
*&---------------------------------------------------------------------*
*& Form clear_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM clear_data.
CLEAR:lv_bwart, "移动类型
lv_sobkz, "特殊库存
lv_werks, "工厂
lv_matnr, "物料号
lv_vbeln, "销售单
lv_posnr, "销售项目
lv_vbeln_in, "接收销售单
lv_posnr_in. "接收销售项目
REFRESH: gt_ztmm_e001,gt_ztmm_e002,gt_ztmm_e003,gt_ztmm_e004. FREE:ztmm_e001.
ENDFORM. "get_matnrdesc
一、执行以上代码得出以下界面:
1-1、主窗口界面逻辑流:
PROCESS BEFORE OUTPUT.
MODULE STATUS_1010.
*
PROCESS AFTER INPUT.
MODULE USER_COMMAND_1010.
1-2、主窗口OUTPUT模块代码:
MODULE status_1010 OUTPUT.
SET PF-STATUS 'ZTMM_STATE'.
SET TITLEBAR 'ZTMM_E001_10'. "USER_COMMAND ENDMODULE. " STATUS_1010 OUTPUT
1-2、主窗口INPUT模块代码:
MODULE user_command_1010 INPUT.
save_ok = sy-ucomm.
CASE save_ok.
WHEN 'LV_BTN1'.
CALL SCREEN 1001.
WHEN 'LV_BTN2'.
CALL SCREEN 1002.
WHEN 'LV_BTN3'.
CALL SCREEN 1003.
WHEN 'LV_BTN4'.
CALL SCREEN 1004.
WHEN 'LV_BTN5' OR 'EXIT' OR 'BACK' OR 'CANC' .
SET SCREEN 0. LEAVE SCREEN.
WHEN 'SAVE'.
MODIFY SCREEN.
ENDCASE.
ENDMODULE. " USER_COMMAND_1010 INPUT
2-1、1001屏幕界面逻辑流:
PROCESS BEFORE OUTPUT.
FIELD !lv_bldat MODULE %_lv_bldat.
FIELD !lv_budat MODULE %_lv_budat.
FIELD !lv_werks MODULE %_lv_werks.
FIELD !lv_vbeln MODULE lv_vbeln.
FIELD !lv_posnr MODULE lv_posnr.
FIELD !lv_matnr MODULE lv_matnr.
MODULE status_1001.
LOOP AT gt_ztmm_e001 WITH CONTROL ztmm_1001 CURSOR ztmm_1001-top_line. MODULE display_ztmm_1001.
ENDLOOP.
PROCESS AFTER INPUT.
LOOP AT gt_ztmm_e001.
MODULE modify_data_1001.
ENDLOOP.
MODULE user_command_1001.
2-2、1001屏幕OUTPUT模块代码:
MODULE status_1001 OUTPUT.
SET PF-STATUS 'ZTMM_STATE'.
SET TITLEBAR 'ZTMM_E001_01'.
DESCRIBE TABLE gt_ztmm_e001 LINES lv_line.
ztmm_1001-lines = lv_line.
IF gt_ztmm_e001 IS INITIAL.
lv_bldat = sy-datum.
lv_budat = sy-datum.
lv_bwart = '411'.
lv_sobkz = 'E'.
ENDIF.
ENDMODULE. " STATUS_1001 OUTPUT
*----------------------------------------------------------------------*
* MODULE display_ztmm_1001 OUTPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE display_ztmm_1001 OUTPUT.
READ TABLE gt_ztmm_e001 INTO ztmm_e001 INDEX ztmm_1001-current_line. " DISPLAY OUTP UT
ENDMODULE. " DISPLAY_ZTMM_1001 OUTPUT
2-2、1001屏幕INPUT模块代码:
*----------------------------------------------------------------------*
***INCLUDE ZTMM_E001_USER_COMMAND_1001I01 .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_1001 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_1001 INPUT.
save_ok = sy-ucomm. "ok_code .
CASE save_ok.
WHEN 'EXIT' OR 'BACK' OR 'CANC' .
PERFORM clear_data.
SET SCREEN 0. LEAVE SCREEN.
WHEN 'SAVE' .
PERFORM save_data_1001 .
WHEN 'BTN_CLEAR' .
FREE:gt_ztmm_e001. "清空列表
WHEN 'BTN_GET_STOCK'.
PERFORM get_data_1001. "读取数据。
ENDCASE.
ENDMODULE. " USER_COMMAND_1001 INPUT
*&---------------------------------------------------------------------*
*& Form get_data_1001
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get_data_1001.
IF lv_bldat IS INITIAL AND lv_budat IS INITIAL.
MESSAGE s000(oo) WITH '请输入凭证日期及转帐日期' DISPLAY LIKE 'E'. EXIT.
ENDIF.
IF lv_werks EQ ''.
MESSAGE s000(oo) WITH '请输入工厂代码' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
IF lv_vbeln EQ '' OR lv_posnr EQ ''.
MESSAGE s000(oo) WITH '请输入销售单及销售项目' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
PERFORM get_stock_data_1001. "读取库存数据
PERFORM get_bwart_1001. "移动类型
PERFORM get_matnrdesc . "网络值描述
ENDFORM. "get_data_1001
*&---------------------------------------------------------------------*
*& Form SAVE_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM save_data_1001.
* ========================== 验证数据 ========================== LOOP AT gt_ztmm_e001 WHERE opt = 'X'.
IF gt_ztmm_e001-opt = 'X'.
IF gt_ztmm_e001-qty = '' OR gt_ztmm_e001-lgort_in = ''.
MESSAGE '输入信息不完整' TYPE 'I'.
RETURN.
ENDIF.
ENDIF.
IF gt_ztmm_e001-qty > gt_ztmm_e001-menge.
MESSAGE '移动数应小于或等于原仓位数' TYPE 'I'.
gt_ztmm_e001-qty = ''.
RETURN.
ENDIF.
ENDLOOP.
* ========================== 保留数据 ==========================
DATA:zt_gm_head_01 LIKE bapi2017_gm_head_01.
DATA:zt_code LIKE bapi2017_gm_code.
DATA:zt_ret_doc LIKE bapi2017_gm_head_ret.
DATA:zt_goodsmvt_item LIKE TABLE OF /afs/bapi2017_gm_item_create WITH HEADER LINE. DATA:materialdocument TYPE bapi2017_gm_head_ret-mat_doc.
DATA:zreturn LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
zreturngr LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
DATA:loc_msg(50),
errflag(1),
lv_year LIKE zt_ret_doc-doc_year .
CLEAR:zt_gm_head_01,zt_goodsmvt_item,zt_code,zt_ret_doc.
" 移动主信息
zt_gm_head_01-pstng_date = lv_budat. "过帐日期
zt_gm_head_01-doc_date = lv_bldat. "凭证日期
zt_gm_head_01-pr_uname = sy-uname. "创建人
zt_code-gm_code = '04'. "货物移动事务代码 MB1B
zt_ret_doc-doc_year = sy-datum. "凭证年份
" 移动明细信息
LOOP AT gt_ztmm_e001 WHERE opt = 'X'.
zt_goodsmvt_item-material = gt_ztmm_e001-matnr. "物料号
zt_goodsmvt_item-plant = gt_ztmm_e001-werks_out. "工厂
zt_goodsmvt_item-stge_loc = gt_ztmm_e001-lgort_out. "仓位
zt_goodsmvt_item-move_type = gt_ztmm_e001-bwart. "移动类型 zt_goodsmvt_item-spec_stock = 'E'. "特殊库存标识
zt_goodsmvt_item-grid_value = gt_ztmm_e001-j_3asize. "网格值
zt_goodsmvt_item-batch = gt_ztmm_e001-charg. "批号
zt_goodsmvt_item-entry_qnt = gt_ztmm_e001-qty. "输入数量
zt_goodsmvt_item-entry_uom = gt_ztmm_e001-meins. "单位
zt_goodsmvt_item-move_mat = gt_ztmm_e001-matnr. "移动物料号 zt_goodsmvt_item-move_plant = gt_ztmm_e001-werks_out."移入工厂 zt_goodsmvt_item-move_stloc = gt_ztmm_e001-lgort_in. "移入仓位 zt_goodsmvt_item-sales_ord = gt_ztmm_e001-vbeln_out. "销售单
zt_goodsmvt_item-s_ord_item = gt_ztmm_e001-posnr_out."销售项目
zt_goodsmvt_item-val_sales_ord = gt_ztmm_e001-vbeln_out. "销售单
zt_goodsmvt_item-val_s_ord_item = gt_ztmm_e001-posnr_out. "销售项目 zt_goodsmvt_item-nb_slips = 1.
APPEND zt_goodsmvt_item.
ENDLOOP.
DESCRIBE TABLE zt_goodsmvt_item LINES lv_line.
IF lv_line > 0 AND NOT zt_goodsmvt_item[] IS INITIAL.
CALL FUNCTION '/AFS/BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = zt_gm_head_01
goodsmvt_code = zt_code-gm_code
IMPORTING
goodsmvt_headret = zt_ret_doc
materialdocument = materialdocument
TABLES
afs_goodsmvt_item = zt_goodsmvt_item
return = zreturn.
ENDIF.
LOOP AT zreturn.
CLEAR:loc_msg.
CONCATENATE '过帐无效!' zreturn-message INTO loc_msg.
IF zreturn-type EQ 'E'.
MESSAGE zreturn-message TYPE 'S'.
errflag = 'X'.
ELSE.
MESSAGE zreturn-message TYPE 'S'.
ENDIF.
ENDLOOP.
IF errflag IS INITIAL AND lv_line > 0.
COMMIT WORK AND WAIT.
CLEAR loc_msg.
IF sy-subrc NE 0.
* MESSAGE '过帐操作显现错误,请稍后再重试!' TYPE 'S'.
MESSAGE s000(oo) WITH '过帐操作显现错误,请稍后再重试' DISPLAY LIKE 'E'. EXIT.
ELSE.
CONCATENATE '过帐成功!物料凭证号:' materialdocument INTO loc_msg.
MESSAGE loc_msg TYPE 'S'.
ENDIF.
ELSE.
MESSAGE loc_msg TYPE 'S'.
ENDIF.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDFORM. "SAVE_DATA
*&---------------------------------------------------------------------*
*& Form modify_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE modify_data_1001 INPUT.
MODIFY gt_ztmm_e001 FROM ztmm_e001 INDEX ztmm_1001-current_line. ENDMODULE. "modify_data INPUT
*&---------------------------------------------------------------------*
*& Form GET_STOCK_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get_stock_data_1001.
IF lv_matnr EQ ''.
SELECT
mska~werks AS werks_out "工厂
mska~matnr "物料号
makt~maktx AS matnr_dsc "物料描述
mska~j_3asize "网格值
mara~j_3apgnr "物料网格编号
mska~lgort AS lgort_out "转出仓位
mska~charg "批次
mska~kalab AS menge "非限制利用库存(数量)
mara~meins "单位
mska~vbeln AS vbeln_out "销售单
mska~posnr AS posnr_out "销售项目
INTO CORRESPONDING FIELDS OF TABLE gt_ztmm_e001
FROM mska
INNER JOIN mara ON mara~matnr = mska~matnr
INNER JOIN makt ON makt~matnr = mara~matnr AND makt~spras = '1' WHERE mska~werks = lv_werks
AND mska~vbeln = lv_vbeln
AND mska~posnr = lv_posnr.
ELSE.
SELECT
mska~werks AS werks_out "工厂
mska~matnr "物料号
makt~maktx AS matnr_dsc "物料描述
mska~j_3asize "网格值
mara~j_3apgnr "物料网格编号
mska~lgort AS lgort_out "转出仓位
mska~charg "批次
mska~kalab AS menge "非限制利用库存(数量)
mara~meins "单位
mska~vbeln AS vbeln_out "销售单
mska~posnr AS posnr_out "销售项目
INTO CORRESPONDING FIELDS OF TABLE gt_ztmm_e001
FROM mska
INNER JOIN mara ON mara~matnr = mska~matnr
INNER JOIN makt ON makt~matnr = mara~matnr AND makt~spras = '1' WHERE mska~werks = lv_werks
AND mska~vbeln = lv_vbeln
AND mska~posnr = lv_posnr
AND mska~matnr = lv_matnr.
ENDIF.
SORT gt_ztmm_e001 BY werks_out matnr lgort_out j_3asize .
DELETE ADJACENT DUPLICATES FROM gt_ztmm_e001.
ENDFORM. "GET_STOCK_DATA
*&---------------------------------------------------------------------*
*& Form get_bwart
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get_bwart_1001. "移动类型
LOOP AT gt_ztmm_e001.
gt_ztmm_e001-bwart = '411'.
MODIFY gt_ztmm_e001.
ENDLOOP.
ENDFORM. "get_bwart
执行代码得出以下界面:
3-1:1002屏幕逻辑流:
PROCESS BEFORE OUTPUT.
FIELD !lv_bldat MODULE %_lv_bldat.
FIELD !lv_budat MODULE %_lv_budat.
FIELD !lv_werks MODULE %_lv_werks.
FIELD !lv_vbeln MODULE %_lv_vbeln.
FIELD !lv_posnr MODULE %_lv_posnr.
FIELD !lv_matnr MODULE %_lv_matnr.
MODULE status_1002.
LOOP AT gt_ztmm_e002 WITH CONTROL ztmm_1002 CURSOR ztmm_1002-top_line. MODULE display_ztmm_1002.
ENDLOOP.
PROCESS AFTER INPUT.
LOOP AT gt_ztmm_e002.
MODULE modify_data_1002.
ENDLOOP.
MODULE user_command_1002.
3-2:1002屏幕OUTPUT模块代码:
MODULE status_1002 OUTPUT.
SET PF-STATUS 'ZTMM_STATE'.
SET TITLEBAR 'ZTMM_E001_02'.
DESCRIBE TABLE gt_ztmm_e002 LINES lv_line. ztmm_1002-lines = lv_line.
IF gt_ztmm_e002 IS INITIAL.
lv_bldat = sy-datum.
lv_budat = sy-datum.
lv_bwart = '412'.
lv_sobkz = 'E'.
ENDIF.
ENDMODULE. " STATUS_1002 OUTPUT
*----------------------------------------------------------------------*
* MODULE display_ztmm_1002 OUTPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE display_ztmm_1002 OUTPUT.
READ TABLE gt_ztmm_e002 INTO ztmm_e001 INDEX ztmm_1002-current_line. " DISPLAY OUTP UT
ENDMODULE. "display_ztmm_1002 OUTPUT
3-3:1002屏幕INPUT模块代码:
*----------------------------------------------------------------------*
***INCLUDE ZTMM_E001_USER_COMMAND_1002I01 .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_1002 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_1002 INPUT.
save_ok = sy-ucomm. "ok_code .
CASE save_ok.
WHEN 'EXIT' OR 'BACK' OR 'CANC'.
PERFORM clear_data.
SET SCREEN 0. LEAVE SCREEN.
WHEN 'SAVE'.
PERFORM save_data_1002.
WHEN 'BTN_CLEAR' .
FREE:gt_ztmm_e002. "清空列表
WHEN 'BTN_GET_STOCK'.
PERFORM get_data_1002. "读取数据。
ENDCASE.
ENDMODULE. " USER_COMMAND_1002 INPUT
*&---------------------------------------------------------------------*
*& Form save_data_1001
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM save_data_1002.
* ========================== 验证数据 ========================== LOOP AT gt_ztmm_e002 WHERE opt = 'X'.
IF gt_ztmm_e002-opt = 'X'.
IF gt_ztmm_e002-qty = '' OR gt_ztmm_e002-lgort_in = ''.
MESSAGE '输入信息不完整' TYPE 'I'.
RETURN.
ENDIF.
ENDIF.
IF gt_ztmm_e002-qty > gt_ztmm_e002-menge.
MESSAGE '移动数应小于或等于原仓位数' TYPE 'I'.
gt_ztmm_e002-qty = ''.
RETURN.
ENDIF.
ENDLOOP.
* ========================== 保留数据 ==========================
DATA:zt_gm_head_01 LIKE bapi2017_gm_head_01.
DATA:zt_code LIKE bapi2017_gm_code.
DATA:zt_ret_doc LIKE bapi2017_gm_head_ret.
DATA:zt_goodsmvt_item LIKE TABLE OF /afs/bapi2017_gm_item_create WITH HEADER LINE. DATA:materialdocument TYPE bapi2017_gm_head_ret-mat_doc.
DATA:zreturn LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
zreturngr LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
DATA:loc_msg(50),
errflag(1),
lv_year LIKE zt_ret_doc-doc_year .
CLEAR:zt_gm_head_01,zt_goodsmvt_item,zt_code,zt_ret_doc.
" 移动主信息
zt_gm_head_01-pstng_date = lv_budat. "过帐日期
zt_gm_head_01-doc_date = lv_bldat. "凭证日期
zt_gm_head_01-pr_uname = sy-uname. "创建人
zt_code-gm_code = '04'. "货物移动事务代码 MB1B
zt_ret_doc-doc_year = sy-datum. "凭证年份
" 移动明细信息
LOOP AT gt_ztmm_e002 WHERE opt = 'X'.
zt_goodsmvt_item-material = gt_ztmm_e002-matnr. "物料号
zt_goodsmvt_item-plant = gt_ztmm_e002-werks_out. "工厂
zt_goodsmvt_item-stge_loc = gt_ztmm_e002-lgort_in. "仓位
zt_goodsmvt_item-batch = gt_ztmm_e002-charg. "批号
zt_goodsmvt_item-move_type = gt_ztmm_e002-bwart. "移动类型
zt_goodsmvt_item-spec_stock = 'E'. "特殊库存标识
zt_goodsmvt_item-sales_ord = gt_ztmm_e002-vbeln_in. "销售单
zt_goodsmvt_item-s_ord_item = gt_ztmm_e002-posnr_in. "销售项目
zt_goodsmvt_item-entry_qnt = gt_ztmm_e002-qty. "输入数量
zt_goodsmvt_item-move_mat = gt_ztmm_e002-matnr. "移动物料号 zt_goodsmvt_item-move_plant = gt_ztmm_e002-werks_out."移入工厂 zt_goodsmvt_item-move_stloc = gt_ztmm_e002-lgort_out."移动仓位
zt_goodsmvt_item-move_batch = gt_ztmm_e002-charg. "移动批号
zt_goodsmvt_item-grid_value = gt_ztmm_e002-j_3asize. "网格值
zt_goodsmvt_item-entry_uom = gt_ztmm_e002-meins. "单位
zt_goodsmvt_item-val_sales_ord = gt_ztmm_e002-vbeln_in. "销售单
zt_goodsmvt_item-val_s_ord_item = gt_ztmm_e002-posnr_in. "销售项目
zt_goodsmvt_item-nb_slips = 1.
APPEND zt_goodsmvt_item.
ENDLOOP.
DESCRIBE TABLE zt_goodsmvt_item LINES lv_line.
IF lv_line > 0 AND NOT zt_goodsmvt_item[] IS INITIAL.
CALL FUNCTION '/AFS/BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = zt_gm_head_01
goodsmvt_code = zt_code-gm_code
IMPORTING
goodsmvt_headret = zt_ret_doc
materialdocument = materialdocument
TABLES
afs_goodsmvt_item = zt_goodsmvt_item
return = zreturn.
ENDIF.
LOOP AT zreturn.
CLEAR:loc_msg.
CONCATENATE '过帐无效: ' zreturn-message INTO loc_msg. IF zreturn-type EQ 'E'.
MESSAGE loc_msg TYPE 'S'.
errflag = 'X'.
ELSE.
MESSAGE zreturn-message TYPE 'S'.
ENDIF.
ENDLOOP.
IF errflag IS INITIAL AND lv_line > 0.
COMMIT WORK AND WAIT.
CLEAR loc_msg.
IF sy-subrc NE 0.
MESSAGE s000(oo) WITH '过帐操作显现错误,请稍后再重试!' DISPLAY LIKE 'E'. EXIT.
ELSE.
CONCATENATE '过帐成功!物料凭证号:' materialdocument INTO loc_msg.
MESSAGE loc_msg TYPE 'S'.
ENDIF.
ELSE.
MESSAGE loc_msg TYPE 'S'.
ENDIF.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDFORM. "SAVE_DATA
*&---------------------------------------------------------------------* *& Form get_bwart_1001
*&---------------------------------------------------------------------* * text
*----------------------------------------------------------------------* FORM get_bwart_1002. "移动类型,销售单,项目号
LOOP AT gt_ztmm_e002.
gt_ztmm_e002-bwart = '412'.
IF lv_vbeln NE ''.
gt_ztmm_e002-vbeln_in = lv_vbeln.
ENDIF.
IF lv_posnr NE ''.
gt_ztmm_e002-posnr_in = lv_posnr.
ENDIF.
MODIFY gt_ztmm_e002.
ENDLOOP.
ENDFORM. "get_bwart
*&---------------------------------------------------------------------* *& Form get_stock_data_1002
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get_stock_data_1002.
SELECT
mchb~werks AS werks_out "工厂
mchb~matnr "物料号
makt~maktx AS matnr_dsc "物料描述
mchb~j_3asize "网格值
mara~j_3apgnr "物料网格编号
mchb~lgort AS lgort_out "转出仓位
mchb~charg "批次
mchb~clabs AS menge "非限制利用库存(数量)
mara~meins "单位
INTO CORRESPONDING FIELDS OF TABLE gt_ztmm_e002
FROM mchb
INNER JOIN mara ON mara~matnr = mchb~matnr
INNER JOIN makt ON makt~matnr = mara~matnr AND makt~spras = '1' WHERE mchb~werks = lv_werks
AND mchb~matnr = lv_matnr.
SORT gt_ztmm_e002 BY werks_out matnr lgort_out j_3asize .
DELETE ADJACENT DUPLICATES FROM gt_ztmm_e002.
ENDFORM. "get_stock_data_1002
*&---------------------------------------------------------------------*
*& Form get_data_1002
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------* FORM get_data_1002.
IF lv_bldat IS INITIAL AND lv_budat IS INITIAL.
MESSAGE '请转输凭证日期及转帐日期' TYPE 'S'.
EXIT.
ENDIF.
IF lv_werks EQ ''.
MESSAGE s000(oo) WITH '请输入工厂代码' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
IF lv_matnr EQ ''.
MESSAGE s000(oo) WITH '请输入物料号' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
IF lv_vbeln EQ '' OR lv_posnr EQ ''.
MESSAGE s000(oo) WITH '请输入接收销售单及项目' DISPLAY LIKE 'E'. EXIT.
ENDIF.
PERFORM get_stock_data_1002. "读取库存数据
PERFORM get_bwart_1002. "移动类型,销售单,项目号
CLEAR:gt_ztmm_e001.
DESCRIBE TABLE gt_ztmm_e001 LINES lv_line.
IF lv_line EQ 0.
gt_ztmm_e001[] = gt_ztmm_e002[].
PERFORM get_matnrdesc. "网络值描述
gt_ztmm_e002[] = gt_ztmm_e001[].
REFRESH gt_ztmm_e001.
ENDIF.
ENDFORM. "get_data_1002
*----------------------------------------------------------------------*
* MODULE modify_data INPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE modify_data_1002 INPUT.
MODIFY gt_ztmm_e002 FROM ztmm_e001 INDEX ztmm_1002-current_line. ENDMODULE. "modify_data INPUT
由以下代码执行得出以下界面:
4-1:1003屏幕逻辑流
PROCESS BEFORE OUTPUT.
FIELD !lv_bldat MODULE %_lv_bldat.
FIELD !lv_budat MODULE %_lv_budat.
FIELD !lv_werks MODULE %_lv_werks.
FIELD !lv_vbeln MODULE %_lv_vbeln.
FIELD !lv_posnr MODULE %_lv_posnr.
FIELD !lv_vbeln_in MODULE %_lv_vbeln_in.
FIELD !lv_posnr_in MODULE %_lv_posnr_in.
FIELD !lv_bwart MODULE %_lv_bwart.
FIELD !lv_sobkz MODULE %_lv_sobkz.
MODULE status_1003.
LOOP AT gt_ztmm_e003 WITH CONTROL ztmm_1003 CURSOR ztmm_1003-top_line. MODULE display_ztmm_1003.
ENDLOOP.
PROCESS AFTER INPUT.
LOOP AT gt_ztmm_e003.
MODULE modify_data_1003.
ENDLOOP.
MODULE user_command_1003.
4-2:1003屏幕OUTPUT模块代码:
MODULE status_1003 OUTPUT.
SET PF-STATUS 'ZTMM_STATE'.
SET TITLEBAR 'ZTMM_E001_03'.
DESCRIBE TABLE gt_ztmm_e003 LINES lv_line.
ztmm_1003-lines = lv_line.
IF gt_ztmm_e003 IS INITIAL.
lv_bldat = sy-datum.
lv_budat = sy-datum.
lv_bwart = '413'.
lv_sobkz = 'E'.
ENDIF.
ENDMODULE. " STATUS_1003 OUTPUT
*----------------------------------------------------------------------* * MODULE display_ztmm_1003 OUTPUT
*----------------------------------------------------------------------*。