Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
mainak-aich
Participant
2,927
Introduction:

In this blog post, I would like to share my knowledge on how operation augmentation can be used to implement consumption specific requirement in RAP ABAP based application.

Goal:

When developing the transactional application on SAP, as a developer our goal is to define the BO once and implement all the consumption specific requirements inside the corresponding consumption CDS view aka BO Projection view in RAP. This is explained in the diagram below.


Consumption Scenarios of BO


Therefore, while developing a particular RAP BO Consumption view, often it will be required to implement following possible requirements.

  • Applying filter criteria by adding 'WHERE' condition inside the BO Projection View

  • Apply default value to different fields in object page while creating a new BO instance. The similar requirement was also explained by ramjee.korada in his blog https://blogs.sap.com/2022/01/22/abap-rap-functions-defaulting-fields-during-new-object-creation-in-...

  • Any other consumption specific scenarios which requires specific behavior of the UI fields for different Fiori UI. E.g. In Fiori App1, a field F1 should be displayed as read-only whereas in Fiori App2, the same field F2 should be editable. Here both the apps are built on top the same RAP BO


Now if you need to implement these kind of requirements in RAP, you can consider implementing operation augmentation. You can read more about it here  https://help.sap.com/docs/abap-cloud/abap-rap/operation-augmentation?version=sap_btp

Business Example:

Now let me share an example on how to define and implement operation augmentation.

Scenario - I will be developing 2 Fiori Apps on top of my RAP BO. They have been developed using RAP managed behavior.


In Fiori App1, I will show all the entries in the List Report UI which has SupersessionType = 'C'. The BO Projection view looks like the following -



define root view entity ZC_SuperSessionChoice
provider contract transactional_query

as projection on ZI_SuperSessionChoice

{

…..

ValidFrom,

Active,

Deleted,

…..

}

where

SupersessionType = 'C'

and Deleted = ' '

Since, we are restricting only the certain fields to be visible in the UI, therefore now whenever we need to create a new instance from the Fiori UI, we need to ensure filling SupersessionType = 'C' in the new record. Otherwise, RAP runtime will throw provider error. Besides, another requirement which says few of the fields e.g. ValidFrom shall be defaulted by current date when creating a new instance.


Fiori App2 will have a completely different UI requirement to default the UI with some other values. But the way to implement the requirement would be similar like Fiori App1. Therefore, I am not explaining it separately.

Implementation Steps:

Now I will show how the above requirements can be implemented using operation augmentation in BO Projection.


 

  1. I will augment the 'CREATE' operation. So my BO Projection BDEF looks like below -


projection implementation in class zbp_c_supersessionchoice unique;

strict ( 2 );

use draft;

use side effects;

define behavior for ZC_SuperSessionChoice alias Choice

{

use create ( augment );



}

2. I will create the behavior implementation of the above BDEF. The augmented create operation implementation looks like below.



METHOD augment_create.

DATA augment_create TYPE TABLE FOR CREATE ZI_SuperSessionChoice.

LOOP AT entities ASSIGNING FIELD-SYMBOL(<entity>).

APPEND VALUE #( %cid = <entity>-%cid

%is_draft = <entity>-%is_draft

%key = <entity>-%key

SupersessionType = zcl_supersession_helper=>gc_ss_type-choice

channel = zcl_supersession_helper=>gc_channel-both

validfrom = cl_abap_context_info=>get_system_date( )

%control-SupersessionType = if_abap_behv=>mk-on

%control-channel = if_abap_behv=>mk-on

%control-ValidFrom = if_abap_behv=>mk-on

) TO augment_create.

ENDLOOP.

MODIFY AUGMENTING ENTITY ZI_SuperSessionChoice

CREATE

FROM augment_create.

ENDMETHOD.

Here I am augmenting the instance being created by filling up some fields beforehand e.g. SuperSessionType with C, validfrom with current date etc. .


 

This will also default those fields values when the instance is displayed in object page during create. Since I filled channel = 'Both' and Valid From = Current date, the same are defaulted when I click on 'Create' button and the object page is displayed.



Default Values in Object Page fields during Create Operation


 

Conclusion:

As shown above, the RAP BO is unchanged. Only the BO projection behavior is enhanced/augmented to achieve the requirement which is only specific to that particular Fiori App.

I hope now if you come across similar requirement in your project you can easily implement the same using operation augmentation. I would love to know your suggestion/feedback on this.
2 Comments
Labels in this area