SAP ABAP Data types

SAP ABAP data types define the technical format of data used in ABAP programs. A data type tells the ABAP runtime what kind of value a data object can store, how much space it may need, and how operations such as assignment, comparison, calculation, and output formatting should behave.

In day-to-day ABAP programming, data types are used with variables, constants, parameters, work areas, structures, internal tables, and references. Choosing the correct ABAP data type makes a program easier to read and helps avoid conversion errors, incorrect sorting, and wrong numeric calculations.

You can read the SAP reference material for ABAP data types in the official SAP ABAP documentation on data types. This tutorial explains the same topic in a beginner-friendly way with common examples.

Three main types of data types in SAP ABAP

SAP ABAP data types are commonly grouped into three broad categories. This grouping is useful when you decide whether a data object should hold one simple value, a structured set of values, or a reference to another object.

  1. Elementary data types – store a single value such as text, number, date, time, or byte data.
  2. Complex data types – combine multiple components, such as structures and internal tables.
  3. Reference data types – store references to data objects or class objects.

For many beginner programs, most declarations start with elementary ABAP data types. Complex and reference types become important when the program works with records, lists, database results, and object-oriented ABAP.

Elementary SAP ABAP data types: fixed length and variable length

Elementary ABAP data types are the basic building blocks for simple variables. They are usually discussed as fixed-length types and variable-length types.

  • Fixed-length elementary types have a defined internal length, such as C, N, D, T, I, P, F, and X.
  • Variable-length elementary types can grow according to the stored value, mainly STRING and XSTRING.

Fixed Length

KeywordData TypeExample
CText field“Hello World”
NNumeric00500
DDate“20171201”
TTime“233010”
PPacked Number200.50
IInteger500
FFloat point number4e5

Variable Length

KeywordType
STRINGCharacter Sequence
XSTRINGByte Sequence

Predefined elementary ABAP data types with purpose and initial values

SAP delivers predefined elementary ABAP data types. These types can be used directly in a program with the DATA, TYPES, CONSTANTS, and parameter declarations. Some types are character-like, some are numeric, and some are byte-like.

Data TypeCategoryTypical UseInitial ValueDescription
CCharacter-likeNames, codes, fixed textSpacesFixed-length text field for alphanumeric characters.
NCharacter-likeNumeric text such as document numbersZerosNumeric text field. It stores digits as characters, not as an arithmetic number.
DCharacter-likeDates00000000Date field in internal format YYYYMMDD.
TCharacter-likeTimes000000Time field in internal format HHMMSS.
STRINGCharacter-likeLong or variable textEmpty stringVariable-length character string.
INumericCounters, indexes, quantities without decimals0Integer number.
PNumericCurrency, amount, quantity with fixed decimals0Packed decimal number. Decimals are defined in the declaration.
FNumericScientific or approximate floating values0Binary floating point number.
DECFLOAT16NumericDecimal floating calculations0Decimal floating point number with shorter precision than DECFLOAT34.
DECFLOAT34NumericDecimal floating calculations needing higher precision0Decimal floating point number with higher precision.
XByte-likeRaw byte dataHex zerosFixed-length byte field.
XSTRINGByte-likeVariable raw byte dataEmpty byte stringVariable-length byte string.

Depending on the ABAP release and programming model, you may also see additional integer types such as B, S, and INT8. In beginner examples, I, P, C, N, D, T, STRING, and XSTRING are the most commonly introduced types.

DATA declaration syntax for ABAP data types

The basic syntax for declaring an ABAP variable is to use DATA followed by the variable name and its type. Length and decimals are added only when the selected type needs them.

</>
Copy
DATA variable_name TYPE data_type.
DATA variable_name TYPE data_type LENGTH length_value.
DATA variable_name TYPE data_type LENGTH length_value DECIMALS decimal_places.
DATA variable_name TYPE data_type VALUE initial_value.

The following program declares variables with common SAP ABAP data types and writes the values to the output list.

</>
Copy
REPORT zdemo_abap_data_types.

DATA employee_name TYPE c LENGTH 20 VALUE 'Anil'.
DATA employee_id   TYPE n LENGTH 6  VALUE '000125'.
DATA joining_date  TYPE d           VALUE '20240115'.
DATA login_time    TYPE t           VALUE '093015'.
DATA item_count    TYPE i           VALUE 25.
DATA net_weight    TYPE p LENGTH 8 DECIMALS 2 VALUE '72.50'.
DATA message       TYPE string      VALUE 'ABAP data types example'.

WRITE: / employee_name,
       / employee_id,
       / joining_date,
       / login_time,
       / item_count,
       / net_weight,
       / message.

Output

Anil
000125
20240115
093015
25
72.50
ABAP data types example

Choosing the correct SAP ABAP data type in programs

The correct type depends on the real meaning of the value. A value that contains only digits is not always a numeric value. For example, an employee number or invoice number may contain digits, but it is usually treated as text because you do not add, subtract, or multiply it.

RequirementRecommended ABAP TypeReason
Fixed-length text such as a short codeCStores fixed-length character data.
Document number with leading zerosN or a Dictionary type based on numeric textKeeps leading zeros and treats the value as text.
Date valueDUses ABAP internal date format YYYYMMDD.
Time valueTUses ABAP internal time format HHMMSS.
Counter, number of rows, loop countISuitable for whole-number arithmetic.
Amount or quantity with fixed decimal placesP with DECIMALSUseful for fixed decimal calculations.
Long free textSTRINGLength can vary according to the stored value.
Raw byte contentX or XSTRINGStores byte-like data instead of character data.

Important notes on ABAP character and numeric data types

  • Data type N is not a numeric type. Type N objects can contain numeric characters (0 to 9), but they are not represented internally as arithmetic numbers.
  • The value range of data type I number is -2**31 to 2**31-1 and consists only whole numbers. Data type I (Integer) is used for the values of counters, number of items, indexes, etc.
  • Data type P allows digits after the decimal point. The number of decimal places is determined in the program using the DECIMALS addition. Type P can be used for distance, weights, amounts, and quantities.
  • The non-numeric data types such as C (text field), D (date), N (numeric text), and T (time) are character-like types. These fields store character-formatted values rather than normal arithmetic numbers.

In practical ABAP development, prefer N for numeric-looking identifiers that must preserve leading zeros, and prefer I, P, or decimal floating types for values that are used in arithmetic calculations. For currency and quantity fields in business programs, Dictionary-based types are often used so that length, decimals, and meaning are consistent across programs.

Complex SAP ABAP data types: structures and internal tables

Complex types : –  Complex types includes structures types and table types.

A structure groups multiple fields under one name. It is commonly used for a single record, such as one employee, one material, or one sales document item. An internal table stores multiple rows of the same line type and is commonly used for lists of records.

</>
Copy
TYPES: BEGIN OF ty_employee,
         id   TYPE n LENGTH 6,
         name TYPE c LENGTH 30,
         age  TYPE i,
       END OF ty_employee.

DATA employee TYPE ty_employee.
DATA employees TYPE STANDARD TABLE OF ty_employee.

Here, ty_employee is a structure type. The variable employee can hold one employee record, while employees can hold many employee records.

Reference SAP ABAP data types for data and objects

Reference Types : – Reference types includes data references and object references.

A reference variable does not store the complete value directly. It stores a reference to another data object or class object. Data references are declared with REF TO data or a more specific type. Object references are declared with REF TO followed by a class or interface name.

</>
Copy
DATA number_value TYPE i VALUE 100.
DATA number_ref   TYPE REF TO i.

GET REFERENCE OF number_value INTO number_ref.

Reference types are useful when working with dynamic data objects, object-oriented ABAP, and APIs that pass references instead of copying complete values.

ABAP Dictionary data types and program-local data types

ABAP programs can use built-in types directly, but business applications often use types from the ABAP Dictionary. Dictionary objects such as data elements and domains help keep field definitions consistent across tables, screens, reports, and interfaces.

  • Built-in ABAP type: declared directly in the program, such as TYPE i or TYPE c LENGTH 10.
  • Program-local type: defined in the program using TYPES and reused in that program.
  • ABAP Dictionary type: defined centrally in the SAP system and reused across programs and database objects.

For learning syntax, built-in types are enough. For real SAP development, Dictionary-based typing is preferred when the field has a business meaning such as material number, company code, amount, currency, or unit of measure.

Common mistakes while using SAP ABAP data types

  • Using N for arithmetic: N stores numeric characters. Use a numeric type such as I or P when the value is used in calculations.
  • Forgetting DECIMALS with packed numbers: A P field should declare decimal places when the value represents an amount, weight, rate, or quantity.
  • Storing dates as plain text: Use D for ABAP date values so that date-specific operations and conversions are easier.
  • Choosing STRING for fixed business codes: Short fixed fields such as company code or status code are usually better represented by fixed character or Dictionary types.
  • Ignoring leading zeros: Identifiers such as customer numbers and document numbers may need leading zeros, so treating them as integers can change their displayed value.

SAP ABAP data types FAQ

How many types of data types are in SAP ABAP?

ABAP data types are commonly grouped into three main categories: elementary data types, complex data types, and reference data types. Elementary types include character-like, numeric, and byte-like predefined types.

What are the most common elementary data types in ABAP?

The common elementary ABAP data types include C, N, D, T, I, P, F, STRING, and XSTRING. Additional integer and decimal floating types may also be available depending on the ABAP release.

Is type N a numeric data type in SAP ABAP?

No. Type N is a character-like numeric text type. It stores digits as characters and is useful for identifiers that may have leading zeros.

Which ABAP data type should be used for currency or quantity values?

For fixed decimal values, P with DECIMALS is commonly used. In business programs, Dictionary-based amount and quantity fields are often preferred because they carry consistent length, decimal, currency, or unit-related meaning.

What is the difference between STRING and C in ABAP?

C is a fixed-length character type, while STRING is variable length. Use C for fixed codes or short fields and STRING for text whose length can vary significantly.

Editorial QA checklist for SAP ABAP data type tutorials

  • Confirm that N is explained as numeric text, not as an arithmetic numeric type.
  • Check that examples using P include DECIMALS when the value has decimal places.
  • Verify that date and time examples follow ABAP internal formats YYYYMMDD and HHMMSS.
  • Use language-abap for ABAP code blocks and output for result-only blocks.
  • Keep complex type examples limited to structures and internal tables unless the tutorial also explains object references in detail.

Summary of SAP ABAP data types for beginners

SAP ABAP data types define how values are stored and processed in an ABAP program. The main categories are elementary, complex, and reference data types. Elementary types hold simple values such as text, numbers, dates, times, strings, and byte data. Complex types such as structures and internal tables combine multiple fields or rows. Reference types point to data objects or class objects.

When declaring ABAP variables, choose the type based on the meaning of the value. Use character-like types for text and identifiers, numeric types for calculations, D and T for dates and times, and Dictionary-based types when the field has a business meaning that should remain consistent across SAP programs.