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.
- Variables
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 variables is always well-defined.
- Constants
Constants are similar to 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 re-used.
- Literals
The value of literals is also hard-coded in the source code. In contrast to constants, literals don't 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
A variable in an ABAP program is declared with keyword DATA.
A DATA statement consists of three parts. Let's look at each part in more detail.
- DATA
- 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 an underscore.
- TYPE
- The type of the variable is specified after addition TYPE. In the example, built-in types i (for integer numbers) and string (character string with variable length) are used.
- VALUE
- 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.
Sources of ABAP Data Types
ABAP offers the following sources of Data Types:
- ABAP Built-in
- ABAP has a set of 13 predefined data types for simple numeric, char-like, and binary data objects.
- TYPES Statement
- Statement TYPES allows you to define 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, they add semantic information, for example, labels. ABAP Dictionary types are particularly useful when implementing user interfaces.