模擬Select-Options對象實現多項數據輸入功能
*COMPLEX_SELECTIONS_DIALOG:開啟輸入多值對話框
TYPE-POOLS:icon."按鈕上顯示圖標時需要調用該類庫
DATA:l_count TYPE i."用於計算內表數值總數
DATA:lmail(50) TYPE c."定義mail地址輸入變量長度及類型
*定義屏幕元素及文本元素
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_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