IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Need help with TRANSLATE()


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Harold Barnes

New User


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

PostPosted: Thu Sep 17, 2020 8:28 am
Reply with quote

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?
Back to top
View user's profile Send private message
Harold Barnes

New User


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

PostPosted: Thu Sep 17, 2020 8:59 am
Reply with quote

Uploading code. (Attached)
Back to top
View user's profile Send private message
prino
Warnings : 1

Senior Member


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

PostPosted: Thu Sep 17, 2020 3:25 pm
Reply with quote

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.
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


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

PostPosted: Thu Sep 17, 2020 5:51 pm
Reply with quote

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.
Back to top
View user's profile Send private message
Harold Barnes

New User


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

PostPosted: Thu Sep 17, 2020 6:09 pm
Reply with quote

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.
Back to top
View user's profile Send private message
enrico-sorichetti

Senior Moderator


Joined: 14 Mar 2007
Posts: 10727
Location: italy

PostPosted: Thu Sep 17, 2020 6:28 pm
Reply with quote

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 )
Back to top
View user's profile Send private message
Harold Barnes

New User


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

PostPosted: Thu Sep 17, 2020 9:49 pm
Reply with quote

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.
Back to top
View user's profile Send private message
Pedro

Global Moderator


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

PostPosted: Fri Sep 18, 2020 7:57 am
Reply with quote

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.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts Translate UPPER CASE to lower case PL/I & Assembler 0
No new posts Translate SQL DB2 3
No new posts How to put a translate variable in th... JCL & VSAM 1
No new posts Translate Unicode to Decimal CLIST & REXX 5
No new posts Utility for Translate & compile C... Mainframe Interview Questions 8
Search our Forums:

Back to Top