Show TOC

Extracting Local Variables from ExpressionsLocate this document in the navigation structure

In a method of an ABAP class, you can create a new variable on the basis of an expression. This means, the tool adds a new local variable and assigns the expressions. Note that other occurrences of the same expression are not replaced with the new variable.

Prerequisites

This functionality is provided in SAP NetWeaver Release 7.31 SP14 and higher as well as Release 7.40 SP05 and higher.

Context

Example

Before Execution After Execution

To copy the source code example, click here Code Example Before Execution

The expression i_speed * '1.6' is to be extracted into a new local variable. In the implementation part of the method, the new local variable (kmh) is defined. The expression is assigned to the new local variable. In the speed statement, the expression is replaced with the new variable.

Procedure

  1. In the implementation part, select the entire expression that you want to replace with a new variable.
  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 Extract local variable.