Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Expand/Collapse a block in a selection screen

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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

5 REPLIES 5

Former Member
0 Kudos

You should be able to do this pretty easily using LOOP AT SCREEN.

Rob

Former Member
0 Kudos

Hi,

Check this example...

* Expand/collapse buttons.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON 2(10)  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(10)  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'.

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.

  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 Kudos

@Naren,

Thanks for the response. I am pretty new to Screen Programming. So this was rather very helpful.

What I actually needed was a toggle button, ie a single button would do the necessary task of toggling between the two blocks.

Besides making the blocks active/inactive, the button should be able to toggle its own name and icon.

I believe this should also be possible by maintaining a global flag since we cant make use of the user command then to detect the state of the button when the event is fired. And then the flag could be checked while looping at the screen elements to change the name and icon of the button accordingly.

I am just speculating this could be a solution, but I am unsure how to proceed.

Any pointers would be helpful.

Thanks and Best Regards,

Puja.

0 Kudos

Thanks a lot Naren...this solved my problem.

Former Member
0 Kudos

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