Tuesday, 13 July 2021

A Step by Step process to trigger Odata Service to send data based on Event Configuration in SAP HANA

In this blog post, I am going to share how to create a simple odata service and trigger GET event for Purchase order data based on Event configurations.

I tried to explain this document in Three steps:

Step 1. creation of Odata service to get data

Step 1. Go to transaction code – SEGW.

Click on Icon Create. A pop window will appear, Fill the details as per below mention in screen shot and click on check icon or enter.

SAP ABAP Exam Prep, SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Study Material

Now we are going to define structure of work area and internal table, Right click on Data model select import and select DDIC structure.

Here give the details of structure and structure name as per your name conventions.

Select radio button Entity type and and click on check box entity set. fill ABAP structure as EKKO and click on next.

Now you will get the pop up screen with EKKO table fields name. Select fields for your structure and click on next.

Other window will appear where we have to select the key field. tick on EBELN as key field and click on finish. You may get warning message, it can be totally ignored.

SAP ABAP Exam Prep, SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Study Material

click on Save button at the top of menu bar

SAP ABAP Exam Prep, SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Study Material

Now click on generate Icon, A pop up window will appear with class details, click on tick icon and proceed further. It will ask for package, give details and proceed further. These are also knowns as runtime artifacts.

SAP ABAP Exam Prep, SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Study Material

SAP ABAP Exam Prep, SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Study Material

Now we will add this odata service. Go to transaction code /IWFND/MAINT_SERVICE.

Click on push button Add services.

Now double click on your project name service. A pop up window will appear, enter the package details and click on tick icon. An Information message will be shown where it will confirm about the service is created and metadata loaded successfully

SAP ABAP Exam Prep, SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Study Material

Now, Go to tcode SEGW and open folder Runtime Artifacts, We can See MPC and DPC classes in that.

MPC – This is used to define model. you can use the method Define to create entity, properties etc using code based implementation.

DPC – used to code your CRUDQ methods as well as function import methods. you write all your logic in redefined methods of DPC extension class.

Now in DPC class, in method GET_ENTITY we need to write our logic for getting data in odata structure, Here I had added a simple select SQL to get EKKO data as shown below.

SAP ABAP Exam Prep, SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Study Material

Now Activate all the changes related to your DPC class, go back to odata project, Click on Generate icon again.

Step 2. Creation of  Event for PO change and Custom Function module to Call odata service

Now, we will be creating a custom Function module to map for Business object event.

create custom function module with below parameters  to capture event and Object id.

SAP ABAP Exam Prep, SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Study Material

SAP ABAP Exam Prep, SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Study Material

Now Write the below logic in side the FM, pass your odata service URL with the Object id as shown below to create Query URL.

SAP ABAP Exam Prep, SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Study Material

SAP ABAP Exam Prep, SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Study Material

Now, Write a code to call your odata service to get data for PO.

SAP ABAP Exam Prep, SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Study Material

Code is ready in Function Module to get the details for Purchase order based on object id received on event trigger.

We will map this Function Module in Event configurations now.

In transaction SWEC, Map the event as shown below

SAP ABAP Exam Prep, SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Study Material

In Transaction SWE2, Map the Event details as shown below

SAP ABAP Exam Prep, SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Study Material

Save the data.

Step: 3 to trigger odata service call.

CPI can map this Odata service to send data to third party. We are triggering Odata to get the data for Purchase order based on event configured.

This FM will be triggered once there is change in PO data, Now let’s test FM

in Se37, Execute FM with below details

SAP ABAP Exam Prep, SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Study Material

After Execution, Check in Transaction /IWFND/APPS_LOG to check your odata service is triggered. In our case it is triggered and in success status as shown below.

SAP ABAP Exam Prep, SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Study Material

Here, We had completed process to trigger Odata Service to send data based on Event Configuration.

In this document, We had create an odata service to get PO details. We had created a custom function module based for event configuration and added logic to call our odata service to get Purchase order details. We had done the Event configuration to trigger  our custom function module. Tested the function module to check if odata service is triggered and checked the status for odata service.

Source: sap.com

No comments:

Post a Comment