Show TOC

Correcting an Interface Attribute AccessLocate this document in the navigation structure

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 ~.

Context

You have the following options for correcting an access to the interface attributes by:

Adding the Interface Name

You can reuse existing interface members by adding the corresponding interface name and the '~' component selector.

Prerequisites

This functionality is provided in SAP NetWeaver Release 7.40 SP08 and higher.

Context

Example

Before Execution After Execution

To copy the source code example, click here

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.

Procedure

  1. In the implementation part, position the cursor on the attribute that is defined in the interface.
  2. Get the quick assist proposals by choosing Quick Fix from the context menu (shortcut Ctrl 1) or by using the Quick Assist view.
  3. Apply Use similar attribute ....
    Note In this example, you can also choose Use similar parameter ... to use the importing parameter.

Code Example Before 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.

Generating an Alias

You generate and reuse an alias from a variable that points to the ~ component selector of an interface.

Prerequisites

This functionality is provided in SAP NetWeaver Release 7.40 SP08 and higher.

Context

Example

Before Execution After Execution

To copy the source code example, click here

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.

Procedure

  1. In the implementation part, position the cursor on the attribute for which you want use an alias.
  2. Get the quick assist proposals by choosing Quick Fix from the context menu (shortcut Ctrl 1) or by using the Quick Assist view.
  3. Apply Declare alias ....

Code Example Before 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.