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: 

Display any container

Former Member
0 Kudos

Hi all,

I have a simple question :

is it possible to display any container on a screen ? I mean that I want to create a container and fill it, and then display it.

For exemple, I would like to create a Function module that takes a container and display a screen with it.

Does anyone know if it is possible ?

Olivier

5 REPLIES 5

Former Member
0 Kudos

Hi,

Yes it is possible. You can create screen with container and can call it from Function module.

Regards,

Satish

0 Kudos

Actually, what I want to do is

1) fill a container

2 call the function module in which I split the main container cl_gui_container=>screen0, and display the container I created before in the container I got from the split.

I don't see how I could assign the container from 1) to the container I created in the function module.

Could you help me to do this ?

Thanks

Olivier

0 Kudos

Hello Olivier

A container is not filled but just created and used as parent (container) for other controls (or containers).

Example: the docking container is the parent of the splitter container (see sample report).

The splitting occurs first and afterwards the returned cell container can be used as parents e.g. for ALV grid controls.

The other way around is not possible (as far as I know) that you create e.g. four grid controls first and then try to fill them into a 2x2 splitter container. Of course it is possible to display the four grid controls in four subscreens that are assembled into one main dynpro.

The sample report ZUS_SDN_TWO_ALV_GRIDS_B partially used FORM routines to create containers and grid controls. Simply think of these routines as function modules in your context. Perhaps the report gives you some ideas how to proceed.

*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_TWO_ALV_GRIDS_B
*&
*&---------------------------------------------------------------------*
*& Screen '0100' contains no elements.
*& ok_code -> assigned to GD_OKCODE
*&
*& Flow logic:
*  PROCESS BEFORE OUTPUT.
*    MODULE STATUS_0100.
**
*  PROCESS AFTER INPUT.
*    MODULE USER_COMMAND_0100.
*&
*& Description: special FORM routines for CONTAINER handling
*&---------------------------------------------------------------------*

REPORT  zus_sdn_two_alv_grids_b.

" Dynamic fieldcatalog on second ALV list




DATA:
  gd_okcode        TYPE ui_func,
  gd_repid         type syrepid,
*
  go_docking       TYPE REF TO cl_gui_docking_container,
  go_splitter      TYPE REF TO cl_gui_splitter_container,
  go_cell_top      TYPE REF TO cl_gui_container,
  go_cell_bottom   TYPE REF TO cl_gui_container,
  go_grid1         TYPE REF TO cl_gui_alv_grid,
  go_grid2         TYPE REF TO cl_gui_alv_grid,
  gs_layout        TYPE lvc_s_layo.


DATA:
  gt_knb1          TYPE STANDARD TABLE OF knb1,
  gt_knvv          TYPE STANDARD TABLE OF knvv.





*---------------------------------------------------------------------*
*       CLASS lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler DEFINITION.

  PUBLIC SECTION.
    CLASS-DATA:
      md_row              TYPE i.

    CLASS-METHODS:
      handle_double_click FOR EVENT double_click OF cl_gui_alv_grid
        IMPORTING
          e_row
          e_column
          es_row_no
          sender.


ENDCLASS.                    "lcl_eventhandler DEFINITION



*---------------------------------------------------------------------*
*       CLASS lcl_eventhandler IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler IMPLEMENTATION.

  METHOD handle_double_click.
*   define local data
    DATA:
      ls_knb1      TYPE knb1.

    CHECK ( sender = go_grid1 ).


    READ TABLE gt_knb1 INTO ls_knb1 INDEX e_row-index.
    CHECK ( ls_knb1-kunnr IS NOT INITIAL ).

    md_row = e_row-index.

    CALL METHOD go_grid1->set_current_cell_via_id
      EXPORTING
*        IS_ROW_ID    =
*        IS_COLUMN_ID =
        is_row_no    = es_row_no.


*   Triggers PAI of the dynpro with the specified ok-code
    CALL METHOD cl_gui_cfw=>set_new_ok_code( 'DETAIL' ).



  ENDMETHOD.                    "handle_double_click

ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION






START-OF-SELECTION.

  SELECT        * FROM  knb1 INTO TABLE gt_knb1
         WHERE  bukrs  = '1000'.


* Create docking container
  CREATE OBJECT go_docking
    EXPORTING
      parent                      = cl_gui_container=>screen0
      ratio                       = 90
    EXCEPTIONS
      OTHERS                      = 6.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


* Create splitter container
  CREATE OBJECT go_splitter
    EXPORTING
      parent            = go_docking
      rows              = 2
      columns           = 1
*      NO_AUTODEF_PROGID_DYNNR =
*      NAME              =
    EXCEPTIONS
      cntl_error        = 1
      cntl_system_error = 2
      OTHERS            = 3.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

* Get cell container
  PERFORM get_cell_container
                         USING
                            go_splitter
                      CHANGING
                            go_cell_top
                            go_cell_bottom.



* Create ALV grids
  PERFORM create_alv_grid
                       USING
                          go_cell_top
                    CHANGING
                          go_grid1.




* Set event handler
  SET HANDLER: lcl_eventhandler=>handle_double_click FOR go_grid1.


  PERFORM create_alv_grid
                       USING
                          go_cell_bottom
                    CHANGING
                          go_grid2.


* Display data
  gs_layout-grid_title = 'Customers'.
  CALL METHOD go_grid1->set_table_for_first_display
    EXPORTING
      i_structure_name = 'KNB1'
      is_layout        = gs_layout
    CHANGING
      it_outtab        = gt_knb1
    EXCEPTIONS
      OTHERS           = 4.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  gs_layout-grid_title = 'Customers Details (Sales Areas)'.
  CALL METHOD go_grid2->set_table_for_first_display
    EXPORTING
      i_structure_name = 'KNVV'
      is_layout        = gs_layout
    CHANGING
      it_outtab        = gt_knvv  " empty !!!
    EXCEPTIONS
      OTHERS           = 4.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


* Link the docking container to the target dynpro
  gd_repid = syst-repid.
  CALL METHOD go_docking->link
    EXPORTING
      repid                       = gd_repid
      dynnr                       = '0100'
*      CONTAINER                   =
    EXCEPTIONS
      OTHERS                      = 4.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


* NOTE: dynpro does not contain any elements
  CALL SCREEN '0100'.
* Flow logic of dynpro (does not contain any dynpro elements):
*
*PROCESS BEFORE OUTPUT.
*  MODULE STATUS_0100.
**
*PROCESS AFTER INPUT.
*  MODULE USER_COMMAND_0100.



END-OF-SELECTION.

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'STATUS_0100'.  " contains push button "DETAIL"
*  SET TITLEBAR 'xxx'.


* Refresh display of detail ALV list
  CALL METHOD go_grid2->refresh_table_display
*    EXPORTING
*      IS_STABLE      =
*      I_SOFT_REFRESH =
    EXCEPTIONS
      OTHERS         = 2.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


ENDMODULE.                 " STATUS_0100  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.

  CASE gd_okcode.
    WHEN 'BACK' OR
         'END'  OR
         'CANC'.
      SET SCREEN 0. LEAVE SCREEN.

*   User has pushed button "Display Details"
    WHEN 'DETAIL'.
      PERFORM entry_show_details.

    WHEN OTHERS.
  ENDCASE.

  CLEAR: gd_okcode.

ENDMODULE.                 " USER_COMMAND_0100  INPUT

*&---------------------------------------------------------------------*
*&      Form  ENTRY_SHOW_DETAILS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM entry_show_details .
* define local data
  DATA:
    ld_row      TYPE i,
    ls_knb1     TYPE knb1,
*
    ls_fcat     TYPE lvc_s_fcat,
    lt_fcat     TYPE lvc_t_fcat.



  CALL METHOD go_grid1->get_current_cell
    IMPORTING
      e_row = ld_row.

  READ TABLE gt_knb1 INTO ls_knb1 INDEX ld_row.
  CHECK ( syst-subrc = 0 ).

  SELECT        * FROM  knvv INTO TABLE gt_knvv
         WHERE  kunnr  = ls_knb1-kunnr.



  CALL METHOD go_grid2->get_frontend_fieldcatalog
    IMPORTING
      et_fieldcatalog = lt_fcat.


  " Logic of fieldcatalog modification:
  " 1st customer selected -> show 1 column only
  " 2nd customer selected -> show 2 columns only
  " 3rd customer selected -> show 3 columns
  " ...
  LOOP AT lt_fcat INTO ls_fcat.
    IF ( syst-tabix <= ld_row ).
      ls_fcat-no_out = ' '.
    ELSE.
      ls_fcat-no_out = 'X'.
    ENDIF.

    MODIFY lt_fcat FROM ls_fcat.
  ENDLOOP.

  go_grid2->set_frontend_fieldcatalog( lt_fcat ).




ENDFORM.                    " ENTRY_SHOW_DETAILS
*&---------------------------------------------------------------------*
*&      Form  GET_CELL_CONTAINER
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_GO_SPLITTER  text
*      <--P_GO_CELL_TOP  text
*      <--P_GO_CELL_BOTTOM  text
*----------------------------------------------------------------------*
FORM get_cell_container
                  USING
                     uo_splitter TYPE REF TO cl_gui_splitter_container
               CHANGING
                     co_cell_top     TYPE REF TO cl_gui_container
                     co_cell_bottom  TYPE REF TO cl_gui_container.

  CALL METHOD uo_splitter->get_container
    EXPORTING
      row       = 1
      column    = 1
    RECEIVING
      container = co_cell_top.

  CALL METHOD uo_splitter->get_container
    EXPORTING
      row       = 2
      column    = 1
    RECEIVING
      container = co_cell_bottom.

ENDFORM.                    " GET_CELL_CONTAINER

*&---------------------------------------------------------------------*
*&      Form  CREATE_ALV_GRID
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_GO_CELL_TOP  text
*      <--P_GO_GRID1  text
*----------------------------------------------------------------------*
FORM create_alv_grid  USING    uo_cell    TYPE REF TO cl_gui_container
                      CHANGING co_grid    TYPE REF TO cl_gui_alv_grid.

  CREATE OBJECT co_grid
    EXPORTING
      i_parent          = uo_cell
    EXCEPTIONS
      OTHERS            = 5.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

ENDFORM.                    " CREATE_ALV_GRID

Regards

Uwe

0 Kudos

A simple code to work with using containers and to display alv list on the container.

REPORT ZALV .


data: okcode like sy-ucomm,
      t_mara type standard table of mara,
      custom1 type ref to cl_gui_custom_container,
      grid1 type ref to cl_gui_alv_grid.




start-of-selection.
set screen '0100'.


*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.

case okcode.

when 'EXIT'.
set screen '0'.
endcase.

ENDMODULE.                 " USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*

MODULE STATUS_0100 OUTPUT.

CREATE OBJECT CUSTOM1
  EXPORTING
    CONTAINER_NAME              = 'MYCUSTOM'.

CREATE OBJECT GRID1
  EXPORTING

    I_PARENT          = custom1.


perform loaddata.
ENDMODULE.                 " STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Form  loaddata
*&---------------------------------------------------------------------*

FORM loaddata.


select * from mara into table t_mara.

CALL METHOD GRID1->SET_TABLE_FOR_FIRST_DISPLAY
 EXPORTING

   I_STRUCTURE_NAME              = 'mara'

  CHANGING
    IT_OUTTAB                     = t_mara

        .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

ENDFORM.                    " loaddata

0 Kudos

HI,

I finally found how to do what I want. So here is the code:

Screen 100 is empty. I can call this Function Module with any instance of class cl_gui_control (so I can call it with a CL_GUI_ALV_GRID or CL_GUI_TOOLBAR)



FUNCTION z_testohue_four4_ord.
*"----------------------------------------------------------------------
*"*"Interface locale :
*"  IMPORTING
*"     REFERENCE(I_PROG) TYPE  CHAR08
*"     REFERENCE(I_FOUR) TYPE  CHAR4
*"     REFERENCE(I_CYCLE) TYPE  CHAR08
*"     REFERENCE(I_CONTROL) TYPE REF TO  CL_GUI_CONTROL
*"----------------------------------------------------------------------
  MOVE i_prog TO w_prog.
  MOVE i_four TO w_four.
  MOVE i_cycle TO w_cycle.
  DATA : w_nb TYPE i.

********* Entête *********************
* On doit créer un object de type document pour l'affichage
* du prog, four et cycle
  CREATE OBJECT l_document
    EXPORTING
      background_color = '36'.

* Création d'un formulaire
  CALL METHOD l_document->add_form
    IMPORTING
      formarea         = l_form.

* On affiche le programme
  CALL METHOD l_form->add_text EXPORTING text = text-t01.
  CALL METHOD l_form->add_gap EXPORTING width = 3.
  CALL METHOD l_form->add_input_element
    EXPORTING
      value         = w_prog
      name          = 'PROG'
      size          = 10
      maxlength     = 10
    IMPORTING
      input_element = l_input_prog.

* On affiche le four
  CALL METHOD l_form->add_gap EXPORTING width = 20.
  CALL METHOD l_form->add_text EXPORTING text = text-t02.
  CALL METHOD l_form->add_gap EXPORTING width = 3.
  CALL METHOD l_form->add_input_element
    EXPORTING
      value         = w_four
      name          = 'FOUR'
      size          = 2
      maxlength     = 3
    IMPORTING
      input_element = l_input_four.

* On affiche le cycle
  CALL METHOD l_form->add_gap EXPORTING width = 20.
  CALL METHOD l_form->add_text EXPORTING text = text-t03.
  CALL METHOD l_form->add_gap EXPORTING width = 3.
  CALL METHOD l_form->add_input_element
    EXPORTING
      value         = w_cycle
      name          = 'CYCLE'
      size          = 5
      maxlength     = 7
    IMPORTING
      input_element = l_input_cycle.

* On joint les deux bouts ...
  CALL METHOD l_document->merge_document.

********* ALV *********************
  CLEAR wt_sflight.
  SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE wt_sflight.


* On sépare l'écran en 3 parties
  CREATE OBJECT l_splitter
    EXPORTING
      link_dynnr              = '100'
      link_repid              = 'SAPLZZOHUEFOUR'
      parent            = cl_gui_container=>screen0
      no_autodef_progid_dynnr = 'X'
      rows              = '3'
      columns           = '1'.

* Le top ne doit faire que 10
  CALL METHOD l_splitter->set_row_height
    EXPORTING
      id           = '1'
      height       = '10'.


* Récupération des containers :
  CALL METHOD l_splitter->get_container
    EXPORTING
      row       = '1'
      column    = '1'
    RECEIVING
      container = l_container_top.
  CALL METHOD l_splitter->get_container
    EXPORTING
      row       = '2'
      column    = '1'
    RECEIVING
      container = l_container_mid.
  CALL METHOD l_splitter->get_container
    EXPORTING
      row       = '3'
      column    = '1'
    RECEIVING
      container = l_container_bot.

* On affiche le top en haut
* Affichage Document dans Container
  CALL METHOD l_document->display_document
    EXPORTING
      parent             = l_container_top.

* Affichage de l'ALV dans celui du bas:
  CREATE OBJECT l_alv EXPORTING i_parent = l_container_bot.
  CALL METHOD l_alv->set_table_for_first_display
    EXPORTING
      i_structure_name              = 'SFLIGHT'
    CHANGING
      it_outtab                     = wt_sflight.


  IF NOT i_control IS INITIAL.
    CALL METHOD l_splitter->add_control
      EXPORTING
        row               = '2'
        column            = '1'
        control           = i_control
    IMPORTING
        result = w_nb.

  ENDIF.


  CALL SCREEN 100.

In the calling program, I create the CL_GUI_CONTROL with parent = CL_GUI_CONTAINER=>screen2. For example :


START-OF-SELECTION.
    CLEAR wt_sflight.

    SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE wt_sflight
    .

    CREATE OBJECT l_alv
      EXPORTING
        i_parent          = cl_gui_container=>screen2.

    CREATE OBJECT l_event.
    SET HANDLER l_event->handle_toolbar FOR l_alv.
    SET HANDLER l_event->handle_user_command FOR l_alv.

    CALL METHOD l_alv->set_table_for_first_display
      EXPORTING
        i_structure_name              = 'SFLIGHT'
      CHANGING
        it_outtab                     = wt_sflight.

  CALL FUNCTION 'Z_TESTOHUE_FOUR4_ORD'
       EXPORTING
            i_prog    = 'Test1'
            i_four    = 'Test'
            i_cycle   = 'Test3'
            i_control = l_alv.

Thanks for your help !

Olivier