REPORT YTEST20160527. *定义结构 DATA:BEGIN OF SCHOOL, CITY TYPE YTJAYCITY-YCT_NAME, NO TYPE YTJAYSCHOOL-YSH_ID, NAME TYPE YTJAYSCHOOL-YSH_NAME, ADDRESS TYPE YTJAYSCHOOL-YSH_ADDR, END OF SCHOOL. *工作区 DATA SCHOOL1 LIKE SCHOOL. *输出表头 ULINE AT /(93). WRITE: / SY-VLINE,(15) '城市',SY-VLINE,(15) '学校编号', SY-VLINE,(15) '学校名称',SY-VLINE,(35) '地址',SY-VLINE. ULINE AT /(93). *输出内容 SELECT YTJAYCITY~YCT_NAME YTJAYSCHOOL~YSH_ID YTJAYSCHOOL~YSH_NAME YTJAYSCHOOL~YSH_ADDR INTO SCHOOL1 FROM YTJAYSCHOOL INNER JOIN YTJAYCITY ON YTJAYSCHOOL~YCT_ID = YTJAYCITY~YCT_ID. WRITE: / SY-VLINE,(15) SCHOOL1-CITY, SY-VLINE,(15) SCHOOL1-NO, SY-VLINE,(15) SCHOOL1-NAME, SY-VLINE,(35) SCHOOL1-ADDRESS,SY-VLINE. ULINE AT /(93). ENDSELECT.
输出结果
在上面的例子中,先输出表头,再从数据表中读取数据并输出,横竖线使用"ULINE"和"SY-VLINE"。
常见的系统变量如下:
输出无条件换页,使用语法:"NEW-PAGE"。
换页并且定义新页面的长度,使用语法:"NEW-PAGE LINE-COUNT 20"
语法:
FORMAT COLOR<n> [ON] INTENSIFIED [ON|OFF] INVERSE [ON|OFF]
COLOR 参数:
COL_BACKGROUND 取决于GUI
COL_HEADING 灰蓝
COL_NORMAL 淡灰
COL_TOTAL 黄
COL_KEY 黄绿
COL_POSITIVE 绿
COL_NEGATIVE 红
COL_GROUP 紫
INTENSIFIED参数:背景颜色参数
INVERSE参数:是否影响前景颜色
REPORT YTEST20160527. *更改背景颜色 FORMAT COLOR COL_HEADING. WRITE 'HELLO WORLD'. WRITE 'WELCOME!'. *更改前景颜色 FORMAT COLOR COL_HEADING INVERSE ON. WRITE / 'HELLO WORLD'. WRITE 'WELCOME'.
输出结果
REPORT YTEST20160527. *定义结构 DATA:BEGIN OF SCHOOL, CITY TYPE YTJAYCITY-YCT_NAME, NO TYPE YTJAYSCHOOL-YSH_ID, NAME TYPE YTJAYSCHOOL-YSH_NAME, ADDRESS TYPE YTJAYSCHOOL-YSH_ADDR, END OF SCHOOL. *工作区 DATA SCHOOL1 LIKE SCHOOL. *输出表头,背景灰蓝 FORMAT COLOR COL_HEADING. ULINE AT /(93). WRITE: / SY-VLINE,(15) '城市',SY-VLINE,(15) '学校编号', SY-VLINE,(15) '学校名称',SY-VLINE,(35) '地址',SY-VLINE. ULINE AT /(93). FORMAT COLOR OFF. *输出内容 *输出关键值为'北京'为红色 SELECT YTJAYCITY~YCT_NAME YTJAYSCHOOL~YSH_ID YTJAYSCHOOL~YSH_NAME YTJAYSCHOOL~YSH_ADDR INTO SCHOOL1 FROM YTJAYSCHOOL INNER JOIN YTJAYCITY ON YTJAYSCHOOL~YCT_ID = YTJAYCITY~YCT_ID. IF SCHOOL1-CITY = '北京'. FORMAT COLOR COL_NEGATIVE. ELSE. FORMAT COLOR OFF. ENDIF. WRITE: / SY-VLINE,(15) SCHOOL1-CITY, SY-VLINE,(15) SCHOOL1-NO, SY-VLINE,(15) SCHOOL1-NAME, SY-VLINE,(35) SCHOOL1-ADDRESS,SY-VLINE. ULINE AT /(93). ENDSELECT.
输出结果
REPORT YTEST20160527. START-OF-SELECTION. WRITE '请按'. FORMAT HOTSPOT ON COLOR 6 INVERSE ON. WRITE '热点'. FORMAT HOTSPOT OFF COLOR OFF. AT LINE-SELECTION. WRITE 'WELCOME!'.
输出结果
单击“热点”字符,输出“WELCOME!”
在单击输出行时输出第二页
REPORT YTEST20160527. START-OF-SELECTION. WRITE:'初始列表,SY-LSIND=',SY-LSIND. AT LINE-SELECTION. IF SY-LSIND = 1. WRITE: '第二列表,SY-LSIND=',SY-LSIND. ENDIF.
输出结果
单击输出行,会输出第二行
制作工具条按钮使用ABAP的菜单编辑器,TCODE:SE41
输入短文本后继续
在应用工具条栏目中,点击如下按钮,出现项目信息
在应用工具条处输入要建立的按钮名称后,双击它
选择静态文本
输入函数文本后继续
选择快捷键按钮
功能类型选择空白,为正常的应用程序功能
在功能键处的返回按钮设置有效,输入名称后,保存,激活
调用的程序代码如下
REPORT YTEST20160527. START-OF-SELECTION. *设置已使用的状态条 SET PF-STATUS 'STA1'. WRITE: '测试工具条按钮'. AT USER-COMMAND. *当单击按钮时输出 CASE SY-UCOMM. WHEN 'OWNSEL'. WRITE: '已选择!'. ENDCASE.
输出结果
当单击“我的按钮”之后,输出如下
在弹出窗口上显示状态条,状态条设计如下
程序代码如下
REPORT YTEST20160527. START-OF-SELECTION. *设置已使用的状态条 SET PF-STATUS 'STA1'. WRITE: '测试工具条按钮'. AT USER-COMMAND. *当单击按钮时输出 CASE SY-UCOMM. WHEN 'OWNSEL'. IF SY-LSIND = 1. SET PF-STATUS 'STA6'. *定义子窗口并输出 WINDOW STARTING AT 10 10 ENDING AT 30 20. WRITE '在子窗口输出!'. WRITE '请注意!'. ENDIF. ENDCASE.
输出结果
隐藏字段是指列表中存在数据但不输出,可以读取该字段。
REPORT YTEST20160527. TABLES: YTJAYCITY, YTJAYSCHOOL. START-OF-SELECTION. SKIP. *输出 ULINE AT /(55). WRITE: / SY-VLINE,(15) '城市编号',SY-VLINE,(15) '城市名称',SY-VLINE,(15) '国家',SY-VLINE. *输出 ULINE AT /(55). SELECT * FROM YTJAYCITY. WRITE:/ SY-VLINE,(15) YTJAYCITY-YCT_ID, SY-VLINE,(15) YTJAYCITY-YCT_NAME, SY-VLINE,(15) YTJAYCITY-YCT_COUNTRY, SY-VLINE. *隐藏关键字 HIDE:YTJAYCITY-YCT_ID. ULINE AT /(55). ENDSELECT. AT LINE-SELECTION. *只输出第一页 IF SY-LSIND = 1. *输出 ULINE AT /(75). WRITE: / SY-VLINE,(15) '学校编号',SY-VLINE,(15) '学校名称',SY-VLINE,(35) '地址',SY-VLINE. ULINE AT /(75). *根据隐藏字段读取并打印城市对应的学校表 SELECT * FROM YTJAYSCHOOL WHERE YCT_ID = YTJAYCITY-YCT_ID. WRITE:/ SY-VLINE,(15) YTJAYSCHOOL-YSH_ID,SY-VLINE,(15) YTJAYSCHOOL-YSH_NAME,SY-VLINE,(35) YTJAYSCHOOL-YSH_ADDR,SY-VLINE. ULINE AT /(75). ENDSELECT. ENDIF.
输出结果
双击城市表的某一行数据,显示该城市下所有的学校信息
以表YTJAYCITY数据查询为例,输入TCODE:SE16,表名YTJAYCITY,数据查询屏幕如下
最大命中数量指返回记录的最大数量。
以YCT_NAME字段为例,两个输入框是查询数据的起始值和终止值,
(1)如果不输入值,表示全部数据
(2)仅输入起始输入框,表示YCT_NAME=输入值
(3)仅输入终止输入框,表示查询数据YCT_NAME<=输入值
对每个输入框,还有模糊匹配等功能,进入输入框,单击右键菜单,屏幕显示选择项,如下图
表示排除当前选择范围,当输入选择条件,输入框右边会有提示
右边的按钮,表示单值和范围选择
选择屏幕有单个栏位检索(PARAMETERS)和范围筛选(SELECT-OPTION)两种。
单个栏位检索(PARAMETERS)
语法:
PARAMETERS<P>[DEFAULT <D>][LOWER CASE][OBLIGATORY][AS CHECKBOX][RADIOBUTTON GROUP <RG>]
[DEFAULT <D>]:默认值
[LOWER CASE]:大小写
[OBLIGATORY]:必须输入
[AS CHECKBOX]:以复选框形式
[RADIOBUTTON GROUP<RG>]:以单选按钮形式
下面例子是选择屏幕输入值,将值输出至屏幕
REPORT YTEST20160527. PARAMETERS: A1(10) TYPE C, A2 TYPE I. WRITE:/ A1,/ A2.
输出结果:点击执行按钮,输出刚才输入的值
范围筛选
使用SELECT-OPTIONS进行多值和多范围检索
REPORT YTEST20160527. DATA DATA1(20) TYPE C. SELECT-OPTIONS D1 FOR DATA1. LOOP AT D1. WRITE: / 'SIGN:', D1-SIGN, 'OPTION:', D1-OPTION, 'LOW:', D1-LOW, 'HIGH:', D1-HIGH. ENDLOOP.输出结果:点击执行按钮,输出刚才输入的范围值
调整输入提示
编写完程序时,查询条件的提示默认是变量名,需要调整为中文提示,选择菜单“转到”-->“文本元素”-->“选择文本”
修改参数D1的提示
单击按钮保存,然后单击按钮激活,单击按钮退回上一屏,单击按钮测试运行,结果如下
REPORT YTEST20160527. SELECTION-SCREEN BEGIN OF SCREEN 500. PARAMETERS DATA1(20) TYPE C. SELECTION-SCREEN END OF SCREEN 500. CALL SELECTION-SCREEN 500.输出结果
REPORT YTEST20160527. SELECTION-SCREEN BEGIN OF LINE. *预设 *SELECTION-SCREEN POSITION 28. SELECTION-SCREEN COMMENT 1(10) S2. PARAMETERS: A1(1) TYPE C, A2(4) TYPE C, S3(9) TYPE C. SELECTION-SCREEN END OF LINE. *为预设值赋值 INITIALIZATION. S2 = '测试输入'.输出结果
REPORT YTEST20160527. SELECTION-SCREEN BEGIN OF BLOCK RDG1 WITH FRAME TITLE S2. PARAMETERS A1 RADIOBUTTON GROUP RG1. PARAMETERS A2 RADIOBUTTON GROUP RG1. PARAMETERS A3 RADIOBUTTON GROUP RG1. SELECTION-SCREEN END OF BLOCK RDG1. INITIALIZATION. S2 = '请选择'.输出结果
REPORT YTEST20160527. TABLES SSCRFIELDS. DATA DONE(2) TYPE C. SELECTION-SCREEN: BEGIN OF SCREEN 500 TITLE TIT, BEGIN OF LINE, PUSHBUTTON 2(10) S1 USER-COMMAND C1, PUSHBUTTON 12(10) S2 USER-COMMAND C2, END OF LINE, END OF SCREEN 500. AT SELECTION-SCREEN. CASE SSCRFIELDS-UCOMM. WHEN 'C1'. DONE = 'C1'. WHEN 'C2'. DONE = 'C2'. ENDCASE. LEAVE TO SCREEN 0. START-OF-SELECTION. CALL SCREEN 500. WRITE: '您按了:',DONE. INITIALIZATION. S1 = '按钮1'. S2 = '按钮2'. TIT = '为选择窗口定义按钮并响应'.输出结果
PROCESS BEFORE OUTPUT. CALL SUBSCREEN A1 INCLUDING SY-REPID NUM1. PROCESS AFTER INPUT. CALL SUBSCREEN A1. MODULE USER_COMMAND-0100.加入返回码“OK_CODE"
REPORT YTEST20160527. *子定义真实的子窗口120 *定义子窗口800 SELECTION-SCREEN BEGIN OF SCREEN 800 AS SUBSCREEN. PARAMETERS: A1(10) TYPE C, A2(10) TYPE C, A3(10) TYPE C. SELECTION-SCREEN END OF SCREEN 800. *定义子窗口900 SELECTION-SCREEN BEGIN OF SCREEN 900 AS SUBSCREEN. PARAMETERS: B1(10) TYPE C, B2(10) TYPE C, B3(10) TYPE C. SELECTION-SCREEN END OF SCREEN 900. *返回码 DATA: OK_CODE TYPE SY-UCOMM, SAVE_OK TYPE SY-UCOMM. *初始窗口为800 DATA: NUM1(4) TYPE N VALUE '800'. *启动120窗口 START-OF-SELECTION. CALL SCREEN 120. *处理按钮事件 MODULE USER_COMMAND-0100 INPUT. SAVE_OK = OK_CODE. CASE SAVE_OK. *每一个按钮调用800窗口 WHEN 'S1'. NUM1 = 800. *每三个按钮调用900窗口 WHEN 'S2'. NUM1 = 900. WHEN 'EXIT'. LEAVE PROGRAM. ENDCASE. ENDMODULE.输出如下