程序目标:VL02N批次拆分操作起来太不友好了,用户想要一个能自动按照库存批次拆分的程序,同时还想要能手动挑选批次拆分的物料批次。
先上代码,后附代码解析,按照步骤来复制到本地可以直接运行使用
*&---------------------------------------------------------------------*
*& Report ZSD_R0028
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZSD_R0028.
TABLES: SSCRFIELDS,STXFTXT,T001." ---TODO
TYPE-POOLS:ICON.
DATA: OK_CODE LIKE SY-UCOMM.
CLASS LCL_EVENT_RECEIVER DEFINITION DEFERRED.
DATA: EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER.
DATA: EVENT_RECEIVER8000 TYPE REF TO LCL_EVENT_RECEIVER.
DATA: GT_FIELDCAT TYPE LVC_T_FCAT,
GS_LAYOUT TYPE LVC_S_LAYO,
GS_VARIANT TYPE DISVARIANT,
GT_T_F4 TYPE LVC_T_F4,
IT_TOOLBAR_EXCLUDING TYPE UI_FUNCTIONS.
DATA: STBL TYPE LVC_S_STBL. "鼠标游标位置
DATA: ET_FILTERED TYPE LVC_T_FIDX.
DATA: GV_CODE TYPE SY-TCODE .
DATA ALV_GRID TYPE REF TO CL_GUI_ALV_GRID. "后面要用到CL_GUI_ALV_GRID类中的方法
DATA ALV_GRID8000 TYPE REF TO CL_GUI_ALV_GRID. "后面要用到CL_GUI_ALV_GRID类中的方法
"SET_TABLE_FIRST_DISPLAY,这个方法基于实例存在,必须
"为这个类创建一个对象。在此处声明。
DATA GS_PARENT TYPE REF TO CL_GUI_CUSTOM_CONTAINER . "定义容器
DATA GT_SELCELL TYPE LVC_T_CELL . "定義選中單元格方法參數
DATA GT_SELROW TYPE LVC_T_ROW . "定義選中行方法參數
*DATA: gr_table TYPE REF TO cl_salv_table.
*DATA: lr_functions TYPE REF TO cl_salv_functions.
"$. Region 此处定义改为需要用到的定义-TODO
TYPES : BEGIN OF TY_ITEM ,
VBELN TYPE LIPS-VBELN , "交貨
POSNR TYPE LIPS-POSNR , "項目
WERKS TYPE LIPS-WERKS , "工廠
LGORT TYPE LIPS-LGORT , "儲存地點
CHARG TYPE LIPS-CHARG , "批次
LFIMG TYPE LIPS-LFIMG , "交貨數量
VRKME TYPE LIPS-VRKME , "銷售單位
ARKTX TYPE LIPS-ARKTX , "項目說明
UECHA TYPE LIPS-UECHA , "上层项目号
MATNR TYPE MATNR,
LINE_COLOR TYPE C LENGTH 4 , "颜色
CELLCOLOR TYPE LVC_T_SCOL . "颜色
TYPES END OF TY_ITEM .
DATA GT_ITEM TYPE TABLE OF TY_ITEM .
DATA GS_ITEM TYPE TY_ITEM .
DATA GS_ITEM2 TYPE TY_ITEM .
DATA GS_ITEM3 TYPE TY_ITEM .
DATA GT_LIPS TYPE TABLE OF LIPS . "存储数量合计数据
DATA GS_LIPS TYPE LIPS .
DATA GS_LIKP TYPE LIKP .
DATA GV_ACCOMPLISH TYPE C . "
DATA GV_SPLIT TYPE C . "
DATA WA_CELLCOLOR TYPE LVC_S_SCOL. " 单元格颜色结构
TYPES : BEGIN OF TY_ITEM_SUM ,
WERKS TYPE LIPS-WERKS , "工廠
LGORT TYPE LIPS-LGORT , "儲存地點
CHARG TYPE LIPS-CHARG , "批次
LFIMG TYPE LIPS-LFIMG , "批次已用數量
VRKME TYPE LIPS-VRKME , "銷售單位
MATNR TYPE MATNR.
TYPES END OF TY_ITEM_SUM .
DATA GT_ITEM_SUM TYPE TABLE OF TY_ITEM_SUM .
DATA GS_ITEM_SUM TYPE TY_ITEM_SUM .
TYPES : BEGIN OF TY_8000 ,
CHBOX TYPE C ,
VBELN TYPE LIPS-VBELN , "交貨
POSNR TYPE LIPS-POSNR , "項目
WERKS TYPE LIPS-WERKS , "工廠
LGORT TYPE LIPS-LGORT , "儲存地點
CHARG TYPE LIPS-CHARG , "批次
LFIMC TYPE LIPS-LFIMG , "批次數量
LFIMA TYPE LIPS-LFIMG , "批次已用數量
LFIMG TYPE LIPS-LFIMG , "交貨數量
VRKME TYPE LIPS-VRKME , "銷售單位
ARKTX TYPE LIPS-ARKTX , "項目說明
UECHA TYPE LIPS-UECHA , "上层项目号
MATNR TYPE MATNR,
LINE_COLOR(4) , "颜色
CELLCOLOR TYPE LVC_T_SCOL . "颜色
TYPES END OF TY_8000 .
DATA GT_8000 TYPE TABLE OF TY_8000 .
DATA GS_8000 TYPE TY_8000 .
TYPES : BEGIN OF TY_MB52 ,
MATNR TYPE MATNR,
MAKTX TYPE MAKTX,
WERKS TYPE WERKS_D,
CHARG TYPE CHARG_D,
ERSDA TYPE DATUM,
LGORT TYPE LGORT_D,
EISBE TYPE EISBE , "安全库存数
LABST TYPE LABST , "现有库存数
DELTE TYPE C , "删除标记
MEINS TYPE MEINS.
TYPES END OF TY_MB52 .
DATA GT_MB52_RAW TYPE TABLE OF TY_MB52 . "原始庫存數據
DATA GT_MB52 TYPE TABLE OF TY_MB52 .
DATA GS_MB52 TYPE TY_MB52 .
FIELD-SYMBOLS TYPE TY_MB52 .
"$. Endregion 此处定义改为需要用到的定义-TODO
DATA: GS_DN_HDATA LIKE BAPIOBDLVHDRCHG,
GS_DN_HCTRL LIKE BAPIOBDLVHDRCTRLCHG,
GS_DN_CTRL LIKE BAPIDLVCONTROL,
GS_DN_ISPL LIKE /SPE/BAPIOBDLVITEMCHG.
DATA: GT_DN_IDATA LIKE TABLE OF BAPIOBDLVITEMCHG,
GT_DN_ICTRL LIKE TABLE OF BAPIOBDLVITEMCTRLCHG,
GS_DN_IDATA LIKE BAPIOBDLVITEMCHG,
GS_DN_ICTRL LIKE BAPIOBDLVITEMCTRLCHG,
GT_DN_ISPL LIKE TABLE OF /SPE/BAPIOBDLVITEMCHG.
DATA: GT_RETN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
DATA :VBELN TYPE LIPS-VBELN ,
POSNR TYPE LIPS-POSNR ,
SEL_NUMB TYPE LIPS-LFIMG ,
TOTLE TYPE LIPS-LFIMG .
*&---------------------------------------------------------------------*
*& Class LCL_EVENT_RECEIVER
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
CLASS LCL_EVENT_RECEIVER DEFINITION.
PUBLIC SECTION.
METHODS HANDLE_DOUBLE_CLICK FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID "定义类中的方法---双击
IMPORTING E_ROW E_COLUMN ES_ROW_NO.
METHODS HANDLE_DOUBLE_CLICK8000 FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID "定义类中的方法---双击
IMPORTING E_ROW E_COLUMN ES_ROW_NO. "
" "
METHODS HANDLE_ONF4 FOR EVENT ONF4 OF CL_GUI_ALV_GRID "定义类中的方法---F4帮助
IMPORTING E_FIELDNAME ES_ROW_NO ER_EVENT_DATA . "
"
METHODS HANDLE_TOOLBAR FOR EVENT TOOLBAR OF CL_GUI_ALV_GRID "定义类中的方法---ALV状态栏按钮
IMPORTING E_OBJECT E_INTERACTIVE . "
"
METHODS HANDLE_USER_COMMAND FOR EVENT USER_COMMAND OF CL_GUI_ALV_GRID "定义类中的方法---按钮触发方法
IMPORTING E_UCOMM . "
"
METHODS HANDLE_DATA_CHANGED FOR EVENT DATA_CHANGED OF CL_GUI_ALV_GRID "定义类中的方法---数据被修改后方法
IMPORTING ER_DATA_CHANGED E_ONF4 E_ONF4_BEFORE E_ONF4_AFTER E_UCOMM. "
METHODS HANDLE_DATA_CHANGED8000 FOR EVENT DATA_CHANGED OF CL_GUI_ALV_GRID "定义类中的方法---数据被修改后方法
IMPORTING ER_DATA_CHANGED E_ONF4 E_ONF4_BEFORE E_ONF4_AFTER E_UCOMM.
METHODS FINISHED_DATA_CHANGED8000 FOR EVENT DATA_CHANGED_FINISHED OF CL_GUI_ALV_GRID "定义类中的方法---数据被修改后方法
IMPORTING E_MODIFIED ET_GOOD_CELLS.
ENDCLASS. "LCL_EVENT_RECEIVER
"$. Endregion 定义
"$. Region 选择屏幕-TODO
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS : P_VBELN TYPE LIKP-VBELN MEMORY ID VL.
SELECTION-SCREEN END OF BLOCK B1 .
*SELECTION-SCREEN PUSHBUTTON 1(22) BUT1 USER-COMMAND DOWNLOAD .
SELECTION-SCREEN: FUNCTION KEY 1 . "激活按钮1
SELECTION-SCREEN: FUNCTION KEY 2 . "激活按钮2
*SELECTION-SCREEN: FUNCTION KEY 3 . "激活按钮3
"$. Endregion 选择屏幕-TODO
INITIALIZATION.
STBL-ROW = 'X'.
STBL-COL = 'X'.
* CALL FUNCTION 'ICON_CREATE' " 给按钮添加图标和文本
* EXPORTING
* NAME = 'ICON_EXPORT' " 按钮的图片的名字 ICON_EXPORT
* TEXT = '模版下载' "按钮的文本
* INFO = '功能'
* IMPORTING
* RESULT = BUT1
* EXCEPTIONS
* OTHERS = 0.
SSCRFIELDS-FUNCTXT_01 = '@B_TXDP@ VL02N查看交貨單' . "设置按钮
SSCRFIELDS-FUNCTXT_02 = '@B_TXCR@ VL10H創建交貨單' .
SSCRFIELDS-FUNCTXT_03 = '@5Y@ 回車執行' .
AT SELECTION-SCREEN.
"$. Region 权限-TODO
* SELECT T001~BUKRS FROM T001 WHERE T001~BUKRS IN @S_BUKRS INTO TABLE @DATA(GT_BUKRS) .
*
* LOOP AT GT_BUKRS INTO DATA(GS_BUKRS).
* AUTHORITY-CHECK OBJECT 'F_BKPF_BUK'
* ID 'BUKRS' FIELD GS_BUKRS-BUKRS
* ID 'ACTVT' FIELD '03'.
* IF SY-SUBRC <> 0.
* MESSAGE '您没有公司代码' && GS_BUKRS-BUKRS && '的操作权限!' TYPE 'E' .
*
* ENDIF.
*
* ENDLOOP.
"$. Endregion 权限-TODO
CASE SSCRFIELDS-UCOMM.
WHEN 'FC01'.
SET PARAMETER ID 'VL' FIELD P_VBELN .
CALL TRANSACTION 'VL02N' AND SKIP FIRST SCREEN .
WHEN 'FC02'.
CALL TRANSACTION 'VL10H' .
WHEN OTHERS.
ENDCASE.
START-OF-SELECTION.
PERFORM FRM_CHECK_IF_ACCOMPLISH . "過賬完成的交貨單跳轉至VL02N不可修改換批
PERFORM FRM_GET_DATA_MB52 . "获取库存数据
PERFORM FRM_GET_DATA_LIPS. "獲取交貨單明細
IF GT_ITEM[] IS NOT INITIAL .
CALL SCREEN 9000.
ENDIF.
"$. Region FORM
MODULE STATUS_9000 OUTPUT.
SET PF-STATUS '9000'.
SET TITLEBAR '9000'.
DATA(GV_FRIST) = 'X' . "判断是不是第一次运行,自添加按钮需要刷新才能显示
PERFORM FRM_DISPLAY_ALV.
IF GV_FRIST = 'X'.
PERFORM PREPARE_LAYOUT CHANGING GS_LAYOUT.
CALL METHOD ALV_GRID->SET_FRONTEND_LAYOUT
EXPORTING
IS_LAYOUT = GS_LAYOUT.
CALL METHOD ALV_GRID->REFRESH_TABLE_DISPLAY "增加按钮需要刷新才会显示出来,否则无法显示。
EXPORTING
IS_STABLE = STBL.
GV_FRIST = '0' ."判断是否为第一次,为第一次则刷新
ENDIF.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_9000 INPUT.
GV_CODE = OK_CODE .
CASE OK_CODE.
WHEN 'BACK'.
CLEAR: GT_ITEM.
LEAVE TO SCREEN 0.
WHEN 'SAVE'.
PERFORM FRM_CREAT_SPLIT_DN . "创建交货单批次拆分
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'CANCEL'.
CLEAR: GT_ITEM.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE.
MODULE STATUS_8000 OUTPUT.
SET PF-STATUS '8000'.
SET TITLEBAR '8000'.
GV_FRIST = 'X' . "判断是不是第一次运行,自添加按钮需要刷新才能显示
PERFORM FRM_DISPLAY_ALV_8000.
IF GV_FRIST = 'X'.
PERFORM PREPARE_LAYOUT CHANGING GS_LAYOUT.
CALL METHOD ALV_GRID8000->SET_FRONTEND_LAYOUT
EXPORTING
IS_LAYOUT = GS_LAYOUT.
CALL METHOD ALV_GRID8000->REFRESH_TABLE_DISPLAY "增加按钮需要刷新才会显示出来,否则无法显示。
EXPORTING
IS_STABLE = STBL.
GV_FRIST = '0' ."判断是否为第一次,为第一次则刷新
ENDIF.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_8000 INPUT.
DATA LV_POSNR TYPE LIPS-POSNR VALUE '90001'.
DATA LV_SUBRC TYPE SY-SUBRC VALUE '0'.
GV_CODE = OK_CODE .
CASE OK_CODE.
WHEN 'SAVE'.
PERFORM FRM_SAVE_CHECK CHANGING LV_SUBRC . "檢查8000子屏幕數據有無問題
CHECK LV_SUBRC = 0 .
DELETE GT_ITEM WHERE UECHA = POSNR . "刪除原有數據,替換為手動選擇的數據
READ TABLE GT_ITEM WITH KEY POSNR = POSNR INTO GS_ITEM .
DATA(LV_LIN) = SY-TABIX + 1 .
LOOP AT GT_8000 INTO GS_8000 WHERE CHBOX = 'X' AND LFIMG <> 0.
GS_ITEM-LGORT = GS_8000-LGORT .
GS_ITEM-CHARG = GS_8000-CHARG .
GS_ITEM-LFIMG = GS_8000-LFIMG .
GS_ITEM-UECHA = POSNR .
GS_ITEM-VBELN = VBELN .
GS_ITEM-LINE_COLOR = '' .
CLEAR : GS_ITEM-CELLCOLOR .
INSERT GS_ITEM INTO GT_ITEM INDEX LV_LIN .
ENDLOOP.
LV_POSNR = '90001'.
PERFORM FRM_REFRESH_POSNR . "數據修改完後,重編項次
PERFORM FRM_REFRESH_COLOUR . "數據修改完後,重編顏色
PERFORM PREPARE_LAYOUT CHANGING GS_LAYOUT . "重設layout 防止失效,也可根據數據變化同步修改最佳列寬
CALL METHOD ALV_GRID->SET_FRONTEND_LAYOUT
EXPORTING
IS_LAYOUT = GS_LAYOUT.
CALL METHOD ALV_GRID->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = STBL.
LEAVE TO SCREEN 0.
WHEN 'REF'.
WHEN 'CANCEL'.
CLEAR: GT_8000.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE.
*----------------------------------------------------------------------*
* CLASS LCL_EVENT_RECEIVER IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.
METHOD HANDLE_DOUBLE_CLICK.
CASE E_COLUMN.
WHEN 'LFIMG'.
PERFORM FRM_GET_8000_DATA USING E_ROW .
CALL SCREEN 8000 STARTING AT 20 1 ENDING AT 150 26. "調用8000子屏幕
WHEN 'VBELN'.
WHEN 'MATNR'.
WHEN OTHERS.
ENDCASE.
ENDMETHOD. "HANDLE_DOUBLE_CLICK双击后触发该段代码,可接T-CODE跳转等功能
METHOD HANDLE_DOUBLE_CLICK8000.
ENDMETHOD. "HANDLE_DOUBLE_CLICK双击后触发该段代码,可接T-CODE跳转等功能
METHOD HANDLE_ONF4.
ENDMETHOD. "需在ALV中调用触发一般与filedcat中的 f4availabl 参数同用
METHOD HANDLE_TOOLBAR. "在ALV状态栏增加按钮,一般是汇总按钮,新增后的按钮可触发HANDLE_USER_COMMAND方法
DATA: LS_TOOLBAR TYPE STB_BUTTON.
CLEAR LS_TOOLBAR.
MOVE 3 TO LS_TOOLBAR-BUTN_TYPE. "分隔符
APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
CLEAR LS_TOOLBAR.
MOVE 'DEL' TO LS_TOOLBAR-FUNCTION. "功能码
MOVE ICON_DELETE_ROW TO LS_TOOLBAR-ICON. "图标
MOVE '刪除自選行' TO LS_TOOLBAR-QUICKINFO.
MOVE '刪除自選行' TO LS_TOOLBAR-TEXT. "显示名称
MOVE ' ' TO LS_TOOLBAR-DISABLED.
APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
CLEAR LS_TOOLBAR.
MOVE 'CLEAR' TO LS_TOOLBAR-FUNCTION. "功能码
MOVE ICON_DELETE TO LS_TOOLBAR-ICON. "图标
MOVE '清空批次拆分' TO LS_TOOLBAR-QUICKINFO.
MOVE '清空批次拆分' TO LS_TOOLBAR-TEXT. "显示名称
MOVE ' ' TO LS_TOOLBAR-DISABLED.
APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
CLEAR LS_TOOLBAR.
MOVE 'ADD' TO LS_TOOLBAR-FUNCTION. "功能码
MOVE ICON_INSERT_ROW TO LS_TOOLBAR-ICON. "图标
MOVE '重新自選' TO LS_TOOLBAR-QUICKINFO.
MOVE '重新自選' TO LS_TOOLBAR-TEXT. "显示名称
MOVE ' ' TO LS_TOOLBAR-DISABLED.
APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
ENDMETHOD. "在ALV状态栏增加按钮,一般是汇总按钮
METHOD HANDLE_USER_COMMAND.
CASE E_UCOMM.
WHEN 'ADD'.
CLEAR : GT_ITEM,GS_ITEM,GT_MB52,GS_MB52 .
GT_MB52 = GT_MB52_RAW .
DELETE GT_MB52 WHERE DELTE = 'X' .
SORT GT_MB52 BY WERKS MATNR CHARG ERSDA .
PERFORM FRM_GET_DATA_LIPS .
WHEN 'DEL'.
CALL METHOD ALV_GRID->GET_SELECTED_ROWS
IMPORTING
ET_INDEX_ROWS = GT_SELROW.
LOOP AT GT_SELROW INTO DATA(GS_SELROW).
CLEAR : GS_ITEM .
GS_ITEM = GT_ITEM[ GS_SELROW-INDEX ] .
IF GS_ITEM-POSNR > 90000.
READ TABLE GT_ITEM WITH KEY POSNR = GS_ITEM-UECHA ASSIGNING FIELD-SYMBOL() .
-LFIMG = -LFIMG + GS_ITEM-LFIMG .
DELETE GT_ITEM[] INDEX GS_SELROW-INDEX .
ENDIF.
ENDLOOP .
WHEN 'CLEAR' .
CLEAR:GT_ITEM ,GS_ITEM ,GS_LIPS.
LOOP AT GT_LIPS INTO GS_LIPS WHERE POSNR < 90000.
MOVE-CORRESPONDING GS_LIPS TO GS_ITEM .
GS_ITEM-LFIMG = GS_LIPS-ORMNG .
GS_ITEM-LINE_COLOR = 'C100' .
APPEND GS_ITEM TO GT_ITEM .
ENDLOOP.
WHEN OTHERS.
ENDCASE.
PERFORM PREPARE_LAYOUT CHANGING GS_LAYOUT.
CALL METHOD ALV_GRID->SET_FRONTEND_LAYOUT
EXPORTING
IS_LAYOUT = GS_LAYOUT.
CALL METHOD ALV_GRID->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = STBL.
ENDMETHOD. "一般与HANDLE_TOOLBAR同用
METHOD HANDLE_DATA_CHANGED.
ENDMETHOD. "数据修改后触发,一般用在数据联动修改如数量字段修改,同时联动修改金额字段
METHOD FINISHED_DATA_CHANGED8000.
DATA LV_SELECTED TYPE LIPS-LFIMG .
DATA LT_DYNPREAD TYPE TABLE OF DYNPREAD.
DATA LS_DYNPREAD TYPE DYNPREAD.
CALL METHOD ALV_GRID8000->GET_SELECTED_CELLS
IMPORTING
ET_CELL = GT_SELCELL .
LOOP AT GT_SELCELL INTO DATA(LS_SELCELL).
CLEAR :GS_8000 .
READ TABLE GT_8000 ASSIGNING FIELD-SYMBOL() INDEX LS_SELCELL-ROW_ID .
CASE LS_SELCELL-COL_ID .
WHEN 'CHBOX'.
IF -CHBOX = 'X'.
CLEAR : GS_8000 .
LOOP AT GT_8000 INTO GS_8000 WHERE CHBOX = 'X' .
LV_SELECTED = GS_8000-LFIMG + LV_SELECTED .
ENDLOOP.
IF -LFIMG = 0.
IF TOTLE - LV_SELECTED >= -LFIMA.
-LFIMG = -LFIMA .
ELSE .
-LFIMG = TOTLE - LV_SELECTED .
ENDIF.
ENDIF.
ELSE .
-LFIMG = 0 .
ENDIF.
WHEN 'LFIMG'.
WHEN OTHERS.
ENDCASE.
ENDLOOP.
CLEAR:SEL_NUMB, GS_8000 .
LOOP AT GT_8000 INTO GS_8000 WHERE CHBOX = 'X'.
SEL_NUMB = SEL_NUMB + -LFIMG .
ENDLOOP.
PERFORM PREPARE_LAYOUT CHANGING GS_LAYOUT.
CALL METHOD ALV_GRID8000->SET_FRONTEND_LAYOUT
EXPORTING
IS_LAYOUT = GS_LAYOUT.
CALL METHOD ALV_GRID8000->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = STBL.
"*- 更新8000屏幕上的一個字段
* LS_DYNPREAD-FIELDNAME = 'SEL_NUMB' .
* LS_DYNPREAD-FIELDVALUE = SEL_NUMB .
* APPEND LS_DYNPREAD TO LT_DYNPREAD .
* CALL FUNCTION 'DYNP_UPDATE_FIELDS'
* EXPORTING
* DYNAME = SY-REPID
* DYNUMB = SY-DYNNR
* TABLES
* DYNPFIELDS = LT_DYNPREAD
* .
ENDMETHOD. "
METHOD HANDLE_DATA_CHANGED8000.
ENDMETHOD. "数据修改后触发,一般用在数据联动修改如数量字段修改,同时联动修改金额字段
ENDCLASS. "LCL_EVENT_RECEIVER IMPLEMENTATION
*&---------------------------------------------------------------------*
*& Form FRM_DISPLAY_ALV
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_DISPLAY_ALV .
CLEAR: GT_FIELDCAT,GS_LAYOUT,IT_TOOLBAR_EXCLUDING.
GS_VARIANT-REPORT = SY-REPID.
GS_VARIANT-HANDLE = '0001'.
IF ALV_GRID IS INITIAL .
******实例化 容器
CREATE OBJECT GS_PARENT
EXPORTING
CONTAINER_NAME = 'ALV'. " 界面中的一个CUNSTOMER CONTROL控件 用于存放类对象。
"使用这个控件把名称赋值给CONTAINER_NAME
******将alv植入到容器中
CREATE OBJECT ALV_GRID
EXPORTING
I_PARENT = GS_PARENT.
PERFORM PREPARE_FIELD_CATALOG CHANGING GT_FIELDCAT.
PERFORM PREPARE_LAYOUT CHANGING GS_LAYOUT.
PERFORM TOOLBAR_EXCLUDING_ITEM CHANGING IT_TOOLBAR_EXCLUDING. "ALV按钮排除EXPORTING参数
CALL METHOD ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = GS_LAYOUT
I_SAVE = 'A'
I_DEFAULT = 'X'
IS_VARIANT = GS_VARIANT
IT_TOOLBAR_EXCLUDING = IT_TOOLBAR_EXCLUDING
CHANGING
IT_OUTTAB = GT_ITEM
IT_FIELDCATALOG = GT_FIELDCAT.
CREATE OBJECT EVENT_RECEIVER. "创建事件
SET HANDLER EVENT_RECEIVER->HANDLE_DOUBLE_CLICK FOR ALV_GRID. "双击事件
SET HANDLER EVENT_RECEIVER->HANDLE_ONF4 FOR ALV_GRID. "F4帮助事件
SET HANDLER EVENT_RECEIVER->HANDLE_TOOLBAR FOR ALV_GRID. "ALV状态栏
SET HANDLER EVENT_RECEIVER->HANDLE_USER_COMMAND FOR ALV_GRID. "按钮事件
SET HANDLER EVENT_RECEIVER->HANDLE_DATA_CHANGED FOR ALV_GRID. "修改事件
* gt_t_f4 = VALUE #( BASE gt_t_f4 ( fieldname = 'ZBB' register = 'X' getbefore = 'X' chngeafter = 'X' ) ) .
* CALL METHOD alv_grid->register_f4_for_fields
* EXPORTING
* it_f4 = gt_t_f4.
CALL METHOD ALV_GRID->REGISTER_EDIT_EVENT "注册编辑事件,否则不会触发更新事件
EXPORTING
I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_MODIFIED.
PERFORM PREPARE_LAYOUT CHANGING GS_LAYOUT.
CALL METHOD ALV_GRID->SET_FRONTEND_LAYOUT
EXPORTING
IS_LAYOUT = GS_LAYOUT.
CALL METHOD CL_GUI_CONTROL=>SET_FOCUS
EXPORTING
CONTROL = ALV_GRID.
CALL METHOD CL_GUI_CFW=>FLUSH.
ELSE.
PERFORM PREPARE_LAYOUT CHANGING GS_LAYOUT.
CALL METHOD ALV_GRID->SET_FRONTEND_LAYOUT
EXPORTING
IS_LAYOUT = GS_LAYOUT.
CALL METHOD ALV_GRID->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = STBL.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_DISPLAY_ALV
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_DISPLAY_ALV_8000 .
CLEAR: GT_FIELDCAT,GS_LAYOUT,IT_TOOLBAR_EXCLUDING.
GS_VARIANT-REPORT = SY-REPID.
GS_VARIANT-HANDLE = '0001'.
IF ALV_GRID8000 IS INITIAL .
******实例化 容器
CREATE OBJECT GS_PARENT
EXPORTING
CONTAINER_NAME = 'SPLIT'. " 界面中的一个CUNSTOMER CONTROL控件 用于存放类对象。
"使用这个控件把名称赋值给CONTAINER_NAME
******将alv植入到容器中
CREATE OBJECT ALV_GRID8000
EXPORTING
I_PARENT = GS_PARENT.
PERFORM PREPARE_FIELD_CATALOG8000 CHANGING GT_FIELDCAT.
PERFORM PREPARE_LAYOUT CHANGING GS_LAYOUT.
PERFORM TOOLBAR_EXCLUDING_ITEM CHANGING IT_TOOLBAR_EXCLUDING. "ALV按钮排除EXPORTING参数
CALL METHOD ALV_GRID8000->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = GS_LAYOUT
I_SAVE = 'A'
I_DEFAULT = 'X'
IS_VARIANT = GS_VARIANT
IT_TOOLBAR_EXCLUDING = IT_TOOLBAR_EXCLUDING
CHANGING
IT_OUTTAB = GT_8000
IT_FIELDCATALOG = GT_FIELDCAT.
CREATE OBJECT EVENT_RECEIVER8000. "创建事件
SET HANDLER EVENT_RECEIVER8000->HANDLE_DOUBLE_CLICK8000 FOR ALV_GRID8000. "双击事件
SET HANDLER EVENT_RECEIVER8000->HANDLE_ONF4 FOR ALV_GRID8000. "F4帮助事件
* SET HANDLER EVENT_RECEIVER8000->HANDLE_TOOLBAR FOR ALV_GRID8000. "ALV状态栏
SET HANDLER EVENT_RECEIVER8000->HANDLE_USER_COMMAND FOR ALV_GRID8000. "按钮事件
SET HANDLER EVENT_RECEIVER8000->HANDLE_DATA_CHANGED8000 FOR ALV_GRID8000. "修改事件
SET HANDLER EVENT_RECEIVER8000->FINISHED_DATA_CHANGED8000 FOR ALV_GRID8000. "数据修改结束后
* gt_t_f4 = VALUE #( BASE gt_t_f4 ( fieldname = 'ZBB' register = 'X' getbefore = 'X' chngeafter = 'X' ) ) .
* CALL METHOD alv_grid->register_f4_for_fields
* EXPORTING
* it_f4 = gt_t_f4.
CALL METHOD ALV_GRID8000->REGISTER_EDIT_EVENT "注册编辑事件,否则不会触发更新事件
EXPORTING
I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_MODIFIED.
CALL METHOD CL_GUI_CONTROL=>SET_FOCUS
EXPORTING
CONTROL = ALV_GRID8000.
CALL METHOD CL_GUI_CFW=>FLUSH.
ELSE.
CALL METHOD ALV_GRID8000->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = STBL.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form PREPARE_FIELD_CATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GT_FIELDCAT text
*----------------------------------------------------------------------*
FORM PREPARE_FIELD_CATALOG CHANGING P_GT_FIELDCAT TYPE LVC_T_FCAT.
DATA LS_FCAT TYPE LVC_S_FCAT.
DEFINE SET_FCAT.
CLEAR ls_fcat.
ls_fcat-fieldname = &1. "字段
ls_fcat-coltext = &2. "描述
ls_fcat-EMPHASIZE = &3. "主键
ls_fcat-edit = &4. "可编辑
ls_fcat-ref_table = &5. "参考表
ls_fcat-ref_field = &6. "参考字段
ls_fcat-ICON = &7. "以圖標輸出
ls_fcat-NO_ZERO = &8. "前导0
ls_fcat-OUTPUTLEN = &9. "列的字符宽度
* ls_fcat-f4availabl = &8.
APPEND ls_fcat TO p_gt_fieldcat.
END-OF-DEFINITION.
SET_FCAT 'WERKS ' '工廠 ' '' '' 'LIPS' 'WERKS' '' '' ''.
SET_FCAT 'VBELN ' '交貨 ' '' '' 'LIPS' 'VBELN' '' '' ''.
SET_FCAT 'POSNR ' '項目 ' '' '' 'LIPS' 'POSNR' '' '' ''.
SET_FCAT 'MATNR ' '料號 ' '' '' 'LIPS' 'MATNR' '' '' ''.
SET_FCAT 'LGORT ' '儲存地點 ' '' '' 'LIPS' 'LGORT' '' '' ''.
SET_FCAT 'CHARG ' '批次 ' '' '' 'LIPS' 'CHARG' '' '' ''.
SET_FCAT 'LFIMG ' '交貨數量 ' '' '' 'LIPS' 'LFIMG' '' '' ''.
SET_FCAT 'VRKME ' '銷售單位 ' '' '' 'LIPS' 'VRKME' '' '' ''.
SET_FCAT 'ARKTX ' '項目說明 ' '' 'X' 'LIPS' 'ARKTX' '' '' ''.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form PREPARE_FIELD_CATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GT_FIELDCAT text
*----------------------------------------------------------------------*
FORM PREPARE_FIELD_CATALOG8000 CHANGING P_GT_FIELDCAT TYPE LVC_T_FCAT.
DATA LS_FCAT TYPE LVC_S_FCAT.
DEFINE SET_FCAT.
CLEAR ls_fcat.
ls_fcat-fieldname = &1. "字段
ls_fcat-coltext = &2. "描述
ls_fcat-EMPHASIZE = &3. "颜色
ls_fcat-edit = &4. "可编辑
ls_fcat-ref_table = &5. "参考表
ls_fcat-ref_field = &6. "参考字段
ls_fcat-CHECKBOX = &7. "勾选框
ls_fcat-NO_ZERO = &8. "前导0
ls_fcat-outputlen = &9. "列的字符宽度
* ls_fcat-f4availabl = &8.
APPEND ls_fcat TO p_gt_fieldcat.
END-OF-DEFINITION.
SET_FCAT 'CHBOX ' '選擇 ' '' 'X' '' '' 'X' '' ''.
SET_FCAT 'WERKS ' '工廠 ' '' '' 'LIPS' 'WERKS' '' '' ''.
SET_FCAT 'MATNR ' '料號 ' '' '' 'LIPS' 'MATNR' '' '' ''.
SET_FCAT 'LGORT ' '儲存地點 ' '' '' 'LIPS' 'LGORT' '' '' ''.
SET_FCAT 'CHARG ' '批次 ' '' '' 'LIPS' 'CHARG' '' '' ''.
SET_FCAT 'LFIMC ' '批次數量 ' '' '' 'LIPS' 'LFIMG' '' '' ''.
SET_FCAT 'LFIMA ' '批次可用數量' '' '' 'LIPS' 'LFIMG' '' '' ''.
SET_FCAT 'LFIMG ' '交貨數量 ' 'C400' 'X' 'LIPS' 'LFIMG' '' '' ''.
* SET_FCAT 'VRKME ' '銷售單位 ' '' '' 'LIPS' 'VRKME' '' '' ''.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form PREPARE_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM PREPARE_LAYOUT CHANGING P_GS_LAYOUT TYPE LVC_S_LAYO.
* P_GS_LAYOUT-ZEBRA = 'X'. "斑馬紋顯示
P_GS_LAYOUT-SEL_MODE = 'A'. "選擇模式
P_GS_LAYOUT-CWIDTH_OPT = 'X'. "最佳列寬
P_GS_LAYOUT-INFO_FNAME = 'LINE_COLOR'. " 行颜色字段
P_GS_LAYOUT-CTAB_FNAME = 'CELLCOLOR'. " 单元格颜色字段
ENDFORM.
FORM TOOLBAR_EXCLUDING_ITEM CHANGING PT_EXCLUDE TYPE UI_FUNCTIONS.
DATA LS_EXCLUDE TYPE UI_FUNC.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_DELETE_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_INSERT_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_APPEND_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE_NEW_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_MOVE_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_CUT.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_UNDO.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_GET_DATA_MB52 .
CHECK GV_ACCOMPLISH <> 'C' .
RANGES :S_WERKS FOR LIPS-WERKS .
RANGES :S_MATNR FOR LIPS-MATNR .
RANGES :S_LGORT FOR LIPS-LGORT .
S_WERKS = 'IEQ' .
S_WERKS-LOW = GS_LIKP-VSTEL .
APPEND S_WERKS .
S_MATNR = 'IEQ' .
CLEAR :GS_LIPS .
LOOP AT GT_LIPS INTO GS_LIPS WHERE POSNR < 900000 .
S_MATNR-LOW = GS_LIPS-MATNR .
APPEND S_MATNR .
ENDLOOP.
"可发料仓限定
SELECT * FROM ZTCOM_RBAC WHERE PROGNAME = @SY-CPROG AND UNAME = 'ZD' AND WERKS = @GS_LIKP-VSTEL INTO TABLE @DATA(LT_KFLC) .
S_LGORT = 'IEQ' .
LOOP AT LT_KFLC INTO DATA(LS_LFLC).
S_LGORT-LOW = LS_LFLC-LGORT .
APPEND S_LGORT .
ENDLOOP.
FIELD-SYMBOLS : TYPE ANY TABLE .
CL_SALV_BS_RUNTIME_INFO=>SET(
DISPLAY = ABAP_FALSE
METADATA = ABAP_FALSE
DATA = ABAP_TRUE ).
SUBMIT RM07MLBS "MB52库存清单
WITH WERKS IN S_WERKS "
WITH MATNR IN S_MATNR "
* WITH LGORT IN S_LGORT "
WITH NEGATIV = ''
WITH PA_SOND = ''
WITH XMCHB = 'X'
WITH NOZERO = 'X'
WITH NOVALUES = ''
WITH PA_HSQ = ''
WITH PA_FLT = 'X'
WITH P_VARI = ''
EXPORTING LIST TO MEMORY
AND RETURN.
IF SY-SUBRC = 0.
TRY.
* cl_salv_bs_runtime_info=>GET_DATA( IMPORTING T_DATA = GT_TABLE ). "submit写法分两种取值方法,FB03那种以SAP数据字典中存在的结构展示的用这种
CL_SALV_BS_RUNTIME_INFO=>GET_DATA_REF( IMPORTING R_DATA = DATA(GT_DATA) ). "MB52这种查看不到标准输出的结构的用这种
ASSIGN GT_DATA->* TO .
IF IS ASSIGNED.
LOOP AT ASSIGNING FIELD-SYMBOL().
CLEAR : GS_MB52 .
MOVE-CORRESPONDING TO GS_MB52.
APPEND GS_MB52 TO GT_MB52 .
ENDLOOP.
ENDIF.
CATCH CX_SALV_BS_SC_RUNTIME_INFO.
MESSAGE '查询结果为空!' TYPE 'E'.
ENDTRY.
CL_SALV_BS_RUNTIME_INFO=>CLEAR_ALL( ).
ENDIF.
SELECT MATNR ,WERKS,CHARG,ERSDA FROM MCHA
FOR ALL ENTRIES IN @GT_MB52
WHERE MATNR = @GT_MB52-MATNR
AND WERKS = @GT_MB52-WERKS
AND CHARG = @GT_MB52-CHARG
INTO TABLE @DATA(LT_MCHA) .
SORT LT_MCHA BY WERKS MATNR CHARG .
CLEAR :GS_MB52 .
LOOP AT GT_MB52 ASSIGNING FIELD-SYMBOL().
CASE GS_LIKP-TRSPG. "保税性质与交货单不同的打上删除标记
WHEN '01'.
IF -LGORT(1) <> 'B'.
-DELTE = 'X' .
ENDIF.
WHEN '02'.
IF -LGORT(1) = 'B'.
-DELTE = 'X' .
CONTINUE .
ENDIF.
WHEN OTHERS.
ENDCASE.
IF -LGORT NOT IN S_LGORT. "非自動挑選倉位的庫存不可自動挑選
-DELTE = 'X' .
ENDIF.
READ TABLE LT_MCHA WITH KEY MATNR = -MATNR
WERKS = -WERKS
CHARG = -CHARG
INTO DATA(LS_MCHA) BINARY SEARCH.
IF SY-SUBRC = 0.
-ERSDA = LS_MCHA-ERSDA .
ENDIF.
ENDLOOP.
GT_MB52_RAW = GT_MB52 .
DELETE GT_MB52 WHERE DELTE = 'X' .
SORT GT_MB52 BY WERKS MATNR CHARG ERSDA .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA_LIPS
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_GET_DATA_LIPS .
CHECK GV_ACCOMPLISH <> 'C' .
DATA LV_MAX TYPE LIPS-LFIMG.
DATA LV_POSNR TYPE LIPS-POSNR VALUE '900001'.
IF GV_SPLIT = 'X'. "是否已经做过了批次分割
CLEAR :GS_ITEM .
LOOP AT GT_LIPS INTO GS_LIPS WHERE POSNR < 900000 .
MOVE-CORRESPONDING GS_LIPS TO GS_ITEM .
GS_ITEM-LINE_COLOR = 'C100' .
APPEND GS_ITEM TO GT_ITEM .
CLEAR :GS_ITEM .
LOOP AT GT_LIPS INTO DATA(LS_LIPS) WHERE UECHA = GS_LIPS-POSNR.
MOVE-CORRESPONDING LS_LIPS TO GS_ITEM .
APPEND GS_ITEM TO GT_ITEM .
CLEAR :GS_ITEM .
ENDLOOP.
ENDLOOP.
ELSE.
CLEAR :GS_ITEM2 ,GS_LIPS .
LOOP AT GT_LIPS INTO GS_LIPS WHERE POSNR < 900000 .
MOVE-CORRESPONDING GS_LIPS TO GS_ITEM2 .
GS_ITEM2-LINE_COLOR = 'C100' .
LV_MAX = GS_ITEM2-LFIMG .
APPEND GS_ITEM2 TO GT_ITEM ASSIGNING FIELD-SYMBOL().
CLEAR :GS_MB52 .
LOOP AT GT_MB52 ASSIGNING FIELD-SYMBOL() WHERE MATNR = GS_LIPS-MATNR AND LABST <> 0.
IF -LABST >= LV_MAX.
MOVE-CORRESPONDING GS_LIPS TO GS_ITEM .
GS_ITEM-POSNR = LV_POSNR .
GS_ITEM-LGORT = -LGORT .
GS_ITEM-CHARG = -CHARG .
GS_ITEM-LFIMG = LV_MAX .
GS_ITEM-UECHA = -POSNR .
APPEND GS_ITEM TO GT_ITEM .
-LABST = -LABST - LV_MAX .
LV_MAX = LV_MAX - LV_MAX .
LV_POSNR = LV_POSNR + 1 .
EXIT .
ELSE .
MOVE-CORRESPONDING GS_LIPS TO GS_ITEM .
GS_ITEM-POSNR = LV_POSNR .
GS_ITEM-LGORT = -LGORT .
GS_ITEM-CHARG = -CHARG .
GS_ITEM-LFIMG = -LABST .
GS_ITEM-UECHA = -POSNR .
APPEND GS_ITEM TO GT_ITEM .
LV_MAX = LV_MAX - -LABST .
-LABST = -LABST - -LABST .
LV_POSNR = LV_POSNR + 1 .
ENDIF.
ENDLOOP.
-LFIMG = LV_MAX .
ENDLOOP.
ENDIF.
LOOP AT GT_ITEM ASSIGNING WHERE POSNR < 900000.
IF -LFIMG <> 0.
WA_CELLCOLOR-FNAME = 'LFIMG'.
WA_CELLCOLOR-COLOR-COL = '3'.
WA_CELLCOLOR-COLOR-INT = '1'.
WA_CELLCOLOR-COLOR-INV = '0'.
APPEND WA_CELLCOLOR TO -CELLCOLOR .
ENDIF .
ENDLOOP.
* CLEAR :GV_SPLIT.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CHECK_IF_ACCOMPLISH
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_CHECK_IF_ACCOMPLISH .
SELECT * FROM LIPS WHERE VBELN = @P_VBELN INTO TABLE @GT_LIPS .
SORT GT_LIPS BY VBELN POSNR .
SELECT SINGLE * FROM LIKP WHERE VBELN = @P_VBELN INTO @GS_LIKP .
GV_ACCOMPLISH = GS_LIKP-WBSTK .
LOOP AT GT_LIPS INTO GS_LIPS WHERE POSNR > 900000 .
GV_SPLIT = 'X' .
EXIT .
ENDLOOP.
IF GV_ACCOMPLISH = 'C'.
MESSAGE '交货已完成'(T01) TYPE 'S' .
SET PARAMETER ID 'VL' FIELD P_VBELN .
CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN .
ENDIF .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CREAT_DN
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_CREAT_SPLIT_DN .
CHECK GV_ACCOMPLISH <> 'C' .
PERFORM FRM_DN_DATA .
PERFORM FRM_DN_BAPI .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_DN_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_DN_DATA .
GS_DN_HDATA-DELIV_NUMB = GS_LIKP-VBELN.
GS_DN_HCTRL-DELIV_NUMB = GS_LIKP-VBELN.
GS_DN_CTRL-UPD_IND = 'U'.
LOOP AT GT_LIPS INTO GS_LIPS.
READ TABLE GT_ITEM WITH KEY POSNR = GS_LIPS-POSNR INTO DATA(LS_TEMP) .
IF SY-SUBRC = 0.
GS_LIPS-LFIMG = LS_TEMP-LFIMG .
ENDIF.
CLEAR :LS_TEMP , GS_DN_IDATA.
GS_DN_IDATA-DELIV_NUMB = GS_LIPS-VBELN.
GS_DN_IDATA-DELIV_ITEM = GS_LIPS-POSNR.
GS_DN_IDATA-MATERIAL = GS_LIPS-MATNR.
GS_DN_IDATA-MATERIAL_EXTERNAL = GS_LIPS-MATNR.
GS_DN_IDATA-MATERIAL_LONG = GS_LIPS-MATNR.
GS_DN_IDATA-FACT_UNIT_DENOM = GS_LIPS-UMVKN.
GS_DN_IDATA-FACT_UNIT_NOM = GS_LIPS-UMVKZ.
GS_DN_IDATA-DLV_QTY = GS_LIPS-LFIMG.
GS_DN_IDATA-DLV_QTY_IMUNIT = GS_LIPS-LFIMG.
APPEND GS_DN_IDATA TO GT_DN_IDATA.
CLEAR GS_DN_ICTRL.
GS_DN_ICTRL-DELIV_NUMB = GS_LIPS-VBELN.
GS_DN_ICTRL-DELIV_ITEM = GS_LIPS-POSNR.
GS_DN_ICTRL-CHG_DELQTY = ABAP_TRUE.
APPEND GS_DN_ICTRL TO GT_DN_ICTRL.
LOOP AT GT_ITEM INTO GS_ITEM WHERE POSNR > 900000 AND UECHA = GS_LIPS-POSNR.
CLEAR GS_DN_IDATA.
GS_DN_IDATA-DELIV_NUMB = GS_LIPS-VBELN.
GS_DN_IDATA-DELIV_ITEM = GS_ITEM-POSNR.
GS_DN_IDATA-HIERARITEM = GS_LIPS-POSNR.
GS_DN_IDATA-USEHIERITM = '1'.
GS_DN_IDATA-MATERIAL = GS_LIPS-MATNR.
GS_DN_IDATA-MATERIAL_EXTERNAL = GS_LIPS-MATNR.
GS_DN_IDATA-MATERIAL_LONG = GS_LIPS-MATNR.
GS_DN_IDATA-BATCH = GS_ITEM-CHARG.
GS_DN_IDATA-DLV_QTY = GS_ITEM-LFIMG.
GS_DN_IDATA-DLV_QTY_IMUNIT = GS_ITEM-LFIMG.
GS_DN_IDATA-FACT_UNIT_DENOM = GS_LIPS-UMVKN.
GS_DN_IDATA-FACT_UNIT_NOM = GS_LIPS-UMVKZ.
APPEND GS_DN_IDATA TO GT_DN_IDATA.
CLEAR GS_DN_ICTRL.
GS_DN_ICTRL-DELIV_NUMB = GS_LIPS-VBELN.
GS_DN_ICTRL-DELIV_ITEM = GS_ITEM-POSNR.
GS_DN_ICTRL-CHG_DELQTY = ABAP_TRUE.
APPEND GS_DN_ICTRL TO GT_DN_ICTRL.
CLEAR GS_DN_ISPL.
GS_DN_ISPL-DELIV_NUMB = GS_LIPS-VBELN.
GS_DN_ISPL-DELIV_ITEM = GS_ITEM-POSNR.
GS_DN_ISPL-STGE_LOC = GS_ITEM-LGORT.
GS_DN_ISPL-PICK_DENIAL = 'X'.
APPEND GS_DN_ISPL TO GT_DN_ISPL.
ENDLOOP.
CLEAR GS_DN_ISPL.
GS_DN_ISPL-DELIV_NUMB = GS_LIPS-VBELN.
GS_DN_ISPL-DELIV_ITEM = GS_LIPS-POSNR.
GS_DN_ISPL-STGE_LOC = GS_ITEM-LGORT.
APPEND GS_DN_ISPL TO GT_DN_ISPL.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_DN_BAPI
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_DN_BAPI .
DATA: L_MESSAGE TYPE STRING.
CHECK LINES( GT_DN_IDATA ) NE 0.
CALL FUNCTION 'BAPI_OUTB_DELIVERY_CHANGE'
EXPORTING
HEADER_DATA = GS_DN_HDATA
HEADER_CONTROL = GS_DN_HCTRL
DELIVERY = GS_LIKP-VBELN
TECHN_CONTROL = GS_DN_CTRL
TABLES
ITEM_DATA = GT_DN_IDATA
ITEM_CONTROL = GT_DN_ICTRL
ITEM_DATA_SPL = GT_DN_ISPL
RETURN = GT_RETN.
LOOP AT GT_RETN WHERE TYPE = 'E' OR TYPE = 'A'.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
MSGID = GT_RETN-ID
MSGNR = GT_RETN-NUMBER
MSGV1 = GT_RETN-MESSAGE_V1
MSGV2 = GT_RETN-MESSAGE_V2
MSGV3 = GT_RETN-MESSAGE_V3
MSGV4 = GT_RETN-MESSAGE_V4
IMPORTING
MESSAGE_TEXT_OUTPUT = L_MESSAGE.
ENDLOOP.
IF SY-SUBRC NE 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
SET PARAMETER ID 'VL' FIELD P_VBELN .
CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN .
ELSE .
MESSAGE L_MESSAGE TYPE 'I' .
ENDIF.
CLEAR : L_MESSAGE,GT_RETN,GT_RETN[],GT_DN_ISPL,GT_DN_ISPL[],
GT_DN_ICTRL,GT_DN_ICTRL[],GT_DN_IDATA,GT_DN_IDATA[],
GS_DN_CTRL,GS_DN_HCTRL,GS_DN_HDATA .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_GET_8000_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_GET_8000_DATA USING E_ROW TYPE LVC_S_ROW .
DATA LV_POSNR TYPE LIPS-POSNR .
DATA LV_MATNR TYPE LIPS-MATNR .
CLEAR : GS_ITEM , GS_ITEM2 ,GT_8000,GS_8000,TOTLE .
READ TABLE GT_ITEM INTO GS_ITEM2 INDEX E_ROW-INDEX .
IF SY-SUBRC = 0.
IF GS_ITEM2-UECHA IS INITIAL. "確認選中的是哪行
GS_ITEM2-POSNR = LV_POSNR = GS_ITEM2-POSNR .
ELSE .
GS_ITEM2-POSNR = LV_POSNR = GS_ITEM2-UECHA .
ENDIF.
LV_MATNR = GS_ITEM2-MATNR . "確認選中的是哪個料號
CLEAR : GS_LIPS .
READ TABLE GT_LIPS INTO GS_LIPS WITH KEY POSNR = LV_POSNR .
TOTLE = GS_LIPS-ORMNG .
"合計除了此選中行其他的用量
CLEAR :GT_ITEM_SUM,GS_ITEM_SUM .
LOOP AT GT_ITEM INTO GS_ITEM .
IF GS_ITEM-UECHA <> LV_POSNR AND GS_ITEM-POSNR <> LV_POSNR AND GS_ITEM-CHARG IS NOT INITIAL. "
MOVE-CORRESPONDING GS_ITEM TO GS_ITEM_SUM .
COLLECT GS_ITEM_SUM INTO GT_ITEM_SUM .
CLEAR :GS_ITEM_SUM .
ELSEIF GS_ITEM-CHARG IS NOT INITIAL .
* TOTLE = TOTLE + GS_ITEM-LFIMG .
ENDIF.
ENDLOOP.
ENDIF.
LOOP AT GT_MB52_RAW INTO DATA(GS_MB52_RAW) WHERE MATNR = LV_MATNR.
MOVE-CORRESPONDING GS_MB52_RAW TO GS_8000 .
GS_8000-LFIMC = GS_MB52_RAW-LABST .
CLEAR GS_ITEM_SUM .
READ TABLE GT_ITEM_SUM WITH KEY MATNR = LV_MATNR LGORT = GS_MB52_RAW-LGORT CHARG = GS_MB52_RAW-CHARG INTO GS_ITEM_SUM .
GS_8000-LFIMA = GS_8000-LFIMC - GS_ITEM_SUM-LFIMG .
APPEND GS_8000 TO GT_8000 .
CLEAR : GS_8000 ,GS_MB52_RAW .
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Module MOD_VALUE_TXT OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE MOD_VALUE_TXT OUTPUT.
VBELN = GS_LIPS-VBELN .
POSNR = GS_LIPS-POSNR .
ENDMODULE.
*&---------------------------------------------------------------------*
*& Form FRM_REFRESH_POSNR
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_REFRESH_POSNR .
LOOP AT GT_ITEM ASSIGNING FIELD-SYMBOL() WHERE CHARG IS NOT INITIAL .
-POSNR = LV_POSNR .
LV_POSNR = LV_POSNR + 1 .
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_REFRESH_COLOUR
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_REFRESH_COLOUR .
LOOP AT GT_ITEM ASSIGNING FIELD-SYMBOL() WHERE CHARG IS INITIAL .
-LINE_COLOR = 'C100' .
CLEAR : -CELLCOLOR .
IF -LFIMG <> 0.
WA_CELLCOLOR-FNAME = 'LFIMG'.
WA_CELLCOLOR-COLOR-COL = '3'.
WA_CELLCOLOR-COLOR-INT = '1'.
WA_CELLCOLOR-COLOR-INV = '0'.
APPEND WA_CELLCOLOR TO -CELLCOLOR .
ENDIF .
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_SAVE_CHECK
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_SAVE_CHECK CHANGING LV_SUBRC TYPE SY-SUBRC .
DATA LV_SUM TYPE LIPS-LFIMG .
DATA LV_FLAG TYPE C VALUE 'X' .
LV_SUBRC = 0 .
CLEAR :GS_8000 , GS_LIPS .
LOOP AT GT_8000 INTO GS_8000 WHERE CHBOX = 'X'.
LV_FLAG = '' .
IF GS_8000-LFIMG = 0.
MESSAGE '交貨數量為0的行將無效'(T03) TYPE 'W' .
ENDIF.
LV_SUM = LV_SUM + GS_8000-LFIMG .
ENDLOOP.
IF LV_FLAG = 'X'.
LV_SUBRC = 2 .
MESSAGE '未勾選行'(T02) TYPE 'I' .
ENDIF.
READ TABLE GT_ITEM ASSIGNING FIELD-SYMBOL() WITH KEY POSNR = POSNR .
READ TABLE GT_LIPS WITH KEY POSNR = POSNR INTO GS_LIPS .
IF LV_SUM <= GS_LIPS-ORMNG.
-LFIMG = GS_LIPS-ORMNG - LV_SUM .
ELSE .
LV_SUBRC = 1 .
MESSAGE '交貨數量數不得大於該交貨單項目總數量'(T02) TYPE 'I' .
ENDIF.
ENDFORM.