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

Doubt in Basic ABAP.

Former Member
0 Likes
539

Hi Gurus,

I have a small doubt in basic ABAP.

What is the exact difference between the below statements.

Types: Begin of ty_data,

matnr type mara-matnr,

end of ty_data.

Types: Begin of ty_data,

matnr type matnr,

end of ty_data.

Types: Begin of ty_data,

matnr like mara-matnr,

end of ty_data.

Types: Begin of ty_data,

matnr like matnr,

end of ty_data.

data: matnr type mara-matnr.

data: matnr type matnr

data: matnr like mara-matnr

data: matnr like matnr.

In those above statement which are correct. And the difference between those statements.

Thanks,

Srihari.

4 REPLIES 4
Read only

Former Member
0 Likes
507

Hi,

All these below give you the same thing. IT basically a declaration for a structure type which can be used as type for internal table. However its better to use TYPE instead of LIKE according the latest conventions and also TYPE is acceptable in OO ABAP as against LIKE.


Types: Begin of ty_data,
matnr type mara-matnr,
end of ty_data.

Types: Begin of ty_data,
matnr type matnr,
end of ty_data.

Types: Begin of ty_data,
matnr like mara-matnr,
end of ty_data.

Same is the case for the declaration as given below which declares varaibles of type matnr i.e material number.


data: matnr type mara-matnr.

data: matnr type matnr

data: matnr like mara-matnr

data: matnr like matnr.

Regards,

Mansi.

Read only

Former Member
0 Likes
507

hi

type refers the existing data type

like refers the existing data object

hope it will help u .

Read only

Former Member
0 Likes
507

hi,

LIKE means the datatype of the variable is similar to the referenced variable.

TYPE means it is a predefined data type.

Eg:

DATA int TYPE i.

Here int is of integer data type.

DATA var LIKE int.

var IS a variable having same data type of int. which in turn is integer.

You can find these helpful when you reference database table variables... You need not know what is the datatype defined.

Also it adds to FLEXIBILITY.

Whenever you make changes to your database tables and fields,

that change is REFLECTED back to your program that is,

You need not change all your program code when you change your table fields...

Hope you understand and appreciate the flexibility that SAP provides to the programmers...

Thanks

Arun

Read only

Former Member
0 Likes
507

Hi,

data: matnr type matnr.

Here you define matnr variable type matnr(data type) .

Matnr is a standard data element contains Data Type ' CHAR ' and Length ' 18 ' .

data: matnr like mara-matnr

here you are defining matnr variable which contain all the technical attributes of mara-matnr.

here you are giving data type to matnr w.r.t mara-matnr.

Regards,

Himanshu