Understanding ABAP Data Types: A Comprehensive Guide

he data types cnx, and p are incomplete, i.e., generic data types, with respect to their length. The type definition syntax has a special addition for this (LENGTH).

The following complex data types are available

  1. Structure tyoe
  2. Table types:
  3. Enumerated types: BEGIN OF ENUM … END OF ENUM …
  4. BDEF derived types: RAP-specific structured and table types. The typical syntax elements are ... TYPE STRUCTURE FOR ... and ... TYPE TABLE FOR ...
  5. Mesh types: Special structured type that contains only table types with structured line types as components that can be linked using mesh associations. The typical syntax element is ... BEGIN OF MESH ... END OF MESH

Describe data objects that contain references to other objects (data objects and instances of classes), which are known as reference variables.

"Numeric types
TYPES te_i TYPE i.
TYPES te_int8 TYPE int8.
TYPES te_decfl16 TYPE decfloat16.
TYPES te_decfl34 TYPE decfloat34.
TYPES te_f TYPE f.
TYPES te_p_l4_d2 TYPE p LENGTH 4 DECIMALS 2.
"Note: LENGTH/DECIMALS must be specified when using the types c, p, n, x. in ABAP Objects contexts.

"Character-like types
"To combine TYPES statements, you can use chained statements, i.e. TYPES followed by a colon and 
"then listing the type declarations separated by a comma.
TYPES: te_c5  TYPE c LENGTH 5,
       te_n4  TYPE n LENGTH 4,
       te_str TYPE string.

"Byte-like types
TYPES te_x_l2 TYPE x LENGTH 2.
TYPES te_xstr TYPE xstring.

"Types for date and time
TYPES te_d TYPE d.
TYPES te_t TYPE t.
TYPES te_utc TYPE utclong.

Complex Types

"Structure type, can contain any type
TYPES: BEGIN OF ts_misc_comps,
          comp1 TYPE i,
          comp2 TYPE string,
          comp3 TYPE te_i,                                    "Existing type
          comp4 LIKE do_num,                                  "Referring to existing data object
          comp5 TYPE string_table,                            "Internal table type (available in DDIC)
          comp6 TYPE TABLE OF zdemo_abap_carr WITH EMPTY KEY, "Internal table type (based on database table)
          comp7 TYPE REF TO i,                                "Reference type
        END OF ts_misc_comps.
"Structure type based on DDIC type
"In this case, a database table is specified whose line type is used as data type
"in this type declaration. You may also use a CDS view (or classic DDIC view in
"standard ABAP) or a dedicated structured type defined in the DDIC.
TYPES ts_ddic_tab TYPE zdemo_abap_carr.

"Internal table type based on internal type that exists in a gloabl interface
TYPES tt_tab_type_from_itf TYPE zdemo_abap_get_data_itf=>carr_tab.

"Internal table types with an elementary line type based on globally available types
"Elementary table type
TYPES tt_strtab TYPE string_table.
"Elementary line type; the type is available in a global interface
TYPES tt_elem_type_from_itf TYPE TABLE OF zdemo_abap_get_data_itf=>occ_rate.

Generic types

FIELD-SYMBOLS:
  "Any data type
  <data>           TYPE data,
  <any>            TYPE any,
  "Any data type can be assigned. Restrictions for formal parameters and 'data': no
  "numeric functions, no description functions, and no arithmetic expressions can be
  "passed to these parameters. However, you can bypass the restriction by applying the
  "CONV operator for the actual parameter.

Leave a comment