umesh
umesh

Reputation: 1

We have many mainframe files which are in EBCDIC format, is there a way in Python to parse or convert the mainframe file into csv file or text file?

I need to read the records from mainframe file and apply the some filters on record values. So I am looking for a solution to convert the mainframe file to csv or text or Excel workbook so that I can easily perform the operations on the file.

I also need to validate the records count.

Upvotes: 0

Views: 2324

Answers (2)

Hogstrom
Hogstrom

Reputation: 3761

I was recently processing the hardcopy log and wanted to break the record apart. I used python to do this as the record was effectively a fixed position record with different data items at fixed locations in the record. In my case the entire record was text but one could easily apply this technique to convert various colums to an appropriate type.

Here is a sample record. I added a few lines to help visualize the data offsets used in the code to access the data:

          1         2         3         4         5         6         7         8         9
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
N 4000000 PROD     19114 06:27:04.07 JOB02679 00000090  $HASP373 PWUB02#C STARTED - INIT 17

Note the fixed column positions for the various items and how they are referenced by position. Using this technique you could process the file and create a CSV with the output you want for processing in Excel.

For my case I used Python 3.

def processBaseMessage(self, message):    
        self.command  = message[1]
        self.routing  = list(message[2:9])
        self.routingCodes = []                       # These are routing codes extracted from the system log.
        self.sysname  = message[10:18]
        self.date     = message[19:24]
        self.time     = message[25:36]
        self.ident    = message[37:45]
        self.msgflags = message[46:54]
        self.msg      = [ message[56:] ]

You can then format into the form you need for further processing. There are other ways to process mainframe data but based on the question this approach should suit your needs but there are many variations.

Upvotes: 0

Martin Packer
Martin Packer

Reputation: 763

Who said anything about EBCDIC? The OP didn't.

If it is all text then FTP'ing with EBCDIC to ASCII translation is doable, including within Python.

If not then either:

  • The extraction and conversion to CSV needs to happen on z/OS. Perhaps with a COBOL program. Then the CSV can be FTP'ed down with

or

  • The data has to be FTP'ed BINARY and then parsed and bits of it translated.

But, as so often is the case, we need more information.

Upvotes: 0

Related Questions