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

data type

Former Member
0 Likes
784

hi.

pls tell me.

what is diff between types and data.

and why we use the constant

5 REPLIES 5
Read only

Former Member
0 Likes
742
Read only

Former Member
0 Likes
742

Constructing New Data Types

The TYPE addition allows you to construct new data types in the TYPES, DATA; CONSTANTS; and STATICSstatements. In the TYPES statement, these are local data types in the program. In the other statements, they are attributes of new data objects, meaning that the newly defined data types are not free-standing. Rather, they are linked to database objects.This means that you can refer to them using the LIKEaddition, but not using TYPE.

To construct new data types, the addition TYPE can be used with the following type constructors:

· Construction of reference types

REF TO type|dobj

· Construction of structured data types

BEGIN OF struc_type.

...

END OF struc_type.

· Construction of table types

tabkind OF linetype

These data types only exist during the runtime of the ABAP program.

Referring to Known Data Types or Data Objects

Using the additions TYPE or LIKE in the TYPESstatement, local data types in a program can be referred to known data types or data objects. This is mainly the case with user-defined elementary data types. If you declare variables using the additions TYPE type or LIKE dobj with statement DATA, the data type of var is already fully defined before the declaration is made.

The known types or data that are referred to must be visible at the point where the data type or variable is declared.

A known data type can be any of the following:

· A predefined ABAP type to which you refer using the TYPE addition

· An existing local data type in the program to which you refer using the TYPE addition

· The data type of a local data object in the program to which you refer using the LIKE addition

· A data type in the ABAP Dictionary to which you refer using the TYPE addition. To ensure compatibility with earlier releases, it is still possible to use the LIKE addition to refer to database tables and flat structures in the ABAP Dictionary. However, you should use the TYPE addition in new programs.

The LIKE addition takes its technical attributes from a visible data object. As a rule, you can use LIKE to refer to any object that has been declared using DATA or a similar statement, and is visible in the current context. The data object only has to have been declared. It is irrelevant whether the data object already exists in memory when you make the LIKE reference.

· In principle, the local data objects in the same program are visible. As with local data types, there is a difference between local data objects in procedures and global data objects. Data objects defined in a procedure obscure other objects with the same name that are declared in the global declarations of the program.

· You can also refer to the data objects of other visible ABAP programs. These might be, for example, the visible attributes of global classes in class pools. If a global class cl_lobal has a public instance attribute or static attribute attr, you can refer to it as follows in any ABAP program:

DATA dref TYPE REF TO cl_global.

DATA: f1 LIKE cl_global=>attr,

f2 LIKE dref->attr.

You can access the technical properties of an instance attribute using the class name and a reference variable without first having to create an object. The properties of the attributes of a class are not instance-specific and belong to the static properties of the class.

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.

This example declares variables with reference to the internal type STRUCT in the program, a component of an existing data object wa_struct, the predefined data object SY-DATUM, the predefined ABAP type t and STRING, and the data element S_CARR_ID from the ABAP Dictionary.

do reward if helpful

Edited by: sharad narayan on Apr 8, 2008 1:10 PM

Read only

venkat_o
Active Contributor
0 Likes
742

Each ABAP program define its own data types using the statement.

TYPES dtype [TYPE type|LIKE dobj] ...
and declare its own variables or instance attributes of classes using the statement
DATA var [{TYPE type}|{LIKE dobj}] ...
Constants Constants are named data objects that you create statically using a declarative statement. They allow you to store data under a particular name within the memory area of a program. The value of a constant must be defined when you declare it. It cannot subsequently be changed. The value of a constant cannot be changed during the execution of the program. If you try to change the value of a constant, a syntax error or runtime error occurs.
CONSTANTS: pi     TYPE p DECIMALS 10 VALUE '3.1415926536'.
Regards, Venkat.O

Read only

Former Member
0 Likes
742

Hi,

Types is a just a skeleton. it defines the variables. you cant use it to store data in it.

u use the Data statment to create a memory space to store the data.

example,


Types: Begin of ty_output,
           vbeln type vbeln_va,
           ernam type ernam,
           end of ty_output.          "Types

Data ls_output type ty_output. "workarea

Regards,

Niyaz

Read only

Former Member
0 Likes
742

Hi,

Types is used just to create a structure. It cannot be used to hold any values.



Types: begin of tp_itab,
 	matnr type mara-matnr,
            end of tp_itab.

The above statements only creates a structure and this cannot be used to hold data.



data: table_itab type standard table of  tp_itab.
data: wa_itab type tp_itab.

The above statement ( 1st line) declares an internal table which can be used to store multiple rows of data.

The above statement's 2nd line.. declares a work area which can be used to store, only one entry.

Constants are used in case you want some values, not to be changed throughout the whole program.

Reward if helpful..

Regards.