Академический Документы
Профессиональный Документы
Культура Документы
SAP NetWeaver AS ABAP Release 731, ©Copyright 2015 SAP AG. All rights reserved.
• ABAP Statements
ABAP words
• Operands
• Operators and Expressions
ABAP Statements
ABAP statements consist of the following tokens and end with a period (.).
ABAP words
Operands
Operators
expressions,
The tokens of a statement must be separated by at least one blank or a line break. Otherwise, blanks and line
breaks between tokens are not significant. An ABAP statement is not restricted to a line in the source text.
No distinction is made between upper and lowercase letters. Apart from ABAP words, operands and operators,
you can also use the following special characters:
If a number of expressions of the same type with operators are linked to an expression, the priority of
the individual operations can be defined usig round brackets (()).
For the purpose of calling functions and methods, round brackets (()) can sometimes be used.
Lists of operands are expressed by round brackets (()) and commas (,) in certain positions.
When forming a chained statement, a colon (:) and commas (,) can be used.
A number of free-standing special characters, such as round brackets for setting the priority, need to be
separated from other tokens by an empty character. Other special characters - as well as the period at the end
- do not have to be separated by an empty character.
Note
Obsolete syntax forms can still occur in all objects apart from classes. In such cases, you can omit the
separators between the tokens.
Example
ABAP statement with the keyword DELETE, the addition WHERE, the operators =, <, >, AND, OR, the operands
itab, col1, op1, col2, op2, col3, op3and round brackets.
DELETE itab
WHERE ( col1 = op1 AND ( col2 > op2 OR col3 < op3 ) ).
ABAP words
ABAP words are the vocabulary of the ABAP language. ABAP statements are composed of ABAP words,
operands, and operators according to defined syntax rules. ABAP words are taken from the English language
and are grouped into ABAP language elements and ABAP language element additions that express the
semantics of a statement. In addition to letters, ABAP words can also contain hyphens (-) to form multi-word
expressions. As well as ABAP words, some operators are also made up of letters.
The first ABAP word of a statement is the ABAP key word. The remaining ABAP words are additions to a key
word. A single ABAP word can be used both as a keyword and as a non-keyword. For example, DATA is used
as a keyword as well as an addition to other keywords.
ABAP words are not reserved names as in some programming languages. Although the use of an ABAP word
for naming conventions is not forbidden, it should be avoided if possible. As following this rule can itself lead to
such a situation by the introduction of new elements, suitable naming conventions should be observed for
reserved names to avoid a collision with language elements.
The following table contains all ABAP words, the names of predefined data types and the names (consisting of
letters) of operators. Names in ABAP programs are not case-sensitive.
Operands
Typical operands are:
Additional information:
Specifying operands
Operand type
Classes
Interfaces
Accordingly, names for operands are either elementary names or names constructed from multiple names
separated by component selectors. An elementary name is used for addressing:
elementary operands
Naming conventions apply to the elementary names. Composite names with component selectors are used for
addressing individual components. A component can itself be a superunit of further components.
Subcomponents can be addressed by chaining multiple names.
In this case, the character - is the structure component selector. The name struct of a structured data type
or a structure must be to the left of the structure component selector. The name struct can itself be
composite. The name comp of the component must be to the right of the structure component selector.
Example
Declaration of a structure struc with the structured data type spfli from ABAP Dictionary and access to its
component carrid.
...
ref->comp
In this case, the character -> is the object component selector. The name ref of a reference variable must be
to the left of the object component selector. The name ref can itself be composite. The name comp of the
component must be to the right of the object component selector. If an attempt is made to access an object
component with a reference variable that contains the null reference, a non-handleable exception is raised.
Dereferencing of a data reference in the statement ASSIGN is an exception to this.
The object component selector dereferences the reference variable ref and makes the components of the
referenced object accessible.
If ref is an object reference variable, the components comp of the object (attributes and methods) to
which the object reference variable points are addressed using the object component selector.
If ref is a data reference variable that is typed as a structure, the components comp of the structure to
which the data reference variable points are addressed using the object component selector.
Note
If ref is a data reference variable, the character * can be specified after the object component selector ->.
This creates the general dereferencing operator ->*. The expression ref->* labels the entire data object to
which the data reference variable points. The dereferencing operator is the only way to dereference data
references. In the case of untyped data reference variables, this was only possible using the statement
ASSIGN. The dereferencing operator cannot be specified after object reference variables. The instance
components of classes can only be accessed using the expression ref->comp.
Example
Access to the public attribute a1 of a class c1 by using the object reference variable oref.
CLASS c1 DEFINITION.
PUBLIC SECTION.
DATA a1 TYPE string READ-ONLY.
ENDCLASS.
...
Example
The data reference variable dref is typed as a structure and the component carrid of the referenced
structure is accessed using the object component selector. The expression dref->carrid has the same
meaning as the chaining dref->*-carrid.
...
class=>comp
In this case, no instance of the class needs to be created. The characters => are the class component selector.
The name class of a class must be to the left of the class component selector. The name comp of the
component must be to the right of the object component selector.
The class component selector can also be used to access the data types and constants of an interface.
intf=>type, intf=>const
The name intf of an interface must be to the left of the class component sector. The name type of a data
type defined using TYPES or the name const of a constant defined using CONSTANTS must be to the right of
the object component selector.
Note
It is also possible to access the static components of a class using the object component selector if an instance
of the class was created.
Example
...
factory=>oref->do_something( ).
...
intf~comp
In this case, the character ~ is the interface component selector. The name intf of an interface must be to the
left of the interface component selector. The name comp of the component must be to the right of the object
component selector.
The name intf~comp identifies the components of interfaces in classes or component interfaces in composite
interfaces.
Note
An interface contains each component exactly once, regardless of how it is composed of component interfaces.
All the interface components are at the same hierarchical level. The name of an interface component is
uniquely defined using intf~comp. intf is always the interface in which the component is declared. A direct
chaining of interface names intf1~...~intfn~comp is not possible.
Example
INTERFACE i1.
TYPES t1 TYPE string.
ENDINTERFACE.
INTERFACE i2.
INTERFACES i1.
METHODS m2 IMPORTING p1 TYPE i1~t1.
ENDINTERFACE.
CLASS c1 DEFINITION.
PUBLIC SECTION.
INTERFACES i2.
ENDCLASS.
...
DATA oref TYPE REF TO c1.
oref->i2~m2( ... ).
...
CLASS c1 IMPLEMENTATION.
METHOD i2~m2.
...
ENDMETHOD.
ENDCLASS.
Chainings
Whenever operands are grouped together from components, which themselves contain components, the
names of these components are composed from chains with multiple component selectors. The following rules
apply to these chained names:
The names to the left of each structure component selector must, as a combined group, address a
structured data type or a structure.
The names to the left of each object component selector must, as a combined group, address a
reference variable.
The class component selector can occur in a name exactly once as the first selector.
The interface component selector can only occur more than once in a label if other component
selectors are listed between the individual interface component selectors.
Example
Declaration of a nested structured data type struc2 in struc1 and a structure struc3 in an interface i1.
The component comp of struc3 is a data reference variable of the static type struc1. The i1 interface is the
component interface of i2 and the latter is implemented in c1. In c2, a static attribute is declared as the object
reference of the static type c1. The expression in the last line can be at an operand position that expects a data
object, and labels the component comp of the structure struc2 in a chaining that starts at class c2. A
prerequisite for use of the expression is that both reference variables, oref and dref, point to the respective
instances.
INTERFACE i1.
TYPES: BEGIN OF struc1,
...
BEGIN OF struc2,
...,
comp TYPE ...,
...,
END OF struc2,
...
END OF struc1.
DATA: BEGIN OF struc3,
...
dref TYPE REF TO struc1,
...
END OF struc3.
ENDINTERFACE.
INTERFACE i2.
INTERFACES i1.
ENDINTERFACE.
CLASS c1 DEFINITION.
PUBLIC SECTION.
INTERFACES i2.
ENDCLASS.
CLASS c2 DEFINITION.
PUBLIC SECTION.
CLASS-DATA oref TYPE REF TO c1.
ENDCLASS.
...
Note
The escape character may be required on rare occasions in which the compiler cannot tell the difference
between an operand and a reserved word of the same name. Otherwise, it can be used for the documentation
of operands in the source code.
Example
Without the escape character ! before CHANGING after USING, the following program extract would have
incorrect syntax, because a formal parameter must be entered after USING. Although the second escape
character is not necessary, it serves to document USING after CHANGING as a formal parameter.
Example
SUBMIT report.
Example
SUBMIT (dobj).
For statements that contain lists of operands or whole sections of statements, an internal table with a
character-type line type can often be specified in parentheses. The table lines must then contain the names of
the individual operands.
Example
Dynamic specification
At many operand positions, the system expects character-type data objects that contain the actual names of
the individual operands at the time of execution. To enable static specification of these operands, you must use
literals.
Example
Note
In some rare cases, there may be exceptions to these rules, in which operands must be set in parentheses or
in inverted commas as literals, but no data objects can be specified. This is noted in the corresponding syntax
descriptions.
Operand type
An operand position is typed using an operand type, which is complete or generic and can also be dependent
on other operand positions, as is the case for statements, for example. When a statement is executed, an
operand with a suitable data type is expected. If a data object specified at an operand position has a different
data type than the operand type, the system generally tries to convert the content of the data object to the
operand type on the basis of the conversion rules at write positions, and vice versa at read positions. Note that
every conversion leads to a longer runtime. If no appropriate conversion rules have been defined, or the
content cannot be converted, a syntax error occurs or an exception is raised. Deviations from this rule, for
example that the data object must exactly match the operand type, or the data object is to be interpreted as an
operand type, regardless of its actual type (casting), are described in the individual statements.
must be specified at operand positions for elementary data objects when the statement is executed.
Generic, typed formal parameters or field symbols can also be specified statically if they are typed more
generally than the expected type.
Note
In non-Unicode programs, flat structures can also be used at all operand positions where elementary fields are
expected. In Unicode programs, this is only possible if the components of the structure are flat and character-
like. In both cases, the structure is handled in the same way as a single data object of type c (implicit casting).
Read positions
Write positions
Subfield access
Read Positions
At a read position, the content of an operand is only read, and not changed, when the statement is executed.
Data objects can be specified as followed at read positions:
Specification of a literal.
Specification of a data object visible at this point using a name dobj, a field symbol <fs>, or a data
reference dref->* dereferenced using the dereferencing operator ->* (providing dref is specified in
full). The names of data objects here include the specification of a text symbol using text-idf, where
idf is the three-character code of the text symbols, or concatenations of reference variables. If a field
symbol is used, it must be assigned to a memory area and a data reference must point to a data
object. Otherwise an unhandleable exception is raised.
As an alternative to specifying a text symbol using text-idf, you can append the three-character
code of a text symbol to the text field literal in parentheses:
If the text symbol exists in the currently loaded text pool, then the content of the text symbol is used
instead of the text field literal, otherwise the literal is used.
If the data object is an internal table, the expressions dobj[], <fs>[], or dref->*[] can also be
used. For dobj[], this ensures that the table body is addressed and no header lines. If an internal
table does not have a header line, its simple name dobj (without []) is interpreted as the table body
at all operand positions. However, if an internal table does have a header line, its simple name dobj
(without []) is interpreted as the header line and not the table body at almost all operand positions.
The operand positions, used to interpret an internal table name with a header as the internal table, are
listed under internal tables with headers. Field symbols <fs> and data references dref->*, on the
other hand, only ever refer to the table body or a possible header line.
Specification of a subarea of a character-type or byte-type data object (or a character-type initial part
of a structure) by specifying an offset/length.
In some positions, number values must be specified directly as digits, although it is often not possible
to specify a sign (which is not the case with numeric literals). Examples are numbers specified in
declarative statements for the length of elementary data objects or for the initial memory requirements
of internal tables.
Notes
Text symbols cannot be listed at all read positions. For example, they are not permitted for specifying
the target of dynamic executions.
A system field should only be specified as an operand at a read position if its content is not set by the
same statement, as otherwise undefined behavior may occur.
At many operand positions, you can specify functions or expressions instead of data objects.
The logical expressions IS ASSIGNED and IS BOUND can be used to check whether field symbols or
data references.
Write Positions
At a write position, the content of the operand is changed when the statement is executed. Only changeable
data objects - that is, no literals, text symbols, constants, or non-changeable formal parameters - can be
specified as follows at write positions:
Specification of a visible data object at this point using a label dobj, a field symbol <fs>, or a
dereferenced data reference dref->* (if dref is typed completely). Similar to read items, you can
add [] for internal tables, to address the table body.
Substring Access
In operand positions, you can access subareas of the following data objects using an offset/length
specification:
Flat structures, whereby one of the following prerequisites must be satisfied in Unicode programs:
o The first Unicode fragment of the structure is flat and character-like, and the substring addressed
by the offset and length specifications is located within this fragment.
In write positions, only flat data objects are permitted; it is not possible to write to substrings of strings.
An offset or length specification is directly appended to either the dobj descriptor of the data object, an <fs>
field symbol, or a dereferenced data reference variable dref->* (only if the data reference variable is fully
typed):
dobj[+off][(len)]
<fs>[+off][(len)]
dref->*[+off][(len)]
The segment of the data object is used that has the offset specified in off and the length (in characters or
bytes) specified in len. For an offset specification without a length, the entire substring is addressed as of the
off character; for a length specification without an offset, the first len characters are addressed (different
rules apply for the ASSIGN statement).
The operands off and len expect data objects of the type i. These data objects must contain positive
integers, with the following exceptions.
A negative offset (but never length 0) can be specified if an <fs> field symbol is specified in the
ASSIGN statement for dobj.
If off is smaller than the length of dobj, an asterisk (*) can be specified for len. The upper limit of
dobj then determines the upper limit of the memory area.
If the prerequisites are not met or if the subarea defined by off and len is not completely contained in the
data object, an exception of class CX_SY_RANGE_OUT_OF_BOUNDS occurs. If off is specified as a
numeric literal, then this literal cannot be prefixed with a sign.
The offset and length specifications are counted in characters for character-like data objects and in bytes for all
other data objects. A character is equivalent to a byte in non-Unicode systems.
A substring specified by an offset or length specification is treated like a data object of the specified length for
which the data type depends on the data type of the original data object, the field symbol, or the data reference
variable, as shown below:
A memory area must not be addressed outside the field boundaries, except in the case of the ASSIGN
statement.
In the case of dynamic operand specification in brackets, no length specifications can be made.
If the length of the substring exactly corresponds to the length of the structure in a substring access to
a structure, the substring does not have data type c; instead, it is handled like the structure itself.
Notes
For read access to substrings of character-like data objects, predefined substring functions that allow
you to search by substring and offset/length specifications are available.
Obsolete syntax forms can still occur with substring access (apart from with classes).
Note
o Predefined functions
o Functional methods
o Method chaining
The return value of the last functional method meth is used as the operand. The return values of
the preceding functional methods must be reference variables that point to objects with the next
corresponding method. All methods must be called using the object component selector with the
exception of the first method meth1, which can be called using the class component selector if it
is a static method.
The instance attribute attr is used as the operand. Methods are called in the same way as
chained methods. The return value of the last method must point to an object that contains the
specified attribute.
Expressions that can be executed in a read position are calculation expressions, which means:
o Arithmetic expressions
o Bit expressions
o String Expressions
Notes
We combine functions with numerical return values and arithmetical expressions together in numeric
expressions.
We combine functions with character-like return value and string expressions as character-like
expressions.
Example
...
The type restrictions defined by the operand type apply in the operand positions. For example, no numerical
functions can be specified in a bit expression.
Notes
Specifying functional methods as actual parameters of methods enables the nesting of method calls in an
operand position.
The three types of calculation expression can be executed as operands of logical expressions, but
they cannot be mixed in one calculation expression.
Arguments of functions
Specification of the row number idx with reference to a table index during access to an internal table
in:
As well as functional methods, all predefined functions that have exactly one unnamed argument can
be specified in the following read positions (if nothing to the contrary is documented):
Operators
Expressions
Operators
ABAP contains the following operators:
Assignment Operators
The assignment operators = and ?= associate the source and target field of an assignment. The
operator = also associates actual parameters with formal parameters, for example in procedure calls
or when working with data clusters.
Arithmetic Operators
The arithmetic operators +, -, *, /, DIV, MOD, and ** associate two or more numeric operands with an
arithmetic expression. In addition, the characters + and - act as plus/minus signs in arithmetic
expressions.
Bit Operators
The bit operators BIT-AND, BIT-OR, and BIT-XOR associate two or more byte-like operands with a
bit expression. The bit operator BIT-NOT negates a byte-like operand.
String Operators
The string operator && chains two character-like operands to a string expression.
Relational Operators
The relational operators =, <>, <, >, <=, >=, and so on associate two operands of any data type with a
logical expression. There are additional relational operators for specific data types.
Boolean Operators
The Boolean operators AND, OR, and EQUIV associate the results of individual logical expressions with
a logical expression. The result of a logical expression is either true or false. The Boolean operator
NOT inverts the result of a logical expression.
Literal Operator
The literal operator & associates two literals or two string templates with a literal or a string template.
Expressions
At certain operand positions the following expressions can be formed:
Logical expressions
Arithmetical expressions
String expressions
Bit expressions
An expression has a result that is used as an operand in the statement. Logical expressions can contain
calculation expressions, that is, arithmetical expressions, string expressions, and bit expressions. The three
different calculation expression types cannot be mixed in one calculation type at the moment.
Note
Although the calculation expression types cannot be mixed directly, a different type of expression can occur as
an argument of a permitted function in another expression. In the same way, logical expressions can occur as
arguments of Boolean functions in calculation expressions.