In today’s interconnected enterprise environments, SAP systems rarely operate in isolation. Integration with external systems—such as third-party applications, cloud services, or other enterprise software—is essential. One of the most flexible and standardized methods for this integration in SAP ABAP is through Web Services. This article explores how ABAP developers can call external systems using web services, enabling seamless communication and data exchange beyond the SAP landscape.
Web services are standardized ways to enable communication between disparate systems over a network, usually the internet or intranet. They allow applications to expose and consume functionality in a platform- and language-independent manner.
Two main types of web services exist:
SAP ABAP supports calling both SOAP and REST web services, providing versatile integration options.
ABAP programs often need to:
Using web services ensures a loosely coupled, standardized interface for these interactions.
Before integration, gather:
SAP provides tools to generate ABAP proxies from WSDL files, simplifying SOAP service consumption.
Process:
Example:
DATA: proxy TYPE REF TO zproxy_external_service.
CREATE OBJECT proxy.
DATA: request TYPE zproxy_external_service=>request,
response TYPE zproxy_external_service=>response.
" Populate request parameters
request-param1 = 'Value1'.
request-param2 = 'Value2'.
" Call the external web service
CALL METHOD proxy->method_name
EXPORTING
input = request
IMPORTING
output = response.
" Process response
WRITE: response-result.
REST services are typically called using HTTP methods. SAP provides classes like CL_HTTP_CLIENT and IF_HTTP_CLIENT to facilitate REST calls.
Steps:
Example:
DATA: http_client TYPE REF TO if_http_client,
lv_response TYPE string,
lv_json_request TYPE string.
" Create HTTP client for the REST endpoint
cl_http_client=>create_by_url(
EXPORTING
url = 'https://api.example.com/data'
IMPORTING
client = http_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
others = 4 ).
" Set HTTP method and headers
http_client->request->set_method( if_http_request=>co_request_method_post ).
http_client->request->set_header_field( name = 'Content-Type' value = 'application/json' ).
" Set JSON payload
lv_json_request = '{"param1":"value1","param2":"value2"}'.
http_client->request->set_cdata( lv_json_request ).
" Send request
CALL METHOD http_client->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2.
CALL METHOD http_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2.
" Get response body
lv_response = http_client->response->get_cdata( ).
" Process JSON response (use CL_TREX_JSON_SERIALIZER or /UI2/CL_JSON)
WRITE: lv_response.
External web services often require secure access.
set_header_field to pass Authorization header.Calling external systems from ABAP using web services is a powerful technique to extend SAP’s capabilities beyond its native environment. By leveraging SOAP proxies for structured, enterprise-grade integrations, or REST calls for lightweight, modern APIs, ABAP developers can build versatile and efficient interfaces. Proper handling of security, error management, and using SAP’s built-in tools ensures robust and maintainable integrations.
Mastering web service consumption in ABAP opens doors to a wide range of business scenarios, enabling SAP systems to be integral parts of today’s interconnected enterprise landscapes.