SAP:观察I_CALLBACK_USER_COMMAND 参数(按钮点击事件)
1、从函数级SLVC_FULLSCREEN里复制 一个在 ”GUI状态“ 下的 “STANDARD_FULLSCREEN”标准全屏幕到 程序Z16_04里。
标准工具添加 定义按钮(关闭、保存)
主程序代码:
*&---------------------------------------------------------------------* *& Report Z16_04 *& 利用 REUSE_ALV_GRID_DISPLAY *&---------------------------------------------------------------------* *& 添加"结束"按钮, *& 1、关闭按钮的关闭程序事件 *& 2、 从函数组 SLVC_FULLSCREEN里复制 GUI状态下的STANDARD_FULLSCREEN . *&---------------------------------------------------------------------* REPORT Z16_04. TYPE-POOLS: SLIS. DATA: GT_EVENTS TYPE SLIS_T_EVENT. DATA: GS_EVENT TYPE SLIS_ALV_EVENT. " ALV 事件 DATA gt_itab TYPE TABLE OF sflight. SELECT * FROM SFLIGHT INTO table GT_ITAB UP TO 25 ROWS. MOVE 'PF_STATUS_SET' TO GS_EVENT-NAME. MOVE 'ALV_STATUS_SET' TO GS_EVENT-FORM. APPEND GS_EVENT TO GT_EVENTS. *& 调用函数 REUSE_ALV_GRID_DISPLAY ,比较 例子 Z16_01 *& 的 REUSE_ALV_LIST_DISPLAY 函数。 CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING * I_INTERFACE_CHECK = ' ' * I_BYPASSING_BUFFER = ' ' * I_BUFFER_ACTIVE = ' ' I_CALLBACK_PROGRAM = sy-repid "程序名称 , I_CALLBACK_PF_STATUS_SET = ' ' " 'alv_status_set' I_CALLBACK_USER_COMMAND = 'ALV_USER_COMMAND' " 按钮事件命令 * I_CALLBACK_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_END_OF_LIST = ' ' I_STRUCTURE_NAME = 'SFLIGHT' * I_BACKGROUND_ID = ' ' * I_GRID_TITLE = * I_GRID_SETTINGS = * IS_LAYOUT = * IT_FIELDCAT = * IT_EXCLUDING = * IT_SPECIAL_GROUPS = * IT_SORT = * IT_FILTER = * IS_SEL_HIDE = * I_DEFAULT = 'X' * I_SAVE = ' ' * IS_VARIANT = IT_EVENTS = gt_events * IT_EVENT_EXIT = * IS_PRINT = * IS_REPREP_ID = * I_SCREEN_START_COLUMN = 0 * I_SCREEN_START_LINE = 0 * I_SCREEN_END_COLUMN = 0 * I_SCREEN_END_LINE = 0 * I_HTML_HEIGHT_TOP = 0 * I_HTML_HEIGHT_END = 0 * IT_ALV_GRAPHICS = * IT_HYPERLINK = * IT_ADD_FIELDCAT = * IT_EXCEPT_QINFO = * IR_SALV_FULLSCREEN_ADAPTER = * IMPORTING * E_EXIT_CAUSED_BY_CALLER = * ES_EXIT_CAUSED_BY_USER = TABLES T_OUTTAB = gt_itab * EXCEPTIONS * PROGRAM_ERROR = 1 * OTHERS = 2 . IF SY-SUBRC <> 0. * Implement suitable error handling here ENDIF. *&------------------------------------------------- *& Form alv_status_set *&------------------------------------------------- *& ALV 自定义工具栏 *&------------------------------------------------ FORM ALV_STATUS_SET USING PT_EXTAB TYPE SLIS_T_EXTAB. CLEAR: PT_EXTAB[]. " 注释在画面上追加'ALV_STATUS'的语句,追加标准ALV_STATUS语句。 "SET PF-STATUS 'ALV_STATUS'. SET PF-STATUS 'STANDARD_FULLSCREEN'. " 追加标准工具栏" ENDFORM. "ALV_STATUS_SET *&------------------------------------------------- *& Form ALV_USER_COMMAND *&------------------------------------------------- *& ALV "关闭" 按钮的点击事件 *&------------------------------------------------ FORM ALV_USER_COMMAND USING p_ucomm LIKE SY-ucomm p_selfield TYPE slis_selfield. "BREAK-POINT. " 单击按钮时传递的命令追加设断点的语句。 CASE p_ucomm. WHEN 'CLOSE'. " 当点击关闭时,退出程序 。 LEAVE PROGRAM. "离开程序(退出程序) WHEN 'SAVE'. MODIFY sflight FROM TABLE gt_itab. " 内表数据保存到数据库表 WHEN OTHERS. ENDCASE. " CASE条件结束。 ENDFORM. " ALV_USER_COMMAND
alv_user_command:
*&------------------------------------------------- *& Form ALV_USER_COMMAND *&------------------------------------------------- *& ALV "关闭" 按钮的点击事件 *&------------------------------------------------ FORM ALV_USER_COMMAND USING p_ucomm LIKE SY-ucomm p_selfield TYPE slis_selfield. "BREAK-POINT. " 单击按钮时传递的命令追加设断点的语句。 CASE p_ucomm. WHEN 'CLOSE'. " 当点击关闭时,退出程序 。 LEAVE PROGRAM. "离开程序(退出程序) WHEN 'SAVE'. MODIFY sflight FROM TABLE gt_itab. " 内表数据保存到数据库表 WHEN OTHERS. ENDCASE. " CASE条件结束。 ENDFORM. " ALV_USER_COMMAND
运行效果:
优质生活从拆开始