I have a Java application on SAP Cloud Platform Cloud Foundry that integrates with SAP S/4HANA Cloud (my company's ERP system) by calling APIs (OData services) in that system. I heard about the SAP S/4HANA Cloud SDK and that it makes such scenarios much easier.
How can I leverage the SAP S/4HANA Cloud SDK? Currently, my code to call SAP S/4HANA looks like this (simplified and joined together) for the scenario of retrieving product master data. I have created the S4Product
class myself as representation of the response. The baseUrl
and authHeader
are determined before by talking to the destination service on SAP Cloud Platform.
StringBuilder url = new StringBuilder(baseUrl);
url.append("/sap/opu/odata/sap/API_PRODUCT_SRV/A_Product");
url.append("&$select=Product,CreationDate");
url.append("&$filter=ProductType eq '1'");
url.append("&$top=10");
URL urlObj = new URL(url.toString());
HttpURLConnection connection = (HttpURLConnection) urlObj.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Authorization",authHeader);
connection.setDoInput(true);
final InputStreamReader in = new InputStreamReader(connection.getInputStream());
String response = CharStreams.toString(in);
List<S4Product> result = Arrays.asList(new Gson().fromJson(response, S4Product[].class));
Now I'm asked to do something similar with business partners. How do I do this for the business partner OData service, using the SDK? Do I have to create a new application if I want to use the SDK?