OData Gateway
Architect / Cross-trackintermediate

OData Gateway Part 5: Service Registration, $metadata and Gateway Client Testing

Key takeaway

Make a SEGW service reachable: activate it in /IWFND/MAINT SERVICE with a system alias, check the ICF node, read $metadata, test all CRUD operations in the Gateway client /IWFND/GW CLIENT, clear metadata caches and transport the registration.

Explanation

📌 KEY POINTS
✅ Generating runtime objects registers the service in the backend; it must also be activated on the frontend in /IWFND/MAINT_SERVICE (Add Service → system alias → package).

✅ $metadata shows what clients will see: entity types, keys, properties, navigation. Read it before coding any consumer.

✅ /IWFND/GW_CLIENT tests GET, POST, PUT, PATCH/MERGE, DELETE and $batch inside SAP, with CSRF tokens and payload templates.

⚠️ After model changes, stale metadata caches cause "property not found" errors — clean caches with /IWFND/CACHE_CLEANUP and /IWBEP/CACHE_CLEANUP.

━━━━━━━━━━━━━━━━━━━━
▶ WHERE WE ARE

Part 4 explained frontend and backend. Now we make the service reachable and test it.

━━━━━━━━━━━━━━━━━━━━
▶ 1. ACTIVATION

  • /IWFND/MAINT_SERVICE → Add Service → system alias (LOCAL in embedded) → filter by technical service name (ZSALES_SRV) → Add Selected Services → package (transportable).
  • This creates the frontend registration and the ICF node /sap/opu/odata/sap/ZSALES_SRV.
  • Check SICF: node must be active.

━━━━━━━━━━━━━━━━━━━━
▶ 2. $METADATA

  • URL: /sap/opu/odata/sap/ZSALES_SRV/$metadata
  • Verify: entity sets, key properties, EDM types, lengths, navigation properties, sap:creatable/updatable flags.
  • Service document (root URL) lists entity sets.

━━━━━━━━━━━━━━━━━━━━
▶ 3. GATEWAY CLIENT (/IWFND/GW_CLIENT)

  • Enter request URI, choose HTTP method, execute.
  • GET with $format=json for readable output.
  • For POST/PUT/DELETE: first GET with header x-csrf-token: Fetch, then send the token (the client handles this automatically in most releases); "Use as Request" copies a response into the request body.
  • Save test cases in the Gateway client for regression.

━━━━━━━━━━━━━━━━━━━━
▶ 4. CACHES

  • Frontend and backend cache the metadata.
  • After regenerating MPC: /IWBEP/CACHE_CLEANUP (backend), /IWFND/CACHE_CLEANUP (frontend), or "Cleanup Cache" in MAINT_SERVICE.

━━━━━━━━━━━━━━━━━━━━
▶ 5. AUTHORIZATION

  • S_SERVICE authorization for the service on the frontend (added via PFCG with the service's TADIR entry).
  • Business authorizations inside your DPC code (AUTHORITY-CHECK) or via CDS DCL.

━━━━━━━━━━━━━━━━━━━━
▶ 6. TRANSPORT

  • Backend: SEGW project, MPC/DPC classes, model and service registration.
  • Frontend: service registration (/IWFND/ objects) and ICF node — in the package chosen during activation. In a hub, activate or transport separately on each FES.

━━━━━━━━━━━━━━━━━━━━
▶ STEP BY STEP

  1. Activate ZSALES_SRV in /IWFND/MAINT_SERVICE with the correct alias.
  2. Open $metadata and verify keys and types.
  3. In /IWFND/GW_CLIENT run GET SalesOrderSet?$format=json.
  4. Change a property length in SEGW, regenerate, observe stale metadata, then clean caches.
  5. Save the GET as a test case.

✅ CHECKPOINT: you can register, verify, test and transport a Gateway service without guesswork.

Code example

ABAP Code
* ===== STEP 1: activation checklist (transactions) =====* /IWFND/MAINT_SERVICE -> Add Service -> System Alias LOCAL*   -> Technical service name ZSALES_SRV -> Add Selected -> package ZSALES* SICF -> /default_host/sap/opu/odata/sap/ZSALES_SRV -> active * ===== STEP 2: Gateway client requests (/IWFND/GW_CLIENT) =====* GET    /sap/opu/odata/sap/ZSALES_SRV/$metadata* GET    /sap/opu/odata/sap/ZSALES_SRV/SalesOrderSet?$top=5&$format=json* GET    /sap/opu/odata/sap/ZSALES_SRV/SalesOrderSet('0000004711')* POST   /sap/opu/odata/sap/ZSALES_SRV/SalesOrderSet   (header x-csrf-token) * ===== STEP 3: quick HTTP smoke test from classic ABAP =====REPORT zgw_smoke_test. DATA: lo_client TYPE REF TO if_http_client,      lv_code   TYPE i,      lv_reason TYPE string,      lv_body   TYPE string. PARAMETERS p_uri TYPE string LOWER CASE  DEFAULT '/sap/opu/odata/sap/ZSALES_SRV/$metadata'. START-OF-SELECTION.  CALL METHOD cl_http_client=>create_internal    IMPORTING      client = lo_client.   cl_http_utility=>set_request_uri( request = lo_client->request                                    uri     = p_uri ).  lo_client->request->set_method( 'GET' ).  lo_client->send( ).  lo_client->receive( ).  lo_client->response->get_status( IMPORTING code   = lv_code                                             reason = lv_reason ).  lv_body = lo_client->response->get_cdata( ).   WRITE: / 'HTTP status:', lv_code, lv_reason.  WRITE: / lv_body(200). * ===== STEP 4: after model changes =====* /IWBEP/CACHE_CLEANUP  and  /IWFND/CACHE_CLEANUP

Real project scenario

After adding a field DeliveryDate to an entity, the Fiori app failed with "Property DeliveryDate not found". The developer re-checked MPC_EXT and DPC_EXT for a day.
$metadata in the browser still showed the old model — the frontend was serving a cached version. Running /IWBEP/CACHE_CLEANUP and /IWFND/CACHE_CLEANUP (and later in each tier after transport) made the new property appear. The team added cache cleanup to the post-transport checklist and saved Gateway client test cases for every entity set.

Common mistakes

  • Generating runtime objects but never activating the service in /IWFND/MAINT_SERVICE.
  • Local package ($TMP) during activation, so the registration is not transported.
  • Forgetting cache cleanup after model changes.
  • Testing only GET, never POST/PUT/DELETE with CSRF tokens.
  • Missing S_SERVICE in the users' roles.

Best practices

  • Verify $metadata first after every model change.
  • Activate in a transportable package; check the ICF node.
  • Keep saved Gateway client test cases per entity set.
  • Include cache cleanup in the transport checklist.
  • Grant S_SERVICE via PFCG roles, not SAP_ALL-like shortcuts.

Interview angle

Questions: "How do you register an OData service?", "Service works in DEV but not in QA — what do you check?", "What is x-csrf-token?"
Strong answer: activate in /IWFND/MAINT_SERVICE with system alias and transportable package, check ICF node, verify $metadata, test in /IWFND/GW_CLIENT. In QA check registration, alias, ICF node, caches, S_SERVICE, error logs. CSRF token is fetched with GET (x-csrf-token: Fetch) and sent with modifying requests to prevent cross-site request forgery.

Practice this lesson

Quick check

1. A POST from an external test tool to a Gateway service fails with 403 "CSRF token validation failed". What is missing?

2. After changing an entity in SEGW and regenerating, the app still sees the old $metadata. What is the usual fix?

3. Which transaction activates a Gateway service after SEGW generation?

Interview questions

1. After transporting a changed OData service to QA, the Fiori app fails with "Property DeliveryDate not found" although the code is correct. What do you check?

Answer it in your own words first, then compare.

2. How would you expose a custom entity to Fiori using SEGW?

Answer it in your own words first, then compare.

Practice more with Interview AI →

Reference-verified: the steps are checked against official SAP documentation and tutorials, and object and field names in the sample code are checked for consistency. The code has not been compiled or run on an SAP system by ERPClimb. Syntax marked release-dependent varies by SAP release, so check it in your own system.

More lessons in this topic

Interview questions on this topic

Related SAP topics