2012 Feb 13 9:42 AM
Hello experts,
I have a structure with two fields, one string as name/ID and the second one REF TO DATA as placeholder for any value, so DATA can take for example another string or a numeric value or whatever. Ok, now I want to handle this DATA based on it's type, which is unknown at that point. So I first DESCRIBE the field (its type). If for example this type results in a string, I want to move this string data from REF TO DATA into a local string value. Then I want to reformat the string value and save it again to the REF TO DATA field.
So, in short, I have these tasks:
1. determine type of REF TO DATA
2a. if it's a string, then move the val. of the string into a local string variable
2b. or alternatively do something else, if it's not a string value
3. do something with the local string, then save it back to the REF TO DATA field
Any ideas?
Thank in advance for your help!
Kind regards, Matthias
2012 Feb 13 9:56 AM
Hi,
U can use field symbols for doing this.It will help you solve this problem.
regards
Karthik.R
2012 Feb 13 9:56 AM
Hi,
U can use field symbols for doing this.It will help you solve this problem.
regards
Karthik.R
2012 Feb 13 10:07 AM
Sorry, I don't understand how field symbols could solve my problem.
Can you please be a bit more specific, maybe with some sample code?
2012 Feb 13 10:14 AM
Take a look at this piece of code. I think it's quite easy to understand how this works.
REPORT ztest.
DATA: data TYPE REF TO data,
string TYPE string,
i TYPE i.
FIELD-SYMBOLS: <FS>.
TYPES: BEGIN OF tipo,
string TYPE string,
data TYPE REF TO data.
TYPES: END OF tipo.
DATA: var TYPE tipo.
VAR-STRING = 'HOLA'.
STRING = 'ADIOS'.
GET REFERENCE OF STRING INTO DATA.
VAR-DATA = DATA.
*VAR-STRING = 'HOLA'.
*I = 12.
*GET REFERENCE OF I INTO DATA.
*VAR-DATA = DATA.
ASSIGN VAR-DATA->* TO <FS>.
DATA: peo_structdescr TYPE REF TO cl_abap_typedescr.
peo_structdescr ?= cl_abap_datadescr=>describe_by_data( <FS> ).
CASE peo_structdescr->type_kind.
WHEN 'I'.
WHEN 'C'.
WHEN 'g'.
ENDCASE.
2012 Feb 13 2:34 PM
Hello Jose,
that does not seem to work, as the following code gives me 'l' as output (where it should be 'g'):
DATA lr_typedesc TYPE REF TO cl_abap_typedescr.
DATA ls_rec TYPE zats_ano_field_name_value.
FIELD-SYMBOLS <fs> TYPE any.
GET REFERENCE OF 'test' INTO ls_rec-value.
ASSIGN ls_rec-value TO <fs>.
lr_typedesc ?= cl_abap_datadescr=>describe_by_data( <fs> ).
WRITE: / lr_typedesc->type_kind.
Any ideas?
2012 Feb 13 9:51 PM
Hi Matthias
I think you missed a little and very important detail here:
ASSIGN ls_rec-value TO <fs>.
That's not what we want, instead you need to use:
ASSIGN ls_rec-value->* TO <fs>.
That's why you are obtaining this type 'l' which is refering to a TYPE REF TO DATA itself. Doing it the right way your final type would be 'C' which corresponds with a character data type.
Best Regards
2012 Feb 15 8:34 AM
2012 Feb 13 10:23 AM
Hi
Actually by using field symbols u can refer to the data u want.
Follow this link:
[http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb387a358411d1829f0000e829fbfe/content.htm]
Regards,
Karthik.R