Show TOC

Specifying a Request BodyLocate this document in the navigation structure

If your OData request is intended to modify data (that is, if you use POST or PUT/PATCH), you may need to pass on that data within the request body of your request. In OData, the request body is typically XML content describing an entity or entity set that you want to create or modify. However, there are also scenarios in which the request body is not XML content. For file upload requests, for example, the request body is typically a byte stream (xstring) describing the file.

Therefore, you can specify the request body in one of the following ways:

  • Define the request body and assign it to an xstring variable.
  • “Convenience approach”: Use the ABAP SMI API to build an entity or entity set object. ABAP SMI will automatically handle the serialization of this object, that is, it will create the corresponding XML representation for the request body, when the request is submitted. For more information, see Collecting the Results.

Use your ABAP SMI API instance lo_api to build an entity or entity set object.

Example

The following code illustrates how to build an entity object lo_entity with the name MyEntity with two properties, Property1 and Property2:

DATA: lo_entity TYPE REF TO if_odl_input_entity.
lo_entity = lo_api->create_input_entity( 'MyEntity' ).
lo_entity->set_simple_property(
  iv_name = 'Property1'
  iv_value = 'Value1'
).
lo_entity->set_simple_property(
  iv_name = 'Property2'
  iv_value = 'Value2'
).		

This object will later serialize to the following XML representation:

<?xml version="1.0" encoding="utf-8" ?> 
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom">
  <atom:title>MyEntity</atom:title> 
  <atom:content>
    <meta:properties mlns:meta=
		"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
      <data:Property1 meta:type="" xmlns:data=
		"http://schemas.microsoft.com/ado/2007/08/dataservices">Value1</data:Property1> 
      <data:Property2 meta:type="" xmlns:data=
		"http://schemas.microsoft.com/ado/2007/08/dataservices">Value2</data:Property2>
    </meta:properties>
  </atom:content>
</atom:entry>