Show TOC

Deleting Unused VariablesLocate this document in the navigation structure

In a source code-based development object, you can delete unused variables in the entire object or only in marked source code. This enables you to automatically find and delete unused variable declarations in order to clean up source code.

Prerequisites

This functionality is provided in SAP NetWeaver Release 7.31 SP06 and higher as well as Release 7.40 SP02 and higher.

Context

This function deletes the following types of unused variables:

  • Local variables within the scope of a method, function module, or form routine
  • Global variables within a class, function group, or report.
    Note In a class, no variables that are declared in the PUBLIC or PROTECTED sections are deleted. The deletion does not delete seemingly unused variables that could be referenced from outside.
Note Deleting an unused variable can cause another variable to become unused if it was referenced. The deletion of unused variables does not perform recursive checks for such variables. It can therefore be useful to run the function more than once in order to find and delete unused variables in such cases. You can undo the deletions using the shortcut Ctrl Z.

Example

Before Execution After Execution

To copy the source code example, click here Code Example Before Execution

The cl_car class contains the name and i_speed as well as the private variables current_speed, delta, temp, and max public variables.

Except the temp variable, all other variables are not used.

Only the unused current_speed, delta, and max private variables have been removed.

Note To see which unused variables have been deleted, hover the marker in the mark bar and check the displayed tooltip.

Procedure

  1. You can delete all unused variables of a source code-based development object:
    1. In the source code editor, position the cursor anywhere within the source code.
    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. Apply Start of the navigation path Source Code Next navigation step Delete Unused Variables (All) End of the navigation path or shortcut (Alt U).
  2. You can delete all unused variables in a selected section of source code:
    1. In the source code editor, select the source code in the method where you want to perform the deletion.
    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. Apply Start of the navigation path Source Code Next navigation step Delete Unused Variables (Selection) End of the navigation path or shortcut (Alt Shift U).