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: 

Add field in an internal table

Former Member
0 Kudos

Hi There,

How to add a field in an internal table created at the runtime using

CREATE DATA D1 TYPE TABLE OF (VAR).

where say var contains name of a DDIC table.

Rgds,

deb.

7 REPLIES 7

Former Member
0 Kudos

Deb,

If the internal table is already created then you cannot add a new field to it at runtime.

But if you want to create the internal table itself at runtime, then as you have written the CREATE DATA statement can be used where D1 is declared as TYPE REF to DATA.

Regards,

Ravi

Note : Please mark all the helpful answers

nishanthbhandar
Contributor
0 Kudos

former_member181962
Active Contributor
0 Kudos

you can use this statament:

TYPES: BEGIN OF ty_itab,

field1,

field2,

END OF ty_itab.

table_name = 'TY_ITAB'.

CREATE DATA my_table TYPE STANDARD TABLE OF (table_name).

Former Member
0 Kudos
after creating internal table use the method for creation of dynamic table and try , i am not sure

DATA: LineType TYPE string, 
      ItabRef  TYPE REF TO DATA. 
FIELD-SYMBOLS:   TYPE STANDARD TABLE. 
... 
LineType = 'SFLIGHT'. 
... 
" Create internal table and attach a field-symbol 
CREATE DATA ItabRef TYPE STANDARD TABLE OF (LineType). 
ASSIGN ItabRef->* TO . 

<b>after this check this and try</b>

******DATA DECLARATION*****************************

FIELD-SYMBOLS : <it_final> TYPE STANDARD TABLE,
                <wa_final> TYPE ANY,
                <w_field> TYPE ANY.


***DYNAMIC CREATION OF FIELDCATALOG****************

*FIRST 2 FIELDS FIELDS FIELD1 AND FIELD2 ARE CONSTANT, FIELDS OBTAINED IN THE LOOP ENDLOOP ARE DYNAMIC,
*LIKEWISE DYNAMIC FIELDCATALOG IS CREATED

  wa_fieldcatalog-fieldname  = 'FIELD1'.
  wa_fieldcatalog-ref_table  = 'E070'.
  wa_fieldcatalog-outputlen  = '13'.
  wa_fieldcatalog-reptext    = 'Created On'.
  wa_fieldcatalog-seltext    = 'Created On'.
  APPEND wa_fieldcatalog TO it_fieldcatalog.
  CLEAR wa_fieldcatalog.
  
  wa_fieldcatalog-fieldname  = 'FIELD1'.
  wa_fieldcatalog-ref_table  = 'E070'.
  wa_fieldcatalog-outputlen  = '13'.
  wa_fieldcatalog-reptext    = 'Created On'.
  wa_fieldcatalog-seltext    = 'Created On'.
  APPEND wa_fieldcatalog TO it_fieldcatalog.
  CLEAR wa_fieldcatalog.


  LOOP AT it_mandt WHERE mandt IN s_mandt.
    CONCATENATE 'CLNT' it_mandt INTO wa_fieldcatalog-fieldname.
    wa_fieldcatalog-inttype    = 'NUMC'.
    wa_fieldcatalog-outputlen  = '14'.
    wa_fieldcatalog-reptext    = it_mandt.
    wa_fieldcatalog-seltext    = it_mandt.

    APPEND wa_fieldcatalog TO it_fieldcatalog.
    CLEAR :wa_fieldcatalog ,it_mandt.
  ENDLOOP.


********CREATE DYNAMIC TABLE************************

  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog           = it_fieldcatalog
    IMPORTING
      ep_table                  = new_table
    EXCEPTIONS
      generate_subpool_dir_full = 1
      OTHERS                    = 2.
  IF sy-subrc <> 0.
*  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  ASSIGN new_table->* TO <it_final>.

*********CREATE WORK AREA****************************

CREATE DATA new_line LIKE LINE OF <it_final>.
  ASSIGN new_line->* TO <wa_final>.

*********INSERTTING WORK AREAR TO INTERNAL TABLE******

    INSERT <wa_final> INTO TABLE <it_final>.

*******POPULATING DATA*******************************  
  LOOP.
   
   ASSIGN COMPONENT 'FIELD1' OF STRUCTURE <wa_final> TO <w_field>.
   <w_field> = '12345'.

    ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <wa_final> TO <w_field>.
   <w_field> = '21453DD'.

   FIELD1 AND FIELD2 ARE COMPONENTS OF FIELDCATALOG.
    
ENDLOOP.      

  ENDLOOP.

Former Member
0 Kudos

0 Kudos

hi,

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' and pass your internal table to get the field catalog

then add the field u want to the field catalog then

  • Create a new Table

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fieldcat

IMPORTING

ep_table = new_table.

now u have a table with the strucure u want.

if u need more help contact me

Regards

Waleed

hymavathi_oruganti
Active Contributor
0 Kudos

data:d1 type ref to data.

field-symbols: <fs> type table, <f1> type any,

<f2> type any.

create data d1 type table (table).

assign d1->* to <fs>.

loop at (table).

move-corresponding (table) to <fs>.

assign (table)-field1 to <f2>.

assign component field1 of structure (table) to

<f1>.

<f1> = <f2>.

endloop.