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

What's difference between the following two structure declaration?

Former Member
0 Likes
1,463

Hi,

I am new to SAP ABAP/4 programming.

I declared the structure,

DATA: BEGIN OF DATA_ITEM,

CARRID LIKE SPFLI-CARRID,

CONNID LIKE SPFLI-CONNID,

END OF DATA_ITEM.

but I read some material,its declaration is

DATA: BEGIN OF DATA_ITEM,

CARRID TYPE SPFLI-CARRID,

CONNID TYPE SPFLI-CONNID,

END OF DATA_ITEM.

I don't know why?

Hi,

I am new to SAP ABAP/4 programming.

I declared the structure,

DATA: BEGIN OF DATA_ITEM,

CARRID LIKE SPFLI-CARRID,

CONNID LIKE SPFLI-CONNID,

END OF DATA_ITEM.

but I read some material,its declaration is

DATA: BEGIN OF DATA_ITEM,

CARRID TYPE SPFLI-CARRID,

CONNID TYPE SPFLI-CONNID,

END OF DATA_ITEM.

I don't know why?

9 REPLIES 9
Read only

Former Member
0 Likes
1,401

Hi,

If you are using Object Oriented programming with classes use TYPE declaration, if you are using normal programming use LIKE.

Newer versions of SAP are classes so better to start your programming with TYPE declaration.

Regards

Subramanian

Read only

Former Member
0 Likes
1,401

Hi xin chen,

No difference. But "LIKE" is an obsolete word after ABAP 4.6C. "Type" is suggested to use by SAP.

Julian

Read only

Former Member
0 Likes
1,401

Hi

DATA - TYPE, LIKE

Syntax

DATA dobj { {TYPE [LINE OF] type}

| {LIKE [LINE OF] dobj} }

[VALUE val|{IS INITIAL}]

[READ-ONLY].

Effect

In the specification of a data type type or a data object dobj, the data type of the variable dobj is already fully defined before the declaration. The syntax and meaning of the additions TYPE and LIKE has exactly the same meaning as the definition of data types with TYPES, except that for DATA after TYPE a standard table type with a generic table key can be specified. In this case, a bound table type with a standard key is created.

Prior to Release 6.10, no VALUE addition was possible if the data type deep, specified using TYPE or LIKE, was a string, a reference type, a table type, or a structured type with deep components. As of Release 6.10, the VALUE addition can also be used for deep data types; however, with the limitation that a start value val can only be specified for the ABAP type string, and otherwise only IS INITIAL.

Example

These statements define two data objects, both of which have the same data type as the database table spfli.

DATA: spfli_wa1 TYPE spfli,

spfli_wa2 LIKE spfli_wa1.

Thanks.

Read only

Former Member
0 Likes
1,401

The above declared structures hold the same meaning. However, the basic difference between TYPE and LIKE is... TYPE refers to existing data type and LIKE refers to existing data object.

For e.g.:

data: var1 type i.

data: var2 like var1.

Here, var1 refers to existing data type i.e. i.

var2 refers to existing data object i.e. var1

Thanks,

Santosh

Read only

Former Member
0 Likes
1,401

hi

good

there only the difference between LIKE and TYPE statement

LIKE->

LIKE Use an existing field as a reference

TYPE->Creates a new type with the name type. If you do nont use the TYPE addition, the new type has the default type C.

thanks

mrutyun^

Read only

Former Member
0 Likes
1,401

Actually

Correct typeing is:

DATA: BEGIN OF DATA_ITEM,

CARRID TYPE S_CARR_ID,

CONNID TYPE S_CONN_ID,

END OF DATA_ITEM.

<b>not</b>

DATA: BEGIN OF DATA_ITEM,

CARRID TYPE SPFLI-CARRID,

CONNID TYPE SPFLI-CONNID,

END OF DATA_ITEM.

TYPE is not interchangable with LIKE.

Regards

Gareth

Read only

Former Member
0 Likes
1,401

Thanks for response.

But in this case why SPFLI-CARRID can not only act as data type but also data object?

Read only

0 Likes
1,401

Hi

DATA: BEGIN OF DATA_ITEM,
             CARRID LIKE SPFLI-CARRID,
             CONNID LIKE SPFLI-CONNID,
           END OF DATA_ITEM.

DATA: BEGIN OF DATA_ITEM,
              CARRID TYPE SPFLI-CARRID,
              CONNID TYPE SPFLI-CONNID,
           END OF DATA_ITEM.

These two definations are the same in ABAP 4 language, there isn't a really difference, just as many guys have said to you before.

From release 4.6A the ABAP OBJECT (ABAP OBJECT ORIENTED PROGRAMMING) language was introducted as extension of ABAP. In the ABAP OBJECT only TYPE statament can be used to define the variables, so a declaration like:

DATA: BEGIN OF DATA_ITEM,
             CARRID LIKE SPFLI-CARRID,
             CONNID LIKE SPFLI-CONNID,
           END OF DATA_ITEM

it's not allowed.

ABAP and ABAP OBJECT are two way of programming.

Max

Read only

Former Member
0 Likes
1,401

Thanks very much.

I will learn ABAP OBJECTS.