Anonymonk:
I have some perl code to do this conversion, which I can't seem to find it at the moment. But if you don't mind using C, I *did* trip across one of my older C programs that did this sort of conversion. It's not pretty, but maybe it might be useful. Towards the end, you just convert your PIC statement into a few function calls to do the conversion work. All the stuff before main are the helper routines to make the conversion section simple.
Much of it is boilerplate (in readmore tags so uninterested people can skip it).
The only bit you need to work with is this section, where you use the functions to split the mainframe file up and convert it into an ASCII flat file:
// **************************************************
// * YOU NEED TO CUSTOMIZE THE CODE BETWEEN HERE... *
// **************************************************
// Now we use Uunpack, Sunpack, and xlat to translate the fiel
+ds.
//
// Let's pretend our input record is:
//
// MERCHANT-NUMBER PIC 9(9) COMP-3.
// STORE-NUMBER PIC 9(9) COMP-3.
// CREATED-DATE PIC 9(8) COMP-3. (FMT=YYYYMMDD)
// MERCHANT-NAME PIC X(32).
// OWNER-NAME PIC X(32).
// CURRENT-BALANCE PIC S9(8)v99.
//
// The first two fields are packed unsigned numeric, using an
+odd number
// of digits, so we use Uunpack:
dst = Uunpack(dst, inbuf+0, 5);
dst = Uunpack(dst, inbuf+5, 5);
// The date is also a packed unsigned numeric, but has only 8
+digits, so
// we tell Uunpack to skip the first digit (otherwise our date
+ would look
// like '0YYYYMMDD'.
dst = Uunpack(dst, inbuf+10, 5, 1);
// The next two fields are simple text fields. This is the ea
+sy
// translation bit. You could call xlat twice, but since they
+'re
// adjacent, I'll translate both text fields at the same time:
xlat(dst, inbuf+15, 64);
// Signed numbers are similar to the unsigned, but they have t
+railing
// signs. A fancy program would move the sign to the front.
+This is
// decidedly *not* a fancy program.
dst = Sunpack(dst, inbuf+74, 6);
// Adding field delimiters, end of record markers, etc., is pr
+etty
// trivial. Here we'll add a CR+LF at the end of each line:
*dst++ = '\r';
*dst++ = '\n';
*dst++ = 0;
// *****************************
// * END OF CUSTOMIZED SECTION *
// *****************************
// Write our translated record
fputs(outbuf, fout);
}
printf("%lu reads\n", recs);
fclose(fin);
fclose(fout);
}
Update: Put the boilerplate code in readmore tags to shorten the node a bit.
...roboticus
When your only tool is a hammer, all problems look like your thumb. |