You are on page 1of 8

Data Types and Data Objects

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) called 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 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 separate name spaces for data objects .

Data Types
user-defined data is based on a set of predefined elementary data types. You can define data types either locally in the declaration part of a program (using the TYPES statement) or globally in the ABAP Dictionary. Data objects Data objects are the physical units with which ABAP statements work at runtime. Each ABAP data object has a set of technical attributes, which are fully defined at all times when an ABAP program is running. The technical attributes of a data object are its length, number of decimal places, and data type. ABAP statements work with the contents of data objects and interpret them according to their data type. You declare data objects either statically in the declaration part of an ABAP program (the most important statement for this is DATA), or dynamically at runtime (for example, when you call procedures). As well as fields in the memory area of the program, the program also treats literals like data objects.
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). Three numeric types: Integer (I), Floating-point number (F) and Packed number (P).

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). T Complex Types Complex types are made up of other types. They allow you to manage and process semantically-related data under a single name. You can access a complex data object either as a whole or by individual component. There are no predefined complex data types in ABAP. You must define them either in your ABAP programs or in the ABAP Dictionary. Structured 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. The following terms are important when we talk about structures: Nested Structures A nested structure is a structure that contains one or more other structures as components. Flat Structures Flat structures contain only elementary data types with a fixed length (no internal tables, reference types, or strings). Deep structures deep structure can apply regardless of whether the structure is nested or not . Any structure that contains at least one internal table, reference type, or string as a component (regardless of nesting) is a deep structure. Internal tables, references, and strings are also known as deep data types. The technical difference between deep structures and all others . When you create a deep structure, the system creates a pointer in memory that points to the real field contents or other administrative information . When you create a flat data type, the actual field contents are stored with the type in memory. Since the field contents are not stored with the field descriptions in the case of deep structures, assignments,

offset and length specifications and other operations are handled differently from flat structures.
Internal Tables

Internal tables consists of a series of lines that all have the same data type. Internal tables are The line type, which can be any elementary type, reference type, or complex data type. The key identifies table rows. It is made up of the elementary fields in the line. The key can be unique or non-unique. 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 you can access the table either by specifying the index or the key. Hashed tables have no linear index. You can only access hashed tables by specifying the key. The system has its own hash algorithm for managing the table.
You should use internal tables whenever you need to use structured data within a program. One imprint use is to store data from the database within a program

Examples for Complex Data Types


The following list contains examples of complex data types 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.

Defining Data Types

Data types

Types in the ABAP Dictionary

Local types in programs

Predefined ABAP types

ABAP Dictionary objects

Types in type groups

This differentiates between


Predefined ABAP types that are built into the kernel. Local data types that you can define in ABAP programs. Data types in the ABAP Dictionary that are available to all programs in the entire system. In the ABAP Dictionary, you can define types either as Dictionary objects or in type groups.

Predefined ABAP Types


These data types are predefined in the R/3 System kernel, and are visible in all ABAP programs. You can use predefined types to define local data types and objects in a program and to specify the type of interface parameters and field symbols.

Predefined Elementary ABAP Types with Fixed Length


These predefined elementary data types are used to specify the types of individual fields whose lengths are always fixed at runtime. The following table shows the different fixed-length data types. All field lengths are specified in bytes. Data Type Initial field length Valid field length Initial value Meaning

Numeric types I F P Character types C

4 8 8

4 8 1 - 16

0 0 0

Integer (whole number) Floating point number Packed number

1 - 65535

''

Text field (alphanumeric characters) Date field (Format: YYYYMMDD)

'00000000'

N T

1 6

1 65535 6

'0 0' '000000'

Numeric text field (numeric characters) Time field (format: HHMMSS)

Hexadecimal type X

1 - 65535

X'0 0'

Hexadecimal field

Data types D, F, I, and T describe the technical attributes of a data object fully. Data types C, N, P, and X are generic. Use a generic type does not have to specify the technical attributes. The initial value (and initial field length in the case of the generic types), are values that are used implicitly in short forms of the TYPES and DATA statements.

The fixed-length predefined types are divided into:

Numeric Types
five non-numeric types (text field (C), numeric text field (N), date field (D), time field (T), and hexadecimal field (X)), there are three numeric types, used in ABAP to display and calculate numbers. Data type N is not a numeric type. Type N objects can only contain numeric characters (0...9), but are not represented internally as numbers. Typical type N fields are account numbers and zip codes. integers - type I The value range of type I numbers is -2**31 to 2**31-1 and includes only whole numbers. Non-integer results of arithmetic operations (e.g. fractions) are rounded, not truncated. You can use type I data for counters, numbers of items, indexes, time periods, and so on. Packed numbers - type P Type P data allows digits after the decimal point. The number of decimal places is generic, and is determined in the program. The value range of type P data depends on its size and the number of digits after the decimal point. The valid size can be any value from 1 to 16 bytes. Two decimal digits are packed into one byte, while the last byte contains one digit and the sign. Up to 14 digits are allowed after the decimal point. The initial value is zero. When working with type P data, it is a good idea to set the program attribute Fixed point arithmetic.Otherwise, type P numbers are treated as integers. You can use type P data for such values as distances, weights, amounts of money, and so on. Floating point numbers - type F The value range of type F numbers is 1x10**-307 to 1x10**308 for positive and negative numbers, including 0 (zero). The accuracy range is approximately 15 decimals, depending on the floating point arithmetic of the hardware platform. Since type F data is internally converted to a binary system, rounding errors can occur. Although the ABAP processor tries to minimize these effects, you should not use type F data if high accuracy is required. Instead, use type P data. You use type F fields when you need to cope with very large value ranges and rounding errors are not critical. Using I and F fields for calculations is quicker than using P fields. Arithmetic operations using I and F fields are very similar to the actual machine code operations, while P fields require more support from the software. Nevertheless, you have to use type P data to meet accuracy or value range requirements.

Character types
Of the five non-numeric types, the four types C, D, N, and T are character types. Fields with these types are known as character fields. Each position in one of these fields takes up enough space for the code of one character. Currently, ABAP only works with single-byte codes such as ASCII and EBCDI.

Hexadecimal Type
The remaining non-numeric type - X - always interprets individual bytes in memory. One byte is represented by a two-digit hexadecimal display. The fields with this type are called hexadecimal fields.

Predefined Elementary ABAP Types with Variable Length


These predefined elementary data types are used to specify the types of individual fields whose lengths are not fixed until runtime. There are two predefined ABAP data types with variable length that are generically known as strings: STRING for character strings A string is a sequence of characters with variable length. A string can contain any number of alphanumeric characters. The length of a string is the number of characters multiplied by the length required for the internal representation of a single character. XSTRING for byte strings A byte string is a hexadecimal type with variable length. It can contain any number of bytes. The length of a byte string is the same as the number of bytes. When you create a string as a data object, only a string header is created statically. This contains administrative information. The actual data objects are created and modified dynamically at runtime by operational statements. The initial value of a string is the empty string with length 0. A structure that contains a string is handled like a deep structure. This means that there are no conversion rules for structures that contain strings.

Predefined Complex Data Types


complex data types that you can use to define local data types or data objects in a program. All complex data types are based on elementary ABAP types, and are constructed in ABAP programs or in the ABAP Dictionary.

Local Data Types in Programs


All ABAP programs can define their own data types. Within a program, can also define local types. You define local data types in a program using the

TYPES <t> ... [TYPE <type>|LIKE <obj>] ...


The type name <t> may be up to 30 characters long. You can use any letters, digits, and the underscore character.

Elementary Data Types


Local elementary data types in a program are defined with reference to predefined elementary types. You use the following syntax:

TYPES <t>[(<length>)] [TYPE <type>|LIKE <obj>] [DECIMALS <dec>].


<type> is one of the predefined ABAP types C, D, F, I, N, P, T, X, STRING, or XSTRING, an existing elementary local type in the program, or a data element defined in the ABAP Dictionary. When you refer to a data element from the ABAP Dictionary, the system converts it into an elementary ABAP type. If you use a LIKE reference, <obj> can be an existing data object with an elementary data type.

Reference Types
You can define reference types locally in your programs or globally in the ABAP Dictionary. You use the following syntax: TYPES <t> TYPE REF TO ... REF TO DATA

Data Types in the ABAP Dictionary


One of the most important tasks of the ABAP Dictionary [Ext.] is to administer database tables in the R/3 database. The Dictionary contains metadescriptions of the database tables, and uses these to create the physical tables in the database. A view is a "virtual table" containing fields from one or more tables.

You might also like