Show TOC

Programming Examples and Test ReportLocate this document in the navigation structure

This programming information includes code snippets to illustrate the ABAP SMI OData API.

  • For executable code, see the scenario tests in class CL_JAM_SCENARIO that are delivered with ABAP SMI. You can also use this code as a template to create your own code.
    Note Since SAP Jam does not support complex properties, no programming examples are available in the scenario tests in class CL_JAM_SCENARIO. Instead, a full example is provided below.
  • To test the ABAP SMI OData API without writing code, use the report R_ODL_TEST. For more information, see the report documentation in the system.
Example: Complex Properties
The following code snippet shows how you can use complex properties in ABAP SMI when integrating with a collaboration platform other than SAP Jam. An example for a complex type or property is Address, which contains the property City.
DATA:
  lo_api               	TYPE REF TO if_odl_api,
  lo_request           	TYPE REF TO if_odl_request,
  lv_result_code       	TYPE     clb2_result_code,
  lo_entity            	TYPE REF TO if_odl_entity,
  lo_propcomplex       	TYPE REF TO if_odl_propcomplex,
  lv_prop_value        	TYPE     string,
  lx_process           	TYPE REF TO cx_odl_process.

* get an API object
lo_api ?= cl_odl_api=>s_create( 	iv_application_id 	= 'ODATA_TEST'
                                	iv_platformtype 	= 'ODataTestV2' "points to http://services.odata.org/V2/ (check transactions CLB2_APPLI_PLATF and CLB2_PLATF)
                                	iv_service        	= 'DEFAULT' ). "points to OData/OData.svc (in transaction SM31, check view CLB2V_SERVICE_C)
*-------------------------------------------------------------------------
* build the request
* GET Suppliers(1)
* URL: http://services.odata.org/V2/OData/OData.svc/Suppliers(ID=1)
lo_request = lo_api->get_request( 'Suppliers' ).
lo_request->navigate_by_simple_key( iv_name = 'ID' iv_value = '1' ).

TRY.
* submit the request
    lo_request->submit( ).

* collect the result
    lv_result_code = lo_request->get_result_code( ).
    lo_entity = lo_request->get_result_entity( ).
    lo_propcomplex = lo_entity->get_complex_property( 'Address' ).
    lv_prop_value = lo_propcomplex->get_simple_property_value( 'City' ).
  CATCH cx_odl_process INTO lx_process.
ENDTRY.