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 and token

  • 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)

  1. Create HTTP client:
CALL METHOD cl_http_client=>create_by_url
  EXPORTING url = lv_url
  IMPORTING client = lo_http_client.
  1. 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' ).
  1. 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( ).
  1. 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

  1. 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.
  1. Convert to Base64 using:
CALL FUNCTION 'SCMS_BASE64_ENCODE_STR'
  EXPORTING input = lv_bin_file
  IMPORTING output = lv_base64_file.
  1. 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 payload

  • Send 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)

CriteriaABAP 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

1
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.