2009 Jan 28 8:13 PM
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
2009 Jan 28 8:26 PM
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
2009 Jan 28 8:22 PM
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.
2009 Jan 28 8:26 PM
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
2009 Jan 28 8:27 PM
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.