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

Add new fields in already declare internal table

Hi gurus,

Is it possible to add some fields in already declared internal table during run time

suppose I have 5 fields in my internal table but during runtime i wish to another 2 fields in same table...is there any way to do this.......thanx in advance.......

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

9 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Dec 19, 2008 at 10:18 AM

    HI.

    refer this link.

    http://www.sap-img.com/ab030.htm

    Regards.

    Jay

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 19, 2008 at 10:19 AM

    Hi Rizwan,

    Welcome to SDN. 😊

    I dont know ur query, but u can add how many fields u want in internal table.

    can add fields in the program and use it in ur program

    Regards

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 19, 2008 at 10:19 AM

    during runtime it is not possible

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 19, 2008 at 10:23 AM

    you can do one thing , create another table with all your 7 fields , and when ever you want to add another 2 fields may be depends on some condition , copy your data from first table to the second internal table with 7 fields

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 19, 2008 at 10:30 AM

    Hi,

    You can create a field catalog for your internal table and during runtime use it to create a dynamic table

    using cl_alv_table_create=>create_dynamic_table.

    Regards,

    Vartika

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 19, 2008 at 10:38 AM

    This message was moderated.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 19, 2008 at 10:50 AM

    Hi,

    I don't think it is possible to add fields to an existing table in runtime.

    If your number of fields are not many you can create another table with all fields and based on field name determined during un time you can assign values to the original table.

    The logic would be as follows,

    FIELD-SYMBOLS:  <fs> TYPE ANY.
    DATA: w_field(10) TYPE c VALUE 'FIELD1'. "For example this is your run time field
    ASSIGN COMPONENT (w_field) OF STRUCTURE it_copy TO <fs>.
    it_original-field = <fs>.

    Or you want to create a the whole table on run time,

    check thi example(here i'm creating table of structure 'SYST' (system fields table) and

    displaying 'subrc' field.

    TYPE-POOLS: slis.
    
    DATA: it_fcat TYPE slis_t_fieldcat_alv,
          is_fcat LIKE LINE OF it_fcat.
    DATA: it_fieldcat TYPE lvc_t_fcat,
          is_fieldcat LIKE LINE OF it_fieldcat.
    DATA: new_table TYPE REF TO data.
    DATA: new_line  TYPE REF TO data.
    FIELD-SYMBOLS: <l_table> TYPE ANY TABLE,
                   <l_line>  TYPE ANY,
                   <l_field> TYPE ANY.
    * Build fieldcat
    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
      EXPORTING
        i_structure_name = 'SYST'
      CHANGING
        ct_fieldcat      = it_fcat[].
    LOOP AT it_fcat INTO is_fcat WHERE NOT reptext_ddic IS INITIAL.
      MOVE-CORRESPONDING is_fcat TO is_fieldcat.
      is_fieldcat-fieldname = is_fcat-fieldname.
      is_fieldcat-ref_field = is_fcat-fieldname.
      is_fieldcat-ref_table = is_fcat-ref_tabname.
      APPEND is_fieldcat TO it_fieldcat.
    ENDLOOP.
    
    * Create a new Table
    CALL METHOD cl_alv_table_create=>create_dynamic_table
      EXPORTING
        it_fieldcatalog = it_fieldcat
      IMPORTING
        ep_table        = new_table.
    
    * Create a new Line with the same structure of the table.
    ASSIGN new_table->* TO <l_table>.
    CREATE DATA new_line LIKE LINE OF <l_table>.
    ASSIGN new_line->* TO <l_line>.
    
    * Test it...
    DO 30 TIMES.
      ASSIGN COMPONENT 'SUBRC' OF STRUCTURE <l_line> TO <l_field>.
      <l_field> = sy-index.
      INSERT <l_line> INTO TABLE <l_table>.
    ENDDO.
    WRITE: / 'sy-subrc'.
    LOOP AT <l_table> ASSIGNING <l_line>.
      ASSIGN COMPONENT 'SUBRC' OF STRUCTURE <l_line> TO <l_field>.
      WRITE: / <l_field>.
    ENDLOOP.

    Regards,

    Manoj Kumar P

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 19, 2008 at 11:39 AM

    you can do one thing , create another table with all your 7 fields , and when ever you want to add another 2 fields may be depends on some condition , copy your data from first table to the second internal table with 7 fields

    creat int table itab_initial wth less fields.

    and itab_final with all required field.

    at any particular condition itab_final[] = itab_initial.

    and populate the final table if this condition satisfy.

    if it does not match then u can use OOps concept.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 20, 2008 at 05:44 AM

    Hi,

    It is possible to implement the functionality you are requesting. So, you have 5 fixed fields + any new number of additional fields to add at runtime? right?

    So how do you get the new fields to be added to your table?

    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.