ABAP 一个隐藏 selection-screen block的实例

以下是一个演示如何通过 selection-screen 中的pushbutton来动态改变屏幕上的字段的显示状态的(即显示或者隐藏)。
注意: 显示 通过本示例可知selection-screen 中的 field 的显示状态都是 的,在程序中修改其属性 active 的值为 '0' 时,该field就回隐藏起来。 但是在下一次屏幕显示前,其默认值又归为显示了。这时候可以在 at selection-screen output 事件或者 PBO中来修改active 值为 '0'即可。
另外,注意使用 modif id *** 来将selection screen 中的 field 指派到 screen-group1 中。 *** 是不超过三个字符的 id 名称,即指定了 screen-group1的值。


*&---------------------------------------------------------------------*
*& Report  ZSELECTION_SCREEN                                           *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  zselection_screen                                           .
INCLUDE <icon>.
TABLES: sscrfields,
        sflight.

SELECTION-SCREEN: PUSHBUTTON /1(40) pbo1      "open block 1
                  USER-COMMAND ucomm_o1 MODIF ID mo1,
                  PUSHBUTTON /1(20) pbc1      "close block 1
                  USER-COMMAND ucomm_c1 MODIF ID mc1.

SELECTION-SCREEN BEGIN OF BLOCK b01 WITH FRAME.
PARAMETERS: name LIKE zgwy_member-name MODIF ID mc1.
SELECT-OPTIONS: s_car FOR sflight-carrid MODIF ID mc1,
*                s_con FOR sflight-connid MODIF ID mc1,
*                s_fld FOR sflight-fldate MODIF ID mc1,
                s_pri FOR sflight-price MODIF ID mc1.

SELECTION-SCREEN END OF BLOCK b01.

SELECTION-SCREEN: PUSHBUTTON /1(40) pbo2      "open block 1
                  USER-COMMAND ucomm_o2 MODIF ID mo2,
                  PUSHBUTTON /1(20) pbc2      "close block 1
                  USER-COMMAND ucomm_c2 MODIF ID mc2.

SELECTION-SCREEN BEGIN OF BLOCK b02 WITH FRAME.
PARAMETERS: name2 LIKE zgwy_member-name MODIF ID mc2.
SELECT-OPTIONS: s_car2 FOR sflight-carrid MODIF ID mc2,
*                s_con2 FOR sflight-connid MODIF ID mc2,
*                s_fld2 FOR sflight-fldate MODIF ID mc2,
                s_pri2 FOR sflight-price MODIF ID mc2.

SELECTION-SCREEN END OF BLOCK b02.

PARAMETERS: par_cb1(1) TYPE c NO-DISPLAY,
            par_cb2(1) TYPE c NO-DISPLAY.


INITIALIZATION.

  CONCATENATE icon_expand: '打开' '' INTO pbo1,
               '打开' '' INTO pbo2.

  CONCATENATE icon_collapse: '关闭' '' INTO pbc1,
                '关闭' '' INTO pbc2.
  par_cb1 = 'X'.
  par_cb2 = 'X'.

AT SELECTION-SCREEN.
  CASE sscrfields-ucomm.
    WHEN 'UCOMM_O1'.
      CLEAR par_cb1.
    WHEN 'UCOMM_C1'.
      par_cb1 = 'X'.
    WHEN 'UCOMM_O2'.
      CLEAR par_cb2.
    WHEN 'UCOMM_C2'.
      par_cb2 = 'X'.
  ENDCASE.


AT SELECTION-SCREEN OUTPUT.
  LOOP AT SCREEN.
    PERFORM close_block USING:  par_cb1 'MO1' 'X',
                                par_cb1 'MC1' space,
                                par_cb2 'MO2' 'X',
                                par_cb2 'MC2' space.

  ENDLOOP.

*&--------------------------------------------------------------------*
*&      Form  close_block
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
*      -->VALUE(U_CLOtextLOCK)
*      -->U_MODIFY_IDtext
*      -->U_CONVERT  text
*---------------------------------------------------------------------*
FORM close_block USING value(u_close_block) LIKE par_cb1
                       u_modify_id LIKE screen-group1
                       u_convert.

  IF NOT u_convert IS INITIAL.
    IF u_close_block IS INITIAL.
      u_close_block = 'X'.
    ELSE.
      CLEAR u_close_block.
    ENDIF.
  ENDIF.

  IF ( screen-group1 = u_modify_id )
    AND ( NOT u_close_block IS INITIAL ).
    screen-active = '0'.
    MODIFY SCREEN.
  ENDIF.

ENDFORM.                    "close_block

你可能感兴趣的:(abap,block,screen,休闲,selection)