logo

Are you need IT Support Engineer? Free Consultant

Calling an SAP BTP Destination from the SAP BTP AB…

  • By sujay
  • 02/06/2026
  • 23 Views

When building extensions on SAP BTP ABAP Environment, you often need to call external HTTP or OData services.

Instead of hardcoding target URLs in your ABAP code, you can define a destination in the SAP BTP cockpit and consume it from ABAP. This keeps the endpoint configuration outside the code and makes it easier to change later.

In this example, I will call the public Northwind OData service from an ABAP Console Application using a BTP destination.

Create the destination in SAP BTP

In the SAP BTP cockpit, create a destination like this:

Name: Northwind

Type: HTTP

Description: Northwind OData services

Proxy Type: Internet

URL: https://services.odata.org

Authentication: NoAuthentication

After saving the destination, run Check Connection.

For this example, the check was successful:

HTTP request (without authentication) to Northwind destination succeeded.

The service we want to call is:

https://services.odata.org/V4/Northwind/Northwind.svc/Products?$top=5

Because the destination already contains the base URL:

https://services.odata.org

the ABAP code only needs to provide the relative path:

/V4/Northwind/Northwind.svc/Products?$top=5

Create the ABAP console class

Create a new global class in ADT, for example:

ZCL_NORTHWIND_DESTINATION_TEST

Use this code:

CLASS zcl_northwind_destination_test DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC.
  PUBLIC SECTION.
    INTERFACES if_oo_adt_classrun.
  PRIVATE SECTION.
    TYPES: BEGIN OF ty_product,
             productid    TYPE i,
             productname  TYPE string,
             unitprice    TYPE p LENGTH 10 DECIMALS 4,
             unitsinstock TYPE i,
           END OF ty_product.
    TYPES: BEGIN OF ty_response,
             value TYPE STANDARD TABLE OF ty_product WITH EMPTY KEY,
           END OF ty_response.
ENDCLASS.

CLASS zcl_northwind_destination_test IMPLEMENTATION.
  METHOD if_oo_adt_classrun~main.
    TRY.
        DATA(lo_destination) =
          cl_http_destination_provider=>create_by_cloud_destination(
            i_name="Northwind"
            i_authn_mode = if_a4c_cp_service=>service_specific
          ).
        DATA(lo_client) =
          cl_web_http_client_manager=>create_by_http_destination(
            lo_destination
          ).
        DATA(lo_request) = lo_client->get_http_request( ).
        lo_request->set_uri_path(
          '/V4/Northwind/Northwind.svc/Products?$top=5'
        ).
        lo_request->set_header_field(
          i_name="Accept"
          i_value="application/json"
        ).
        DATA(lo_response) = lo_client->execute(
          i_method = if_web_http_client=>get
        ).
        DATA(ls_status) = lo_response->get_status( ).
        DATA(lv_body)   = lo_response->get_text( ).
        out->write( |HTTP Status : { ls_status-code } { ls_status-reason }| ).
        DATA(ls_response) = VALUE ty_response( ).
        /ui2/cl_json=>deserialize(
          EXPORTING
            json        = lv_body
            pretty_name = /ui2/cl_json=>pretty_mode-camel_case
          CHANGING
            data        = ls_response
        ).
        out->write( '===== PRODUCTS =====' ).
        LOOP AT ls_response-value INTO DATA(ls_product).
          out->write(
            |{ ls_product-productid } - { ls_product-productname } | &&
            |Price: { ls_product-unitprice } | &&
            |Stock: { ls_product-unitsinstock }|
          ).
        ENDLOOP.
        lo_client->close( ).
      CATCH cx_root INTO DATA(lx_error).
        out->write( |Error: { lx_error->get_text( ) }| ).
    ENDTRY.
  ENDMETHOD.
ENDCLASS.

Run the class using:

Run As > ABAP Application Console

Key part of the code

The destination is consumed using:

DATA(lo_destination) =

  cl_http_destination_provider=>create_by_cloud_destination(

    i_name="Northwind"

    i_authn_mode = if_a4c_cp_service=>service_specific

  ).

Then an HTTP client is created from that destination:

DATA(lo_client) =

  cl_web_http_client_manager=>create_by_http_destination(

    lo_destination

  ).

Console output

The output should look like this:

HTTP Status : 200 OK

===== PRODUCTS =====

1 - Chai Price: 18.0000 Stock: 39

2 - Chang Price: 19.0000 Stock: 17

3 - Aniseed Syrup Price: 10.0000 Stock: 13

4 - Chef Anton's Cajun Seasoning Price: 22.0000 Stock: 53

5 - Chef Anton's Gumbo Mix Price: 21.3500 Stock: 0

This confirms that the ABAP class successfully resolved the BTP destination, called the Northwind OData service, received the response, deserialised the JSON, and printed the result.

Note about trial systems

During testing on a trial ABAP environment, the destination-based approach returned:

Destination error: Destination not found

The same destination-based code worked successfully in a non-trial SAP BTP ABAP system.

So if you see this in a trial environment, the issue may be related to destination visibility or Destination service integration in that specific trial setup, not the ABAP code itself.

Conclusion

Calling a BTP destination from SAP BTP ABAP Environment requires only a few lines of code:

This keeps the external system configuration in SAP BTP and allows your ABAP code to stay clean and portable.

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *