In the source code editor of a development object, you can substitute literals with variables. This enables you to replace a specific, unchanging value that is used several times or to improve the readability of ABAP source code. However, literals should only be extracted if the abstraction results in a compliant solution.
Example
In the following examples, literals can be replaced with a variable:
The following examples display the extraction of a certain literal in a variable:
Literal Type | Example | Constant Name | Constant Type | Constant Value |
---|---|---|---|---|
Character | 'Hello Planet !' | hello_planet | String | Float |
'Hello Planet !' | 'Hello Planet !' | hello_planet | String | 'Hello Planet !' |
String Template | |Hello { name }!| | hello | String | 'Hello ' or '!' |
Integer | 255 | _255 | i | 255 |
Float | '3.141529' | _3141529 | decfloat16 | '3.141529' |
The following limitations apply when extracting variables from literals:
You can extract variables from a literal using the following refactoring functions:
When you extract a variable in the source code of a development object, the definition DATA 'your name' TYPE <type> VALUE <value> is added. Also, in the development object the corresponding literal is replaced with the variable.
The name of the generated variable is derived from the literal and automatically generated. The following limitations exist for the creation of the variable name:
Finally, a pragma (##NO_TEXT) is added in the declaration. Therefore, no translation warnings will be issued by the ABAP Compiler syntax check.