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: 

Creating the containers Dynamically for ALV grid?

Former Member
0 Kudos

Hi Guys,

Can anybody tell me How to create the containers Dynamically?

My req is i have to Multiple ALV grids based on Plant. so how to create dynamically containers and ALV grids based on Plant.

If there is any change in the Plant then i have to create new Container and New grid .Can anybody tell me whether its possible or not.If so how? or if not what to do?

Thanks,

Gopi.

9 REPLIES 9

former_member583013
Active Contributor
0 Kudos

Maybe this could help you out -:)

<a href="/people/alvaro.tejadagalindo/blog/2006/11/27/dynamic-alv-list-display ALV List Display</a>

Greetings,

Blag.

Former Member
0 Kudos

Hi,

I havent understood why u need to create multiple ALV grids based on plant. What is the selection screen parameter in this scenario. Y u need to create a new container , why dont u try to create the dynamic alv based on the data from the plant?

Give the exact scenario and what exactly you want to do?

Regards

Kannaiah

0 Kudos

Hi Kannaiah,

My functional guy told me to create a new grid for each plant means i got the data in my final internal table but i have to display header infromation with Plant and Item details in the grid.Like that whenever plant changes i have to create new grid and new header for each plant.

Coming to the other Q'n?why we need to create new container?

becoz i have to display in a single screen all the grids based on diff plant.we don't know how many plants we can get?so, we have to create the grids and container dynamically.

Selection screen parameter's are Plant , Material Number ,Fiscal Year , Period and Quanity str type.

.i was not able to get ur last Qn" Why dont u try to create Dynamic ALV based on the data vrom the Plant?"

My doubt is how to create Dynamic ALV's(in my final internal table i am having plant material number , vendor, mixing ratio ........)and other Qnis is it possible to create dynamic ALV's without Containers i mean Custom Control.

Thanks,

Gopi.

0 Kudos

Hi,

As per my understanding,

whenever a multiple plants are given in the selection screen, u need to display the data corresponding to each plant in mutliple grids or

whenever materials are given in selection screen, u need to display the materials corresponding to the plant in each grid.

rsdemo_splitter_control , rsdemo_easy_splitter_control , check these two demo pgrms, these might help you. Let me know if my understanding is not correct.

Coming to Dynamic ALV, we need to create a custom container once only, but the field catalog changes depending upon the data in the final internal table.

Regards

Kannaiah

0 Kudos

Hi Kannaiah,

Nope,we have to fill the selection screen variables and we have to display based on Plants only no materials Display.

Regarding last point which u told i am having a doubt.Can we display multiple ALV GRIDs in a single container that to dynamic ALV grids with header for each ALV grid ?if so how if possible example.

Thanks,

Gopi.

0 Kudos

Hi,

first to say i havent understood ur requirement.

U said: My functional guy told me to create a new grid for each plant means i got the <b>data in my final internal table</b> but i have to <b>display header infromation with Plant and Item details in the grid</b>.

What is the data that is in final internal table.

What data is displayed in header and items.

Selection screen parameter's are <b>Plant , Material Number ,Fiscal Year , Period and Quanity str type.</b> what is the need of material number is selections screen and what is this Fiscal year , y u r using here?

Are all these are selectoptions r parameters ? u said u r passing variables. what are the variables here u r using?

Regarding Dynamic ALV, refer to the thread below:

Come up with a clear requirement:

what is the selection screen

data to be fetched frm tables

final table comprises of

what should be displayed and how

Regards

Kannaiah

0 Kudos

Hi Kannaiah,

Th fields in the Final Internal table are Field

MATNR--CKMLMV001

WERKS--CKMLMV001

GJAHR--CKMLMV003

MGTYP--CKMLMV003

MISCH VERH--CKMLMV003

KALNR BAL--CKMLMV003

PERIO--CKMLMV003

KALNR--CKMLMV001

EKORG ND--CKMLMV001

LIFNR ND--CKMLMV001

The selection Options field are

Field Name

CKMLMV003-MATNR --Selection Option

CKMLMV003-WERKS--Selection otpions

CKMLMV003-GJAHR--Selection otpions

CKMLMV003-Perio--Selection otpions

CKMLMV003-MGTYP--Parameters

This is the Requirement

"1. Usually, ‘plant – fiscal year – Period - quantity structure type’ are specified in selection criteria to get the materials that have procurement alternatives in costing plant, during that year and period. Rarely, individual material selection is done.

2. Use the above combination and query on table CKMLMV003 for the materials. Note down the particulars of Plant, material, mixing ratio (MISCH VERH) and procurement alternative (KALNR BAL) from output.

3. Query on table CKMLMV001 with ‘Plant, material and procurement alternative (KALNR)’ and note down the particulars of Procurement alternative, Vendor and Purchasing organization from the output.

Note : CKMLMV003-KALNR BAL = CKMLMV001-KALNR

4. Bring the selected output from CKMLMV003 and CKMLMV001 tables and arrange them as shown in the output layout in G6.

"

Header containes : Qty stru type: XXXX

Purch org : XXXX

Plant : XXXX

Item data : Material Fiscal year Period Vendor Mix ratio Vendor Mix ratio Vendor Mix ratio Vendor Mix ratio Vendor Mix ratio

Thanks,

Gopi.

uwe_schieferstein
Active Contributor
0 Kudos

Hello Gopi

I must admit that I do not understand your requirements yet perhaps the following sample report <b>ZUS_SDN_SPLITTER_CONTAINER</b> may be useful:

*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_SPLITTER_CONTAINER
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zus_sdn_splitter_container.

**type-pools:  abap.

TYPES: ty_t_knb1    TYPE STANDARD TABLE OF knb1
                    WITH DEFAULT KEY.

TYPES: BEGIN OF ty_s_control.
TYPES: cell    TYPE REF TO cl_gui_container.
TYPES: grid    TYPE REF TO cl_gui_alv_grid.
TYPES: data    TYPE ty_t_knb1.
TYPES: layout  TYPE lvc_s_layo.
TYPES: variant TYPE disvariant.
TYPES: END OF ty_s_control.
TYPES: ty_t_control  TYPE STANDARD TABLE OF ty_s_control
                     WITH DEFAULT KEY.

DATA:
  gs_control       TYPE ty_s_control,
  gt_controls      TYPE ty_t_control.

DATA:
  gd_repid         TYPE syst-repid,
  gd_okcode        TYPE ui_func,
*
  go_docking       TYPE REF TO cl_gui_docking_container,
  go_splitter      TYPE REF TO cl_gui_splitter_container,
**  go_cell          TYPE REF TO cl_gui_container,
**  go_grid          TYPE REF TO cl_gui_alv_grid,
  gs_layout        TYPE lvc_s_layo.


DATA:
  gd_msg           TYPE bapi_msg,
  gd_perc          TYPE i,
  gd_lines         TYPE i,
  gd_idx           TYPE i,
  gd_cnt           TYPE i,
  gt_knb1          TYPE STANDARD TABLE OF knb1.


PARAMETERS:
  p_row    TYPE i  DEFAULT '3',
  p_col    TYPE i  DEFAULT '3'.

START-OF-SELECTION.

  PERFORM init_controls.



  DESCRIBE TABLE gt_controls.
  gd_lines = syst-tfill.


  SELECT * FROM knb1 INTO TABLE gt_knb1 UP TO 100 ROWS
    WHERE bukrs = '1000'.

  LOOP AT gt_controls INTO gs_control.
    gd_idx = syst-tabix.
    gd_cnt = syst-tabix * 5.

    gd_perc = ( syst-tabix * 100 ) / gd_lines.
    CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
      EXPORTING
        percentage       = gd_perc
*       TEXT             = ' '
              .

    gs_control-data = gt_knb1.
    DELETE gt_knb1 INDEX 1.

    "   Set individual layout and variant
    gs_control-layout-cwidth_opt = abap_true.
    gs_control-layout-zebra      = abap_true.
    gs_control-layout-no_toolbar = abap_true.
    gs_control-layout-smalltitle = abap_true.

    WRITE gd_idx TO gs_control-layout-grid_title NO-ZERO.
    CONDENSE gs_control-layout-grid_title NO-GAPS.
    CONCATENATE gs_control-layout-grid_title
                '. Customer'
      INTO gs_control-layout-grid_title.

    CALL METHOD gs_control-grid->set_table_for_first_display
      EXPORTING
        i_structure_name = 'KNB1'
        is_layout        = gs_control-layout
        i_save           = 'A'
        is_variant       = gs_control-variant
      CHANGING
        it_outtab        = gs_control-data
      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.

    MODIFY gt_controls FROM gs_control INDEX gd_idx.
  ENDLOOP.

  gd_msg = gd_lines.
  CONDENSE gd_msg NO-GAPS.
  CONCATENATE gd_msg 'grids displayed on single screen.'
    INTO gd_msg
    SEPARATED BY space.
  MESSAGE gd_msg  TYPE 'S'.

* 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'.



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.


    WHEN OTHERS.
  ENDCASE.

  CLEAR: gd_okcode.

ENDMODULE.                 " USER_COMMAND_0100  INPUT


*&---------------------------------------------------------------------*
*&      Form  INIT_CONTROLS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM init_controls .
* define local data
  DATA:
    ld_column  TYPE i,
    ls_control TYPE ty_s_control.

  REFRESH: gt_controls.

* 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.

  CALL METHOD go_docking->set_extension( 99999 ).


* Create splitter container
  CREATE OBJECT go_splitter
    EXPORTING
      parent            = go_docking
      rows              = p_row
      columns           = p_col
*      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.


  DO p_col TIMES.
    ld_column = syst-index.

    DO p_row TIMES.

* Get cell container
      CLEAR: ls_control.
      CALL METHOD go_splitter->get_container
        EXPORTING
          row       = syst-index
          column    = ld_column
        RECEIVING
          container = ls_control-cell.

*   Create ALV grid
      CREATE OBJECT ls_control-grid
        EXPORTING
          i_parent          = ls_control-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.

      APPEND ls_control TO gt_controls.
    ENDDO.  " rows

  ENDDO.  " columns

ENDFORM.                    " INIT_CONTROLS

Regards

Uwe

0 Kudos

Hi Uwe Schieferstein,

The code you have created is marvellous, it was a great help to me..... thanks....But now my requirement has changed a little.  here you have used a Table KNB1 which is standard and we know the max no of fields in it, I have to handle with dynamic no of columns of internal table suppose a date range...  so how to manage that..... can you please help me out.. with an example..  thanks in advance...