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: 

Dynamic columns in report... NON ALV REPORT

Former Member
0 Kudos

Hey Guys,

I have a internal table which has abt 50 columns now i wanna show only the columns that have any value in it...

Now this is not an ALV report... this is a basic report....

So anyideas as to where i can start on this.... i dont want to write if conditions...

i am tryin to make this as elegent as possible...

all help will be appreciated

Thanks

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Try this..

In this example..I have an internal table with the columns MATNR, WERKS, LGORT & MENGE...The ITAB is having value only for matnr and werks..It will print only MATNR and WERKS in the output..

<b>* Data declarations.</b>

DATA: BEGIN OF itab OCCURS 0,

matnr TYPE matnr,

werks TYPE werks_d,

lgort TYPE mard-lgort,

menge TYPE ekpo-menge,

END OF itab.

DATA: BEGIN OF itab_desc OCCURS 0,

compname(30),

text(20),

END OF itab_desc.

DATA: v_repid TYPE syrepid.

DATA: t_comp LIKE rstrucinfo OCCURS 0 WITH HEADER LINE.

FIELD-SYMBOLS: <fs>.

DATA: t_allowed_fields(30) OCCURS 0 WITH HEADER LINE.

<b>* Program.</b>

v_repid = sy-repid.

<b>* Sample data.</b>

itab-matnr = 'TEST'. itab-lgort = '0001'.APPEND itab.

itab-matnr = 'TEST12'. itab-lgort = '0001'.APPEND itab.

itab-matnr = 'TEST123'.itab-lgort = '0001'.APPEND itab.

<b>* Store the columns texts.</b>

itab_desc-compname = 'MATNR'. itab_desc-text = 'Material'.

APPEND itab_desc.

itab_desc-compname = 'WERKS'. itab_desc-text = 'Plant'.

APPEND itab_desc.

itab_desc-compname = 'LGORT'. itab_desc-text = 'Sto. Loc'.

APPEND itab_desc.

itab_desc-compname = 'MENGE'. itab_desc-text = 'Quantity'.

APPEND itab_desc.

<b>* Get the components for that internal table.</b>

CALL FUNCTION 'GET_COMPONENT_LIST'

EXPORTING

program = v_repid

fieldname = 'ITAB'

TABLES

components = t_comp.

<b>* Get the columns that has some value.</b>

LOOP AT t_comp.

LOOP AT itab.

ASSIGN COMPONENT t_comp-compname OF STRUCTURE itab TO <fs>.

IF NOT <fs> IS INITIAL.

EXIT.

ENDIF.

ENDLOOP.

  • Allowed columns.

IF NOT <fs> IS INITIAL.

t_allowed_fields = t_comp-compname.

APPEND t_allowed_fields.

ENDIF.

ENDLOOP.

<b>* Print the Header.</b>

LOOP AT t_allowed_fields.

READ TABLE t_comp WITH KEY compname = t_allowed_fields.

READ TABLE itab_desc WITH KEY compname = t_allowed_fields.

WRITE: AT (t_comp-olen) itab_desc-text COLOR COL_HEADING.

ENDLOOP.

<b>* Print the data.</b>

LOOP AT itab.

WRITE: / space.

LOOP AT t_allowed_fields.

READ TABLE t_comp WITH KEY compname = t_allowed_fields.

ASSIGN COMPONENT t_comp-compname OF STRUCTURE itab TO <fs>.

WRITE: AT (t_comp-olen) <fs>.

ENDLOOP.

ENDLOOP.

Thanks,

Naren

4 REPLIES 4

Former Member
0 Kudos

Hi,

Try this..

In this example..I have an internal table with the columns MATNR, WERKS, LGORT & MENGE...The ITAB is having value only for matnr and werks..It will print only MATNR and WERKS in the output..

<b>* Data declarations.</b>

DATA: BEGIN OF itab OCCURS 0,

matnr TYPE matnr,

werks TYPE werks_d,

lgort TYPE mard-lgort,

menge TYPE ekpo-menge,

END OF itab.

DATA: BEGIN OF itab_desc OCCURS 0,

compname(30),

text(20),

END OF itab_desc.

DATA: v_repid TYPE syrepid.

DATA: t_comp LIKE rstrucinfo OCCURS 0 WITH HEADER LINE.

FIELD-SYMBOLS: <fs>.

DATA: t_allowed_fields(30) OCCURS 0 WITH HEADER LINE.

<b>* Program.</b>

v_repid = sy-repid.

<b>* Sample data.</b>

itab-matnr = 'TEST'. itab-lgort = '0001'.APPEND itab.

itab-matnr = 'TEST12'. itab-lgort = '0001'.APPEND itab.

itab-matnr = 'TEST123'.itab-lgort = '0001'.APPEND itab.

<b>* Store the columns texts.</b>

itab_desc-compname = 'MATNR'. itab_desc-text = 'Material'.

APPEND itab_desc.

itab_desc-compname = 'WERKS'. itab_desc-text = 'Plant'.

APPEND itab_desc.

itab_desc-compname = 'LGORT'. itab_desc-text = 'Sto. Loc'.

APPEND itab_desc.

itab_desc-compname = 'MENGE'. itab_desc-text = 'Quantity'.

APPEND itab_desc.

<b>* Get the components for that internal table.</b>

CALL FUNCTION 'GET_COMPONENT_LIST'

EXPORTING

program = v_repid

fieldname = 'ITAB'

TABLES

components = t_comp.

<b>* Get the columns that has some value.</b>

LOOP AT t_comp.

LOOP AT itab.

ASSIGN COMPONENT t_comp-compname OF STRUCTURE itab TO <fs>.

IF NOT <fs> IS INITIAL.

EXIT.

ENDIF.

ENDLOOP.

  • Allowed columns.

IF NOT <fs> IS INITIAL.

t_allowed_fields = t_comp-compname.

APPEND t_allowed_fields.

ENDIF.

ENDLOOP.

<b>* Print the Header.</b>

LOOP AT t_allowed_fields.

READ TABLE t_comp WITH KEY compname = t_allowed_fields.

READ TABLE itab_desc WITH KEY compname = t_allowed_fields.

WRITE: AT (t_comp-olen) itab_desc-text COLOR COL_HEADING.

ENDLOOP.

<b>* Print the data.</b>

LOOP AT itab.

WRITE: / space.

LOOP AT t_allowed_fields.

READ TABLE t_comp WITH KEY compname = t_allowed_fields.

ASSIGN COMPONENT t_comp-compname OF STRUCTURE itab TO <fs>.

WRITE: AT (t_comp-olen) <fs>.

ENDLOOP.

ENDLOOP.

Thanks,

Naren

0 Kudos

Thanks Naren...

Problem solved excellent solution u r a 10/10 man.....

actually this also opened a lot of other ideas.. i really dont fancy field symbols... but they are pretty flexible....

Former Member
0 Kudos

Hi Abhishek,

What Narendar has suggested you is the only solution. Because he is using the Fied-symobol will work fine for any sort of table also. But this logic has some bug becuase if suppose in the 2nd row 2field doesn't has the data and 1st row 1st field has the data then it won't looks like a table because in the second 2nd row, 3field information will sit in the place of 2nd field inforamton.

Please let me know what Kind of situation you want why you need that. Depending on that i can provide you the logic.

<b>Logic here as follows:</b>

LOOP AT t_comp.
   LOOP AT itab.
       ASSIGN COMPONENT t_comp-compname OF STRUCTURE itab TO <fs>.
       IF NOT <fs> IS INITIAL.
       EXIT.
       ENDIF.
ENDLOOP.

* Allowed columns.
IF NOT <fs> IS INITIAL.
t_allowed_fields = t_comp-compname.
APPEND t_allowed_fields.
ENDIF.
ENDLOOP.

Warm Regards,

Vijay

0 Kudos

Hi Vijay,

I could not really find a bug,.. i tested around the scenario that you had mentioned .... but it showed up just fine ...

am i missing something ?