How to read files written with COBOL
Steve Williams
stevewilliams at wwc.com
Tue May 11 00:54:08 EDT 2004
Batista, Facundo wrote:
> People:
>
> I'm trying to convert my father from using COBOL to Python, :)
>
> One difficult thing we stuck into is how to read, from python, files written
> with COBOL.
>
> Do you know a module that allows me to do that?
>
> It should avoid us the work to write a COBOL program that open the COBOL
> file and write a CSV one (easily readable from python).
>
> Thank you all!
>
> Facundo Batista
> Desarrollo de Red
> fbatista at unifon.com.ar
> (54 11) 5130-4643
> Cel: 15 5132 0132
>
>
>
I wrote an ETL system in python for a client to convert from Microfocus
COBOL to DB2. Here are some of the problems I saw:
1) COBOL has a very rich set of datatypes defined by the PICTURE clause
character
unsigned integer
zoned signed integer
integer trailing sign separate
integer leading sign separate
packed signed decimal
packed unsigned decimal
floating point
with the usual COBOL zoo of implied decimal points and scaling
Not to mention COBOL allowing formatted numeric data to be
used as source fields in arithmetic operations.
In my application, each of these types was converted by a
parameter-driven function.
That is, I took the original COBOL 01 level definition and
converted it to a list with definition parameters name, type,
length, decimal point, etc. to make it easy for Python and
to add some stuff to make DB2 happy (convert to title case. . .)
I doubt if you can easily write a parser for the COBOL PICTURE
clause and for most cases it would be a waste of time. I just
converted the definition by using 'replacing all occurences' in
a text processor.
I had the most problem with Microfocus unsigned decimal, as
I'd never seen it before.
2) Reading fixed and variable length records wasn't much of a problem
Reading Microfocus keyed sequential data with embedded indexes
took some bit-level coding.
3) None of this would be remotely attractive to a COBOL programmer.
Converting the data to CSV, however, might get his attention
as it's pretty easy in Python and not much fun in COBOL.
I you want to sell dad, talk about text and string processing
in Python.
More information about the Python-list
mailing list