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: 

Field symbols dynamic assigning

Former Member
0 Kudos
3,684

Hi,

I have a problem when dynamicly assigning into a field symbol.

This is my code:

data: field type char100 value 'ITAB[&]-FIELD',

lv_tab type char1.

do 10 times.

itab-field = 6.

append itab.

enddo.

loop at itab.

lv_tab = sy-tabix.

condense lv_tab no-gaps.

replace '&' into field with lv_tab.

assign (field) to <fs>.----


> this is where i get the error: sy-subrc = 4

<fs> = 9.

unassign <fs>.

endloop.

Any helpful answer would be appreciated.

Regards,

Roberto

1 ACCEPTED SOLUTION

naimesh_patel
Active Contributor
0 Kudos
532

You don't have to give the ROW number in the field name when you try to assign it to field symbol.

Actually, it you have to put the value in that field, which you are trying to assign to the Field Symbol. It is better to use explicit work area instead of the headre line of the table.


data: wa_itab like line of itab.  " << Work area

data: field type char100 value 'WA_ITAB-FIELD',   "field name
lv_tab type char1.

do 10 times.
itab-field = 6.
append itab.
enddo.

loop at itab into wa_itab.
assign (field) to <fs>.
<fs> = 9.
unassign <fs>.
endloop.

Regards,

Naimesh Patel

3 REPLIES 3

Former Member
0 Kudos
532

Hi,

loop at itab.
lv_tab = sy-tabix.
condense lv_tab no-gaps.
replace '&' into field with lv_tab.
assign (field) to <fs>.------------------------------> this is where i get the error: sy-subrc = 4
<fs> = 9.
unassign <fs>.
endloop.

'

As per the above there should exist field declaration for ITAB1-FIELD, ITAB2-FIELD etc.. because you are replacing the & with sy-tabix of the loop and assing the value to derived field. The declaration for these fields should exist in the program.

naimesh_patel
Active Contributor
0 Kudos
533

You don't have to give the ROW number in the field name when you try to assign it to field symbol.

Actually, it you have to put the value in that field, which you are trying to assign to the Field Symbol. It is better to use explicit work area instead of the headre line of the table.


data: wa_itab like line of itab.  " << Work area

data: field type char100 value 'WA_ITAB-FIELD',   "field name
lv_tab type char1.

do 10 times.
itab-field = 6.
append itab.
enddo.

loop at itab into wa_itab.
assign (field) to <fs>.
<fs> = 9.
unassign <fs>.
endloop.

Regards,

Naimesh Patel

former_member156446
Active Contributor
0 Kudos
532

I could not understand your req.. but as per my understanding...

FIELD-SYMBOLS: <fs> TYPE ANY.

DATA: field1 TYPE char100 VALUE 'ITAB&-FIELD',
        field TYPE char100,

lv_tab TYPE char1.

DO 10 TIMES.
  itab-field = 6.
  APPEND itab.
ENDDO.

LOOP AT itab.
  field = field1.
  lv_tab = sy-tabix.
  CONDENSE lv_tab NO-GAPS.
  REPLACE '&' IN field WITH lv_tab.
  ASSIGN field TO <fs>.

ENDLOOP.