2014 Mar 11 3:02 PM
Hello all,
I am not used to field-symbols and I don't know if it's possible to do.
I need to create a node for a ALV Tree and the hierarchy changes 9 times. So, instead of create 9 loops I want to create a Perform and use the field as parameter.
case 'X'.
when s1.
perform tree_nodes_s1 using 'BEZEI' 'NAME1' 'VTEXT'.
when s2.
perform tree_nodes_s2 using 'BEZEI' 'VTEXT' ''.
.....
In the Form
loop at it_data into wa_data.
if l_field1 is not initial.
on change of field.
perform add_carrid_line using wa_data ''
changing l_carrid_key.
endon.
endif.
So, the field need to be wa_data-bezei or wa_data-name1 or wa_data-vtext etc.
I guess that I saw it on SAP code but I really don't know how to reproduce it.
Thanks,
Andréa
2014 Mar 11 3:06 PM
Hello Andréa,
FIELD-SYMBOLS: <l_field> TYPE ANY.
ASSIGN COMPONENT i_fieldname OF STRUCTURE wa_data TO <l_field>.
CHECK sy-subrc = 0.
Where i_fieldname is an importing parameter containing the field name. After that you can work with <l_field> like it was that field of structure wa_data.
kind regards
Roland
2014 Mar 11 3:06 PM
Hello Andréa,
FIELD-SYMBOLS: <l_field> TYPE ANY.
ASSIGN COMPONENT i_fieldname OF STRUCTURE wa_data TO <l_field>.
CHECK sy-subrc = 0.
Where i_fieldname is an importing parameter containing the field name. After that you can work with <l_field> like it was that field of structure wa_data.
kind regards
Roland
2014 Mar 11 3:25 PM
I did that before and I thought that it was wrong because I got this same error message:
The field "<L_FIELD1>" specified under LIKE either has no type or a generic type. type.
Code
field-symbols: <l_field1> type any.
assign component param1 of structure wa_data to <l_field1>.
check sy-subrc = 0.
loop at it_data into wa_data.
if <l_field1> is not initial.
on change of <l_field1>.
perform add_carrid_line using wa_data ''
changing l_carrid_key.
endon.
endif.
Not sure if I can use it on 'on change of'.
do you know the right type to declare?
Thanks,
Andrea
2014 Mar 11 3:33 PM
No, you cannot use a typeless field symbol like this, since it refers to a single variable, not to a column as in "on change of".
Try something like this:
if <l_field1> is not initial.
if l_string <> <l_field1>.
perform add_carrid_line using wa_data ''
changing l_carrid_key
endif.
l_string = <l_field1>.
endif.
Roland
2014 Mar 11 4:22 PM
2014 Mar 11 4:25 PM
Before the loop the fields are empty of course, you just created a reference. They should be filled within the loop though. (Provided there are values in the first place.)
2014 Mar 11 4:29 PM
Ok.. I thought that it will be like wa_data-bezei and not the value.
Make sense!
Thanks