SAP Gateway Part 3: SEGW Model, Registration, Metadata and Transports
Walk through the SEGW service lifecycle: model entity types and sets, generate MPC and DPC classes, implement DPC EXT, register the service in /IWFND/MAINT SERVICE, check metadata, and transport everything consistently.
Explanation
📌 KEY POINTS
✅ SEGW flow: model → generate runtime artifacts (MPC, DPC, *_EXT) → implement DPC_EXT → register → test.
✅ Only change the *_EXT classes; generated base classes are overwritten on regeneration.
✅ Register the service in /IWFND/MAINT_SERVICE (on the hub in hub scenarios) with the right system alias.
⚠️ Transport SEGW project, classes AND the service registration — missing one breaks QAS/PRD.
━━━━━━━━━━━━━━━━━━━━
▶ WHERE WE ARE
Parts 1–2 explained the runtime. This part shows how a classic SEGW service is built and moved through the landscape. (New services: use RAP; this knowledge is for maintaining existing ones.)
━━━━━━━━━━━━━━━━━━━━
▶ 1. MODEL IN SEGW
- Create project ZPURCHREQ (package, description).
- Data Model: entity types (PurchaseRequest, PurchaseRequestItem) with properties, keys, and flags (creatable, updatable, filterable, sortable); entity sets; associations and navigation properties; function imports.
- Model from a DDIC structure, from RFC/BAPI, or manually.
━━━━━━━━━━━━━━━━━━━━
▶ 2. GENERATE RUNTIME ARTIFACTS
"Generate Runtime Objects" creates:
- ZCL_ZPURCHREQ_MPC and ZCL_ZPURCHREQ_MPC_EXT — model provider (metadata).
- ZCL_ZPURCHREQ_DPC and ZCL_ZPURCHREQ_DPC_EXT — data provider (CRUD methods).
- Registration objects: technical model and technical service name (ZPURCHREQ_SRV).
📌 REMEMBER: implement and enhance only in the _EXT classes.\n\n━━━━━━━━━━━━━━━━━━━━\n▶ 3. IMPLEMENT DPC_EXT\nRedefine the methods you need: GET_ENTITYSET, GET_ENTITY, CREATE_ENTITY, UPDATE_ENTITY, DELETE_ENTITY, CREATE_DEEP_ENTITY, EXECUTE_ACTION. Keep business logic in separate classes (reusable, testable); DPC_EXT maps OData ↔ business logic.
MPC_EXT: redefine DEFINE for extra annotations or metadata tweaks.
━━━━━━━━━━━━━━━━━━━━
▶ 4. REGISTER AND ACTIVATE
- /IWFND/MAINT_SERVICE → Add Service → system alias (LOCAL for embedded) → find ZPURCHREQ_SRV → add with a package and transport.
- This creates the ICF node and the service entry (with version).
- Test with /IWFND/GW_CLIENT: $metadata, then entity sets.
━━━━━━━━━━━━━━━━━━━━
▶ 5. METADATA AND CHANGES
- Model changes → regenerate → implement → clean metadata cache on the backend and hub.
- Keep property names stable once consumers exist (same contract rules as in RAP Service Definitions Part 3).
━━━━━━━━━━━━━━━━━━━━
▶ 6. TRANSPORTS
- Workbench transport: SEGW project, MPC/DPC(_EXT) classes, business logic classes.
- The service registration on the gateway system (hub or embedded) is a separate transportable entry created during registration — check it is in a transport.
- After import: verify service active, system alias correct, cache cleaned.
━━━━━━━━━━━━━━━━━━━━
▶ STEP BY STEP
- Create a small SEGW project with one entity set.
- Generate, redefine GET_ENTITYSET in DPC_EXT.
- Register in /IWFND/MAINT_SERVICE; test in GW client.
- Add a property; regenerate; clean cache; verify $metadata.
✅ CHECKPOINT: you can build, register and transport a SEGW service safely.
Code example
" ===== SEGW lifecycle checklist =====" 1 SEGW: project ZPURCHREQ, package ZPR_GW" entity type PurchaseRequest (key RequestID), entity set PurchaseRequestSet" entity type PurchaseRequestItem, association Header 1:n Item, navigation ToItems" 2 Generate runtime objects:" ZCL_ZPURCHREQ_MPC / _MPC_EXT (model provider)" ZCL_ZPURCHREQ_DPC / _DPC_EXT (data provider) <- implement ONLY in _EXT" technical service ZPURCHREQ_SRV, version 0001" 3 Implement DPC_EXT (below)" 4 /IWFND/MAINT_SERVICE -> Add Service -> alias LOCAL / backend alias" -> ZPURCHREQ_SRV -> package + transport (creates ICF node + service entry)" 5 /IWFND/GW_CLIENT: /sap/opu/odata/sap/ZPURCHREQ_SRV/$metadata" 6 Transport: SEGW project + classes + business classes + service registration " ===== DPC_EXT: thin mapping layer, logic in a separate class =====CLASS zcl_zpurchreq_dpc_ext DEFINITION PUBLIC INHERITING FROM zcl_zpurchreq_dpc CREATE PUBLIC. PROTECTED SECTION. METHODS purchaserequestse_get_entity REDEFINITION. METHODS purchaserequestse_get_entityset REDEFINITION.ENDCLASS. CLASS zcl_zpurchreq_dpc_ext IMPLEMENTATION. METHOD purchaserequestse_get_entity. " key from the URL: PurchaseRequestSet('4711') DATA(request_id) = CONV char10( it_key_tab[ name = 'RequestID' ]-value ). er_entity = CORRESPONDING #( zcl_pr_service=>read_request( request_id ) ). IF er_entity IS INITIAL. RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception EXPORTING textid = /iwbep/cx_mgw_busi_exception=>resource_not_found entity_type = iv_entity_name. ENDIF. ENDMETHOD. METHOD purchaserequestse_get_entityset. " paging / filtering done properly in Part 4 et_entityset = CORRESPONDING #( zcl_pr_service=>read_requests( max_rows = 100 ) ). ENDMETHOD.ENDCLASS. " ===== MPC_EXT: metadata tweaks only =====" METHOD define. super->define( ). " e.g. add annotations / set property flags" ENDMETHOD.Real project scenario
A SEGW service worked in DEV but returned 404 in QAS. The classes and project had been transported, but the service registration created in /IWFND/MAINT_SERVICE was saved as a local object in DEV, so QAS had no service entry.
The team registered the service with a transport, imported it, cleaned the metadata caches and verified the ICF node. They added "registration in a transport?" to the SEGW release checklist.
Common mistakes
- Changing generated MPC/DPC base classes instead of _EXT.
- Business logic directly in DPC_EXT.
- Registration saved as local object, not transported.
- Wrong system alias when registering on the hub.
- Forgetting cache cleanup after model changes.
- Renaming properties used by consumers.
Best practices
- Use SEGW only to maintain or extend existing services; RAP for new ones.
- Implement only in _EXT classes; keep logic in reusable classes.
- Register services with a transport and correct alias.
- Clean metadata caches after changes.
- Keep a release checklist for SEGW transports.
Interview angle
Questions: "Explain the SEGW development process", "What are MPC and DPC classes?", "Why do services fail after transport?"
Strong answer: model entity types/sets/associations in SEGW, generate MPC (metadata) and DPC (data) classes plus _EXT subclasses, implement CRUD by redefining DPC_EXT methods (logic in separate classes), register in /IWFND/MAINT_SERVICE with system alias and transport, test in GW client. Typical transport issues: missing registration, wrong alias, stale caches, inactive ICF node.
Practice this lesson
Quick check
1. Where should custom code be implemented in a SEGW project?
2. Which tool records the payload of requests for one specific user to analyze an intermittent issue?
3. How should a DPC_EXT method report a business error such as "supplier blocked"?
Interview questions
1. When would you still use SEGW today, and how do you keep SEGW services maintainable?
Answer it in your own words first, then compare.
2. A SEGW service works in DEV but returns 404 in QAS. What are the likely causes?
Answer it in your own words first, then compare.
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.