Hello,

Sign up to join our community!

Welcome Back,

Please sign in to your account!

Forgot Password,

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask a question.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

SAP EWM Help Latest Questions

  • 0
  • 0
DPM125
Beginner

what are access specifiers in SAP and tell the difference between them and explain their use ?

Access specifiers define the visibility and accessibility of class components such as attributes, methods, and events. They help in implementing encapsulation, a core concept of object-oriented programming (OOP), by controlling which parts of a class can be accessed from outside the class or by its subclasses.

There are three main access specifiers in SAP ABAP:

1. PUBLIC

2. PROTECTED

3. PRIVATE

Steps to Use Access Specifiers in ABAP Classes

1. Create a class using CLASS…ENDCLASS.

2. Define sections for PUBLIC, PROTECTED, and PRIVATE using PUBLIC SECTION, PROTECTED SECTION, PRIVATE SECTION.

3. Place the methods or attributes under the appropriate section based on the intended visibility.

4. Instantiate the class and test accessibility from outside and inside (e.g., subclasses).

Access Specifier Visibility Scope Accessible From Use Case Example

PUBLIC High Anywhere (outside class too) General methods available to all

PROTECTED Medium Inside class + subclasses Internal logic exposed to subclasses only

PRIVATE Low Only inside the class Helper methods/data hidden from outside

Access specifiers in SAP ABAP enable secure and modular class design:

· Use PUBLIC for features meant to be openly accessible.

· Use PROTECTED when you want subclass access but hide from external calls.

· Use PRIVATE to fully encapsulate internal logic or helper routines.

so Outside the class

we cannot call the Private and protected Methods or attributes

 

Related Questions

Leave an answer

Leave an answer