Show TOC

Converting Local Variables to ParametersLocate this document in the navigation structure

Context

In SAP NetWeaver 7.4 or higher, you can convert a local variable into a parameter.

You can create one of the following parameter types:

  • Importing
  • Returning
  • Changing
  • Exporting

Example

The local variable current_speed is to be promoted as a parameter:

CLASS cl_local_variable_parameter DEFINITION PUBLIC CREATE PUBLIC . 
 PRIVATE SECTION. 
  CONSTANTS max_speed VALUE 100. 
  METHODS check_speed 
   RETURNING 
    VALUE(result) TYPE i. 
ENDCLASS. 
 
CLASS cl_local_variable_parameter IMPLEMENTATION. 
 METHOD check_speed. 
  DATA current_speed TYPE i. 
  IF ( current_speed > max_speed ). 
   result = abap_false. 
  ENDIF. 
 ENDMETHOD. 
ENDCLASS.

Procedure

  1. In the source code editor, navigate to the method and position the cursor on the definition of the local variable.
  2. In the context menu, choose Quick Fix or use the shortcut (Ctrl 1).
  3. In the Quick Fix dialog box, double-click Convert 'local variable' to [importing / changing / exporting / returning] parameter.

Results

The declaration of the importing parameter (current_speed) is added to the method signature. In addition, the declaration of the former local variable is deleted in the implementation.

Example

ABAP class after conversion:

CLASS cl_local_variable_parameter DEFINITION PUBLIC CREATE PUBLIC . 
 PRIVATE SECTION. 
  DATA: result TYPE i. 
  CONSTANTS max_speed VALUE 100. 
  METHODS check_speed 
   IMPORTING 
    current_speed TYPE i. 
   RETURNING 
    VALUE(result) TYPE i. 
ENDCLASS. 

CLASS cl_local_variable_parameter IMPLEMENTATION. 
 METHOD check_speed. 
  IF ( current_speed > max_speed ). 
   result = abap_false. 
  ENDIF. 
 ENDMETHOD. 
ENDCLASS.