
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.
Example
The expression length * width is to be extracted into a new local variable:
CLASS cl_local_variable_expression IMPLEMENTATION. METHOD check_area. DATA: length, width, result TYPE i. IF ( length * width > 100 ). result = abap_true. ENDIF. ENDMETHOD. ENDCLASS.
In the implementation part of the method, the new variable (area) is defined. The expression is assigned to the new variable. In the IF statement, the expression is replaced with the new variable.
Example
ABAP class after extraction:
CLASS cl_local_variable_expression IMPLEMENTATION.
METHOD check_area.
DATA: length, width, result TYPE i,
area TYPE p.
area = length * width.
IF ( area > 100 ).
result = abap_true.
ENDIF.
ENDMETHOD.
ENDCLASS.