Skip to Content
Technical Articles

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.

 

5 Comments
You must be Logged on to comment or reply to a post.