Enhancing standard APIs on S/4HANA

SAP APIs Enhancing standard APIs on S4HANA

Share This Post

4 minutes

SAP APIs

In 2016 SAP launched API Business Hub which is the central catalogue of SAP APIs for application developers to search and discover standard and out of the box ways of accessing/integrating SAP data with third-party systems or applications.

S/4HANA API is a concept somehow similar to BAPIs known from SAP ECC systems. The difference here is that in the S/4HANA they are RESTful APIs and use the oData protocol, whereas BAPIs were mainly called using RFC connection (if called from outside of SAP). Also, under the hood, S/4HANA APIs are built using CDS views as opposed to regular ABAP.

Having said that, you can leverage the APIs to quickly build reports without the need of developing the backend and database logic. That is the case if the API you need is available in the API Business Hub and provides all the data you need. Sometimes, you may find that the API doesn’t provide all the information you need, but fear not, SAP got you covered and allows you to extend the API and add additional fields.

What is covered in this blog post:

Business Scenario

System Prerequisites: S/4HANA System, Eclipse with ABAP Development Tools

 

You are building a PowerBI Purchase Order report. You want to access the SAP data and have identified a relevant API Purchase Order API in the API Business Hub. It ticks almost all the boxes, however, it is missing “Send Status” information on the PO header level. An SAP Developer skilled in CDS views* can enhance the API for you and add the required field.

 (Read Radek’s detailed blog post “ABAP CDS Views – All you need to know” here) 

Where to find the SAP API?

The API Business Hub can be accessed using the following URL: https://api.sap.com/. Searching for “Purchase Order” we have found a relevant API – “API_PURCHASEORDER_PROCESS_SRV”. You can then check if this API is available in your system version and activate it.

A purchase order using SAP APIs

Although the “Package” above says SAP S/4HANA Cloud, this API is also available in S/4HANA on premise version which is used in this blog post.

How to identify the relevant object for enhancement?

As already mentioned, most of the APIs are created using CDS views, which are then exposed using the oData protocol to the outside world. To add the extra field, you have to identify the APIs Gateway project and then the relevant CDS view name. It is the CDS view that is enhanced directly and the API, which is created with reference to the CDS view will inherit the enhancement.

 

1. Launch transaction SEGW

2. Click the ‘Open Project’ button and type API_PRUCHASEORDER_PROCESS

3. Expand the Gateway project and click on “CDS-Entity Exposures”. This will display on the right-hand side all CDS views used in that API. We are interested in A_PurchaseOrder (PO Header Level) and this is the CDS view we will be enhancing.

SAP APIs gateway service builder

 

Extending the CDS view

We can now extend the CDS view using Eclipse. This is done by creating a new “Data Definition” element and the “Extend View” template.

1. Launch Eclipse and connect to your system.

2. Click File -> New -> Other -> Data Defintion

3. Enter Name and Description, click next and select transport.

4. Select ‘Extend View’ Template.

5. Add the additional fields SendStatus and SendStatusText from another CDS view or SAP table. In the example below I have created a custom CDS view ZI_MessageStatus which is a layer on top of NAST table to provide us with Purchase Order send status and its description.

Elements in the extension:

  1. SE11 Artifact name which gets generated
  2. CDS View name that is being extended
  3. Extension Name
  4. Custom CDS view that contains the Purchase Order message status information, joined using association.
  5. SendStatus and SendStatusText – extra fields coming from the ZI_MessageStatus CDS view. They will now appear on A_PurchaseOrder CDS view level through the extension

 

6. Activate your extension

7. Launch the A_PurchaseOrder CDS view. Note that a new icon has appeared which indicates that it has been enhanced, and shows the enhancement name:

 

Test your SAP APIs

Now it is time to validate that your new fields are visible and providing the correct data.

1. Check if the new fields have appeared in transaction SEGW for

-project: API_PRUCHASEORDER_PROCESS,
-entity type: A_PurchaseOrderType
-node: properties

File directory of SAP APIs purchase order process

SAP APIs file directory

2. Test your service in the browser or SAP Gateway Client in transaction /IWFND/MAINT_SERVICE

Using request URI: /sap/opu/odata/sap/API_PURCHASEORDER_PROCESS_SRV/A_PurchaseOrder

We can now see that the newly added fields are appearing:

SAP APIs newly added fields

 

Summary

SAP provides a list of standard APIs which can be leveraged with minimum effort. Keep in mind that these APIs can be extended if there missing data to fit your exact requirements. This is done mostly through the extension of CDS views

These extensions are upgrade proof, which means that after system upgrade they should remain untouched. In other words, this is a similar concept to Enhancements/BADIs/Customer Exits known from ECC.

If you can’t find a relevant API out of the box in the API Hub, then a custom oData service can be created by SAP Developer with the knowledge of CDS views. 

Get in touch if you have any questions or need assistance – we are here to help!

Search by a topic below...

Read our latest articles...

Didn’t find what you are looking for? Send us your questions.

We are here to help.
Colleagues at work at Absoft SAP Consultancy