Although TMG(Table Maintenance Generator) is powerful and function group which it generated can be enhanced by additional events, it's not enough especially for customized screen element, advanced table relation etc. , so creating table maintenance via alv grid is good choice based on beautiful and powerful alv gird tools.The following sample code is from my recently participating project and it fully replaces TMG by implementing create, delete and modify activities.
1. View Structure
2. Screen 200
3. Code
REPORT YVFM0031 LINE-SIZE 200
MESSAGE-ID ZU
NO STANDARD PAGE HEADING .
INCLUDE YVFM0031TOP.
INCLUDE YVFM0031CLS.
INCLUDE YVFM0031SCR.
INCLUDE YVFM0031O01.
INCLUDE YVFM0031F01.
INCLUDE YVFM0031I01.
INCLUDE YVFM0031E01.
*&---------------------------------------------------------------------*
*& Include YVFM0031TOP
*&---------------------------------------------------------------------*
CLASS LCL_EVENT_RECEIVER DEFINITION DEFERRED.
TABLES : YVCNPMMT, MARA,MAKT.
INCLUDE <ICON>.
****Constants***********************************************************
CONSTANTS : GC_TRUE TYPE C VALUE 'X',
GC_FALSE TYPE C VALUE SPACE,
GC_SPACE TYPE C VALUE SPACE,
GC_SAVE TYPE SY-UCOMM VALUE 'SAVE',
GC_BACK TYPE SY-UCOMM VALUE 'BACK',
GC_EXIT TYPE SY-UCOMM VALUE 'EXIT',
GC_FADD TYPE SY-UCOMM VALUE 'FADD',
GC_FDEL TYPE SY-UCOMM VALUE 'FDEL',
GC_FCOP TYPE SY-UCOMM VALUE 'FCOP',
GC_FADDT TYPE TEXT40 VALUE 'New Entry',
GC_DELT TYPE TEXT40 VALUE 'Dele Entry',
GC_DELETE TYPE TEXT40 VALUE 'D'.
****** Common *********************************************************
DATA : GK_CON TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
GK_CON_SP TYPE REF TO CL_GUI_SPLITTER_CONTAINER,
GK_CON_GRID TYPE REF TO CL_GUI_CONTAINER,
GK_CON_LOG TYPE REF TO CL_GUI_CONTAINER,
GK_GRID TYPE REF TO ZCL_GUI_ALV_GRID,
GK_GRID_PRO TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL,
GT_FIELDCAT TYPE LVC_T_FCAT,
GS_FIELDCAT TYPE LVC_S_FCAT,
GS_LAYOUT TYPE LVC_S_LAYO,
GT_F4 TYPE LVC_T_F4,
GT_EXCLUDE TYPE UI_FUNCTIONS,
GS_VARIANT TYPE DISVARIANT,
GT_SORT TYPE LVC_T_SORT,
EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER.
*-. Basic Output List
TYPES : BEGIN OF T_XPROT,
ROW_ID TYPE INT4, "-. ROW ID.
FNAME(30) TYPE C, "-. Fieldname.
MSGTX(120) TYPE C, "-. Message.
ERROR TYPE C, "-. Error.
END OF T_XPROT.
*-. Error List
DATA : GT_XPROT TYPE TABLE OF T_XPROT WITH KEY ROW_ID FNAME,
WA_XPROT TYPE T_XPROT.
*-. FIELD-SYMBOLS
FIELD-SYMBOLS : <PRO> TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.
TYPES : BEGIN OF GT_OUTTAB.
INCLUDE STRUCTURE YVCNPMMV.
TYPES : MARK TYPE C,
STAT TYPE C,
ERROR TYPE C.
TYPES : CELLTAB TYPE LVC_T_STYL.
TYPES : END OF GT_OUTTAB.
DATA : GT_XLIST TYPE TABLE OF GT_OUTTAB.
DATA : GS_XLIST TYPE GT_OUTTAB.
DATA : DT_XLIST TYPE TABLE OF GT_OUTTAB.
DATA : DS_XLIST TYPE GT_OUTTAB.
DATA : GT_ROW TYPE LVC_T_ROW,
GS_ROW TYPE LVC_S_ROW.
DATA : LT_CELLTAB TYPE LVC_T_STYL,
L_INDEX TYPE I,
P_MODE(1).
DATA: L_VALID TYPE C,
L_TABIX LIKE SY-TABIX,
L_DATUM LIKE SY-DATUM,
LV_CN(2) TYPE N,
LV_TEXT(100).
DATA : G_CHANGE TYPE C,
G_SUBRC TYPE SY-SUBRC,
G_TABIX TYPE SY-TABIX,
OK_CODE TYPE SY-UCOMM,
SAVE_OK TYPE SY-UCOMM,
L_ERR_CHK(1),
L_ANS TYPE C.
DATA : LV_DELETE TYPE STRING.
*&---------------------------------------------------------------------*
*& Include YVFM0031CLS
*&---------------------------------------------------------------------*
CLASS LCL_EVENT_RECEIVER DEFINITION.
PUBLIC SECTION.
METHODS:
HANDLE_DATA_CHANGED
FOR EVENT DATA_CHANGED OF ZCL_GUI_ALV_GRID
IMPORTING SENDER ER_DATA_CHANGED,
HANDLE_DATA_CHANGED_FINISHED
FOR EVENT DATA_CHANGED_FINISHED OF ZCL_GUI_ALV_GRID
IMPORTING SENDER E_MODIFIED,
HANDLE_ON_F4
FOR EVENT ONF4 OF ZCL_GUI_ALV_GRID
IMPORTING E_FIELDNAME ES_ROW_NO ER_EVENT_DATA
ET_BAD_CELLS E_DISPLAY,
HANDLE_CONTEXT_MENU
FOR EVENT CONTEXT_MENU_REQUEST OF ZCL_GUI_ALV_GRID
IMPORTING E_OBJECT,
HANDLE_USER_COMMAND
FOR EVENT USER_COMMAND OF ZCL_GUI_ALV_GRID
IMPORTING E_UCOMM,
HANDLE_TOOLBAR
FOR EVENT TOOLBAR OF ZCL_GUI_ALV_GRID
IMPORTING SENDER E_OBJECT E_INTERACTIVE.
ENDCLASS. "lcl_event_receiver DEFINITION
*-. Class Implementation...............................................
CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.
METHOD HANDLE_DATA_CHANGED.
PERFORM PRO_DATA_CHANGED USING ER_DATA_CHANGED.
ENDMETHOD. "handle_data_changed
METHOD HANDLE_DATA_CHANGED_FINISHED.
PERFORM PRO_DATA_CHANGED_FINISHED USING E_MODIFIED.
ENDMETHOD. "handle_data_changed_finished
METHOD HANDLE_ON_F4.
PERFORM PRO_HANDLE_ON_F4 USING E_FIELDNAME ES_ROW_NO ER_EVENT_DATA
ET_BAD_CELLS E_DISPLAY.
ENDMETHOD. "handle_on_f4
METHOD HANDLE_CONTEXT_MENU.
CALL METHOD E_OBJECT->CLEAR.
ENDMETHOD. "handle_context_menu
METHOD HANDLE_USER_COMMAND.
PERFORM PRO_USER_COMMAND_GRID USING E_UCOMM.
ENDMETHOD. "handle_user_command
METHOD HANDLE_TOOLBAR.
PERFORM PRO_TOOLBAR USING SENDER E_OBJECT.
ENDMETHOD. "handle_toolbar
ENDCLASS. "lcl_event_receiver IMPLEMENTATION
*&---------------------------------------------------------------------*
*& Include YVFM0031SCR
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK BL1 WITH FRAME TITLE TEXT-001.
*-Material select options
SELECT-OPTIONS : S_YMTNR FOR YVCNPMMT-YMTNR,
S_MATNR FOR YVCNPMMT-MATNR.
SELECTION-SCREEN END OF BLOCK BL1.
*&---------------------------------------------------------------------*
*& Include YVFM0031O01
*&---------------------------------------------------------------------*
MODULE STATUS_0200 OUTPUT.
DATA: GT_EXMU TYPE TABLE OF SY-UCOMM.
CLEAR GT_EXMU.
IF G_CHANGE NE GC_TRUE.
APPEND GC_SAVE TO GT_EXMU.
ENDIF.
SET PF-STATUS 'M200' EXCLUDING GT_EXMU.
SET TITLEBAR 'T200'.
CHECK GK_CON IS INITIAL.
PERFORM PRO_INIT_OBJECT.
ENDMODULE. " status_0200 OUTPUT
*&---------------------------------------------------------------------*
*& Include YVKR0403_CSF01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form pro_get_data
*&---------------------------------------------------------------------*
FORM PRO_GET_DATA .
REFRESH : GT_XLIST.
SELECT * FROM YVCNPMMT
INTO CORRESPONDING FIELDS OF TABLE GT_XLIST
WHERE YMTNR IN S_YMTNR
AND MATNR IN S_MATNR.
SORT GT_XLIST.
LOOP AT GT_XLIST INTO GS_XLIST.
SELECT SINGLE MAKTX INTO GS_XLIST-MAKTX FROM MAKT
WHERE MATNR = GS_XLIST-MATNR
AND SPRAS = '1'.
IF SY-SUBRC NE 0.
SELECT SINGLE MAKTX INTO GS_XLIST-MAKTX FROM MAKT
WHERE MATNR = GS_XLIST-MATNR
AND SPRAS = 'E'.
ENDIF.
GS_XLIST-STAT = 'D'.
MODIFY GT_XLIST FROM GS_XLIST.
CLEAR : GS_XLIST.
ENDLOOP.
CLEAR GS_XLIST.
GS_XLIST-STAT = 'C'. "
DO 20 TIMES.
APPEND GS_XLIST TO GT_XLIST.
ENDDO.
ENDFORM. " pro_select_data
*&---------------------------------------------------------------------*
*& Form pro_init_object
*&---------------------------------------------------------------------*
FORM PRO_INIT_OBJECT .
PERFORM PRO_CREATE_OBJECT.
PERFORM PRO_SET_LAYOUT.
PERFORM PRO_SET_SORT.
PERFORM PRO_GET_FIELDCAT.
PERFORM PRO_ADJUST_FIELDCAT.
PERFORM PRO_REGISTER_EVENT.
PERFORM PRO_SET_REGISTER_F4.
PERFORM PRO_SET_HANDLER.
PERFORM PRO_SET_CELLTAB.
PERFORM PRO_DISPLAY_GRID.
PERFORM PRO_OTHERS_SETTING.
ENDFORM. " pro_init_object
*&---------------------------------------------------------------------*
*& Form pro_create_object
*&---------------------------------------------------------------------*
FORM PRO_CREATE_OBJECT .
*-. Container
CREATE OBJECT GK_CON
EXPORTING
CONTAINER_NAME = 'CON'.
*-. Split container
CREATE OBJECT GK_CON_SP
EXPORTING
PARENT = GK_CON
ROWS = 2
COLUMNS = 1.
*-. Container
PERFORM PRO_SET_CONTAINER_SIZE USING 1 100.
PERFORM PRO_SET_CONTAINER_SIZE USING 2 0.
*-. Split container
CALL METHOD GK_CON_SP->SET_BORDER
EXPORTING
BORDER = GC_FALSE.
CALL METHOD GK_CON_SP->GET_CONTAINER
EXPORTING
ROW = 1
COLUMN = 1
RECEIVING
CONTAINER = GK_CON_GRID.
CALL METHOD GK_CON_SP->GET_CONTAINER
EXPORTING
ROW = 2
COLUMN = 1
RECEIVING
CONTAINER = GK_CON_LOG.
*-. Grid
CREATE OBJECT GK_GRID
EXPORTING
I_PARENT = GK_CON_GRID
I_APPLOGPARENT = GK_CON_LOG
I_APPL_EVENTS = GC_TRUE.
*-. Log grid
CREATE OBJECT GK_GRID_PRO
EXPORTING
I_CONTAINER = GK_CON_LOG
I_CALLING_ALV = GK_GRID.
*-. Event Receiver
CREATE OBJECT EVENT_RECEIVER.
ENDFORM. " pro_create_object
*&---------------------------------------------------------------------*
*& Form pro_set_layout
*&---------------------------------------------------------------------*
FORM PRO_SET_LAYOUT.
*-. Layout
GS_LAYOUT-SEL_MODE = 'A'.
GS_LAYOUT-BOX_FNAME = 'MARK'.
GS_LAYOUT-DETAILINIT = GC_TRUE.
GS_LAYOUT-SMALLTITLE = GC_TRUE.
GS_LAYOUT-ZEBRA = GC_TRUE.
GS_LAYOUT-CWIDTH_OPT = GC_TRUE.
GS_LAYOUT-STYLEFNAME = 'CELLTAB'.
ENDFORM. " pro_set_layout
*&---------------------------------------------------------------------*
*& Form pro_get_fieldcat
*&---------------------------------------------------------------------*
FORM PRO_GET_FIELDCAT .
*-. FIELDCATALOG
DATA: L_DATUM(08).
CLEAR GT_FIELDCAT.
SY-DATUM = SY-DATUM + 1.
MOVE SY-DATUM TO L_DATUM.
SET PARAMETER ID 'ALVBUFFER' FIELD L_DATUM.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_BYPASSING_BUFFER = GC_FALSE
I_BUFFER_ACTIVE = GC_TRUE
I_STRUCTURE_NAME = 'YVCNPMMV'
CHANGING
CT_FIELDCAT = GT_FIELDCAT[]
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
ENDFORM. " pro_get_fieldcat
*&---------------------------------------------------------------------*
*& Form pro_adjust_fieldcat
*&---------------------------------------------------------------------*
FORM PRO_ADJUST_FIELDCAT .
*-. FIELDCATALOG 세부구성.
DATA: LS_FCAT TYPE LVC_S_FCAT.
LOOP AT GT_FIELDCAT INTO LS_FCAT.
CASE LS_FCAT-FIELDNAME.
WHEN 'YMTNR'.
LS_FCAT-COLTEXT = TEXT-H01.
LS_FCAT-EDIT = GC_TRUE.
LS_FCAT-KEY = GC_TRUE.
WHEN 'YMKTX'.
LS_FCAT-COLTEXT = TEXT-H02.
LS_FCAT-EDIT = GC_TRUE.
WHEN 'MATNR'.
LS_FCAT-COLTEXT = TEXT-H03.
LS_FCAT-EDIT = GC_TRUE.
WHEN 'MAKTX'.
LS_FCAT-COLTEXT = TEXT-H04.
WHEN 'YMEIP'.
LS_FCAT-COLTEXT = TEXT-H05.
LS_FCAT-EDIT = GC_TRUE.
WHEN 'YMEIN'.
LS_FCAT-COLTEXT = TEXT-H06.
LS_FCAT-EDIT = GC_TRUE.
WHEN 'BRGEW'.
LS_FCAT-COLTEXT = TEXT-H07.
LS_FCAT-EDIT = GC_TRUE.
LS_FCAT-NO_ZERO = GC_TRUE.
WHEN 'LAENG'.
LS_FCAT-COLTEXT = TEXT-H08.
LS_FCAT-EDIT = GC_TRUE.
LS_FCAT-NO_ZERO = GC_TRUE.
WHEN 'BREIT'.
LS_FCAT-COLTEXT = TEXT-H09.
LS_FCAT-EDIT = GC_TRUE.
LS_FCAT-NO_ZERO = GC_TRUE.
WHEN 'HOEHE'.
LS_FCAT-COLTEXT = TEXT-H10.
LS_FCAT-EDIT = GC_TRUE.
LS_FCAT-NO_ZERO = GC_TRUE.
WHEN 'YINWV'.
LS_FCAT-COLTEXT = TEXT-H11.
LS_FCAT-EDIT = GC_TRUE.
WHEN 'YINRW'.
LS_FCAT-COLTEXT = TEXT-H12.
ENDCASE.
MODIFY GT_FIELDCAT FROM LS_FCAT INDEX SY-TABIX.
ENDLOOP.
ENDFORM. " pro_adjust_fieldcat
*&---------------------------------------------------------------------*
*& Form pro_register_event
*&---------------------------------------------------------------------*
FORM PRO_REGISTER_EVENT.
*-. Enter.
CALL METHOD GK_GRID->REGISTER_EDIT_EVENT
EXPORTING
I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_ENTER.
*
ENDFORM. " pro_register_event
*&---------------------------------------------------------------------*
*& Form pro_set_register_f4
*&---------------------------------------------------------------------*
FORM PRO_SET_REGISTER_F4 .
DATA: LS_F4 TYPE LVC_S_F4.
CLEAR : GT_F4[].
CALL METHOD GK_GRID->REGISTER_F4_FOR_FIELDS
EXPORTING
IT_F4 = GT_F4[].
ENDFORM. " pro_set_register_f4
*&---------------------------------------------------------------------*
*& Form pro_set_handler
*&---------------------------------------------------------------------*
FORM PRO_SET_HANDLER .
SET HANDLER: EVENT_RECEIVER->HANDLE_USER_COMMAND FOR GK_GRID,
EVENT_RECEIVER->HANDLE_CONTEXT_MENU FOR GK_GRID,
EVENT_RECEIVER->HANDLE_TOOLBAR FOR GK_GRID,
EVENT_RECEIVER->HANDLE_DATA_CHANGED FOR GK_GRID,
EVENT_RECEIVER->HANDLE_DATA_CHANGED_FINISHED FOR GK_GRID.
SET HANDLER EVENT_RECEIVER->HANDLE_CONTEXT_MENU FOR GK_GRID.
APPEND : CL_GUI_ALV_GRID=>MC_FC_GRAPH TO GT_EXCLUDE,
CL_GUI_ALV_GRID=>MC_FC_INFO TO GT_EXCLUDE,
CL_GUI_ALV_GRID=>MC_FC_PRINT TO GT_EXCLUDE,
CL_GUI_ALV_GRID=>MC_FC_SUM TO GT_EXCLUDE,
CL_GUI_ALV_GRID=>MC_FC_SUBTOT TO GT_EXCLUDE,
CL_GUI_ALV_GRID=>MC_FC_VIEWS TO GT_EXCLUDE,
CL_GUI_ALV_GRID=>MC_FC_LOC_APPEND_ROW TO GT_EXCLUDE,
CL_GUI_ALV_GRID=>MC_FC_LOC_COPY TO GT_EXCLUDE,
CL_GUI_ALV_GRID=>MC_FC_LOC_COPY_ROW TO GT_EXCLUDE,
CL_GUI_ALV_GRID=>MC_FC_LOC_CUT TO GT_EXCLUDE,
CL_GUI_ALV_GRID=>MC_FC_LOC_DELETE_ROW TO GT_EXCLUDE,
CL_GUI_ALV_GRID=>MC_FC_LOC_INSERT_ROW TO GT_EXCLUDE,
CL_GUI_ALV_GRID=>MC_FC_LOC_MOVE_ROW TO GT_EXCLUDE,
CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE TO GT_EXCLUDE,
CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE_NEW_ROW TO GT_EXCLUDE,
CL_GUI_ALV_GRID=>MC_FC_LOC_UNDO TO GT_EXCLUDE.
ENDFORM. " pro_set_handler
*&---------------------------------------------------------------------*
*& Form PRO_SET_CELLTAB
*&---------------------------------------------------------------------*
FORM PRO_SET_CELLTAB .
LOOP AT GT_XLIST INTO GS_XLIST.
REFRESH LT_CELLTAB.
PERFORM FILL_CELLTAB USING GS_XLIST-STAT
CHANGING LT_CELLTAB.
CLEAR GS_XLIST-CELLTAB.
INSERT LINES OF LT_CELLTAB INTO TABLE GS_XLIST-CELLTAB.
MODIFY GT_XLIST FROM GS_XLIST.
ENDLOOP.
ENDFORM. " PRO_SET_CELLTAB
*&---------------------------------------------------------------------*
*& Form FILL_CELLTAB
*&---------------------------------------------------------------------*
FORM FILL_CELLTAB USING P_STAT
CHANGING PT_CELLTAB TYPE LVC_T_STYL.
DATA : LS_CELLTAB TYPE LVC_S_STYL.
LOOP AT GT_FIELDCAT INTO GS_FIELDCAT.
LS_CELLTAB-FIELDNAME = GS_FIELDCAT-FIELDNAME.
CASE P_STAT.
WHEN 'C'.
IF LS_CELLTAB-FIELDNAME EQ 'YMTNR'.
LS_CELLTAB-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_ENABLED.
INSERT LS_CELLTAB INTO TABLE PT_CELLTAB.
ENDIF.
WHEN 'M' OR 'D'.
IF LS_CELLTAB-FIELDNAME EQ 'YMTNR'.
LS_CELLTAB-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.
INSERT LS_CELLTAB INTO TABLE PT_CELLTAB.
ENDIF.
ENDCASE.
ENDLOOP.
ENDFORM. " FILL_CELLTAB
*&---------------------------------------------------------------------*
*& Form pro_display_grid
*&---------------------------------------------------------------------*
FORM PRO_DISPLAY_GRID .
GS_VARIANT = SY-REPID.
CALL METHOD GK_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = GS_LAYOUT
IT_TOOLBAR_EXCLUDING = GT_EXCLUDE
IS_VARIANT = GS_VARIANT
I_SAVE = 'A'
CHANGING
IT_OUTTAB = GT_XLIST[]
IT_SORT = GT_SORT[]
IT_FIELDCATALOG = GT_FIELDCAT[]
EXCEPTIONS
INVALID_PARAMETER_COMBINATION = 1
PROGRAM_ERROR = 2
OTHERS = 3.
CHECK SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDFORM. " pro_display_grid
*&---------------------------------------------------------------------*
*& Form pro_others_setting
*&---------------------------------------------------------------------*
FORM PRO_OTHERS_SETTING.
GK_GRID_PRO->MT_FIELDCATALOG = GT_FIELDCAT[].
CALL METHOD CL_GUI_CONTROL=>SET_FOCUS
EXPORTING
CONTROL = GK_GRID.
ENDFORM. " pro_others_setting
*&---------------------------------------------------------------------*
*& Form pro_set_container_size
*&---------------------------------------------------------------------*
FORM PRO_SET_CONTAINER_SIZE USING VALUE(P_ID) VALUE(P_HEIGHT).
CALL METHOD GK_CON_SP->SET_ROW_HEIGHT
EXPORTING
ID = P_ID "-. Container ID.
HEIGHT = P_HEIGHT. "-. Height.
ENDFORM. " pro_set_container_size
*&---------------------------------------------------------------------*
*& Form pro_command_back
*&---------------------------------------------------------------------*
FORM PRO_COMMAND_BACK .
CASE SAVE_OK.
WHEN GC_BACK.
LEAVE TO SCREEN 0.
WHEN GC_EXIT.
LEAVE PROGRAM.
ENDCASE.
ENDFORM. " pro_command_back
*&---------------------------------------------------------------------*
*& Form pro_toolbar
*&---------------------------------------------------------------------*
FORM PRO_TOOLBAR USING P_SENDER TYPE REF TO ZCL_GUI_ALV_GRID
P_OBJ TYPE REF TO CL_ALV_EVENT_TOOLBAR_SET.
PERFORM PRO_ADD_MENU USING: GC_FADD ICON_CREATE
P_OBJ->MT_TOOLBAR GC_FADDT,
GC_FDEL ICON_DELETE_ROW
P_OBJ->MT_TOOLBAR GC_DELT.
ENDFORM. " pro_toolbar
*&---------------------------------------------------------------------*
*& Form pro_add_menu
*&---------------------------------------------------------------------*
FORM PRO_ADD_MENU USING P_FADD P_ICON
PP_OBJ TYPE TTB_BUTTON P_TEXT.
DATA: LS_TOOLBAR TYPE STB_BUTTON.
MOVE P_FADD TO LS_TOOLBAR-FUNCTION. "-. Function code.
MOVE P_ICON TO LS_TOOLBAR-ICON. "-. Icon.
MOVE SPACE TO LS_TOOLBAR-DISABLED. "-. Disabled.
MOVE P_TEXT TO LS_TOOLBAR-TEXT.
APPEND LS_TOOLBAR TO PP_OBJ.
ENDFORM. " pro_add_menu
*&---------------------------------------------------------------------*
*& Form PRO_HANDLE_ON_F4
*&---------------------------------------------------------------------*
FORM PRO_HANDLE_ON_F4 USING P_FIELDNAME TYPE LVC_FNAME
P_ROW_NO TYPE LVC_S_ROID
P_EVENT_DATA TYPE REF TO CL_ALV_EVENT_DATA
P_BAD_CELLS TYPE LVC_T_MODI
P_DISPLAY.
FIELD-SYMBOLS <ITAB> TYPE LVC_T_MODI.
DATA : LS_MODI TYPE LVC_S_MODI.
P_EVENT_DATA->M_EVENT_HANDLED = GC_TRUE.
ENDFORM. " PRO_HANDLE_ON_F4
*&---------------------------------------------------------------------*
*& Form pro_user_command_grid
*&---------------------------------------------------------------------*
FORM PRO_USER_COMMAND_GRID USING P_UCOMM.
CASE P_UCOMM.
WHEN GC_FDEL.
PERFORM PRO_HANDLE_COMMAND_FDEL.
WHEN GC_FADD.
PERFORM PRO_HANDLE_COMMAND_FADD.
ENDCASE.
ENDFORM. " pro_user_command_grid
*&---------------------------------------------------------------------*
*& Form pro_command_save
*&---------------------------------------------------------------------*
FORM PRO_COMMAND_SAVE .
DATA : LS_PMMT TYPE YVCNPMMT,
LT_PMMT LIKE TABLE OF LS_PMMT.
DATA : GS_TEMP TYPE GT_OUTTAB.
CALL METHOD GK_GRID->CHECK_CHANGED_DATA
IMPORTING
E_VALID = L_VALID.
*
CHECK L_VALID IS NOT INITIAL.
CHECK GT_XPROT[] IS INITIAL.
DELETE GT_XLIST WHERE MATNR = GC_SPACE OR YMTNR = GC_SPACE.
CLEAR : G_SUBRC, LV_TEXT.
LOOP AT GT_XLIST INTO GS_XLIST WHERE STAT = 'C'.
CLEAR LV_CN.
LOOP AT GT_XLIST INTO GS_TEMP
WHERE YMTNR = GS_XLIST-YMTNR.
LV_CN = LV_CN + 1.
IF LV_CN > 1.
CONCATENATE 'Material' GS_XLIST-MATNR TEXT-E02 INTO LV_TEXT.
MESSAGE S000(ZU) WITH LV_TEXT DISPLAY LIKE 'E'.
G_SUBRC = 4. EXIT.
ENDIF.
ENDLOOP.
CHECK G_SUBRC EQ 0.
SELECT SINGLE * FROM YVCNPMMT
WHERE YMTNR = GS_XLIST-YMTNR.
IF SY-SUBRC = 0.
CLEAR DS_XLIST.
READ TABLE DT_XLIST INTO DS_XLIST WITH KEY YMTNR = GS_XLIST-YMTNR.
IF SY-SUBRC <> 0.
CONCATENATE 'Material' GS_XLIST-MATNR TEXT-E02 INTO LV_TEXT.
MESSAGE S000(ZU) WITH LV_TEXT DISPLAY LIKE 'E'.
G_SUBRC = 4. EXIT.
ENDIF.
ENDIF.
ENDLOOP.
CHECK G_SUBRC EQ 0.
REFRESH : LT_PMMT.
LOOP AT DT_XLIST INTO GS_XLIST WHERE STAT = 'M'
OR STAT = 'D'.
MOVE-CORRESPONDING GS_XLIST TO LS_PMMT.
APPEND LS_PMMT TO LT_PMMT.
CLEAR : LS_PMMT, GS_XLIST.
ENDLOOP.
DELETE YVCNPMMT FROM TABLE LT_PMMT.
COMMIT WORK.
REFRESH : LT_PMMT.
LOOP AT GT_XLIST INTO GS_XLIST WHERE STAT = 'M'
OR STAT = 'C'.
GS_XLIST-YINRW = '0'.
MOVE-CORRESPONDING GS_XLIST TO LS_PMMT.
APPEND LS_PMMT TO LT_PMMT.
GS_XLIST-STAT = 'M'.
REFRESH LT_CELLTAB.
PERFORM FILL_CELLTAB USING GS_XLIST-STAT
CHANGING LT_CELLTAB.
CLEAR GS_XLIST-CELLTAB.
INSERT LINES OF LT_CELLTAB INTO TABLE GS_XLIST-CELLTAB.
MODIFY GT_XLIST FROM GS_XLIST.
CLEAR : LS_PMMT, GS_XLIST.
ENDLOOP.
MODIFY YVCNPMMT FROM TABLE LT_PMMT.
COMMIT WORK.
MESSAGE S000(ZU) WITH TEXT-S01.
G_CHANGE = GC_SPACE.
ENDFORM. " pro_command_save
*&---------------------------------------------------------------------*
*& Form PRO_DATA_CHANGED
*&---------------------------------------------------------------------*
FORM PRO_DATA_CHANGED
USING P_OBJECT TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.
DATA : LS_CELL TYPE LVC_S_MODI.
DATA : L_ROWID TYPE INT4.
DATA : L_TABIX LIKE SY-TABIX.
FIELD-SYMBOLS: <DATA> TYPE STANDARD TABLE.
ASSIGN P_OBJECT TO <PRO>.
ASSIGN <PRO>->MP_MOD_ROWS->* TO <DATA>.
LOOP AT <DATA> INTO GS_XLIST.
L_TABIX = SY-TABIX.
CLEAR LS_CELL.
READ TABLE <PRO>->MT_GOOD_CELLS INTO LS_CELL
WITH KEY TABIX = L_TABIX.
CHECK SY-SUBRC EQ 0.
MOVE LS_CELL-ROW_ID TO L_ROWID.
DELETE GT_XPROT WHERE ROW_ID EQ L_ROWID.
PERFORM PRO_ERROR_CHECK USING L_ROWID.
READ TABLE GT_XPROT WITH KEY ROW_ID = L_ROWID
TRANSPORTING NO FIELDS.
IF SY-SUBRC = 0. GS_XLIST-ERROR = 'X'. ENDIF.
PERFORM PRO_MODIFY_CELL
USING: GS_XLIST-ERROR L_ROWID 'ERROR',
GS_XLIST-STAT L_ROWID 'STAT',
GS_XLIST-YMTNR L_ROWID 'YMTNR',
GS_XLIST-YMKTX L_ROWID 'YMKTX',
GS_XLIST-MATNR L_ROWID 'MATNR',
GS_XLIST-MAKTX L_ROWID 'MAKTX',
GS_XLIST-YMEIP L_ROWID 'YMEIP',
GS_XLIST-YMEIN L_ROWID 'YMEIN',
GS_XLIST-BRGEW L_ROWID 'BRGEW',
GS_XLIST-LAENG L_ROWID 'LAENG',
GS_XLIST-BREIT L_ROWID 'BREIT',
GS_XLIST-HOEHE L_ROWID 'HOEHE',
GS_XLIST-YINWV L_ROWID 'YINWV'.
ENDLOOP.
IF SY-SUBRC = 0.
G_CHANGE = GC_TRUE.
ENDIF.
CHECK NOT <PRO>->MT_PROTOCOL[] IS INITIAL.
PERFORM PRO_SET_CONTAINER_SIZE USING 1 80.
PERFORM PRO_SET_CONTAINER_SIZE USING 2 20.
ENDFORM. " PRO_DATA_CHANGED
*&---------------------------------------------------------------------*
*& Form PRO_DATA_CHANGED_FINISHED
*&---------------------------------------------------------------------*
FORM PRO_DATA_CHANGED_FINISHED USING P_MODIFIED.
CHECK P_MODIFIED EQ GC_TRUE.
PERFORM PRO_DISPLAY_PROTOCOL.
CALL METHOD GK_GRID->OPTIMIZE_FIELDS.
ENDFORM. " PRO_DATA_CHANGED_FINISHED
*&---------------------------------------------------------------------*
*& Form pro_modify_cell
*&---------------------------------------------------------------------*
FORM PRO_MODIFY_CELL USING P_VALUE P_ID P_FIELD.
*
CALL METHOD <PRO>->MODIFY_CELL
EXPORTING
I_ROW_ID = P_ID "-. row.
I_FIELDNAME = P_FIELD "-. field.
I_VALUE = P_VALUE. "-. value.
*
ENDFORM. " pro_modify_cell
*&---------------------------------------------------------------------*
*& Form PRO_ERROR_CHECK
*&---------------------------------------------------------------------*
FORM PRO_ERROR_CHECK USING P_ROWID.
*-. STAT
IF GS_XLIST-STAT = 'D'.
GS_XLIST-STAT = 'M'.
ENDIF.
CHECK GS_XLIST-MATNR IS NOT INITIAL.
SELECT SINGLE MATNR INTO GS_XLIST-MATNR FROM MARA
WHERE MATNR = GS_XLIST-MATNR.
IF SY-SUBRC NE 0.
PERFORM PRO_APPEND_XPROT USING P_ROWID 'MATNR' TEXT-E01.
ELSE.
IF GS_XLIST-MAKTX IS INITIAL.
SELECT SINGLE MAKTX FROM MAKT INTO GS_XLIST-MAKTX
WHERE MATNR = GS_XLIST-MATNR
AND SPRAS = '1'.
IF SY-SUBRC NE 0.
SELECT SINGLE MAKTX FROM MAKT INTO GS_XLIST-MAKTX
WHERE MATNR = GS_XLIST-MATNR
AND SPRAS = 'E'.
ENDIF.
ENDIF.
ENDIF.
IF GS_XLIST-YINRW IS INITIAL.
GS_XLIST-YINRW = '0'.
ENDIF.
ENDFORM. " PRO_ERROR_CHECK
*&---------------------------------------------------------------------*
*& Form pro_append_xprot
*&---------------------------------------------------------------------*
FORM PRO_APPEND_XPROT USING PP_ROW_ID PP_FIELD PP_TEXT.
*
GS_XLIST-ERROR = GC_TRUE.
MOVE: PP_ROW_ID TO WA_XPROT-ROW_ID, "-. ROW ID.
PP_FIELD TO WA_XPROT-FNAME, "-. Field.
PP_TEXT TO WA_XPROT-MSGTX. "-. 메시지.
APPEND WA_XPROT TO GT_XPROT. CLEAR WA_XPROT.
*
ENDFORM. " pro_append_xprot
*&---------------------------------------------------------------------*
*& Form PRO_DISPLAY_PROTOCOL
*&---------------------------------------------------------------------*
FORM PRO_DISPLAY_PROTOCOL .
DATA: L_INDEX TYPE INT4.
CALL METHOD GK_GRID_PRO->FREE.
IF NOT GT_XPROT[] IS INITIAL.
SORT GT_XPROT.
LOOP AT GT_XPROT INTO WA_XPROT.
PERFORM PRO_ADD_PROTOCOL_ENTRY_GK USING WA_XPROT-ROW_ID
WA_XPROT-FNAME
WA_XPROT-MSGTX.
ENDLOOP.
PERFORM PRO_SET_CONTAINER_SIZE USING 1 80.
PERFORM PRO_SET_CONTAINER_SIZE USING 2 20.
CALL METHOD GK_GRID_PRO->DISPLAY_PROTOCOL.
ELSE.
PERFORM PRO_SET_CONTAINER_SIZE USING 1 100.
PERFORM PRO_SET_CONTAINER_SIZE USING 2 0.
ENDIF.
ENDFORM. " PRO_DISPLAY_PROTOCOL
*&---------------------------------------------------------------------*
*& Form pro_add_protocol_entry_gk
*&---------------------------------------------------------------------*
FORM PRO_ADD_PROTOCOL_ENTRY_GK USING P_ID P_FIELD P_MSG.
*
CALL METHOD GK_GRID_PRO->ADD_PROTOCOL_ENTRY
EXPORTING
I_MSGID = 'ZU'
I_MSGNO = '000'
I_MSGTY = 'E'
I_MSGV1 = P_MSG
I_FIELDNAME = P_FIELD
I_ROW_ID = P_ID.
ENDFORM. " pro_add_protocol_entry_gk
*&---------------------------------------------------------------------*
*& Form pro_handle_command_fdel
*&---------------------------------------------------------------------*
FORM PRO_HANDLE_COMMAND_FDEL .
DATA: L_TABIX TYPE SY-TABIX,
L_ROWID TYPE INT4.
REFRESH GT_ROW[].
CLEAR : L_ANS, G_SUBRC.
CALL METHOD GK_GRID->GET_SELECTED_ROWS
IMPORTING
ET_INDEX_ROWS = GT_ROW[].
DELETE GT_ROW WHERE ROWTYPE <> SPACE.
IF GT_ROW[] IS INITIAL.
MESSAGE S000(ZU) WITH 'No line selected'.
EXIT.
ENDIF.
CHECK G_SUBRC IS INITIAL.
LOOP AT GT_ROW INTO GS_ROW.
CLEAR: GS_XLIST, WA_XPROT.
READ TABLE GT_XLIST INTO GS_XLIST INDEX GS_ROW-INDEX.
CHECK SY-SUBRC = 0.
MOVE GC_DELETE TO: GS_XLIST-ERROR, WA_XPROT-ERROR.
MOVE-CORRESPONDING GS_XLIST TO DS_XLIST.
APPEND DS_XLIST TO DT_XLIST.
MODIFY GT_XLIST FROM GS_XLIST INDEX GS_ROW-INDEX
TRANSPORTING ERROR.
MODIFY GT_XPROT FROM WA_XPROT TRANSPORTING ERROR
WHERE ROW_ID EQ GS_ROW-INDEX.
ENDLOOP.
CHECK L_ANS IS INITIAL.
PERFORM PRO_CHECK_CONFIRM USING TEXT-002 TEXT-003
CHANGING L_ANS.
CHECK L_ANS EQ 'J'.
DELETE GT_XLIST WHERE ERROR EQ GC_DELETE.
REFRESH : GT_XPROT.
CLEAR : GS_XLIST.
LOOP AT GT_XLIST INTO GS_XLIST WHERE ERROR EQ GC_TRUE.
CLEAR : L_TABIX.
L_TABIX = SY-TABIX.
MOVE L_TABIX TO L_ROWID.
PERFORM PRO_ERROR_CHECK USING L_ROWID.
ENDLOOP.
MESSAGE S000(ZU) WITH TEXT-004.
G_CHANGE = GC_TRUE.
* ALV Grid refresh
CALL METHOD GK_GRID->REFRESH_TABLE_DISPLAY.
PERFORM PRO_DISPLAY_PROTOCOL.
CALL METHOD GK_GRID->OPTIMIZE_FIELDS.
ENDFORM. " pro_handle_command_fdel
*&---------------------------------------------------------------------*
*& Form pro_handle_command_fadd
*&---------------------------------------------------------------------*
FORM PRO_HANDLE_COMMAND_FADD .
DATA: L_TABIX TYPE SY-TABIX,
L_ROWID TYPE INT4.
CLEAR : GS_XLIST.
GS_XLIST-STAT = 'C'.
REFRESH LT_CELLTAB.
PERFORM FILL_CELLTAB USING GS_XLIST-STAT
CHANGING LT_CELLTAB.
CLEAR GS_XLIST-CELLTAB.
INSERT LINES OF LT_CELLTAB INTO TABLE GS_XLIST-CELLTAB.
APPEND GS_XLIST TO GT_XLIST.
* ALV Grid refresh
CALL METHOD GK_GRID->REFRESH_TABLE_DISPLAY.
PERFORM PRO_DISPLAY_PROTOCOL.
ENDFORM. " pro_handle_command_fadd
*&---------------------------------------------------------------------*
*& Form pro_check_confirm
*&---------------------------------------------------------------------*
FORM PRO_CHECK_CONFIRM USING P_VAL1 P_VAL2 CHANGING P_ANS.
*
CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
EXPORTING
DEFAULTOPTION = 'Y' "-. Default
TEXTLINE1 = P_VAL1 "-. 내역.
TITEL = P_VAL2 "-. Title.
START_COLUMN = 25
START_ROW = 6
CANCEL_DISPLAY = GC_FALSE
IMPORTING
ANSWER = P_ANS.
ENDFORM. " pro_check_confirm
*&---------------------------------------------------------------------*
*& Form PRO_ERR_CHECK
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM PRO_ERR_CHECK .
CALL METHOD GK_GRID->CHECK_CHANGED_DATA
IMPORTING
E_VALID = L_VALID.
CHECK L_VALID IS NOT INITIAL.
CHECK GT_XPROT[] IS INITIAL.
LOOP AT GT_XLIST INTO GS_XLIST.
IF NOT GS_XLIST-YMTNR IS INITIAL.
IF GS_XLIST-MATNR IS INITIAL.
MESSAGE S000(ZU) WITH 'SAP material not input error'.
L_ERR_CHK = 'Y'.
ENDIF.
IF GS_XLIST-YMKTX IS INITIAL.
MESSAGE S000(ZU) WITH 'Description not input error'.
L_ERR_CHK = 'Y'.
ENDIF.
IF GS_XLIST-YINWV IS INITIAL.
MESSAGE S000(ZU) WITH 'Weight/Volumn indicator not input error'.
L_ERR_CHK = 'Y'.
ENDIF.
IF GS_XLIST-YINWV = '0'.
IF GS_XLIST-BRGEW IS INITIAL OR GS_XLIST-BRGEW LE 0.
MESSAGE S000(ZU) WITH 'Gross weight must greater than 0'.
L_ERR_CHK = 'Y'.
ENDIF.
ENDIF.
IF GS_XLIST-YINWV = '1'.
IF GS_XLIST-LAENG IS INITIAL OR GS_XLIST-LAENG LE 0
OR GS_XLIST-BREIT IS INITIAL OR GS_XLIST-BREIT LE 0
OR GS_XLIST-HOEHE IS INITIAL OR GS_XLIST-HOEHE LE 0.
MESSAGE S000(ZU) WITH 'Volumn must greater than 0'.
L_ERR_CHK = 'Y'.
ENDIF.
ENDIF.
IF ( GS_XLIST-YMEIP IS INITIAL AND GS_XLIST-YMEIN IS INITIAL )
OR ( GS_XLIST-YMEIP IS NOT INITIAL AND GS_XLIST-YMEIN IS NOT INITIAL ).
MESSAGE S000(ZU) WITH 'Only one Unit should have value'.
L_ERR_CHK = 'Y'.
ENDIF.
ENDIF.
MODIFY GT_XLIST FROM GS_XLIST.
ENDLOOP.
CALL METHOD GK_GRID->REFRESH_TABLE_DISPLAY.
ENDFORM. " PRO_ERR_CHECK
*&---------------------------------------------------------------------*
*& Form PRO_SET_SORT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM PRO_SET_SORT .
DATA : GS_SORT TYPE LVC_S_SORT.
GS_SORT-FIELDNAME = 'YMTNR'.
GS_SORT-SPOS = '1'.
GS_SORT-DOWN = GC_TRUE.
APPEND GS_SORT TO GT_SORT. CLEAR GS_SORT.
ENDFORM. " PRO_SET_SORT
*&---------------------------------------------------------------------*
*& Include YVFM0031I01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module exit INPUT
*&---------------------------------------------------------------------*
MODULE EXIT INPUT.
IF GK_CON IS NOT INITIAL.
CALL METHOD GK_CON->FREE.
FREE GK_CON.
ENDIF.
LEAVE PROGRAM.
ENDMODULE. " exit INPUT
*&---------------------------------------------------------------------*
*& Module user_command_0200 INPUT
*&---------------------------------------------------------------------*
MODULE USER_COMMAND_0200 INPUT.
SAVE_OK = OK_CODE.
CLEAR OK_CODE.
CASE SAVE_OK.
WHEN GC_BACK OR GC_EXIT.
PERFORM PRO_COMMAND_BACK.
WHEN GC_SAVE.
CLEAR L_ERR_CHK.
PERFORM PRO_ERR_CHECK.
IF L_ERR_CHK = 'Y'.
ELSE.
PERFORM PRO_CHECK_CONFIRM USING TEXT-005 TEXT-003
CHANGING L_ANS.
CHECK L_ANS EQ 'J'.
PERFORM PRO_COMMAND_SAVE.
CALL METHOD GK_GRID->REFRESH_TABLE_DISPLAY.
PERFORM PRO_DISPLAY_PROTOCOL.
CALL METHOD GK_GRID->OPTIMIZE_FIELDS.
ENDIF.
ENDCASE.
ENDMODULE. " user_command_0200 INPUT
*&---------------------------------------------------------------------*
*& Include YVFM0031E01
*&---------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM PRO_GET_DATA.
*
CALL SCREEN 200.