× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: Formatting an unformatted file
  • From: "James W. Kilgore" <omudi1b@xxxxxxxxxxxxxxx>
  • Date: Tue, 17 Nov 1998 08:40:04 -0800
  • Organization: Progressive Data Systems, Inc.

Jeff,

Several years ago I read an article on "Finite State Machines" which is the 
model
we have used for all projects of this type.
Unfortunately I don't recall which rag it was published in.

But I'll try to cover the highlights:

By looking at your data, you define a finite number of "states" that are 
possible
and you perform code based upon the current state and the transition to a new
state.  You process the data one character at a time.

Looking at what you have provided:
State = 0 = beginning of file to first non blank character; transition code
stores character and changes state to 1
State = 1 = Store all characters until first quotation mark, transition code
stores variable name and changes state to 2
State = 2 = Store all characters until second quotation mark, transition code
stores variable value and changes state to 3
State = 3 = Second quotation mark until next non blank character, transition 
code
tests for '$' and changes state to 4
etc.

Naturally you have to decide at what point to populate the record and perform a
write.  If you can count on ROUTE"nnnn" always defining the start of a new data
group then it would be done on the transition from state 1 to 2 when stored
variable name is ROUTE.  If there is a particular variable that always ends a
group, it would be done when you change from state 2 to 3.

To keep things simple, the comment lines are just tossed out unless you also 
need
to process them.

The PC file would be an input primary, program described.  The record format
would be a single field which corresponds with an array of single character
elements. Your mainline code would be something like:

    C        input,1       ifne    '#'
    C                      z-add 1    arrayindex
    C        arrayindex    dowle arraylength
    C*
    C        state         caseq 0    state0
    C        state         caseq 1    state1
    C        state         caseq 2    state2
    C        state         caseq 3    state3
    C                      end
    C*
    C                      add   1    arrayindex
    C                      enddo
    C                      endif
    C*-------------------------------------------------------------
    C        state0        begsr
    C        input,arrayindex    ifne *blank
    C                      move    input,arrayindex    name,nameindex
    C                      z-add 1    state
    C                      endif
    C                      endsr
    C*---------------------------------------------------------------

The remaining subroutines test for transition and act accordingly.
Maybe the article is posted on a web page somewhere.  FSM's do come in handy
sometimes.

Your data has more states then I mentioned, like the value for TERMS is not
within quotation marks, so you have to look for a quotation mark or a blank
character, but I hope I've been able to convey the concept enough for you to see
the potential for a FSM solution.

HTH
James W. Kilgore
email@james-w-kilgore.com


Jeff Crosby wrote:

> To all,
>
> I am going to be doing an application whereby I must read a file from a
> PC that looks like this:
>
> ROUTE "0541"
>
> INVOICE "1234567890"
> DELIVER_DATE "19981116"
> DELIVER_TIME "121500"
> # comment lines start with #
> TERMS 01
> ADJ_QUANT 1 5 2
> ADJ_PRICE 1 5.1295 12.25
> ADJ_ALLOW 1 295 "FSPI" $ 2.5051 02
>
> INVOICE "987650"
> DELIVER_DATE "19981116"
> DELIVER_TIME "131500"
> TERMS 01
> ADJ_QUANT 1 4 3
> ADJ_PRICE 1 4.12 6.25
> ADJ_ALLOW 1 295 "FSPI" $ 2.51 02
> ADJ_QUANT 1 1 2
> ADJ_PRICE 1 4.00 4.10
>
> ROUTE "0545"
> INVOICE "1267890"
> DELIVER_DATE "19981116"
> DELIVER_TIME "121500"
> # this is a comment line
> TERMS 01
> ADJ_QUANT 1 5 2
> ADJ_PRICE 1 5.1295 12.25
> ADJ_ALLOW 1 295 "FSPI" $ 2.5051 02
>
> INVOICE "987650"
> DELIVER_DATE "19981116"
> DELIVER_TIME "131500"
> TERMS 01
> ADJ_QUANT 1 4 3
> ADJ_PRICE 1 4.12 6.25
> ADJ_ALLOW 1 295 "FSPI" $ 2.51 02
> ADJ_QUANT 1 1 2
> ADJ_PRICE 1 4.00 4.10
>
> etc, etc, etc.
>
> and put it into formatted OS/400 files.  Consecutive input records can
> all relate to what will become a single OS/400 database record.
>
> Blank records and comments are to be ignored.
>
> I have done this on a smaller scale in the past via the Brute Force And
> Ignorance Method(1), but I can't believe there isn't an easier way to do
> it.  This is not the forte of RPG, though the RPGIV syntax makes it a
> lot easier.  Has anyone got or seen a good way that you can point me in
> the direction of?  Thanks.
>
> -Jeff
>
> (1) "Brute Force And Ignorance Method" is a registered trademark of Dave
> Shaw.  Used here totally without his permission or knowledge.  I'll
> probably hear about it too. <g>
> +---
> | This is the Midrange System Mailing List!
> | To submit a new message, send your mail to MIDRANGE-L@midrange.com.
> | To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com.
> | To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com.
> | Questions should be directed to the list owner/operator: david@midrange.com
> +---
+---
| This is the Midrange System Mailing List!
| To submit a new message, send your mail to MIDRANGE-L@midrange.com.
| To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com.
| To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.