Flat File Parser Configuration Example
From MidrangeWiki
Purpose
This example shows how to move the parser configuration out of the program into a xml file for easier configuration. It is the same scenario as the validation example.
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/xmlconfig.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#############" /> <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>