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

KEYWORDS TYPE AND DATA

Former Member
0 Likes
1,877

When is a types keyword used n when is the data keyword used?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,701
TYPES :  used to declare structures.

DATA : used to declare internal tables and simple data declarations

types : begin of ty_itab,
             matnr like mara-matnr,
             maktx like makt-maktx,
           end of ty_itab.

data : itab type table of ty_itab.
10 REPLIES 10
Read only

Former Member
0 Likes
1,702
TYPES :  used to declare structures.

DATA : used to declare internal tables and simple data declarations

types : begin of ty_itab,
             matnr like mara-matnr,
             maktx like makt-maktx,
           end of ty_itab.

data : itab type table of ty_itab.
Read only

Former Member
0 Likes
1,701

Hi,

TYPES key word is used declaring local types within the program...TYPES key word cannot be used to store values in the run time..

DATA key word is used to declare variable/structure or internal table..Using which you can store values in the run time..

Thanks,

Naren

Read only

Former Member
0 Likes
1,701

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.

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...

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

Read only

Former Member
0 Likes
1,701

See the diffrence :

  • Structure

types : begin of ty_itab,

fld1(1) type c,

end of ty_itab.

  • Internal table

data i_itab type standard table of ty_itab.

here i can not use types ty_itab in the program,if i use then i will get syntax error..

types is nothing but structure..

data - related to work area or internal table,variable

you can use data statemnt in anywhere in the program.

Read only

0 Likes
1,701

i have seen that using data also we can create a stucture with ocurrs 0

Read only

0 Likes
1,701

when you see occurs 0,nothing but internal table,

this is not structure.

Read only

0 Likes
1,701

Yes its an internal table but using both the keywords can we create a structure ?is it correct to use the data keyword to create a structure?

Read only

0 Likes
1,701

data wa_itab like line of itab.

this is work area also we call as structure ,it will have only one record during runtime,

where as internal table ,it will have many records during run time

when you use types statment in the data decalration and you can not use in select query.

Read only

0 Likes
1,701

thanks for the answer

Read only

Former Member
0 Likes
1,701

Hi krishna,

<b>types</b> is data type which doen't have memory space to hlod data,

<b>data</b> is data object which has memory space to hold data,

<b>types</b> keywords are attributes to the <b>data</b> keywords.

regards,

seshu.