Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
745

Navigation is supported in soap data source when a web service has such an operation which takes an input parameter which is the key element of another entity set.

Steps from Design Time tool

  1. Create an OData Service Implementation Project
  2. Create an OData Model for 2 entities salesOrders and Customers. Define a navigation from customers to salesOrders as below. This model fetches all the salesOrders for a specific customer. So the web service must have an operation like getSalesOrders and this operation must take customerId as an input parameter and return the sales order list. Here Navigation Property Name is SalesOrdersSet

    3. Right click on odatasvc and choose Select data source

    4. Select the SalesOrders entitySet and choose the query CRUD operation. Select the data source SOAP Service.

   

    5. Specify the wsdl file and choose the getSalesOrders operation from the list of soap operations and click on finish

    6. Right click on Query and select Define Custom Code

     7. Select the script type as either javascript or groovy script

     8. The navigation segment path has to be fetched from the odata request uri and a proper request payload has to be created. If the navigation segment path is like CustomerSet(10)/SalesOrdersSet, then the key predicate customerId = 10 must be fetched from the navigation segment path and this should be an input parameter to the web service operation getSalesOrders.


function processRequestData(message) {
var uriInfo = getUriInfo(message);
importPackage(org.apache.olingo.odata2.api.uri);
importPackage(java.util);
var map = new HashMap();
var navSegments = uriInfo.getNavigationSegments();
var first = true;
if (navSegments.size() > 0) {
  var keyPredicate = "";
  for (var i=0; i<uriInfo.getKeyPredicates().size();i++) {
   importPackage(org.apache.olingo.odata2.api.edm);
   var key=uriInfo.getKeyPredicates().get(i);
   edmSimpleType = key.getProperty().getType();
   if (first) {
    first = false;
   } else {
    first = true;
   }
   keyPredicate = getWhereString(key, edmSimpleType);
  }
  map.put("CustID", keyPredicate);
  message.setBody(map);
}
return message;
}
function getUriInfo(message) {
importPackage(org.apache.olingo.odata2.api.uri);
importPackage(com.sap.gateway.core.ip.component.commons);
var uriInfo = message.getHeaders().get(
   ODataExchangeHeaderProperty.UriInfo.toString());
return uriInfo;
}
function getWhereString(key, edmSimpleType) {
var appendStr = "";
importPackage(org.apache.olingo.odata2.api.edm);
if (!(edmSimpleType == EdmSimpleTypeKind.Int16
   .getEdmSimpleTypeInstance()
   || edmSimpleType == EdmSimpleTypeKind.Int32
     .getEdmSimpleTypeInstance()
   || edmSimpleType == EdmSimpleTypeKind.Int64
     .getEdmSimpleTypeInstance()
   || edmSimpleType == EdmSimpleTypeKind.Decimal
     .getEdmSimpleTypeInstance() || edmSimpleType == EdmSimpleTypeKind.Double
    .getEdmSimpleTypeInstance())) {
  appendStr = "\'" + key.getLiteral() + "\'";
} else {
  appendStr = key.getLiteral();
}
return appendStr;
}

If the OData request is https://localhost:8083/gateway/odata/SAP/SOAP;v=1/CustomersSet(10)/SalesOrdersSet

The request payload looks like

   <soapenv:Body>
      <tes:getSalesOrders>
         <tes:CustID>10</tes:CustID>
      </tes:getSalesOrders>
   </soapenv:Body>

   9. Right click on Query and select Define Response Mapping

   10. Do the response mapping.

   11. Select a data source for the other entity set as well.

   12. Right Click on Project and select Generate and Deploy Integration Content. This will deploy the bundle.

Now fire an OData Request https://localhost:8083/gateway/odata/SAP/SOAP;v=1/CustomersSet(10)/SalesOrdersSet on the browser and response will give the list of sales orders with customerId 10.

1 Comment