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: 

difference between [b]TYPES[/b] and [b]DATA.[/b]

Former Member
0 Kudos

Hi,

Can you please tell me the difference between <b>TYPES</b> and <b>DATA.</b>

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.

5 REPLIES 5

Former Member
0 Kudos

Thanks I got on my own

Former Member
0 Kudos

TYPES

Syntax Forms

Use Predefined Types

1. TYPES { {dtype[(len)] TYPE abap_type [DECIMALS dec]}

| {dtype TYPE abap_type [LENGTH len] [DECIMALS dec]} }.

Refer to Existing Types

2. TYPES dtype { {TYPE [LINE OF] type}

| {LIKE [LINE OF] dobj} }.

Reference Types

3. TYPES dtype { {TYPE REF TO type}

| {LIKE REF TO dobj} }.

Structured Types

4. TYPES BEGIN OF struc_type.

...

{TYPES dtype ...} | {INCLUDE {TYPE|STRUCTURE} ...}.

...

TYPES END OF struc_type.

Table Types

5. TYPES dtype { {TYPE tabkind OF [REF TO] type}

| {LIKE tabkind OF dobj} }

[WITH key] [INITIAL SIZE n].

Ranges Table Types

6. TYPES dtype {TYPE RANGE OF type}|{LIKE RANGE OF dobj}

[INITIAL SIZE n].

Effect

The statement TYPES dtype defines either any independent data type dtype or a structured data type struc_type. The naming conventions apply to the names dtype and struc_type. The defined data type can be viewed within the current context from this position.

Any data type dtype is either defined with the addition TYPE and a type, or with the addition LIKE and a data object. The syntax allows you to define elementary data types, reference types, structured types, and table types.

For the definition of a structured type struc_type, any type definitions of two TYPES statements are included with the additions BEGIN OF and END OF; a structured data type struc_type is defined here, which contains the included data types as components struc_type-dtype. The structure definitions can be nested.

DATA

Syntax Forms

Using Predefined Types

1. DATA { {dobj[(len)] TYPE abap_type [DECIMALS dec]}

| {dobj TYPE abap_type [LENGTH len] [DECIMALS dec]} }

[VALUE val|{IS INITIAL}]

[READ-ONLY].

Reference to Existing Types

2. DATA dobj { {TYPE [LINE OF] type}

| {LIKE [LINE OF] dobj} }

[VALUE val|{IS INITIAL}]

[READ-ONLY].

Reference Variables

3. DATA dobj { {TYPE REF TO type}

| {LIKE REF TO dobj} }

[VALUE val|{IS INITIAL}]

[READ-ONLY].

Strukturen

4. DATA BEGIN OF struc [READ-ONLY].

...

{DATA dobj ...} | {INCLUDE {TYPE|STRUCTURE} ...}.

...

DATA END OF struc.

Interne Tabellen

5. DATA itab { {TYPE tabkind OF [REF TO] type}

| {LIKE tabkind OF dobj} }

[WITH key] [INITIAL SIZE n]

[WITH HEADER LINE]

[VALUE IS INITIAL]

[READ-ONLY].

Ranges Table

6. DATA rtab {TYPE RANGE OF type}|{LIKE RANGE OF dobj}

[INITIAL SIZE n]

[WITH HEADER LINE]

[VALUE IS INITIAL]

[READ-ONLY].

Effect

The statement DATA dobj either declares an arbitrary variable dobj or a structure struc. The naming conventions apply to the names dobj and struc. The declared data object is visible within the current context as of this position. Within the declaration part of a class or an interface, DATA declares an instance attribute. Its validity is bound to an instance of a class.

The data type of an arbitrary variable dobj is defined either using the TYPE addition and a type specification or using the LIKE addition and the specification of a data object. The syntax allows the definition of elemenary data objects, reference variables, structures, and internal table types. If neither TYPE nor LIKE is specified, a data object with the bound data type c of length 1 is created.

For the definition of a structure struc, arbitrary data declarations are included by two DATA statements with the additions BEGIN OF and END OF. Here a struc structure is declared that contains the enclosed data objects dobj as a struc-dobj component. Structure definitions can be nested.

Notes

The syntax of the DATA statement corresponds to the syntax of the TYPES statement, with the exception of two additions. In this way, a new data type can be defined during the declaraion of a data object. The most important difference compared with the statement TYPES is that a data type defined using DATA - not derived from an existing type - is available only as a property of the declared data object and is not independent. This kind of data type is bound to its data object.

Data objects that are declared in a program, but are not accessed there statically, cause a warning message in the enhanced program check.

Regards,

Pavan.

Former Member
0 Kudos

hi,

The main difference between TYPE and LIKE parameter when defining or declaring the object is that TYPE is used to refer existing DATA TYPE (elementary or structured or user defined) while LIKE is used to declare data objects with reference to existing DATA OBJECTS.

Consider the following example.

DATA: fname(20),

mname(20),

lname(20),

add1(20),

add2(20),

add3(20).

If you have DATA statement like above, and if you need to change the length of all the fields say from 20 to 25, then you need to change all the fields i.e., going through each and every statement.

But consider the following case where TYPES has been used.

TYPES:str(20)

DATA:fname type str,

Mname type str,

Lname type str,

Add1 type str,

Add2 type str,

Add3 type str.

Former Member
0 Kudos

HI,

1. TYPES statement defines the structure without allocation of memory, DATA statements allocate the memory at runtime.

2. Create a structure by using types statement and refer it by using the DATA statement.

3. In order to avoid the internal table declaration without header line, we are declaring a structure by types statemnet and declaring an internal table with reference to the structure.

Write the following in ur report,

TYPES: BEGIN OF tI_EKKO,

EBELN LIKE EKKO-EBELN,

AEDAT LIKE EKKO-AEDAT,

BUKRS LIKE EKKO-BUKRS,

BSART LIKE EKKO-BSART,

LIFNR LIKE EKKO-LIFNR,

END OF tI_EKKO.

DATA: BEGIN OF I_EKKO,

EBELN LIKE EKKO-EBELN,

AEDAT LIKE EKKO-AEDAT,

BUKRS LIKE EKKO-BUKRS,

BSART LIKE EKKO-BSART,

LIFNR LIKE EKKO-LIFNR,

END OF I_EKKO.

break-point.

now execute the program and at the breakpoint try to check value of I_EKKO and tI_EKKO. ONLY I_EKKO will be allocated meomory tI_EKKO will not be.

Regards,

Padmam.

Former Member
0 Kudos

Hi,

plz go through the following thread...

****do rewards if usefull

vijay