ASCII to EBCDIC Conversion with DFSORT
MartinPacker 11000094DH Comments (4) Visits (17394)
(Scroll down if you're not interested in DB2)
This past week I've been updating our SQL Analysis code to cope with Unicode SQL statements. (If you bind a package or plan once you've gone to DB2 Version 8 New Function Mode the statement text is stored in the Catalog in Unicode.) These statements are in Unicode UTF-8 which is extremely similar to ASCII. So I snaffled some existing code of mine that converts from ASCII to EBCDIC and pressed it into service...
If the first 10 bytes of the statement text (minus the 2 4-byte header fields) contain X'40' (an EBCDIC null (space)) then I consider the text to be in EBCDIC. Otherwise I deem it to be ASCII - and do the conversion. (You might ask "what about statements like ROLLBACK?" Well, it turns out that in SYSPACKSTMT there is always a trailing blank on the statement text - so that's alright. :-)
(In fact my code decodes all the structural information in the SYSPACKSTMT STMT column - including extracting information on host variables.)
Now, my colleagues sometimes just want to take a look at the statement text sometimes - without bothering to run my code. So here's what I learned when creating a DFSORT job I set up for them to run, converting the statement text from ASCII to EBCDIC.
Converting ASCII to EBCDIC With DFSORT
First, a disclaimer: Certain codepoints might need slight adjustment in some countries - for example if you have dollar versus pound sterling issues.
First you code an ALTSEQ statement: