OData Gateway
Architect / Cross-trackintermediate

OData Gateway Part 2: SEGW vs RAP — Two Ways to Build OData

Key takeaway

Compare the classic SEGW approach (code-based DPC EXT, referenced data sources, mapped CDS) with RAP (CDS + behavior definition + service definition + service binding), including the obsolete @OData. publish shortcut, and decide which to use on a given system and project.

Explanation

📌 KEY POINTS
✅ SEGW (transaction-based Gateway Service Builder): model entity types and write CRUD logic yourself in DPC_EXT — full control, more code.

✅ RAP (ABAP RESTful Application Programming Model): CDS views + behavior definition + service definition + service binding generate the OData service; the framework handles CRUD, $filter, paging, $expand, draft and ETags.

✅ SAP's strategic model for new development is RAP (and the only one in ABAP Cloud); SEGW remains supported for existing services and older releases.

⚠️ @OData.publish: true on a CDS view was a shortcut in S/4 1511–1909-era systems; it is considered obsolete — do not start new services with it.

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

Part 1 built a small SEGW service. Before going deeper, know the alternative you will meet on every S/4 project.

━━━━━━━━━━━━━━━━━━━━
▶ 1. SEGW CODE-BASED

  • Entity types modelled or imported (DDIC, RFC/BAPI).
  • Logic in DPC_EXT methods: GET_ENTITYSET, CREATE_ENTITY, etc.
  • You implement filter, paging, sorting, $expand and error handling yourself.
  • Works on any NetWeaver 7.x Gateway system.

━━━━━━━━━━━━━━━━━━━━
▶ 2. SEGW WITH CDS (REFERENCED DATA SOURCE / MAPPING)

  • Data Model → Reference → Data Source: a CDS view becomes the entity set; read operations are generated.
  • Create/update still coded in DPC_EXT.
  • Good middle way on S/4 on-premise when RAP is not possible.

━━━━━━━━━━━━━━━━━━━━
▶ 3. @OData.PUBLISH (OBSOLETE SHORTCUT)

  • Annotation on a CDS view that generates a service automatically (activate in /IWFND/MAINT_SERVICE).
  • Read-only unless combined with BOPF; replaced by RAP.

━━━━━━━━━━━━━━━━━━━━
▶ 4. RAP

  • Data model: CDS view entities (root + child with composition).
  • Behavior definition (BDEF): create, update, delete, validations, determinations, actions.
  • Behavior implementation: ABAP class (managed: framework persists; unmanaged: you call BAPIs / legacy code).
  • Service definition: expose entities.
  • Service binding: OData V2 or V4, UI or Web API; publish locally.

━━━━━━━━━━━━━━━━━━━━
▶ 5. DECISION GUIDE

  • S/4HANA 2020+ new app or API: RAP.
  • Existing SEGW service needing a change: stay in SEGW unless a rewrite is planned.
  • ECC or old NetWeaver: SEGW.
  • Complex legacy logic (BAPIs): RAP unmanaged or SEGW calling BAPIs.

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

  1. Open your Part 1 SEGW project and list what you had to code.
  2. In ADT, look at a released RAP service (e.g. a service binding in your system) and its service definition.
  3. Compare: what does RAP give for free (paging, filter, $expand)?
  4. Decide for one planned app which model you would choose and why.

✅ CHECKPOINT: you can explain SEGW vs RAP and choose correctly for a given system and requirement.

Code example

ABAP Code
* ===== STEP 1: SEGW - you write the read logic yourself (DPC_EXT) =====METHOD salesorderset_get_entityset.  DATA: lt_so TYPE zcl_zsales_mpc=>tt_salesorder.  SELECT vbeln AS salesorder erdat AS createdon kunnr AS customer    FROM vbak    INTO CORRESPONDING FIELDS OF TABLE lt_so    UP TO 100 ROWS.* Filter, paging, sorting, $count: also your job (Part 7)  et_entityset = lt_so.ENDMETHOD. // ===== STEP 2: RAP - data model (CDS view entity, root) =====@AccessControl.authorizationCheck: #NOT_REQUIRED@EndUserText.label: 'Sales order (RAP root)'define root view entity ZR_SalesOrderRap  as select from zso_head{  key so_id      as SalesOrder,      customer   as Customer,      created_on as CreatedOn} // ===== STEP 3: RAP - service definition =====@EndUserText.label: 'Sales order service'define service ZUI_SALESORDER {  expose ZR_SalesOrderRap as SalesOrder;} // ===== STEP 4: RAP - service binding (created in ADT, no code) =====// Binding type: OData V4 - UI  ->  Publish// Filter, paging, sorting, $count and $expand work without extra ABAP.// Create/update/delete come from the behavior definition (RAP topic).

Real project scenario

On an S/4HANA 2021 project, a team started a new approval app in SEGW out of habit. After three weeks they had written filter, paging, draft-like locking and error mapping by hand, and Fiori elements features like the filter bar needed more custom code.
The architect stopped and rebuilt the app in RAP: CDS view entities, a managed behavior definition and an OData V4 UI service binding. The rebuilt service had fewer than a third of the lines of code, and filter, paging and $expand worked out of the box. Existing SEGW services were left untouched.

Common mistakes

  • Starting new S/4 services in SEGW without considering RAP.
  • Using @OData.publish for new services.
  • Rewriting stable SEGW services to RAP without a business reason.
  • Assuming RAP is only for greenfield tables — unmanaged RAP can wrap BAPIs.
  • Mixing SEGW and RAP logic for the same business object.

Best practices

  • New S/4 apps and APIs: RAP.
  • Keep SEGW for existing services and older releases.
  • Use SEGW referenced data sources when you need CDS-based reads in SEGW.
  • Document the chosen model per service.
  • Reuse CDS view entities as the data model for both.

Interview angle

Questions: "SEGW or RAP — which do you choose?", "What is @OData.publish?", "What does RAP generate for you?"
Strong answer: SEGW is code-based with MPC/DPC_EXT where you implement CRUD, filter, paging, $expand yourself; RAP uses CDS, behavior definition, service definition and binding (V2/V4) with framework-handled CRUD and query options, and is SAP's strategic model and mandatory in ABAP Cloud. @OData.publish is an obsolete CDS shortcut. Choose RAP for new S/4 work, SEGW for existing services or old releases.

Practice this lesson

Quick check

1. Which OData versions can a RAP service binding publish?

2. On a current S/4HANA system, how should a new read service for a CDS view be exposed?

3. Compared with a code-based SEGW service, what does a RAP-based OData service provide without extra ABAP code?

Interview questions

1. When would you choose RAP/CDS OData over classic SEGW?

Answer it in your own words first, then compare.

2. A stable SEGW OData V2 API is used by three external partners. A new architect wants to rewrite it in RAP "because SEGW is old". How do you evaluate this?

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