Data Types and Data Objects
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).
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
Data types
4 8 8
4 8 1 - 16
0 0 0
1 - 65535
''
'00000000'
N T
1 6
1 65535 6
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.
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.
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