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

like and type

Former Member
0 Likes
419

what is thye exact difference between type and like...

thanks

what is thye exact difference between type and like...

thanks

2 REPLIES 2
Read only

Former Member
0 Likes
388

<u>TYPE:</u>

You use the TYPE addition in various ABAP statements for defining data types and specifying

the types of interface parameters or field symbols. The TYPE addition can have various

meanings depending on the syntax and context.

Examples:

ABAP Statements with TYPE References

\ Definition of local program types using

TYPES <t> TYPE <type>.

The new data type <t> has the same type as <type>.

Declaration of data objects using

DATA <f> TYPE <type>.

CLASS-DATA <f> TYPE <type>.

CONSTANTS <f> TYPE <type>.

STATICS <f> TYPE <type>.

PARAMETERS <f> TYPE <type>.

The data object <f> has a data type corresponding to the type <type>.

Dynamic creation of data objects using

CREATE DATA <dref> TYPE <type>.

Specification of the type of a formal parameter in a subroutine using

FORM <sub> ... USING|CHANGING <p> TYPE <type> ...

The technical attributes of the formal parameter <p> are inherited from those of the

declared data type <type>. You can then only pass actual parameters that have these

attributes.

Specification of the type of a formal parameter in a method using

METHODS <meth> ... IMPORTING|EXPORTING|CHANGING <p> TYPE <type>

The technical attributes of the formal parameter <p> are inherited from those of the

declared data type <type>. You can then only pass actual parameters that have these

attributes.

Specification of the type of a field symbol

FIELD-SYMBOLS <fs> TYPE <type>.

The technical attributes of the field symbol <FS> are inherited from those of the declared

data type <type>. You can then only pass actual parameters that have these attributes.

<u>LIKE</u>

You use the LIKE addition, similarly to the TYPE addition, in various ABAP statements for

defining data types and specifying the types of interface parameters or field symbols.

Examples:

ABAP Statements with LIKE References

Definition of local types in a program using

TYPES <t> LIKE <obj>.

The new data type <t> inherits all of the technical attributes of the data object <obj>.

Declaration of data objects using

DATA <f> LIKE <obj>.

CLASS-DATA <f> LIKE <obj>.

CONSTANTS <f> LIKE <obj>.

STATICS <f> LIKE <obj>.

PARAMETERS <f> LIKE <obj>.

The data object <f> inherits all of the technical attributes of the data object <obj>.

Dynamic creation of data objects using

CREATE DATA <dref> LIKE <obj>.

Specification of the type of a formal parameter in a subroutine using

FORM <sub> ... USING|CHANGING <p> LIKE <obj> ...

The technical attributes of the formal parameter <p> are inherited from those of the

declared data object <obj>. You can then only pass actual parameters that have these

attributes.

Specification of the type of a formal parameter in a method using

METHODS <meth> ... IMPORTING|EXPORTING|CHANGING <p> LIKE <obj> ...

The technical attributes of the formal parameter <p> are inherited from those of the

declared data type <type>. You can then only pass actual parameters that have these

attributes.

Read only

Former Member
0 Likes
388

Have a look at below links:

http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb367a358411d1829f0000e829fbfe/content.htm

http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb2ff3358411d1829f0000e829fbfe/frameset.htm

If you use the addition TYPE, you can either reference to an inbuilt ABAP type, a predefined elementary type in the local program, or to a data element defined in the ABAP Dictionary.

If you use a LIKE reference, dobj can be an existing data object with an elementary data type. If you do not use the TYPE or LIKE addition, the system uses the default predefined type c.

In other words, 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...

When you take reference of objects that occupies memory ( data elements, variables decalared with DATA) then use LIKE and when you are taking ref. to a elementry data types(C,I,D,T...) or to a variables declared with TYPES statement then we use TYPE

I hope it helps.

Best Regards,

Vibha

One Request for you Abhay: <b>Please mark all the helpful answers</b>