Data Types & Data Objects

Generic types (only for parameters / field symbols): any, data, simple, numeric, clike, csequence, xsequence, any table, index table, standard table, sorted table, hashed table.

5.1 Built-in elementary types

DATA n TYPE i. 8-byte integer (7.50+) Packed decimal (BCD) 8 (1–16 bytes) TYPE p LENGTH 8 DECIMALS 2 decfloat16 / decfloat34 Decimal floating point Binary floating point avoid for money TYPE c LENGTH 10 Numeric text (digits only) postal codes, document numbers Date YYYYMMDD UTC timestamp (7.54+) utclong_current()

Generic types (only for parameters / field symbols): any, data, simple, numeric, clike, csequence, xsequence, any table, index table, standard table, sorted table, hashed table.

5.2 DATA, TYPES, CONSTANTS

TYPES ty_amount TYPE p LENGTH 15 DECIMALS 2.          " local type

DATA lv_name   TYPE string.
DATA lv_amount TYPE ty_amount VALUE '123.45'.
DATA lv_matnr  TYPE matnr.                            " DDIC data element
DATA lv_carrid TYPE spfli-carrid.                     " table field reference
DATA lv_copy   LIKE lv_amount.                        " same type as another object

CONSTANTS gc_max_rows TYPE i VALUE 100.
CONSTANTS: BEGIN OF gc_status,
             open   TYPE c LENGTH 1 VALUE 'O',
             closed TYPE c LENGTH 1 VALUE 'C',
           END OF gc_status.

IF lv_status = gc_status-open. ... ENDIF.

5.3 Structures

TYPES: BEGIN OF ty_flight,
         carrid TYPE s_carr_id,
         connid TYPE s_conn_id,
         fldate TYPE s_date,
         price  TYPE s_price,
       END OF ty_flight.

DATA ls_flight TYPE ty_flight.
ls_flight-carrid = 'LH'.
ls_flight-connid = '0400'.

" Include another structure
TYPES BEGIN OF ty_ext.
        INCLUDE TYPE ty_flight.
TYPES   seats_free TYPE i.
TYPES END OF ty_ext.

5.4 Table types and reference types (preview)

Type categories: elementary (i, c, string…), complex (structures, table types), reference (REF TO).

TYPES ty_flights TYPE STANDARD TABLE OF ty_flight WITH EMPTY KEY.
DATA  lt_flights TYPE ty_flights.

DATA lr_int  TYPE REF TO i.               " data reference
DATA lo_obj  TYPE REF TO zcl_hello_world. " object reference

5.5 Inline declarations (7.40+)

DATA(lv_text) = `inline string`.                  " type derived: string
DATA(lv_num)  = 42.                               " i
SELECT * FROM scarr INTO TABLE @DATA(lt_carriers).
LOOP AT lt_carriers INTO DATA(ls_carrier).
ENDLOOP.
LOOP AT lt_carriers ASSIGNING FIELD-SYMBOL(<ls_carrier>).
ENDLOOP.
FINAL(lv_const) = 3.                              " 7.57+: immutable inline variable

5.6 Literals

Text field literal c (trailing spaces ignored) string (trailing spaces kept) i (or p if large) '12.34' (as text) converted on assignment

5.7 Type conversion

ABAP converts automatically between compatible types following conversion rules (e.g. c → i if the text is numeric; otherwise CX_SY_CONVERSION_NO_NUMBER). Explicit conversion: CONV:

DATA(lv_p) = CONV decfloat34( '1.5' ).
DATA(lv_s) = CONV string( 42 ).
DATA(lv_i) = EXACT i( '42' ).              " raises exception if lossy

5.8 Date and time arithmetic

DATA(lv_today)    = sy-datum.
DATA(lv_tomorrow) = lv_today + 1.          " dates add days
DATA(lv_days)     = CONV i( lv_tomorrow - lv_today ).
DATA lv_first     TYPE d.
lv_first = lv_today.
lv_first+6(2) = '01'.                      " offset/length: first day of month

GET TIME STAMP FIELD DATA(lv_ts).          " TIMESTAMP (packed, UTC)
CONVERT TIME STAMP lv_ts TIME ZONE sy-zonlo INTO DATE DATA(lv_d) TIME DATA(lv_t).