Introducing ABAP Syntax (2024)

Variables, Constants, and Literals

Introducing ABAP Syntax (1)

A data object in an ABAP program represents a reserved section of the program memory. ABAP knows three types of data objects: variables, constants and literals.

A variable is a data object with content that can change during runtime. A variable is identified by a name. The name is also used to address the data object at runtime. The starting value of an ABAP variable is well defined.
Constants are like variables. But, in contrast to variables the value is hard coded in the source code and must not change during runtime. Like variables, constants have a name by which they can be reused.

The value of literals is also hard coded in the source code. In contrast to constants, literals do not have a name. Because of that you cannot reuse a literal. Only use literals to specify the values for constants and the starting values for variables.

ABAP data objects are always typed: Every data object is based on a data type which determines the kind of information they can contain. The data type of an ABAP data object stays the same throughout a program execution.

Declaration of Variables

Introducing ABAP Syntax (2)

A variable in an ABAP program is declared with the keyword DATA.

A DATA statement consists of the following parts:


Keyword DATA is followed by the name of the variable. The name of a variable may be up to 30 characters long. It may contain the characters A-Z, the digits 0–9 and the underscore character. The name must begin with a letter or underscore.

The type of the variable is specified after the addition TYPE. In the example, built-in types I (for integer numbers) and string (character string with variable length) are used.
Addition VALUE is optional, and you can use it to specify a start value for the variable. If VALUE is missing, the variable is created with an initial value that depends on the technical type of the variable.

Use of Data Types

Introducing ABAP Syntax (3)

ABAP offers the following sources of data types:

ABAP Built-in (Predefined ABAP Types)

ABAP has a set of 13 predefined data type for simple numeric, char-like, and binary data objects.

TYPES Statements

Statement TYPES allows you to define predefined data types and reuse them in different places, depending on the location of the definition.

ABAP Dictionary
The ABAP dictionary is a part of the ABAP Repository. Among other things, it manages global data types, which are available throughout the system. ABAP Dictionary types not only define technical properties, but they also add semantic information – for example, labels. ABAP Dictionary types are particularly useful when implementing user interfaces.

ABAP Built-in (Predefined ABAP Types)

Introducing ABAP Syntax (4)

Some important standard ABAP types (built-in data types) are listed in the figure. The ABAP types are categorized as either complete or incomplete data types. Complete data types already contain type-specific, fixed-length specifications. Incomplete data types contain a default length but allow for a different length to be specified. In the case of type P, you may also specify a number of decimal places.

Complete ABAP Types


A field of type string is a character-like field of variable length. The ABAP runtime system allocates and releases memory to optimize the management of string variables. You cannot influence this behavior directly. The maximum length of a string is governed by settings that the system administrator makes. However, in practice, we talk about strings being unlimited in length.


A field of type I is a numeric field that contains a whole number. The system allocates 4 bytes (32 bits) for such a field that allows for values between -2^31 and +2^31.


A field of type D represents a data. In ABAP, the date always has the format YYYMMDD (without separators). The system converts this format according to the current locale before the value is displayed on the user interface. Likewise, when the user enters a date, the systems convert it into the ABAP format before you start to process it.


A field of Type T represents a time. In ABAP, this has the format HHMMSS (without separators in 24-hour format). If the current locale used 12-hour format, the system converts the values automatically.

Incomplete ABAP Types

A field of type C is a character-like field of specific length. You specify is length in characters; the run time system then assigns double the number of bytes in order to accommodate the field. You use this type when a fixed length is important.

A field of type N is a character field or a specific length that only contains digits. This field should contain a sequence of digits that you do not want to regard as a number and perform calculations with – for example, this could be a personnel number or a cost center.


A field of type P (P for ‘packed number’) is a field that contains a numeric value with a specified number of digits and decimal places. Use this type for numbers with decimal places or where the value range type I is not sufficient.

ABAP Standard Data Types – Character-like and Numeric Data Types

ABAP Standard Data Types

cFixed-length character stringAny characters. Has a fixed length.
dDateHolds dates in the format YYYYMMDD.
tTimeHolds times in the format HHMMSS.
Numeric Types
iIntegerWhole numbers (no decimal places).
pPacked NumberDecimal numbers.

Use of Local Types

Introducing ABAP Syntax (5)

Instead of using built-in-types in the DATA statement directly you can use statement TYPES to define the type first.You can then use the type in a DATA statement after the TYPE addition.

Use of Global Types – ABAP Dictionary

Introducing ABAP Syntax (6)

In an SAP system, there are thousands of business entities, such as country code, plant, material number, fiscal year, cost center, and so on. Technically, it would be possible to define these entities in every single program using the build-in ABAP types that you have just seen. However, this would be extremely labor-intensive and error prone. Instead, SAP provides the ABAP Dictionary, which is the central store for important date types and the tool that you used to create database tables.

In the ABAP Dictionary, single business entities are described by data elements. In the example variable, variable airport is typed with data element /DMO/AIRPORT_ID.

When you press the F2 key to display the details of the data type you can see that technically this type is a character of length 3. In addition, the data element provides the description "Flight Reference Scenario: Airport ID" and the four field labels of different length.

When you press the F3 key to navigate to the definition of the type, a new view opens with the editor for data elements.

Constants and Literals

Declaration of Constants

Introducing ABAP Syntax (7)


A constant is a data object with a hard-coded value that must not be changed during runtime. Any write access to a constant will lead to a syntax error.

In ABAP, you declare a constant using keyword CONSTANTS. A CONSTANT statement consists of the same parts as a DATA statement. The only difference is that the VALUE addition is mandatory.

You can use the VALUE addition in the special form VALUE IS INITIAL, if the value of the constant should be the type-specific initial value.

Declaration of Literals

Introducing ABAP Syntax (8)


Literals are anonymous data objects with a hard-coded value. Literals are often used to define non-initial values for constants and non-initial starting value for variables.

Technically, you can use literals anywhere in your code. To support readability and maintainability, it is recommended to define and use constants instead.

ABAP knows three types of literals:

  • Number Literals are integer numbers with or without sign. Number literals usually have data type I. Only if the value is too large for data type I, type p is used with a sufficient length and without decimal places.
  • Text Literals are character strings in a pair of single quotes ( ‘ ). String literals are of type STRING. They should be used to provide values for string typed data objects.
  • String Literals are character strings in a pair of singe quotes ( ‘ ). String literals are of type STRING. They should be used to provide values for string typed data objects.

Chained Statements

Introducing ABAP Syntax (9)

You can also define structured types in ABAP program using the TYPES statement. The structure definition begins with the statement TYPES BEGIN OF, structure type name> and ends with TYPES END OF <structure type name>. In between, you name each component and specify its type in an additional TYPES statement.

A compact form uses keyword TYPES only once, followed by a colon ( : ). The BEGIN OF addition, the END OF addition and the component definitions in between are then separated by commas.

This is referred to as a chain statement.

Introducing ABAP Syntax (10)Note

In the past, chain statements were used a lot in ABAP. These days, they are only recommended to combine statements that belong closely together.

Comments in ABAP

Introducing ABAP Syntax (11)

A comment is an explanation that is added to a program to help others understand the code. Comments are a piece of source code that is ignored by the compiler or interpreter.

In ABAP, there are two different ways to define a piece of source code as a comment:

  • The star sign (*) in the first column identifies the entire line as a comment
  • The double quote sign (") identifies the rest of the line, that is, the code to the right as a comment
Introducing ABAP Syntax (2024)


Top Articles
Latest Posts
Article information

Author: Barbera Armstrong

Last Updated:

Views: 5543

Rating: 4.9 / 5 (79 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Barbera Armstrong

Birthday: 1992-09-12

Address: Suite 993 99852 Daugherty Causeway, Ritchiehaven, VT 49630

Phone: +5026838435397

Job: National Engineer

Hobby: Listening to music, Board games, Photography, Ice skating, LARPing, Kite flying, Rugby

Introduction: My name is Barbera Armstrong, I am a lovely, delightful, cooperative, funny, enchanting, vivacious, tender person who loves writing and wants to share my knowledge and understanding with you.