Portal | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
Harold Barnes

New User

Joined: 27 Oct 2015
Posts: 30
Location: United States

 Posted: Thu Sep 17, 2020 8:28 am    Post subject: Need help with TRANSLATE() I've built 2 tables, one for EBCDIC to ASCII and the other for ASCII to EBCDIC strin = "A" estr = translate(strin,ASC,EBC) say "estr:" c2x(estr) I'm expecting: estr: 41 Instead I get : estr: C1 So translate is not finding 'C1'x in the EBCDIC table and does not change it. Thinking that my translate table might be bad (never happens) I manually extract the 'C1'x position from the EBCDIC table. epos = x2d('c1'x) + 1 say "epos: " epos epos: 194 aval = substr(EBC,epos,1) say "aval: c2x(aval) aval: 41 So my EBCDIC table is good. EBCDIC 'A' is ASCII '41'x apos = x2d('41'x) + 1 apos: 66 aval = substr(ASC,apos,1) say "aval:" c2x(aval) aval: C1 So my ASCII table is good. ASCII '41'x is EBCDIC 'C1'x' (letter A) Each table is 256 bytes of hex values. All values have corresponding values. Why doesn't translate find the value?

Harold Barnes

New User

Joined: 27 Oct 2015
Posts: 30
Location: United States

 Posted: Thu Sep 17, 2020 8:59 am    Post subject: Need help with TRANSLATE() Uploading code. (Attached)
prino

Senior Member

Joined: 07 Feb 2009
Posts: 1220
Location: Vilnius, Lithuania

Posted: Thu Sep 17, 2020 3:25 pm    Post subject: Re: Need help with TRANSLATE()

 Harold Barnes wrote: ...Thinking that my translate table might be bad (never happens)...

If you're so effing certain of yourself, why do you bother to ask here?

And your translate tables are utter crap, and don't allow for correct round-robin translations.
Nic Clouston

Global Moderator

Joined: 10 May 2007
Posts: 2406
Location: Hampshire, UK

 Posted: Thu Sep 17, 2020 5:51 pm    Post subject: Reply to: Need help with TRANSLATE() Please do not post attachments - some people are not allowed to download and some do not do it as a security precaution. They are also an interference with rapid browsing of the problem. A simple cut and paste is good enough and more economical. Use the code tags to present code and data.
Harold Barnes

New User

Joined: 27 Oct 2015
Posts: 30
Location: United States

 Posted: Thu Sep 17, 2020 6:09 pm    Post subject: I was being sarcastic about the possibility of me making a mistake. I found the problem. I expected it to work like an ALC translate but it doesn't. Assumptions will get you every time. The ASC table just needed to be generated like this: ASC = "" do i = 0 to 255 val = x2c(d2x(i) ASC = ASC || val end So basically I generate a table entry for every ascii value. Seems stupid but that's the way translate() works. Coding: atran = transalate("A",ASC,EBC) ..will scan the EBC table and find x'C1' in the x'41' position. Then it will go to the x'41' position in the ASC table and find x'41' (surprising) The reverse works as well. atran = transalate('41'x,EBC,ASC) ..will scan the ASC table and find x'41' in the x'41' position. (surprising) Then it will go to the x'41' position in the EBC table and find x'C1' Problem solved.
enrico-sorichetti

Senior Member

Joined: 14 Mar 2007
Posts: 10700
Location: italy

Posted: Thu Sep 17, 2020 6:28 pm    Post subject: Reply to: Need help with TRANSLATE()

the tables might be good , the translate invocation is wrong

when translating from ascii to ebcdic and/or the other way around it is enough to use the output table
the input translate table when omitted defaults to XRANGE('00'x,'FF'x)

 Code: ebc = translate(asciidata, cp00367_to_cp01047 ) where cp00367_to_cp01047 could be something along the lines of                     /* 0 1 2 3 4 5 6 7 8 9 A B C D E F              */ cp00367_to_cp01047  = "40404040404040404040404040404040"x || , /* 0 */                       "40404040404040404040404040404040"x || , /* 1 */                       "405A7F7B5B6C507D4D5D5C4E6B604B61"x || , /* 2 */                       "F0F1F2F3F4F5F6F7F8F97A5E4C7E6E6F"x || , /* 3 */                       "7CC1C2C3C4C5C6C7C8C9D1D2D3D4D5D6"x || , /* 4 */                       "D7D8D9E2E3E4E5E6E7E8E9ADE0BD5F6D"x || , /* 5 */                       "79818283848586878889919293949596"x || , /* 6 */                       "979899A2A3A4A5A6A7A8A9C04FD0A140"x || , /* 7 */                       "40404040404040404040404040404040"x || , /* 8 */                       "40404040404040404040404040404040"x || , /* 9 */                       "40404040404040404040404040404040"x || , /* A */                       "40404040404040404040404040404040"x || , /* B */                       "40404040404040404040404040404040"x || , /* C */                       "40404040404040404040404040404040"x || , /* D */                       "40404040404040404040404040404040"x || , /* E */                       "40404040404040404040404040404040"x      /* F */                     /* 0 1 2 3 4 5 6 7 8 9 A B C D E F              */

also You might consider the quirks of code page handling ( {} different hex values for different code pages )
Harold Barnes

New User

Joined: 27 Oct 2015
Posts: 30
Location: United States

 Posted: Thu Sep 17, 2020 9:49 pm    Post subject: Reply to: Need help with TRANSLATE() enrico-sorichetti Thanks for the reminder to use XRANGE() and for mentioning the default input of TRANSLATE(). Your table coding style is a lot cleaner than mine as well. Thanks for sharing. Nic Clouston: I attached the code thinking that it might make it easier for someone to play. I'll avoid in the future.
Pedro

Global Moderator

Joined: 01 Sep 2006
Posts: 2205
Location: Silicon Valley

 Posted: Fri Sep 18, 2020 7:57 am    Post subject: Reply to: Need help with TRANSLATE() Enrico's table has '40'x for non-display characters, but I vaguely recall that some displays (maybe it was IPCS) show non-display characters as 'periods'. as place holders so that you can tell there is something there other than spaces.
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics Translate UPPER CASE to lower case steve-myers PL/I & Assembler 0 Mon Oct 19, 2015 9:33 am Translate SQL Jimy Carol DB2 3 Thu Sep 05, 2013 7:11 pm How to put a translate variable in th... vasco ferreira JCL & VSAM 1 Wed Nov 03, 2010 2:19 pm Translate Unicode to Decimal HameedAli CLIST & REXX 5 Wed Dec 09, 2009 1:14 pm Utility for Translate & compile C... Amolondhe007 Mainframe Interview Questions 8 Thu Aug 13, 2009 1:20 pm

 © 2003-2020 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us