Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Expand/Collapse a block in a selection screen

Hey Folks,

I have a requirement , where I have a selection screen, with 3 selection blocks. I have a requirement that I need to make 2 of these blocks expandible/collapsible on the toggle of a button.. How can this be achieved.

In case of a normal screen, I would have had to create the blocks as subscreens (one type of screen for expanded state...another for collapsed state) and called it from the main screen. But how do I achieve the same using the selection screens?

I was considering creating the blocks as subscreens in the selection screen and calling them in the PBO of the main selection screen. However, I am unsure if thats a wise thing to do since the screen is generated automatically in case of a selection screen and I do believe its not a good idea to manually alter it.

Does anyone has any pointers on this?

Thanks and Best Regards,

Puja.

Former Member
Former Member replied

Hi,

I have modified the code to show the expand/collapse ICON accordingly..Please check..

TABLES sscrfields.
TYPE-POOLS icon.

* Expand/collapse buttons.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON 2(23)  b1 USER-COMMAND usr1.
SELECTION-SCREEN END OF LINE.

* Block 1
SELECTION-SCREEN BEGIN OF BLOCK b1.
PARAMETERS: p_test1 TYPE char10  MODIF ID m1,
            p_test2 TYPE char10  MODIF ID m1.
SELECT-OPTIONS  s_date  FOR sy-datum MODIF ID m1.
SELECTION-SCREEN END OF BLOCK b1.

* Block 2
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON 2(23)  b2 USER-COMMAND usr2.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF BLOCK b2.
PARAMETERS: p_test3 TYPE char10  MODIF ID m2,
            p_test4 TYPE char10  MODIF ID m2.
SELECTION-SCREEN END OF BLOCK b2.

* Declarations
DATA: v_flag, v_flag1.

INITIALIZATION.
  b1 = 'Button1'.
  b2 = 'Button2'.
  v_flag = 'X'.
  v_flag1 = 'X'.

AT SELECTION-SCREEN.

* Check the user command.
  IF sy-ucomm = 'USR1'.

    IF v_flag IS INITIAL.
      v_flag = 'X'.
    ELSE.
      CLEAR v_flag.
    ENDIF.

  ELSEIF sy-ucomm = 'USR2'.

    IF v_flag1 IS INITIAL.
      v_flag1 = 'X'.
    ELSE.
      CLEAR v_flag1.
    ENDIF.

  ENDIF.


AT SELECTION-SCREEN OUTPUT.

  IF v_flag1 = 'X'.
    CALL FUNCTION 'ICON_CREATE'
      EXPORTING
        name   = icon_expand
        text   = 'Button 2'
        info   = 'Button 2'
      IMPORTING
        RESULT = b2
      EXCEPTIONS
        OTHERS = 0.

  ELSEIF v_flag1 IS INITIAL.
    CALL FUNCTION 'ICON_CREATE'
      EXPORTING
        name   = icon_collapse
        text   = 'Button 2'
        info   = 'Button 2'
      IMPORTING
        RESULT = b2
      EXCEPTIONS
        OTHERS = 0.
  ENDIF.

  IF v_flag = 'X'.
    CALL FUNCTION 'ICON_CREATE'
      EXPORTING
        name   = icon_expand
        text   = 'Button 1'
        info   = 'Button 1'
      IMPORTING
        RESULT = b1
      EXCEPTIONS
        OTHERS = 0.

  ELSEIF v_flag IS INITIAL.
    CALL FUNCTION 'ICON_CREATE'
      EXPORTING
        name   = icon_collapse
        text   = 'Button 1'
        info   = 'Button 1'
      IMPORTING
        RESULT = b1
      EXCEPTIONS
        OTHERS = 0.
  ENDIF.

  LOOP AT SCREEN.

* Expand collapse block1
    IF v_flag = 'X' AND screen-group1 = 'M1'.
      screen-active = 0.
    ELSEIF v_flag IS INITIAL AND screen-group1 = 'M1'.
      screen-active = 1.
    ENDIF.

* Expand collapse block2
    IF v_flag1 = 'X' AND screen-group1 = 'M2'.
      screen-active = 0.
    ELSEIF v_flag1 IS INITIAL AND screen-group1 = 'M2'.
      screen-active = 1.
    ENDIF.

    MODIFY SCREEN.

  ENDLOOP.

Thanks

Naren

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question