John Dunlop writes:
Folks,
I am dealing with an application that reads barcoded information into
flat files onto the HP3000. Unfortunately, sometimes the odd character
or two gets mis-read (we are only talking say 10 in 5,000) and this
"invalid character" can cause the next application to refuse to load
the file. Therefore, I have been experimenting with ways to scan the
file to pinpoint these bad characters. The only valid characters are
numbers 0-9, all upper case characters and spaces. I was going to use
Suprtool's pattern-matching but it seems that it cannot discern upper
case from lower (please correct me if I'm wrong). I could use Cobol
(being probably the fastest way) but my Cobol is not current. So, I
looked at CI programming and tried a construct to read the file
character by character e.g. :
[snip first bit]
setvar n finfo(hpstdin,"eof")
setvar y 0
while setvar(n,n-1)>=0 and
len(setvar(buf,rtrim(input())))>=0
setvar y !y + 1
setvar i 1
while setvar(i,i+1) < !flen
setvar z ord(str("!buf",i,1))
if (z > 47 and z < 58)
okay so read next...
elseif (z > 40 and z < 91)
okay so read next...
elseif z <> 32
echo Line !y : Char !i = ![str("!buf",i,1)]
endif
endwhile
endwhile
etc...
This works fine but is slow and inefficient.
I would be interested to hear from anyone who could suggest a
better/faster/more efficient way of scanning each character of a
datafile.
------------------------Reply Separator------------------------
John,
This may not be exactly what you're looking for. However, the
technique used validates the input BEFORE writing to the file. The
sample below does a cursory check to make sure the barcode number
fits the constant criteria for a valid number (i.e., 14 digits, valid
5 digit prefix, numeric).
Most everything after the second "else" statement is related to
"check digit" processing. There are a number of different types of
barcodes and for each type there can be a number of different check
digit algorithyms to choose from. If you do some form of check digit
processing you can eliminate most of the scanner (or keyboard)
misreads. The sample builds a file of Query commands that is input
to a job that updates an Image database.
Sample:
comment ******************************************************
comment * PATNUMS *
comment * *
comment * This command file accepts patron numbers from the *
comment * teminal, edit checks them and writes them to a file*
comment * named PATRONS. *
comment * *
comment * If the file PATRONS already exist, the terminal *
comment * input patron numbers are appended to it - else, the*
comment * file is created and opened for appending. *
comment ******************************************************
comment *
if finfo('patrons',0) = FALSE
build patrons;dev=disc;rec=-80,50,f,ascii;disc=10000
endif
file patrons,old;dev=disc;rec=-80,50,f,ascii;acc=append;save
setvar check 0
setvar ans "z"
setvar bell (chr(7)+chr(7)+chr(7))
setvar shtbell chr(7)
while "!ans" <> ""
while !check < 1
setvar ans ""
input ans;prompt="Patron # : !shtbell";wait=300
if "!ans" = ""
setvar check 1
else
if (numeric("!ans") = FALSE) or (len("!ans") <> 14) or &
(lft("!ans",5) <> "22769")
echo !bell
echo !shtbell THE PATRON NUMBER MUST BE NUMERIC,
echo !shtbell EXACTLY 14 DIGITS IN LENGTH AND
echo !shtbell BEGIN WITH 22769.
echo !bell
else
setvar count 1
setvar tally 0
while !count < 14
setvar digit1 str("!ans",!count,1)
if odd(!count) = TRUE
setvar digit1 (!digit1 * 2)
if !digit1 > 9
setvar digit2 lft("!digit1",1)
setvar digit1 rht("!digit1",1)
setvar digit1 (!digit1 + !digit2)
endif
endif
setvar tally (!tally + !digit1)
setvar count (!count + 1)
endwhile
setvar digit1 rht("!tally",1)
setvar digit1 (10 - !digit1)
if !digit1 = 10
setvar digit1 0
endif
setvar digit2 rht("!ans",1)
if !digit1 <> !digit2
echo !bell
echo !shtbell INVALID PATRON NUMBER, TRY AGAIN.
echo !bell
else
echo F BORROWER.Card-Number = !ans >>*patrons
echo UPDATE REPL,BORROWER.CATEGORY="NOAD";END >>*patrons
endif
endif
endif
endwhile
endwhile
return
Steven P. Barrett [log in to unmask]
Systems Analyst
Fairfax County Public Library (703) 222-3132 - Voice
Technical Operations Center (703) 222-3135 - FAX
4000 Stringfellow Rd.
Chantilly, VA 20151
--- The opinions expressed here are mine alone . ---
If God had meant for us to have distributed systems, he
would have put little brains in our hands and in our
fingers. (Unknown Author)
|