Flat File Parser EAN Validation Example
From MidrangeWiki
Purpose
This example shows how to validate an UPC or EAN code (no matter what length) with the FFP EAN validator and the VALIDATOR service program (from rpgnextgen.com). In fact it works with every code which has a check digit generated by the modulus-10 method.
Data Format
The data format is exactly the same as in the validation example.
Line Formats
Identifier | Data | |
---|---|---|
Store ID | 100 | 4 digits numeric |
Date | 110 | date ISO format yyyy-MM-dd |
Item | 210 | 13 alphanumeric (EAN) |
Quantity | 220 | 4 digits numeric |
End | 999 | no extra data |
Code
Only the parser and a configuration provider need to be created. Everything else is done by the configuration provider.
The whole program:
/include 'ffp/parser_h.rpgle' /include 'ffp/xml_config_provider_h.rpgle' D parser S * D configProvider S * D configPath S 1000A /free configPath = '/home/iusr0001/src/ffp/example/validator2-config.xml' + x'00'; parser = ffp_create(); configProvider = ffp_config_xml_create(%addr(configPath)); ffp_setConfigurationProvider(parser : configProvider); ffp_loadConfiguration(parser); ffp_parse(parser); ffp_finalize(parser); *inlr = *on; /end-free
XML Configuration file
<?xml version="1.0" ?> <!DOCTYPE config SYSTEM "ffp.dtd" > <config ignoreBlankLines="yes" processInvalidLines="yes"> <lineFormat name="id" type="var" imageString="100####" /> <lineFormat name="date" type="var" imageString="110@@@@@@@@@@"> <field length="3" /> <field length="10"> <validator serviceprogram="FFPVALDAT" procedure="ffp_validator_date_create" parameter="*ISO" /> </field> </lineFormat> <lineFormat name="store" type="var" imageString="120######" /> <lineFormat name="item" type="var" imageString="210#############"> <field length="3" /> <field length="13"> <validator serviceprogram="FFPVALEAN" procedure="ffp_validator_ean_create" /> </field> </lineFormat> <lineFormat name="quantity" type="var" imageString="220#######" > <field length="3" /> <field length="6"> <validator serviceprogram="FFPVALRNG" procedure="ffp_validator_range_create" parameter="1 99999" /> </field> </lineFormat> <lineFormat name="end" type="const" imageString="999" /> <inputProvider serviceprogram="RNGINSTMF" procedure="rng_input_stmf_create" parameter="/home/iusr0001/src/ffp/example/xmlconfig-input.txt" /> <lineProcessor serviceprogram="FFPPRCG" procedure="ffp_processor_grouping_create" parameter="id end FFPEX02EX" /> <logger serviceprogram="FFPLOGJOBL" procedure="ffp_logger_joblog_create" /> </config>
If the only valid item number is an EAN13 code than the code length can be passed as a parameter to the validator instance creation procedure like this:
<lineFormat name="item" type="var" imageString="210#############"> <field length="3" /> <field length="13"> <validator serviceprogram="FFPVALEAN" procedure="ffp_validator_ean_create" parameter="13" /> </field> </lineFormat>