Converting Locals to Class Members
You can convert definitions of a local variable, local constant, or local type and paste them into the private section of the current class. Therefore, you can make certain local elements of individual methods available for all methods within an ABAP class.
Prerequisites
Context
Example
| Before Execution | After Execution |
|---|---|
To copy the source code example, click here Code Example Before Execution |
|
|
The speed variable is declared local variable inside the implementation of the drive method. |
The local declaration has been removed and replaced by an attribute declaration. The attribute has been added to the private section. |
Procedure
- In the implementation part, position the cursor on the corresponding local declaration (variable, constant, or type).
- Get the quick assist proposals by choosing Quick Fix from the context menu (shortcut Ctrl 1) or by using the Quick Assist view.
- Apply Convert 'local variable' to attribute, Convert 'local constant' to constant, or Convert 'local type' to class type.