Application Development 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: 

type and like

Former Member
0 Kudos

1. TYPES : BEGIN OF I_VBAK,

VBELN LIKE VBAK-VBELN,

ERDAT LIKE VBAK-ERDAT,

ERNAM LIKE VBAK-ERNAM,

CHECK_BOX TYPE C,

END OF I_VBAK.

2. TYPES : BEGIN OF I_VBAK,

VBELN type VBAK-VBELN,

ERDAT type VBAK-ERDAT,

ERNAM type VBAK-ERNAM,

CHECK_BOX TYPE C,

END OF I_VBAK.

what makes the diffrence here if I declare with type and like.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

This message was moderated.

7 REPLIES 7

Former Member
0 Kudos

Hi!

In this case, nothing.

There are some restrictions, for example you can't use LIKE in OO environment, and you have to use TYPE keywork for pre-defined TYPES.

Regards

Tamá

Former Member
0 Kudos

Please check

Former Member
0 Kudos

Hi,

In the present case , there is no difference.

But that doesn't means both TYPE and LIKE are same.

refering to SAP HELP

type is used to refer known datatype

REF:

TYPE <type>

to refer to any data type <type> that is already known at this point in the program. It can be used in any of the statements listed below. The expression <obj> is either the name of the data object or the expression

And like for global datatype

LIKE <obj>

can be used in the same ABAP statements as the TYPE addition to refer to any data object <obj> that is already visible at that point in the program. The expression <obj> is either the name of the data object or the expression

hope it will clear the doubt.

Regards,

anirban

Former Member
0 Kudos

This message was moderated.

Former Member
0 Kudos

hi shilpa,

it doesn't make remarkable difference,

but use of LIKE in this way is get obsolute.

it gives error in EXTENDED PROGRAM CHECK (EPC).

ragards,

sandeep

Former Member
0 Kudos

Hi,

In the above case there is no difference .

1.

Like: It is when data object link with the other data

object.

type refers to the user defined data types

like refers to existing data type of data object

2.

TYPE, you assign datatype directly to the data object while declaring.

LIKE,you assign the datatype of another object to the declaring data object. The datatype is referenced indirectly.

3.

Type is a keyword used to refer to a data type whereas Like is a keyword used to copy the existing properties of already existing data object.

4.

type refers the existing data type

like refers the existing data object

Regards,

Sujit

Former Member
0 Kudos

Hi,

TYPE is used while refering to the data types and types declared using types statement, where as LIKE is used to refer to the data objects.

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

TYPE means it is a predefined data type.

But within a program if two variables are defined one using LIKE and another using TYPE, both referring to the same field, then there is no difference.

If I include a type pool within a program, then I can define my variables only using TYPE to refer to any type defined in that pool. I cannot use LIKE in this scenario. Also, if I want to use native types like C, N, etc, I cannot use LIKE there either. I can use LIKE ABC only if ABC is in the database or if ABC is defined previously in the same program.

I can use TYPE ABC, if ABC is defined in database as a TYPE and included in the program with the statement TYPE-POOLS. I can use it, if it is the native types. I can use it, if it is already defined in the dictionary as a structure/table or structure/table field, or even if it is defined as a data element or a domain. So I can declare a variable V_BUKRS TYPE BUKRS, but I cannot define a variable V_BUKRS LIKE BUKRS.

But if I intend to use V_BUKRS to store company code, I will prefer to declare it as V_BUKRS LIKE T001-BUKRS, only because if tomorrow for some reason, the definition of T001-BUKRS changes to a data element for example, BUKRS_N(say DEC 4) instead of the data element BUKRS(CHAR 4) that it refers to now, I don't have to change my programs because I am referring to the table field and inhereting its properties. Whereas, had I declared my V_BUKRS TYPE BUKRS and the table now changed to BUKRS_N, I will be forced to change my program as there will be a type incompatability.

hope this is useful.

plz reward if useful.

thanks,

dhanashri.