[转]ABAP CHECKBOX 和LISTBOX使用指南
1.什么是checkbox:
就是一个复选框,可以用like或者type来定义,为1个字符型变量。它是parameter的一个选项,parameter xxx as checkbox就可以在选择屏幕上显示一个复选框。
2.什么是listbox:
就是一个下拉列表,你可以在这个列表中选择一条记录进行某种操作。也是parameter的一个选项,parameter xxx as listbox就可以在选择屏幕上显示一个下拉列表。
3.如何使用:
下面我们用一个程序来说明这两者的使用方法。
REPORT Z_TEXT
TYPE-POOLS: VRM . “存放combobox内容的type pool
DATA: NAME TYPE VRM_ID , “ list box的名称
LIST TYPE VRM_VALUES , “ list box的值
VALUE LIKE LINE OF LIST . “ list box的结构
*定义checkbox,指定command,为了能够响应选择屏幕中值的改变
PARAMETERS: P_CB1 TYPE C AS CHECKBOX DEFAULT 'X' USER-COMMAND CHECK,
P_CB2 TYPE C AS CHECKBOX DEFAULT 'X' USER-COMMAND CHECK.
*定义listbox,必须指定visible length
PARAMETERS: P_LIST1(10) TYPE C AS LISTBOX
VISIBLE LENGTH 15 ,
P_LIST2(20) TYPE C AS LISTBOX
VISIBLE LENGTH 25 .
*开始执行
AT SELECTION-SCREEN OUTPUT .
*--〉选择1而没有选择2
IF P_CB1 = 'X' AND P_CB2 = ''.
*---〉向listbox里面添加值
REFRESH LIST .
VALUE-KEY = '1111111111' . “这个就是变量P_LIST的值
VALUE-TEXT = '1111111111' . “这个是text
APPEND VALUE TO LIST .
VALUE-KEY = '2222222222' .
VALUE-TEXT = '2222222222' .
APPEND VALUE TO LIST .
VALUE-KEY = '3333333333' .
VALUE-TEXT = '3333333333' .
APPEND VALUE TO LIST .
*---〉调用函数显示listbox里面的值
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
ID = 'P_LIST1'
VALUES = LIST.
*---〉把第二个listbox的值清空,并且不能输入
CLEAR P_LIST2 .
LOOP AT SCREEN .
IF SCREEN-NAME = 'P_LIST2' .
SCREEN-INPUT = 0 .
MODIFY SCREEN .
ENDIF .
ENDLOOP .
*--〉选择2,没有选择1,同上
ELSEIF P_CB2 = 'X' AND P_CB1 = ''.
REFRESH LIST .
VALUE-KEY = 'AAAAAAAAAAAAAAAAAAAA' .
VALUE-TEXT = 'AAAAAAAAAAAAAAAAAAAA' .
APPEND VALUE TO LIST .
VALUE-KEY = 'BBBBBBBBBBBBBBBBBBBB' .
VALUE-TEXT = 'BBBBBBBBBBBBBBBBBBBB' .
APPEND VALUE TO LIST .
VALUE-KEY = 'CCCCCCCCCCCCCCCCCCCC' .
VALUE-TEXT = 'CCCCCCCCCCCCCCCCCCCC' .
APPEND VALUE TO LIST .
APPEND VALUE TO LIST .
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
ID = 'P_LIST2'
VALUES = LIST.
*---〉清空listbox 1的值
CLEAR P_LIST1 .
LOOP AT SCREEN .
IF SCREEN-NAME = 'P_LIST1' .
SCREEN-INPUT = 0 .
MODIFY SCREEN .
ENDIF .
ENDLOOP .
*--〉都没有选择,都清空且不能输入
ELSEIF P_CB1 = '' AND P_CB2 = '' .
CLEAR: P_LIST1,P_LIST2 .
LOOP AT SCREEN .
IF SCREEN-NAME = 'P_LIST1' .
SCREEN-INPUT = 0 .
MODIFY SCREEN .
ENDIF .
ENDLOOP .
LOOP AT SCREEN .
IF SCREEN-NAME = 'P_LIST2' .
SCREEN-INPUT = 0 .
MODIFY SCREEN .
ENDIF .
ENDLOOP .
*--〉都选,执行
ELSEIF P_CB1 = 'X' AND P_CB2 = 'X' .
REFRESH LIST .
VALUE-KEY = '1111111111' .
VALUE-TEXT = '1111111111' .
APPEND VALUE TO LIST .
VALUE-KEY = '2222222222' .
VALUE-TEXT = '2222222222' .
APPEND VALUE TO LIST .
VALUE-KEY = '3333333333' .
VALUE-TEXT = '3333333333' .
APPEND VALUE TO LIST .
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
ID = 'P_LIST1'
VALUES = LIST.
REFRESH LIST .
VALUE-KEY = 'AAAAAAAAAAAAAAAAAAAA' .
VALUE-TEXT = 'AAAAAAAAAAAAAAAAAAAA' .
APPEND VALUE TO LIST .
VALUE-KEY = 'BBBBBBBBBBBBBBBBBBBB' .
VALUE-TEXT = 'BBBBBBBBBBBBBBBBBBBB' .
APPEND VALUE TO LIST .
VALUE-KEY = 'CCCCCCCCCCCCCCCCCCCC' .
VALUE-TEXT = 'CCCCCCCCCCCCCCCCCCCC' .
APPEND VALUE TO LIST .
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
ID = 'P_LIST2'
VALUES = LIST.
ENDIF .
START-OF-SELECTION .
*--〉输出到第二屏幕看看
WRITE: P_LIST1 ,/ P_LIST2 .