&---------------------------------------------------------------------*
*& REPORT ZTEST
*&
*&---------------------------------------------------------------------*
REPORT ZTEST_ALV_UPDATE NO STANDARD PAGE HEADING.
*&---------------------------------------------------------------------*
*& TYPE-POOLS
*&---------------------------------------------------------------------*
TYPE-POOLS:
SLIS.
*&---------------------------------------------------------------------*
*& TYPES
*&---------------------------------------------------------------------*
TYPES:
BEGIN OF TYP_T001,
BUKRS TYPE T001-BUKRS,
BUTXT TYPE T001-BUTXT,
ORT01 TYPE T001-ORT01,
FMHRDATE TYPE T001-FMHRDATE,
BUVAR TYPE T001-BUVAR,
DDROP TYPE INT4,
END OF TYP_T001.
*&---------------------------------------------------------------------*
*& DATA
*&---------------------------------------------------------------------*
DATA:
TD_LIST TYPE LVC_T_DROP,
TD_FIELDCAT TYPE TABLE OF LVC_S_FCAT,
TD_T001 TYPE TABLE OF TYP_T001.
DATA:
TH_LAYOUT TYPE LVC_S_LAYO.
**&---------------------------------------------------------------------*
**& CLASS CL_EVENT_RECEIVER DEFINITION
**&---------------------------------------------------------------------*
*CLASS CL_EVENT_RECEIVER DEFINITION.
*
* PUBLIC SECTION.
*
* METHODS:
* DATA_CHANGE FOR EVENT DATA_CHANGED_FINISHED OF CL_GUI_ALV_GRID.
*
*ENDCLASS.
*
*CLASS CL_EVENT_RECEIVER IMPLEMENTATION.
*
* METHOD DATA_CHANGE.
*
* ENDMETHOD.
*
*ENDCLASS.
*&---------------------------------------------------------------------*
*& AT SELECTION-SCREEN
*&---------------------------------------------------------------------*
INITIALIZATION.
*&---------------------------------------------------------------------*
*& AT SELECTION-SCREEN
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN.
*&---------------------------------------------------------------------*
*& AT SELECTION-SCREEN
*&---------------------------------------------------------------------*
START-OF-SELECTION.
* 取数据
PERFORM FRM_GET_DATA.
* ALV显示
PERFORM FRM_DISPLAY_ALV.
*&---------------------------------------------------------------------*
*& FORM FRM_GET_DATA
*&---------------------------------------------------------------------*
* 取数据
*----------------------------------------------------------------------*
FORM FRM_GET_DATA .
SELECT BUKRS
BUTXT
ORT01
FMHRDATE
BUVAR
INTO TABLE TD_T001
FROM T001
WHERE BUKRS < 'CA01'.
ENDFORM. " FRM_GET_DATA
*&---------------------------------------------------------------------*
*& FORM FRM_DISPLAY_ALV
*&---------------------------------------------------------------------*
* ALV显示
*----------------------------------------------------------------------*
FORM FRM_DISPLAY_ALV .
* FIELDCAT设置
PERFORM FRM_SET_FIELDCAT.
* LAYOUT设置
PERFORM FRM_SET_LAYOUT.
* ALV画面输出
PERFORM FRM_OUTPUT_ALV.
ENDFORM. " FRM_DISPLAY_ALV
*&---------------------------------------------------------------------*
*& FORM FRM_SET_FIELDCAT
*&---------------------------------------------------------------------*
* FIELDCAT设置
*----------------------------------------------------------------------*
FORM FRM_SET_FIELDCAT .
* FIELDCAT 各项属性设置
PERFORM FRM_SET_FIELDCAT_ATTRIBUTE USING: 'BUKRS' '公司代码' SPACE SPACE,
'BUTXT' '公司名称' SPACE SPACE,
'ORT01' '所在城市' SPACE SPACE,
'FMHRDATE' '日期' 'X' SPACE,
'BUVAR' '选择框' 'X' 'X',
'DDROP' '下拉框' 'X' SPACE.
ENDFORM. " FRM_SET_FIELDCAT
*&---------------------------------------------------------------------*
*& FORM FRM_SET_FIELDCAT_ATTRIBUTE
*&---------------------------------------------------------------------*
* FIELDCAT 各项属性设置
*----------------------------------------------------------------------*
* -->I_FIELDNAME 字段名
* -->I_SCRTEXT_L 标签名
* -->I_EDIT 可编辑
*----------------------------------------------------------------------*
FORM FRM_SET_FIELDCAT_ATTRIBUTE USING I_FIELDNAME TYPE LVC_S_FCAT-FIELDNAME
I_SCRTEXT_L TYPE LVC_S_FCAT-SCRTEXT_L
I_EDIT TYPE LVC_S_FCAT-EDIT
I_CHECKBOX TYPE LVC_S_FCAT-CHECKBOX.
* 局部变量的定义
DATA:
LTH_FIELDCAT TYPE LVC_S_FCAT.
LTH_FIELDCAT-FIELDNAME = I_FIELDNAME.
LTH_FIELDCAT-SCRTEXT_L = I_SCRTEXT_L.
LTH_FIELDCAT-EDIT = I_EDIT.
LTH_FIELDCAT-CHECKBOX = I_CHECKBOX.
IF LTH_FIELDCAT-FIELDNAME = 'DDROP'.
LTH_FIELDCAT-DRDN_FIELD = 'DDROP'.
ENDIF.
APPEND LTH_FIELDCAT TO TD_FIELDCAT.
CLEAR:
LTH_FIELDCAT.
ENDFORM. " FRM_SET_FIELDCAT_ATTRIBUTE
*&---------------------------------------------------------------------*
*& FORM FRM_SET_LAYOUT
*&---------------------------------------------------------------------*
* LAYOUT设置
*----------------------------------------------------------------------*
FORM FRM_SET_LAYOUT .
DATA:
LW_TABIX TYPE SY-TABIX,
LTH_T001 LIKE LINE OF TD_T001,
LTH_LIST TYPE LVC_S_DROP.
LOOP AT TD_T001 INTO LTH_T001.
LW_TABIX = SY-TABIX.
LTH_LIST-HANDLE = LW_TABIX.
LTH_LIST-VALUE = 'AAA'.
APPEND LTH_LIST TO TD_LIST.
CLEAR LTH_LIST.
LTH_LIST-HANDLE = LW_TABIX.
LTH_LIST-VALUE = 'BBB'.
APPEND LTH_LIST TO TD_LIST.
CLEAR LTH_LIST.
LTH_T001-DDROP = LW_TABIX.
MODIFY TD_T001 FROM LTH_T001.
CLEAR LTH_T001.
ENDLOOP.
TH_LAYOUT-CWIDTH_OPT = 'X'.
ENDFORM. " FRM_SET_LAYOUT
*&---------------------------------------------------------------------*
*& FORM FRM_OUTPUT_ALV
*&---------------------------------------------------------------------*
* ALV画面输出
*----------------------------------------------------------------------*
FORM FRM_OUTPUT_ALV .
DATA:
LTD_EVENT TYPE TABLE OF slis_alv_event,
LTH_EVENT TYPE slis_alv_event,
W_TITLE TYPE SY-TITLE.
W_TITLE = 'ALV明细画面'.
SY-TITLE = W_TITLE.
* CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
* EXPORTING
* I_LIST_TYPE = 0
* IMPORTING
* ET_EVENTS = LTD_EVENT
* EXCEPTIONS
* LIST_TYPE_WRONG = 1
* OTHERS = 2
* .
* IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
* ENDIF.
*
* LOOP AT LTD_EVENT INTO LTH_EVENT.
* IF LTH_EVENT-NAME = 'CALLER_EXIT'.
* LTH_EVENT-FORM = 'FRM_ENTER_BUTTON'.
* MODIFY LTD_EVENT FROM LTH_EVENT.
* ENDIF.
* ENDLOOP.
LTH_EVENT-NAME = 'CALLER_EXIT'.
LTH_EVENT-FORM = 'FRM_SET_DDROP'.
APPEND LTH_EVENT TO LTD_EVENT.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_PF_STATUS_SET = 'FRM_SET_STATUS'
I_CALLBACK_USER_COMMAND = 'FRM_SET_COMMAND'
IS_LAYOUT_LVC = TH_LAYOUT
IT_FIELDCAT_LVC = TD_FIELDCAT
I_DEFAULT = 'X'
I_SAVE = 'A'
IT_EVENTS = LTD_EVENT
TABLES
T_OUTTAB = TD_T001
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " FRM_OUTPUT_ALV
*&---------------------------------------------------------------------*
*& FORM FRM_SET_DDROP
*&---------------------------------------------------------------------*
* 下拉框事件的添加
*----------------------------------------------------------------------*
FORM FRM_SET_DDROP USING EXCLUDING.
DATA:
* LW_EVENT_RECEIVER TYPE REF TO CL_EVENT_RECEIVER,
* LTH_LIST TYPE LVC_S_DROP,
* LTD_LIST TYPE LVC_T_DROP,
LW_GRID TYPE REF TO CL_GUI_ALV_GRID.
* LTH_LIST-HANDLE = 1.
* LTH_LIST-VALUE = 'AAA'.
* APPEND LTH_LIST TO LTD_LIST.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = LW_GRID
.
CALL METHOD LW_GRID->SET_DROP_DOWN_TABLE
EXPORTING
IT_DROP_DOWN = TD_LIST
* IT_DROP_DOWN_ALIAS =
.
* CREATE OBJECT LW_EVENT_RECEIVER.
* SET HANDLER:
* LW_EVENT_RECEIVER->DATA_CHANGE FOR LW_GRID.
ENDFORM.
*&---------------------------------------------------------------------*
*& FRM_SET_STATUS
*&---------------------------------------------------------------------*
* 自定义状态栏
*----------------------------------------------------------------------*
FORM FRM_SET_STATUS USING EXCLUDING.
SET PF-STATUS 'STANDARD_FULLSCREEN'.
ENDFORM.
FORM FRM_SET_COMMAND USING I_UCOMM TYPE SY-UCOMM
I_SELFIELD TYPE SLIS_SELFIELD.
ENDFORM.
来源:https://www.cnblogs.com/xjm123/p/3604397.html