ABAP Keyword Documentation → ABAP - Reference → ABAP Syntax → ABAP Statements → Operands
Names for Individual Operands
An individual operand, meaning an operand that is not an expression, can be elementary or made up of components. Composite operands are:
- Structured data types or data objects (structure)
- Instances of classes (objects)
- 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
- components that are unique in the current context
- superunits made up of components
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.
Other versions: 7.31 | 7.40 | 7.54
Structure Component Selector
A component comp
of a structured data type or a structure struct
is accessed using the name
struct-comp
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
.
DATA struc TYPE spfli.
...
... struc-carrid ...
Object Component Selector
A component comp
of an object is accessed using the name
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 componentscomp
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 componentscomp
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.
...
DATA oref TYPE REF TO c1.
... oref->a1 ...
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
.
DATA dref TYPE REF TO sflight.
...
... dref->carrid ...
Class Component Selector
A static component comp
of a class can be accessed using the name
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
Declaration of a class factory
and access to its static attribute oref
.
CLASS factory DEFINITION CREATE PRIVATE.
PUBLIC SECTION.
CLASS-DATA oref TYPE REF TO factory.
CLASS-METHODS class_constructor.
METHODS do_something.
ENDCLASS.
...
factory=>oref->do_something( ).
...
CLASS factory IMPLEMENTATION.
METHOD class_constructor.
CREATE OBJECT oref.
ENDMETHOD.
METHOD do_something.
...
ENDMETHOD.
ENDCLASS.
Interface component selector
A component comp
of an interface is accessed using the name
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.
Programming Guideline
Address interface components using interface reference variables
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
Declaration of interfaces and access to their components.
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.
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.
...
... c2=>oref->i1~struc3-dref->struc2-comp ...
Escape Character for Names
The character !
can be written directly before a name in order to distinguish it from an
ABAP word with the same name in a statement. With the
exception of the first word, each word of a statement that is preceded by the escape character is interpreted
as an operand, and not as an ABAP word, when the program is generated. The escape character itself is not part of a name and is ignored when the statement is executed.
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.
FORM test USING !CHANGING
CHANGING !USING.
using = changing.
ENDFORM.