ABAP CHECKBOX 和LISTBOX使用

*&---------------------------------------------------------------------*
*& Report  ZJC20051014_1
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZJC20051014_1.

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 .

你可能感兴趣的:(1.SAP)