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

Data type problem..

Former Member
0 Likes
569

Dear All,

When learning abap i encountered a strange situation . Consider the program below.

Report ztest.
  data : BEGIN OF stru,
          du  type c LENGTH 10,
          du2 type c LENGTH 12,
         END OF stru.
 data stru1 type stru.
     stru-du = '12345678'.
    stru-du2 = '9999999'.
    stru1 = stru.
 

If i put breakpoint and look at the data type of stru1 it is N(10) and the absolute type(?) is '\TYPE=STRU' the value in stru1 is '6789999999' . Can anyone pls explain why data type of stru1 is N(10) .I am aware that like should have been used if i wanted stru1 data type similar to that of stru.

Thanks,

Kiran A.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
516

Hello Kiran,

DATA : BEGIN OF stru,

du TYPE c LENGTH 10,

du2 TYPE c LENGTH 12,

END OF stru.

data stru1 type stru.

here stru1 is defined from standard data element (STRU) Structure Description, not from your structure declaration of stru,

if you want to do so you need to declare using TYPES not data, then your code will go like this,

types : BEGIN OF stru,

du TYPE c LENGTH 10,

du2 TYPE c LENGTH 12,

END OF stru.

DATA stru1 TYPE stru.

DATA stru2 TYPE stru.

stru1-du = '12345678'.

stru1-du2 = '9999999'.

stru2 = stru1.

thanks,

Swanand Paranjape.

3 REPLIES 3
Read only

Former Member
0 Likes
517

Hello Kiran,

DATA : BEGIN OF stru,

du TYPE c LENGTH 10,

du2 TYPE c LENGTH 12,

END OF stru.

data stru1 type stru.

here stru1 is defined from standard data element (STRU) Structure Description, not from your structure declaration of stru,

if you want to do so you need to declare using TYPES not data, then your code will go like this,

types : BEGIN OF stru,

du TYPE c LENGTH 10,

du2 TYPE c LENGTH 12,

END OF stru.

DATA stru1 TYPE stru.

DATA stru2 TYPE stru.

stru1-du = '12345678'.

stru1-du2 = '9999999'.

stru2 = stru1.

thanks,

Swanand Paranjape.

Read only

Former Member
0 Likes
516

Hi Akiran,

There is already a built-in type stru in SAP system whose datatype is NUMC(10).You can check it by TCode SE11 and select the radio button and write stru in the DATA TYPE field.

For that reason when you are defining stru1 TYPE stru the stru1 is created with datatype numc(10) or N(10) as technical type.Instead of that you declare DATA:stru1 LIKE stru.

Regards,

Suvajit.

Read only

Former Member
0 Likes
516

thanks for the reply..