Skip to Content
Technical Articles
Author's profile photo Punit Jhanwar

Handle Actions in RESTful ABAP

In this blog post we will see how to handle “Actions” in Transaction Behavior of Core Data Services. “Actions” are addition operations in addition to CRUD operations.

Please refer to below tutorial on implementation of Transaction behavior (Create, Update and Delete) on CDS. In this blog post we are going to add ‘Action’ in the application discussed in below link.

https://developers.sap.com/tutorials/abap-environment-transactional-enablement.html

The application from the above link is for booking details with Create, Delete and Update operation. We are going to add action button on screen to cancel booking.

 

To handle ‘Actions’, following changes are required in application.

  1. Add field ‘Status’ to data model i.e. database table and CDS View.
  2. Add the new field to Fiori application.
  3. Implement handler for the Action ‘Cancel’.

 

1.  Add field ‘Status’ to data model i.e. database table and CDS View

a. Open database table ZTBOOKING_XXX in Eclipse. Add field ‘Status’ to the table and activate        the table

b. Open CSD View ZI_BOOKING_XXX and add field ‘status’     

2.  Add the new field to Fiori application

a.  Open CDS View ZI_BOOKING_XXX. Add following UI Annotation to add column to UI                Consumer

@UI: {  lineItem: [ { position: 50, label: ‘Status’, importance: #HIGH }]}

 

 

b.  Refresh Fiori app. Column ‘Status’ is now available in Fiori App.

 

c.  Add action ‘Cancel’ to Behavior Definition ZI_BOOKING_XXX

d.  Expose the action to Fiori App by adding following annotation to the CDS View ZI_BOOKING_XXX.

{ type: #FOR_ACTION, dataAction: ‘cancel_booking’, label: ‘Cancel’ }

 

e.  Refresh Fiori App. Action ‘Cancel’ will now appear on screen.

 

3. Implement handler for Action ‘Cancel’

a.  Go to ‘Behavior Implementation’ of ZI_BOOKING_XXX. Add importing parameter IT_CANCELLED_BOOKING for action BOOKING~CANCEL_BOOKING and result table ET_CANCELLED_BOOKING.

b.  Go to implementation of method ‘MODIFY’ and add code to set ‘status’ to ‘Cancelled’ and update ‘Last Changed Date’

c.  Refresh the fiori app.

 

Select a record and click on ‘Cancel’ action button. ‘Status’ column is updated to Cancelled for selected record.

 

Conclusion

Here we have learned how Actions are implemented in RESTful ABAP Programming Model. In the post Action Button ‘Cancel’ is added to the screen and Action handler is implemented.

 

Assigned Tags

      7 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Prasenjit Bist
      Prasenjit Bist

      cool

      Author's profile photo Dhiraj More
      Dhiraj More

      Hi Puneet,

      Thanks for sharing your knowledge. Can you please help me with my query on Service Development in cloud platform. Could you please visit the link

      https://answers.sap.com/questions/12943336/development-in-sap-cloud-foundary-platform.html

      Thanks,

      Dhiraj M

      Author's profile photo VIGNESH SV
      VIGNESH SV

      Hi Punit,

      Is it possible to add Actions in non-transactional App (only display App) ? I tried the above steps, could able to add in UI annotations and also in Behaviour definition.

      Action button was visible. But when I check for Behavior Implementation, it has CRUD methods as well.

      Is it not possible to add Actions in Display Apps ?

      Thanks & Regards,

      Vignesh.

      Author's profile photo Kousik Ghosh
      Kousik Ghosh

      Hi Punit,

      is it possible to add some Message Toast at the bottom of the app page after the action is successful or unsuccessful? I mean from the back-end code itself, not with UI breakout.

      Author's profile photo Paul McFarling
      Paul McFarling

      I'm a couple of years late but add a informational message to your reported table.

      *lo_aux->get_new_message() is just  a wrapper on CL_ABAP_BEHV->new_message(). 
      
       APPEND VALUE #( %msg = lo_aux->get_new_message( id = '00'
                                                       number = '001'
                                                       severity = if_abap_behv_message=>severity-information
                                                       v1 = 'Approval request sent'
                                                      )
                                                      %key-contract_uuid = lr_contract->%tky-contract_uuid
                                                      %cid = lr_contract->contractno
                                                      contract_uuid = lr_contract->contract_uuid )
                                                    TO reported-contract.
      
      
      
      
      Author's profile photo Daniel Ojados Conesa
      Daniel Ojados Conesa

      Hi Punit, experts,

      Thanks for sharing your knowledge 🙂

      How would you make it to enable an action for all instances of an entity? In the sample of this blog, to make visible a button to cancel all instances at once, not having to select any of them to be triggered?

      Thanks.

      Regards,

      Daniel

      Author's profile photo Ashok Kumar
      Ashok Kumar

      Its an awesome blog thank you Punit Jhanwar