在Selection Screen上面要做出listbox不是一件困難的事情,參照下面的寫法就很簡單了
REPORT ZLISTBOX.
*引用type-pool VRM
TYPE-POOLS: VRM.
*宣告internal table及workarea
DATA: IT_VAL1 TYPE VRM_VALUES. "第一個下拉選單
DATA: IT_VAL2 TYPE VRM_VALUES. "第二個下拉選單
DATA: W_LINE LIKE LINE OF IT_VAL1. "work area
*選擇畫面欄位,指定為LISTBOX
PARAMETERS: P_BUKRS LIKE T001-BUKRS AS LISTBOX
VISIBLE LENGTH 25 OBLIGATORY.
PARAMETERS: P_MONTH LIKE T247-MNR AS LISTBOX
VISIBLE LENGTH 12 OBLIGATORY.
*初始化時將資料讀入下拉選單table
INITIALIZATION.
SELECT BUKRS BUTXT FROM T001 INTO (W_LINE-KEY, W_LINE-TEXT).
APPEND W_LINE TO IT_VAL1.
CHECK P_BUKRS IS INITIAL.
P_BUKRS = W_LINE-KEY.
ENDSELECT.
SELECT MNR LTX FROM T247 INTO (W_LINE-KEY, W_LINE-TEXT)
WHERE SPRAS = SY-LANGU.
APPEND W_LINE TO IT_VAL2.
CHECK P_MONTH IS INITIAL.
P_MONTH = W_LINE-KEY.
ENDSELECT.
*選擇畫面出現時將下拉選單的值指到table的
AT SELECTION-SCREEN OUTPUT.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
ID = 'P_BUKRS'
VALUES = IT_VAL1.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
ID = 'P_MONTH'
VALUES = IT_VAL2.
*印出下拉選單選出來的資料
END-OF-SELECTION.
WRITE: / 'Company Code:', P_BUKRS.
WRITE: / 'Month:', P_MONTH.
執行結果如下: