Show TOC

Reusing Existing ConstantsLocate this document in the navigation structure

You can reuse a member or local constant that has already been generated. Note that all occurrences of the same literal remain unchanged.

Prerequisites

An existing constant is already defined for the same literal in a certain ABAP class.

Context

Example

Before Execution After Execution
CLASS cl_car DEFINITION. 
 PUBLIC SECTION . 
  METHODS: drive 
   IMPORTING 
    i_speed TYPE i. 
 PRIVATE SECTION . 
  CONSTANTS max_speed TYPE i VALUE 220. 
  DATA: current_speed TYPE i. 
ENDCLASS. 
 
CLASS cl_car IMPLEMENTATION. 
 METHOD drive. 
  IF i_speed > 220. 
   current_speed = 220. 
  ELSE. 
   current_speed = i_speed. 
  ENDIF. 
 ENDMETHOD. 
ENDCLASS.

To copy the source code example, click hereCode Example Before Execution

CLASS cl_car DEFINITION. 
 PUBLIC SECTION . 
  METHODS: drive 
   IMPORTING 
    i_speed TYPE i. 
 PRIVATE SECTION . 
  CONSTANTS max_speed TYPE i VALUE 220. 
  DATA: current_speed TYPE i. 
ENDCLASS. 
 
CLASS cl_car IMPLEMENTATION. 
 METHOD drive. 
  IF i_speed > max_speed. 
   current_speed = max_speed. 
  ELSE. 
   current_speed = i_speed. 
  ENDIF. 
 ENDMETHOD. 
ENDCLASS.
The literal '200' is to be replaced with an existing constant In the source code of the ABAP class, all occurrences of the literal are replaced with the name of the existing constant.

Procedure

  1. In the source code editor, select the literal that is to be replaced by an existing constant.
  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. In the Quick Fix dialog box, double-click Use local constant or Use member constant.