Show TOC

Changing Visibility of MembersLocate this document in the navigation structure

Context

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.

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

The speed_check method is moved from the private section to the public section:

CLASS cl_visibility_member DEFINITION PUBLIC CREATE PUBLIC . 
 PUBLIC SECTION . 
 PRIVATE SECTION . 
  METHODS: speed_check. 
ENDCLASS.
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. In the context menu, choose Quick Fix or use the shortcut (Ctrl 1).
  3. In the Quick Fix dialog box, double-click 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.

Results

The source code editor moves the entire member definition to the selected section.

The cursor remains at the original position. This enables you to move further members into another section directly from your current position.

Example

The member of the speed_check method is moved to the public section:

CLASS cl_visibility_member DEFINITION PUBLIC CREATE PUBLIC . 
 PUBLIC SECTION . 
  METHODS: speed_check. 
 PRIVATE SECTION . 
ENDCLASS.