IT CanvassTalk to an advisor
SAP examples · LessonReviewed by Arjun, SAP Solution Architect · Updated · Published · SAP S/4HANA 2023 · all levels

SAP API examples: an OData call and a BAPI call

These API examples show calling SAP over its interfaces, an OData request, a BAPI call, illustrating how external and custom code interacts with SAP data.

Quick answer

Two API calls in SAP's two dominant styles. OData: GET A_BusinessPartner from API_BUSINESS_PARTNER with $top=5, a bearer token and Accept application/json, the pattern for web and cloud. BAPI: CALL FUNCTION BAPI_MATERIAL_GET_DETAIL from ABAP with the material exported and general data and RETURN imported. Authenticate properly, check HTTP status or RETURN, use released APIs.

Key takeaways
  • Watch out: Skipping result/error checks.
  • Worked examples: odata (external call), bapi (abap), what it teaches.
  • How API examples fits into SAP development and the wider SAP landscape

OData (external call)

GET /sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner?$top=5
Authorization: Bearer <token>
Accept: application/json

BAPI (ABAP)

CALL FUNCTION 'BAPI_MATERIAL_GET_DETAIL'
  EXPORTING material = lv_matnr
  IMPORTING material_general_data = ls_data
            return = ls_return.

What it teaches

The examples show the two dominant styles: modern OData/REST (JSON over HTTP, token auth, query options) for web/cloud, and classic BAPI/RFC for program-level SAP access. Always authenticate properly, check results (HTTP status or RETURN), and use released APIs from the Business Accelerator Hub.

Common pitfalls

  • Skipping result/error checks.
  • Hard-coded credentials.
  • Using unreleased interfaces.
Already working on SAP and stuck on a live ticket?Get an expert SAP developer on screen-share to finish your daily tasks with you. Deliver on time, protect your reputation and your job. Monthly support only, no task-wise plans.Task assigned · no idea where to startStill stuck · your job on the lineExpert joins your screenDelivered on timeExplore On Job Support