Testing SAP RAP OData Service Using SAP Gateway Client
Share

[[{“value”:”

Introduction:

The ABAP RESTful Application Programming Model (RAP) provides a modern framework for developing transactional applications and exposing business data through OData services. Once a RAP service is created and published using a Service Binding, it is important to test the exposed service and verify that the different operations work as expected.

In this blog, I will demonstrate how to test a SAP RAP OData Service using the SAP Gateway Client. The testing covers the service URL, entity set operations, CRUD operations, filtering, and RAP business validations and determination.

The service binding used in this example is:

ZSB_TE_MATERIAL_V

Service URL:

/sap/opu/odata/sap/ZSB_TE_MATERIAL_V

Entity Set:

zC_te_material_V

The following operations will be tested:

  • Reading a single record using key fields

  • Filtering records using $filter

  • Creating a new record using POST

  • Updating an existing record using PATCH

  • Deleting a record using DELETE

  • Testing RAP business validations

  • Handling validation errors in SAP Gateway Client

  • Verifying that invalid records are not created

  • Testing RAP determination to automatically calculate and update the Totalprice

 in service binding we will have service URL to testing in sap gateway.

Dadapeer_2-1787550530639.png

GET Operation – Reading a Record

The GET operation is used to retrieve an existing record from the RAP OData V2 service. To read a specific record, we need to provide the values of the key fields in the service URL.

Service URL:

/sap/opu/odata/sap/ZSB_TE_MATERIAL_V/zC_te_material_V(Materialid='103',Orderid='3')

In this example, the record is retrieved using Materialid = 103 and Orderid = 3 as the key fields.

Dadapeer_4-1787550781366.png

Filter in Read Operation

The GET method can also be used to retrieve records based on specific conditions by using the OData $filter query option.

HTTP Method: GET

Service URL:

/sap/opu/odata/sap/ZSB_TE_MATERIAL_V/zC_te_material_V?$filter=Materialid eq '103'

In this example, the $filter option is used to retrieve records where Materialid is equal to 103.

Dadapeer_6-1787564470064.png

POST Operation – Creating a New Record

The POST operation is used to create a new record in the RAP OData V2 service. To create a record, the required field values are passed in the HTTP request body.

HTTP Method: POST

Service URL:

/sap/opu/odata/sap/ZSB_TE_MATERIAL_V/zC_te_material_V

HTTP Request Body:

{
  "Materialid": "104",
  "Orderid": "4",
  "Materialname": "LOGI Keyboard",
  "Price": "1600",
  "Quantity": "2",
  "Totalprice": "3200"
}

Dadapeer_7-1787564604486.png

 

PATCH Operation – Updating an Existing Record

To update an existing record, the key field values must be provided in the request URL. The fields that need to be changed are passed in the HTTP request body.

The update is performed using the PATCH HTTP method.

Request URL:

/sap/opu/odata/sap/ZSB_TE_MATERIAL_V/zC_te_material_V(Materialid='101',Orderid='100')

HTTP Request Body:

{
  "Materialname": "Gaming Laptop",
  "Price": "2500",
  "Quantity": "3",
  "Totalprice": "7500"
}

In this example, the record identified by Materialid = 101 and Orderid = 100 is updated with the new material name, price, quantity, and total price.

Dadapeer_10-1787551579315.png

Verifying the Updated Record

After successfully performing the update operation, we can use the GET method to retrieve the record again and verify that the changes have been applied successfully.

By using the same key fields in the request URL, we can confirm that the updated values are reflected in the response.

Dadapeer_0-1787551795170.png

DELETE Operation

The DELETE method is used to delete an existing record by passing its key field values in the request URI.

Request URI:
/sap/opu/odata/sap/ZSB_TE_MATERIAL_V/zC_te_material_V(Materialid='101',Orderid='100')

HTTP Method: DELETE

A successful deletion returns 204 – No Content.

Dadapeer_0-1787551955886.png

Validation

The RAP application has validations for Material ID, Order ID, and Material Name.

The validation was triggered successfully, and the invalid record was not created.

Dadapeer_1-1787553226491.png

Dadapeer_3-1787553374816.png

determination for calculating the total price. When the Price and Quantity values are provided or changed, the determination is triggered and calculates the value automatically 

  • Http method : post 
  •  Request url :  /sap/opu/odata/sap/ZSB_TE_MATERIAL_V/zC_te_material_V
  • HTTP Request Body:

    {
      "Materialid": "112",
      "Orderid": "4",
      "Materialname": "gui det keybord ",
      "Price": "800",
      "Quantity": "5",
      "Totalprice": ""
    }

    Dadapeer_0-1787642164109.png

     

Conclusion

In this blog, we explored how to test a SAP RAP OData Service using the SAP Gateway Client. We covered the complete CRUD operations, including GET, POST, PATCH, and DELETE, along with filtering and verification of updated records.

We also tested the RAP business validations and verified that invalid records are prevented from being created through the Gateway Client and RAP determination, which automatically calculates Totalprice based on Price and Quantity, and verified that the calculated value is updated correctly.

This provides a simple and practical approach to testing RAP OData services and validating their behavior before consuming them in applications such as SAP Fiori.

“}]] 

  Read More Technology Blog Posts by Members articles 

#abap

By ali

Leave a Reply