ABAP屏幕显示
1write语句
Write关键词,‘/’控制输出换行
语法:write [/] <输出内容>
语法:write at [/<数字>[(数字)]] <输出内容>
示例:
DATA testTxt TYPE String value 'hello world!'.
WRITE at / testTxt."换行
WRITE at /5 testTxt."从第5列开始输出
WRITE at /(10) testTxt."只显示10位字符
WRITE at /5(15) testTxt."从第5列开始显示15位字符
WRITE:/'****************************'.
"write <obj> <format> 按照固定格式显示
WRITE / testTxt LEFT-JUSTIFIED. "靠左显示
WRITE / testTxt RIGHT-JUSTIFIED. "靠右显示
WRITE / testTxt CENTERED. "居中显示
WRITE / testTxt NO-GAP. "无空格显示
DATA testTime type String value '1234311111'.
WRITE / testTime USING EDIT MASK '__:__:__'. "使用固定格式显示
Data testData type String value '00000134'.
WRITE / testData no-ZERO."不输出前面0, no-sign 不输出正负号
DATA testData1 type F value '3.44444'.
WRITE / testData1 DECIMALS 3 . "显示小数点后位数
DATA testData2 type F value '3.44564'.
WRITE / testData2 ROUND 3. "四舍五入小数位数
"write as checkbox
WRITE:/'****************************'.
DATA: FLAG1 VALUE '',
FLAG2 VALUE 'X'.
WRITE: / 'CHECK FLAG 1:' , FLAG1 AS CHECKBOX.
WRITE: / 'CHECK FLAG 2:' , FLAG2 AS CHECKBOX.
"write as sinbol Icon
INCLUDE <SYMBOL>.
INCLUDE <ICON>.
WRITE: / 'Phone Symbol:' , SYM_PHONE AS SYMBOL.
WRITE: / 'Alarm Icon:' , ICON_ALARM AS ICON.
"Skip产生空白列
WRITE:/'****************************'.
SKIP. "产生空白列.
DATA:temp LIKE TABLE OF spfli WITH HEADER LINE.
SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE temp WHERE CARRID = 'AA'.
WRITE:/1(5)'id',(4) '国家',(18) '出发城市',(18) '目标城市'.
LOOP AT temp.
WRITE:/1(5) temp-connid,(4) temp-countryfr,(18) temp-cityfrom,(18) temp-cityto.
ENDLOOP.
2屏幕元素
语法:
输入框:
Parameters: <变量名> type <数据类型>
[default <值>]
[lower case]
[OBLIGATORY]
多选按钮:
Parameters:<变量名> as checkbox [default ‘X’].
设置是否选中
单选按钮:
Parameters:<变量名> radiobutton group <组名>
范围输入框:
Select-options <变量名> for <数据类型>
[NO DATABASE SELECTION]
[NO-EXTENSION]
[NO INTERVALS]
No database selection:如果数据类型是数据库表,不用根据表现有内容选择值;
No-extension: 范围选择框,不显示multi-option画面,
No intervals:只显示一个输入框,不显示范围输入。
单选按钮组:
Selection-screen begin of block <按钮组名> with frame.
Parameter <按钮名> radiobutton group <组名>.
…………
Selection-screen end of block <按钮组名>.
示例1:
"***************************************************
*PARAMETERS, 一些输入框,button,radioButton
***************************************************
PARAMETERS: NAME(8) TYPE C DEFAULT 'lily',"设置默认值
addr(10) type C LOWER CASE,"将输入转换成小写,默认输入转换成大写
AGE TYPE I,
BIRTH TYPE D OBLIGATORY , "设置强制输入
dog as CHECKBOX DEFAULT 'x',"多选按钮
cat as CHECKBOX .
PARAMETERS: boy RADIOBUTTON GROUP sex,"单选按钮
girl RADIOBUTTON GROUP sex.
TABLES SPFLI.
SELECT-OPTIONS AIRLINE FOR SPFLI-CONNID."范围选择框
SELECT-OPTIONS AIRLINE1 FOR SPFLI-CONNID NO-EXTENSION."范围选择框,不显示multi-option画面
SELECT-OPTIONS AIRLINE2 FOR SPFLI-CONNID NO INTERVALS."范围选择框,不显示区间画面
SELECTION-SCREEN SKIP 1. "产生两个空白列
SELECTION-SCREEN ULINE 20(30). "产生底线,位置(长度)
"选择屏幕
SELECTION-SCREEN BEGIN OF BLOCK RADIO WITH FRAME .
PARAMETER R1 RADIOBUTTON GROUP GR1.
PARAMETER R2 RADIOBUTTON GROUP GR1.
PARAMETER R3 RADIOBUTTON GROUP GR1.
SELECTION-SCREEN END OF BLOCK RADIO.
示例2:
*选择屏幕pushbutton
SELECTION-SCREEN BEGIN OF BLOCK main WITH FRAME TITLE text-001. "带边框和标题
"显示在一行
SELECTION-SCREEN BEGIN OF LINE.
"user-command,绑定命令,使用sy-ucomm可以获取到
"pushbutton 位置(长度),指定按钮出现位置和长度
SELECTION-SCREEN PUSHBUTTON 1(20) but1 USER-COMMAND bt1.
SELECTION-SCREEN PUSHBUTTON 23(20) but2 USER-COMMAND bt2.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK main.
"选择屏幕,不带标题
SELECTION-SCREEN BEGIN OF BLOCK main1 WITH FRAME . "只带边框
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON 1(20) but3 USER-COMMAND bt3.
SELECTION-SCREEN PUSHBUTTON 22(20) but4 USER-COMMAND bt4.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK main1.
INITIALIZATION.
* t1 = '输入栏名称'.
"but1 = '按键'.
CALL FUNCTION 'ICON_CREATE' "给按钮添加图标和文本
EXPORTING
name = icon_check "按钮的图片的名字
text = 'button1 按钮1' "按钮的文本
info = '按钮1'
IMPORTING
result = but1
EXCEPTIONS
OTHERS = 0.
CALL FUNCTION 'ICON_CREATE' " 给按钮添加图标和文本
EXPORTING
name = icon_execute_object " 按钮的图片的名字
text = 'button2 按钮2' "按钮的文本
info = '按钮2'
IMPORTING
result = but2
EXCEPTIONS
OTHERS = 0.
CALL FUNCTION 'ICON_CREATE' " 给按钮添加图标和文本
EXPORTING
name = icon_execute_object " 按钮的图片的名字
text = 'button3 按钮3' "按钮的文本
info = '按钮3'
IMPORTING
result = but3
EXCEPTIONS
OTHERS = 0.
CALL FUNCTION 'ICON_CREATE' " 给按钮添加图标和文本
EXPORTING
name = icon_execute_object " 按钮的图片的名字
text = 'button4 按钮4' "按钮的文本
info = '按钮4'
IMPORTING
result = but4
EXCEPTIONS
OTHERS = 0.
AT SELECTION-SCREEN.
CASE sy-ucomm.
WHEN 'BT1'.
MESSAGE '您单击了自定义按钮' TYPE 'S'.
WHEN 'BT2'.
MESSAGE '您单击了自定义按钮2' TYPE 'S'.
ENDCASE.
3屏幕弹窗
示例:
********************************************************定义弹窗
"screen 定义窗体
SELECTION-SCREEN BEGIN OF SCREEN 200 as window.
PARAMETERS:s_name(10) TYPE C.
PARAMETERS:type as CHECKBOX.
SELECTION-SCREEN END OF SCREEN 200 .
"设置弹窗位置
call SCREEN 200
STARTING AT 50 2
ENDING AT 100 2. "调用screen ,第一个横坐标,第二个纵坐标
"不设置默认include window 显示
call SCREEN 100.
4子屏幕
示例:
"用于screen painter 创建屏幕
SELECTION-SCREEN BEGIN OF SCREEN 300 as SUBSCREEN.
PARAMETERS:s_name1(10) TYPE C.
PARAMETERS:type1 as CHECKBOX.
SELECTION-SCREEN END OF SCREEN 300.
5block和screen
示例:
"*******************************************************block
*该语法在屏幕中定义一个BLOCK,其扩展语法包括:
*WITH FRAME:创建一个框架。
*TITLE title:创建一个带标题的框架。
*NO INTERVALS:所创建的框架中限制SELECT 只有一个输入项。
SELECTION-SCREEN BEGIN OF BLOCK blk1.
PARAMETERS:s_name2(10) TYPE C.
SELECTION-SCREEN END OF BLOCK blk1.
SELECTION-SCREEN BEGIN OF SCREEN 401.
SELECTION-SCREEN BEGIN OF BLOCK blk3 .
SELECTION-SCREEN BEGIN OF LINE. "同一行显示
SELECTION-SCREEN POSITION 50. "空格
PARAMETERS:s_name4(10) TYPE C.
PARAMETERS:s_name5(10) TYPE C.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK blk3.
SELECTION-SCREEN END OF SCREEN 401.
SELECTION-SCREEN BEGIN OF SCREEN 400.
"block可以在screen内
SELECTION-SCREEN BEGIN OF BLOCK blk2 WITH FRAME TITLE text-001 NO INTERVALS.
PARAMETERS:s_name3(10) TYPE C.
SELECT-OPTIONS s_type FOR SY-REPID.
SELECTION-SCREEN ULINE. "换行线
SELECTION-SCREEN SKIP 2. "产生空行
SELECTION-SCREEN END OF BLOCK blk2.
SELECT-OPTIONS s_type1 FOR SY-REPID.
"include blk,调用其他屏幕定义的block
SELECTION-SCREEN INCLUDE BLOCKS blk3.
SELECTION-SCREEN END OF SCREEN 400.
"调用屏幕
CALL SCREEN 400.
6图示和pushbutton
"**********************************************pushbutton 按钮
INCLUDE <ICON>. "图示 “TCODE”:ICON 查看图示
SELECTION-SCREEN PUSHBUTTON /1(20) btn1 USER-COMMAND btn.
SELECTION-SCREEN PUSHBUTTON /1(20) btn2 USER-COMMAND btn.
AT SELECTION-SCREEN OUTPUT.
MOVE 'my btn1' TO btn1. "为按钮1 赋值添加描述
WRITE ICON_GRAPHICS AS ICON TO btn2. "添加图示
CONCATENATE btn2 'my btn2' INTO btn2 SEPARATED BY SPACE. "按钮2赋值,并连接图示,空格连接
7组件文本显示
"*****************************************selection-screen comment 重设本地元素注释
"必须是在同一line
SELECTION-SCREEN BEGIN OF LINE.
"文本显示
SELECTION-SCREEN COMMENT (40) text-002 FOR FIELD p1.
SELECTION-SCREEN POSITION 45.
PARAMETERS p1(10) TYPE C.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS:TYPE AS CHECKBOX.
"文本显示
SELECTION-SCREEN COMMENT (40) text-003 FOR FIELD TYPE.
SELECTION-SCREEN END OF LINE.
8自定义菜单
示例1:
"******************************************SELECTION-SCREEN FUNCTION KEY n.
"用于在工具栏上新增一个功能按钮。该按钮的定义保存在系统结构体SSCRFIELDS中,
"n为一个整数的序数,例如当n等于1时,其按钮描述保存在字段SSCRFIELDS-FUNCTXT_01中,
"其按钮对象命名为“FC01",保存在字段SSCRFIELDS-UCOMM中。
"
*
TABLES SSCRFIELDS.
SELECTION-SCREEN FUNCTION KEY 1.
SELECTION-SCREEN FUNCTION KEY 2.
PARAMETERS:s_name(10) TYPE C.
INITIALIZATION.
MOVE 'BUTTON1' TO SSCRFIELDS-FUNCTXT_01.
MOVE 'BUTTON2' TO SSCRFIELDS-FUNCTXT_02.
AT SELECTION-SCREEN.
if SSCRFIELDS-UCOMM = 'FC01'.
MESSAGE i000 WITH 'press button1'.
ELSEIF SSCRFIELDS-UCOMM = 'FC02'.
MESSAGE i000 WITH 'press button2'.
ENDIF.
示例2:
"**********************工具栏菜单,通过菜单制作器
TYPE-POOLS ICON.
TABLES SSCRFIELDS.
DATA FUNCTXT TYPE SMP_DYNTXT."SMP_DYNTXT(菜单制作器:动态文本的程序接口)
PARAMETERS: P_CARRID TYPE S_CARR_ID,
P_CITYFR TYPE S_FROM_CIT.
SELECTION-SCREEN: FUNCTION KEY 1,
FUNCTION KEY 2.
INITIALIZATION. "屏幕初始化
FUNCTXT-ICON_ID = ICON_WS_PLANE."文本字段中的图标(替换显示,别名)
FUNCTXT-QUICKINFO = 'Preselected Carrier'."菜单制作器:信息文本 (4.0),鼠标移去过去显示的信息TIP
FUNCTXT-ICON_TEXT = 'LH'."菜单制作器:图标文本 (4.0),菜单名称
SSCRFIELDS-FUNCTXT_01 = FUNCTXT.
FUNCTXT-ICON_TEXT = 'UA'.
SSCRFIELDS-FUNCTXT_02 = FUNCTXT.
AT SELECTION-SCREEN.
CASE SSCRFIELDS-UCOMM.
WHEN 'FC01'.
P_CARRID = 'LH'.
P_CITYFR = 'Frankfurt'.
WHEN 'FC02'.
P_CARRID = 'UA'.
P_CITYFR = 'Chicago'.
ENDCASE.
9卷标子屏幕
示例:
"*********************************************tab 标签分页
"用于在屏幕上定义一个分页控件(tab),每个页签都是由一个子屏幕控制,n代表分页控件的高度,
"屏幕加载时必须先通过INTIALIZATION事件初始化
SELECTION-SCREEN BEGIN OF SCREEN 100 as SUBSCREEN .
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME.
PARAMETERS:s_name(10) TYPE C.
SELECTION-SCREEN END OF BLOCK blk1.
SELECTION-SCREEN END OF SCREEN 100.
SELECTION-SCREEN BEGIN OF SCREEN 200 as SUBSCREEN.
PARAMETERS:s_name1(10) TYPE C.
SELECTION-SCREEN END OF SCREEN 200.
*定义一个TAB空间,取名为MYTAB,控件高为5,共人两个选项卡BUTTON1\BUTTON2
*两个选项卡的功能代码分别为btn1\btn2
SELECTION-SCREEN:BEGIN OF TABBED BLOCK MYTAB FOR 5 LINES, "指框框高度为5LINES.
TAB (20) BUTTON1 USER-COMMAND btn1,
TAB (20) BUTTON2 USER-COMMAND btn2,
END OF BLOCK MYTAB.
INITIALIZATION.
BUTTON1 = TEXT-010.
BUTTON2 = TEXT-020.
MYTAB-PROG = SY-REPID.
MYTAB-DYNNR = 100.
AT SELECTION-SCREEN.
CASE SY-UCOMM.
WHEN 'BTN1'.
MYTAB-DYNNR = 100.
MYTAB-ACTIVETAB = 'BUTTON1'.
WHEN 'BTN2'.
MYTAB-DYNNR = 200.
MYTAB-ACTIVETAB = 'BUTTON2'.
ENDCASE.
10页签子屏幕
示例:
TABLES SSCRFIELDS.
* 定义子屏幕为100
SELECTION-SCREEN BEGIN OF SCREEN 100 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-010.
PARAMETERS: P1(10) TYPE C,
P2(10) TYPE C,
P3(10) TYPE C.
SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN END OF SCREEN 100.
* 定义子屏幕为200
SELECTION-SCREEN BEGIN OF SCREEN 200 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-020.
PARAMETERS: Q1(10) TYPE C,
Q2(10) TYPE C,
Q3(10) TYPE C.
SELECTION-SCREEN END OF BLOCK B2.
SELECTION-SCREEN END OF SCREEN 200.
*定义子屏幕为300
SELECTION-SCREEN BEGIN OF SCREEN 300 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK B3 WITH FRAME TITLE TEXT-030.
PARAMETERS: R1(10) TYPE C,
R2(10) TYPE C,
R3(10) TYPE C.
SELECTION-SCREEN END OF BLOCK B3.
SELECTION-SCREEN END OF SCREEN 300.
* STANDARD SELECTION SCREEN
SELECTION-SCREEN: FUNCTION KEY 1, "工具栏按钮
FUNCTION KEY 2.
SELECTION-SCREEN: BEGIN OF TABBED BLOCK SUB FOR 10 LINES,
END OF BLOCK SUB.
INITIALIZATION.
SSCRFIELDS-FUNCTXT_01 = '@0D@'. "按钮描述字段,图标形貌
SSCRFIELDS-FUNCTXT_02 = '@0E@'. "按钮描述字段,图标形貌
SUB-PROG = SY-REPID. "必选项
SUB-DYNNR = 100.
AT SELECTION-SCREEN.
CASE SY-DYNNR. "当前显示屏幕的名称
WHEN 100.
IF SSCRFIELDS-UCOMM = 'FC01'. "触发事件的TOOL BAR CONTROL
SUB-DYNNR = 300. "指定显示哪个屏幕
ELSEIF SSCRFIELDS-UCOMM = 'FC02'.
SUB-DYNNR = 200.
ENDIF.
WHEN 200.
IF SSCRFIELDS-UCOMM = 'FC01'.
SUB-DYNNR = 100.
ELSEIF SSCRFIELDS-UCOMM = 'FC02'.
SUB-DYNNR = 300.
ENDIF.
WHEN 300.
IF SSCRFIELDS-UCOMM = 'FC01'.
SUB-DYNNR = 200.
ELSEIF SSCRFIELDS-UCOMM = 'FC02'.
SUB-DYNNR = 100.
ENDIF.
ENDCASE.
11动态屏幕
示例:
TABLES:aufk,afvv.
SELECTION-SCREEN BEGIN OF BLOCK bl1 WITH FRAME TITLE text-002.
PARAMETERS: p1 RADIOBUTTON GROUP g1 USER-COMMAND uc DEFAULT 'X',
p2 RADIOBUTTON GROUP g1 .
PARAMETERS: p_chk AS CHECKBOX USER-COMMAND uc1.
SELECTION-SCREEN END OF BLOCK bl1.
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
SELECT-OPTIONS:s_date FOR afvv-fssld MODIF ID ty1.
SELECT-OPTIONS:s_name FOR aufk-werks MODIF ID ty1.
SELECTION-SCREEN END OF BLOCK blk1.
SELECTION-SCREEN BEGIN OF BLOCK blk2 WITH FRAME TITLE text-003.
PARAMETERS:p_werks LIKE aufk-werks MODIF ID ty2.
SELECT-OPTIONS:s_aufnr FOR aufk-aufnr MODIF ID ty2.
SELECTION-SCREEN END OF BLOCK blk2.
AT SELECTION-SCREEN OUTPUT.
PERFORM f_screen_control_show.
PERFORM f_screen_control_obli.
PERFORM f_screen_control_output.
AT SELECTION-SCREEN.
PERFORM f_chk_obli.
START-OF-SELECTION.
WRITE:/ 'screen'.
"Screen结构参数
FORM f_screen_control_parm.
LOOP AT SCREEN.
WRITE:/ 'name',screen-name.
WRITE:/ 'group1',screen-group1.
WRITE:/ 'group2',screen-group2.
WRITE:/ 'group3',screen-group3.
WRITE:/ 'group4',screen-group4.
WRITE:/ 'required',screen-required. "显示是否必输
WRITE:/ 'input',screen-input. "控制是否只读
WRITE:/ 'output',screen-output.
WRITE:/ 'itensified',screen-intensified.
WRITE:/ 'invisible',screen-invisible.
WRITE:/ 'length',screen-length.
WRITE:/ 'active',screen-active. "控制是否显示
WRITE:/ 'display_3d',screen-display_3d.
WRITE:/ 'value_helo',screen-value_help.
WRITE:/ 'request',screen-request.
WRITE:/ 'values_in_combo',screen-values_in_combo.
WRITE:/ 'color',screen-color.
ENDLOOP.
ENDFORM.
"Screen元素是否显示
FORM f_screen_control_show.
LOOP AT SCREEN.
if p1 = 'X' AND screen-group1 = 'TY2' .
"screen-active值为0:隐藏;为1:显示
screen-active = '0'.
ELSEif p2 = 'X' AND screen-group1 = 'TY1'.
screen-active = '0'.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
ENDFORM.
"Screen元素是否显示必输标志
FORM f_screen_control_obli.
"动态设置字段必输
LOOP AT SCREEN.
"这里设置modif id 为TY1为必输,只是有必输标志,真正控制需要其他代码检查
IF p1 = 'X' AND screen-group1 = 'TY1'.
"必输,screen-required = '2',必输标志
screen-required = '2'.
ENDIF.
IF p2 = 'X' AND screen-group1 = 'TY2'.
"必输,screen-required = '2',必输标志
screen-required = '2'.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
ENDFORM.
"Screen元素是否可输入
FORM f_screen_control_output.
"动态设置字段是否可输入
LOOP AT SCREEN.
IF p_chk = 'X' AND screen-group1 = 'TY1'.
"input=0,X不可输入;input=1可以输入
screen-input = '0'.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
ENDFORM.
"检查必输字段
FORM f_chk_obli.
"这里真正控制字段必输
IF p1 = 'X' AND s_date IS INITIAL.
MESSAGE s000 WITH 'Please fill all required fields'.
STOP.
ENDIF.
IF p2 = 'X' AND ( p_werks IS INITIAL OR s_aufnr IS INITIAL ).
MESSAGE s000 WITH 'Please fill all required fields'.
STOP.
ENDIF.
ENDFORM.
12弹出框
调用function,‘POPUP_WITH_TABLE_DISPLAY_OK’显示弹窗。
示例:
DATA :BEGIN OF itab OCCURS 0,
name(100) type c,
END OF itab.
itab-name = 'tang'.
APPEND itab.
itab-name = 'tang'.
APPEND itab.
call FUNCTION 'POPUP_WITH_TABLE_DISPLAY_OK'
EXPORTING endpos_col = 80
endpos_row = 8
startpos_col = 40
startpos_row = 1
titletext = 'test pop'
TABLES valuetab = itab.
参数endpos_col、endpos_row、startpos_col、startpos_row指定弹窗在主屏幕中显示位置。
调用funtion ’POPUP_TO_CONFIRM’显示一个确认弹窗。
示例:
DATA:answer(10) type c.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
TITLEBAR = '确认弹窗'
* DIAGNOSE_OBJECT = ' '
TEXT_QUESTION = '请确认'
* DEFAULT_BUTTON = '1'
DISPLAY_CANCEL_BUTTON = ''
* USERDEFINED_F1_HELP = ' '
* START_COLUMN = 25
* START_ROW = 6
* POPUP_TYPE =
* IV_QUICKINFO_BUTTON_1 = ' '
* IV_QUICKINFO_BUTTON_2 = ' '
IMPORTING
ANSWER = answer
* TABLES
* PARAMETER =
* EXCEPTIONS
* TEXT_NOT_FOUND = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
else.
WRITE:answer. "选择yes 返回1 ; 选择no 返回2; 选择cancel 返回A
ENDIF.
调用function,‘POPUP_TO_DECIDE_LIST’显示一个带单选选择列表的弹窗。
示例:
DATA: t_spopli like spopli OCCURS 0 WITH HEADER LINE.
DATA: answer(10) type c.
t_spopli-selflag = 'X'. "默认选中选项
t_spopli-varoption = 'hello world'.
t_spopli-inactive = 'X'. "是否可用
APPEND t_spopli to t_spopli.
t_spopli-selflag = 'X'.
t_spopli-varoption = 'world'.
t_spopli-inactive = ' '.
APPEND t_spopli to t_spopli.
t_spopli-selflag = ' '.
t_spopli-varoption = 'hello'.
t_spopli-inactive = ' '.
APPEND t_spopli to t_spopli.
CALL FUNCTION 'POPUP_TO_DECIDE_LIST'
EXPORTING
CURSORLINE = 2
* MARK_FLAG = ' '
* MARK_MAX = 1
* START_COL = 0
* START_ROW = 0
TEXTLINE1 = '请选择'
* TEXTLINE2 = ' '
* TEXTLINE3 = ' '
TITEL = '选择弹窗'
* DISPLAY_ONLY = ' '
IMPORTING
ANSWER = answer
TABLES
T_SPOPLI = t_spopli
* EXCEPTIONS
* NOT_ENOUGH_ANSWERS = 1
* TOO_MUCH_ANSWERS = 2
* TOO_MUCH_MARKS = 3
* OTHERS = 4
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ELSE.
WRITE:answer. "反馈选中的选项数
ENDIF.
调用function,‘FILENAME_GET’显示一个输入栏,返回输入内容弹窗。
示例:
"弹出弹窗获取用户输入文件路径
DATA:filename type SDOK_FILNM.
CALL FUNCTION 'FILENAME_GET'
EXPORTING
IV_FILENAME = 'D:\record\test.txt' "默认文件路径
TITLE = '选择文件'
IMPORTING
EV_FILENAME = filename.
WRITE:filename.
调用function,‘POPUP_TO_SELECT_MONTH’显示一个日期选择弹窗。
DATA:select_month like ISELLIST-MONTH.
DATA:return like sy-subrc.
CALL FUNCTION 'POPUP_TO_SELECT_MONTH'
EXPORTING
ACTUAL_MONTH = 11 "默认选择月份
FACTORY_CALENDAR = 'CN' "选择年份范围由factory_calendar决定
HOLIDAY_CALENDAR = 'CN'
* LANGUAGE = SY-LANGU
* START_COLUMN = 8
* START_ROW = 5
IMPORTING
SELECTED_MONTH = select_month
RETURN_CODE = return
* EXCEPTIONS
* FACTORY_CALENDAR_NOT_FOUND = 1
* HOLIDAY_CALENDAR_NOT_FOUND = 2
* MONTH_NOT_FOUND = 3
* OTHERS = 4
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ELSE.
WRITE:'选择了',select_month,'月'.
ENDIF.
调用function,‘F4_DATE’显示日期选择弹窗。
DATA:date like WORKFLDS-GKDAY.
DATA:week like SCAL-WEEK.
DATA:week_begin like sy-datum.
DATA:week_end like sy-datum.
CALL FUNCTION 'F4_DATE'
EXPORTING
DATE_FOR_FIRST_MONTH = '20180901' "初始日期,可以不传
* DISPLAY = 'x'
FACTORY_CALENDAR_ID = 'CN'
* GREGORIAN_CALENDAR_FLAG = ' '
HOLIDAY_CALENDAR_ID = 'CN'
* PROGNAME_FOR_FIRST_MONTH = ' '
* DATE_POSITION = 'x'
IMPORTING
SELECT_DATE = date
* SELECT_WEEK = week
* SELECT_WEEK_BEGIN = week_begin
* SELECT_WEEK_END = week_end
EXCEPTIONS
CALENDAR_BUFFER_NOT_LOADABLE = 1
DATE_AFTER_RANGE = 2
DATE_BEFORE_RANGE = 3
DATE_INVALID = 4
FACTORY_CALENDAR_NOT_FOUND = 5
HOLIDAY_CALENDAR_NOT_FOUND = 6
PARAMETER_CONFLICT = 7
OTHERS = 8
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
CASE sy-subrc.
WHEN 1.
WRITE:/'CALENDAR_BUFFER_NOT_LOADABLE'.
WHEN 2.
WRITE:/ 'DATE_AFTER_RANGE'.
WHEN 3.
WRITE:/ 'DATE_BEFORE_RANGE'.
WHEN 4.
WRITE:/ 'DATE_INVALID'.
WHEN 5.
WRITE:/ 'HOLIDAY_CALENDAR_ID_MISSING'.
WHEN 6.
WRITE:/ 'HOLIDAY_CALENDAR_NOT_FOUND'.
WHEN 7.
WRITE:/ 'PARAMETER_CONFLICT'.
WHEN OTHERS.
WRITE:/ 'other exception'.
ENDCASE.
ELSE.
WRITE:/'date=',date,'week=',week,'week_begin',week_begin,'week_end',week_end.
ENDIF.
13下拉选择框
实例1:
"****************************屏幕显示下拉选择框
DATA:lv_id TYPE vrm_id.
DATA:t_list TYPE vrm_values.
DATA:wa_value LIKE LINE OF t_list.
"下拉选择框
PARAMETERS:s_box TYPE C AS LISTBOX VISIBLE LENGTH 20 DEFAULT '2'.
"初始化
INITIALIZATION.
PERFORM init_listbox.
START-OF-SELECTION.
PERFORM get_sel_value.
"初始化多选框
FORM init_listbox.
wa_value-key = '1'.
wa_value-text = '选择1'.
APPEND wa_value TO t_list.
wa_value-key = '2'.
wa_value-text = '选择2'.
APPEND wa_value TO t_list.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
ID = 'S_BOX'
VALUES = t_list
EXCEPTIONS
ID_ILLEGAL_NAME = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM.
"获取多选框值
FORM get_sel_value.
"s_box值为key值
WRITE:/ s_box.
ENDFORM.
14Search Help
示例1:
"************************************************
"search help
"************************************************
DATA:gv_date TYPE datum.
DATA:gv_carrid TYPE spfli-carrid.
"自定义search help
DATA:gv_field TYPE char10.
DATA:gv_str TYPE string.
TYPES:BEGIN OF s_carrname,
carrname TYPE char20,
END OF s_carrname.
DATA:lt_carrname TYPE TABLE OF s_carrname.
DATA:ls_carrname LIKE LINE OF lt_carrname.
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME.
"1日期类型,只要定义datum类型,触发search help
PARAMETERS:p_date TYPE datum.
SELECT-OPTIONS:s_date FOR gv_date.
"2表类型,字段spfli-carrid,使用table定义search help:H_SCARR
PARAMETERS:p_carr LIKE gv_carrid.
SELECT-OPTIONS:s_carr FOR gv_carrid.
"3自定义search help值,使用f4 help
PARAMETERS:p_field LIKE gv_field.
SELECT-OPTIONS:s_field FOR gv_field.
"4使用f1,帮助文档
PARAMETERS:p_field1 LIKE gv_field.
"5已有search help,f4 help
PARAMETERS:p_field2 LIKE gv_field.
SELECT-OPTIONS:s_field2 FOR gv_field.
"6文件选择search help
PARAMETERS:p_field3 LIKE gv_str.
SELECTION-SCREEN END OF BLOCK blk1.
"使用f4帮助
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_field.
PERFORM f_search_hlp_field USING 'CARRNAME' CHANGING p_field.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_field-low.
PERFORM f_search_hlp_field USING 'CARRNAME' CHANGING s_field-low.
"使用f1帮助
AT SELECTION-SCREEN ON HELP-REQUEST FOR p_field1.
PERFORM f_search_hlp_field1.
"使用f4帮助
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_field2.
PERFORM f_search_hlp_field2 CHANGING p_field2.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_field2-low.
PERFORM f_search_hlp_field2 CHANGING s_field2-low.
"使用f4帮助
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_field3.
PERFORM f_search_hlp_field3 CHANGING p_field3.
START-OF-SELECTION.
"使用f4,返回table
FORM f_search_hlp_field
USING iv_retfield
CHANGING ev_field.
DATA:lv_retfield TYPE dfies-fieldname VALUE 'CARRNAME'.
DATA:lv_dynprofield TYPE help_info-dynprofld.
DATA:lt_return TYPE TABLE OF ddshretval.
DATA:ls_return LIKE LINE OF lt_return.
"获取search help,carrname值表
SELECT carrname INTO TABLE lt_carrname FROM scarr.
SORT lt_carrname.
DELETE ADJACENT DUPLICATES FROM lt_carrname.
"调用search help
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = iv_retfield "返回字段
dynpprog = sy-repid
dynpnr = sy-dynnr
value_org = 'S'
TABLES
value_tab = lt_carrname "search help显示值list
return_tab = lt_return "返回选择值table
.
IF sy-subrc <> 0.
MESSAGE 'Search help failed!' TYPE 'E'.
ELSE.
READ TABLE lt_return INTO ls_return INDEX 1.
ev_field = ls_return-fieldval.
ENDIF.
ENDFORM.
"f1 help,说明文档
FORM f_search_hlp_field1.
DATA:lt_links TYPE TABLE OF tline.
DATA:ls_links LIKE LINE OF lt_links.
"方式1:
CALL FUNCTION 'HELP_OBJECT_SHOW'
EXPORTING
dokclass = 'DE'
dokname = 'SYDATUM'
TABLES
links = lt_links.
* "方式2:
* CALL FUNCTION 'HELP_OBJECT_SHOW_FOR_FIELD'
* EXPORTING
* called_for_tab = 'SCARR'
* called_for_field = 'CARRNAME'.
ENDFORM.
"使用f4帮助
FORM f_search_hlp_field2
CHANGING iv_field.
DATA:lv_reset TYPE char1.
DATA:lt_return TYPE TABLE OF ddshretval.
DATA:ls_return LIKE LINE OF lt_return.
"通过使用已有table字段的search help
CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'
EXPORTING
tabname = 'SCARR'
fieldname = 'CARRID'
IMPORTING
user_reset = lv_reset
TABLES
return_tab = lt_return.
IF sy-subrc = 0.
READ TABLE lt_return INTO ls_return INDEX 1.
iv_field = ls_return-fieldval.
ENDIF.
ENDFORM.
"使用f4帮助,文件选择框
FORM f_search_hlp_field3
CHANGING iv_field.
DATA:lv_file TYPE ibipparms-path.
"调用F4_FILENAME,点击输入框后小方块弹出文件选择框
CALL FUNCTION 'F4_FILENAME'
IMPORTING
file_name = lv_file."返回文件名
IF sy-subrc = 0.
iv_field = lv_file.
ENDIF.
ENDFORM.