Show TOC

Changing Visibility of MembersLocate this document in the navigation structure

In an ABAP class or ABAP interface, you can move a member definition between the public, protected, and private sections in order to switch its availability.

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 refactoring option can be triggered for the following member types:

  • Types
  • Constants
  • Attributes
  • Methods
  • Events
  • Aliases
Note Depending on the current section of the selected member, two refactoring aids are available as shown in the following table:
Current Section Option 1 Option 2
Private Make protected Make public
Protected Make private Make public
Public Make private Make protected

Example

Before Execution After Execution

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

The speed attribute is declared in the private section.

The declaration of the speed attribute has has been removed from the private section and added in the public section.

Decreasing Visibility

Some refactoring aids decrease (public > protected > private > local) the visibility of members of a class.

So, if the visibility of the target section is more restrictive than in the current section, the refactoring will check whether any usages exist that will no longer be available after the change. In this case, the developer is informed and can decide to reject or apply the change.

Increasing Visibility

Some refactoring aids increase (local > private > protected > public) the visibility of members or locals inside a class.

So, if the visibility of a member (or local) is increased, subsequent processing might depend on other declarations that are no longer visible for the member. In this case, the developer is informed and can decide to reject or apply the change.

Procedure

  1. In the definition part, position the cursor on the member you want to move to another section.
  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 Make 'member' protected, Make 'member' public, or Make 'member' private. Note that the corresponding refactoring options for the possible target sections will be displayed depending on the current cursor position.