SAP Bit
Home
Get Started
  • Overview
  • Transaction Codes
  • Tables
  • Function Modules
  • Data Elements
  • Domains
  • IMG Activities
  • Overview
  • Standard RFCs
  • Custom RFCs
  • Overview
  • OData URLs
  • OData Services
GitHub
Home
Get Started
  • Overview
  • Transaction Codes
  • Tables
  • Function Modules
  • Data Elements
  • Domains
  • IMG Activities
  • Overview
  • Standard RFCs
  • Custom RFCs
  • Overview
  • OData URLs
  • OData Services
GitHub
  • OData

    • OData Services in SAP
    • OData URLs in SAP
    • OData Services in SAP

OData Services in SAP

This page provides detailed information on standard and custom OData services in SAP, including entity sets, operations, and implementation details.

Understanding OData Services

OData services in SAP are RESTful APIs that expose SAP data and functionality to external applications. Each service:

  • Has a unique service name and namespace
  • Contains one or more entity sets (collections of entities)
  • Defines the data model using metadata
  • Supports standard HTTP methods (GET, POST, PUT, DELETE)

Service Structure

Service Document

The service document lists all available entity sets in the service. It is accessed by requesting the service root URL:

https://<server>:<port>/sap/opu/odata/SAP/ZGWSAMPLE_SRV/

Metadata Document

The metadata document describes the data model of the service, including entity types, properties, and relationships. It is accessed by appending $metadata to the service root URL:

https://<server>:<port>/sap/opu/odata/SAP/ZGWSAMPLE_SRV/$metadata

The metadata document includes:

  • Entity types and their properties
  • Complex types
  • Associations between entity types
  • Function imports (actions)
  • Annotations

Entity Sets

Entity sets are collections of entities of a specific type. They are accessed by appending the entity set name to the service root URL:

https://<server>:<port>/sap/opu/odata/SAP/ZGWSAMPLE_SRV/SalesOrderSet

Standard SAP OData Services

SAP provides numerous standard OData services for various business domains:

Business Suite / ERP Services

Service NameDescriptionKey Entity SetsUsage
GWSAMPLE_BASICSample service for demonstrationBusinessPartnerSet, ProductSet, SalesOrderSetLearning and testing
API_BUSINESS_PARTNERBusiness Partner APIA_BusinessPartner, A_Customer, A_SupplierManage business partners
API_SALES_ORDER_SRVSales Order APIA_SalesOrder, A_SalesOrderItemManage sales orders
API_MATERIAL_DOCUMENT_SRVMaterial Document APIA_MaterialDocumentHeader, A_MaterialDocumentItemManage material documents
API_PURCHASEORDER_PROCESS_SRVPurchase Order APIA_PurchaseOrder, A_PurchaseOrderItemManage purchase orders

S/4HANA Services

Service NameDescriptionKey Entity SetsUsage
API_BUSINESS_PARTNERBusiness Partner APIA_BusinessPartner, A_Customer, A_SupplierManage business partners
API_PRODUCT_SRVProduct APIA_Product, A_ProductDescriptionManage products
API_SALES_ORDER_SRVSales Order APIA_SalesOrder, A_SalesOrderItemManage sales orders
API_PURCHASE_ORDER_SRVPurchase Order APIA_PurchaseOrder, A_PurchaseOrderItemManage purchase orders
API_BANK_SRVBank APIA_BankDetail, A_BankDirectoryEntryManage bank data

SAP Gateway Foundation Services

Service NameDescriptionKey Entity SetsUsage
CATALOGSERVICEService catalogServiceGroups, ServiceReferencesBrowse available services
METADATAMetadata repositoryNamespaces, Services, EntityTypesExplore service metadata
USERMANAGEMENTUser managementUsers, RolesManage users and roles

Creating Custom OData Services

Organizations can create custom OData services to expose specific business data and functionality:

Development Approaches

Gateway Service Builder (Transaction SEGW)

  1. Create a new project in Transaction SEGW
  2. Define the data model (entity types, properties, associations)
  3. Generate the runtime objects
  4. Implement the required methods (GET_ENTITY, GET_ENTITYSET, etc.)
  5. Register the service in Transaction /IWFND/MAINT_SERVICE

ABAP RESTful Programming Model (RAP)

  1. Define business objects using CDS views
  2. Create behavior definitions and implementations
  3. Expose the business objects as OData services
  4. Register the service in Transaction /IWFND/MAINT_SERVICE

Implementation Details

Data Provider Class

The data provider class implements the methods required to handle OData requests:

CLASS zcl_zsample_dpc IMPLEMENTATION.
  METHOD /iwbep/if_mgw_appl_srv_runtime~get_entityset.
    CASE iv_entity_name.
      WHEN 'Customer'.
        " Retrieve customer data
        SELECT * FROM kna1 INTO TABLE @DATA(lt_customers)
          UP TO 100 ROWS.
          
        " Convert to OData format
        LOOP AT lt_customers INTO DATA(ls_customer).
          APPEND INITIAL LINE TO et_entityset ASSIGNING FIELD-SYMBOL(<fs_entity>).
          MOVE-CORRESPONDING ls_customer TO <fs_entity>.
        ENDLOOP.
        
      WHEN 'SalesOrder'.
        " Retrieve sales order data
        " ...
    ENDCASE.
  ENDMETHOD.
  
  METHOD /iwbep/if_mgw_appl_srv_runtime~get_entity.
    " Implementation for retrieving a single entity
    " ...
  ENDMETHOD.
  
  " Other methods for create, update, delete operations
  " ...
ENDCLASS.

Model Provider Class

The model provider class defines the data model of the service:

CLASS zcl_zsample_mpc IMPLEMENTATION.
  METHOD define.
    " Define Customer entity type
    DATA: lo_entity_type TYPE REF TO /iwbep/if_mgw_odata_entity_typ.
    
    lo_entity_type = model->create_entity_type( 'Customer' ).
    lo_entity_type->set_keys( VALUE #( ( 'CustomerID' ) ) ).
    
    lo_entity_type->create_property( 'CustomerID' )->set_type_edm_string( ).
    lo_entity_type->create_property( 'CustomerName' )->set_type_edm_string( ).
    lo_entity_type->create_property( 'City' )->set_type_edm_string( ).
    lo_entity_type->create_property( 'Country' )->set_type_edm_string( ).
    
    " Create entity set
    model->create_entity_set( 'Customers' )->set_entity_type( 'Customer' ).
    
    " Define other entity types and sets
    " ...
  ENDMETHOD.
ENDCLASS.

Service Registration and Activation

Registration Process

  1. Open Transaction /IWFND/MAINT_SERVICE
  2. Select "Add Service"
  3. Enter the system alias and service name
  4. Add the service to a service group
  5. Activate the service

Configuration Parameters

  • CORS Settings: Enable Cross-Origin Resource Sharing
  • Authentication: Configure authentication methods (Basic, OAuth, SAML)
  • Authorization: Define authorization objects for access control
  • Caching: Configure caching behavior for improved performance

Testing OData Services

SAP Gateway Client

Transaction /IWFND/GW_CLIENT provides a user interface for testing OData services:

  1. Enter the service URL
  2. Select the HTTP method (GET, POST, PUT, DELETE)
  3. Add request headers and body (for POST/PUT)
  4. Execute the request
  5. View the response

External Tools

  • Postman: Popular API testing tool
  • cURL: Command-line tool for making HTTP requests
  • SAP API Business Hub: Test SAP APIs directly in the browser

Security Considerations

Authentication

OData services support various authentication methods:

  • Basic Authentication: Username and password
  • OAuth 2.0: Token-based authentication
  • SAML: Security Assertion Markup Language
  • X.509 Certificates: Certificate-based authentication

Authorization

Access to OData services can be controlled using:

  • PFCG Roles: SAP role-based authorization
  • Scopes: OAuth 2.0 scopes for fine-grained access control
  • Custom Authorization Checks: Implemented in the service code

Data Protection

  • Implement field-level authorization
  • Filter sensitive data before returning it
  • Use HTTPS for secure communication
  • Implement proper input validation to prevent injection attacks

Performance Optimization

Server-Side Optimization

  • Use appropriate database indexes
  • Implement efficient ABAP code
  • Use entity buffering where appropriate
  • Optimize database queries

Client-Side Optimization

  • Use $select to limit the properties returned
  • Use $filter to reduce the amount of data transferred
  • Use $expand judiciously
  • Implement client-side caching

Monitoring and Troubleshooting

Monitoring Tools

  • Transaction /IWFND/ERROR_LOG: View OData service errors
  • Transaction STAD: Runtime analysis
  • Transaction ST22: ABAP dump analysis
  • Transaction SLG1: Application log

Common Issues

  • 404 Not Found: Service or entity not found
  • 401 Unauthorized: Authentication failed
  • 403 Forbidden: Authorization failed
  • 500 Internal Server Error: Server-side error

Best Practices

  • Design services around business entities and use cases
  • Follow OData protocol standards
  • Implement proper error handling
  • Document services thoroughly
  • Use standard services where available
  • Test services with various client scenarios
  • Consider performance implications for large data sets
  • Implement proper security measures
Edit this page
Last Updated:: 4/12/25, 1:49 AM
Contributors: Taylor Brazelton
Prev
OData URLs in SAP