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: 

ALV with variable columns

Former Member
0 Kudos

Hi All,

I have to do a ALV with variable no. of columns. i.e Depending on the data , the columns should get populated.

Thanks in advance.

Dnyanesh

3 REPLIES 3

Former Member
0 Kudos

The solution here is to create a internal table dynamically depending on how many columns you want. Please take a look at my blog, where a table can be created at runtime from the fieldcatalog.

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

former_member181962
Active Contributor
0 Kudos

CReate a dynamic internal table and buid the field catalog for that internal table.

Refer the following thread for some insight.

Regards,

ravi

Former Member
0 Kudos

Hi Dnyanesh,

If you know the no. of columns to be used in the ALV before hand then you can change the field catalog.

but if you dont know the no. of columns then you can create dynamic table.

eg:

1. Create your field catalog either manually or automatically using the function module, LVC_FIELDCATALOG_MERGE. Add more rows to the field catalog table (T_FIELDCAT) at run time.

2. Use the field catalog to create a table dynamically using the method below.

DATA: T_OUTPUT TYPE REF TO DATA

FIELD-SYMBOLS: <T_OUTPUT> TYPE TABLE

Call Method CL_ALV_TABLE_CREATE->CREATE_DYNAMIC_TABLE

Exporting

IT_FIELDCATALOG = T_FIELDCAT

Importing

EP_TABLE = T_OUTPUT

ASSIGN T_OUTPUT->* TO <T_OUTPUT>.

Now the field symbol <T_OUTPUT> is pointing to an output table of the structure that contains the fields which were determined at runtime. Now fill this table with the data and pass <T_OUTPUT> to the method SET_TABLE_FOR_FIRST_DISPLAY and the ALV grid should show the data properly.

Example:

*the content of itab will be fields of the new table

loop at itab1 into wa1.

Gs_FIELDCAT-TABNAME = 'itab2'.

GS_FIELDCAT-FIELDNAME = wa1-packid.

GS_FIELDCAT-OUTPUTLEN = 2.

GS_FIELDCAT-KEY = space.

GS_FIELDCAT-SELTEXT_L = wa1-packid.

GS_FIELDCAT-COL_POS = 1.

GS_FIELDCAT-JUST = 'L'.

APPEND GS_FIELDCAT TO GT_FIELDCAT.

endloop.

LOOP AT GT_FIELDCAT INTO GS_FIELDCAT.

MOVE-CORRESPONDING GS_FIELDCAT TO ls_fcat.

APPEND ls_fcat TO lt_fieldcat.

ENDLOOP.

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING it_fieldcatalog = lt_fieldcat

IMPORTING ep_table = t_output.

you can refer the following link also.

hope this helps.

do get back if you need further clarification.

Regards,

Kinshuk