I am using Jon Skeet's EBCDIC implementation in .NET to read a VSAM file downloaded in binary mode with FTP from a mainframe system. It works very well for reading/writing in this encoding, but it does not have anything to read packed-decimal values. My file contains these, and I need to unpack them (at the cost of more bytes, obviously).
How can I do this?
My fields are defined as PIC S9(7)V99 COMP-3.
Ahh, BCD. Honk if you used it in 6502 assembly.
Of course, the best bet is to let the COBOL MOVE do the job for you! One of these possibilities may help.
(Possibility #1) Assuming you do have access to the mainframe and the source code, and the output file is ONLY for your use, modify the program so it just MOVEs the value to a plain unpacked PIC S9(7)V99.
(Possibility #2) Assuming it's not that easy, (e.g., file is input for other pgms, or can't change the code), you can write another COBOL program on the system that reads that file and writes another. Cut and paste the file record layout with the BCD into the new program for input and output files. Modify the output version to be non-packed. Read a record, do a 'move corresponding' to transfer the data, and write, until eof. Then transfer that file.
(Possibility #3) If you can't touch the mainframe, note the description in the article you linked in your comment. BCD is relatively simple. It could be as easy as this (vb.net):
I tested it with a few variations of this call:
E.g., is -40.1. But just a few. So it might still be wrong.
So then if your comp-3 starts, say, at byte 10 of the input record layout, this would solve it:
Noting the formulas from the data-conversion article for the # of bytes to send in, and the # of 9's before and after the V.
Store the result in a Decimal to avoid rounding errors. Esp if it's $$$. Float & Double WILL cause you grief! If you're not processing it, even a string is better.
of course it could be harder. Where I work, the mainframe is 9 bits per byte. Serious. That's what makes the first 2 possibilities so salient. Of course what really makes them better is the fact the you may be a PC only programmer and this is a great excuse to get a mainframe programmer to do the work for you! If you are so lucky to have that option...
Peace, -Al