Beyond ABAPdesigned by@Tejoram97
Beyond ABAP / CORE ABAP / Web Services (SOAP & REST)

Web Services (SOAP & REST)

CORE ABAP · ABAP Development ·

Open the interactive lesson →
  1. Web service basics
  2. SOAP
  3. SOAP provider: function module → service definition → SOAMANAGER
  4. SOAP consumer: proxy → logical port → ABAP call
  5. REST services in ABAP
  6. SOAP vs REST vs OData
  7. Interview questions

How an ABAP system offers and calls web services: SOAP services (service definition, SOAMANAGER, consumer proxies) and simple REST services through the Internet Communication Framework (ICF). OData – SAP's standard REST protocol for Fiori – has its own page (08 OData). Running example: a function module that counts the flight schedules of an airline (ZFM_XXX_SCHDLCOUNT, table SPFLI).

Part 1 – Web service basics

A web service is a set of open protocols and standards that lets applications exchange data over the network (HTTP), even if they are written in different languages and run on different platforms. The interface is described in a machine-readable format (XML for SOAP).

  • WSDL – Web Services Description Language: an XML document that describes what a service offers – operations, input/output message types, protocol binding and the endpoint URL. It is the contract between provider and consumer.
  • Service provider: the system that offers the service and its WSDL. Service consumer: usually an application that reads the WSDL and calls the service.
  • Service registry: a directory where providers publish services and consumers find them.
SOA triangle: publish, search, URL, WSDL, SOAP calls; UDDI is legacy, how services are found today

The classic SOA triangle: (1) the provider publishes its service, (2) the consumer searches the registry, (3) gets the URL, (4/5) requests and receives the WSDL, then calls the provider with SOAP messages.

Legacy – UDDI (know it for interviews)

UDDI (Universal Description, Discovery and Integration) was the XML standard for such registries. The public UDDI Business Registry – including SAP's node at uddi.sap.com – was shut down around 2006. In practice the WSDL URL is exchanged directly; in SAP landscapes services are found in the SAP Services Registry (PI/PO) or the SAP Business Accelerator Hub (api.sap.com) for SAP's own APIs.

Web services in AS ABAP

  • AS ABAP has a standard architecture and tools (SE80, SOAMANAGER, SPROXY) to provide and consume web services.
  • RFC-enabled function modules and BAPIs can be exposed as services with a wizard (inside-out).
  • Used SAP ↔ SAP and SAP ↔ non-SAP (.NET, Java, cloud services).
  • Two families: SOAP (a protocol with a strict contract) and REST (an architectural style; OData is the SAP flavour).

Part 2 – SOAP

SOAP (originally Simple Object Access Protocol; since SOAP 1.2 just a name) is an XML-based messaging protocol. Every message is an envelope with an optional header (security, addressing) and a body (the payload or a fault). It is independent of programming language and is usually sent over HTTP(S) POST. Security standards such as WS-Security (signatures, encryption) plug into the header.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:sap-com:document:sap:rfc:functions">
<soapenv:Header/>
<soapenv:Body>
<urn:ZFM_XXX_SCHDLCOUNT>
<IV_CARRID>LH</IV_CARRID>
</urn:ZFM_XXX_SCHDLCOUNT>
</soapenv:Body>
</soapenv:Envelope>

To use SOAP in ABAP you need two parts: a service definition on the provider side (returns an output for the given input) and a service consumer (consumer proxy) on the calling side.

SOAP in ABAP: provider steps 1–4, WSDL contract, consumer steps 5–8

Term

Meaning

Inside-out

Start from existing ABAP (FM/BAPI/class) and generate the service definition + WSDL from it

Outside-in

Start from a WSDL / ESR service interface and generate ABAP proxies from it (SPROXY / SE80)

Service definition

Provider-side repository object describing the service (generated from the FM)

Endpoint / binding

Runtime configuration in SOAMANAGER: URL, authentication, transport security

Consumer proxy

Generated ABAP class + data types that build and send the SOAP message for you

Logical port

Runtime configuration of a consumer proxy in SOAMANAGER: target URL, user, security

Part 3 – SOAP provider: function module → service definition → SOAMANAGER

3.1 Create the function module (SE37)

Create the FM in a customer function group with processing type Remote-Enabled Module (RFC). RFC parameters must be passed by value. Activate it.

FUNCTION zfm_xxx_schdlcount.
*"  IMPORTING
*"     VALUE(IV_CARRID) TYPE  S_CARR_ID
*"  EXPORTING
*"     VALUE(EV_COUNT) TYPE  I
SELECT COUNT(*) FROM spfli
WHERE carrid = @iv_carrid
INTO @ev_count.
ENDFUNCTION.

3.2 Create the service definition

  • SE37 menu Utilities → More Utilities → Create Web Service → From the Function Module, or SE80 → Enterprise Services → Create → Service Provider → Existing ABAP Object (inside-out).
  • Follow the wizard: name of the service definition (e.g. ZSD_XXX_SCHDLCOUNT), the endpoint (FM), a security profile (e.g. basic authentication + SSL), package, transport. Activate.

3.3 Configure it in SOAMANAGER

A service definition is only a design-time object. SOAMANAGER (opens in the browser) creates the runtime binding / endpoint that consumers call.

  • 1. Tab Service Administration → Web Service Configuration.
  • 2. Search for the service definition ZSD_XXX_SCHDLCOUNT and open it.
  • 3. Tab Configurations → Create Service.
  • 4. Enter the service name (ZSV_XXX_SCHDLCOUNT), a description and the binding name (ZSB_XXX_SCHDLCOUNT) → Next.
  • 5. Provider security: under Transport Channel Authentication tick User ID/Password (basic authentication). Production: HTTPS + SSL client certificate or SSO where possible.
  • 6. Next → Finish. The binding appears under the service.
  • 7. On the binding row, click Open Binding WSDL Generation (4th icon) – it shows the WSDL URL and the endpoint. Give this URL to the consumer.
SOAMANAGER steps 1–7: Web Service Configuration, search, Create Service, names, security, Finish, WSDL URL

3.4 Test and monitor

  • Test with the Web Service Navigator / Test icon in SOAMANAGER, or import the WSDL into SoapUI / Postman and send a request.
  • SRT_UTIL – error log and traces for SOAP runtime calls; SRT_MONI – message monitor (asynchronous/reliable messaging); SOAMANAGER → Logs and Traces.
  • Authorization: the calling user needs S_SERVICE for the service and the RFC authorizations (S_RFC) of the function group.

Part 4 – SOAP consumer: proxy → logical port → ABAP call

4.1 Generate the consumer proxy (SE80)

  • 1. SE80 → Local Objects (or your package) → right-click Enterprise Services → Create.
  • 2. In the wizard choose Service Consumer → Continue.
  • 3. Choose External WSDL/Schema → data source URL → enter the WSDL URL from SOAMANAGER (log on – basic authentication is required).
  • 4. Package (or Local Object) and a prefix such as ZCP_XXX_ so the generated objects are recognisable.
  • 5. Complete → save and activate the consumer proxy (class ZCP_XXX_CO_… plus data types).

With PI/PO the WSDL usually comes from the Enterprise Services Repository; then the proxy is generated in SPROXY (outside-in) instead.

4.2 Create the logical port (SOAMANAGER)

A generated proxy cannot be called until it has a logical port: SOAMANAGER → Service Administration → Web Service Configuration → search the consumer proxy → Create → Logical Port (manual configuration or WSDL-based: WSDL URL + user/password) → set it as default → Save. Without it the call fails with cx_ai_system_fault ("no logical port").

SE80 consumer proxy wizard: Enterprise Services → Create, Service Consumer, External WSDL URL, prefix, activate; then logical port

4.3 Call the service in ABAP

TRY.
DATA(lo_proxy) = NEW zcp_xxx_co_zsd_schdlcount( logical_port_name = 'ZLP_SCHDLCOUNT' ).
DATA(ls_input) = VALUE zcp_xxx_zfm_xxx_schdlcount( iv_carrid = 'LH' ).

lo_proxy->zfm_xxx_schdlcount( EXPORTING input  = ls_input
IMPORTING output = DATA(ls_output) ).
WRITE: / |Flight schedules for LH: { ls_output-ev_count }|.

CATCH cx_ai_system_fault INTO DATA(lx_system).    "technical: port, network, auth
MESSAGE lx_system->get_text( ) TYPE 'E'.
CATCH cx_ai_application_fault INTO DATA(lx_app).  "business fault sent by provider
MESSAGE lx_app->get_text( ) TYPE 'E'.
ENDTRY.

The class, method and type names are generated from the WSDL – look them up in the proxy (SE80 / SPROXY). If logical_port_name is omitted, the default logical port is used.

Part 5 – REST services in ABAP

5.1 REST in one minute

REST (Representational State Transfer) is an architectural style: resources are addressed by URLs and changed with HTTP methods; data travels as JSON or XML; every request is stateless. Details and the six REST constraints are on page 08 OData, Part 1.

Method

Purpose

Idempotent?

Has body?

GET

Read a resource

Yes

No

POST

Create / trigger an action

No

Yes

PUT

Replace a resource completely

Yes

Yes

PATCH

Change some fields

Not guaranteed

Yes

DELETE

Delete a resource

Yes

No

A request = method + URL + headers + optional body; a response = status code + headers + body.

5.2 Why a plain REST service instead of OData?

  • OData needs an entity model (entity types, keys, sets). For a small technical endpoint (a webhook, a file upload, a callback from a third-party system with its own JSON format) a plain ICF handler is simpler.
  • You must then do yourself what Gateway gives for free: URL parsing, JSON mapping, paging, error format, CSRF protection, metadata/documentation.
  • OData does not require GET_ENTITYSET to allow POST. A modifying OData request only needs an X-CSRF-Token, fetched by any GET (service document or $metadata) – see page 08 OData, Part 11.

5.3 Provider: ICF handler class

REST in ABAP: client → SICF service node → handler class → business logic; REST library option
  • 1. SE24: create class ZCL_FLIGHT_REST_HANDLER and add interface IF_HTTP_EXTENSION (tab Interfaces).
  • 2. Implement method HANDLE_REQUEST: read method, parameters and body from server->request, write status, content type and body to server->response.
CLASS zcl_flight_rest_handler DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES if_http_extension.
ENDCLASS.

CLASS zcl_flight_rest_handler IMPLEMENTATION.
METHOD if_http_extension~handle_request.
CASE server->request->get_method( ).
WHEN if_http_request=>co_request_method_get.  "GET /sap/bc/zflights?carrid=LH
DATA(lv_carrid) = to_upper( server->request->get_form_field( 'carrid' ) ).
SELECT carrid, connid, cityfrom, cityto FROM spfli
WHERE carrid = @lv_carrid                 "host variable: no SQL injection
INTO TABLE @DATA(lt_flights).
server->response->set_content_type( 'application/json' ).
server->response->set_cdata( /ui2/cl_json=>serialize(
data        = lt_flights
pretty_name = /ui2/cl_json=>pretty_mode-camel_case ) ).
server->response->set_status( code = 200 reason = 'OK' ).

WHEN if_http_request=>co_request_method_post.  "POST with a JSON body
DATA ls_flight TYPE spfli.
/ui2/cl_json=>deserialize( EXPORTING json = server->request->get_cdata( )
CHANGING  data = ls_flight ).
" AUTHORITY-CHECK, validation, save via BAPI / class ...
server->response->set_status( code = 201 reason = 'Created' ).

WHEN OTHERS.
server->response->set_status( code = 405 reason = 'Method Not Allowed' ).
ENDCASE.
ENDMETHOD.
ENDCLASS.
  • 3. SICF (required – without it the class is never called): choose a path, e.g. default_host/sap/bc/ → right-click → New Sub-Element zflights → description, Logon Data (standard SAP logon, or a fixed service user only if really needed) → tab Handler List: enter ZCL_FLIGHT_REST_HANDLER → save → right-click → Activate Service.
  • 4. Test: https://<host>:<port>/sap/bc/zflights?carrid=LH&sap-client=100 in the browser (GET) or Postman.

Option B – SAP REST library

For several resources, inherit the SICF handler from CL_REST_HTTP_HANDLER, redefine IF_REST_APPLICATION~GET_ROOT_HANDLER and attach URL templates to CL_REST_ROUTER (lo_router->attach( iv_template = '/flights' iv_handler_class = 'ZCL_FLIGHTS_RESOURCE' )). Each resource class inherits CL_REST_RESOURCE and redefines IF_REST_RESOURCE~GET / POST / PUT / DELETE.

JSON in ABAP

  • /ui2/cl_json=>serialize( ) / deserialize( ) – most used, options for camelCase and initial values.
  • CALL TRANSFORMATION id SOURCE data = ls_data RESULT XML lo_writer with an if_sxml_writer of type JSON – the built-in asJSON format.
  • ABAP Cloud: xco_cp_json (released API) – /ui2/cl_json is also released there.

Security for your own REST services

  • HTTPS only (certificates in STRUST), authentication in SICF logon data, AUTHORITY-CHECK in the code.
  • CSRF: a browser-callable POST/PUT/DELETE endpoint needs CSRF protection. The REST library supports the same X-CSRF-Token: Fetch handshake as Gateway (CL_REST_HTTP_HANDLER has a built-in check, method HANDLE_CSRF_TOKEN); a plain IF_HTTP_EXTENSION handler does not protect you automatically.
  • Never build SQL from request parameters; validate all input.

5.4 Consumer: calling an external REST API from ABAP

Create an SM59 destination of type G (HTTP to external server: host, path prefix, SSL, logon) and use IF_HTTP_CLIENT:

cl_http_client=>create_by_destination( EXPORTING  destination = 'Z_FLIGHT_API'  "SM59 type G
IMPORTING  client      = DATA(lo_client)
EXCEPTIONS OTHERS      = 1 ).
IF sy-subrc <> 0.
RETURN.
ENDIF.
lo_client->request->set_method( if_http_request=>co_request_method_get ).
cl_http_utility=>set_request_uri( request = lo_client->request uri = '/flights?carrid=LH' ).

lo_client->send( EXCEPTIONS OTHERS = 1 ).
lo_client->receive( EXCEPTIONS OTHERS = 2 ).
IF sy-subrc = 0.
lo_client->response->get_status( IMPORTING code = DATA(lv_status) ).
DATA(lv_json) = lo_client->response->get_cdata( ).
ENDIF.
lo_client->close( ).
  • cl_http_client=>create_by_url( ) works too, but a destination keeps host and credentials out of the code.
  • ABAP Cloud (BTP, S/4HANA Cloud, clean core – see Clean Core › 01 Clean Core): use the released classes cl_http_destination_provider (destination from a communication arrangement) and cl_web_http_client_manager=>create_by_http_destination( ), then lo_client->execute( if_web_http_client=>get ).

Part 6 – SOAP vs REST vs OData

SOAP

Plain REST

OData (REST + rules)

Nature

Protocol (XML messaging)

Architectural style

Standardised REST protocol (OASIS / ISO)

Payload

XML only

JSON, XML, anything

JSON (V2 also Atom XML)

Contract

WSDL (strict)

None by default (OpenAPI optional)

$metadata (EDM model)

Operations

Named operations

HTTP verbs on URLs

CRUD-Q + query options + actions

Querying

Only what the operation offers

Whatever you code

$filter, $select, $expand, paging out of the box

Security

WS-Security, SSL

SSL, OAuth, CSRF – you build it

SSL, OAuth, CSRF built into Gateway

ABAP tools

SE80 / SPROXY, SOAMANAGER

SICF + IF_HTTP_EXTENSION / CL_REST_*

SEGW or RAP service binding

Typical use

B2B, PI/PO, legacy SAP–SAP enterprise services, reliable messaging

Webhooks, small technical endpoints, calling external APIs

Fiori / UI5 apps, SAP APIs on api.sap.com, Web APIs

Rule of thumb in S/4HANA: for new APIs and Fiori apps build OData with RAP (service binding: UI or Web API – see RAP › 03 and 11); use SOAP where partners or middleware require it; use a plain ICF REST handler only for special technical endpoints.

Part 7 – Interview questions

Q1. What is a web service, and what are WSDL and UDDI?

A standards-based interface for applications to exchange data over HTTP. WSDL is the XML contract (operations, messages, endpoint). UDDI was the registry standard for publishing/finding services – obsolete; the public registries were shut down around 2006.

Q2. SOAP vs REST?

SOAP is an XML protocol with a strict WSDL contract and WS-* standards. REST is an architectural style using URLs and HTTP verbs, usually with JSON – lighter and easier for web/mobile clients.

Q3. How do you expose a function module as a SOAP service?

RFC-enabled FM in SE37 → Utilities → More Utilities → Create Web Service → From the Function Module (service definition) → SOAMANAGER: Web Service Configuration → Create Service (binding, authentication) → copy the WSDL URL and test.

Q4. How do you consume a SOAP service in ABAP?

Generate a consumer proxy from the WSDL (SE80 Enterprise Services → Service Consumer, or SPROXY), create a logical port in SOAMANAGER, then instantiate the proxy class with the logical port and call its method, catching cx_ai_system_fault / cx_ai_application_fault.

Q5. Inside-out vs outside-in?

Inside-out: generate the service from existing ABAP (FM/BAPI). Outside-in: start from a WSDL or ESR interface and generate the ABAP proxy, then implement or call it.

Q6. What is a logical port and what happens without one?

The runtime configuration of a consumer proxy (endpoint URL, credentials, security) in SOAMANAGER. Without it the proxy call raises cx_ai_system_fault.

Q7. How do you build a REST service in ABAP without OData?

Class implementing IF_HTTP_EXTENSION, logic in HANDLE_REQUEST (method, form fields, body → JSON response and status), registered as handler of a service node in SICF and activated. For many resources use CL_REST_HTTP_HANDLER + CL_REST_ROUTER + CL_REST_RESOURCE.

Q8. How do you call an external REST API from ABAP?

SM59 destination type G + cl_http_client=>create_by_destination, set method and URI, send, receive, read status and body, deserialize the JSON. In ABAP Cloud: cl_http_destination_provider + cl_web_http_client_manager.

Q9. What is a CSRF token and when is it needed?

A token that proves a modifying request comes from the real client session. Fetch it with X-CSRF-Token: Fetch on a GET, send it on POST/PUT/PATCH/DELETE; missing → 403. GETs don't need it.

Q10. Where do you analyse failing SOAP calls?

SRT_UTIL (error log, traces), SRT_MONI (message monitor), SOAMANAGER Logs and Traces, ST22 for dumps, and a test with SoapUI / the WS Navigator.

Q11. When would you choose SOAP, plain REST or OData?

OData (RAP) for Fiori apps and new APIs; SOAP when a partner/middleware requires WSDL contracts or WS-Security; plain REST for small technical endpoints and when calling third-party JSON APIs.

🏠 Start Here · ◀ 08 · OData · 10 · Enhancements ▶ · Sections: CORE ABAP | OOPS ABAP | ABAP on HANA | Clean Core | RAP | ABAP Points | SAP Fiori | SAPUI5 | Mobile Development (MDK) | BTP Foundations | BTP Development | CAP | SAP Build | ABAP on BTP | Integration Suite | SAP Business AI | SAP BASIS | Security | SAP SDLC

Functional: FICO ABAP | TRM ABAP | VIM | SAP BIS | SD ABAP | MM ABAP | PP ABAP | QM ABAP | PM ABAP | PS ABAP | EWM | TM ABAP | GTM ABAP | EHS ABAP | HR ABAP | BW | SAP Datasphere | SAP Business Data Cloud | SAP MDG | SAP Analytics Cloud | SAP Ariba | SAP CX | SAP IBP