Input validation

Rejecting bad input before it reaches the database. While this can be done manually inside a handler, there are solutions in place to derive type, range, enum and mandatory checks from the model definitions.

Overview

InCAPassessed
SAP SHIPS
Node.js →

@sap/cds Enforces @mandatory, @assert.range, @assert.format, @assert.target and @assert with a CXL case expression whenever data is written: the static checks on the input, the expressions collected into one query and run in the database, and a failure rejects the request and rolls the transaction back.

Java →

com.sap.cds:cds-services-bom Enforces declarative @assert and @mandatory constraints whenever data is written, and translates the resulting validation error messages out of the box.

Not covered: It stops at what a range, a regular expression or a CXL expression run in the database can say about an entity's elements: @assert.format takes a pattern and has no named format such as email or uri, and @assert.target does not check across services or against a target created in the same deep insert. Past that the check is a before handler of the developer's own, or a second vocabulary: JSON Schema keywords per element, evaluated by Ajv, in sap-cap-validator-plugin, and Zod schemas registered in a before handler in cds-validate. capire's own advice at that edge is to try the declarative constraints first and to write the before handler only past them; in CAP Java the Before phase is the one meant for validating the incoming parameters.

SourceDeclarative Constraints — capirechecked
InABAPassessed

In ABAP the rules sit in ABAP Dictionary, on domains, data elements and check tables, and the screen applies them. Code that takes data in without a screen calls a check of its own, by type in abap-data-validator or against fixed values in abapDomCheck.

SAP SHIPS

On a classic dynpro, fields that refer to ABAP Dictionary are checked before PAI runs: a value must exist in its check table and be one of its domain's fixed values. In RAP, a validation declared in the behavior definition runs in the save sequence and can reject an instance, with its check written in the behavior pool.

Not covered: At the screen. Data that reaches the system through an upload, an RFC call or a program passes no dictionary check, and a RAP validation checks only what its author implemented.

InUI5assessed

In a UI5 app input is checked in the browser, against the type of the property it is bound to, before it reaches the model; the service behind it still checks what it receives.

SAP SHIPS

Data types check user input on its way into the model: a type's constraints, the maximum of an Integer say, are validated when the input is parsed, the OData types carry the property facets as constraints, and a custom type implements validateValue. With handleValidation set in the manifest or on the component, a failed check becomes a validation message on the control's property.

Not covered: At the input of one bound property: the documentation places the check in parsing what was entered and creates the message when the data changes, and it describes no check of a whole form at once.

THE COMMUNITY ADDS

No community artifact is documented here.

Artifacts8

Group by8 of 8 artifacts
ArtifactSignals
CDS plugins2
capvalCustom messages and handler classes for CAP input validation
Signals
none
sap-cap-validator-pluginCAP plugin validating input against @Validator JSON Schema rules
Signals
Quiet+1
Packages6
@sap/cdsCAP Node.js runtime
Signals
none
abap-data-validatorValidation library for ABAP checking dates, emails and GUIDs
Signals
Quiet
abapDomCheckChecks field values against domain fixed values and check tables
Signals
Quiet
cap-toolkitUtility bundle for CAP handlers: builder, roles, validation, queries
Signals
Functional boundary
cds-validateZod schemas as CAP validation middleware
Signals
none
com.sap.cds:cds-services-bomMaven bill of materials pinning CAP Java module versions
Signals
none

Content10

Group by10 of 10 pieces
Piece, what it offers
Declarative Programming in CAP: Less Code, More Value
SAP Community, BirgitS, BlogThe reasoning
Building Secure SAPUI5 Applications: Best Practices for Developers
SAP Community, Manisha_19, Blog
Open Source UI5 Form Validator
SAP Community, actor:learnin, Blog
Show 7 more
CAPVAL: A project is born
SAP Community, MattBrightman, Blog
Extend SAP Cloud Application Programming Model(CAP) Validations with the CAPVAL Plugin
SAP Community, MattBrightman, BlogThe reasoningRunnable code
#CAP-TechBytes Input Validation
SAP Community, Thajunniza, BlogThe reasoning
#BTP #SAPCAP: Quirky Nuggets (N01-N02)
SAP Community, Ajit Kumar Panda, Blog
[Part - 1] Enrich CAP based Services with Behaviors using Annotations
SAP Community, Ajit Kumar Panda, Blog
Learn how to define constraints declaratively in your CDS model
SAP Developer Center, SAP, TutorialThe reasoningA recipe
Everything new: Try out the latest features in CAP
SAP TechEd — session catalogue, Daniel Hutzel, Daniel Schlachter, TalkA recipe
CAPVAL: A project is born
SAP Community, MattBrightman, Blog
Extend SAP Cloud Application Programming Model(CAP) Validations with the CAPVAL Plugin
SAP Community, MattBrightman, BlogThe reasoningRunnable code
Declarative Programming in CAP: Less Code, More Value
SAP Community, BirgitS, BlogThe reasoning
Everything new: Try out the latest features in CAP
SAP TechEd — session catalogue, Daniel Hutzel, Daniel Schlachter, TalkA recipe

Seen working1

ArtifactSignals
Samples1
assert-targetWhich CAP paths trigger @assert.target and which do not
No license

Details

What changed — and what it makes stale1
@sap/cds 8.5.0, CAP, Node.js

@assert.range accepts open intervals, a min or max wrapped in parentheses, and an underscore for infinity. Before this release a range was a closed [min, max] and a one-sided bound needed a case expression or a handler. CAP Java gained the same in 3.5.0.

Makes stale:

Advice that @assert.range cannot express 'strictly positive' or an unbounded side, and the before handlers written for that.

Coverage
statecore and community, CAP
assessed
state in ABAPcore and community, assessed
state in UI5core only, assessed
relationshipunassessed
also inABAP, UI5
For your agent
Ref
capability:input-validation
JSON
/capabilities/input-validation.json
MCP
Connecting an agent