abap-data-validator
A validation library for ABAP that checks values such as dates, emails, URLs, JSON and GUIDs against type rules through one interface, or a whole internal table against a set of rules.
Validating incoming data field by field in ABAP usually means hand-written checks scattered across a program. This provides check classes for types including date, time, timestamp, email, INT4, regular expression, URL, JSON, hex, IMEI, GUID and base64 (HTML is marked experimental), each reachable through a shared zif_adv_check interface and a static is_valid method. validate_by_element extends the same checks to quantity and amount data elements, and validate runs a full set of rules against an internal table in one call, with a new type added by implementing the interface and registering a class.
Facts
Where it sits
Who is behind it
In the atlas: maintains 3, contributes to 6@hhelibebmaintainerFrederik HudákContributes to this
In the atlas: contributes to 4@FreHuLars HvamContributes to this
In the atlas: maintains 13, contributes to 92, wrote 1@larshp2 contributors
Before choosing this
Signals
ActivityQuietNo published releases; repository quiet for 40 months
It publishes no releases, and its repository has been quiet for at least 24 full months. This may be normal for stable software; check whether its current state still fits your use.
What it declares
Every artifact
- Type
- Package
- Origin
- Independently maintained
As a package
- Where it runs
- does not say
- Distributed through
- does not say
Connections
Rejecting bad input before it reaches a handler
Eleven abap2UI5 apps, one per open-source ABAP library
Download
README
quoted from hhelibeb/abap-data-validator under MIT, readabap-data-validator
A data validation tool.
ABAP Data Validator is a tool to simplify data validation process for SAP ABAP development.
Goals:
- General validation interface, which allows complete validation work by one method call.
- Centralize some validation logic, avoid duplicate & inconsistent, decrease maintenance cost.
- Avoid potential dump.
To achieve the goal, ABAP Data Validator has some features
- Built-in validation logic.
- Customizable validation rules.
- Extendable validation program.
- Internal exception handling.
Type list
ABAP Data Validator supports validations for types below (updating),
- Date.
- Time.
- Timestamp.
- Email.
- INT4.
- REGEX string.
- URL.
- JSON.
- HEX.
- IMEI.
- GUID.
- BASE64.
- HTML (experimental). And validation of mandatory, validate by reference data elements are also supported.
Usage
Single field validation
For every type, ABAP Data Validator has a special check class. You can use static method is_valid of check class to validate data just like a built-in function. Example:
IF zcl_adv_email_check=>is_valid( 'example@github.com' ).
"do something
ENDIF.
Every check class implements the interface zif_adv_check, which contains methodis_valid.

The naming convention of check classes is ZCL_ADV_typename_CHECK.
All classes have unit tests.
Validation with reference data element
For easy to use, is_valid is a quite simple method, that means it can't provide function on validation of quantity and amount type. In order to solve this issue, ABAP Data Validator provide another way to validate data.
DATA(result) = NEW zcl_adata_validator( )->->validate_by_element(
data = '11.0'
element = 'MENGE_D' "quantity data element name
).
Now data elements with below type are supported,
- Date.
- Time.
- Timestamp.
- INT4.
- GUID.
- HEX.
- Packed(including most of the quantity type and amount type).
To keep the check method simple, there is also no exception definition of the method validate_by_element. The method handles exceptions internally, and return a result with the result-valid = abap_false, result-type = 'Invalid Type' (fixed value).
Internal table validation
Class zcl_adata_validator provides a general validation method validate.
TRY.
DATA(result) = NEW zcl_adata_validator( )->validate(
rules = my_rules
data = uploaded_data
).
CATCH zcx_adv_exception INTO DATA(ex).
DATA(msg) = ex->get_text( ).
ENDTRY.
zcl_adata_validator calls check methods internally according to the exporting rules and returns the result.
Rules customization
By the parameter RULES, you can customize the validation.
DATA: rules TYPE zcl_adata_validator=>ty_rules_t.
rules = VALUE #(
( fname = 'FIELD1' required = abap_true initial_or_empty = abap_false user_type = zcl_adata_validator=>c_type_date )
( fname = 'FIELD2' required = abap_false initial_or_empty = abap_true user_type = zcl_adata_validator=>c_type_date )
( fname = 'FIELD3' required = abap_true initial_or_empty = abap_false user_type = zcl_adata_validator=>c_type_email )
).
Extend validation for special type
There are two ways to extend the validation:
- Pass regular expression by RULES-REGEX.
- Create a new class which implements
zif_adv_check, and pass the type name & class name tozcl_adata_validator->constructor.
Regex example. If you want to check whether the input email is a gmail address, you can assign gmail\.com$ to rule-regex:
DATA: rules TYPE zcl_adata_validator=>ty_rules_t.
DATA: cases TYPE ty_case_t.
cases = VALUE #(
( field3 = 'ZZZ2@gmail.com') "correct, it is a gmail address
( field3 = 'ZZZ2@outlook.com') "incorrect, it is not a gmail address
).
rules = VALUE #(
( fname = 'FIELD3' user_type = zcl_adata_validator=>c_type_email regex = 'gmail\.com$' regex_msg = 'Only gmail supported')
).
Or add a new class, and add it to check config on demand:
DATA: check_class_config TYPE zcl_adata_validator=>ty_check_config_t.
check_class_config = VALUE #( ( type = zcl_adata_validator=>c_type_new class = 'ZCL_NEW_VALIDATOR' ) ).
TRY.
DATA(result) = NEW zcl_adata_validator( check_class_conifg = check_class_config )->validate(
rules = rules
data = cases
).
CATCH zcx_adv_exception INTO DATA(ex).
DATA(msg) = ex->get_text( ).
ENDTRY.
Configuration
The configuration is hard coded in zcl_adata_validator's constructor. You can also pass you own configuration into the constructor. It allows you to change the function without modifying the existed program.
DATA: check_class_config TYPE zcl_adata_validator=>ty_check_config_t.
SELECT * FROM my_config_table INTO TABLE @check_class_config.
TRY.
DATA(result) = NEW zcl_adata_validator( check_class_conifg = check_class_config )->validate(
rules = rules
data = cases
).
CATCH zcx_adv_exception INTO DATA(ex).
DATA(msg) = ex->get_text( ).
ENDTRY.
Note: Custom config will cover default config.
Requirment
ABAP Version: 740 SP08 or higher
For ABAP Cloud, there is another release which was contributed by ArneVanH. Please find it on the Releases page. Refer to issue https://github.com/hhelibeb/abap-data-validator/issues/21 for more details
Exception
The exception class zcx_adv_exception is copied from zcx_abapgit_exception for it is easy to use:)
TODO
Now only date, time and email type are supported. Need to add more check classes.
- More types.
- Auto Type detecting.
History
Notes
on-premise version and cloud version (thanks to ArneVanH)
Others providing
Compare all 8 on the Input validation page →- abapDomCheckabapDomCheckChecks a structure's field values against ABAP domain fixed values and check tables outside the GUI, such as during a data import, answering with a rejected flag and the messages behind it.independent, abapChecks field values against domain fixed values and check tablesfrom ABAP
- com.sap.cds:cds-services-bomcom.sap.cds:cds-services-bomThe Maven bill of materials for CAP Java, pinning every com.sap.cds module in a release, from the API and core runtime to the Spring Boot starters and the CQN engine, to the same version.sap official, capMaven bill of materials pinning CAP Java module versionsfrom CAP
- cap-toolkitcap-toolkitA utility bundle for CAP handlers, with a chainable HandlerBuilder, role checks, validation rules and query helpers, collecting boilerplate that otherwise repeats across projects into one dependency.independent, capUtility bundle for CAP handlers: builder, roles, validation, queriesfrom CAP
- sap-cap-validator-pluginsap-cap-validator-pluginA CAP plugin that checks incoming data against JSON Schema rules written as @Validator annotations on model elements, evaluated by Ajv, with no handler to register.independent, capCAP plugin validating input against @Validator JSON Schema rulesfrom CAP
- capvalcapvalReplaces the message a failed input validation annotation returns, and adds @validation.handler, which names a class that runs a check of the developer's own.independent, capCustom messages and handler classes for CAP input validationfrom CAP
- cds-validatecds-validateA package that runs Zod schemas as CAP validation middleware, so one schema replaces the hand-written checks at the top of a handler and failures come back as OData 422 errors per field.independent, capZod schemas as CAP validation middlewarefrom CAP
- @sap/cds@sap/cdsThe CAP Node.js runtime, which compiles the CDS model, serves the services declared in it, answers generic requests before any handler runs, and loads every cds-plugin.sap official, capCAP Node.js runtimefrom CAP
Details
Sources
Sources are graph entities: the same page may back several entries, and an unreachable source flags every row that rests on it.
Compatibility and provenance
abaplint
Contributors
History in the atlas
- First seen.
For your agent
- Ref
artifact:hhelibeb-abap-data-validator- JSON
- /artifacts/hhelibeb-abap-data-validator.json
- MCP
- Connecting an agent