Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

COBOL to ascii conversions

by sweetblood (Parson)
on Dec 03, 2004 at 21:03 UTC ( #412282=perlquestion: print w/ replies, xml ) Need Help??
sweetblood has asked for the wisdom of the Perl Monks concerning the following question:

I have a bunch of data files along with COBOL copybooks. I need to convert these COBOL data files to ascii. I suspect I'll need to use pack/unpack to get at these data, but I don't have the foggiest notion where to begin. I do have perlpacktut and Pack/Unpack Tutorial, I have not read them as yet but will start as soon as I finish this post.

The copybooks I have look like this:

01 CLASS-OUT. 05 CCNUM-OUT PIC X(14). 05 CCDESC-OUT PIC X(40). 05 CL-OUT PIC X(14). 05 CLDESC-OUT PIC X(38).
or
01 MASTER-OUT REDEFINES HEADER-RECORD. 05 CC-NUMBER PIC 9(04). 05 MTD-UNITS PIC S9(07). 05 MTD-DOLLARS PIC S9(09). 05 INV-ON-HAND PIC S9(07).
I also have a COBOL reference that tells me that 'PIC X(14).' tells me that the data field is a 14-byte alpha-numeric field and that PIC S9(07) is a 7-byte signed integer. I'm just not sure how to get Perl to pass this as ascii.

I would really appreciate any suggetions on how to start.

Thanks!!!

Update: This is on an HP-UX with Perl 5.6.1

Sweetblood

Comment on COBOL to ascii conversions
Select or Download Code
Re: COBOL to ascii conversions
by VSarkiss (Monsignor) on Dec 03, 2004 at 21:07 UTC

    You probably mean EBCDIC, which is an encoding, not COBOL, which is a language. You can use EBCDIC-to-ASCII converters (most often in mainframe file transfer programs). After that, you have a plain, fixed-width, ascii file to work with. It's usually a lot simpler than trying to do the EBCDIC conversion yourself.

    As an aside, there are COBOL fields that are a pain to parse (COMP fields, specifically), but if you have plain X and 9 fields, you're OK.

    Update
    For example, once you have it in ascii, you can handle your first record with something as simple as:

    ($ccnum_out, $ccdesc_out, $cl_out, $cldesc_out) = unpack('A14 A40 A14 A38', $class_out);
    Assuming $class_out contains the whole line. For more details on unpack, take a look at perlfunc:pack.

Re: COBOL to ascii conversions
by fglock (Vicar) on Dec 03, 2004 at 21:27 UTC

    Check the Encode module:

    use Encode; ... from_to($data, "EBCDIC", "ASCII");

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://412282]
Approved by VSarkiss
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2014-08-22 02:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (145 votes), past polls