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: 

Changing width of a custom container dynamically

Former Member
0 Kudos

Hi,

I have an ABAP report that has 2 custom containers on a screen: CC1 on the left, showing a tree and another one (CC2) consuming the rest of the screen. Depending on what node the user selects in the tree (left CC), I would like to dynamically adjust the width of CC1 and CC2.

Is there a way to do it? I found the method SET_WIDTH of CL_GUI_CUSTOM_CONTAINER (which CC1 and CC2 are instances of), but it does not seem to work.

Any help is appreciated.

Guenther

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Here is a coding example that demonstrates dynamically changing the width of the container.

What you cannot see is the screen definition. Screen 100 has a single custom container that fills the entire screen and is set to be resizable. The container name is 'MY_CONTAINER'. Next screen is set to 0.

Flow logic of screen:

PROCESS BEFORE OUTPUT.

  MODULE pbo.

PROCESS AFTER INPUT.

Cut and paste this program and define the screen. Run the program and keep hitting ENTER to see the size change from left to right. After 9 times, the program will end.

REPORT  zcdf_docking_example.

DATA:
  w_sash           TYPE sy-index,
  r_cstm_ctnr      TYPE REF TO cl_gui_custom_container,
  r_easy_splt_ctnr TYPE REF TO cl_gui_easy_splitter_container.

CLASS cl_gui_easy_splitter_container DEFINITION LOAD.

DO 9 TIMES.

  w_sash = sy-index * 10.

  CALL SCREEN 100.

ENDDO.

MODULE pbo OUTPUT.

  IF r_cstm_ctnr IS INITIAL.

    CREATE OBJECT r_cstm_ctnr
         EXPORTING container_name = 'MY_CONTAINER'.

    CREATE OBJECT r_easy_splt_ctnr
           EXPORTING
             parent = r_cstm_ctnr
             orientation =
               cl_gui_easy_splitter_container=>orientation_horizontal.

*   Set starting sash position.  Position is a percentage.

    CALL METHOD r_easy_splt_ctnr->set_sash_position
           EXPORTING
             sash_position = w_sash.

*   Put ALV in left container.

*    CREATE OBJECT r_alv_grid1
*           EXPORTING
*             i_parent = r_easy_splt_ctnr->top_left_container.

*   Put ALV in right container.

*    CREATE OBJECT r_alv_grid2
*           EXPORTING
*             i_parent = r_easy_splt_ctnr->bottom_right_container.

  ELSE.

    CALL METHOD r_easy_splt_ctnr->set_sash_position
           EXPORTING
             sash_position = w_sash.

  ENDIF.

ENDMODULE.                 " pbo  OUTPUT

Let us know how it goes.

7 REPLIES 7

Former Member
0 Kudos

Hi Guenther,

Did you call the following after the change:

CALL METHOD CL_GUI_CFW=>FLUSH

EXCEPTIONS

CNTL_SYSTEM_ERROR = 1

CNTL_ERROR = 2.

Or possibly Did you call the function module 'CONTROL_FLUSH' after the change?

Regards,

Rob.

Former Member
0 Kudos

Hi Guenther,

One of the options that you must consider is the docking container, which would also allow the user the flexibility to resize the screen as he likes. And I think it makes for better UI design and is also easy to program.

Regards,

Anand Mandalika.

0 Kudos

Hi Guenther

Docking container is OK and may be more feasible for some cases, however I would prefer the <b>splitter container</b> if it suits to your needs. You can inspect relevant classes and demo programs by searching with "SPLITTER" mask.

Easy splitter (<b>CL_GUI_EASY_SPLITTER_CONTAINER</b>) is a lite version, but if you need more features than it offers you can use the classical one (<b>CL_GUI_SPLITTER_CONTAINER</b>).

Hope you find this helpful...

*--Serdar

Former Member
0 Kudos

Here is a coding example that demonstrates dynamically changing the width of the container.

What you cannot see is the screen definition. Screen 100 has a single custom container that fills the entire screen and is set to be resizable. The container name is 'MY_CONTAINER'. Next screen is set to 0.

Flow logic of screen:

PROCESS BEFORE OUTPUT.

  MODULE pbo.

PROCESS AFTER INPUT.

Cut and paste this program and define the screen. Run the program and keep hitting ENTER to see the size change from left to right. After 9 times, the program will end.

REPORT  zcdf_docking_example.

DATA:
  w_sash           TYPE sy-index,
  r_cstm_ctnr      TYPE REF TO cl_gui_custom_container,
  r_easy_splt_ctnr TYPE REF TO cl_gui_easy_splitter_container.

CLASS cl_gui_easy_splitter_container DEFINITION LOAD.

DO 9 TIMES.

  w_sash = sy-index * 10.

  CALL SCREEN 100.

ENDDO.

MODULE pbo OUTPUT.

  IF r_cstm_ctnr IS INITIAL.

    CREATE OBJECT r_cstm_ctnr
         EXPORTING container_name = 'MY_CONTAINER'.

    CREATE OBJECT r_easy_splt_ctnr
           EXPORTING
             parent = r_cstm_ctnr
             orientation =
               cl_gui_easy_splitter_container=>orientation_horizontal.

*   Set starting sash position.  Position is a percentage.

    CALL METHOD r_easy_splt_ctnr->set_sash_position
           EXPORTING
             sash_position = w_sash.

*   Put ALV in left container.

*    CREATE OBJECT r_alv_grid1
*           EXPORTING
*             i_parent = r_easy_splt_ctnr->top_left_container.

*   Put ALV in right container.

*    CREATE OBJECT r_alv_grid2
*           EXPORTING
*             i_parent = r_easy_splt_ctnr->bottom_right_container.

  ELSE.

    CALL METHOD r_easy_splt_ctnr->set_sash_position
           EXPORTING
             sash_position = w_sash.

  ENDIF.

ENDMODULE.                 " pbo  OUTPUT

Let us know how it goes.

0 Kudos

Hi Charles

Thanks for the demonstration for easy splitter container which I intended to write here but you have already done...

*--Serdar

0 Kudos

Fantastic piece of code, Charles. Thanks for sharing with us.

Regards,

Subramanian V.

Former Member
0 Kudos

All,

First of all, I would like to thank everybody for their help!

I finally ended up using the splitter container approach - initially I tried to avoid it because I had to change the layout of multiple screens. It looks like this is the (only?) best way to go and since I had to touch all these modules anyway, I put in some additional changes and cosmetics.

One of these moments where one single change request triggers quite a bit of reengineering...

Again, thanks everybody!

Guenther