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: 

Enhance the structure of the existing Field Symbol ?

Former Member
0 Kudos

Dear All,

My scenario is like this :

I have a dynamic internal table in the form of a Field Symbol.

This Field Symbol will have one structure assigned to it dynamically.


    CREATE DATA gt_rson_table TYPE TABLE OF (gwa_znrows_def-rson).
    ASSIGN gt_rson_table->* TO <fs_t_rson>.

Now from the above statement it is clear that the Field Symbol <fs_t_rson> will be having the structure of the Table (gwa_znrows_def-rson).

But now I want to add one more field to this structure after the above assigning .

i.e Say in the above assignment of the Field Symbol, <fs_t_rson> has 5 fields then I want to add one more field to it (Year like MJAHR) and so it should contain 6 fields now .

Is it possible to achieve this ?

If yes let me know the procedure !

Thanks & Regards,

Deepu.K

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Nop, once you create the data and assign it, you can not add another field. You have to add the fields before it. Here is an example of how to add components and create a dynamic internal table.

REPORT zrich_0001 .


TYPE-POOLS:
  abap.

DATA:
  gr_structdescr    TYPE REF TO cl_abap_structdescr,
  gr_tabledescr     TYPE REF TO cl_abap_tabledescr,
  gr_datadescr      TYPE REF TO cl_abap_datadescr,
  gt_components     TYPE abap_component_tab,
  gw_component      TYPE LINE OF abap_component_tab,
  gr_wa             TYPE REF TO data,
  gr_tab            TYPE REF TO data.

FIELD-SYMBOLS: <fs_wa> TYPE ANY.
FIELD-SYMBOLS: <fs_tab> TYPE table.

START-OF-SELECTION.

* determine components of structure -> GT_COMPONENTS
  MOVE 'COMP1' TO gw_component-name.
  gw_component-type ?= cl_abap_elemdescr=>get_c( p_length = 10 ).
  INSERT gw_component INTO TABLE gt_components.

  MOVE 'COMP2' TO gw_component-name.
  gw_component-type ?= cl_abap_elemdescr=>get_c( p_length = 20 ).
  INSERT gw_component INTO TABLE gt_components.

* get structure descriptor -> GR_STRUCTDESCR
  gr_structdescr ?= cl_abap_structdescr=>create( gt_components ).

* create work area of structure GR_STRUCTDESCR -> GR_WA
  CREATE DATA gr_wa TYPE HANDLE gr_structdescr.
  ASSIGN gr_wa->* TO <fs_wa>.


  gr_datadescr ?= gr_structdescr.
  gr_tabledescr ?= cl_abap_tabledescr=>create( gr_datadescr ).

* Create dynmaic internal table
  CREATE DATA gr_tab TYPE HANDLE gr_tabledescr.
  ASSIGN gr_tab->* TO <fs_tab>.

Regards,

Rich Heilman

1 REPLY 1

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Nop, once you create the data and assign it, you can not add another field. You have to add the fields before it. Here is an example of how to add components and create a dynamic internal table.

REPORT zrich_0001 .


TYPE-POOLS:
  abap.

DATA:
  gr_structdescr    TYPE REF TO cl_abap_structdescr,
  gr_tabledescr     TYPE REF TO cl_abap_tabledescr,
  gr_datadescr      TYPE REF TO cl_abap_datadescr,
  gt_components     TYPE abap_component_tab,
  gw_component      TYPE LINE OF abap_component_tab,
  gr_wa             TYPE REF TO data,
  gr_tab            TYPE REF TO data.

FIELD-SYMBOLS: <fs_wa> TYPE ANY.
FIELD-SYMBOLS: <fs_tab> TYPE table.

START-OF-SELECTION.

* determine components of structure -> GT_COMPONENTS
  MOVE 'COMP1' TO gw_component-name.
  gw_component-type ?= cl_abap_elemdescr=>get_c( p_length = 10 ).
  INSERT gw_component INTO TABLE gt_components.

  MOVE 'COMP2' TO gw_component-name.
  gw_component-type ?= cl_abap_elemdescr=>get_c( p_length = 20 ).
  INSERT gw_component INTO TABLE gt_components.

* get structure descriptor -> GR_STRUCTDESCR
  gr_structdescr ?= cl_abap_structdescr=>create( gt_components ).

* create work area of structure GR_STRUCTDESCR -> GR_WA
  CREATE DATA gr_wa TYPE HANDLE gr_structdescr.
  ASSIGN gr_wa->* TO <fs_wa>.


  gr_datadescr ?= gr_structdescr.
  gr_tabledescr ?= cl_abap_tabledescr=>create( gr_datadescr ).

* Create dynmaic internal table
  CREATE DATA gr_tab TYPE HANDLE gr_tabledescr.
  ASSIGN gr_tab->* TO <fs_tab>.

Regards,

Rich Heilman