473,507 Members | 2,416 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to read files written with COBOL

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
fb******@unifon.com.ar
(54 11) 5130-4643
Cel: 15 5132 0132

Jul 18 '05 #1
7 14733

"Batista, Facundo" <FB******@uniFON.com.ar> wrote in message
news:ma**************************************@pyth on.org...
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).
What's the OS for the two languages? COBOL from mainframe
to X86ish is very different from some flavor of Windows or Unix
COBOL.

Also, are we talking fixed or variable length records? And if
variable, how are they structured?

In either case, I think the struct module (under String Services)
is what you're looking for.

John Roth
Thank you all!

Facundo Batista
Desarrollo de Red
fb******@unifon.com.ar
(54 11) 5130-4643
Cel: 15 5132 0132

Jul 18 '05 #2
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
fb******@unifon.com.ar
(54 11) 5130-4643
Cel: 15 5132 0132

i'm going to watch this thread with interest. a couple of weeks ago, i
asked about python to legacy mvs particularly for DB2 and Adabas access.
i got zero responses which suggested to me that no tools or modules
are in wide use.

i think you are undertaking a simpler problem generally. if all your
records are text it should be fairly straightforward. if not, you'll
need to figure out how to map COBOL data representations into python.

i seem to remember COMP-3, COMP-5 and packed decimal formats, among
others. what they mean, i dont't know, but generally various floating
and fixed point formats.

you also need to handle REDEFINES which is used to produce a c-union
sort of arrangement, where multiple formats can be used to access the
same record.

88-Levels are a similar problem.

after Y2K, a lot of COBOL files contain some non-obvious date handling,
which could involve bit manipulation.

if you learn of any sorts of tools at all, please post them back here.
python screen scrapers, python compatible database drivers, anything at all.

interesting project idea: a COBOL to python _code_ converter. should
be feasible, in light of COBOL's very limited syntax.

ah, COBOL fun. all us old guys are reflecting on how glad we are we
left it behind.

it might be a good exercise for your dad, if he wants to retool himself,
and he already knows all the data format stuff.
Jul 18 '05 #3

"asdf sdf" <as**@asdf.com> wrote in message
news:VY*******************@newssvr29.news.prodigy. com...
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
fb******@unifon.com.ar
(54 11) 5130-4643
Cel: 15 5132 0132
i'm going to watch this thread with interest. a couple of weeks ago, i
asked about python to legacy mvs particularly for DB2 and Adabas access.
i got zero responses which suggested to me that no tools or modules
are in wide use.


I missed seeing it, somehow, but you're also right: I don't know
of any tools either.
i think you are undertaking a simpler problem generally. if all your
records are text it should be fairly straightforward. if not, you'll
need to figure out how to map COBOL data representations into python.
In other words, take the 01s under the FD and create an object
that would expose all the converted data elements for the record?
Could be a somewhat interesting project, and it shouldn't be all
that hard since data descriptions are a fairly limited syntax.
you also need to handle REDEFINES which is used to produce a c-union
sort of arrangement, where multiple formats can be used to access the
same record.
Redefines in implicit - it's just multiple level 01s under the same FD.
88-Levels are a similar problem.
Aren't an issue. 88s are basically an isXXX type function call. That's not
how they're implemented, but that's the basic semantics.
after Y2K, a lot of COBOL files contain some non-obvious date handling,
which could involve bit manipulation.

if you learn of any sorts of tools at all, please post them back here.
python screen scrapers, python compatible database drivers, anything at all.
interesting project idea: a COBOL to python _code_ converter. should
be feasible, in light of COBOL's very limited syntax.

ah, COBOL fun. all us old guys are reflecting on how glad we are we
left it behind.


Ain't that the truth!

John Roth
Jul 18 '05 #4
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
fb******@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.

Jul 18 '05 #5
Steve Williams wrote:
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 <...snipping various items...>
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. . .)

Steve,

I've been looking for ideas on getting at DB2 and Adabas from Python.
You might have some thoughts.

Is it feasible to go to directly to MVS/DB2/Adabas from Python on Unix
or Win?

Is it more realistic to hit DB2 on AIX or Linux and use some kind of DB2
linking or replication to reach DB2/MVS?

Other ideas? Maybe 3270 emulation with screen scraping? How about
telnet 3270? (Hundreds years of ago, I could dial into a command line
MVS environment.)

I don't mean to hijack the thread. I think this is related and might be
helpful to unfortunates to have to interoperate with legacy systems.



Jul 18 '05 #6
asdf sdf wrote:
Steve Williams wrote:
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


<...snipping various items...>
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. . .)


Steve,

I've been looking for ideas on getting at DB2 and Adabas from Python.
You might have some thoughts.

Is it feasible to go to directly to MVS/DB2/Adabas from Python on Unix
or Win?

Is it more realistic to hit DB2 on AIX or Linux and use some kind of DB2
linking or replication to reach DB2/MVS?

Other ideas? Maybe 3270 emulation with screen scraping? How about
telnet 3270? (Hundreds years of ago, I could dial into a command line
MVS environment.)

I don't mean to hijack the thread. I think this is related and might be
helpful to unfortunates to have to interoperate with legacy systems.


Well, the application processed a lot of data on a nightly basis. It
used FTP to connect to the COBOL machine (an AIX box) and FTP callbacks
to sequentially read the files and convert the the data. There are two
a bugs in the Python FTP module that surface if the file size is larger
than 2 gig, but they're easily fixed.

I developed this application on Windows, initially targeting a test DB2
database on Windows and then moving the DB2 database to AIX and posting
with ODBC over the network from Windows.

In the full production environment I moved the Python
application to AIX. The moves were straightforward--Python was platform
independent for my purposes.

Initially I used ODBC or the API to post the data to DB2, but
that turned out to be slow. To get the speed I needed, I just wrote
the converted data to a CSV flat file and passed the file to the
DB2 loader utilities. No matter how good your code is, you'll never
outperform the database utilities.

I've never used replication or linking. I know nothing about DB2 on
MVS. In general, my experience with DB2 on networks (admittedly Unix
and Windows boxes) tells me accessing DB2 on MVS over a network would
not be a problem. I know nothing about ADABAS.

Python will certainly do TELNET and screen scraping, but life is short.

Other than the overall success of the project (I've been told successful
data warehouse projects are rare) the major benefit of using Python was
the ability to try new concepts quickly. With python you have
enormous flexibility, as opposed to compiled languages (COBOL, C, etc)
or third party ETL utilities.

As an example, my application converted accounting data on
a nightly basis. With no advance warning, the Accounting department
converted to another package. The python code to extract and load
the data from the new system was written and in production in 2 days.

Jul 18 '05 #7
Steve Williams <st***********@wwc.com> wrote in message news:<nJ*********************@nwrddc01.gnilink.net >...
asdf sdf wrote:
Is it feasible to go to directly to MVS/DB2/Adabas from Python on Unix
or Win?
At least for DB2 this shouldn't be a problem - but would typically
involve a separate product - called "DB2 Connect". Shouldn't be cheap
or require any MVS components:
http://www-306.ibm.com/software/data/db2/db2connect/
Is it more realistic to hit DB2 on AIX or Linux and use some kind of DB2
linking or replication to reach DB2/MVS?

No, DB2 Connect should give you odbc, jdbc, cli, etc protocols
directly to mvs. You can go through another db2 database, but that's
probably extra work & complexity.
Other than the overall success of the project (I've been told successful
data warehouse projects are rare) the major benefit of using Python was
the ability to try new concepts quickly. With python you have
enormous flexibility, as opposed to compiled languages (COBOL, C, etc)
or third party ETL utilities.


Nice case study. I've been building ETL systems for twelve years and
am on my second python etl project right now. Python has proved
itself the best option - there's nothing like adaptability when you've
got a dozen system interfaces to maintain! And its quick learning
curve has meant that bringing others up to speed has been a snap.

Most of my communication with db2 is just over the command line (via
popen2.Popen3) which is the only way to issue commands such as load,
export, force application, list application, etc. However, quite a
few of my summaries are run this way as well (typically mass inserts)
and aside from the primitive error codes, it works fine. There's also
at least one db2 python package (PyDB2). Here's a link to the
package:
http://sourceforge.net/projects/pydb2/
and here's a link to a tutorial for it:
https://www6.software.ibm.com/reg/de...91&S_CMP=DB2DD
I'm not using it yet, though a coworker just installed and started
using a python db2 module - I assume that it is this one.

And as far as reading files written in COBOL, here's a few thoughts:
1. don't make python read all the COBOL data types, instead make the
COBOL program write out a plain ascii record. Writing to a
fixed-length ascii record is very simple (if a little tedious to parse
on the other side).
2. if you can't modify the COBOL output...then you could consider a
commercial (perhaps with a free trial license) product that already
provides COBOL 'copybook' interpretation. There are quite a few of
these, though the least expensive ones I'm aware of are SyncSort, Data
Junction, and perhaps Compuware's FileAid. Don't think any have a
regular license for less than $1500.
3. if you have to read non-character cobol files, then I'd try to
just keep the number of options down to a reasonable number: you may
only need to support a few formats - such as zoned & packed decimal
(comp-3) for instance. Variable length files, float, comp-4, isam,
etc aren't that common. Redefines are often used in conjuction with
record types, and this can be sometimes simplified by just splitting
the file into multiple separate files by record type. And all the
formatting in the picture clause can be easily handled in the program
that reads the files (implied decimal places, signs, etc are all very
simple).

buck
Jul 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

242
13132
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any...
2
4850
by: none | last post by:
Hi, Any one know of some code to read cobol data files.... thanks timb
2
4974
by: Thomasb | last post by:
Hi! In our company we have a huge amount of COBOL sub-routines that are called from other COBOL-programs. Now we are looking for a method to call them from Windows/Web applications. One...
13
10201
by: EricJ | last post by:
hi i need to access cobol data files from .net, the files have no or .vix extention (i think thats a acucobol or something like that) (/me has completely no experience in cobol) i heard that...
2
1434
by: singlal | last post by:
Hi, my question was not getting any attention because it moved to 2nd page; so posting it again. Sorry for any inconvenience but I need to get it resolved fast. Need your help! ...
35
11335
by: RyanS09 | last post by:
Hello- I am trying to write a snippet which will open a text file with an integer on each line. I would like to read the last integer in the file. I am currently using: file = fopen("f.txt",...
7
2125
by: Tracks | last post by:
I have old legacy code from vb5 where data was written to a file with a variant declaration (this was actually a coding error?)... in vb5 the code was: Dim thisdata as integer Dim thatdata...
0
2697
by: tickle | last post by:
Need to convert this PL/SQL script to Dynamic SQL Method 2 * copybook - celg02u3.sql SIR 24265 * * updates dt_deny for all rows in * * ...
4
1772
by: Michiel Overtoom | last post by:
Giveitawhril wrote... No: Real programmers first eat a quiche and then return to their Pascal programming. C is alive and kicking. Every language has its place. Plus, there exists...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7111
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7031
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5042
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1542
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.