PackagePackagetypeA library you install and call yourself.See every one →What this type is →independently maintainedindependently maintainedoriginPublished by one person or a small company outside SAP. Says nothing about quality; the readings say that.See every one →

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

Last pushLicenceMIT

Where it sits

Lives in
Provides
Input validationABAPInput validationcapabilityRejecting 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.

Who is behind it

He HHe HPersonMaintains this
In the atlas: maintains 3, contributes to 6
@hhelibeb
maintainerFrederik HudákPersonContributes to this
In the atlas: contributes to 4
@FreHu
Lars HvamPersonContributes to this
In the atlas: maintains 13, contributes to 92, wrote 1
@larshp
2 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

Connections2

README

quoted from hhelibeb/abap-data-validator under MIT, read
hhelibeb/abap-data-validator/README.mdOn GitHub

abap-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. check classere

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 to zcl_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.
MIT, read

History

Latest

v0.9

Notes

on-premise version and cloud version (thanks to ArneVanH)

Input validation
  1. abapDomCheckChecks field values against domain fixed values and check tablesfrom ABAP
  2. com.sap.cds:cds-services-bomMaven bill of materials pinning CAP Java module versionsfrom CAP
  3. cap-toolkitUtility bundle for CAP handlers: builder, roles, validation, queriesfrom CAP
  4. sap-cap-validator-pluginCAP plugin validating input against @Validator JSON Schema rulesfrom CAP
  5. capvalCustom messages and handler classes for CAP input validationfrom CAP
  6. cds-validateZod schemas as CAP validation middlewarefrom CAP
  7. @sap/cdsCAP Node.js runtimefrom CAP

Details

Sources3
dotabapdiscovered herechecked
github.com/hhelibeb/abap-data-validatortree, pushes, contributors, CIchecked
README.mdquoted, and what the entry declareschecked

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
discovered viadotabap
first seen in the atlas
ecosystem and domainabap, security-and-compliance
abaplint
issues under its own abaplint configuration11
lines3,217
statements1,654
objects17
files47
analysed, master
abaplint version2.120.84
Contributors2

From the repository’s contributor list, .

History in the atlas1
  1. First seen.
For your agent
Ref
artifact:hhelibeb-abap-data-validator
JSON
/artifacts/hhelibeb-abap-data-validator.json
MCP
Connecting an agent