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: 

Answer my question

Former Member
0 Kudos

Difference between Like and TYPE in ABAP.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Use like when there is an existing data type and you want to refer to the existing one.

EXAMPLE : TYPES char1 type C

(Has to be a field from the ABAP dictionary)

EXAMPLE : TYPES char2 LIKE char1

(NOTE : Here we can have ABAP dictionary types OR reference to a field created in the program)

Here char2 is created like char1

However you CANNOT create cha2 type char1

THANKS.

6 REPLIES 6

Former Member
0 Kudos

Hi,

Diff bn TYPE N LIKE.

Go through the link.

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

TYPE - Type is used to tell the system what is the type of data object(variable) you want to create .

LIKE: If there is already a data object declared and you want to declare a similar data object you can just refer to the previous data object using like.

Check this thread.

https://forums.sdn.sap.com/click.jspa?searchID=711746&messageID=2270752

https://forums.sdn.sap.com/click.jspa?searchID=711746&messageID=512214

Regards,

Priyanka.

Former Member
0 Kudos

hi....

i would suggest u have a proper subject to your query.

Eg: This would explain:

TYPES: BEGIN OF struct,

number_1 TYPE i,

number_2 TYPE p DECIMALS 2,

END OF struct.

DATA: wa_struct TYPE struct,

number LIKE wa_struct-number_2,

date LIKE sy-datum,

time TYPE t,

text TYPE string,

company TYPE s_carr_id.

Regards,

Bijal

Former Member
0 Kudos

hi,

If we use type it wll not allocate memory inmmediately.

where as if we use like then it will allocate memory immediately.

data : itab like mara.

data : itab-matnr type matnr.

Reward with points if helpful.

Former Member
0 Kudos
Internal table declaration   
Declaring internal tables is an essential part of writing ABAP code as this is where most of the data retrieved 
from database tables will be stored. During the select statement you retrieve data from a database table into 
an internal table (multiple rows) or a work area or header line (single row).   
 
*&---------------------------------------------------------------------*
*& Report  ZTYPES                                                      *
*&                                                                     *
*&---------------------------------------------------------------------*
REPORT  ZTYPES                                                  .

* Table declaration (old method)
DATA: BEGIN OF tab_ekpo OCCURS 0,             "itab with header line
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
 END OF tab_ekpo.

*Table declaration (new method)     "USE THIS WAY!!!
TYPES: BEGIN OF t_ekpo,
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
 END OF t_ekpo.
DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,      "itab
      wa_ekpo TYPE t_ekpo.                    "work area (header line)

* Build internal table and work area from existing internal table
DATA: it_datatab LIKE tab_ekpo OCCURS 0,      "old method
      wa_datatab LIKE LINE OF tab_ekpo.

* Build internal table and work area from existing internal table,
* adding additional fields
TYPES: BEGIN OF t_repdata.
        INCLUDE STRUCTURE tab_ekpo.  "could include EKKO table itself!!
TYPES: bukrs  TYPE ekpo-werks,
       bstyp  TYPE ekpo-bukrs.
TYPES: END OF t_repdata.
DATA: it_repdata TYPE STANDARD TABLE OF t_repdata INITIAL SIZE 0,   "itab
      wa_repdata TYPE t_repdata.              
 

girish

Former Member
0 Kudos

Both almost do the same thing.

Ex: variable declaration.

data: lv_matnr type matnr,

lv_matnr1 type matnr.

But SAP now recomanded to use TYPE in case of LIKE. If you use LIKE you will get a error/worning in the extendad syntax check which will advice you to use type instead of like in the newer versions of SAP.

to declare the table we use type table of and while work area we use like line of.

Ex:

data: it_mara type table of t_mara,

wa_mara like line og it_mara.

Former Member
0 Kudos

Use like when there is an existing data type and you want to refer to the existing one.

EXAMPLE : TYPES char1 type C

(Has to be a field from the ABAP dictionary)

EXAMPLE : TYPES char2 LIKE char1

(NOTE : Here we can have ABAP dictionary types OR reference to a field created in the program)

Here char2 is created like char1

However you CANNOT create cha2 type char1

THANKS.