0
    /**
 * Calls {@code GET API_SALES_ORDER_SRV/A_SalesOrder} through
 * {@link FluentHelperRead} to get the SalesOrder events expanded to sales
 * order items and filtered by {@code keys} list
 *
 * @param keys
 *          the list of sales orders IDs to be fetched
 * @return the list of sales orders or an empty list if {@code keys} is empty
 *
 * @throws ODataException
 *           in case the request was not successful
 * @throws IllegalArgumentException
 *           in case {@code keys} is null
 *
 * @see //ProcessSalesOrderService#getAllSalesOrder()
 * @see <a href=
 *    "https://api.sap.com/shell/discover/contentpackage/SAPS4HANACloud/api/API_SALES_ORDER_SRV?resource=A_SalesOrder&operation=get_A_SalesOrder">SAP
 *    API Business Hub</a> for details of
 *    {@code GET API_SALES_ORDER_SRV/A_SalesOrder} endpoint
 */
public List<SalesOrderHeader> getByKeys(@NonNull Collection<String> keys) throws IllegalArgumentException, ODataException {
    if (keys.size() == 0) {
        return Collections.emptyList();
    }
    
    
    // create OData $filter with all keys 
    final ExpressionFluentHelper<SalesOrderHeader> filter = keys.stream()
            .map(key -> SalesOrderHeader.SALES_ORDER.eq(key))
            .reduce(ExpressionFluentHelper::or)
            .get();

    try {
        HttpDestinationProperties destinationprop = null;
        return salesOrderService.getAllSalesOrder()
            .select(SalesOrderHeader.ALL_FIELDS, SalesOrderHeader.TO_ITEM)
            .filter(filter)
            .execute(destinationprop );
    } catch (com.sap.cloud.sdk.odatav2.connectivity.ODataException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

I found the above sample code but since I am new to SAP and my system is an OnPrem version deployed on AWS. I am not sure how to pass the HttpDestinationProperties destinationprop Further that method seems to be deprecated. I am looking for some sample code to call the Sales order Odata Service using the code I generated using the instructions provided. I generated the code using a maven plugin. https://sap.github.io/cloud-sdk/docs/java/features/odata/generate-typed-odata-v2-and-v4-client-for-java I am using the odata V2 Plugin

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48

1 Answers1

2

Usually you would use the SAP BTP Cloud Foundry Destination Service and Connectivity Service. Make sure to also have a Cloud Connector connected to your sub-account, it will act as reverse-proxy to the On-Premise system. You bind the destination service (e.g. plan lite) as well as the connectivity service (e.g. plan lite) to your application.

Once the prerequisites are met, you can use the SAP Cloud SDK code to resolve destinations:

// General API usage:
Destination destination = DestinationAccessor.getDestination("my-destination");

// Cast to HTTP destination:
HttpDestination httpDestination = destination.asHttp(); 

// Apply dedicated ERP logic for SAP S/4HANA
HttpDestination erpHttpDestination = httpDestination.decorate(DefaultErpHttpDestination::new);

(Of course you can boil it down to a one-liner.)

The OData call itself can be called like the following without try-catch:

return salesOrderService.getAllSalesOrder()
  .select(SalesOrderHeader.ALL_FIELDS, SalesOrderHeader.TO_ITEM)
  .filter(filter)
  .executeRequest( erpHttpDestination );

That's it!

PS.: If you want to define your destination in static code, that would be possible with the DefaultErpHttpDestination.builder("http://your-proxy-host:44300") API. However this is obviously not best-practice.

Alexander Dümont
  • 903
  • 1
  • 5
  • 9
  • I was trying to connect to the Odata Service from my desktop. I am able to get to the URL from my desktop without issues so I should be able to get to it without using SAP BTP cloud foundry I assume? – Alan Varghese Jan 14 '22 at 02:23
  • I assume your desktop is connected to a company network / proxy. The SAP BTP Cloud Foundry is **not** connected to your company network without _Cloud Connector_ – Alexander Dümont Jan 17 '22 at 21:46