2015 Jun 18 7:15 AM
Ok I'll admit it - my ABAP is a little rusty but I can usually get by.
However I've tried about 15 options on this one and I can't seem to crack it.
I am trying to derefence a generic reference to a typed structure as follows:
So there is a type
E.g.
TYPES: begin of mytype,
number type decimal,
currency type c(5),
end of mytype.
DATA:
ls_mydata TYPE mytype,
lr_struc TYPE REF TO DATA.
FIELD-SYMBOLS:
<fs_mydata> TYPE mydata.
So lr_struc is correctly holding a generic reference to a structure of type mytype.
However if I try to do something like this:
ASSIGN lr_struc->* TO <fs_mydata>.
I get short dumps and move cast errors saying that the source and target types don't match. Except I can see in the debugger that they do absolutely match in every respect and I can see the data in them without problem.
So far I have tried various combinations of CAST, ASSIGN, ASSIGN... CASTING but no go.
All the examples I have found so far use examples that are only simple variables... not structures.
What I'm trying to do is read the value of number and currency that are held in the reference.
What am I doing wrong... ?
2015 Jun 18 8:24 AM
Hi Jocelyn,
I tried your code and in my system it worked without any problem.
The only thing I had to do was to change
<fs_mydata> TYPE mydata.
to
<fs_mydata> TYPE mytype.
However, I'm unsure if this was only a typo introduced when creating the blog post. Here is the code I used:
REPORT zcd_test.
TYPES: BEGIN OF mytype,
number TYPE decfloat16,
currency TYPE char5,
END OF mytype.
DATA:
ls_mydata TYPE mytype,
lr_struc TYPE REF TO data.
FIELD-SYMBOLS:
<fs_mydata> TYPE mytype.
ASSIGN lr_struc->* TO <fs_mydata>.
BREAK-POINT.
When the break point is reached <fs_mydata> isn't assigned to anything as lr_struc hasn't been created so far. When I change the code to the foillowing:
REPORT zcd_test.
TYPES: BEGIN OF mytype,
number TYPE decfloat16,
currency TYPE char5,
END OF mytype.
DATA:
ls_mydata TYPE mytype,
lr_struc TYPE REF TO data.
FIELD-SYMBOLS:
<fs_mydata> TYPE mytype.
CREATE DATA lr_struc TYPE mytype.
ASSIGN lr_struc->* TO <fs_mydata>.
BREAK-POINT.
<fs_mydata> is also assigned when the breakpoint is reached.
Hope this helps.
Christian
Ok I'll admit it - my ABAP is a little rusty but I can usually get by.
However I've tried about 15 options on this one and I can't seem to crack it.
I am trying to derefence a generic reference to a typed structure as follows:
So there is a type
E.g.
TYPES: begin of mytype,
number type decimal,
currency type c(5),
end of mytype.
DATA:
ls_mydata TYPE mytype,
lr_struc TYPE REF TO DATA.
FIELD-SYMBOLS:
<fs_mydata> TYPE mydata.
So lr_struc is correctly holding a generic reference to a structure of type mytype.
However if I try to do something like this:
ASSIGN lr_struc->* TO <fs_mydata>.
I get short dumps and move cast errors saying that the source and target types don't match. Except I can see in the debugger that they do absolutely match in every respect and I can see the data in them without problem.
So far I have tried various combinations of CAST, ASSIGN, ASSIGN... CASTING but no go.
All the examples I have found so far use examples that are only simple variables... not structures.
What I'm trying to do is read the value of number and currency that are held in the reference.
What am I doing wrong... ?
2015 Jun 18 8:11 AM
Hi Jocelyn,
you may need to call this statement before assigning it to field symbol?
CREATE DATA lr_struc TYPE mydata.
Thanks,
Sharath
2015 Jun 18 8:21 AM
2015 Jun 18 8:24 AM
Hi Jocelyn,
I tried your code and in my system it worked without any problem.
The only thing I had to do was to change
<fs_mydata> TYPE mydata.
to
<fs_mydata> TYPE mytype.
However, I'm unsure if this was only a typo introduced when creating the blog post. Here is the code I used:
REPORT zcd_test.
TYPES: BEGIN OF mytype,
number TYPE decfloat16,
currency TYPE char5,
END OF mytype.
DATA:
ls_mydata TYPE mytype,
lr_struc TYPE REF TO data.
FIELD-SYMBOLS:
<fs_mydata> TYPE mytype.
ASSIGN lr_struc->* TO <fs_mydata>.
BREAK-POINT.
When the break point is reached <fs_mydata> isn't assigned to anything as lr_struc hasn't been created so far. When I change the code to the foillowing:
REPORT zcd_test.
TYPES: BEGIN OF mytype,
number TYPE decfloat16,
currency TYPE char5,
END OF mytype.
DATA:
ls_mydata TYPE mytype,
lr_struc TYPE REF TO data.
FIELD-SYMBOLS:
<fs_mydata> TYPE mytype.
CREATE DATA lr_struc TYPE mytype.
ASSIGN lr_struc->* TO <fs_mydata>.
BREAK-POINT.
<fs_mydata> is also assigned when the breakpoint is reached.
Hope this helps.
Christian
2015 Jun 25 1:00 PM
Thanks folks... that was very helpful.
Yes you were correct I was one reference away from success.
The answer in the end was something closer to this which is very similar to Christian's answer.
lr_struc = REF #( ls_source_struc_ref ).
ASSIGN lr_struc->* TO <fs_struc>.
ls_mydata = CAST mytype( <fs_struc> )->*.
It's been a rough ride getting used to the new dereferencing approaches - so really appreciate being thrown a couple of lifelines to get me thinking harder.
Thanks all!
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |