Friday 5 July 2013

JULY 5


On the fourth day of my training I  learned about various elementary , reference and complex data types and their length in ABAP/4.

Data Types in ABAP/4


Programs work with local data. Data consists of strings of bytes in the memory area of the
program. A string of related bytes is called a field. Each field has an identity (a name) and a
data type. All programming languages have a concept that describes how the contents of a field
are interpreted according to the data type.
In the ABAP type concept, fields are called data objects. Each data object is an instance of an
abstract data type. Data types in ABAP are not just attributes of fields, but can be defined in their
own right. There are separate name spaces for data objects and data types. This means that a
name can at the same time be the name of a data object as well as the name of a data type.
The data type determines how the contents of a data object are interpreted by ABAP statements.
As well as occurring as attributes of a data object, data types can also be defined independently.
We can then use them later on in conjunction with a data object. We can define data types
independently either in the declaration part of an ABAP program (using the TYPES statement), or
in the ABAP Dictionary.

ABAP contains the following data types:

  • elementary
  •  reference
  •  complex types.

Elementary Types

Elementary types are the smallest indivisible unit of types. They can be grouped as those withfixed length and those with variable length.

  • Fixed-Length Elementary Types:   

There are eight predefined types in ABAP with fixed length:
Four character types: Character (C), Numeric character (N), Date (D), and Time (T).
 One hexadecimal type: Byte field (X).

List of Pre-defined Data Types


Data
Type
Internal
Description
Default
Internal
Length
Max
Internal
Length

Valid
Values
Default
Initial
Value
c
character
1
65535
Any char
Blank
n
numeric text
1
65535
0-9
0
d
date
8 (fixed)
-
0-9
00000000
t
time
6 (fixed)
-
0-9
000000
x
hexadecimal
1
65535
Any
 


Three numeric types: Integer (I), Floating-point number (F) and Packed number (P).

List Of Numeric Data Types

Data
Type


Description
Default
Internal
Length

Max
Length

Max
Decimals

Valid
Values
Default
Initial
Value
i
integer
4(fixed)
-
0
-231 to +231
0
p
packed decimal
8
16
14
0-9 .
0
f
floating-point
8
8
15*
-1E-307 to 1E308
0.0

  • Variable-Length Elementary Types:

There are two predefined types in ABAP with variable length:
STRING for character strings
XSTRING for byte strings

Reference Types :

Reference types describe data objects that contain references (pointers) to other objects (data
objects and objects in ABAP Objects). There is a hierarchy of reference types that describes the
hierarchy of objects to which the references can point. There are no predefined references - we
must define them ourself in a program.

Complex Types:

Complex types are made up of other types. They allow us to manage and process
semantically-related data under a single name. We can access a complex data object either as
a whole or by individual component. There are no predefined complex data types in ABAP. We
must define them either in our ABAP programs or in the ABAP Dictionary.

Complex types are divided further into structures and internal tables.

  • Structures

A structure is a sequence of any elementary types, reference types, or complex data types.
We use structures in ABAP programs to group work areas that logically belong together. Since
the elements of a structure can have any data type, structures can have a large range of uses.
For example, we can use a structure with elementary data types to display lines from a database
table within a program.
The following terms are important when we talk about structures:

  • Nested and non-nested structures
  • Flat and deep structures

A nested structure is a structure that contains one or more other structures as components. Flat
structures contain only elementary data types with a fixed length (no internal tables, reference

types, or strings). The term deep structure can apply regardless of whether the structure is nested or not. Nested structures are flat so long as none of the above types is contained in any
nesting level.
  • Internal Tables

Internal tables consists of a series of lines that all have the same data type. Internal tables are
characterized by:

  1. The line type, which can be any elementary type, reference type, or complex data type.
  2. The key identifies table rows. It is made up of the elementary fields in the line. The key can be unique or non-unique.
  3. The access method determines how ABAP will access individual table entries. There are three access types, namely unsorted tables, sorted index tables and hash tables. For index tables, the system maintains a linear index, so we can access the table either by specifying the index or the key.Hashed tables have no linear index. We can only access hashed tables by specifying  the key. The system has its own hash algorithm for managing the table.

Examples for Complex Data Types

The following list contains examples of complex data types in ascending order of complexity:
1. Structures consisting of a series of elementary data types of fixed length (non-nested, flat
structures)

2. An internal table whose line type is an elementary type (vector).
 
3. Internal tables whose line type is a non-nested structure ('real' table)

4. Structures with structures as components (nested structures, flat or deep)

5. structures containing internal tables as components (deep structures)

6. Internal tables whose line type contains further internal tables.