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: 

how can increase or decrease the no.of internal table fields dynamically.

Former Member
0 Kudos

how can increase or decrease the no.of internal table fields dynamically.

Hi all,

i have 30 fields are there in the Internal table. i want to display them in the alv report.

now my problem is, based on the condition i want to display only 10 fields or only 20 fields or only 30 fields and vise versa of the in internal table in the alv report.

how can increase or decrease the no.of internal table fields dynamically.

can any body explain me briefly with examples...

Thanks,

Mythily Guptha

7 REPLIES 7

SuhaSaha
Advisor
Advisor
0 Kudos

For this you have to use dynamic internal tables. You cannot increase / decrease the no. of fields in a statically defined internal table.

satyajit_mohapatra
Active Contributor
0 Kudos

The fields not required in ALV output can be hidden by populating the NO_OUT option in fieldcatalog . Later user can display the fields using change layout option.

Former Member
0 Kudos

Dynamic internal table is an extension to internal table concept, used when the number of fields is not known at the design time or until the compile time.

Creating Dynamic internal table

 PARAMETERS : p_table(10) TYPE C. 

  DATA: w_tabname TYPE w_tabname,             

             w_dref TYPE REF TO data,              

             w_grid TYPE REF TO cl_gui_alv_grid.  

  FIELD-SYMBOLS: <t_itab> TYPE ANY TABLE.  

  w_tabname = p_table.  

  CREATE DATA w_dref TYPE TABLE OF (w_tabname). 

  ASSIGN w_dref->* TO <t_itab>

.

Populating Dynamic internal table

 SELECT * 

    FROM (w_tabname) UP TO 20 ROWS 

    INTO TABLE <t_itab>

.

Displaying dynamic internal table using Grid.

CREATE OBJECT w_grid 

    EXPORTING i_parent = cl_gui_container=>screen0.  

  CALL METHOD w_grid->set_table_for_first_display 

    EXPORTING 

      i_structure_name = w_tabname 

    CHANGING 

      it_outtab        = <t_itab>

CALL SCREEN 100.

Former Member
0 Kudos

Hi ,

Try using the field symbols .

Hope this will be helpful.

Thanks & Regards,

Rajasekhar.

satyajit_mohapatra
Active Contributor
0 Kudos

Usually, dynamic tables are created, when the fields of the internal table are not certain. But, in your case, you have 30 static fields already declared and you need it to be displayed based on some conditions.

So, instead of creating a dynamic internal table you can modify the display attributes in ALV. If you hide the fields, then later the user can display it modifying layout settings. Otherwise, it's better not to create a field catalog for a field, which doesn't need to be displayed.

Thus you can have 30 fields in your internal table and can create fieldcatalog for 20 fields to be displayed based on your conditions.

Please refer the below code.



TYPE-pools: SLIS.

TYPES: BEGIN OF test,
        f1 type c,
        f2 type c,
        f3 type c,
       end of test.

DATA: ttest type table of test,
      stest type test,
      sfcat type slis_fieldcat_alv,
      tfcat type table of slis_fieldcat_alv.

PARAMETERS: p_check TYPE c,
            p_check1 type c.

stest-f1 = '1'.
stest-f2 = '2'.
stest-f3 = '3'.
APPEND stest TO ttest.

sfcat-fieldname = 'F1'.
sfcat-tabname   = 'TTEST'.
IF p_check EQ 'X'.               "Hide the field 1, but user can display it later using layout settings
  sfcat-no_out   = 'X'.
ENDIF.
APPEND sfcat TO tfcat.
CLEAR sfcat.

IF p_check1 NE 'X'.             "Hide the field 2, can not be displayed through layout settings
  sfcat-fieldname = 'F2'.
  sfcat-tabname   = 'TTEST'.
  APPEND sfcat TO tfcat.
  CLEAR sfcat.
ENDIF.


sfcat-fieldname = 'F3'.
sfcat-tabname   = 'TTEST'.
APPEND sfcat TO tfcat.
CLEAR sfcat.


CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
 EXPORTING
   IT_FIELDCAT                       = tfcat[]
 TABLES
    T_OUTTAB                          = ttest
* EXCEPTIONS
*   PROGRAM_ERROR                     = 1
*   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.

Former Member
0 Kudos

Hi,

I think your scenario related to Variants in ALV.

Try in that way

Regards,

Raghava Channooru.

Former Member
0 Kudos

Hi,

Hope this link will hlep to solve your issue http://help-abap.blogspot.com/2008/09/dynamic-internal-table-creation.html

Regards,

Pravin