Flat File Parser Echo Example

From MidrangeWiki
Revision as of 09:40, 29 December 2010 by Mihael (talk | contribs) (input providers have its own project now)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Purpose

This example shows how to use the FFP (Flat File Parser) service programs in the most simplistic way.

The data is read from a stream file on the IFS and then shown on the screen with the matching line format.

Data Format

 00012010-12-201234567890123450
 00012010-12-201234567890987900
Position Description
1 - 4 store id
5 - 14 transaction date (format *ISO)
15 - 37 item number (EAN)
38 - 40 quantity

Code

     /**
      * \brief FFP Example : Echo input to screen
      *
      * \author Mihael Schmidt
      * \date   19.12.2010
      */

     H dftactgrp(*no) actgrp(*caller)
     
      *---------------------------------------------------------------
      * PEP
      *---------------------------------------------------------------
     D main            PR                  extpgm('FFPEX01')
     D main            PI


      *---------------------------------------------------------------
      * Prototypes
      *---------------------------------------------------------------
      // 
      // as we do the configuration manually we need
      // to include the prototypes of the ffp modules
      //
      /include 'ffp/parser_h.rpgle'
      /include 'ffp/line_processor_h.rpgle'
      /include 'ffp/echo_line_processor_h.rpgle'
      // input providers have its own project
      /include 'rng/input_provider_h.rpgle'
      /include 'rng/streamfile_input_provider_h.rpgle'

      
      *---------------------------------------------------------------
      * Variables
      *---------------------------------------------------------------
     D parser          S               *
     D lineProcessor   S               *
     D inputProvider   S               *
      
     D lineFormatImage...
     D                 S            100A
     D inputPath       S           1000A

      /free
       lineFormatImage = '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@' + x'00';
       inputPath = '/home/iusr0001/src/ffp/example/echo-input.txt' + x'00';
       
       // create parser instance
       parser = ffp_create();

       // create line processor instance
       lineProcessor = ffp_processor_echo_create();

       // create input provider instance
       inputProvider = rng_input_stmf_create(%addr(inputPath)); 
       
       //
       // configure parser
       //
       ffp_addLineFormatFromImage(parser : 'Variable line Format' :
                                  %addr(lineFormatImage));
       ffp_addLineProcessor(parser : lineProcessor);
       ffp_setInputProvider(parser : inputProvider);
       
       // do the actual parsing
       ffp_parse(parser);
       
       // clean up
       ffp_finalize(parser);
       
       *inlr = *on;
       return;
      /end-free