In the implementation part of an ABAP class, you can create a new method that returns the result of a selected expression. The tool declares this returning parameter with type Integer and the selected expression is replaced with a call to the new method.
Example
Here, the expression length * width is extracted into a method:
CLASS CL_METHOD_CHECK_AREA DEFINITION PUBLIC. " This class describes the 'length * width' extraction of an expression to a new method PUBLIC SECTION. DATA: length TYPE i, width TYPE i. METHODS: check_area RETURNING VALUE(r_result) TYPE abap_bool. ENDCLASS. CLASS CL_METHOD_CHECK_AREA IMPLEMENTATION. METHOD check_area. IF length * width > 100. r_result = abap_false. ELSE. r_result = abap_true. ENDIF. ENDMETHOD. ENDCLASS.
The extracted method is created with the name new_method.
In the private section of the definition part, the name of the extracted method (new_method) is added and the appropriate parameters are declared.
In the implementation part, the selected expression is added in a new method. In the former call, the expression is replaced with the name of the extracted method (new_method).
Example
ABAP class after extraction:
CLASS CL_METHOD_CHECK_AREA DEFINITION PUBLIC. "This class describes the 'length * width' extraction of an expression for a new method. PUBLIC SECTION. DATA: length TYPE i, width TYPE i. METHODS: check_area RETURNING VALUE(r_result) TYPE abap_bool. PRIVATE SECTION. METHODS: new_method RETURNING VALUE(r_result) TYPE i. ENDCLASS. CLASS CL_METHOD_CHECK_AREA IMPLEMENTATION. METHOD check_area. IF new_method( ) > 100. r_result = abap_false. ELSE. r_result = abap_true. ENDIF. ENDMETHOD. METHOD new_method. r_result = length * width. ENDMETHOD. ENDCLASS.