技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
odata-abap【数据与研究】OData service development in ABAP — CDS-exposed OData, SADL service definitions, RAP service bindings, SEGW legacy, OData V2/V4, query options, deep insert, ETag, batch, service registration. Use when creating OData services, exposing CDS views, or troubleshooting SAP Gateway errors.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Three approaches: CDS-exposed (simplest), Service Definition + Binding (RAP, recommended), SEGW (legacy).
/IWFND/MAINT_SERVICE@OData.publish: true
@EndUserText.label: 'Product API'
define view entity Z_C_PRODUCT_API
as select from zproduct
{
key product_guid as ProductGuid,
material as Material,
material_type as MaterialType,
description as Description,
created_at as CreatedAt,
@Consumption.filter: { mandatory: false }
plant as Plant
}
Z_C_PRODUCT_API_CDS/IWFND/MAINT_SERVICE → Add Service/IWFND/GW_CLIENT)Service Definition (SRVD):
@EndUserText.label: 'Product Service'
define service Z_PRODUCT_SRV {
expose Z_C_PRODUCT_API as Product;
expose Z_C_PRODUCT_TEXT_API as ProductText;
}
Service Binding (SRVB) in ADT:
Z_PRODUCT_SRVSEGW → Create Project → Data Model
Entity: Product
Properties: ProductGuid (Edm.Guid, Key), Material (Edm.String)
Generate runtime artifacts → DPC_EXT class
DPC_EXT implementation:
METHOD products_get_entity.
DATA(lv_guid) = io_tech_request_context->get_converted_keys(
)->get_value( 'PRODUCTGUID' ).
SELECT SINGLE * FROM zproduct
WHERE product_guid = @lv_guid
INTO CORRESPONDING FIELDS OF @er_entity.
ENDMETHOD.
Material eq 'MAT001'$expand=ProductText$orderby=CreatedAt desc$top=10&$skip=20$select=Material,Description$count=true (V2) / $count path segment (V4)POST /sap/opu/odata/sap/Z_PRODUCT_SRV/Product
Content-Type: application/json
{
"Material": "MAT001",
"Description": "Test Product",
"to_ProductText": [
{ "Language": "EN", "Description": "English text" },
{ "Language": "DE", "Description": "German text" }
]
}
@Semantics.systemDate.lastChangedAt: true
created_at as LastChangedAt
Client sends If-Match: <etag> header. Server returns 412 Precondition Failed if record changed.
POST /sap/opu/odata/sap/Z_PRODUCT_SRV/$batch
Content-Type: multipart/mixed; boundary=batch_boundary
--batch_boundary
Content-Type: application/http
GET Product('ABC123') HTTP/1.1
--batch_boundary
Content-Type: application/http
POST Product HTTP/1.1
Content-Type: application/json
{"Material":"MAT002","Description":"Batch created"}
--batch_boundary--
/IWFND/MAINT_SERVICELOCALZ_PRODUCT_SRV (or Z_C_PRODUCT_API_CDS)0001$filter on Edm.Guid fails — Cause: GUIDs need special syntax. Solution: use ProductGuid eq guid'xxxx-xxxx-...' (V2) or ProductGuid eq xxxxxxxx-xxxx-... without quotes (V4).
Service not visible after activation — Cause: CDS view activated but Gateway cache stale. Solution: run /IWFND/CACHE_CLEANUP or /IWFND/MED_CLEANUP to clear metadata cache.
$expand returns empty — Cause: navigation property not defined or association cardinality mismatch. Solution: verify association in CDS view and that the target entity is also exposed in the same service.
SEGW generates code but 500 error — Cause: DPC_EXT method not redefined or super-> call missing. Solution: redefine method in Z-class, not base class; call super-> for unhandled entities.
OData V2 vs V4 mismatch — Cause: V4 uses different query syntax ($count path vs $count=true). Solution: check service binding type; V4 doesn't support $inlinecount.
Draft-enabled entity not editable — Cause: draft actions not exposed or @ObjectModel.draftEnabled: true missing. Solution: add @ObjectModel.draftEnabled: true to CDS view and activate.
# 1. Check $metadata loads
curl -u <user>:<pass> \
"https://<host>/sap/opu/odata/sap/Z_PRODUCT_SRV/\$metadata"
# 2. Query entity set
curl -u <user>:<pass> \
"https://<host>/sap/opu/odata/sap/Z_PRODUCT_SRV/Product?\$top=5"
# 3. Verify in SAP Gateway Client (/IWFND/GW_CLIENT)
# GET /sap/opu/odata/sap/Z_PRODUCT_SRV/$metadata → expect 200
# 4. Check service is registered
# /IWFND/MAINT_SERVICE → search Z_PRODUCT_SRV → Status: green
# 5. Test deep insert
curl -X POST -H "Content-Type: application/json" \
-d '{"Material":"TEST","to_ProductText":[]}' \
"https://<host>/sap/opu/odata/sap/Z_PRODUCT_SRV/Product"