‎2012 Jun 28 9:36 AM
Hi experts,
Please see the below code:
FIELD-SYMBOLS :
<fs_selval> TYPE c.
DATA:
l_selfld(40) TYPE c.
l_selfld = 'KOMG-VGPOS'.
ASSIGN (l_selfld) TO <fs_selval>.
On running, I got the above mentioned dump.
Questions:
1) VGPOS is of type NUMC, which caused the error. How can this compatibility issue be resolved?
2) Why is ASSIGN (l_selfld) used instead of ASSIGN l_selfld {without the brackets}...?
Regards,
Peter
‎2012 Jun 28 10:06 AM
1) Declare field symbol as
FIELD-SYMBOLS :
<fs_selval> TYPE any.
2) Brackets denote the value of the variable. Without brackets it directly assigns the variable to field symbol. Try doing both and check the difference in debugger
‎2012 Jun 28 10:06 AM
1) Declare field symbol as
FIELD-SYMBOLS :
<fs_selval> TYPE any.
2) Brackets denote the value of the variable. Without brackets it directly assigns the variable to field symbol. Try doing both and check the difference in debugger
‎2012 Jun 28 10:32 AM
Hi Chinmay,
Thanks for the response.
Why is it that TYPE ANY is not recommended way of declaring?
Also can we declare field symbol without giving any type?
Thanks again,
peter
‎2012 Jun 28 11:59 AM
Hi Peter,
Type Any is generic type which determine at runtime. In this case Type Any has little bit slow performance wise comparatively with typed statement.
But in case of dynamic programing we don't know the type at the time of declaration.
Kind Regards
Ravi Lanjewar
‎2012 Jun 28 1:11 PM
Hello Peter,
I don't agree with Chinmay's suggestion to use TYPE ANY - it's half correct!
In your case you know the type of the data object whose memory address you want to assign & so TYPE ANY is not required.
You can use the CASTING addition of the ASSIGN statement to make your code work:
DATA: gv_numc TYPE vgpos VALUE 1.
FIELD-SYMBOLS: <gv_char> TYPE c.
* Cast the numeric type to a character field
ASSIGN ('GV_NUMC') TO <gv_char> CASTING.
IF <gv_char> IS ASSIGNED.
WRITE: 'Numeric Value:' , 20 gv_numc,
/ 'Character Value:' , 20 <gv_char>.
ENDIF.In an Unicode(UC) environment data objects of TYPE c, n, d, t are referred to as character-like data types. Each character in the data object is represented by 2 bytes (in UC systems the system code page is UTF-16 ) - hence you will not face any conversion issues when assigning the memory address.
Try CASTING non character-type data objects (TYPE p, i, f) to a character-type field symbol.
BR,
Suhas
Message was edited by: Suhas Saha