Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Create data

Former Member
0 Likes
1,270

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".

14 REPLIES 14
Read only

Former Member
0 Likes
1,241

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.

Read only

Former Member
0 Likes
1,241

i haven't understand..

can you write in my code...

Read only

matt
Active Contributor
0 Likes
1,241

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

Read only

Former Member
0 Likes
1,241

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!

Read only

matt
Active Contributor
0 Likes
1,241

>

> it works.

No it doesn't.

Read only

Former Member
0 Likes
1,241

This message was moderated.

Read only

Former Member
0 Likes
1,241

when i reading the abap objects book, i understand what the create data doing.

But when i implementation it, i don't know.........

Read only

matt
Active Contributor
0 Likes
1,241

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

Read only

Former Member
0 Likes
1,241

i know, what create data to do, but i can't to use it.

Read only

matt
Active Contributor
0 Likes
1,241

>

> 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

Read only

Former Member
0 Likes
1,241

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

Read only

matt
Active Contributor
0 Likes
1,241

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.

Read only

Former Member
0 Likes
1,241

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?

Read only

Former Member
0 Likes
1,241

Is gv_v1 new variabl?