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

Internal table with variable no of columns

Hi All,

I have to create an internal table with some fixed columns and rest of the table should be dynamic. The total no of columns depends on a field of some other table. hence, the number of columns of the table are unknown. How to create such a table.

Thanks,

Neha

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

7 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Apr 01, 2009 at 11:21 AM

    Hi Neha,

    You have to use field symbols to create the columns dynamically.

    Regards,

    jaya ram

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 01, 2009 at 11:28 AM

    Check this code:

    
    FIELD-SYMBOLS : <fs_it>    TYPE table,
    
    DATA: it_fs_it        TYPE REF TO data.
              it_tab_desc_aux TYPE lvc_t_fcat,
    
    *fulfill the fieldcatalog with the colums you want
    
     CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = it_tab_desc_aux
        IMPORTING
          ep_table = it_fs_it.
    
    ASSIGN it_fs_it->* TO <fs_it>.
    
    

    Regards

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      In that case you have to add 92 lines to the fieldcatalog table, with the metatada of your columns. On the line of the comment *fullfill fieldcatalog.

      Example lets suppose we want (no_columns) of type carrid.

      
      DATA: no_columns type i.
      no_columns = 92.
      
      DO no_columns TIMES.
      
      it_tab_desc_aux-fieldname = 'cARRID'.
      it_tab_desc_aux-ref_field = 'cARRID'.
      it_tab_desc_aux-ref_field = 'SFLIGHT'.
      APPEND it_tab_desc_aux.
      
      ENDDO.
      
      

      Regards.

  • author's profile photo Former Member
    Former Member
    Posted on Apr 01, 2009 at 11:30 AM

    Hi,

    use FM lvc_table_create, pass the class name and call it after like below..

    cl_alv_table_create-->create_dynamic_table.

    Hope it helps!!

    Regards,

    Pavan

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 02, 2009 at 04:41 AM

    Hi..

    Try Below code.

    DATA: IT_LVC_T_FCAT TYPE LVC_T_FCAT,

    IS_LVC_T_FCAT LIKE LINE OF IT_LVC_T_FCAT.

    FIELD-SYMBOLS: <DYN_TABLE> TYPE STANDARD TABLE,

    <DYN_WA>,

    <DYN_FIELD>.

    • Create dynamic internal table and assign to FS

    CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

    EXPORTING

    IT_FIELDCATALOG = IT_LVC_T_FCAT

    IMPORTING

    EP_TABLE = DY_TABLE.

    ASSIGN DY_TABLE->* TO <DYN_TABLE>.

    • Create dynamic work area and assign to FS

    CREATE DATA DY_LINE LIKE LINE OF <DYN_TABLE>.

    ASSIGN DY_LINE->* TO <DYN_WA>.

    Salil ...

    Edited by: salil chavan on Apr 2, 2009 6:42 AM

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 02, 2009 at 11:53 AM

    Thanks,

    the problem is solved now

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 17, 2011 at 11:20 AM

    Try this code:

    DATA: dy_table TYPE REF TO data,

    dy_line TYPE REF TO data.

    FIELD-SYMBOLS: <dyn_table> TYPE ANY TABLE,

    <dyn_wa>.

    CREATE DATA dy_table TYPE STANDARD TABLE OF (fill Table name here).

    ASSIGN dy_table->* TO <dyn_table>.

    • Create dynamic work area and assign to FS

    CREATE DATA dy_line LIKE LINE OF <dyn_table>.

    ASSIGN dy_line->* TO <dyn_wa>.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 02, 2012 at 08:37 AM

    HI,

    assume that you want to have a report that user able to select table name (for example mara ,...) and then system displays data in ALV to user.

    write bellow codes:

    ====================================

    data: QUERY_TABLE LIKE DD02L-TABNAME .

    PARAMETERS :
    p_tab LIKE QUERY_TABLE .


    DATA: BEGIN OF WORK, BUFFER(30000), END OF WORK,

    DREF TYPE REF TO DATA.


    FIELD-SYMBOLS: <WA> TYPE ANY, <COMP> TYPE ANY.

    FIELD-SYMBOLS: <ITAB> TYPE STANDARD TABLE.

    START-OF-SELECTION .

    QUERY_TABLE = p_tab . "table name

    ASSIGN WORK TO <WA> CASTING TYPE (QUERY_TABLE).

    CREATE DATA DREF TYPE STANDARD TABLE OF (QUERY_TABLE).

    ASSIGN DREF->* TO <ITAB>.

    SELECT * FROM (QUERY_TABLE) UP TO i_rows rows INTO TABLE <ITAB> .

    regards ,

    REZA ROSTAMI / SAPHIRAN(www.saphiran.com) ABAPER


    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.