Technical Articles
Buffering CDS View Entities
A CDS entity buffer temporarily caches the data retrieved from a CDS view entity into the shared memory of the current AS ABAP instance.
Starting with the following ABAP releases, buffering of CDS view entities is supported:
- SAP BTP, ABAP Environment 2202
- ABAP platform cloud 2202
This new object type (R3TR/DTEB) marks the last step towards feature completeness comparing the new CDS view entities with CDS DDIC-based views.
Please refer to the related blog posts for further information on CDS view entities and migrating from CDS DDIC-based views.
Additionally, please get informed what objects are typical candidates for buffering and check the content of ABAP table buffering.
What’s different?
The following table contrasts buffering of CDS DDIC-based views and new CDS view entities:
Attribute | CDS DDIC-based view | CDS view entity |
Buffered Object | CDS-managed DDIC view | CDS view entity |
Definition of Buffer | Using annotations | Real syntax |
Change of SAP-delivered objects | Requires modification | Defines additional buffer object |
Generic Buffer: Number of key elements | Client column (MANDT) counts | Client column (MANDT) does not count |
Prepare CDS View Entity for Buffer Definitions
The following annotation makes sure your CDS view entity is prepared for buffer definitions:
@AbapCatalog.entityBuffer.definitionAllowed: true
This annotation is required as a first step to allow subsequent creation of buffer definition objects. The annotation itself does not lead to a buffer, but ensures the following restrictions apply:
- Views with parameters are not supported
- Views with unstable calculations are not supported (e.g. utcl_current, tstmp_current_utctimestamp)
- Session variables (other than client) can not be used
- Base objects have to be tables
- Key length > 900 bytes is not supported
- LOB key fields are not allowed
- Views without key fields can not be buffered
- Data aging in base tables is not allowed
Syntax
DEFINE VIEW ENTITY BUFFER ON <entity_name>
TYPE SINGLE|GENERIC|FULL
LAYER CORE|LOCALIZATION|INDUSTRY|PARTNER|CUSTOMER
[NUMBER OF KEY ELEMENTS <number>] // Needed for buffer type "GENERIC"
Attribute Name | Description |
LAYER | Multiple buffers on the same entity can be defined on different layers. Thus, it is allowed to overrule a buffer definition of a previous software layer. E.g. a buffer definition in layer CORE can be disabled by a buffer definition in layer CUSTOMER. |
TYPE | The buffer definition types are identical to the buffering type specifications in SE11 / technical settings or values of @AbapCatalog.buffering.type. Additionally, type NONE can be specified to disable an existing buffer definition. |
NUMBER OF KEY ELEMENTS |
The key element specification is required for generic buffering, as set for CDS DDIC-based view buffering with annotation @AbapCatalog.buffering.numberOfKeyFields. The client column is not taken into account. |
Layering relevance
Example
Right click on the CDS view entity and choose “New Entity Buffer”
Specify the Name, Description and Package of the buffer definition
Edit the buffer definition source code
After activating the DTEB object ZDEMO_BUFFER, queries to entity DEMO_CDS_FULL_BUFFERED_VIEW are buffered on the application server.
News with 2022 / 2208
With the following releases, functional scope of DTEB buffer definitions has increased:
- SAP BTP, ABAP Environment 2208
- ABAP platform cloud 2208
- S/4HANA 2022
The restriction “Base objects have to be tables” is not valid anymore. Base objects of type CDS view entity are now supported in addition to tables.
To allow a CDS view entity to function as a base object for buffering, it is required this base CDS view entity specifies annotation @AbapCatalog.entityBuffer.definitionAllowed : true.
Schema of View on View buffering
In case of questions, please feel free to leave a comment.
Hi Joerg. How often buffer refreshes? Can developer clear buffer manually?
Hi Aleksandr,
The synchronization and reset mechanisms are identical to buffered table and DDIC view data, please refer to https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenbuffer_synchro.htm for further information.
Kind regards, Joerg
Thanks, Joerg.
Will buffered tables that are included in buffered CDS Entities be stored again the shared memory, or will there be a reference to the shared table?
Thanks, Stephan
Hi Stephan
Data is maintained for each buffered object individually, so if queries on the table and the view occur, data is kept for both objects individually in the buffer.
This is the same as for buffered SE11 views and buffered DDIC based CDS views.
Please keep in mind that CDS Views might contain aggregates, where predicates, JOINs, UNIONs.
An application might need to consider reviewing their data accesses if a) data is to be buffered, b) amount of data is large, and c) tables and views are accessed.
Kind regards, Joerg
Hi Jörg, hi All,
This is a great feature (buffering data retrieved from CDS view entity on app server), which is missing for traditional DDC CDS views. I have tried it with READ ENTITIES EML command and it works. Buffering seems NOT to be working if I will use traditional SELECT statement against CDS view entity having entity buffer. In such case ATC check complains (if the SELECT statement occurs inside the loop) that non-buffered access to db may cause high traffic between db and app server. The usage of READ ENTITIES (instead of SELECT) inside the loop eliminates ATC issue. But then next problem appears: I cannot select required data using READ ENTITIES and selection criteria against the NON-KEY FIELDS of the CDS view entity (and still keep the usage of buffering mechanism described here). I am the beginner when it comes to RAP programming, so would be grateful for any hints for the problem I have raised in this comment.
Take care
Bogdan
Hi Bogdan,
Buffering of data is supported for DDIC based CDS views (using only annotations) as well as CDS view entities (using annotaitons and entity buffers).
Please keep in mind that predicates for generic or single buffered objects must include the generic or all key columns. If any of the restrcitions are not met by the query, the buffer is not used.
With regards to READ ENTITY EML, please check your usage, it should not be used in loops.
Kind regards, Joerg
Thanks Joreg for the helpful hints and links:
Please keep in mind that predicates for generic or single buffered objects must include the generic or all key columns. If any of the restrcitions are not met by the query, the buffer is not used.
This is now crystal clear to me :-).
I am surprised with this limit:
With regards to READ ENTITY EML, please check your usage, it should not be used in loops.
...as the main advantage of the buffering data on app server can be observed while accessing over and over again the same database records inside the loop. I know, that in such case it is better to move SELECT (or READ ENTITIES) outside the loop, but in my case we are talking about the generic, universal solution, where the data access outside the loop cannot be 100% ensured. I have checked, that it is possible to retrieve the data from VIEW ENTITY using both statements: READ ENTITIES or old good SELECT. But as I understood from the documentation the usage of SELECT against VIEW ENTITY will skip the entity buffer - right? This is why I decided to use the combination of entity buffer plus READ ENTITIES statement to achieve better performance in case of data retrieval inside the loop. Is there any significant difference between READ ENTITIES and SELECT statements in case they are called inside the loop?
Best regards
Bogdan
Hi Bogdan,
>SELECT against VIEW ENTITY will skip the entity buffer - right?
No. The blog article "Buffering CDS View Entities" is about entity buffering on the ABAP server for ABAP SQL SELECT statements. So buffering an entity using a CDS entity buffer is the perfect measure for ABAP SQL SELECTs.
The behavior of the ABAP table buffer is described in detail in the above mentioned links, namely https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abensap_puffering.htm.
With regards to READ entity and RAP transactional buffering, I was told the RAP guide ist a good starting point to understand these concepts:
With regards to READ ENTITY and buffering in RAP (transactional buffering), I am not an expert. Please check the RAP Guide for this: https://help.sap.com/docs/btp/sap-abap-restful-application-programming-model/abap-restful-application-programming-model?locale=en-US.
Best regards, Joerg
EDIT: Added intro to 2nd link (it is for the RAP concepts, i.e. RAP transactional buffering).
Hi, if we select a cds view which is not buffered, but fetch the association which is buffered in an open sql, will we benefit from the buffer?
for example:
Select
from <nonbufferedcds> as cds
fields
cds~column1,
\_bufferedassociation-column2
into table @data(lt_result)
Hi Sebastien,
In this case, the JOIN that is generated in SQL by the association path is executed on Hana DB. No ABAP buffered data is used.
Best Regards, Joerg