Skip to Content

Consuming OData service in ABAP via CL_HTTP_CLIENT->CREATE_BY_URL

This blog explain how can we use CL_HTTP_CLIENT to call OData service in a target system. This can only be used for a simple OData serivce with minimal parameters.

CL_HTTP_CLIENT can be used  to perform the HTTP communication in ABAP.

There are two options to create an object of type CL_HTTP_CLIENT:

  1. Create by destination: A HTTP destination is pre-created in the SM59 transaction, where the information about the authentication and the service URI for the REST service access is stored.

    The factory method CL_HTTP_CLIENT=>CREATE_BY_DESTINATION is used in this case to instantiate the ABAP HTTP object.

  2. Create by URL: All required connection datails are specified on object construction, i.e. without any link to a destinat

    DATA: lo_http_client TYPE REF TO if_http_client,
                 lv_service TYPE string.
    ***This service returns the count of the entityset
    lv_service = '*SRV/*Set/$count
    *** Use CL_HTTP_CLIENT to consume the OData service using the method "create_by_url"
           url                = lv_service
           client             = lo_http_client
           argument_not_found = 1
           plugin_not_active  = 2
           internal_error     = 3
           OTHERS             = 4 ).
    *** Call the following method to autheticate the user/password and client for the remote connection.
         CLIENT = '200'
         USERNAME = '*'
         PASSWORD = '*'
         LANGUAGE = 'E'
    **** Send the request
           http_communication_failure = 1
           http_invalid_state         = 2 ).
    *** Receive the respose
           http_communication_failure = 1
           http_invalid_state         = 2
           http_processing_failed     = 3 ).
    *** Read the result 
      CLEAR lv_result .
       lv_result = lo_http_client->response->get_cdata( ).
     write: lv_result.


    The factory method CL_HTTP_CLIENT=>CREATE_BY_URL is used to in this case to instantiate the ABAP HTTP object.

In the above example we are returning a number.

Disadvantage of this approach is that it can be used with the parameters that can be passed in the URL as input.

Be the first to leave a comment
You must be Logged on to comment or reply to a post.