-6

i have downloaded a text file from Mainframe which contains S9(07)V99 COMP-3, S9(4) COMP-4, S9(3), COMP-3 value in text file, how to read actual value of it in java.

  • Can you give us examples of these values? – NomadMaker Sep 23 '20 at 14:25
  • Looks like this is related to cobol. You're not making it easy for anyone to help you... – James Z Sep 23 '20 at 14:29
  • 2
    The formats of `COMP` and `COMP-n` data are system-specific, so it would help to know what system wrote the data. On IBM mainframes, `COMP-3` is packed-decimal and `COMP-4` is 2s-complement binary integer, but they could be just about anything on a different platform. And you say this is **text file** you're dealing with? – Kevin Anderson Sep 23 '20 at 14:44
  • The best solution would be to create a new file without `COMP-3` or `COMP-4` in COBOL and read this file into your JAVA program. – Christoph Schreiber Jan 26 '21 at 03:52

1 Answers1

1

There are 2 basic directions for a file like this

  • Convert comp-(n) fields to Text Fields on the mainframe (the sort utility is a good option) and do standard EBCDIC to ASCII transfer / translate.
  • Do a binary (no EBCDIC Translation) transfer. You will have to handle
    • Mainframe file Structures yourself (they are different to PC / Unix strucutures)
    • Translate Ebcdic to Java-Unicode (For US Ebcdic, the encoding is CP037 (or IBM037)
    • Translate the Comp-(n) variables
    • The JRecord can Read mainframe files in java using a Cobol Copybook. It can also handle mainframe file Structures

Either way you will probably have to do another file Transfer. If you edit your transferred file with notepad an can read some of the Text, the file is corrupt.

Why Transfer binary Mainframe files as EBCDIC

When converting an EBCDIC file to ASCII, the conversion program will try and convert every byte, including binary fields.

Consider a comp-3 field with a value of 400

  Hex Represention   Hex representation after translation to ASCII
  
  
    40 0c               20 0c 
    

in this case the EBCDIC space character (x'40') has been translated to the ASCII space character (x'20') and 400 is now 200.

Mainframe File Structures

The 2 most common file structures on the Mainframe are

  • Fixed Width files (RECFM=FB) - where every record (line) is a fixed length
  • Variable Record Length files (RECFM=FB) - where every record (line) is preceded by the length (RDW -record descriptor word).

RecordEditor / JRecord

JRecord will let you read the mainframe file using a Cobol copybook. It can do the translation and handle mainframe file structures.

The Generate option of the RecordEditor can create skelton code to read a mainframe Cobol file from a sample file and Cobol Copybook.

Also see How do you generate java~jrecord code for a Cobol copybook.

Bruce Martin
  • 9,845
  • 1
  • 24
  • 36
  • Is there any guide or steps how to use sort utility on the mainframe to convert comp-(n) fields to Text Fields – girish mulgunds Sep 24 '20 at 07:10
  • There are several manuals suitably constructed with Contents and Index pages, freely available and easily searched for. But why not ask the person/team who sent you the data in the first place to do the conversion and re-send? – NicC Sep 24 '20 at 09:08