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

Dynamic fieldnames

Former Member
0 Likes
570

Hi Experts,

I am wondering something.

In an ABAP program, datas are extracted from an csv file with many columns (100).

The datas are similar for each columns.

In my internal table, my fields are called field1, field2...Etc.

Is it possible to do a loop to fill these fields.

Something like that:

DO wv_i TIMES.

field(wv_i) = wv_i.

ENDDO.

Where the wv_i is the end of the fieldname.

Thanks.

Nicolas.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
542

Hi

You can do it with field symbols.

Try this.

FIELD-SYMBOLS : <fs1> TYPE ANY.

DATA : field1 TYPE i.

DATA : l_char6 TYPE char6,

l_char1 TYPE c.

START-OF-SELECTION.

DO 1 TIMES.

MOVE sy-index TO l_char1.

CONCATENATE 'FIELD' l_char1 INTO l_char6.

ASSIGN (l_char6) TO <fs1>.

<fs1> = 1.

ENDDO.

WRITE : <fs1>.

4 REPLIES 4
Read only

Former Member
0 Likes
543

Hi

You can do it with field symbols.

Try this.

FIELD-SYMBOLS : <fs1> TYPE ANY.

DATA : field1 TYPE i.

DATA : l_char6 TYPE char6,

l_char1 TYPE c.

START-OF-SELECTION.

DO 1 TIMES.

MOVE sy-index TO l_char1.

CONCATENATE 'FIELD' l_char1 INTO l_char6.

ASSIGN (l_char6) TO <fs1>.

<fs1> = 1.

ENDDO.

WRITE : <fs1>.

Read only

0 Likes
542

Hello,

Thank you ganesh.

Your solution works fine!

Thank you to others too even if I didn't test your solutions.

Nicolas.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
542

try this logic.


data:it_string type table of string.
data:wa_string type string.
data:itab_data type table of XYZ.
data:wa_data type xyz.

do.
read dataset file_path into wa_string.
if sy-subrc = 0.
clear it_string[].
split wa_string at *tab* into it_string.
loop at it_string into wa_string.
assign component sy-tabix of structure wa_data to <fs>.
if sy-subrc = 0.
<fs> = wa_string.
endif.
at last.
append wa_data ti itab_data.
endloop.
else.
exit.
endif.

Read only

Former Member
0 Likes
542

Hi,

it can be done, one way of doing it in a performant way is shown here

With kind regards

Uwe Gebhardt