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: 

differences b/w data &types....

Former Member
0 Kudos

hi every body

what is the difference between DATA &TYPES,LIKE&TYPE.

What is the transaction code to know all the transaction codes.

regards

ganesh

6 REPLIES 6

former_member181966
Active Contributor
0 Kudos

<b>Syntax Diagram

DATA</b>

Simple Field Definitions

- DATA f.

- DATA f(len).

Defining a Structured Data Object

- DATA: BEGIN OF struc,

...

END OF struc.

Defining an Internal Table

- DATA itab TYPE itabtype [WITH HEADER LINE].

- DATA itab {TYPE tabkind OF linetype|LIKE tabkind OF lineobj}

WITH [UNIQUE|NON-UNIQUE] keydef

[INITIAL SIZE n] [WITH HEADER LINE].

- DATA itab {TYPE TABLE OF linetype|LIKE TABLE OF lineobj}.

- DATA itab {TYPE RANGE OF type|DATA itab LIKE RANGE OF f}.

- DATA itab [TYPE linetype|LIKE lineobj] OCCURS n

[WITH HEADER LINE].

- DATA: BEGIN OF itab OCCURS n,

...

END OF itab [VALID BETWEEN f1 AND f2].

Defining Shared Data Areas

- DATA: BEGIN OF COMMON PART c,

...

END OF COMMON PART.

Additional help

Variables

<b>Syntax Diagram

TYPES</b>

Simple type definition

- TYPES type.

- TYPES type(len).

Definition of a structured type

- TYPES: BEGIN OF structype

...

END OF structype.

Definition of an internal table type

- TYPES itabtype {TYPE tabkind OF linetype|

LIKE tabkind OF lineobj}

[WITH [UNIQUE|NON-UNIQUE] keydef] [INITIAL SIZE n].

- TYPES itabtype {TYPE RANGE OF type|TYPES itabtype LIKE RANGE OF

f}.

- TYPES itabtype {TYPE linetype|LIKE lineobj} OCCURS n.

Additional help

Defining Data Types

Find transaction :<u><b>SE93</b></u>

SAP help :

http://help.sap.com/saphelp_470/helpdata/EN/d1/8019f9454211d189710000e8322d00/frameset.htm

also search SDN with keyword "ABAP help"

Hope this’ll give you idea!!

<b>P.S award the points.</b>

Good luck

Thanks

Saquib Khan

"Some are wise and some are otherwise"

former_member186741
Active Contributor
0 Kudos

Data creates an internal variable for you...Types sets up a template which you can then use to create variables. You usually use it to define structures that you're going to use more than once in your program.

Like/Type are very similar.. they both refer to already existing data entities (which can be defined in the data dictinary or in your program).

data w_matnr like mara-matnr.

is identical to:

data w_matnr type matnr.

Browse table TSTC and/or TSTCT to see transaction codes.

0 Kudos

To clarify a bit, TYPES statement define the structure of your memory space without allocation of memory, DATA statements allocate the memory at runtime.

Regards,

Rich Heilman

0 Kudos

Hi..

LIKE & TYPE

For all practical purposes there are the same. The only additional advantage with types is that you can define your own types(including complex ones) in the data dictionary and reuse them accross various programs.

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.

2. try this code (just copy paste)

report abc.

types : char50(50) type c.

*----


type.

data : d1 type c, "--- native

d2 type n, "--- native

d25 type char50 , "----


User defined data type

d3 type bukrs, "---- data element / domain

d4 type persno, "---- data element / domain

d5 type t001, "---- table

d99 type c

.

data :

*l1 like c "----


Not Allowed

*l2 like n "----


Not Allowed

*l25 like char50 , "----


User defined data type

*l3 like bukrs "----


Not Allowed

*l4 like persno, "----


Not Allowed

l5 like t001 , "---- table

Former Member
0 Kudos

Hi ganesh,

1. what is the difference between DATA &TYPES

As the name suggests,

DATA = it DECLARES a memory variable

and occupies some space.

TYPE = it just DEFINES the type of the variable,

but does not occupy and space in memory.

After that we can use DATA

and make a variable of the above type.

2. LIKE and TYPE.

For all practical purposes there are the same. The only additional advantage with types is that you can define your own types(including complex ones) in the data dictionary and reuse them accross various programs.

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.

2. try this code (just copy paste)

report abc.

types : char50(50) type c.

*----


type.

data : d1 type c, "--- native

d2 type n, "--- native

d25 type char50 , "----


User defined data type

d3 type bukrs, "---- data element / domain

d4 type persno, "---- data element / domain

d5 type t001, "---- table

d99 type c

.

data :

*l1 like c "----


Not Allowed

*l2 like n "----


Not Allowed

*l25 like char50 , "----


User defined data type

*l3 like bukrs "----


Not Allowed

*l4 like persno, "----


Not Allowed

l5 like t001 , "---- table

l99 like pa0001

.

regards,

amit m.

Former Member
0 Kudos

Hi,

Check out this link:

Also refer link:

http://www.sapdevelopment.co.uk/tips/tips_itab.htm

Regards,

Anjali