0

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.

umesh
  • 1
  • 3
  • 2
    Duplicate of [this answer](https://stackoverflow.com/a/25702057/4717755) ? – PeterT Jun 12 '19 at 18:46
  • @PeterT it's not text file, how can we read the file which is not . txt file? – umesh Jun 12 '19 at 18:58
  • It depends on the contents: that could be anything. Maybe a SAS file, maybe something else, we can't guess for you. The best, and often the only way, is to open the files with the original software that created them, and export to something more "portable", and documented. –  Jun 12 '19 at 19:01
  • 1
    "it's not text file" - isn't EBCDIC just a representation of text data? https://en.wikipedia.org/wiki/EBCDIC – Tim Williams Jun 12 '19 at 19:26
  • This sort of thing comes up often. [Here](https://github.com/cschneid-the-elder/rants/blob/master/advice-reading-mainframe-data.md) are some things you might want to consider. – cschneid Jun 12 '19 at 21:17
  • Do you have a Cobol Copybook ??? in which case StingRay could be used also look at https://stackoverflow.com/questions/56437665/ebcdic-to-ascii-conversions/56439482#56439482 – Bruce Martin Jun 12 '19 at 23:08
  • @umesh do you have a record layout of the file your trying to consume. Not unlike CSV,s there are natural breaks in mainframe data. They however are generally broken based on offset and data type. – Hogstrom Jun 13 '19 at 02:31
  • Why not use the already existing tools on the mainframe to do the filtering? – Kevin McKenzie Jun 13 '19 at 15:03

2 Answers2

0

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.

Martin Packer
  • 648
  • 4
  • 12
0

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.

Hogstrom
  • 3,581
  • 2
  • 9
  • 25