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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bringing MainFrames back to live with Julia converting ebcdic to text file

Status
Not open for further replies.

siralf

Systems Engineer
Jun 14, 2020
1
US
Hello Geeks,
Some guidance would enlighten my dark world.
I have ebcdic files coming in and need to covert these to ASCII so I can push/digest these to other systems like Oracle and Kafka for processing...

So, I'm wondering if I can write these functions in Julia. It's said that it's super fast.
I found this closed post. Credit to Rick, he did a great job with these two functions:
*** ------------------------------------------------------------------ ***
***
*** 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('!@#$%^&*()_+{}:"<>?|~-=[];,./`'+"'"))
***
*** ------------------------------------------------------------------ ***
FUNCTION asc2ebc && Convert ASCII to EBCDIC
PARAMETER zcasc
PRIVATE lcebc, lnii, lntmp

*** Note: There is no EBCDIC '!' or '^' ***
IF TYPE('gcchrebc') <> "C"
RELEASE gcchrebc && jic
PUBLIC gcchrebc
gcchrebc = ""
* - 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 = ""
FOR lnii = 1 to LEN(zcasc)
lntmp = ASC(SUBSTR(zcasc, lnii, 1))+1 && (+1 from zero to one based)
IF lntmp < 128 && OK to Translate
lcebc = lcebc + SUBSTR(gcchrebc, lntmp, 1)
ELSE && No direct equivalance
lcebc = lcebc + chr(255)
ENDIF
ENDFOR

RETURN lcebc

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

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

IF TYPE('gcchrasc') <> "C"
RELEASE gcchrasc && jic
PUBLIC gcchrasc

gcchrasc = ""
* - 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)
* - & -> 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)
* - ` -> "
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 = ""
FOR lnii = 1 to LEN(zcebc)
* && (+1 from zero based to one based)
lcasc = lcasc + SUBSTR(gcchrasc, ASC(SUBSTR(zcebc, lnii, 1))+1, 1)
ENDFOR

RETURN lcasc

*** ------------------------------------------------------------------ ***
 
So what's your question?

Use any language you like and know, look up the definition of EBCDIC and go for it: First google result:
You want fast? Either go for assembler or C/C++. Any new language is built on top of these and by definition always a higher-level language with more comfort and less speed And CPUs still run assembler only.
But mapping some byte combinations to others is no big deal.

Just, why reinvent the wheel when other languages support EBCDIC?

Bye, Olaf.

Olaf Doschke Software Engineering
 
Siraf,

As Olaf mentioned for fast conversion go to C/C++. If an EBCDIC file contains packed fields you'll have to describe each column starting and ending position and, therefore, overall record width.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top