2006 Nov 27 11:30 AM
Hi all,
Can anybody pls. tell me how to output dynamic columns in a report. my req. is that i've to generate so many columns as there are no. of unique(a particular field value) rows in my internal table. for e.g say suppose i've 5 rows in my internal table which has 2 fields, one short text & it's corresponding value. so now my report output shud have 5 columns with the short text as the column heading & the their corresponding values below each column heading. i heard it can be done thru field-symbols. can anyone pls. guide me.
Hi all,
Can anybody pls. tell me how to output dynamic columns in a report. my req. is that i've to generate so many columns as there are no. of unique(a particular field value) rows in my internal table. for e.g say suppose i've 5 rows in my internal table which has 2 fields, one short text & it's corresponding value. so now my report output shud have 5 columns with the short text as the column heading & the their corresponding values below each column heading. i heard it can be done thru field-symbols. can anyone pls. guide me.
2006 Nov 27 11:36 AM
Hi
It seem not to make a sense to do this by field-symbols, you should create a dynamic internal table to use them.
If you have few hits you can loop your table twice:
- The first loop to write the header
LOOP AT ITAB.
WRITE: ITAB-FIELD1.
ENDLOOP.
- The second one to write the value
LOOP AT ITAB.
WRITE: / ITAB-FIELD2.
ENDLOOP.
If you need to use ALV to print the data:
U have to create a fieldcat:
DATA: INDEX(4) TYPE N.
LOOP AT ITAB.
Each line of ITAB is a colunm for new ITAB
MOVE SY-TABIX TO INDEX
CONCATENATE 'FIELD' INDEX INTO
LT_FIELDCAT-FIELDNAME.
Transfer the rest of data to indicate the kind of data
and the description
APPEND LT_FIELDCAT TO GT_FIELDCAT.
ENDLOOP
Use class CL_ALV_TABLE_CREATE to create the new table
Max
2006 Nov 27 11:36 AM
See this blog, you can do that.
/people/ravikumar.allampallam/blog/2005/05/31/expand-the-list-of-columns-in-a-report-dynamically
regards,
Ravi
note - Please mark all the helpful answers
2006 Nov 27 11:41 AM
Hi Sushma,
This piece of code might be useful.
The following sections will help you to understand the steps required to define a Dynamic ALV.
Following symbol signifies:
Þ Important
Main Steps Required
The following are the main steps that are to be performed for defining a dynamic Alv
1. Defining a field catalog
2. Defining the dynamic table
3. Filling data into the table
4. Displaying ALV list
Defining a field catalog
The purpose of defining a field catalog first in case of Dynamic ALV is somewhat different than in case of normal ALV. In case of Dynamic ALV the field catalog is used to define the final internal table that will hold the data, and would be used to display the final output.
Þ It is very important to remember that the field catalog table be refreshed first, else it might give an error.
For example:
DATA: T_FIELDCAT TYPE LVC_T_FCAT,
L_FIELDCAT TYPE LVC_S_FCAT.
Refresh T_FIELDCAT.
CLEAR L_FIELDCAT.
L_FIELDCAT-FIELDNAME = 'LIFNR'.
L_FIELDCAT-INTTYPE = ''.
L_FIELDCAT-OUTPUTLEN = 10.
L_FIELDCAT-COLTEXT = TEXT-002.
APPEND L_FIELDCAT TO T_FIELDCAT.
Defining the dynamic table.
This table will hold the final data that needs to be displayed. To declare the table the following things need to be done.
Declare a field symbol
Displaying Alv List
This is done in the same way as we do for normal Alv. Call function REUSE_ALV_GRID_DISPLAY and pass the field catalog table in the export parameters and the dynamic table in Tables.
Reward Points if it is helpful.
Reagrds,
Kiran I
2006 Nov 27 11:43 AM
Hi Sushma,
Check this demo program <b>BCALV_TABLE_CREATE</b>. This explains you
how to create dynamic table and how to populate it.
Thanks & Regards,
Siri.