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 table column dynamically?

Former Member
0 Kudos
1,537

Hi,

I need to display some information using ALV. But my table's columns are not static. Its column size can be change respect to station. Now, It it possible to add new columns to internal table and show with ALV?

Thanks.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
429

Hi,

Take a look at these blogs which deal with dynamic internal tables ....

/people/ravikumar.allampallam/blog/2005/05/31/expand-the-list-of-columns-in-a-report-dynamically

/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table

/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap

You will have to create the entire internal table dynamically, once created you cannot add any more fields to the table.

Regards,

Ravi

Note :Please mark the helpful answers

8 REPLIES 8

Manohar2u
Active Contributor
0 Kudos
429

Can'nt we try to fill field catalog based on the logic?

Regds

Manohar

Former Member
0 Kudos
429

Hi,

I mean that my internal table's column size can be 10 or 15 or 17 or another number respect to user's selection. So, I can not define internal table statically.

0 Kudos
429

As manohar said modify the field catalog and dont forget to call

REFRESH_TABLE_DISPLAY method of cl_gui_alv_grid. (i assume you are using class based ALV)

Regards

Raja

0 Kudos
429

in such a case you need to define the internal table dynamically

which can be done using

call method cl_alv_table_create=>create_dynamic_table

exporting

it_fieldcatalog = it_fieldcat

importing

ep_table = new_table.

search this forum for code sample on using this.

Regards

Raja

Manohar2u
Active Contributor
0 Kudos
429

then you need to create dynamic internal table and respective field catalog.

Regds

Manohar

Former Member
0 Kudos
429

HI,

This is a Example progrma to create a Dinamic Internal table

*&---------------------------------------------------------------------*
*& Report  ZDEEP_DYNAMIC_INTERNALTABLE                                 *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

report  zdeep_dynamic_internaltable             .

data: d_ref type ref to data,
d_ref2 type ref to data ,
i_alv_cat type table of lvc_s_fcat,
ls_alv_cat like line of i_alv_cat.


types tabname like dcobjdef-name .
parameter: p_tablen type tabname.

data: begin of itab occurs 0.
include structure dntab.
data: end of itab.


field-symbols : <f_fs> type table,
<f_fs1> type table,
<f_fs2> type any,
<f_fs3> type table,
<f_fs4> type any.

refresh itab.
call function 'NAMETAB_GET'
exporting
langu = sy-langu
tabname = p_tablen
tables
nametab = itab

exceptions
no_texts_found = 1.
loop at itab .
ls_alv_cat-fieldname = itab-fieldname.
ls_alv_cat-ref_table = p_tablen.
ls_alv_cat-ref_field = itab-fieldname.
append ls_alv_cat to i_alv_cat.
endloop.
* internal table build
call method cl_alv_table_create=>create_dynamic_table
exporting it_fieldcatalog = i_alv_cat
importing ep_table = d_ref .
assign d_ref->* to <f_fs>.

select * from (p_tablen) into corresponding fields of table <f_fs>.


loop at <f_fs> assigning <f_fs2>.
assign itab-fieldname to <f_fs4>.
loop at itab.
write: / <f_fs4>.
endloop.

endloop.

Hope this helps you

Thanks

Sudheer

Former Member
0 Kudos
429

Hi,

Refer this below link also

http://www.sap-img.com/ab030.htm

Sudheer

Former Member
0 Kudos
430

Hi,

Take a look at these blogs which deal with dynamic internal tables ....

/people/ravikumar.allampallam/blog/2005/05/31/expand-the-list-of-columns-in-a-report-dynamically

/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table

/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap

You will have to create the entire internal table dynamically, once created you cannot add any more fields to the table.

Regards,

Ravi

Note :Please mark the helpful answers