Description
Using a default clause on a structured element in CDL has been a compiler warning since CDS 6.0. In CDS compiler v7 (CDS 10), it is promoted to a hard error. Elements whose type is a structured type — a user-defined type with sub-elements, an aspect, or an embedded entity — cannot have a default value clause. The fix is to remove the default clause and initialize structured elements through application logic or service handler code instead. Scalar default clauses (e.g. String default 'active', Integer default 0) remain fully valid and are not affected.
How to Check
- [ ] Run
cds compile— the compiler emits a hard error for each structured element with adefaultclause. - [ ] Search all
.cdsfiles for the\bdefault\bpattern to locate all default clauses, then verify whether the element type is structured.
Migration Steps
Locate structured elements with
defaultclauses:cds// Breaking: default on a structured element type type Address { street : String; city : String; } entity Orders { key ID : UUID; deliveryAddr : Address default { street: 'Unknown', city: 'Unknown' }; }Remove the
defaultclause from the CDL definition:diffentity Orders { key ID : UUID; - deliveryAddr : Address default { street: 'Unknown', city: 'Unknown' }; + deliveryAddr : Address; }Initialize the structured element in a
before CREATEhandler or through the application's data preparation logic:jsthis.before('CREATE', Orders, req => { if (!req.data.deliveryAddr) { req.data.deliveryAddr = { street: 'Unknown', city: 'Unknown' }; } });
Examples
default on a structured element — breaking:
// Breaking: Address is a custom structured type
entity Orders {
key ID : Integer;
shipping : Address default { street: '', city: '' }; // error in v7
}default on a scalar element — valid, not affected:
// Not breaking: String is a scalar type
entity Books {
key ID : Integer;
status : String default 'available'; // fine, no change needed
}Notes
The restriction applies to any element whose resolved type has sub-elements, including inline structured types, named types defined with type ... { }, and aspects. Scalar built-in types (String, Integer, Decimal, Boolean, Date, etc.) and their constrained variants remain fully valid targets for default clauses.