Show TOC

Assigning a Statement to a New VariableLocate this document in the navigation structure

Prerequisites

This quick assist is provided if the statement has a result.

Context

You can create an attribute or local variable in order to assign the result of a functional method call. A functional method provides a returning parameter.

Example

The new variable new_speed is to be added to replace the call of the speed_control method:

CLASS cl_car DEFINITION PUBLIC. 
 PUBLIC SECTION. 
  METHODS: drive 
   IMPORTING 
    i_speed TYPE i. 
 PRIVATE SECTION. 
ENDCLASS. 
 
CLASS cl_car IMPLEMENTATION. 
 METHOD drive. 
  nmin( val1 = 220 val2 = i_speed ). 
 ENDMETHOD. 
ENDCLASS.

Procedure

  1. In the implementation part, position the cursor in front of the functional method call for which you want to create a new variable or attribute.
  2. In the context menu, choose Quick Fix or use the shortcut (Ctrl 1).
  3. In the Quick Fix dialog box, double-click Assign statement to new local variable or Assign statement to new attribute.

Results

In the implementation part of the method, the new variable (new_variable) is declared.

At the cursor position, the new variable is added and assigned to the existing statement.

Now, you can change the new name (for example, new_speed).

Example

ABAP class after the assignment:

CLASS cl_car DEFINITION PUBLIC.
 PUBLIC SECTION.
  METHODS: drive
   IMPORTING 
    i_speed TYPE i.
 PRIVATE SECTION.
ENDCLASS.
 
CLASS cl_car IMPLEMENTATION.
 METHOD drive. 
  DATA: new_speed TYPE i.
  new_speed = nmin( val1 = 220 val2 = i_speed ).
  nmin( val1 = 220 val2 = i_speed ).
 ENDMETHOD.
ENDCLASS.