0% found this document useful (0 votes)
20 views4 pages

Rap - Interface & Abstarct Class

The document discusses the use of interfaces and abstract classes in RAP, highlighting the If_rap_query_provider interface for common services and the IF_SADL_EXIT_CALC_ELEMENT_READ for virtual elements in projection views. It explains the characteristics of abstract classes, particularly the local saver class, which allows for inheritance and partial implementation. The document concludes with guidelines on when to use interfaces versus abstract classes based on their structural relationships and functionalities.

Uploaded by

rbharathisap
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views4 pages

Rap - Interface & Abstarct Class

The document discusses the use of interfaces and abstract classes in RAP, highlighting the If_rap_query_provider interface for common services and the IF_SADL_EXIT_CALC_ELEMENT_READ for virtual elements in projection views. It explains the characteristics of abstract classes, particularly the local saver class, which allows for inheritance and partial implementation. The document concludes with guidelines on when to use interfaces versus abstract classes based on their structural relationships and functionalities.

Uploaded by

rbharathisap
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Learning Interface and abstract class with RAP

Interface:
1.) If_rap_querry_provider:

This interface is commonly used in unmanaged RAP with custom entities as data
models. The logic is implemented in the If_rap_query_provider~select method of
the query implementation class.
• If classes are not related by inheritance but need to provide common
services (like the select method here), an interface is used.
• The interface offers shared functionality, which future classes must
implement.
• By default, interfaces are final, meaning they cannot be inherited or
instantiated.
• In an interface, the select method is declared in the public section (we can
only declare public, as both inheritance and instantiation is not allowed).

Custom entity

Querry implementation class


2.) IF_SADL_EXIT_CALC_ELEMENT_READ:

In rap, virtual elements are used in projection view to expose a data in ui or odata
service, which does not exist in db. Here the
IF_SADL_EXIT_CALC_ELEMENT_READ~CALCULATE method is used to set the
value for the virtual element.

Virtual element in projection view

Implementation class
Abstract class:

1.) Local saver class:

• The local saver class is implicitly abstract and final by default.


• An abstract class is used here because there is an inheritance relationship,
where the local handler class is inheriting from the cl_abap_behavior_saver
class.
• Since it is an abstract class, it can be inherited but not instantiated.
• Additionally, you can observe that all methods are written with protected
visibility. In an abstract class, methods can be defined as public or
protected, while in an interface, only public methods are allowed.
• Furthermore, you'll notice that there are implementations for methods
within the same class. This is possible because an abstract class can
contain both concrete and abstract methods. This allows for partial
implementation, where some methods can be implemented, and others
can remain abstract for subclasses to implement.

Local saver class in abap behaviour pool.


Interface vs Abstract Class
When to use an interface:
• Primarily to leverage abstraction, an interface provides a blueprint for common
functionalities but does not provide any implementation.
• If you have classes that are not related by inheritance but still need to provide
common services to their users, an interface is appropriate.
When to use an abstract class:
• Abstract classes offer a similar form of abstraction to interfaces, but they are
used when classes are related by inheritance and need to act as an incomplete
blueprint. In this case, some methods must be implemented within the class
itself, while others remain abstract.

For any queries, please feel free to reach out to me on LinkedIn:


www.linkedin.com/in/arunagirish-b-987220225

You might also like