一, 屏幕基本元素(单值输入框,RANGE输入,单选按钮,复选框定义)
TABLES: SFLIGHT.
SELECTION-SCREEN BEGIN OF BLOCK bk1 WITH FRAME TITLE text-001.
PARAMETERS: P_CARRID LIKE SFLIGHT-CARRID ." 单值输入框
SELECT-OPTIONS: "定义RANGE输入
S_CARRID FOR SFLIGHT-CARRID ,
S_CONNID FOR SFLIGHT-CONNID ,
S_1 FOR SCARR-CARRID DEFAULT 'AA' TO 'AZ' OPTION BT SIGN E . "设置默认值
SELECTION-SCREEN SKIP 1. "屏幕换行
PARAMETERS: PR_01 RADIOBUTTON GROUP gp1 DEFAULT 'X', "定义RADIOBUTTON
PR_02 RADIOBUTTON GROUP gp1.
PARAMETERS: p_old TYPE c AS CHECKBOX. "定义复选框
SELECTION-SCREEN ULINE.
SELECTION-SCREEN SKIP 1. "屏幕换行
SELECTION-SCREEN COMMENT 1(65) TEXT-T02 ."屏幕上输出文本
SELECTION-SCREEN SKIP 1. "屏幕换行
SELECTION-SCREEN PUSHBUTTON 30(10) PHB_01 USER-COMMAND PB1 . "添加按钮
SELECTION-SCREEN END OF BLOCK bk1.
DEFAULT 'A' | 设置初始值 |
LENGTH N | 定义长度,只适用于C,N,X,P |
DECIMALS des | 指定小数点位数 |
MEMORY ID pid | 指定SAP内存参数ID |
MATCHCODE OBJECT mobj | 设定使用的Search Help (SE11 中定义搜索帮助) |
MODIF ID | 通过screen-group1为屏幕元素分组 |
NO-DISPLAY | 不显示在画面上 |
LOWER CASE | 区分大小写(默认大写) |
DEFAULT 'A' | 始值初始值 |
DEFAULT g... OPTION op... SIGN s | 设置初始的option和sign |
DEFAULT g TO h | 设置初始的LOW值和HIGH值 ,SIGN为 ‘BT’ |
DEFAULT g TO h OPTION op... SIGN s | 设置初始的OPTION,SIGN, LOW值和HIGH值 ,SIGN只能为BT 或 NB |
MEMORY ID pid | 指定SAP内存参数ID |
MATCHCODE OBJECT mobj | 设定使用的Search Help |
OBLIGATORY | 设定必输项,画面上显示?,不输入时自动报错 |
VISIBLE LENGTH vlen | 设置显示长度 |
NO-EXTENSION | 隐藏多指输入按钮 |
NO INTERVALS | 隐藏HIGH 输入部分 |
1.2 添加 FUNCTION KEY .
TABLES: SSCRFIELDS .
SELECTION-SCREEN FUNCTION KEY 1.
SELECTION-SCREEN FUNCTION KEY 2.
SELECTION-SCREEN FUNCTION KEY 3.
DATA LS_DYNTXT TYPE SMP_DYNTXT .
CLEAR LS_DYNTXT .
LS_DYNTXT-ICON_ID = ICON_CREATE .
LS_DYNTXT-QUICKINFO = 'CREATE' .
SSCRFIELDS-FUNCTXT_02 = LS_DYNTXT .
CLEAR LS_DYNTXT .
LS_DYNTXT-ICON_ID = ICON_DISPLAY .
LS_DYNTXT-QUICKINFO = 'DISPLAY' .
SSCRFIELDS-FUNCTXT_02 = LS_DYNTXT .
CLEAR LS_DYNTXT .
LS_DYNTXT-ICON_ID = ICON_DELETE .
LS_DYNTXT-QUICKINFO = 'DELETE' .
SSCRFIELDS-FUNCTXT_02 = LS_DYNTXT .
二,SELECTION-SCREEN BEGIN OF LINE 应用, 将多个参数组合后显示在一行中,在行组中不能使用SELECT-OPTIONS, SELECTION-SCREEN SKIP N 语句
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: P_BOX AS CHECKBOX.
"指定关于参数的描述 SELECTION-SCREEN COMMENT fmt name
SELECTION-SCREEN COMMENT 5(29) text-001.
PARAMETERS: P_TEXT TYPE string.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE. "list 带描述
SELECTION-SCREEN COMMENT 1(31) TEXT-L01 FOR FIELD P_LIST.
PARAMETERS: P_LIST TYPE T001-BUKRS AS LISTBOX VISIBLE LENGTH 10 USER-COMMAND LS1.
PARAMETERS: P_BUTXT TYPE T001-BUTXT.
SELECTION-SCREEN END OF LINE.
SELECT SINGLE BUTXT FROM T001 INTO P_BUTXT WHERE BUKRS = P_LIST .
为下拉框赋值 CALL FUNCTION 'VRM_SET_VALUES'
TYPE-POOLS VRM.
DATA: VID TYPE VRM_ID VALUE 'xxx', "下拉框的名称
VLIST TYPE VRM_VALUES,
VALUES LIKE LINE OF VLIST.
SELECT ZKEY AS KEY
TEXT
FROM ZSTU_SALARY
INTO CORRESPONDING FIELDS OF TABLE VLIST[]
ORDER BY KEY
.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
ID = VID
VALUES = VLIST
EXCEPTIONS
ID_ILLEGAL_NAME = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE '下拉框出错,请联系管理员!' TYPE 'I' DISPLAY LIKE 'S'.
ENDIF.
三, 动态修改选择屏幕
3.1 SCRENN 参数
选择屏幕、对话屏幕都有对应的SCREEN内表,下面是几个重要属性:
Name : Name of the screen field。如果参数是select-options类型参数,则参数名以LOW与HIGH后缀来区分。
GROUP: 选择屏幕元素通过MODIF ID 选项设置GROUP1(对话屏幕通过属性设置),将屏幕元素分为一组,方便屏幕的元素的批量修改
REQUIRED:控制文本框、下拉列表屏幕元素的必输性,使用此属性后会忽略OBLIGATORY选项。取值如下:
0:不必输,框中前面也没有钩
1:必输,框中前面有钩,系统会自动检验是否已输入,相当于OBLIGATORY选项
2:不必输,但框中前面有钩,系统不会检查是否已输入,此时需要手动检验INPUT:控制屏幕元素(包括复选框、单选框、文本框)的可输性
ACTIVE:控制屏幕元素的可见性
3.2 屏幕假必输,将输入框的REQUIRED属性设置为2(显示必须的钩,但系统不会自动进行必输验证),去掉OBLIGATORY选 项(不去掉也会被忽略),并在AT SELECTION-SCREEN ON field事件里时手动进行为空验证
PARAMETERS P_INPUT(128) MODIF ID mxy .
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN .
"的必输性:外观上打钩,但不自动校验
IF screen-group1 = 'MXY'.
screen-required = '2'."外观上打钩,但不自动校验
MODIFY SCREEN.
ENDLOOP.
AT SELECTION-SCREEN ON P_INPUT.
IF P_INPUT IS INITIAL
MESSAGE e055(00).
ENDIF.
3.3 屏幕隐藏字段
PARAMETERS: RB_01 RADIOBUTTON GROP G1 USER-COMMAND RA1,
RB_02 RADIOBUTTON GROP G1 .
LOOP AT SCREEN .
CASE 'X' .
WHEN RB_01 .
IF SCREEN-GROUP1 = '***'
SCREEN-ACTIVE = 1 .
MODIFY SCREEN .
ENDIF.
WHEN RB_02 .
IF SCREEN-GROUP1 = '***'
SCREEN-ACTIVE = 0 .
MODIFY SCREEN .
ENDIF.
ENDLOOP.
四, 屏幕事件
INITIALIZATION "初始化屏幕字段(SET TITLEBAR ,GUI STATUS, SET PF-STATUS),主要用于显示SELECTION-SCREEN之前
AT SELECTION-SCREEN " 屏幕跳出之前
START-OF-SELECTION "取数据,在 START-OF-SELECTION 事件处,也 处理没有附 加到事件关 键字的所有 语句,或在 FORM-ENDFORM 块后写这些 语句
END-OF-SELECTION "展示数据,要在系统读取和处理完 逻辑数据库的所有数据库表之后定过程块
TOP-OF-PAGE "普通报表输出页头
END-OF-PAGE "普通报表输出页尾
AT SELECTION-SCREEN(类似一个FORM),在屏幕中INPUT FIELD的值有变更时执行的事件,例如CHECKBOX的选择与否,RADIOBUTTON的选择,LISTBOX的选择等等。
所以分为以下几个方面:
1. ... ON field :对SELECTION SCREEN具体的字段进行校验,若错误则重新输入,其他字段变灰
2. ... ON END OF sel :SELECT-OPTION触发的事件,用于整个选择表输入结束后各行的检查
3. ... OUTPUT :设置屏幕上画面布局
4. ... ON HELP-REQUEST FOR psel_low_high :当光标位于某屏幕字段时,选择的帮助(F1)
5. ... ON RADIOBUTTON GROUP radi :单选按钮事件,必须进行整体输入检查
6. ... ON BLOCK block :抑制块内输入值
7. ... ON VALUE-REQUEST FOR psel_low_high :当光标位于某屏幕字段时,选择的帮助(F4)
4.2 START-OF-SELECTION中的事件,STOP关键字终止过程块,转向 END-OF-SELECTION, 而EXIT关键字终止程序块后不执行 END-OF-SELECTION 过程块
WRITE 'Test Program for STOP'.
DO 3 TIMES.
WRITE : / 'STOP' , SY-INDEX.
STOP .
ENDDO.
END-OF-SELECTION.
WRITE: / 'End of selection'.
START-OF-SELECTION .
WRITE 'Test Program for exit'.
DO 3 TIMES.
WRITE : / 'EXIT' , SY-INDEX.
ENDDO.
EXIT .
END-OF-SELECTION.
WRITE: / 'End of selection'.
五、屏幕数据检查
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE."常用于F4搜索帮助
AT SELECTION-SCREEN ON RADIOBUTTON GROUP G1."对单选按钮的检查
CASE 'X'.
WHEN R1.
MESSAGE '默认R1 已被选择' TYPE 'I' .
WHEN R2.
MESSAGE 'R2 已被选择' TYPE 'I' .
WHEN R3.
MESSAGE 'R3 已被选择' TYPE 'I' .
WHEN OTHERS.
ENDCASE.
AT SELECTION-SCREEN ON BLOCK B1.
IF NUM3 GT 1000 or num2 GT 1000 or num1 GT 1000.
MESSAGE '请输入小于1000的数字' TYPE 'E'.
ENDIF.