Skip to Content
Author's profile photo Anurag Sinha

Creating EXPAND AND COLLAPSE BUTTON IN SELECTION SCREEN.

In i shall show how to create a expand and collapse button in a selection screen with two blocks.

firstly we  need to go to the table ICON and see what icon is required. We can find the icon text in this table. Which is needed to be written in the code. The main objective is to create this

EXPAND.png

/wp-content/uploads/2013/09/collapse_285850.png

To achieve this we have to create global or local variable

gc_collp    TYPE char4     VALUE ‘@3T@’,

gc_exp      TYPE char4     VALUE ‘@3S@’.

This are the Icon in text fields which can be found in the table ICON.

NOW at the INITIALIZATION EVENT we have to write the code:

MOVE  gc_collp  TO sscrfieldsfunctxt_02.

   LOOP AT SCREEN.

     IF screengroup1 = gc_a.

       screenactive = 1.

       MODIFY SCREEN.

     ENDIF.

   ENDLOOP.



AT SELECTION SCREEN EVENT

we have to write  the code:

IF syucomm gc_fc02.

     IF sscrfieldsfunctxt_02 = icon_collapse.

       gv_var = gc_exp.

       MOVE gc_exp TO sscrfieldsfunctxt_02.

     ELSEIF sscrfieldsfunctxt_02 = icon_expand.

       gv_var = gc_collp.

       MOVE gc_collp TO sscrfieldsfunctxt_02.

     ENDIF.

   ENDIF.


*(gc_fc02 is function code FC02 Text for pushbuttons which is generated when we press the collapse button u can hard code is as well)

and in the end we need to write in the event at selection screen output:

IF gv_var = gc_exp.

     LOOP AT SCREEN.

       IF screengroup1 = gc_a.

         screenactive = 0.

         MODIFY SCREEN.

       ENDIF.

     ENDLOOP.

   ELSEIF gv_var = gc_collp.

     LOOP AT SCREEN.

       IF screengroup1 = gc_a.

         screenactive = 1.

         MODIFY SCREEN.

       ENDIF.

     ENDLOOP.

   ENDIF.

*(gv_var is the variable in which the icon texts are stored).

Hope this will help for future purposes..

Thanks and Regards

Anurag Sinha.




Assigned Tags

      8 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Raymond Giuseppi
      Raymond Giuseppi

      You could just create a program variant, mark fields hidden in collapsed status as hidden in this variant, use it in the transaction definition. Then SAP will manage itself the expand/collapse buttons.

      Regards,

      Raymond

      Author's profile photo Anurag Sinha
      Anurag Sinha
      Blog Post Author

      Hi raymond,

                       It will be a help if you can explain a bit more,

      Thanks And reagards ,

      Anurag Sinha

      Author's profile photo Raymond Giuseppi
      Raymond Giuseppi
      • Remove the coding in the PBO (AT SELECTION-SCREEN OUTPUT)
      • Create a variant for the report, in the save screen, check the "hide field" for the fields of the block you want to hide with collapse

      • Execute the report with this variant

      -

      Just use this variant in the transaction definition (I would suggest to crate a CUS&nnn variant so will always been transported, and user wont be allowed to change it)

      Regards,

      Raymond

      Author's profile photo Anurag Sinha
      Anurag Sinha
      Blog Post Author

      Hi Raymond,

                          It really cool but my requirement was that icon collapse needed to be shown at first. So is there any way to do that without so much coding? And more over it is need to be shown all the time whenever the t-code is called.

      Author's profile photo Former Member
      Former Member

      Hi

      In generally I prefer to adds the expand and collapse buttons into the selection-screen, not in the bar, just before the section to be shown/Hidden:

      SELECTION-SCREEN PUSHBUTTON 1(10EXP1 USER-COMMAND EXP1 MODIF ID EX1.

      SELECTION-SCREEN SKIP.

      SELECTION-SCREEN PUSHBUTTON 1(10COL1 USER-COMMAND COL1 MODIF ID BL1.

      SELECTION-SCREEN BEGIN OF BLOCK BL1 WITH FRAME.

      PARAMETERS: P_BUKRS LIKE T001-BUKRS  MODIF ID BL1,

                   P_WERKS LIKE T001W-WERKS MODIF ID BL1.

      SELECTION-SCREEN END   OF BLOCK BL1.

      SELECTION-SCREEN PUSHBUTTON 1(10EXP2 USER-COMMAND EXP2 MODIF ID EX2.

      SELECTION-SCREEN SKIP.

      SELECTION-SCREEN PUSHBUTTON 1(10COL2 USER-COMMAND COL2 MODIF ID BL2.

      SELECTION-SCREEN BEGIN OF BLOCK BL2 WITH FRAME.

      PARAMETERS: P_BELNR LIKE BKPF-BELNR MODIF ID BL2,

                   P_GJAHR LIKE BKPF-GJAHR MODIF ID BL2.

      SELECTION-SCREEN END   OF BLOCK BL2.

      DATA: L_BL1 TYPE FLAG.

      DATA: L_BL2 TYPE FLAG.

      INITIALIZATION.

         EXP1 EXP2 = '@3S@'.

         COL1 COL2 = '@3T@'.

         L_BL1 = 'E'.

         L_BL2 = 'E'.

      AT SELECTION-SCREEN OUTPUT.

         IF L_BL1 = 'E'.

           LOOP AT SCREEN.

             IF SCREEN-GROUP1 = 'EX1'.

               SCREEN-ACTIVE = 0.

               MODIFY SCREEN.

             ENDIF.

           ENDLOOP.

         ELSE.

           LOOP AT SCREEN.

             IF SCREEN-GROUP1 = 'BL1'.

               SCREEN-ACTIVE = 0.

               MODIFY SCREEN.

             ENDIF.

           ENDLOOP.

         ENDIF.

         IF L_BL2 = 'E'.

           LOOP AT SCREEN.

             IF SCREEN-GROUP1 = 'EX2'.

               SCREEN-ACTIVE = 0.

               MODIFY SCREEN.

             ENDIF.

           ENDLOOP.

         ELSE.

           LOOP AT SCREEN.

             IF SCREEN-GROUP1 = 'BL2'.

               SCREEN-ACTIVE = 0.

               MODIFY SCREEN.

             ENDIF.

           ENDLOOP.

         ENDIF.

      AT SELECTION-SCREEN.

         CASE SY-UCOMM.

           WHEN 'EXP1'. L_BL1 = 'E'.

           WHEN 'COL1'. L_BL1 = 'C'.

           WHEN 'EXP2'. L_BL2 = 'E'.

           WHEN 'COL2'. L_BL2 = 'C'.

         ENDCASE.

      Max

      Author's profile photo Anurag Sinha
      Anurag Sinha
      Blog Post Author

      Hi max my requirement was to create the button on the bar only 😎 .

      Thanks And regards,

      Anurag Sinha

      Author's profile photo Former Member
      Former Member

      Nice....

      Author's profile photo ASHIS LOHIA
      ASHIS LOHIA

      Nice.