Skip to Content
author's profile photo Former Member
Former Member

Dynamic columns in report... NON ALV REPORT

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Apr 25, 2007 at 12:52 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 25, 2007 at 05:19 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.