ascii to ecbdic conversion

Forums for specific tips, techniques and example code
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

ascii to ecbdic conversion

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:32 pm

by John Porter >> Fri, 16 Feb 2001 1:37:18 GMT

Anyone have a Jade method (or dll) to do this?

Thanks,
John Porter

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: ascii to ecbdic conversion

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:32 pm

by Craig Petrie >> Tue, 31 Jul 2001 23:16:34 GMT
Anyone have a Jade method (or dll) to do this?

Thanks,
John Porter
The following is the implementation that Peter Fitchett and I created,: _______________________________________________________________ stringToEBCDIC(asciiValue :String) :String;

// Intent : To convert a field from PC ASCII to Unisys EBCDIC

constants
EBCDIC = #'00 01 02 03 37 2D 2E 2F 16 05 25 0B 0C 0D 0E 0F' &
#'10 11 12 13 3C 3D 32 26 18 19 3F 27 1C 1D 1E 1F' &
#'40 4F 7F 7B 5B 6C 50 7D 4D 5D 5C 4E 6B 60 4B 61' &
#'F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 7A 5E 4C 7E 6E 6F' &
#'7C C1 C2 C3 C4 C5 C6 C7 C8 C9 D1 D2 D3 D4 D5 D6' &
#'D7 D8 D9 E2 E3 E4 E5 E6 E7 E8 E9 4A E0 5A 5F 6D' &
#'79 81 82 83 84 85 86 87 88 89 91 92 93 94 95 96' &
#'97 98 99 A2 A3 A4 A5 A6 A7 A8 A9 C0 6A D0 A1 07' &
// n.b. ascii chars > 127 decimal do not have ebcdic equivalent - hence translate to null
// included in the string just in case - handles up to 255 - the complete range of 8-bit values
#'00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' &
#'00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' &
#'00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' &
#'00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' &
#'00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' &
#'00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' &
#'00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' &
#'00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00';

vars
i :Integer;
str :String;
begin

foreach i in 1 to asciiValue.length do
str := EBCDIC[asciiValue[i:1].Binary.Integer + 1]; // + 1 to get correct position in constant string(e.g. dec(1) is at pos 2)
endforeach;

epilog
return str;
end;

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: ascii to ecbdic conversion

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:32 pm

by Eric Peachey >> Wed, 1 Aug 2001 0:49:06 GMT
_______________________________________________________________ stringToEBCDIC(asciiValue :String) :String;

Would it be safer to return a Binary? I think Jade does funny things occasionally with Strings with embedded nulls. Sometimes it interprets the null as end of String. Perhaps if you store it on a persistent object.

Perhaps this has changed?

Cheers,

Eric

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: ascii to ecbdic conversion

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:32 pm

by Craig Shearer >> Wed, 1 Aug 2001 1:35:52 GMT

No Eric, this hasn't changed. Recall the passwords problem we had? - local variable strings seem capable of having embedded nulls, but when stored on objects, they don't... or is it the other way around???? :-)

Should be fixed, I believe.

Craig.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: ascii to ecbdic conversion

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:32 pm

by Theodore Taptiklis >> Wed, 1 Aug 2001 2:17:59 GMT
No Eric, this hasn't changed. Recall the passwords problem we had? - local variable strings seem capable of having embedded nulls, but when stored on objects, they don't... or is it the other way around???? :-)

You are correct Craig,
JADE handles embedded nulls in strings in all almost all contexts except when they are stored in embedded string attributes (they are handled in slobs). I had to say almost, because there have been cases where strings have been passed to external "C" runtime functions that interpret a null as string terminator resulting in truncation.
Should be fixed, I believe.

"Fixing" the embedded string attribute case will require storing the string length in the object (as it is for slobs) with all that entails in terms of structure changes and reorgs etc.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: ascii to ecbdic conversion

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:32 pm

by connie >> Sat, 13 Aug 2005 4:15:42 GMT

this is a message for theodore taptiklis - if he knew John hugh Johnston in Dunedin in mid 1960's - John will be 60 on Monday - can theodore contact connie@connielene.com please

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: ascii to ecbdic conversion

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:32 pm

by John Porter >> Wed, 1 Aug 2001 7:16:27 GMT

I also have (now) asciiToEbcdic and ebcdicToAscii methods. Since no one replied to me 6 months ago I wrote them myself. You should have asked me - I could have saved you the effort of building that ugly constant. That was the hardest part. My methods are on the String class, with class constants so they can be used from multiple methods.

Cheers,
John P


Return to “Tips and Techniques”

Who is online

Users browsing this forum: No registered users and 25 guests

cron