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: 

why we use like in parameters and why not type

Former Member
0 Kudos

hi

could anybody inform me

what is the difference between like and type while using parameters .

thanx

kals.

6 REPLIES 6

former_member181962
Active Contributor
0 Kudos

Hi Kalyan,

YOu CAN use TYPE in Parameters. Search the forum for generic questions.

Regards,

ravi

Former Member
0 Kudos

Hello Kalyan,

Uc an also use TYPE.

Check this:

PARAMETERS: P_WERKS TYPE MARC-WERKS OBLIGATORY,

If useful reward.

Vasanth

Former Member
0 Kudos

hi,

TYPE type

Effect

The field in the program has the type type.

Example

PARAMETERS: NUMBER(4) TYPE P DEFAULT 999.

LIKE g

Effect

Creates the field p with the same attributes as the field g, which has already been declared. g can be an ABAP Dictionary field, or a field in the program that has already been declared.

Note

You cannot use the LIKE g and TYPE type additions together. Neither can you specify an explicit length (so, for example, PARAMETERS p(len) LIKE g is not allowed).

Example

PARAMETERS PROGRAM LIKE SY-REPID.

Notes

If g is an ABAP Dictionary field with type CHAR, length 1, and fixed values 'X' and ' ' (defined in its domain), the parameter is always displayed as a checkbox on the selection screen (see also the AS CHECKBOX addition).

Field attributes on the selection screen:

The input/output fields on the selection screen have the same attributes as the field g in the LIKE addition (that is, the same type, length, and in the case of ABAP Dictionary fields, the same conversion exit.

If g is an ABAP Dictionary field, most of its field attributes are updated automatically if you change them in the Dictionary. The exceptions to this are the "Check table" and "Fixed values" attributes. If these change, you must reactivate the program in the ABAP Workbench. The selection screen is then automatically regenerated.

PARAMETERS may not have a deep type. This applies to both the TYPE and LIKE additions.

Parameters are displayed on the selection screen up to 45 characters long (scrollable to 132 charactrs). If you define a longer field, either explicitly (like p(200)) or implicitly (using LIKE), the parameter is truncated after the 132nd character on the selection screeen. However, in the SUBMIT statement, you can pass longer paraemters to an executable program if they have been excluded from the selection screen using the NO-DISPLAY addition. If you do not use NO-DISPLAY, the parameter is still truncated, even if you run the program without displaying the selection screen (seeSUBMIT without the VIA SELECTION-SCREEN addition).

Regards,

Sruthi

Former Member
0 Kudos

Hi,

Like - is for whole structure it will take, ex. Name like Kunnr. means name field contains the kunnr field structure.

Type - is for specific for data types, ex. Name type C. means Name field has character data type.

Regards,

Bhaskar

if satisfy reward me

Former Member
0 Kudos

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.

... TYPE type

Effect

The field f is created with type type. For the type, you can specify either one of the predefined types listed below, a type defined using the TYPES statement, or a type created in the ABAP Dictionary.

The standard length ( SL ) of a field depends on its type.

Type Explanation SL Initial value

C Text (Character) 1 space

N Numeric text 1 '00...0'

D Date (YYYYMMDD) 8 '00000000'

T Time (HHMMSS) 6 '000000'

X Hexadecimal (HeX code) 1 X'00'

I Integer 4 0

P Packed number 8 0

F Floating point number 8 0

STRING Character sequence (string) variable-length empty string

XSTRING Byte sequence (X string)

variable-length empty hexadecimal string

Example

DATA NUMBER TYPE I.

DATA WA_SPFLI TYPE SPFLI.

The field NUMBER is created with type I. You can now use it in the program. In particular, you can assign numeric values to the field and use it in calculations ( ABAP number types).

The field WA_SPFLI is created using the type of the database table SPFLI from the ABAP Dictionary. This field is structured and can be used especially for working with data from database table SPFLI.

... LIKE f1

The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas.

See Cannot Use LIKE References to Dictionary Types.

Effect

Field f is created with the same field attribtues as the data object f1, which has already been declared. Any data object (field, parameter, structure...) is allowed as long as its type has been fully specified.

f1 can be any ABAP Dictionary reference.

Example

DATA TABLE_INDEX LIKE SY-TABIX.

The field TABLE_INDEX now has the same attributes as SY-TABIX (index field for internal tables).

Note

You should use this addition whenever you can. If the type of a field to which you are referring changes, the ABAP runtime system updates all references automatically. It also stops the system from carrying out unnecessry (and maybe undesirable) type conversions

Check these

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

For TYPE

http://help.sap.com/saphelp_47x200/helpdata/en/d3/2e974d35c511d1829f0000e829fbfe/frameset.htm

For LIKE

http://help.sap.com/saphelp_47x200/helpdata/en/d3/2e974d35c511d1829f0000e829fbfe/frameset.htm

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

Regards,

Saumya

Former Member
0 Kudos

The Basic difference between TYPE and LIKE goes like this .

1) TYPE takes the data dictionary definition of a Data Element / an Elemental type ( e.g TYPE C ) as the Basis for Data Declaration .

LIKE takes the Data Dictioanary definition of a table field as the Basis for the data declaration .

In most practical terms this makes very little difference when actually using the variable defined. However, there are circumstances (e.g. in ABAP OO) where you cannot use the LIKE <table-field> statement in order to define variables.

2) b) From Memory Consumption Point of View we should Use TYPE than LIKE . The TYPE addition should be the only construction that allows a reference to data types, while the LIKE addition should only be used for data objects . The Repository objects in the ABAP Dictionary are data types, not data objects. Outside the ABAP Objects context, the LIKE reference to database tables and flat structures in the ABAP Dictionary is still allowed for compatibility reasons.The LIKEreference can only be used for local data objects

3) c) when u declare a variable using "LIKE", then ur variable will be becoming the exact mirror image as that of the specified variable in the LIKE statement. the most imp thing is , when u use the LIKE statement, u inherit also the TECHNICAL Attributes of the variable.But whereas in the case of TYPE u can overwrite the technical attributes...

For Eg:

Data: a like MARA-matnr,

Data: c type MARA-matnr.

4) d the like statement creates a variable statically ie the memory is allocated before runtime .where as when u declare a variable by type no memorary is allocated but it just refers to the variable and the m omory is allocated only at runtime

5) e) I've just browsed the ABAP manual and noticed the only difference between LIKE and TYPE: you cannot use LIKE addition in ABAP Objects context (e.g. METHODS declaration and attributes declatation) with reference to ABAP Dictionary objects. So, you can do this:

Give Reward points if it is useful .

Thanks

RM