2009 May 13 8:19 AM
Why i can do that?
data gf_v1 type n length 5.
data gr_v1 type ref to data.
start-of-selection.
gf_v1 = 3423.
create data gr_v1 like gf_v1.
gr_v1 = 1111.
break-point.
end-of-selection.
The error message is
The type of GR_V1 cannot converted to the type of "1111".
You use CREATE DATA usually when you don't know the type of the data you are using until run time.
If you are a beginner, leave it for now, and come back to the issue when you've thoroughly learned the basics.
matt
2009 May 13 8:22 AM
Hi,
In order to create data, you need to create a field symbol first and then assign it to field symbol.
Correction in your program:
data gf_v1 type n length 5.
data gr_v1 type ref to data.
FIELD-SYMBOLS <fs> TYPE ANY.
start-of-selection.
gf_v1 = 3423.
create data gr_v1 like gf_v1.
ASSIGN gr_v1->* TO <fs>.
<fs> = 1111.
break-point.
end-of-selection.
2009 May 13 8:27 AM
2009 May 13 8:41 AM
Marty.
Have you read the ABAP documentation on CREATE DATA.
> CREATE DATA gr_v1 LIKE gf_v1.
creates a reference to some data that has the same structure as gf_v1. I.e. a place in memory. gr_v1 refers (or "points to") this place in memory.
To get to the actual value you have to use field symbols in conjunction with the dereferencing operator ->*
> FIELD-SYMBOLS: <fs> TYPE n LENGTH 5.
> ASSIGN gr_v1->* TO <fs>.
> <fs> = 1111.
Are you trying to do something specific, or just understand how CREATE DATA works?
matt
2009 May 13 8:32 AM
HI Marty
change the type of the gf_v1 to integer ( TYPE I )
do like that
data gf_v1 type I.instead of
data gf_v1 type n length 5.it works.
Thanks!
2009 May 13 8:36 AM
2009 May 13 8:37 AM
2009 May 13 9:47 AM
when i reading the abap objects book, i understand what the create data doing.
But when i implementation it, i don't know.........
2009 May 13 10:03 AM
You use CREATE DATA usually when you don't know the type of the data you are using until run time.
If you are a beginner, leave it for now, and come back to the issue when you've thoroughly learned the basics.
matt
2009 May 13 10:15 AM
2009 May 13 10:21 AM
>
> i know, what create data to do, but i can't to use it.
Your initial post shows clearly that you don't fully understand. You've already been given some examples. ( Ignoring the one that's just wrong ).
Last chance:
>create data gr_v1 like gf_v1.
Creates a place in memory with the same shape as the variable gf_v1. gr_v1 then contains a reference to / a pointer to / the address of that place in memory.
Comment out your line "gr_v1 = 1111." and when you get to the debugger, look at the value of gr_v1. You'll see it contains reference data - not numerical character data.
Simply- your program doesn't pass syntax check because you are trying to assign numerical character data to a reference variable. You can only assign references to reference variables.
If doesn't work because you can't assign numeric character data to a reference variable. You can only assign references to reference variables.
As previously stated:
To get to the actual value you have to use field symbols in conjunction with the dereferencing operator ->*
> FIELD-SYMBOLS: <fs> TYPE n LENGTH 5.
> ASSIGN gr_v1->* TO <fs>.
> * <fs> = 1111.*
Do you understand now?
matt
2009 May 13 10:41 AM
aha........ok......
now i try again
data gv_v2 type ref to i.
data gv_type type c length 1 value 'I'.
data gv_v1 type i.
field-symbols <fs> type any.
start-of-selection.
gv_v1 = 1111.
create data gv_v2 type (gv_type).
ASSIGN gv_v2->* to <fs>.
<fs> = gv_v1.
break-point.
end-of-selection.
when i change the value from <fs>, it will be change by gv_v2->* too, but doesn't change by gv_v1
2009 May 13 10:53 AM
That's right. gv_v1 and <fs> are separate objects.
But try this:
data gv_v2 type ref to i.
data gv_type type c length 1 value 'I'.
data gv_v1 type i.
field-symbols <fs> type any.
start-of-selection.
gv_v1 = 1111.
GET REFERENCE OF gv_v1 INTO gv_v2.
ASSIGN gv_v2->* to <fs>.
<fs> = '2222'.
break-point.
2009 May 13 10:55 AM
now, that is it, what i want show you.
data gv_v2 type ref to data.
data gv_type type c length 1 value 'I'.
data gv_v1 type ref to i.
data gv_v3 type i.
field-symbols <fs> type any.
start-of-selection.
gv_v3 = 1111.
create data gv_v1.
gv_v1->* = gv_v3.
create data gv_v2 type (gv_type).
gv_v2 ?= gv_v1.
break-point.
end-of-selection.
by debugging, when i change the value from gv_v1->*, it won't be change by gv_v3. why?
the reference point of the memory from gv_v3, or?
2009 May 13 1:21 PM
| User | Count |
|---|---|
| 6 | |
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |