Using Dictionary Objects as Data Types

Objective

After completing this lesson, you will be able to Describe the use of dictionary objects as data types.

Dictionary Objects As Data Types

In the previous unit of this course it was shown how to use dictionary objects of type Database Table to define tables on the database. It was also shown how Data Elements are used to specify the technical and semantical properties of table fields. Finally, a dictionary object of type Structure was created and included into the field list of a database table.

All three dictionary object types, Data Element, Database Table, and Structure, can also serve as data types for variables, method parameters, and so on.

Note

It is not possible to use domains as data types. Domains are only used as foundation for data elements.

Dictionary objects of type Table Type are not related to the definition of database tables. Their only purpose is to be used as data types in ABAP coding.

The nature of the data types are rather obvious. A Data Element is a scalar type, a Structure is a structure type and a Table Type is the type of an internal table. The only surprise might be nature of Database Tables.

When used as data types, database tables are structure types. Avoid using database tables directly as data types.

In the past, ABAP developers often used dictionary objects as data types. This was mainly because there were no real alternatives for global data types, that is data types that are available in any ABAP code within the system. This changed when it became possible to define types in global classes and interfaces. The public types of a global class and types in interfaces have the same visibility as dictionary types. They also have an advantage: Types in classes and interfaces come with the context of the class or the interface. Dictionary types only have the package they belong to.

Note

Avoid defining new dictionary objects that only serve as data types, unless you depend on dictionary features like extensibility or additional semantics. Use types in classes and interfaces instead.

Try It Out: Dictionary Objects as Data Types

  1. Create a new global class that implements interface IF_OO_ADT_CLASSRUN.
  2. Copy the following code snippet to the implementation part of method if_oo_adt_classrun~main( ):
    Code Snippet
    Copy code
    Switch to dark mode
    123456789101112
    * Declarations * DATA travel TYPE /dmo/travel_id. * DATA travel TYPE /dmo/s_travel_key. * DATA travel TYPE /dmo/travel. * DATA travel TYPE /dmo/t_travel. * Assignments travel = '123'. "elementary travel = VALUE #( travel_id = '123' ). "structure travel = VALUE #( ( travel_id = '123' ) ). "table

    In this coding, the commented declarations of data object travel use different dictionary objects as data type.

  3. Remove the comment from one of the DATA declarations. Which of the three value assignments cause syntax errors? What does this tell you about the nature of the data object?
  4. In the DATA declaration, place the cursor on the data type and use the tooltip description (function key F2) to find out what type of dictionary object it is.
  5. Repeat with the other DATA declarations in turn.

Data Elements as Data Types

All data elements that are used in database table definitions can also be used as data types. This is not valid the other way round. The following exceptions exists:

Data elements with a reference type

It is technically not possible to type the field of a database table with a reference type. Data elements which use a reference type are not allowed in database table definitions.

Data elements with a predefined type

When defining a database table, it is strongly recommended to use data elements that refer to a domain. Data elements that directly use a predefined type should not be used in database table definitions, even though technically this is possible.

Log in to track your progress & complete quizzes