** Convert EBCDIC to clear text **

Help with writing and running scripts

** Convert EBCDIC to clear text **

Postby SpectraGuy » Thu Nov 15, 2007 1:53 am

hi guys.

i was wondering how could i convert EBCDIC value to clear text using UltraEdit.

E.g. If EBCDIC value E7E2C3E3 is converted to clear text, it'd be XSCT.

appreciate your valuable expertise.

:)
User avatar
SpectraGuy
Newbie
 
Posts: 2
Joined: Wed Nov 14, 2007 12:00 am

Re: ** Convert EBCDIC to clear text **

Postby fgeurts » Thu Nov 15, 2007 10:36 pm

If you do an ASCII FTP of the EBCDIC file into UltraEdit, it will automatically convert into clear text. Alternatively, if you already have the binary EBCDIC file on your PC, simply select the File/Conversions/EBCDIC to ASCII option from the UE menu.

Cheers...

Frank
User avatar
fgeurts
Advanced User
Advanced User
 
Posts: 61
Joined: Sun Feb 20, 2005 12:00 am
Location: Brisbane, Australia

Re: ** Convert EBCDIC to clear text **

Postby SpectraGuy » Sun Nov 18, 2007 8:26 am

Frank,
In mainframe host CICS dump screen, the info is all in EBCDIC.
I saved the CICS dump info & download it locally to my PC.
After that, I did the following :

) open UE, go to File -> New
b) paste "E7 E2 C3 E3" where it was copied from CICS dump info
c) go to File -> Conversions -> EBCDIC To ASCII

I got ¤€¤€¢“€¤“ instead of XSCT.

At what point did I go wrong?
User avatar
SpectraGuy
Newbie
 
Posts: 2
Joined: Wed Nov 14, 2007 12:00 am

Re: ** Convert EBCDIC to clear text **

Postby jorrasdk » Sun Nov 18, 2007 1:34 pm

Ok, you are in fact not dealing with "real" EBCDIC data but with hex escaped EBCDIC data. And out of the box UE cannot do conversions of that.

First you have to change the hex escaped EBCDIC back into "normal" EBCDIC. Then you can use UE's conversion EBCDIC to ASCII.

But you need a script to do this in UE, so you have to have at least version 13 of UE ? (If not upgrade to UE version 13 - or find another tool for this task).

The script in the following will first "un-escape" your EBCDIC dump data and then convert into ASCII.

Before data:
Code: Select all
E7E2C3E3
E7 E2 C3 E3


After the script has run:
Code: Select all
XSCT
XSCT


The script itself:
Code: Select all
// First select the entire contents of the active document:
UltraEdit.activeDocument.selectAll();

// Next retrieve the selected data into a variable:
var iLines = UltraEdit.activeDocument.selection;

// Delete contents of active file:
UltraEdit.activeDocument.deleteText();

// Remove spaces
iLines = iLines.replace(/[ ]/g,"");

// Split into lines - assume DOS format line endings
var iLineArr = iLines.split("\r\n");

// outputvariable:
var oStr = "";

// Run through all lines
for (i=0;i<iLineArr.length;i++) {
   // Drop empty lines
   if(iLineArr[i].length < 2) {
      continue;
   }

   // Run through single line
   for (j=0;j<iLineArr[i].length;j=j+2) {
      var iChr = iLineArr[i].substr(j,2); /* read a single hex escaped character */

      if(iChr=="00") { /* hex 00 is suppressed as blank */
         iChr="40"; /* hex 40 = blank in EBCDIC */
      }

      // Un-escape two character hex into single character EBCDIC
      oStr = oStr + String.fromCharCode(parseInt( iChr, 16 ));
   }
   // 0D=>CR  25=>LF i EBCDIC
   oStr = oStr + String.fromCharCode(parseInt( "0D", 16 ));
   oStr = oStr + String.fromCharCode(parseInt( "25", 16 ));

   // Write un-escaped line back into the active UE document
   UltraEdit.activeDocument.write(oStr);
   oStr = "";
}

// Convert from EBCDIC to ASCII:
UltraEdit.activeDocument.fromEBCDIC();


Have fun with this
User avatar
jorrasdk
Master
Master
 
Posts: 275
Joined: Mon Mar 19, 2007 11:00 pm
Location: Denmark

Re: ** Convert EBCDIC to clear text **

Postby maryv » Mon Nov 19, 2007 7:27 pm

Very, very slick, jorrasdk!
User avatar
maryv
Basic User
Basic User
 
Posts: 26
Joined: Wed Mar 21, 2007 11:00 pm


Return to Scripts