主要的程式
====================================================
TYPE-POOLS: VRM.
DATA: NAME TYPE VRM_ID,
LIST TYPE VRM_VALUES,
VALUE LIKE LINE OF LIST.
NAME = 'P_LIST'.
VALUE-KEY = '1'.
VALUE-TEXT = 'LINE 1'.
APPEND VALUE TO LIST.
VALUE-KEY = '2'.
VALUE-TEXT = 'LINE 2'.
APPEND VALUE TO LIST.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING ID = NAME VALUES = LIST.
====================================================
一、Create dropdown in selection screen
在一般的 Report,則透過 FUNCTION VRM_SET_VALUES 針對畫面中的 OBJECT 來進行設定,其結果如下
SAMPLE PROGRAM :
====================================================REPORT Z_EX_RPT_DROPDOWN_LIST.
TYPE-POOLS: VRM.
DATA: NAME TYPE VRM_ID,
LIST TYPE VRM_VALUES,
VALUE LIKE LINE OF LIST.
PARAMETERS: P_LIST(10) AS LISTBOX VISIBLE LENGTH 10.
AT SELECTION-SCREEN OUTPUT.
NAME = 'P_LIST'.
VALUE-KEY = '1'.
VALUE-TEXT = 'LINE 1'.
APPEND VALUE TO LIST.
VALUE-KEY = '2'.
VALUE-TEXT = 'LINE 2'.
APPEND VALUE TO LIST.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING ID = NAME VALUES = LIST.
START-OF-SELECTION.
WRITE: / 'PARAMETER:', P_LIST.
====================================================
上面程式宣告了一個 PARAMTER,以 LISTBOX 顯示,長度 10
PARAMETERS: P_LIST(10) AS LISTBOX VISIBLE LENGTH 10.
二、Create dropdown in table control or screen
有時侯在建己建立的 Screen 中也想要加入下 Dropdown Listbox 時,也可以用於 Input/Output Field 或是在 Table Control
在 Screen 選擇 Input/Output Field 後,於 Dropdown 選擇 Listbox or Listbox With Key
Table Control 中的 Input/Output Field 也同樣選擇 Listbox or Listbox With Key
Report 是在 AT SELECTION-SCREEN OUTPUT. 中呼叫 FUNCTION 'VRM_SET_VALUES',但在 Screen 中則要在 PBO 中宣告一個 MODULE 進行呼叫
Sample Program :
====================================================
REPORT Z_EX_RPT_DROPDOWN_LIST2.
TYPE-POOLS VRM.
DATA : OK_CODE LIKE SY-UCOMM.
DATA : BEGIN OF ITAB OCCURS 0,
DROPDOWN TYPE C,
END OF ITAB.
DATA : WA_ITAB LIKE ITAB.
CONTROLS : TC_0100 TYPE TABLEVIEW USING SCREEN 0100.
"自訂下拉選單用
DATA: G_NAME TYPE VRM_ID,
G_LIST TYPE VRM_VALUES,
G_VALUE LIKE LINE OF G_LIST.
INITIALIZATION.
START-OF-SELECTION.
CALL SCREEN 0100.
END-OF-SELECTION.
"Screen 0100 Status
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'S0100'.
MODULE INIT_DROPDOWN.
ENDMODULE. " STATUS_0100 OUTPUT
"Screen 0100 PAI Command
MODULE USER_COMMAND_0100 INPUT.
CASE OK_CODE.
WHEN 'BACK' OR 'CANC' OR 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
"INIT DROPDOWN
MODULE INIT_DROPDOWN OUTPUT.
CLEAR: G_LIST, G_LIST[].
G_VALUE-KEY = 'A'.
G_VALUE-TEXT = 'FIRST OPTION'.
APPEND G_VALUE TO G_LIST.
G_VALUE-KEY = 'B'.
G_VALUE-TEXT = 'SECOND OPTION'.
APPEND G_VALUE TO G_LIST.
G_VALUE-KEY = 'C'.
G_VALUE-TEXT = 'THIRD OPTION'.
APPEND G_VALUE TO G_LIST.
G_NAME = 'WA_ITAB-DROPDOWN'.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = G_NAME
values = G_LIST.
G_NAME = 'TEXT1'.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = G_NAME
values = G_LIST.
ENDMODULE. " INIT_DROPDOWN OUTPUT
====================================================
沒有留言:
張貼留言