
You want to use an attribute of an interface. But you have forgotten to use the name of the interface as a prefix, followed by ~.
You have the following options for correcting an access to the interface attributes by:
You can reuse existing interface members by adding the corresponding interface name and the '~' component selector.
Example
| Before Execution | After Execution |
|---|---|
![]() |
![]() |
| The used speed variable is not declared in the cl_car class but in the if_car interface. | The speed variable has been replaced by if_car~speed. |
INTERFACE if_car.
DATA: speed TYPE i.
ENDINTERFACE.
CLASS cl_car DEFINITION.
PUBLIC SECTION.
INTERFACES: if_car.
METHODS: drive
IMPORTING
i_speed TYPE i.
ENDCLASS.
CLASS cl_car IMPLEMENTATION.
METHOD drive.
IF speed = 0.
...
ENDIF.
ENDMETHOD.
ENDCLASS.You generate and reuse an alias from a variable that points to the ~ component selector of an interface.
Example
| Before Execution | After Execution |
|---|---|
![]() |
![]() |
|
The used speed variable is not declared in the cl_car class but in the if_car interface. |
The name speed has been declared as alias for the if_car~speed attribute in the public section of the cl_car class where the interface is implemented. This alias can now be used in the implementation. This enables you to access the defined attribute directly without the if_car~ prefix. Note ADT automatically uses the name of the attribute for the
alias. You can rename the alias after execution.
|
INTERFACE if_car.
DATA: speed TYPE i.
ENDINTERFACE
CLASS cl_car DEFINITION.
PUBLIC SECTION
INTERFACES: if_car.
METHODS: drive
IMPORTING
i_speed TYPE i.
ENDCLASS.
CLASS cl_car IMPLEMENTATION.
METHOD drive.
IF speed = 0.
...
ENDIF
ENDMETHOD.
ENDCLASS.