Application Development and Automation 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: 
Read only

Populating dynamically added components

Shky
Product and Topic Expert
Product and Topic Expert
0 Likes
489

Hi,

I have a structure Struc1 (Components A,B,C,D).

During my runtime, I add components to this structure and now it has (A,B,C,D, X1,X2) as follows.

DATA:

lr_struc TYPE REF TO cl_abap_structdescr,

lt_comp TYPE cl_abap_structdescr=>component_table.

ls_comp-name = 'X1'.

ls_comp-type ?= cl_abap_structdescr=>describe_by_name( 'OBJID' ).

APPEND ls_comp TO lt_comp.

ls_comp-name = 'X2'.

ls_comp-type ?= cl_abap_structdescr=>describe_by_name( 'OBJID' ).

APPEND ls_comp TO lt_comp.

Now I have the following to populate the data.

DATA: ls_struc1 type Struc1. "Defined above

Field-symbols: <Ls_data> type any.

MOVE CORRESPONDING ls_struc1 TO <ls_data>.

now the fields A,B,C,D are populated for <ls_data>.

But how do I do the same for fields X1 and X2. I see them as fields for <ls_data> in the runtime, but not sure how to populate that.

(ie., how to get <ls_data>-X1 and <ls_data>-X2. )

Can someone help me?

Regards,

Shalini.

3 REPLIES 3
Read only

Nawanandana
Active Contributor
0 Likes
467

hi

u can use like this

FIELD-SYMBOLS: <eval_wa> TYPE pay_eval_period.

DATA: l_eval_tab TYPE pay_t_eval_period.

LOOP AT l_eval_tab ASSIGNING <eval_wa>.

Read only

Shky
Product and Topic Expert
Product and Topic Expert
0 Likes
467

Hi,

Thanks for the reply.

I need to populate a structure of type ANY ie., <ls_data>.

Thanks,

Shalini.

Read only

Former Member
0 Likes
467

Hi,

Try to use the following syntax:

Field-symbols: <fs> type any.

DO.

Assign component sy-index of structure <ls_data> to <fs>.

if sy-subrc = 0.

<fs> = 'value to be populated'.

else.

exit.

endif.

ENDDO.