Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converting ebcdic to text file 4

Status
Not open for further replies.

sncheong

Programmer
Jan 18, 2001
47
NZ
i am trying a trial copy of vedit [www.vedit.com] to convert ebcdic to text file and haven't much progress. any guru to guide me to evaluate vedit or better still, is that an easier way to convert ebcdic file to text/ascii file? ta
 
Will you need to convert these files on a regular basis, or is this a one-time situation? How large are the files? Is the process time critical? Have you also checked out DataJunction (
I wrote an EBCDIC/ASCII (and ASCII/EBCDIC) string conversion function in FoxPro 2.0, that worked for my needs. If you'd like, I'll post them - they're basically just lookup tables.

Rick
 
tks rick, i love to try your approach. please post. i have to do the conversion on a regular basis and the ebcdic data file can be as large as 50mb. meanwhile, i shall go to datajunction and have a look-see. ta
 
*** ------------------------------------------------------------------ ***
***
*** These routines convert ASCII (ANSI) and EBCDIC strings.
***
*** asc2ebc(str) : ASCII String to EBCDIC String
***
*** ebc2asc(str) : EBCDIC String to ASCII String
***
*** EXAMPLES:
***
*** ? ebc2asc(asc2ebc('0123456789'))
*** ? ebc2asc(asc2ebc('abcdefghijklmnopqrstuvwxyz'))
*** ? ebc2asc(asc2ebc(UPPER('abcdefghijklmnopqrstuvwxyz')))
*** ? ebc2asc(asc2ebc('!@#$%^&amp;*()_+{}:&quot;<>?|~-=[];,./`'+&quot;'&quot;))
***
*** ------------------------------------------------------------------ ***
FUNCTION asc2ebc &amp;&amp; Convert ASCII to EBCDIC
PARAMETER zcasc
PRIVATE lcebc, lnii, lntmp

*** Note: There is no EBCDIC '!' or '^' ***
IF TYPE('gcchrebc') <> &quot;C&quot;
RELEASE gcchrebc &amp;&amp; jic
PUBLIC gcchrebc
gcchrebc = &quot;&quot;
* - NUL -> SI
gcchrebc = gcchrebc+chr(000)+chr(001)+chr(002)+chr(003);
+chr(055)+chr(045)+chr(046)+chr(047)
gcchrebc = gcchrebc+chr(022)+chr(005)+chr(021)+chr(011);
+chr(012)+chr(013)+chr(014)+chr(015)
* - DLE -> US
gcchrebc = gcchrebc+chr(016)+chr(017)+chr(018)+chr(019);
+chr(060)+chr(061)+chr(050)+chr(038)
gcchrebc = gcchrebc+chr(024)+chr(025)+chr(063)+chr(033);
+chr(028)+chr(029)+chr(030)+chr(031)
* - <space> -> /
gcchrebc = gcchrebc+chr(064)+chr(255)+chr(127)+chr(123);
+chr(091)+chr(108)+chr(080)+chr(125)
gcchrebc = gcchrebc+chr(077)+chr(093)+chr(092)+chr(078);
+chr(107)+chr(096)+chr(075)+chr(097)
* - 0 -> ?
gcchrebc = gcchrebc+chr(240)+chr(241)+chr(242)+chr(243);
+chr(244)+chr(245)+chr(246)+chr(247)
gcchrebc = gcchrebc+chr(248)+chr(249)+chr(122)+chr(094);
+chr(076)+chr(126)+chr(110)+chr(111)
* - @ -> O
gcchrebc = gcchrebc+chr(124)+chr(193)+chr(194)+chr(195);
+chr(196)+chr(197)+chr(198)+chr(199)
gcchrebc = gcchrebc+chr(200)+chr(201)+chr(209)+chr(210);
+chr(211)+chr(212)+chr(213)+chr(214)
* - P -> _
gcchrebc = gcchrebc+chr(215)+chr(216)+chr(217)+chr(226);
+chr(227)+chr(228)+chr(229)+chr(230)
gcchrebc = gcchrebc+chr(231)+chr(232)+chr(233)+chr(074);
+chr(224)+chr(090)+chr(255)+chr(109)
* - ` -> o
gcchrebc = gcchrebc+chr(121)+chr(129)+chr(130)+chr(131);
+chr(132)+chr(133)+chr(134)+chr(135)
gcchrebc = gcchrebc+chr(136)+chr(137)+chr(145)+chr(146);
+chr(147)+chr(148)+chr(149)+chr(150)
* - p -> DEL
gcchrebc = gcchrebc+chr(151)+chr(152)+chr(153)+chr(162);
+chr(163)+chr(164)+chr(165)+chr(166)
gcchrebc = gcchrebc+chr(167)+chr(168)+chr(169)+chr(192);
+chr(079)+chr(208)+chr(161)+chr(007)
ENDIF
lcebc = &quot;&quot;
FOR lnii = 1 to LEN(zcasc)
lntmp = ASC(SUBSTR(zcasc, lnii, 1))+1 &amp;&amp; (+1 from zero to one based)
IF lntmp < 128 &amp;&amp; OK to Translate
lcebc = lcebc + SUBSTR(gcchrebc, lntmp, 1)
ELSE &amp;&amp; No direct equivalance
lcebc = lcebc + chr(255)
ENDIF
ENDFOR

RETURN lcebc

*** ------------------------------------------------------------------ ***

FUNCTION ebc2asc &amp;&amp; Convert EBCDIC to ASCII
PARAMETER zcebc
PRIVATE lcasc, lnii

IF TYPE('gcchrasc') <> &quot;C&quot;
RELEASE gcchrasc &amp;&amp; jic
PUBLIC gcchrasc

gcchrasc = &quot;&quot;
* - NUL -> SI
gcchrasc = gcchrasc+chr(000)+chr(001)+chr(002)+chr(003);
+chr(255)+chr(009)+chr(255)+chr(127)
gcchrasc = gcchrasc+chr(255)+chr(255)+chr(255)+chr(011);
+chr(012)+chr(013)+chr(014)+chr(015)
* - DLE -> US
gcchrasc = gcchrasc+chr(016)+chr(017)+chr(018)+chr(019);
+chr(255)+chr(255)+chr(008)+chr(255)
gcchrasc = gcchrasc+chr(024)+chr(025)+chr(255)+chr(255);
+chr(028)+chr(029)+chr(030)+chr(031)
* - LF -> BEL
gcchrasc = gcchrasc+chr(255)+chr(255)+chr(255)+chr(255);
+chr(255)+chr(010)+chr(023)+chr(027)
gcchrasc = gcchrasc+chr(255)+chr(255)+chr(255)+chr(255);
+chr(255)+chr(005)+chr(006)+chr(007)
* - SYN -> SUB
gcchrasc = gcchrasc+chr(255)+chr(255)+chr(022)+chr(255);
+chr(255)+chr(255)+chr(255)+chr(004)
gcchrasc = gcchrasc+chr(255)+chr(255)+chr(255)+chr(255);
+chr(020)+chr(021)+chr(255)+chr(026)
* - <space> -> Vert Bar
gcchrasc = gcchrasc+chr(032)+chr(255)+chr(255)+chr(255);
+chr(255)+chr(255)+chr(255)+chr(255)
gcchrasc = gcchrasc+chr(255)+chr(255)+chr(091)+chr(046);
+chr(060)+chr(040)+chr(043)+chr(124)
* - &amp; -> Not
gcchrasc = gcchrasc+chr(038)+chr(255)+chr(255)+chr(255);
+chr(255)+chr(255)+chr(255)+chr(255)
gcchrasc = gcchrasc+chr(255)+chr(255)+chr(093)+chr(036);
+chr(042)+chr(041)+chr(059)+chr(255)
* - - -> ?
gcchrasc = gcchrasc+chr(045)+chr(047)+chr(255)+chr(255);
+chr(255)+chr(255)+chr(255)+chr(255)
gcchrasc = gcchrasc+chr(255)+chr(255)+chr(255)+chr(044);
+chr(037)+chr(095)+chr(062)+chr(063)
* - ` -> &quot;
gcchrasc = gcchrasc+chr(255)+chr(255)+chr(255)+chr(255);
+chr(255)+chr(255)+chr(255)+chr(255)
gcchrasc = gcchrasc+chr(255)+chr(096)+chr(058)+chr(035);
+chr(064)+chr(039)+chr(061)+chr(034)
* - a -> i
gcchrasc = gcchrasc+chr(255)+chr(097)+chr(098)+chr(099);
+chr(100)+chr(101)+chr(102)+chr(103)
gcchrasc = gcchrasc+chr(104)+chr(105)+chr(255)+chr(255);
+chr(255)+chr(255)+chr(255)+chr(255)
* - j -> r
gcchrasc = gcchrasc+chr(255)+chr(106)+chr(107)+chr(108);
+chr(109)+chr(110)+chr(111)+chr(112)
gcchrasc = gcchrasc+chr(113)+chr(114)+chr(255)+chr(255);
+chr(255)+chr(255)+chr(255)+chr(255)
* - ~ -> z
gcchrasc = gcchrasc+chr(255)+chr(126)+chr(115)+chr(116);
+chr(117)+chr(118)+chr(119)+chr(120)
gcchrasc = gcchrasc+chr(121)+chr(122)+chr(255)+chr(255);
+chr(255)+chr(255)+chr(255)+chr(255)
* - .. ..
gcchrasc = gcchrasc+chr(255)+chr(255)+chr(255)+chr(255);
+chr(255)+chr(255)+chr(255)+chr(255)
gcchrasc = gcchrasc+chr(255)+chr(255)+chr(255)+chr(255);
+chr(255)+chr(255)+chr(255)+chr(255)
* - { -> I
gcchrasc = gcchrasc+chr(123)+chr(065)+chr(066)+chr(067);
+chr(068)+chr(069)+chr(070)+chr(071)
gcchrasc = gcchrasc+chr(072)+chr(073)+chr(255)+chr(255);
+chr(255)+chr(255)+chr(255)+chr(255)
* - } -> R
gcchrasc = gcchrasc+chr(125)+chr(074)+chr(075)+chr(076);
+chr(077)+chr(078)+chr(079)+chr(080)
gcchrasc = gcchrasc+chr(081)+chr(082)+chr(255)+chr(255);
+chr(255)+chr(255)+chr(255)+chr(255)
* - \ -> Z
gcchrasc = gcchrasc+chr(092)+chr(255)+chr(083)+chr(084);
+chr(085)+chr(086)+chr(087)+chr(088)
gcchrasc = gcchrasc+chr(089)+chr(090)+chr(255)+chr(255);
+chr(255)+chr(255)+chr(255)+chr(255)
* - 0 -> 9
gcchrasc = gcchrasc+chr(048)+chr(049)+chr(050)+chr(051);
+chr(052)+chr(053)+chr(054)+chr(055)
gcchrasc = gcchrasc+chr(056)+chr(057)+chr(255)+chr(255);
+chr(255)+chr(255)+chr(255)+chr(255)
ENDIF

lcasc = &quot;&quot;
FOR lnii = 1 to LEN(zcebc)
* &amp;&amp; (+1 from zero based to one based)
lcasc = lcasc + SUBSTR(gcchrasc, ASC(SUBSTR(zcebc, lnii, 1))+1, 1)
ENDFOR

RETURN lcasc

*** ------------------------------------------------------------------ ***

 
many tks rick, i'll let you know how i fare with your codes.
 
I used Data Junction to convert phone company ebcdic to SQL and it worked great. It also looks like the fox code provided will do the job also, and it is sure cheaper.
 
rick, i converted an ebcdic file but i have a lot of small squares boxes in the text file. i wonder whether i can send both files to you for your expert opinion whether i am on the right track. tks
 
Sorry, I missed your last post. I'd assume that the &quot;square boxes&quot; are null characters (Chr(0)). Because there are 256 possible characters in EBCDIC, and only 128 in ASCII (ANSI), my table maps those 128 &quot;extra&quot; characters to the null character. This would normally only happen if your file isn't completely EBCDIC, but rather had embedded binary fields. In a case like this, you'd need to get a lot more sophisticated in the conversion than my simple character mapping. So as not to get (more) unwanted SPAM, if you still need me to look at the files, please zip them up before sending them. I'm including a variant on my user group e-mail address - I'll assume you can figure out what to remove to make it valid. mmfudg@NOSPAMmelange-inc.com.

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top