Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Declarative statemnts →  Data Types and Data Objects →  Declaring Data Objects 

Literals

Besides the named data objects which can be addressed by their names in the ABAP program (this includes the text symbols) and the anonymous data objects created by the CREATE DATA statement, there are literals which are defined in the source code of a program by specifying a string representing a value. Possible literals are numeric literals and character literals. The character literals comprise text field literals and text string literals.

Other versions: 7.31 | 7.40 | 7.54

Numeric Literals

Numeric literals consist of continuous sequences of numbers with a maximum of 31 digits (0 to 9), which can be directly preceded by a plus (+) or minus (-) sign.

  • Numeric literals between -2147483648 and 2147483647 are integer literals and have the predefined ABAP type i.
  • Numeric literals outside of this interval are packed numeric literals and have the predefined ABAP type p with a length of 8 bytes if they are not longer than 15 digits, and with a length of 16 bytes if they are between 16 and 31 digits long.

In numeric literals, neither decimal separators nor scientific notation with mantissa and exponent are possible. To be able to represent numbers with fractional portion or numbers in scientific notation as a literal, you must use character literals. When using them at operand positions at which a numeric value is expected, they are converted accordingly. The same applies for numbers with more than 31 digits.

Text Field Literals

Text field literals are character strings included in single inverted commas ('). They have the data type c in the length of the included characters, including trailing blanks. There is no empty text field literal: The text field literal '' is identical to the text field literal ' ' of length 1.

To represent an inverted comma inside a text field literal, you must enter two consecutive inverted commas. The length of a text field literal must lie between 1 and 255 characters.

You can use the character & (literal operator) to join several text field literals as one text field literal, even across several program lines. Trailing blanks are not ignored.

Trailing blanks are not ignored. If a text field literal is specified at an operand position at which a text symbol is possible, you can append the three-digit identifier idf of a text symbol in round brackets.

... 'Literal'(idf) ...

If the text symbol exists in the currently loaded text pool, then the content of the text symbol is used instead of the literal, otherwise the literal is used.

Text string literals

Text string literals are character strings included in single backquotes (`), which have the data type string. The empty text string literal `` represents a string of length 0.

To represent a backquote within a text string literal, you must enter two consecutive backquotes. A text string literal can have a maximum of 255 characters. An empty text string literal is the same as an empty string of length 0.

You can use the character & (literal operator) to join multiple text string literals as one text string literal, even across multiple program lines. Trailing blanks are not ignored.

Programming Guideline

Using Literals


Notes

  • An individual literal is not allowed to extend across multiple lines. Multiple character literals across different lines can, however, be joined as one literal using the literal operator &.

  • Character literals joined using the literal operator & are also subject to the upper limit of 255 characters. Longer character strings can only be concatenated at runtime, for example, with the chaining operator &&.

  • When used for literals, the literal operator & must not be confused with the chaining operator && that can be used in string expressions to chain character-like operators. Whereas linking literals with the literal operator takes place once at the compilation of a program, the chaining operator executes a genuine operation at runtime and chains any number of character-like operands. The trailing blanks of operands with fixed lengths, in particular text field literals, are ignored.

  • In character literals, only characters can be used that are available in all code pages supported by SAP. In the worst case, a program can no longer be executed when it uses a code page other than the one it was created with. We recommend that you only use 7-Bit-ASCII-characters.

  • There are no special literals for byte fields or byte strings of types x and xstring.

  • When using literals as actual parameters for typed formal parameters, special rules apply.

  • You can directly represent inverted commas in text string literals and backquotes in text field literals.

  • At the end of text field literals, you should avoid blanks if they are ignored at the respective operand position (see Trailing Blanks in Character String Processing). In particular, this also applies for the text field literal ' '. Conversely, the specification of the supposedly empty text field literal '' in positions where closing spaces are taken into account may be a trap.

  • With the exception of classes, obsolete syntax forms can still be found when dealing with literals, for example, literals that extend over multiple lines.

Example

Representation of inverted commas and backquotes in literals. The first two and the last two literals always have the same meaning.

WRITE: / 'This is John's bike', 
       / `This is John's bike`, 
       / 'This is a backquote: `', 
       / `This is a backquote: ```.