All Projects → hhelibeb → abap-data-validator

hhelibeb / abap-data-validator

Licence: MIT license
A data validation tool.

Programming Languages

ABAP
45 projects

Projects that are alternatives of or similar to abap-data-validator

SAP-ABAP-Development
SAP ABAP development, customization and enhancement guides
Stars: ✭ 51 (+82.14%)
Mutual labels:  sap, abap
ABAP-Library
Useful ABAP code snippets
Stars: ✭ 118 (+321.43%)
Mutual labels:  sap, abap
abaK
ABAP constants done right
Stars: ✭ 26 (-7.14%)
Mutual labels:  sap, abap
Simple-Data-Explorer
Simple Data Explorer
Stars: ✭ 37 (+32.14%)
Mutual labels:  sap, abap
fundamental-tools
Web applications with ABAP, done simple.
Stars: ✭ 42 (+50%)
Mutual labels:  sap, abap
abap2xlsx
Generate your professional Excel spreadsheet from ABAP
Stars: ✭ 493 (+1660.71%)
Mutual labels:  sap, abap
abap mustache
Mustache template engine for ABAP
Stars: ✭ 14 (-50%)
Mutual labels:  sap, abap
nwabap-ui5uploader
This module allows a developer to upload SAPUI5/OpenUI5 sources into a SAP NetWeaver ABAP system.
Stars: ✭ 15 (-46.43%)
Mutual labels:  sap, abap
bw toolbox
📊 🔨 📦 Collection of all tools for SAP BW useful for daily work
Stars: ✭ 24 (-14.29%)
Mutual labels:  sap, abap
xtt
ABAP template engine for Excel, Word, Html & Pdf
Stars: ✭ 21 (-25%)
Mutual labels:  sap, abap
eui
Easy UI in SAP
Stars: ✭ 34 (+21.43%)
Mutual labels:  sap, abap
ABAPFavorites
ABAP Favorites Eclipse Plugin
Stars: ✭ 23 (-17.86%)
Mutual labels:  sap, abap
JSON2ABAPType
Creator of ABAP types on a base of JSON structure
Stars: ✭ 40 (+42.86%)
Mutual labels:  sap, abap
ABAP-Swagger
Expose ABAP REST services with Swagger/openapi spec
Stars: ✭ 80 (+185.71%)
Mutual labels:  abap
Teched17
Code for the demo I gave at SAP TechEd 2017
Stars: ✭ 45 (+60.71%)
Mutual labels:  abap
openui5-tour
OpenUI5 Tour enables an user-friendly way to showcase products and features in your website.
Stars: ✭ 21 (-25%)
Mutual labels:  sap
abapOpenReview
ABAP Review Tool
Stars: ✭ 19 (-32.14%)
Mutual labels:  abap
sapui5-cli
Simple CLI to scaffold SAPUI5 / OpenUI5 projects.
Stars: ✭ 17 (-39.29%)
Mutual labels:  sap
cloud-sdk
The SAP Cloud SDK documentation and support repository.
Stars: ✭ 29 (+3.57%)
Mutual labels:  sap
Typeorm
ORM for TypeScript and JavaScript (ES7, ES6, ES5). Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.
Stars: ✭ 26,559 (+94753.57%)
Mutual labels:  sap

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( '[email protected]' ).
 "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 = '[email protected]') "correct, it is a gmail address
    ( field3 = '[email protected]') "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

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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].