Show TOC

Declaring Variables from UsageLocate this document in the navigation structure

Context

You can create an attribute, local variable, or a parameter (importing, returning, changing, or exporting) on the basis of a usage in a method implementation.

Example

The variable speed is used but not yet declared:

CLASS cl_car DEFINITION. 
 PUBLIC SECTION. 
  METHODS drive. 
 PRIVATE SECTION. 
ENDCLASS. 
 
CLASS cl_car IMPLEMENTATION. 
 METHOD drive. 
  speed = 50. 
 ENDMETHOD.
ENDCLASS.

Procedure

  1. In the implementation part, select the usage that you want to replace with a parameter.
  2. In the context menu, choose Quick Fix or use the shortcut (Ctrl 1).
  3. In the Quick Fix dialog box, select Declare [importing / changing / exporting / returning] parameter from usage or Declare local variable from usage.

Results

In the private section, the attribute (speed) is added and declared.

Example

ABAP class after extraction:

CLASS cl_car DEFINITION. 
 PUBLIC SECTION. 
  METHODS drive. 
 PRIVATE SECTION. 
  DATA: speed TYPE i.
ENDCLASS. 
 
CLASS cl_car IMPLEMENTATION. 
 METHOD drive. 
  speed = 50. 
 ENDMETHOD. 
ENDCLASS.