Show TOC

Declaring Inline Variables ExplicitlyLocate this document in the navigation structure

Prerequisites

The local variable is declared inline using the statement addition DATA(temp).

Context

In a method implementation, you can convert inline declarations of one or several local variables into explicit declarations.

Example

The inline declaration DATA(temp) is removed and an explicit declaration is inserted in the method implementation.

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

Procedure

  1. In the implementation part, position the cursor on the inline declared variable.
  2. In the context menu, choose Quick Fix or use the shortcut (Ctrl 1).
  3. In the Quick Fix dialog box, double-click Declare local variable 'variable' explicitly.

Results

In the corresponding method, the new local variable (temp) is generated and replaces the undeclared inline variable. The type (i) is derived from the usage of the variable.

Example

Implementation part of the ABAP class after declaration:

CLASS cl_car IMPLEMENTATION. 
 METHOD drive. 
  DATA: temp TYPE i. 
  temp = nmin( val1 = 220 val2 = i_speed ). 
  current_speed = temp. 
 ENDMETHOD. 
ENDCLASS.