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 new fields in already declare internal table

Former Member
0 Kudos

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.......

10 REPLIES 10

Former Member
0 Kudos

HI.

refer this link.

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

Regards.

Jay

Former Member
0 Kudos

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

JozsefSzikszai
Active Contributor
0 Kudos

during runtime it is not possible

Former Member
0 Kudos

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

0 Kudos

Dear Akash,

There is not only 2 fields this is just i have taken as example, but the actual field will be know during runtime only, hence this will not be fruitful to me.

Thanx!

Former Member
0 Kudos

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

Former Member
0 Kudos

This message was moderated.

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

dev_parbutteea
Active Contributor
0 Kudos

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?