The issue is that CDS view extensions alone don’t automatically extend OData service definitions in SAP S/4HANA 2020. You need to work through all three layers:
1. CDS View Extension (you’ve done this correctly):
Your CDS extension looks good, but ensure you’re using the correct annotation syntax for 2020. The @OData.property annotations are legacy - use @EndUserText instead:
@AbapCatalog.sqlViewAppendName: 'ZDEMANDEXT'
extend view I_DemandForecast with Z_DEMAND_FORECAST_EXT {
@EndUserText.label: 'Custom Region'
zregion_code as CustomRegion,
@EndUserText.label: 'Custom Priority'
zpriority_level as CustomPriority
}
2. OData Annotation Usage:
Create a metadata extension (DDLX object) specifically for OData exposure. This is the missing piece. Create Z_DEMAND_FORECAST_EXT_MDE:
@Metadata.layer: #CUSTOMER
annotate view Z_DEMAND_FORECAST_EXT with
{
@UI.lineItem: [{position: 100}]
@Consumption.valueHelpDefinition: [{entity: {name: 'I_Region', element: 'Region'}}]
CustomRegion;
@UI.lineItem: [{position: 110}]
CustomPriority;
}
3. Service Binding Activation:
This is critical. You must extend the service definition AND republish the binding:
Step 3a - Create Service Definition Extension in Eclipse ADT:
- Right-click on API_DEMAND_PLANNING service definition
- Select “New” → “Service Definition Extension”
- Name it Z_API_DEMAND_PLANNING_EXT
- Add your custom fields explicitly:
extend service definition API_DEMAND_PLANNING {
expose Z_DEMAND_FORECAST_EXT as DemandForecast {
CustomRegion,
CustomPriority
}
}
Step 3b - Republish Service Binding:
- Transaction /IWFND/MAINT_SERVICE
- Find service API_DEMAND_PLANNING
- Click “SAP Gateway Client” to test current metadata
- Note the metadata version
- Click “Deactivate” then “Activate and Maintain”
- This regenerates the OData $metadata document
- Clear ICF service cache: transaction SMICM → Goto → HTTP Server Cache → Invalidate Globally
Step 3c - Verify Registration:
- Transaction /IWBEP/REG_SERVICE
- Search for API_DEMAND_PLANNING
- Check “System Alias” and “Service Version”
- Click “Load Metadata” and verify your custom fields appear in the entity type definition
- If fields are missing, use “Reload” button to force metadata refresh from service definition
Additional Configuration:
- Authorization: Ensure role S_SERVICE includes your extended view Z_DEMAND_FORECAST_EXT with activity 03 (display)
- Access Control: If your CDS view has DCL (Data Control Language), create corresponding DCL extension:
@MappingRole: true
define role Z_DEMAND_FORECAST_EXT_DCL {
grant select on Z_DEMAND_FORECAST_EXT
where inheriting conditions from entity I_DemandForecast;
}
Testing:
Query the OData metadata to verify field exposure:
GET /sap/opu/odata/sap/API_DEMAND_PLANNING/$metadata
Look for <Property Name="CustomRegion" and <Property Name="CustomPriority" in the EntityType definition.
Then test data retrieval:
GET /sap/opu/odata/sap/API_DEMAND_PLANNING/DemandForecast?$select=ForecastID,CustomRegion,CustomPriority
The most common mistake is skipping the service definition extension (step 3a). CDS extensions and metadata annotations alone are insufficient - you must explicitly extend the service definition to expose custom fields via OData. All three layers must align for custom fields to be externally accessible.
This draft is based on general SAP S/4HANA knowledge. It has not been verified against your specific version and environment. Practitioners: verify the steps and share your experience below.