Implementing HTTP Integration in ABAP


This guide documents how to implement direct HTTP integration in ABAP without using middleware.
The method shared here integrates SAP with an external system (e.g. Baselinker) through a REST API by sending and receiving JSON, handling retries, and transmitting PDF documents encoded in Base64.
Read carefully docu for your partner system! For example for Baselinker https://api.baselinker.com/. They always provide mandatory info and examples of requests.
๐น 1. Retrieve Configuration Parameters
Start by storing all integration parameters (such as API URL, token, retry count) in a Z-table. Query this table at runtime to keep your code flexible and environment-agnostic.
Key steps:
Query parameter table (
SELECT * FROM zbaselinker_param INTO TABLE lt_param
)Validate mandatory parameters like
url
andtoken
Optional: Retrieve retry count and convert to integer
๐น 2. Read Required Business Data
Query business data needed for the external call:
- Example: Get customer order number for the invoice
SELECT SINGLE * INTO lv_bstkd
FROM vbrp INNER JOIN vbkd ON vbkd~vbeln = vbrp~aubel
WHERE vbrp~vbeln = iv_vbeln.
๐น 3. Prepare JSON Request
Use predefined JSON templates with placeholders (&1
, &2
, etc.). Replace these dynamically with actual values.
lv_json_request = gc_json_getinvoices.
REPLACE '&1' IN lv_json_request WITH 'getInvoices'.
REPLACE '&2' IN lv_json_request WITH lv_bstkd.
๐น 4. Execute HTTP Call (GET Invoice ID)
- Create HTTP client:
CALL METHOD cl_http_client=>create_by_url
EXPORTING url = lv_url
IMPORTING client = lo_http_client.
- Set headers:
lo_http_client->request->set_header_field( name = 'X-BLToken' value = lv_token ).
lo_http_client->request->set_header_field( name = 'Content-Type' value = 'application/x-www-form-urlencoded' ).
- Set payload and send:
lo_http_client->request->set_method( 'POST' ).
lo_http_client->request->set_cdata( lv_json_request ).
lo_http_client->send( ).
lo_http_client->receive( ).
- Deserialize JSON:
/ui2/cl_json=>deserialize(
EXPORTING json = lv_json_response
CHANGING data = ls_response ).
Include retry logic (WHILE lv_retry < lv_retry_count
) in case of errors or communication failures.
๐น 5. Prepare PDF for Upload
- Use
CONVERT_OTF
to convert SAP OTF format to binary PDF:
CALL FUNCTION 'CONVERT_OTF'
EXPORTING format = 'PDF'
IMPORTING bin_file = lv_bin_file
TABLES otf = it_otf lines = lt_lines.
- Convert to Base64 using:
CALL FUNCTION 'SCMS_BASE64_ENCODE_STR'
EXPORTING input = lv_bin_file
IMPORTING output = lv_base64_file.
- Replace values into JSON upload template:
REPLACE '&3' WITH lv_base64_file.
REPLACE '&4' WITH iv_vbeln.
๐น 6. Execute HTTP Call (Send File)
Re-use the same HTTP client (lo_http_client
) and update the request body with the new payload.
Set
cdata
with Base64 payloadSend and receive
Deserialize JSON response
Retry if needed
๐น 7. Final Error Handling and Logging
Use
MESSAGE ... INTO lv_dummy
and custom logging (add_msg( )
)Return on error or complete successfully with
ev_rc = '0'
๐ง When to Use ABAP Directly vs. Middleware (PO/CPI)
Criteria | ABAP Direct (Recommended) | Middleware (PO/CPI) Recommended |
One-to-one integration | โ | โ |
Simple JSON/REST calls | โ | โ |
Real-time response needed | โ | โ |
Requires transformation/mapping | โ | โ |
Multiple systems (fan-out) | โ | โ |
OAuth2 or SAML authentication | โ (harder) | โ |
Central monitoring required | โ | โ |
External API outside firewall | โ (risk) | โ |
Low maintenance, fast delivery | โ | โ |
Dzmitryi Kharlanau, Senior SAP consultant
Subscribe to my newsletter
Read articles from Dzmitryi Kharlanau directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Dzmitryi Kharlanau
Dzmitryi Kharlanau
SAP Logistics Consultant with 10+ years of experience in SAP SD, SAP MM, SAP LE, and SAP IS-Automotive. Skilled in SAP system support, integration, and process improvements. Achievements โ๏ธ Delivered custom logistics solutions, overseeing the entire process from concept to go-live. โ๏ธ Achieved SLA compliance in JIT environments, managing tasks from requirements to release independently. โ๏ธ Resolved complex issues swiftly, minimizing downtime and optimizing efficiency. Interests: Motivated to work with ๐ง S/4HANA SD, MM, BTP, and ABAP, taking responsibility for end-to-end solutions.