WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Miscellaneous

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

EBCDIC To ASCII Conversion

Keywords: 	  EBCDIC  ASCII  Conversion EBCIDIC

Question:

Is there a way in WinBatch to convert a file in EBCDIC into ASCII?

I have a bunch of mainframe files that I need to convert, then do further processing.

Answer:

Yes. The BinaryXlate function is designed to do this. Example below.

Basically:

Load ebcidic file into an binary buffer.
Load translation table into another binary buffer.

For each byte in source buffer, use byte value as index into translation buffer, grab value in translation buffer and replace original byte with it. Do next byte.

Half the problem will be creating the translation table. However it can be saved in a file and only have to be generated once.

1 See the Function BinaryXlate, in the WIL help file.

;EBCDIC to ASCII translation table
;Codes  0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
row0 ="000 001 002 003 032 009 032 127 032 032 032 011 012 013 014 015" ; 0x0-
row1 ="016 017 018 019 032 032 008 032 024 025 032 032 032 032 032 032" ; 0x1-
row2 ="032 032 028 032 032 010 023 027 032 032 032 032 032 005 006 007" ; 0x2-
row3 ="032 032 022 032 032 030 032 004 032 032 032 032 020 021 032 032" ; 0x3-
row4 ="032 032 032 032 032 032 032 032 032 032 155 046 060 040 043 032" ; 0x4-

row5 ="038 032 032 032 032 032 032 032 032 032 033 036 042 041 059 191" ; 0x5-
row6 ="045 047 032 032 032 032 032 032 032 032 124 044 037 095 062 063" ; 0x6-
row7 ="032 032 032 032 032 032 032 032 032 032 058 035 064 039 061 034" ; 0x7-
row8 ="032 097 098 099 100 101 102 103 104 105 032 032 032 032 032 032" ; 0x8-
row9 ="032 106 107 108 109 110 111 112 113 114 032 032 032 032 032 032" ; 0x9-
row10="032 126 115 116 117 118 119 120 121 122 032 032 032 032 032 032" ; 0xA-

row11="032 032 032 032 032 032 032 032 032 032 032 032 032 032 032 032" ; 0xB-
row12="123 065 066 067 068 069 070 071 072 073 032 032 032 032 032 032" ; 0xC-
row13="125 074 075 076 077 078 079 080 081 082 032 032 032 032 032 032" ; 0xD-
row14="092 032 083 084 085 086 087 088 089 090 032 032 032 032 032 032" ; 0xE-
row15="048 049 050 051 052 053 054 055 056 057 032 032 032 032 032 032" ; 0xF-

;Allocte 256 bytes for a 1:1 translation table
bbxlate=BinaryAlloc(256)
;load translation table from ROW variables above. 

; Could have loaded ir from a file also
for rowdigit=0 to 15
    for coldigit= 0 to 15
       BinaryPoke(bbxlate,(rowdigit*16)+coldigit,ItemExtract(coldigit+1,row%rowdigit%," "))
    next
next

;Ask user for a file name of an EBCDIC file
fn=AskFileName("EBCDIC -> ASCII", "", "EBCDIC files|*.ebc|All Files|*.*","*.*",1)
;Generate corresponding *.asc name
fnout=FileMapName(fn,strcat(FilePath(fn),"*.asc"))

;Get size of source file
fs=FileSize(fn)
;Allocate a binary buffer that size

bb=BinaryAlloc(fs)
;Read source file into binary buffer
BinaryRead(bb,fn)
;Perform the magic Xlate function
BinaryXlate(bb,bbxlate,0)
;Write result file do the output file
BinaryWrite(bb,fnout)
;Free binary buffers
BinaryFree(bb)
BinaryFree(bbxlate)

;claim victory
Message("All","Done"))


Article ID:   W14621
Filename:   EBCDIC To ASCII.txt
File Created: 2002:06:14:15:49:24
Last Updated: 2002:06:14:15:49:24