1

I have mainframe file in EBCDIC format and I want to convert those files into ASCII format.

I have tried converting EBCDIC to ASCII using python 2.6 but there are many issues in that like compression field didn't get converted and records count gets increased.

Is there any way to convert EBCDIC files having compressed fields to ASCII format.

user9185088
  • 119
  • 1
  • 1
  • 10
  • 4
    If it contains packed or binary fields it isn't what I would call an EBCDIC-file. Your best bets would be: 1.) process it "as is" on the unix-side with proper handling of the record-layout and encoding or 2.) convert it to a pure EBCDIC-file (without packed or binary fields) on the mainframe-side, then convert it to ASCII. – piet.t Jun 04 '19 at 06:25
  • It's doesn't contain packed or binary fields, it's pure mainframe file and I'm not sure how to proceed further – user9185088 Jun 04 '19 at 06:58
  • 1
    Well, what's that thing you call "compression field"? – piet.t Jun 04 '19 at 07:01
  • In copybook it's length is mentioned as PIC S999V99 [COMP-3]. – user9185088 Jun 04 '19 at 07:03
  • That is packed decimal field – Bruce Martin Jun 04 '19 at 07:04
  • This field is not getting converted correctly while I'm doing with python 2.6 – user9185088 Jun 04 '19 at 07:06
  • 1
    As Bruce Martin said, `COMP-3` is a "packed decimal" (or short "packed") field - any records containing this datatype will be totally destroyed by any type of EBCDIC->ASCII-conversions (if it is not aware of the record-format as defined in the copybook). – piet.t Jun 04 '19 at 07:08
  • So there ain't any way to convert those packed decimal Fields correctly while converting EBCDIC -> ASCII? – user9185088 Jun 04 '19 at 07:10

2 Answers2

2

If you already have the file downloaded you can convert it easily from EBCDIC to ASCII in a Linux or MacOS machine by using the command line. To accomplish that you need to use the dd command.

Here a quick overview of some parameters it uses:

dd [bs=size] [cbs=size] [conv=conversion] [count=n] [ibs=size] [if=file] [imsg=string] [iseek=n] [obs=s] [of=file] [omsg=string] [seek=n] [skip=n]

There are more parameters that those above, to check all available just do the command: man dd, it will show all other available parameters and the explanation of each one.

In your case you should start with:

dd conv=ascii if=EBCDIC_file.txt of=ASCII_file.txt

where EBCDIC_file.txt is the filename of your input EBCDIC file and ASCII_file.txt will be the file created as output with all bytes converted from EBCDIC to ASCII.

Likewise you can do the reverse by using conv=ebcdic to convert a file from ASCII to EBCDIC.

Here's the man page for dd on the web: https://www.man7.org/linux/man-pages/man1/dd.1.html

When you mention compressed in your file, do you mean the whole file comes compressed from the mainframe? Probably it came TERSED (by using terse utility on mainframe). If this is the case, there is a public version of terse that runs on DOS, Linux, MacOS, AIX and others. It is available on cbtape site: http://www.cbttape.org/ftp/cbt/CBT892.zip

mwfearnley
  • 2,377
  • 1
  • 27
  • 29
1

Options

Some options

  • Convert the file to a Text file on the mainframe (sort or eastrieve will both do this)
  • If it is a once off the Fileaid/File master can convert the file to Text on the mainframe
  • If it is a once off the RecordEditor should be able to edit the file with a Cobol Copybook. It can also generate JRecord code to read the file.

  • If there is only one Record-Type in the file, CobolToCsv can use the Cobol Copybook to convert the file to a CSV.

  • The JRecord lets you read a Cobol Copybook in Java
  • JRecord has a COBOL Copy utility will let you do a Cobol to cobol copy. If there is only one Record type you can
    • Copy the EBCDIC Copybook to the equivalent Ascii copybook (ext fields are converted, binary fields are left unchanged). This is usefull if converting a Mainframe Cobol file for use in a Windows / Linux Cobol system
    • Copy a EBCDIC Binary Copybook to an Ascii Text copybook
  • The Stingray project provides access to cobol files in python

CobolTCsv

For Example to convert a Cobol Data File to Csv (single record type) using CobolToCsv :

java -jar ../lib/Cobol2Csv.jar -I In/DTAR020.bin  -O Out/o_DTAR020_space.csv ^
         -C DTAR020.cbl  ^
         -Q DoubleQuote  -FS Fixed_Length    ^
         -IC CP037 -Delimiter ,

Where

  • In/DTAR020.bin is the Input Cobol data file
  • Out/o_DTAR020_space.csv is the output Csv file
  • **DTAR020.cbl ** is the Cobol Copybook
  • Fixed_Length idicates it a fixed length File (FB on the Mainframe)

RecordEditor

Bruce Martin
  • 9,845
  • 1
  • 24
  • 36
  • Is there any other method like using Unix or Python? – user9185088 Jun 06 '19 at 16:28
  • In the answer I mention StingRay which is written in python also Cobol2Csv can be run in Unix (if you have java installed). The mainframe options (sort, eaytrieve) could be run under Mainframe~ZOs~Unix shell. MicroFocus probably has options that run under Unix but they would be expensive – Bruce Martin Jun 07 '19 at 08:30