Google Search - Blog...........

SAP ABAP - Data Types & Data Objects.

• Data objects are units created during runtime.
• Data object cannot exist without data type.
• Occupies memory space.

Kinds of Data Objects

1. INTERNAL DATA OBJECTS

• Literal

A literal has a fixed value.
Ex WRITE: “WORK HARD”

• Variables

DATA statement is used to create variables
Ex DATA: NUM TYPE I
NUM is a variable declared by DATA statement. Any variable, which you use in program, need to be declared before you use it and can be done by DATA statement.

Here variable is declared by referring to existing data type.

Variable can also be declared by referring existing data object.
Ex. We have already declared NUM by DATA statement.
DATA: PRICE LIKE NUM.
Here variable is declared by using LIKE parameter, which tells system that price has all the attributes of data object NUM i.e., PRICE is also of type I.

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.

• Constant

Constant is a data object, which contains fixed value through out the program. Constant can be declared in program by using CONSTANT statement.

Ex. CONSTANT: INT TYPE I VALUE 15.

In program value of INT cannot be changed. If you give a statement like INT = 20.
In this case system will give error.

2. EXTERNAL DATA OBJECTS

Are defined in tables i.e., in ABAP/4 dictionary. You can access this data from table.

TABLES: SFLIGHT
DATA: SEATS LIKE SFLIGHT-SEATSMAX.

3. SYSTEM-DEFINED DATA OBJECTS

SPACE & SYSTEM VARIABLES like sy-uname, sy-datum, & sy-repid.

4. SPECIAL DATA OBJECTS

PARAMETERS: are variable, which can accept value from user.

SELECTIONS CRITERIA: are special internal tables to accept value range from user.


Need for Data types:

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.

In this case if you need to change the length of all fields from 20 to 25. Then just change the length of STR and change will be reflected for all the fields.

If you define all the types in TYPE-POOL i.e., global definition of all the types, you can use these types anywhere and in any program.

No comments:

Post a Comment