ABAP Elementary data types

In this chapter we will learn Elementary data types but before that let us understand Types and Objects.

TYPES and OBJECTS

Types are descriptions and are used to declare variables ( data objects ) in ABAP programs. Types do no occupy memory whereas data objects occupy their own memory space.

ABAP standard Data types

These are known as pre-defined elementary data types. The ABAP Data types can be used to declare data objects, interface parameters, input/output fields and so on.

ABAP Predefined numeric data types are :

Standard typeDescription
I, INT8type for integer, fixed length 4 for ( I ), fixed length 8 for ( INT8 )
Ftype for float number ( F ), fixed length 8
P packed decimals
DECFLOAT16, DECFLOAT34DECFLOAT16 ( 8 bytes with 16 decimal places ), DECFLOAT34 ( 16 bytes with 34 decimal places )

ABAP Predefined non-numeric data types are :

Standard typeDescription
CType for character string
NType for numerical character string
Dtype for date ( D ), format YYYYMMDD, fixed length 8
Ttype for time ( T ), format HHHHMMSS, fixed length 6
XType for byte sequence – Hexadecimal string)
STRINGdynamic length
XSTRINGdynamic length hexadecimal string ( byte sequence )

SAP ABAP Elementary Data types – Complete or Incomplete

The above mentioned ABAP elementary data types are either Complete ABAP Elementary types – they have fixed length or Incomplete ABAP Elementary types – these do not contain a fixed length and, we need to specify the length of the variable.

ABAP Elementary Data types Complete
Standard typeSyntax
I, INT8DATA lv_int TYPE i.
FDATA lv_float TYPE f.
D DATA lv_date TYPE d.
T DATA lv_time TYPE t.
DECFLOAT16, DECFLOAT34 DATA lv_decnumber TYPE decfloat16.
STRINGDATA lv_string TYPE string.
XSTRINGDATA lv_xstring TYPE xstring.
SAP ABAP Elementary Data types – Incomplete

When using incomplete standard data types, developer needs to specify the length of the variable.

Standard TypeSyntax
CDATA lv_name TYPE C LENGTH 10.
NDATA lv_number TYPE N LENGTH 5.
Xhexadecimal type ( byte sequence )
PDATA lv_precision TYPE P LENGTH 5 DECIMALS 2.

Apart from elementary types, we also have complex types and reference types in ABAP.

In ABAP, You can define data types either locally in the declaration part of a program ( using the TYPES keyword ) or globally in the ABAP Dictionary. Types declared by user are know as user-defined types and types given by SAP are known as standard types.

Type Conversion

When moving data between data objects of different types, automatic type conversion is performed by ABAP. This automatic type conversion is followed by conversion rules predefined in ABAP layer.

DATA LV_CHAR TYPE C LENGTH 5 VALUE 12345.
DATA LV_INT TYPE I.
LV_INT = LV_CHAR.

As lv_char holds data which can be stored in a variable of type integer, the above assignment will work.

DATA LV_CHAR TYPE C LENGTH 5 VALUE 'ABC123'.
DATA LV_INT TYPE I.
LV_INT = LV_CHAR.

The above assignment will fail throwing a runtime error CX_SY_CONVERSION_NO_NUMBER as the data of lv_char cannot be kept in a variable of type integer.

DATA LV_CHAR TYPE C LENGTH 5 VALUE 12345.
DATA LV_INT TYPE I.
LV_INT = LV_CHAR + 10.

This system will attempt type conversion before performing the arithmetic operation. Instead of relying on system type conversion, it is advised to use correct TYPE based on the data to be processed. For example, to store date and time information, use TYPE d and t respectively, instead of any other TYPE.

DATA LV_DATE TYPE D VALUE '20220101'.
WRITE LV_DATE.

As it is TYPE D, system setting’s or user settings will be applied to display the output.