Develop Advanced Extensions with SAP Cloud SDK

Querying SAP APIs in a Java program

Objectives
After completing this lesson, you will be able to:

After completing this lesson, you will be able to:

  • Query an SAP API using the SAP Cloud SDK in a Java program

Retrieving Code Snippets

In the SAP API Business Hub, code snippets are provided for every service segment for various development languages. The Java code snippets work "as is" and are able to read the service, so they offer a good starting point. Nevertheless, the given code reads the service at a low and a data model unaware level, using the standard Java.net API. The request message must be composed and include the required technical parameters. The response comes as a plain JavaScript Object Notation (JSON) content that needs to be interpreted by you. The possibility to create complex queries is very limited.

Accessing the APIs Using SAP Cloud SDK

Using the SAP Cloud Software Development Kit (SDK), you can read the data in a way that is aware of the Virtual Data Model (VDM). Here are some examples:

  • Get the service for the business partner by creating an instance of the DefaultBusinessPartnerService() class.
  • Run "SQL like" queries across the service using specific business object aware classes.
  • The SQL equivalent of the Java code, as shown in the figure, would be something like the following:

    SELECT BUSINESS_PARTNER, LAST_NAME, FIRST_NAME FROM BUSINESSPARTNER WHERE FIRST_NAME = "PETER"

Save progress to your learning plan by logging in or creating an account