模拟Select-Options对象实现多项数据输入功能
Select-Options对象可以同时输入多项值并将所输入数据存入内表以供程序使用,不过Select-Options的功能有一定的局限性,它所能显示信息的长度是固定的,对于一些较长的文本,会因为输出长度过短而影响显示效果(如地址信息)。本例将以邮件地址输入字段为例,创建一个长度为50的可输入多值的文本对象。
本例中需要定义一个隐藏的Select-Options对象,用于保存实际输入数据。需要定义一个够长的文本框及一个多值输入按钮作为数据传递的接口。数据会通过所定义的文本框传递到隐藏的Select-Options对象中,并通过改变多值输入按钮上的图标样式来表示该对象中是否存在数据。
相关函数:
COMPLEX_SELECTIONS_DIALOG:开启输入多值对话框
- REPORT ZR_EXAMPLE_04 .
- TYPE-POOLS: ICON. “按钮上显示图标时需要调用该类库
- DATA: L_COUNT TYPE I. “用于计算内表数值总数
- DATA: LMAIL(50) TYPE C. “定义Mail地址输入变量长度及类型
- *定义屏幕元素及文本元素(参考第7章)
- SELECTION-SCREEN: BEGIN OF BLOCK ALV WITH FRAME TITLE TEXT-002.
- SELECTION-SCREEN: BEGIN OF LINE.
- SELECTION-SCREEN: COMMENT (14) TEXT-001.
- PARAMETERS: MAILCOPY LIKE LMAIL.
- SELECTION-SCREEN: PUSHBUTTON 63(5) PUBU USER-COMMAND MAILBUTT.
- SELECTION-SCREEN: END OF LINE.
- SELECTION-SCREEN: END OF BLOCK ALV.
- DATA: MAILTYPE TYPE C VALUE ”.
- *定义一隐藏的SELECT-OPTIONS用于保存输入值
- SELECT-OPTIONS: MAILADD FOR LMAIL NO-DISPLAY .
- AT SELECTION-SCREEN OUTPUT.
- CLEAR L_COUNT.
- DESCRIBE TABLE MAILADD LINES L_COUNT.
- *判断内表是否有值来设置按钮图标
- IF L_COUNT > 1.
- WRITE ICON_DISPLAY_MORE AS ICON TO PUBU.
- ELSE.
- WRITE ICON_ENTER_MORE AS ICON TO PUBU.
- ENDIF.
- AT SELECTION-SCREEN.
- CLEAR L_COUNT.
- DESCRIBE TABLE MAILADD LINES L_COUNT.
- *实现内表与文本元素间的值传递
- IF NOT MAILCOPY IS INITIAL AND MAILADD[] IS INITIAL.
- MAILADD-LOW = MAILCOPY.
- APPEND MAILADD.
- ENDIF.
- IF L_COUNT = 1.
- REFRESH MAILADD.
- CLEAR MAILADD.
- IF NOT MAILCOPY IS INITIAL.
- MAILADD-LOW = MAILCOPY.
- APPEND MAILADD.
- ENDIF.
- ENDIF.
- IF L_COUNT > 1 .
- IF MAILCOPY IS INITIAL.
- DELETE MAILADD INDEX 1.
- ELSE.
- MAILADD-LOW = MAILCOPY.
- MODIFY MAILADD INDEX 1 TRANSPORTING LOW.
- ENDIF.
- ENDIF.
- *在单击按钮的事件时调用输入多值输入对话框
- IF SY-UCOMM = ‘MAILBUTT’.
- PERFORM SHOW_BOX.
- ENDIF.
- *———————————————————————*
- * 调用多值输入对话框 *
- *———————————————————————*
- FORM SHOW_BOX.
- TYPE-POOLS AQADH .
- DATA: TAB_AND_FIELD TYPE RSTABFIELD.
- TAB_AND_FIELD-TABLENAME = ‘ADR6’.
- TAB_AND_FIELD-FIELDNAME = ‘SMTP_ADDR’.
- *该函数将输入值传递给内表
- CALL FUNCTION ‘COMPLEX_SELECTIONS_DIALOG’
- EXPORTING
- TEXT = ‘SET E-Mail To ‘
- TAB_AND_FIELDTAB_AND_FIELD = TAB_AND_FIELD
- TABLES
- RANGE = MAILADD[]
- EXCEPTIONS
- NO_RANGE_TAB = 1
- CANCELLED = 2
- INTERNAL_ERROR = 3
- OTHERS = 4.
- *将内表首行值传给文本对象,显示在屏幕上
- IF NOT MAILADD[] IS INITIAL.
- READ TABLE MAILADD INDEX 1.
- MAILCOPY = MAILADD-LOW.
- ELSE.
- MAILCOPY = ”.
- ENDIF.
- ENDFORM
程序输出界面如图16-4所示。
IT虾米网 |
图16-4 自定义多值输入文本对象执行界面 |
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/18283.html