ABAP学习(18):ABAP弹窗function
ABAP弹出框
SAP中可以使用function,显示弹窗。根据不同弹窗类型,SAP对弹出框进行了分组,例如:SPO1,SPO2等。SAP系统中有一些这些分组的函数的样例函数,可以通过 RS+分组+* 进行搜索,例如SPO4的弹窗样例,使用RSSPO4*进行搜索。所有的function源码都在Package:SZP下。
1.SP01类型
包含一些提示信息,让用户确认的弹窗。
示例1:POPUP_TO_CONFIRM函数使用
"显示弹窗 FORM spo1_pop. "接收选择结果 DATA:ANSWER(1) TYPE C. "传入表,没啥用 DATA:parm LIKE TABLE OF SPAR WITH HEADER LINE. "使用popup_to_confirm,一个确认弹窗 CALL FUNCTION 'POPUP_TO_CONFIRM' EXPORTING "弹窗标题 TITLEBAR = '请确认' "额外文本,可以使用se61维护Dialog Text, "示例中使用:TEXT1_ZUM_POPUP_TO_CONFIRM DIAGNOSE_OBJECT = '' "弹窗显示确认问题文本 TEXT_QUESTION = '这是弹窗显示确认问题' "最左边按钮文本,默认yes TEXT_BUTTON_1 = 'yes' "最左边按钮图标:Table:Icon,Tcode:Icon都可以查看图标,传入icon名 ICON_BUTTON_1 = 'ICON_CHECKED' "中间按钮文本,默认no TEXT_BUTTON_2 = 'No' "中间按钮图标 ICON_BUTTON_2 = 'ICON_INCOMPLETE' "初始选中按钮 DEFAULT_BUTTON = '1' "是否显示cancel按钮 DISPLAY_CANCEL_BUTTON = 'X' "显示一个info按钮,帮助信息,但是se61找不到对应值 USERDEFINED_F1_HELP = 'TEST_TEXT_ZUR_SPO1' "弹窗开始列 START_COLUMN = 25 "弹窗开始行 START_ROW = 6 "弹窗文本左边图标 POPUP_TYPE = 'ICON_MESSAGE_INFORMATION' "未知功能 * IV_QUICKINFO_BUTTON_1 = '' * IV_QUICKINFO_BUTTON_2 = '' IMPORTING "选择值1:yes;2:no;A:cancel; ANSWER = ANSWER TABLES "传入table,源码没使用? PARAMETER = parm * EXCEPTIONS * TEXT_NOT_FOUND = 1 * OTHERS = 2 . IF SY-SUBRC <> 0. MESSAGE s000 WITH 'error'. ELSE. MESSAGE s000 WITH answer. ENDIF. ENDFORM.
示例2:POPUP_TO_CONFIRM_STEP使用
FORM spo1_pop1. "提示do not use "接收选择结果 DATA:ANSWER(1) TYPE C. CALL FUNCTION 'POPUP_TO_CONFIRM_STEP' EXPORTING DEFAULTOPTION = 'Y' "显示两行文本 TEXTLINE1 = 'textline 1' TEXTLINE2 = 'textline 2' "弹窗标题 TITEL = 'popup title' START_COLUMN = 25 START_ROW = 6 "是否显示cancel按钮 CANCEL_DISPLAY = '' IMPORTING "返回值J:yes;N:no;A:cancel ANSWER = ANSWER. IF SY-SUBRC <> 0. MESSAGE s000 WITH 'error'. ELSE. MESSAGE s000 WITH answer. ENDIF. ENDFORM.
示例3:POPUP_TO_CONFIRM_WITH_VALUE函数使用
FORM spo1_pop2. "提示do not use "接收选择结果 DATA:ANSWER(1) TYPE C. CALL FUNCTION 'POPUP_TO_CONFIRM_WITH_VALUE' EXPORTING "默认按钮 DEFAULTOPTION = 'Y' "显示文本 OBJECTVALUE = '100' "文本后缀 TEXT_AFTER = '%' "文本前缀 TEXT_BEFORE = '百分比:' TITEL = 'title' START_COLUMN = 25 START_ROW = 6 CANCEL_DISPLAY = 'X' IMPORTING ANSWER = ANSWER. IF SY-SUBRC <> 0. MESSAGE s000 WITH 'error'. ELSE. MESSAGE s000 WITH answer. ENDIF.
类似还有函数:POPUP_TO_CONFIRM_WITH_MESSAGE,POPUP_TO_CONFIRM_LOSS_OF_DATA,但是都不推荐使用,这种提示信息的直接使用POPUP_TO_CONFIRM就够了。
2.SPO2类型
和SPO1类似,显示一些信息供用户确认。
示例1:POPUP_TO_DECIDE函数使用
"显示三行文本弹窗 FORM spo2_pop1. "do not use "接收选择结果 DATA:ANSWER(1) TYPE C. "显示弹窗 CALL FUNCTION 'POPUP_TO_DECIDE' EXPORTING "默认按钮 DEFAULTOPTION = '1' "三行文本 TEXTLINE1 = 'first line' TEXTLINE2 = 'second line' TEXTLINE3 = 'third line' "按钮1,2的文本 TEXT_OPTION1 = 'yes' TEXT_OPTION2 = 'no' "按钮1,2的图标 * ICON_TEXT_OPTION1 = ' ' * ICON_TEXT_OPTION2 = ' ' "弹窗标题 TITEL = 'title' "开始行列 START_COLUMN = 25 START_ROW = 6 "是否显示cancel按钮 CANCEL_DISPLAY = 'X' IMPORTING "选择返回1:按钮1;2:按钮2;A:cancel按钮 ANSWER = ANSWER. IF SY-SUBRC <> 0. MESSAGE s000 WITH 'error'. ELSE. MESSAGE s000 WITH answer. ENDIF. ENDFORM.
示例2:POPUP_TO_DECIDE_WITH_MESSAGE函数使用
FORM spo2_pop2. "do not use "接收选择结果 DATA:ANSWER(1) TYPE C. "显示弹窗 CALL FUNCTION 'POPUP_TO_DECIDE_WITH_MESSAGE' EXPORTING "默认按钮 DEFAULTOPTION = '1' "diagno文本,必须有一个 DIAGNOSETEXT1 = 'dia1' * DIAGNOSETEXT2 = 'dia2' * DIAGNOSETEXT3 = 'dia3' "text文本行,至少有一个 TEXTLINE1 = 'text1' * TEXTLINE2 = 'text2' * TEXTLINE3 = 'text3' "按钮文本 TEXT_OPTION1 = 'yes' TEXT_OPTION2 = 'no' "按钮图标 * ICON_TEXT_OPTION1 = * ICON_TEXT_OPTION2 = "标题 TITEL = 'title' START_COLUMN = 25 START_ROW = 6 CANCEL_DISPLAY = 'X' IMPORTING ANSWER = answer. IF SY-SUBRC <> 0. MESSAGE s000 WITH 'error'. ELSE. MESSAGE s000 WITH answer. ENDIF. ENDFORM.
3.SPO4类型
接收用户输入信息弹窗。
示例1:使用POPUP_GET_VALUES函数
使用table类型参数fields结构:
tabname:接收值所在数据库表名
fieldname:字段名
value:值,用户输入或预设
field_obl:是否必输栏位
fieldtext:栏位文本
"显示输入值弹窗 FORM spo4_pop. "接收值的字段 DATA:fileds TYPE TABLE OF sval WITH HEADER LINE. DATA:retcode(1) TYPE C. "设置字段 CLEAR fileds. fileds-tabname = 'SPFLI'. fileds-fieldname = 'CARRID'. fileds-value = '02'. * fileds-fieldtext = '航班id'. APPEND fileds. CLEAR fileds. fileds-tabname = 'SPFLI'. fileds-fieldname = 'CONNID'. fileds-field_obl = 'X'. APPEND fileds. CALL FUNCTION 'POPUP_GET_VALUES' EXPORTING "是否值检查 NO_VALUE_CHECK = '' "标题 POPUP_TITLE = 'title' "设置位置 START_COLUMN = '5' START_ROW = '5' IMPORTING "点击cancel,返回A RETURNCODE = retcode TABLES "接收值的字段内表 FIELDS = fileds. IF SY-SUBRC <> 0. * Implement suitable error handling here MESSAGE s000 WITH retcode. ELSE. MESSAGE s000 WITH retcode. LOOP AT fileds. WRITE: / fileds-fieldname,fileds-value. ENDLOOP. ENDIF. ENDFORM.
示例2:POPUP_GET_VALUES_DB_CHECKED函数,填写数据会验证是否在数据库中存在
FORM spo4_pop1. "接收值的字段 DATA:fileds TYPE TABLE OF sval WITH HEADER LINE. DATA:retcode(1) TYPE C. "设置字段 CLEAR fileds. fileds-tabname = 'SPFLI'. fileds-fieldname = 'CARRID'. APPEND fileds. CALL FUNCTION 'POPUP_GET_VALUES_DB_CHECKED' EXPORTING "是否检查填写数据是否存在 CHECK_EXISTENCE = 'X' "title POPUP_TITLE = 'title' "位置设置 START_COLUMN = '5' START_ROW = '5' IMPORTING RETURNCODE = retcode TABLES FIELDS = fileds. IF SY-SUBRC <> 0. * Implement suitable error handling here MESSAGE s000 WITH retcode. ELSE. MESSAGE s000 WITH retcode. LOOP AT fileds. WRITE: / fileds-fieldname,fileds-value. ENDLOOP. ENDIF. ENDFORM.
示例3:POPUP_GET_VALUES_USER_CHECKED函数,可以执行额外程序的子form程序,做栏位输入检查
FORM spo4_pop2. "接收值的字段 DATA:fileds TYPE TABLE OF sval WITH HEADER LINE. DATA:retcode(1) TYPE C. "设置字段 CLEAR fileds. fileds-tabname = 'SPFLI'. fileds-fieldname = 'CARRID'. APPEND fileds. "弹窗获取输入值执行额外form CALL FUNCTION 'POPUP_GET_VALUES_USER_CHECKED' EXPORTING "执行的form名 FORMNAME = 'CHECK_EXIT' POPUP_TITLE = 'title' "form所在program名 PROGRAMNAME = 'TEST_POPUP' "开始行列 START_COLUMN = '5' START_ROW = '5' "??? NO_CHECK_FOR_FIXED_VALUES = '' IMPORTING RETURNCODE = retcode TABLES FIELDS = fileds. IF SY-SUBRC <> 0. * Implement suitable error handling here MESSAGE s000 WITH retcode. ELSE. MESSAGE s000 WITH retcode. ENDIF. ENDFORM. "执行用户自定义检查逻辑,当error有值,显示info弹窗 FORM check_exit TABLES fileds STRUCTURE sval CHANGING error STRUCTURE svale. LOOP AT fileds. "自定义检查是否数据库存在 SELECT SINGLE * FROM SPFLI WHERE CARRID = fileds-value. IF sy-subrc <> 0. "数据库表 ERROR-ERRORTAB = 'SPFLI'. "检查字段 ERROR-ERRORFIELD = 'CARRID'. "package:SZP下message classes中可以找到对应值 ERROR-MSGTY = 'I'. ERROR-MSGID = 'S4'. ERROR-MSGNO = '510'. ENDIF. ENDLOOP. ENDFORM.
示例4:POPUP_GET_VALUES_USER_HELP函数,可以执行额外程序的子form程序,做栏位输入检查,自定义f1,f4帮助
FORM spo4_pop3. "接收值的字段 DATA:fileds TYPE TABLE OF sval WITH HEADER LINE. DATA:retcode(1) TYPE C. "设置字段 CLEAR fileds. fileds-tabname = 'SPFLI'. fileds-fieldname = 'CARRID'. APPEND fileds. CALL FUNCTION 'POPUP_GET_VALUES_USER_HELP' EXPORTING "F1帮助from名 F1_FORMNAME = 'F1_HELP' "F1帮助form所在program F1_PROGRAMNAME = 'TEST_POPUP' "F4帮助form名 F4_FORMNAME = 'F4_HELP' "F4帮助所在program F4_PROGRAMNAME = 'Z_TEST_POPUP' "自定义检查form名 * FORMNAME = ' ' POPUP_TITLE = 'title' "自定义检查form所在program * PROGRAMNAME = ' ' "设置显示位置 * START_COLUMN = '5' * START_ROW = '5' * NO_CHECK_FOR_FIXED_VALUES = ' ' IMPORTING RETURNCODE = retcode TABLES FIELDS = fileds. IF SY-SUBRC <> 0. * Implement suitable error handling here MESSAGE s000 WITH retcode. ELSE. MESSAGE s000 WITH retcode. ENDIF. ENDFORM. FORM f1_help USING TABNAME FIELDNAME. MESSAGE s000 WITH TABNAME FIELDNAME 'no f1 help'. ENDFORM. "F4帮助逻辑 FORM f4_help USING TABNAME FIELDNAME DISPLAY CHANGING RETURNCODE VALUE. DATA: BEGIN OF F_TAB OCCURS 10. INCLUDE STRUCTURE HELP_VALUE. DATA: END OF F_TAB, BEGIN OF V_TAB OCCURS 200, VALUE(40) TYPE C, END OF V_TAB. "字段表 F_TAB-TABNAME = 'SPFLI'. F_TAB-FIELDNAME = 'CARRID'. F_TAB-SELECTFLAG = 'X'. APPEND F_TAB. "填充值 SELECT * FROM SPFLI. V_TAB = SPFLI-CARRID. APPEND V_TAB. ENDSELECT. "显示获取到的值 CALL FUNCTION 'HELP_VALUES_GET_WITH_TABLE' EXPORTING * CUCOL = 0 * CUROW = 0 DISPLAY = DISPLAY FIELDNAME = FIELDNAME TABNAME = TABNAME * NO_MARKING_OF_CHECKVALUE = ' ' * TITLE_IN_VALUES_LIST = ' ' * TITEL = ' ' * SHOW_ALL_VALUES_AT_FIRST_TIME = ' ' * NO_CONVERSION = ' ' IMPORTING SELECT_VALUE = VALUE TABLES FIELDS = F_TAB VALUETAB = V_TAB. ENDFORM.
示例5:POPUP_GET_VALUES_USER_BUTTONS函数,可以执行额外程序的子form程序,自定义f1,f4帮助,多两个功能按钮执行额外逻辑
FORM spo4_pop4. "接收值的字段 DATA:fileds TYPE TABLE OF sval WITH HEADER LINE. DATA:retcode(1) TYPE C. DATA:ICON_OK_PUSH LIKE ICON-NAME VALUE ICON_OKAY. DATA:ICON_CREATE_PUSH LIKE ICON-NAME VALUE ICON_CREATE. DATA:ICON_SEARCH_PUSH LIKE ICON-NAME VALUE ICON_SEARCH. "设置字段 CLEAR fileds. fileds-tabname = 'SPFLI'. fileds-fieldname = 'CARRID'. APPEND fileds. CALL FUNCTION 'POPUP_GET_VALUES_USER_BUTTONS' EXPORTING "F1帮助from名,form所在program名 * F1_FORMNAME = ' ' * F1_PROGRAMNAME = ' ' "F4帮助from名,form所在program名 * F4_FORMNAME = ' ' * F4_PROGRAMNAME = ' ' "用户点击按钮响应form,form所在program名 FORMNAME = 'USER_CODE' PROGRAMNAME = 'Z_TEST_POPUP' "title POPUP_TITLE = 'title' "ok按钮文本,图标及提示 OK_PUSHBUTTONTEXT = 'ok' ICON_OK_PUSH = ICON_OK_PUSH QUICKINFO_OK_PUSH = 'ok' "按钮1文本,图标及提示 FIRST_PUSHBUTTON = 'creat' ICON_BUTTON_1 = ICON_CREATE_PUSH QUICKINFO_BUTTON_1 = 'creat something' "按钮2文本,图标及提示 SECOND_PUSHBUTTON = 'seach' ICON_BUTTON_2 = ICON_SEARCH_PUSH QUICKINFO_BUTTON_2 = 'search something' * START_COLUMN = '5' * START_ROW = '5' * NO_CHECK_FOR_FIXED_VALUES = ' ' IMPORTING RETURNCODE = retcode TABLES FIELDS = fileds * EXCEPTIONS * ERROR_IN_FIELDS = 1 * OTHERS = 2 . IF SY-SUBRC <> 0. * Implement suitable error handling here MESSAGE s000 WITH retcode. ELSE. MESSAGE s000 WITH retcode. ENDIF. ENDFORM. "响应用户选点击按钮 FORM USER_CODE TABLES FIELDS STRUCTURE SVAL USING CODE CHANGING ERROR STRUCTURE SVALE SHOW_POPUP. CASE CODE. "点击ok按钮 WHEN 'FURT'. MESSAGE s000 WITH 'button ok' code. "按钮响应后,是否弹窗继续显示,为空直接关闭,为X不不关闭 SHOW_POPUP = ''. "点击button1 WHEN 'COD1'. MESSAGE s000 WITH 'button1' code. SHOW_POPUP = 'X'. "点击button2 WHEN 'COD2'. MESSAGE s000 WITH 'button2' code. SHOW_POPUP = 'X'. ENDCASE. ENDFORM.
4.SPO5类型
示例1:POPUP_TO_DECIDE_LIST函数,显示弹窗包含一个选项表,供用户选择,单选或多选。
FORM spo5_pop. "选择列表 DATA: t_selist LIKE SPOPLI OCCURS 5 WITH HEADER LINE. DATA: answer TYPE C. "选择标志 t_selist-SELFLAG = 'X'. "选项 t_selist-VAROPTION = '选项1'. "INACTIVE字段控制是否不可选 * t_selist-INACTIVE = 'X'. APPEND t_selist. t_selist-SELFLAG = ''. t_selist-VAROPTION = '选项2'. APPEND t_selist. "显示一个选择列表 CALL FUNCTION 'POPUP_TO_DECIDE_LIST' EXPORTING "光标所在选项行 CURSORLINE = 1 "单选按钮,多选框 "MARK_FLAG不设置,MARK_MAX = 1单选 "MARK_FLAG="X",MARK_MAX = 0 多选checkbox * MARK_FLAG = 'X' MARK_MAX = 1 "设置弹窗位置 * START_COL = 0 * START_ROW = 0 TEXTLINE1 = 'text1' TEXTLINE2 = 'text2' TEXTLINE3 = 'text3' "title TITEL = 'title' "仅显示 * DISPLAY_ONLY = 'X' IMPORTING ANSWER = answer TABLES T_SPOPLI = t_selist. IF SY-SUBRC <> 0. * Implement suitable error handling here MESSAGE s000 WITH answer. ELSE. MESSAGE s000 WITH answer. ENDIF. ENDFORM.
5.SPO6类型
示例1:POPUP_DISPLAY_TEXT函数,显示se61创建文本
FORM spo6_pop. DATA: CANCELLED(1) TYPE C. "显示文本text,只能是se61创建text CALL FUNCTION 'POPUP_DISPLAY_TEXT' EXPORTING "语言 * LANGUAGE = SY-LANGU "标题 POPUP_TITLE = 'title' "位置 * START_COLUMN = 10 * START_ROW = 3 "文本对象,se61,dialog text类型创建 TEXT_OBJECT = 'SPO_EXAMPLE_1' "helpmodal * HELP_MODAL = 'X' IMPORTING CANCELLED = CANCELLED. IF SY-SUBRC <> 0. * Implement suitable error handling here MESSAGE s000 WITH CANCELLED. ELSE. MESSAGE s000 WITH CANCELLED. ENDIF. "POPUP_DISPLAY_TEXT_WITH_PARAMS函数 "text_objext = 'SPO_EXAMPLE_2',可以在se61中找到,参数名规则:"&参数名&" "定义参数表,可以在文本中插入参数 "DATA:params LIKE SPAR OCCURS 0 WITH HEADER LINE. "PARAM字段:参数名;VALUE字段:参数值 ENDFORM.
示例2:POPUP_DISPLAY_TEXT函数,显示se61创建文本,显示自定义按钮button
FORM spo6_pop1. DATA:params LIKE SPAR OCCURS 0 WITH HEADER LINE. DATA:USER_BUTTONS LIKE SMP_DYNTXT OCCURS 0 WITH HEADER LINE. DATA:answer LIKE RSNEWLENG-FCODE. params-PARAM = 'V1'. params-VALUE = '参数1'. APPEND params. "设置自定义按钮 USER_BUTTONS-TEXT = 'tips1'. USER_BUTTONS-ICON_ID = ICON_CLOSE. USER_BUTTONS-ICON_TEXT = 'exit'. APPEND USER_BUTTONS. CALL FUNCTION 'POPUP_DISPLAY_TEXT_USER_BUTTON' EXPORTING "语言 * LANGUAGE = SY-LANGU "title POPUP_TITLE = 'title' "位置 * START_COLUMN = 5 * START_ROW = 5 * DOCU_CLASS = 'DT' "文本对象,se61建立dialog text类型创建 TEXT_OBJECT = 'SPO_EXAMPLE_2' "是否显示ok,cancel按钮 DISPLAY_OK_BUTTON = 'X' DISPLAY_CANCEL_BUTTON = 'X' IMPORTING ANSWER = answer TABLES "用户自定义按钮 USER_BUTTONS = USER_BUTTONS PARAMETER = params. IF SY-SUBRC <> 0. * Implement suitable error handling here MESSAGE s000 WITH answer. ELSE. MESSAGE s000 WITH answer. ENDIF. ENDFORM.
本文来自博客园,作者:渔歌晚唱,转载请注明原文链接:https://www.cnblogs.com/tangToms/p/12458812.html