The ABAP Dictionary allows you to define global data types. You can use the TYPE addition of an appropriate ABAP statement to refer to these data types in any ABAP program in the system.
You define these data types using the ABAP Dictionary. The following input fields are relevant to data types:
There are three groups on the initial screen:
Database Tables and Views
One of the most important tasks of the ABAP Dictionary is to administer database tables in the R/3 database. The Dictionary contains meta-descriptions 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.
In the description of a database table, the table lines consist of single fields or columns. An elementary data type must be assigned to each column. The elementary types in the ABAP Dictionary are data elements. Like data objects in ABAP programs, database tables and views have data types as attributes. A line of a database table or view has the data type of a flat structure, which consists of individual data elements.
In ABAP programs, you can use the TYPE addition with the data type of a database table or view. You may refer to the whole structure or to individual components:
... TYPE
refers to the complex data type of the structure,
... TYPE
refers to the elementary data type of component
If you define a complex data type
TYPES
the components of the data type
To ensure compatibility with previous releases, you can still use the LIKE addition to refer to database tables or views, except within classes. The reason for this is that in earlier releases, the physical presence of the database tables as objects was emphasized, even though the Dictionary only contains meta-descriptions and data types.
Defining program-local data types by referring to database tables and views is one of the essential techniques for processing data from database tables in ABAP. Data objects that you define in this way always have the right type to contain data from the corresponding database table. ABAP Open SQL allows you to read a single field, a range of fields, or an entire database table or view into an internal table.
TYPES: city type spfli-cityfrom,
spfli_type TYPE STANDARD TABLE OF spfli WITH DEFAULT KEY.
DATA: wa_city TYPE city,
wa_spfli TYPE spfli_type.
...
SELECT SINGLE cityfrom FROM spfli
INTO wa_city
WHERE carrid = 'LH' AND connid = '400'.
...
SELECT * FROM spfli INTO TABLE wa_spfli.
...
This example defines an elementary data type CITY that refers to a single field of the database table SPFLI and an internal table SPFLI_TYPE, whose line type is the same as the structure of the database table. The SELECT statement reads data from the database into the corresponding data objects.
Data types
Data types are the actual type definitions in the ABAP Dictionary. They allow you to define elementary types, reference types, and complex types that are visible globally in the system. The data types of database tables are a subset of all possible types, namely flat structures. Global object types (classes and interfaces) are not stored in the ABAP Dictionary, but in the class library. You create them using the Class Builder.
For a detailed description of data types and their definitions, refer to the Types section of the ABAP Dictionary documentation. The following descriptions mention the types only briefly, along with how you can refer to them from ABAP programs.
Data Elements
Data elements in the ABAP Dictionary describe individual fields. They are the smallest indivisible units of the complex types described below, and are used to specify the types of columns in the database. Data elements can be elementary types or reference types.
- Elementary Types
Elementary types are part of the dual-level domain concept for fields in the ABAP Dictionary. The elementary type has semantic attributes, such as texts, value tables, and documentation, and has a data type. There are two different ways to specify a data type:
- By directly assigning an ABAP Dictionary type.
You can assign a predefined ABAP Dictionary type and a number of characters to an elementary type. The ABAP Dictionary has considerably more predefined types than the ABAP programming language. The number of characters here is not the field length in bytes, but the number of valid characters excluding formatting characters. The data types are different because the predefined data types in the ABAP Dictionary have to be compatible with the external data types of the database tables supported by the R/3 System.
When you refer to data types from the ABAP Dictionary in an ABAP program, the predefined Dictionary types are converted to ABAP types as follows:
Dictionary type | Meaning | Maximum length n | ABAP type |
DEC | Calculation/amount field | 1-31, 1-17 in tables | P((n+1)/2) |
INT1 | Single-byte integer | 3 | Internal only |
INT2 | Two-byte integer | 5 | Internal only |
INT4 | Four-byte integer | 10 | I |
CURR | Currency field | 1-17 | P((n+1)/2) |
CUKY | Currency key | 5 | C(5) |
QUAN | Amount | 1-17 | P((n+1)/2) |
UNIT | Unit | 2-3 | C(n) |
PREC | Accuracy | 16 | Internal only |
FLTP | Floating point number | 16 | F(8) |
NUMC | Numeric text | 1-255 | N(n) |
CHAR | Character | 1-255 | C(n) |
LCHR | Long character | 256-max | C(n) |
STRING. | String of variable length | 1-max | STRING. |
RAWSTRING | Byte sequence of variable length | 1-max | XSTRING |
DATS | Date | 8 | D |
ACCP | Accounting period YYYYMM | 6 | N(6) |
TIMS | Time HHMMSS | 6 | T |
RAW | Byte sequence | 1-255 | X(n) |
LRAW | Long byte sequence | 256-max | X(n) |
CLNT | Client | 3 | C(3) |
LANG | Language | internal 1, external 2 | C(1) |
("max" in LCHR and LRAW is the value of a preceding INT2 field. The "internal" length of a LANG field is in the Dictionary, the "external" length refers to the display on the screen.
- Assigning a domain
The technical attributes are inherited from a domain. Domains are standalone Repository objects in the ABAP Dictionary. They can specify the technical attributes of a data element. One domain can be used by any number of data elements. When you create a domain, you must specify a Dictionary data type (see above table) and the number of characters.
- Reference Types
Reference types describe single fields that can contain references to global classes and interfaces from the ABAP class library.
In an ABAP program, you can use the TYPE addition to refer directly to a data element. The predefined Dictionary data types of the domain are then converted into the corresponding ABAP types.
If you define a local data type in a program by referring to a data element as follows:
TYPES
the semantic attributes of the data element are inherited and will be used, for example, when you display a data object with type
TYPES company TYPE s_carr_id.
DATA wa_company TYPE company.
wa_company = 'UA '.
WRITE: 'Company:', wa_company.
This example defines a local type COMPANY that refers to the data element S_CARR_ID. The data element is linked to the identically-named domain S_CARR_ID. The domain defines the technical attributes as data type CHAR with length 3. The local data type COMPANY in the program therefore has the ABAP type C(3). COMPANY also adopts the semantic attributes of the data element. In the above example, we declare a data object WA_COMPANY with this type and display it on a list. If the user chooses F1 help for the output field, the help text stored in the ABAP Dictionary will appear in a dialog box.
structures
A structure is a sequence of any other data types from the ABAP Dictionary, that is, data elements, structures, table types, or database tables. When you create a structure in the ABAP Dictionary, each component must have a name and a data type.
In an ABAP program, you can use the TYPE addition to refer directly to a structure.
If you define a local data type in a program by referring to a structure as follows:
TYPES
the construction blueprint of the structure is used to create a local structure
To ensure compatibility with previous releases, it is still possible to use the LIKE addition in an ABAP program to refer to a structure in the ABAP Dictionary (except in classes).
Suppose the structure STRUCT is defined as follows in the ABAP Dictionary:
Field name | Type name | Description |
COL1 | CHAR01 | Character field with length 1 |
COL2 | CHAR08 | Character field with length 8 |
COL3 | CHAR10 | Character field with length 10 |
The types CHAR01 to CHAR10 are data elements with corresponding domains. We can refer to this structure in ABAP:
TYPES struct_type TYPE struct.
DATA wa TYPE struct_type.
wa-col1 = '1'.
wa-col2 = '12345678'.
wa-col3 = '1234567890'.
This program creates a local structure in the program - STRUCT_TYPE - and a corresponding data object WA. We can address the components using the component names from the original structure.
Table Types
Table types are construction blueprints for internal tables that are stored in the ABAP Dictionary. When you create a table type in the ABAP Dictionary, you specify the line type, access type, and key. The line type can be any data type from the ABAP Dictionary, that is, a data element, a structure, a table type, or the type of a database table. You can also enter a predefined Dictionary type directly as the line type, in the same way that you can with a domain.
In an ABAP program, you can use the TYPE addition to refer directly to a table type.
If you define a local data type in a program by referring to a table type as follows:
TYPES
No comments:
Post a Comment