ABAP中如何使用listbox

*******************************************
**原创文章,版权所有,转载请保留信息
**msn:njchouer@hotmail.com
**作者:chouer
*******************************************

*&---------------------------------------------------------------------*
*& Report Ztest
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT Ztest.

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 .

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/332542/viewspace-53546/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/332542/viewspace-53546/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值