ABAP Keyword Documentation → ABAP Programming Guidelines → Structure and Style → Alternative Spellings
Alternative Language Constructs
Other versions: 7.31 | 7.40 | 7.54
Background
Alternative language constructs are parts of statements that can be written in different ways. One reason for this are the constant new developments in the language. Often, new spellings are introduced and the old spellings retained for reasons of downward-compatibility.
Rule
Using consistent spelling
If there is more than one spelling for a statement, choose one of these spellings and use it consistently throughout your development work It is best to choose the spelling that most accurately reflects the semantics of the statement.
Details
To make your programming easier to understand, always choose the spelling that is most accurate and easiest to read, and which (where applicable) matches the spelling used in other statements. The following list contains some examples:
- If you can choose from a range of comparison operators
(
=
orEQ
,>
or GT,<
orLT
,>=
or GE,<=
orLE
) we recommend that you pick a type of operator and stick to it within the context of a program. The variant with the characters =, <, and > is seen as more modern, but also overloads these characters. The logical operators that consist of two letters are better matched to other logical operators such asCO
,CN
, and so on, which have no alternative forms.
- Within logical expressions it is best to use the addition
NOT
of the predicatesBETWEEN
,IN
, IS ASSIGNED,IS BOUND
,IS INITIAL
, and IS SUPPLIED instead of the identical logical operatorNOT
, for improved readability. For example, the expressionIS NOT INITIAL
is easier than the logically identical expressionNOT a IS INITIAL
. This corresponds to the definition of comparison expressions, where a <> b is more intuitive thanNOT a = b
.
- The addition
LENGTH len
of the declarative statementsDATA
andTYPES
is preferable to the length specified in parentheses (len
). This then matches the spelling used inCREATE DATA ... LENGTH
. In addition to this, it is easy to mistake the parenthesized form for dynamic tokens. Only dynamic tokens should use this form.
- Within the parameter list of the statements
EXPORT
andIMPORT
, use the equals sign (=) instead of the additionsFROM
orTO
. The spelling then matches the spelling used in parameter lists in other calls, such as methods, functions modules, and transformations.
- The optional addition
SUBSTRING
of the statementsFIND
andREPLACE
can be used to make a clearer distinction from the alternative additionREGEX
.
- Always use the semantically identical addition
ACTUAL LENGTH
instead of the additionLENGTH
of the statementREAD DATASET
. This makes the distinction from the similar additionMAXIMUM LENGTH
clearer. The last two examples are typical of the way new additions are added to the language, while retaining the old spelling (in a shortened form) for reasons of downward compatibility.
Bad example
The following piece of source code shows how the statement FIND
is used inconsistently
within a program. The first and third FIND
statements are alternative spellings with the same meaning.
DATA text TYPE string.
...
FIND '...' IN text.
...
FIND REGEX '...' IN text.
...
FIND SUBSTRING '...' IN text.
...
Good example
The following piece of source code shows the same statements as in the example above, but with consistent spelling. This expresses the semantic distinction between searching for a substring and searching for a regular expression in clear syntax.
DATA text TYPE string.
...
FIND SUBSTRING '...' IN text.
...
FIND REGEX '...' IN text.
...
FIND SUBSTRING '...' IN text.
...