*&---------------------------------------------------------------------*
*& Report ZMMR114_A
*&---------------------------------------------------------------------*
*& Author : NathanSun
*& Create Date : 2019-07-08
*& Program Type : Report
*& Description : 模具主档表配置表维护程序
*&---------------------------------------------------------------------*
REPORT ZMMR114_A.
*&---------------------------------------------------------------------*
*& 包含 ZMMR112_TOP
*&---------------------------------------------------------------------*
TABLES:ZTMJZD.
TYPE-POOLS:SLIS,T001W,ICON.
*OOALV-DEFINITION
DATA GO_ALV_GRID TYPE REF TO CL_GUI_ALV_GRID.
DATA GO_ALV_GRID_SUB TYPE REF TO CL_GUI_ALV_GRID.
DATA LO_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
DATA OK_CODE TYPE SY-UCOMM.
DATA OK_SAVE TYPE SY-UCOMM.
*global fields
DATA: DRAGDROP_TREE TYPE REF TO CL_DRAGDROP,
DRAGDROP_ALV TYPE REF TO CL_DRAGDROP,
FLG_NEW,
GRID TYPE REF TO CL_GUI_ALV_GRID,
GS_LAYOUT_ALV TYPE LVC_S_LAYO,
GS_TOOLBAR TYPE STB_BUTTON,
G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
G_CONTAINER_OBJECT TYPE REF TO CL_GUI_DOCKING_CONTAINER,
G_DROPEFFECT TYPE I,
G_HANDLE_TREE TYPE I,
G_HANDLE_ALV TYPE I,
G_HIERARCHY_HEADER TYPE TREEV_HHDR,
G_REPID LIKE SY-REPID,
CONTROLS_CREATED1,
TREE1 TYPE REF TO CL_GUI_ALV_TREE,
IT_NODE_KEY TYPE LVC_T_NKEY.
DATA: CONTROLS_CREATED.
DATA: GT_DATA TYPE TABLE OF ZTMJZD WITH HEADER LINE.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
PARAMETERS: S_WERKS TYPE ZTMJZD-WERKS MODIF ID C1 OBLIGATORY. "工厂
PARAMETERS: S_MATNR TYPE ZTMJZD-MATNR MODIF ID C1 OBLIGATORY. "磨具编码
PARAMETERS: S_ZMJQS TYPE ZTMJZD-ZMJQS MODIF ID C1 OBLIGATORY. "模具腔数
*SELECT-OPTIONS: S_WERKS FOR ZTMJZD-WERKS MODIF ID C1 . "工厂
*SELECT-OPTIONS: S_MATNR FOR ZTMJZD-MATNR MODIF ID C1 . "磨具编码
*SELECT-OPTIONS: S_ZMJQS FOR ZTMJZD-ZMJQS MODIF ID C1 . "模具腔数
SELECT-OPTIONS: S_MSMRQ FOR ZTMJZD-MSMRQ MODIF ID C1 . "初始设计寿命日期
SELECT-OPTIONS: S_MSMRQ1 FOR ZTMJZD-MSMRQ1 MODIF ID C1 . "延长设计寿命1日期
SELECT-OPTIONS: S_MSMRQ2 FOR ZTMJZD-MSMRQ2 MODIF ID C1 . "延长设计寿命2日期
SELECT-OPTIONS: S_MSMRQ3 FOR ZTMJZD-MSMRQ3 MODIF ID C1 . "延长设计寿命3日期
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS:
R1 RADIOBUTTON GROUP RAD2 .
SELECTION-SCREEN COMMENT 03(10) TEXT-001. "*单选按钮的名称
PARAMETERS:
R2 RADIOBUTTON GROUP RAD2 .
SELECTION-SCREEN COMMENT 16(20) TEXT-002. "*单选按钮的名称
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK B1.
*&---------------------------------------------------------------------*
*& 包含 ZMMR112_CLASS
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
* CLASS cl_event_receiver DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS CL_EVENT_RECEIVER DEFINITION.
PUBLIC SECTION.
" 声明单击事件的方法
METHODS HANDLE_HOTSPOT_CLICK
FOR EVENT HOTSPOT_CLICK OF CL_GUI_ALV_GRID
IMPORTING E_ROW_ID E_COLUMN_ID.
" 声明双击事件方法
METHODS HANDLE_DOUBLE_CLICK
FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
IMPORTING E_ROW E_COLUMN.
" 声明TOOLBAR事件方法
METHODS HANDLE_TOOLBAR
FOR EVENT TOOLBAR OF CL_GUI_ALV_GRID
IMPORTING E_OBJECT E_INTERACTIVE.
" 声明USER-COMMAND 事件方法
METHODS HANDLE_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.
" ENTE时触发
METHODS HANDLE_ENTER
FOR EVENT DATA_CHANGED_FINISHED OF CL_GUI_ALV_GRID
IMPORTING E_MODIFIED ET_GOOD_CELLS.
"Drag
METHODS HANDLE_ONDRAG
FOR EVENT ONDRAG OF CL_GUI_ALV_GRID
IMPORTING E_ROW
E_COLUMN
ES_ROW_NO
E_DRAGDROPOBJ.
"Drop
METHODS HANDLE_ONDROP
FOR EVENT ONDROP OF CL_GUI_ALV_GRID
IMPORTING E_ROW
E_COLUMN
E_DRAGDROPOBJ.
PRIVATE SECTION.
ENDCLASS. "CL_EVENT_RECEIVER DEFINITION
*----------------------------------------------------------------------*
* CLASS cl_event_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS CL_EVENT_RECEIVER IMPLEMENTATION.
" 单击事件方法的实现
METHOD HANDLE_HOTSPOT_CLICK.
ENDMETHOD. "HANDLE_HOTSPOT_CLICK
" 双击事件方法的实现
METHOD HANDLE_DOUBLE_CLICK.
GO_ALV_GRID_SUB->REFRESH_TABLE_DISPLAY( ).
ENDMETHOD. "HANDLE_DOUBLE_CLICK
" 实现TOOLBAR事件方法
METHOD HANDLE_TOOLBAR.
DATA: LS_TOOLBAR TYPE STB_BUTTON.
DELETE E_OBJECT->MT_TOOLBAR WHERE FUNCTION = '&PRINT_BACK'.
CLEAR: LS_TOOLBAR.
LS_TOOLBAR-BUTN_TYPE = 3. " 分隔符
APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
CLEAR: LS_TOOLBAR.
LS_TOOLBAR-FUNCTION = 'SAVE'. "功能码
LS_TOOLBAR-ICON = ICON_SYSTEM_SAVE. " 图标名称
LS_TOOLBAR-TEXT = '保存数据'. " 按钮上显示的文本
LS_TOOLBAR-QUICKINFO = '保存数据'. " 图标的提示信息
LS_TOOLBAR-BUTN_TYPE = 0. " 0表示正常按钮
LS_TOOLBAR-DISABLED = ''. " X表示灰色,不可用
APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
ENDMETHOD. "HANDLE_TOOLBAR
" 实现USER-COMMAND 事件方法
METHOD HANDLE_COMMAND.
* DATA: REF TYPE REF TO CL_GUI_ALV_GRID.
* DATA : LV_STABLE TYPE LVC_S_STBL. "刷新稳定性
** RANGES: L_WERKS FOR T001W-WERKS.
** RANGES: L_MATNR FOR MARA-MATNR.
* DATA:L_BUKRS TYPE T001K-BUKRS.
*
* LV_STABLE-ROW = '1'.
* LV_STABLE-COL = '1'.
*
* CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
* IMPORTING
* E_GRID = REF.
* CALL METHOD REF->CHECK_CHANGED_DATA.
CASE E_UCOMM.
WHEN 'SAVE'.
* DEMO=>MAIN( ).
* SORT gt_data[] BY bedat.
* CALL METHOD go_alv_grid->refresh_table_display "内表改变时刷新ALV
* EXPORTING
* is_stable = lv_stable.
PERFORM FOM_SAVEDATA .
WHEN OTHERS.
ENDCASE.
* CALL METHOD REF->REFRESH_TABLE_DISPLAY
* EXPORTING
* IS_STABLE = LV_STABLE.
ENDMETHOD. "HANDLE_COMMAND
" 实现DATA_CHANGED 事件方法
METHOD HANDLE_DATA_CHANGED.
DATA GS_LAYOUT_ALV TYPE LVC_S_LAYO.
DATA : LV_STABLE TYPE LVC_S_STBL.
LV_STABLE-ROW = '1'.
LV_STABLE-COL = '1'.
GS_LAYOUT_ALV-CWIDTH_OPT = 'X'.
CALL METHOD GO_ALV_GRID_SUB->SET_FRONTEND_LAYOUT
EXPORTING
IS_LAYOUT = GS_LAYOUT_ALV.
CALL METHOD GO_ALV_GRID_SUB->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = LV_STABLE.
CALL METHOD CL_GUI_CONTROL=>SET_FOCUS
EXPORTING
CONTROL = GO_ALV_GRID_SUB.
CALL METHOD CL_GUI_CFW=>FLUSH.
ENDMETHOD. "handle_data_changed
METHOD HANDLE_ENTER.
DATA GS_LAYOUT_ALV TYPE LVC_S_LAYO.
DATA : LV_STABLE TYPE LVC_S_STBL.
LV_STABLE-ROW = '1'.
LV_STABLE-COL = '1'.
GS_LAYOUT_ALV-GRID_TITLE = '模具主档表配置表维护程序'."标题栏文本
GS_LAYOUT_ALV-SEL_MODE = 'D'. "选择方式
GS_LAYOUT_ALV-CWIDTH_OPT = 'X'. "优化列宽
CALL METHOD GO_ALV_GRID_SUB->SET_FRONTEND_LAYOUT
EXPORTING
IS_LAYOUT = GS_LAYOUT_ALV.
CALL METHOD GO_ALV_GRID_SUB->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = LV_STABLE.
CALL METHOD CL_GUI_CONTROL=>SET_FOCUS
EXPORTING
CONTROL = GO_ALV_GRID_SUB.
CALL METHOD CL_GUI_CFW=>FLUSH.
ENDMETHOD. "HANDLE_MODIFY
* Drag & Drop
METHOD HANDLE_ONDRAG.
CHECK NOT E_ROW IS INITIAL.
* PERFORM DISPLAY_FLIGHTS USING NODE_KEY.
* CALL METHOD CL_GUI_CFW=>SET_NEW_OK_CODE EXPORTING NEW_CODE =
* FCODE_ENTR.
ENDMETHOD.
* Drag & Drop
METHOD HANDLE_ONDROP.
CHECK NOT E_ROW IS INITIAL.
*
ENDMETHOD.
ENDCLASS. "cl_event_receiver IMPLEMENTATION
*&---------------------------------------------------------------------*
*& 包含 ZMMR112_FOM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form GET_MONTH_LASTDAY
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM GET_MONTH_LASTDAY .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form SCREEN_SETTING
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM SCREEN_SETTING .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FOM_GETDATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FOM_GETDATA .
CLEAR GT_DATA[] .
SELECT * INTO CORRESPONDING FIELDS OF TABLE GT_DATA[] FROM ZTMJZD
* WHERE WERKS IN S_WERKS
* AND MATNR IN S_MATNR
* AND ZMJQS IN S_ZMJQS
WHERE WERKS = S_WERKS
AND MATNR = S_MATNR
AND ZMJQS = S_ZMJQS
AND MSMRQ IN S_MSMRQ
AND MSMRQ1 IN S_MSMRQ1
AND MSMRQ2 IN S_MSMRQ2
AND MSMRQ3 IN S_MSMRQ3
.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form CREATETREECONTROL
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM CREATETREECONTROL .
DATA L_FCAT_CACHE TYPE LVC_T_FCAT.
DATA WA_LAYOUT_CACHE TYPE LVC_S_LAYO.
DATA WA_FIELD TYPE LVC_S_FCAT.
DATA LO_EVENT TYPE REF TO CL_EVENT_RECEIVER.
CREATE OBJECT LO_CONTAINER
EXPORTING
CONTAINER_NAME = 'CONT01'.
CREATE OBJECT GO_ALV_GRID_SUB
EXPORTING
I_PARENT = LO_CONTAINER.
CALL METHOD GO_ALV_GRID_SUB->REGISTER_EDIT_EVENT
EXPORTING
I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_ENTER
EXCEPTIONS
ERROR = 1
OTHERS = 2.
DEFINE FILL_FIELD.
wa_field-fieldname = &1.
wa_field-coltext = &2.
IF wa_field-fieldname = 'MATNR' .
wa_field-ref_table = 'MARA'.
wa_field-REF_FIELD = 'MATNR'.
ENDIF.
IF wa_field-fieldname = 'WERKS' .
wa_field-ref_table = 'ZTMJZD'.
wa_field-REF_FIELD = 'WERKS'.
ENDIF.
IF wa_field-fieldname = 'MSMRQ'
or wa_field-fieldname = 'MSMRQ1'
or wa_field-fieldname = 'MSMRQ2'
or wa_field-fieldname = 'MSMRQ3'
.
wa_field-ref_table = 'ZTMJZD'.
wa_field-REF_FIELD = 'MSMRQ'.
ENDIF.
IF R1 IS NOT INITIAL.
IF wa_field-fieldname = 'ZMJQS'
OR wa_field-fieldname = 'MJCSM'
OR wa_field-fieldname = 'MSMRQ'
OR wa_field-fieldname = 'MJYSM1'
OR wa_field-fieldname = 'MSMRQ1'
OR wa_field-fieldname = 'MJYSM2'
OR wa_field-fieldname = 'MSMRQ2'
OR wa_field-fieldname = 'MJYSM3'
OR wa_field-fieldname = 'MSMRQ3'
.
wa_field-edit = 'X'.
ENDIF.
ELSE .
wa_field-edit = 'X'.
ENDIF.
APPEND wa_field TO l_fcat_cache .
CLEAR wa_field.
END-OF-DEFINITION.
FILL_FIELD :
'MATNR' '物料编号',
'WERKS' '工厂',
'ZMJQS' '模具腔数',
'MJCSM' '模具初始设计寿命',
'MSMRQ' '初始设计寿命日期',
'MJYSM1' '模具延长设计寿命1',
'MSMRQ1' '延长设计寿命1日期',
'MJYSM2' '模具延长设计寿命2',
'MSMRQ2' '延长设计寿命2日期',
'MJYSM3' '模具延长设计寿命3',
'MSMRQ3' '延长设计寿命3日期'.
CREATE OBJECT LO_EVENT.
SET HANDLER LO_EVENT->HANDLE_TOOLBAR FOR GO_ALV_GRID_SUB.
SET HANDLER LO_EVENT->HANDLE_COMMAND FOR GO_ALV_GRID_SUB.
SET HANDLER LO_EVENT->HANDLE_ONDROP FOR GO_ALV_GRID_SUB.
* SET HANDLER LO_EVENT->HANDLE_DATA_CHANGED FOR GO_ALV_GRID_SUB.
SET HANDLER LO_EVENT->HANDLE_ENTER FOR GO_ALV_GRID_SUB.
WA_LAYOUT_CACHE-GRID_TITLE = '模具主档表配置表维护程序'."标题栏文本
WA_LAYOUT_CACHE-SEL_MODE = 'D'. "选择方式
WA_LAYOUT_CACHE-CWIDTH_OPT = 'X'. "优化列宽
* handle for D'n'D
* WA_LAYOUT_CACHE-S_DRAGDROP-ROW_DDID = G_HANDLE_ALV.
CALL METHOD GO_ALV_GRID_SUB->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = WA_LAYOUT_CACHE
CHANGING
IT_FIELDCATALOG = L_FCAT_CACHE
IT_OUTTAB = GT_DATA[].
* CLEAR GT_DATA_D[].
GO_ALV_GRID_SUB->REFRESH_TABLE_DISPLAY( ).
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FOM_SAVEDATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FOM_SAVEDATA .
DATA:CHECK1 TYPE C .
DATA:CHECK2 TYPE C .
SORT GT_DATA BY WERKS MATNR .
DELETE GT_DATA[] WHERE WERKS IS INITIAL AND MATNR IS INITIAL .
LOOP AT GT_DATA.
SELECT SINGLE * INTO @DATA(GT_MARC) FROM MARC
WHERE WERKS = @GT_DATA-WERKS
AND MATNR = @GT_DATA-MATNR
.
CLEAR CHECK1 .
CLEAR CHECK2 .
IF SY-SUBRC <> 0.
DATA(LV_WERKS) = GT_DATA-WERKS .
DATA(LV_MATNR1) = GT_DATA-MATNR .
CHECK1 = 'X'.
EXIT.
ENDIF.
SELECT SINGLE * INTO @DATA(GT_MARA) FROM MARA
WHERE MATNR = @GT_DATA-MATNR
AND MTART = 'Z005'
.
IF SY-SUBRC <> 0.
DATA(LV_MATNR2) = GT_DATA-MATNR .
CHECK2 = 'X'.
EXIT.
ENDIF.
CLEAR GT_DATA .
ENDLOOP.
IF CHECK1 IS INITIAL AND CHECK2 IS INITIAL.
MODIFY ZTMJZD FROM TABLE GT_DATA[] .
COMMIT WORK .
MESSAGE '保存村成功!'TYPE 'S' .
CLEAR GT_DATA[] .
ELSEIF CHECK1 IS NOT INITIAL .
MESSAGE '模具' && LV_MATNR1 && '在工厂' && LV_WERKS && '下' && '无主档数据' TYPE 'S' DISPLAY LIKE 'E'.
ELSEIF CHECK2 IS NOT INITIAL .
MESSAGE '模具' && LV_MATNR2 && '的类型并非Z005' TYPE 'S' DISPLAY LIKE 'E'.
ELSE .
ENDIF.
* CLEAR GT_DATA_D[].
GO_ALV_GRID_SUB->REFRESH_TABLE_DISPLAY( ).
ENDFORM.
*&---------------------------------------------------------------------*
*& 包含 ZMMR112_PBO
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'PF_0100'.
SET TITLEBAR 'TITLE_0100'.
CHECK CONTROLS_CREATED IS INITIAL.
CALL METHOD CL_GUI_CFW=>FLUSH."触发SAP GUI更新界面
PERFORM CREATETREECONTROL. "实例化ALV_GRID
CONTROLS_CREATED = 'X'.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module TREE_AND_DOCKING OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE TREE_AND_DOCKING OUTPUT.
* SET PF-STATUS 'xxxxxxxx'.
* SET TITLEBAR 'xxx'.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module SCREEN_SETTING_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE SCREEN_SETTING_0100 OUTPUT.
* SET PF-STATUS 'xxxxxxxx'.
* SET TITLEBAR 'xxx'.
ENDMODULE.
*&---------------------------------------------------------------------*
*& 包含 ZMMR112_PAI
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module CANCEL INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE CANCEL INPUT.
LEAVE PROGRAM .
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
OK_SAVE = SY-UCOMM .
CLEAR SY-UCOMM .
CLEAR OK_CODE .
CASE OK_SAVE.
WHEN 'BACK' .
LEAVE TO SCREEN 0 .
* WHEN 'BT_8' .
* demo=>main( ).
WHEN OTHERS .
ENDCASE .
ENDMODULE.
INITIALIZATION .
PERFORM GET_MONTH_LASTDAY.
AT SELECTION-SCREEN OUTPUT.
AT SELECTION-SCREEN.
PERFORM SCREEN_SETTING.
START-OF-SELECTION.
IF R1 IS NOT INITIAL.
PERFORM FOM_GETDATA .
ELSE.
DO 50 TIMES.
APPEND INITIAL LINE TO GT_DATA[] .
ENDDO.
ENDIF.
CALL SCREEN 100.
#——————————————————————————————
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
MODULE TREE_AND_DOCKING.
MODULE SCREEN_SETTING_0100.
PROCESS AFTER INPUT.
MODULE CANCEL AT EXIT-COMMAND.
MODULE USER_COMMAND_0100.
#——————————————————————————————