Create a Remote Client Proxy and ABAPConsole Application
In the SAP Business Technology Platform, ABAP Environment, in your consuming system, create an ABAP Console application (ABAP class) that instantiates a proxy, which passes an OData request to a remote service.
Overview
You will learn
- How to create an HTTP client in an ABAP class
- How to instantiate a client proxy in this class that fetches data from your provisioning system
- How to output that data in an ABAP Console app This tutorial is based on: SAP Help Portal: Creating a Remote Client Proxy. Therefore, this tutorial will only cover in detail those aspects that are different, such as using the
cl_http_destination_provider=>create_by_comm_arrangementmethod.
Prerequisites
Steps
##Prerequisites
- IMPORTANT: This tutorial cannot be completed on a trial account
- IMPORTANT: This tutorial is part of a mission. You must complete the previous parts first; otherwise, you may experience errors or unexpected behavior. The link to the mission is available at the top right of the screen, immediately above the list of steps
First, in the consuming system, you create the class that instantiates the client proxy.
In ADT, open your package
Z_BTP_2_BTP_###and choose New > ABAP Class.Enter the following, then choose Next. and description:
- Name:
ZCL_PROXY_TRAVELS_### - Description: Get travel data from PRV, where PRV = your provisioning system
- Add interface:
if_oo_adt_classrun*This will enable you to test your connection by outputting your results to the ABAP console first, before you create the artifacts for the Fiori app.
- Name:
Choose the transport request, then choose Finish.
- Replace the skeleton code with the following.
```ABAP
CLASS zcl_get_travels_### DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
TYPES t_business_data TYPE TABLE OF z###_model_travels=>tys_simple_travel_type.
METHODS get_travels
IMPORTING
top TYPE i OPTIONAL
skip TYPE i OPTIONAL
EXPORTING
et_business_data TYPE t_business_data
*
* RAISING
* /iwbep/cx_cp_remote
* /iwbep/cx_gateway
* cx_web_http_client_error
* cx_http_dest_provider_error
.
INTERFACES if_oo_adt_classrun .
INTERFACES if_rap_query_provider .
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_get_travels_### IMPLEMENTATION.
METHOD get_travels.
" Variables for http_client and client_proxy
DATA:
lo_http_client TYPE REF TO if_web_http_client,
lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy,
lo_request TYPE REF TO /iwbep/if_cp_request_read_list,
lo_response TYPE REF TO /iwbep/if_cp_response_read_lst.
" 1. Get the destination of remote system; Create http client
DATA(lo_destination) = cl_http_destination_provider=>create_by_comm_arrangement(
comm_scenario = '<Comm Scenario ID'
** comm_system_id = '<Comm System ID>'
* service_id = ''
).
lo_http_client = cl_web_http_client_manager=>create_by_http_destination( lo_destination ).
"2. create client proxy
lo_client_proxy = /iwbep/cl_cp_factory_remote=>create_v2_remote_proxy(
EXPORTING
is_proxy_model_key = VALUE #( repository_id = 'DEFAULT'
proxy_model_id = 'Z###_MODEL_TRAVELS'
proxy_model_version = '###1' )
io_http_client = lo_http_client
iv_relative_service_root = '/sap/opu/odata/sap/Z_C_TRAVEL_API_O2_###' " = the service endpoint in the service binding in PRV' ).
).
ASSERT lo_http_client IS BOUND .
" 3. Navigate to the resource and create a request for the read operation
lo_request = lo_client_proxy->create_resource_for_entity_set( 'SIMPLE_TRAVEL' )->create_request_for_read( ).
lo_request->set_top( 50 )->set_skip( 0 ).
" 4. Execute the request and retrieve the business data
lo_response = lo_request->execute( ).
lo_response->get_business_data( IMPORTING et_business_data = et_business_data ).
" Handle remote Exception
ENDMETHOD.
METHOD if_oo_adt_classrun~main.
DATA business_data TYPE TABLE OF z###_model_travels=>tys_simple_travel_type.
TRY.
get_travels(
IMPORTING
et_business_data = business_data
) .
out->write( business_data ).
CATCH cx_root INTO DATA(exception).
out->write( cl_message_helper=>get_latest_t100_exception( exception )->if_message~get_text( ) ).
ENDTRY.
ENDMETHOD.
METHOD if_rap_query_provider~select.
ENDMETHOD.
ENDCLASS.
```
- Format, save and activate your class (
Shift+F1,Ctrl+S,Ctrl+F3).
Select your class in the Project Explorer and choose Run as…> Application Console (F9) from the context menu.
Your output should look like this:

Resources
Discussion
Share feedback on this tutorial or join the conversation in SAP Community.