Mentor SAP

Read the BusinessPartnerSet Entity

We want to read the BusinessPartnerSet entity set from our OData sample service. The service document already contains the relative URI of the entity set.

 

We use the query parameter sap-ds-debug=true. This way the XML response is formatted as a HTML page that can be consumed by any browser without any problem. Otherwise the XML response may be rendered as a news feed by the browser.

 

The issue is that Microsoft Internet Explorer does not render JSON responses correctly and other browsers such as Firefox need an appropriate add-on to be installed. Using the query option sap-ds-debug=true means that you can follow any relative links by choosing them in the HTML page to navigate to the related resource from within the browser.

 

If we choose the relative link that points to the list of business partners, we receive a response in the ATOM XML format as shown in the figure, Read the BusinessPartnerSet Entity, since ATOM XML is the default format that is used by OData V2.

 

 

Read an Entity Set

The ATOM XML response is an array with multiple entries, which are shown here in a collapsed form so that we only see the full entry payload for the first entry. The first of the highlighted elements of the expanded business partner entity identifies the entity itself. That is, if you append the value of the href attribute of this element to the service’s base URL, the READ operation for that single entity is performed.

 

The query string sap-ds-debug=true is used in this example.

 

Due to this addition, the values of the href attribute of the element is rendered as a hyperlink. That is, you can choose this link to perform the READ operation for the corresponding entity. The second element expresses the navigation property ToSalesOrders from the BusinessPartnerSet entity set to its related connections. To navigate to the related resource, the required URL is created again by appending the value of the href attribute to the base URL. Also in this case you can simply choose the rendered hyperlink BusinessPartnerSet(‘0100000000’)/ToSalesOrders to navigate to the related connections.

 

 

Read the First Entry in the BusinessPartnerSet

We now follow the URI in the metadata section to read just the first entry in the business partner entity set, which has an ID of 0100000000. This URI is also called the self-link of this entity.

 

If you compare this response with the previous one, you’ll see that the entity payload is identical, and the entity set only contains the surrounding array in addition.

 

At the end you will see the three navigation properties pointing to the SalesOrderSet, the ProductSet, and to the ContactsSet that contains the contacts of the business partners. All navigation properties are URIs. As a consumer of an OData service you can just follow this URI and navigate through this web of data. Let’s do so and fire a GET call at the SalesOrders URI.

 

 

We now examine the first URI that points to itself. This is called the self-link of this entity. If we expand the first entry, we can see the full entry payload. The metadata section contains a URI identifying this first entry, and the entry type. This section is followed by all of the properties and their values.

 

Read BusinessPartner SalesOrders

 

The result is a list of SalesOrders associated with the selected business partner. While we can see the payload of the first entry, the other entries have been collapsed for readability.

 

Sales Orders Navigation Properties

One use case for navigation properties is the navigation from one screen that shows the details of a business partner to a second screen that lists all sales orders that are associated with that business partner.

 

In a similar way to properties, navigation properties are specified in a separate element of the metadata document, called a NavigationProperty.