ABAP——选择屏幕
常用控件
效果:
代码:
************************************************************************ * 程 序 名: * 程序描述:选择屏幕 * 事务代码: ************************************************************************ * 修改日志 ************************************************************************ * 日期 版本 修改人 描述 * -------- ---- ------------ ------------------------------------------- * 20190923 1.0 Amell 创建程序 * ************************************************************************ REPORT zpprtest. *********************************************************************** * Tables Definitions ************************************************************************ TABLES: mara. ************************************************************************ * Data Definitions 定义数据 ************************************************************************ ************************************************************************ * Selection Screen 选择屏幕 ************************************************************************ SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001. PARAMETERS: p_werks TYPE marc-werks DEFAULT '2000'. "单值输入框 SELECT-OPTIONS: s_erdat FOR mara-ersda, "范围输入框 s_matnr FOR mara-matnr NO INTERVALS."范围输入框(不显示后一个输入框) SELECTION-SCREEN END OF BLOCK b1. SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-002. PARAMETERS: p_01 AS CHECKBOX. "复选框 PARAMETERS: p_02 RADIOBUTTON GROUP g1 DEFAULT 'X', "单选框 p_03 RADIOBUTTON GROUP g1. PARAMETERS: p_04(10) AS LISTBOX VISIBLE LENGTH 10. "下拉框 SELECTION-SCREEN END OF BLOCK b2. SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE TEXT-003. SELECTION-SCREEN SKIP 1. "空行 SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN COMMENT (70) TEXT-004. "一行备注 SELECTION-SCREEN END OF LINE. SELECTION-SCREEN END OF BLOCK b3. ************************************************************************ * Initialization 初始化事件 ************************************************************************ INITIALIZATION. ************************************************************************ * At Selection Screen PAI事件 ************************************************************************ AT SELECTION-SCREEN. ************************************************************************ * At Selection Screen Output PBO事件 ************************************************************************ AT SELECTION-SCREEN OUTPUT. PERFORM frm_pbo_selection_screen. ************************************************************************ * Report Format 报表格式 ************************************************************************ TOP-OF-PAGE. END-OF-PAGE. ************************************************************************ * Main Process 主要逻辑 ************************************************************************ START-OF-SELECTION. END-OF-SELECTION. *&---------------------------------------------------------------------* *& Form FRM_PBO_SELECTION_SCREEN *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_pbo_selection_screen . DATA: lv_name TYPE vrm_id, lt_list TYPE vrm_values, ls_list LIKE LINE OF lt_list. "选择屏幕增加下拉框的值 lv_name = 'P_04'. ls_list-key = '1'. ls_list-text = '广州'. APPEND ls_list TO lt_list. ls_list-key = '2'. ls_list-text = '深圳'. APPEND ls_list TO lt_list. ls_list-key = '3'. ls_list-text = '珠海'. APPEND ls_list TO lt_list. CALL FUNCTION 'VRM_SET_VALUES' EXPORTING id = lv_name values = lt_list. "控制日期范围两个输入框必填 LOOP AT SCREEN. IF screen-name = 'S_ERDAT-LOW'. screen-required = '1'. MODIFY SCREEN. ENDIF. IF screen-name = 'S_ERDAT-HIGH'. screen-required = '1'. MODIFY SCREEN. ENDIF. ENDLOOP. ENDFORM.
自定义按钮
效果:
代码:
************************************************************************ * 程 序 名: * 程序描述:选择屏幕 * 事务代码: ************************************************************************ * 修改日志 ************************************************************************ * 日期 版本 修改人 描述 * -------- ---- ------------ ------------------------------------------- * 20190923 1.0 Amell 创建程序 * ************************************************************************ REPORT zpprtest. *********************************************************************** * Tables Definitions ************************************************************************ TABLES: sscrfields. ************************************************************************ * Data Definitions 定义数据 ************************************************************************ DATA: gs_functxt TYPE smp_dyntxt. ************************************************************************ * Selection Screen 选择屏幕 ************************************************************************ PARAMETERS: p_werks TYPE marc-werks OBLIGATORY. SELECTION-SCREEN: FUNCTION KEY 1. "下载模板按钮 SELECTION-SCREEN: FUNCTION KEY 2. "导入模板按钮 ************************************************************************ * Initialization 初始化事件 ************************************************************************ INITIALIZATION. PERFORM frm_init_selection_screen. ************************************************************************ * At Selection Screen PAI事件 ************************************************************************ AT SELECTION-SCREEN. ************************************************************************ * At Selection Screen Output PBO事件 ************************************************************************ AT SELECTION-SCREEN OUTPUT. ************************************************************************ * Report Format 报表格式 ************************************************************************ TOP-OF-PAGE. END-OF-PAGE. ************************************************************************ * Main Process 主要逻辑 ************************************************************************ START-OF-SELECTION. END-OF-SELECTION. *&---------------------------------------------------------------------* *& Form FRM_INIT_SELECTION_SCREEN *&---------------------------------------------------------------------* *& 初始化选择屏幕 *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_init_selection_screen . "选择屏幕增加按钮 gs_functxt-icon_id = icon_export. "按钮图标 gs_functxt-quickinfo = '下载模板'. "鼠标聚焦在按钮上显示 gs_functxt-icon_text = '下载模板'. "按钮说明 sscrfields-functxt_01 = gs_functxt. CLEAR gs_functxt. gs_functxt-icon_id = icon_import. "按钮图标 gs_functxt-quickinfo = '导入模板'. "鼠标聚焦在按钮上显示 gs_functxt-icon_text = '导入模板'. "按钮说明 sscrfields-functxt_02 = gs_functxt. CLEAR gs_functxt. ENDFORM.
动态显示
效果:
代码:
************************************************************************ * 程 序 名: * 程序描述:选择屏幕 * 事务代码: ************************************************************************ * 修改日志 ************************************************************************ * 日期 版本 修改人 描述 * -------- ---- ------------ ------------------------------------------- * 20190923 1.0 Amell 创建程序 * ************************************************************************ REPORT zpprtest. *********************************************************************** * Tables Definitions ************************************************************************ ************************************************************************ * Data Definitions 定义数据 ************************************************************************ ************************************************************************ * Selection Screen 选择屏幕 ************************************************************************ SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001. PARAMETERS: c_01 AS CHECKBOX USER-COMMAND u01, r_01 RADIOBUTTON GROUP g1 DEFAULT 'X' MODIF ID dat, r_02 RADIOBUTTON GROUP g1 MODIF ID dat, c_02 AS CHECKBOX USER-COMMAND u01, r_03 RADIOBUTTON GROUP g2 DEFAULT 'X' MODIF ID qty, r_04 RADIOBUTTON GROUP g2 MODIF ID qty. SELECTION-SCREEN END OF BLOCK b1. ************************************************************************ * Initialization 初始化事件 ************************************************************************ INITIALIZATION. ************************************************************************ * At Selection Screen PAI事件 ************************************************************************ AT SELECTION-SCREEN. ************************************************************************ * At Selection Screen Output PBO事件 ************************************************************************ AT SELECTION-SCREEN OUTPUT. PERFORM frm_pbo_selection_screen. ************************************************************************ * Report Format 报表格式 ************************************************************************ TOP-OF-PAGE. END-OF-PAGE. ************************************************************************ * Main Process 主要逻辑 ************************************************************************ START-OF-SELECTION. END-OF-SELECTION. *&---------------------------------------------------------------------* *& Form FRM_PBO_SELECTION_SCREEN *&---------------------------------------------------------------------* *& 选择屏幕显示前处理 *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_pbo_selection_screen . "根据是否勾选日期或数量来显示对应的单选框 LOOP AT SCREEN. IF screen-group1 = 'DAT'. IF c_01 = 'X'. screen-active = 1. ELSE. screen-active = 0. ENDIF. ENDIF. IF screen-group1 = 'QTY'. IF c_02 = 'X'. screen-active = 1. ELSE. screen-active = 0. ENDIF. ENDIF. MODIFY SCREEN. ENDLOOP. ENDFORM.
选项卡
效果:
代码:
************************************************************************ * 程 序 名: * 程序描述:选择屏幕 * 事务代码: ************************************************************************ * 修改日志 ************************************************************************ * 日期 版本 修改人 描述 * -------- ---- ------------ ------------------------------------------- * 20190923 1.0 Amell 创建程序 * ************************************************************************ REPORT zpprtest. *********************************************************************** * Tables Definitions ************************************************************************ ************************************************************************ * Data Definitions 定义数据 ************************************************************************ ************************************************************************ * Selection Screen 选择屏幕 ************************************************************************ SELECTION-SCREEN BEGIN OF SCREEN 100 AS SUBSCREEN. SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN COMMENT (70) TEXT-001. SELECTION-SCREEN END OF LINE. SELECTION-SCREEN END OF SCREEN 100. SELECTION-SCREEN BEGIN OF SCREEN 200 AS SUBSCREEN. SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN COMMENT (70) TEXT-002. SELECTION-SCREEN END OF LINE. SELECTION-SCREEN END OF SCREEN 200. SELECTION-SCREEN: BEGIN OF TABBED BLOCK tab FOR 10 LINES, TAB (25) tab1 USER-COMMAND u01, TAB (25) tab2 USER-COMMAND u02, END OF BLOCK tab. ************************************************************************ * Initialization 初始化事件 ************************************************************************ INITIALIZATION. PERFORM frm_init_selection_screen. ************************************************************************ * At Selection Screen PAI事件 ************************************************************************ AT SELECTION-SCREEN. PERFORM frm_pai_selection_screen. ************************************************************************ * At Selection Screen Output PBO事件 ************************************************************************ AT SELECTION-SCREEN OUTPUT. ************************************************************************ * Report Format 报表格式 ************************************************************************ TOP-OF-PAGE. END-OF-PAGE. ************************************************************************ * Main Process 主要逻辑 ************************************************************************ START-OF-SELECTION. CASE tab-dynnr. WHEN '100'. WRITE '执行了选项卡1'. WHEN '200'. WRITE '执行了选项卡2'. ENDCASE. END-OF-SELECTION. *&---------------------------------------------------------------------* *& Form FRM_INIT_SELECTION_SCREEN *&---------------------------------------------------------------------* *& 初始化选择屏幕 *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_init_selection_screen . tab1 = TEXT-003. tab2 = TEXT-004. tab-prog = sy-repid. "取内存里的mytab-dynnr IMPORT tab-dynnr TO tab-dynnr FROM MEMORY ID 'TAB'. "为了用户返回选择屏幕的时候,默认选中之前已经选择的选项卡 IF tab-dynnr IS INITIAL. tab-dynnr = 100. tab-activetab = 'U01'. ELSE. CASE tab-dynnr. WHEN 100. tab-dynnr = 100. tab-activetab = 'U01'. WHEN 200. tab-dynnr = 200. tab-activetab = 'U02'. ENDCASE. ENDIF. ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_PAI_SELECTION_SCREEN *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_pai_selection_screen . CASE sy-ucomm. WHEN 'ONLI'. "用内存记录的mytab-dynnr EXPORT tab-dynnr FROM tab-dynnr TO MEMORY ID 'TAB'. WHEN 'U01'. tab-dynnr = 100. tab-activetab = 'TAB1'. WHEN 'U02'. tab-dynnr = 200. tab-activetab = 'TAB2'. ENDCASE. ENDFORM.
落霞与孤鹜齐飞,秋水共长天一色