SAP API INTEGRATION GUIDE
SAP API Integration – Complete Beginner Guide
(With Simple Example)
chaudharichetan0066@[Link]
SAP API INTEGRATION GUIDE
1. What is API Integration?
API (Application Programming Interface) integration allows SAP to
communicate with external systems (websites, mobile apps, third‑party
tools, cloud platforms, etc.) using HTTP/HTTPS.
In simple words:
SAP ↔ API ↔ External System
Example: - SAP sends customer data to a logistics system - SAP fetches
exchange rates from a public API - SAP receives sales orders from an
e‑commerce website
2. Types of API Integration in SAP
2.1 Outbound API (SAP → External System)
SAP calls an external API.
Example: - Send invoice data to a tax portal - Get weather or exchange
rate from external service
2.2 Inbound API (External System → SAP)
External system calls SAP.
Example: - Website creates sales order in SAP - Mobile app fetches
employee details from SAP
3. API Communication Methods in SAP
Method Description
REST API Most commonly used (JSON format)
SOAP Web Service XML based service
OData SAP standard REST service
RFC / IDoc SAP to SAP or legacy integration
chaudharichetan0066@[Link]
SAP API INTEGRATION GUIDE
In modern SAP, REST + OData are most used.
4. Tools Used for API Integration in SAP (ABAP)
Tool/Class Purpose
CL_HTTP_CLIENT Call REST APIs
IF_HTTP_CLIENT Interface for HTTP communication
/UI2/CL_JSON Convert JSON ↔ ABAP
SM59 Create HTTP destination
SICF Activate HTTP services
STRUST SSL certificate setup
5. End-to-End Scenario (Simple Example)
Scenario:
SAP needs to fetch exchange rates from an external API.
API URL:
[Link]
Response (JSON):
{
"base": "USD",
"rates": {
"INR": 83.25
}
}
Goal: Call API from ABAP and read INR value.
chaudharichetan0066@[Link]
SAP API INTEGRATION GUIDE
6. Step-by-Step Outbound API Integration (REST)
Step 1: Create HTTP Destination (SM59)
1. Go to SM59
2. Create destination type G (HTTP Connection)
3. Maintain:
o Target Host: [Link]
o Service No: 443
o Path Prefix: /latest
4. Save and test connection
Step 2: ABAP Program to Call API
DATA: lo_http_client TYPE REF TO if_http_client,
lv_response TYPE string,
ls_data TYPE string.
CALL METHOD cl_http_client=>create_by_destination
EXPORTING
destination = 'EXCHANGE_API'
IMPORTING
client = lo_http_client.
lo_http_client->request->set_method( 'GET' ).
lo_http_client->request->set_header_field(
name = 'Content-Type'
value = 'application/json' ).
CALL METHOD lo_http_client->send.
CALL METHOD lo_http_client->receive.
lv_response = lo_http_client->response->get_cdata( ).
WRITE: / lv_response.
chaudharichetan0066@[Link]
SAP API INTEGRATION GUIDE
Step 3: Convert JSON to ABAP Structure
TYPES: BEGIN OF ty_rates,
inr TYPE string,
END OF ty_rates,
BEGIN OF ty_data,
base TYPE string,
rates TYPE ty_rates,
END OF ty_data.
DATA: ls_result TYPE ty_data.
/ui2/cl_json=>deserialize(
EXPORTING json = lv_response
CHANGING data = ls_result ).
WRITE: / 'USD to INR:', ls_result-rates-inr.
7. Inbound API in SAP (Expose SAP as API)
Methods: 1. Create OData Service (SEGW) 2. Create REST API using
ICF Handler 3. Use SAP Gateway / RAP (Recommended for
S/4HANA)
Simple Example Scenario
External system sends customer data → SAP saves in table.
chaudharichetan0066@[Link]
SAP API INTEGRATION GUIDE
Flow:
External System
HTTP POST
SAP ICF Service
ABAP Logic
Database
8. Authentication Methods
Type Usage
Basic Authentication Username & Password
API Key Header parameter
OAuth 2.0 Secure modern authentication
Client Certificate SSL based authentication
Example Header:
lo_http_client->request->set_header_field(
name = 'Authorization'
value = 'Bearer <token>' ).
chaudharichetan0066@[Link]
SAP API INTEGRATION GUIDE
9. Error Handling Best Practice
Always check:
DATA lv_status TYPE i.
lv_status = lo_http_client->response->get_status( ).
IF lv_status = 200.
WRITE: 'Success'.
ELSE.
WRITE: 'Error:', lv_status.
ENDIF.
10. Complete Integration Flow (Architecture)
SAP Program
CL_HTTP_CLIENT
HTTP/HTTPS
External API Server
JSON Response
chaudharichetan0066@[Link]
SAP API INTEGRATION GUIDE
/UI2/CL_JSON
ABAP Structure
Database / Display
11. Real-Time Use Cases in Projects
• GST / Tax portal integration
• Payment gateway integration
• Courier / Logistics tracking
• Bank API integration
• Third‑party HR system integration
• E‑commerce order sync
12. Security Considerations
• Use HTTPS only
• Maintain certificates in STRUST
• Do not hardcode credentials
• Store API keys securely (TVARVC / Secure store)
13. Performance Tips
• Use background jobs for large data
• Avoid multiple API calls inside loops
• Use batch APIs if available
chaudharichetan0066@[Link]
SAP API INTEGRATION GUIDE
14. Interview Questions
Q1. How do you call REST API in SAP?
Q2. How do you convert JSON to ABAP?
Q3. Where do you maintain API URL?
Q4. Difference between OData and REST?
15. Summary
API integration in SAP allows communication with external systems
using HTTP/REST. The main steps are: 1. Create destination (SM59) 2.
Call API using CL_HTTP_CLIENT 3. Receive JSON response 4.
Convert to ABAP structure 5. Process data
This is one of the most important skills for modern SAP ABAP and
S/4HANA developers.
chaudharichetan0066@[Link]