SAP Knowledge Base Article - Public

3616518 - API_SALES_ORDER_SRV – Internal Server Error When Using "$inlinecount=allpages" in SAP S/4HANA Cloud Public Edition

Symptom

  • Calling the OData service API_SALES_ORDER_SRV with the parameter $inlinecount=allpages results in a 500 Internal Server Error.
  • Other requests with limits like $top=300, $top=500, or $top=1000 work as expected.
  • Error Message: "In the context of Data Services an unknown internal server error occurred"

Environment

SAP S/4HANA Cloud Public Edition

Reproducing the Issue

  1. Perform a GET request to the Sales Order API without filters:
    • GET https://<host>/sap/opu/odata/sap/API_SALES_ORDER_SRV/A_SalesOrder?$inlinecount=allpages
    • Result:  500 Internal Server Error
  2. Perform a GET request to the Sales Order API with a record limit using $top=300:

    • GET https://<host>/sap/opu/odata/sap/API_SALES_ORDER_SRV/A_SalesOrder?$top=300
    • Result:  200 OK (Success)

Cause

The $inlinecount=allpages parameter instructs the backend to count all sales orders before returning data, which can cause:

  • High database load when querying a large dataset.
  • Memory overflow or timeout issues if too many records exist.
  • System constraints in SAP Gateway or backend that prevent large count operations.

Resolution

  1. Use Pagination Instead of $inlinecount=allpages (Recommended):
  • Rather than fetching all records at once, retrieve data in smaller chunks using pagination.
  • Example:

GET /A_SalesOrder?$top=1000&$skip=0  

GET /A_SalesOrder?$top=1000&$skip=1000  

GET /A_SalesOrder?$top=1000&$skip=2000  

  • Why? This avoids forcing the backend to count all records and reduces system load.

    2. Estimate Total Record Count Without $inlinecount:

  • If a total record count is needed, consider these alternatives:
  • Fetch a small sample ($top=1) and check the highest SalesOrder ID.
  • Use a custom CDS View or backend report to get the total count separately. Note: Contact SAP Account manager or Consultant for this request.

    3. If $inlinecount=allpages must be used, engage SAP BASIS team for performance tuning.

See Also

3450503 - Timeout Error in API_SALES_ORDER_SRV - SAP for Me

Keywords

SAP S/4HANA Cloud Public Edition, internal server error, sales order api, API_SALES_ORDER_SRV, $top, pagination, performance, sap s/4hana cloud, $inlinecount=allpages, pagination, performance issue, high database load, memory overflow, timeout issues, sap gateway, backend constraints , KBA , SD-SLS-SO-2CL , Sales Orders (Public Cloud) , Problem

Product

SAP S/4HANA Cloud Public Edition all versions