Portal | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Forum Index
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
Translate UPPER CASE to lower case

Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler
View previous topic :: :: View next topic  
Author Message

Active Member

Joined: 30 Nov 2013
Posts: 860
Location: The Universe

PostPosted: Mon Oct 19, 2015 9:33 am    Post subject: Translate UPPER CASE to lower case
Reply with quote

Just for my amusement I was reviewing some very old topics in Assembler language and came across this one. The "solution" is incorrect, because its author ignored something important: the solution damaged characters that are not upper case characters.

In EBCDIC, lower case characters are in the range X'81' to X'89'. X'91 to X'99', and X'A2 to X'A9'. The upper case characters are in the range X'C1' to X'C9', X'D1' to X'D9', and X'E2' to X'E9'. The classic solution in EBCDIC to translate lower case characters to upper case is to OR X'40' into the character, so lower case a, X'81' becomes X'C1', upper case A. This does not damage a blank (X'40') or the punctuation characters. The solution in the earlier article performed an AND of B'10111111'. This will convert A to a, but a blank will become X'00', and the punctuation characters will be hopelessly damaged.

The "correct" solution uses the TR instruction and a translate table -
         TR    STRING,TRTAB
TRTAB    DC    0XL256'0'
         DC    (C'A')AL1(*-TRTAB)
         DC    C'abcdefghi',(C'J'-(*-TRTAB))AL1(*-TRTAB)
         DC    C'jklmnopqr',(C'S'-(*-TRTAB))AL1(*-TRTAB)
         DC    C'stuvwxyz',(256-(*-TRTAB))AL1(*-TRTAB)
There are many ways to code this translate table. (C'A')AL1(*-TRTAB) inserts text to translate a character from X'00' to X'BF' to itself, which takes care of blank and the punctuation characters. The remainder of the table I leave to the reader to interpret. Many programmers might choose this -
TRTAB    DC    256AL1(*-TRTAB)
         ORG   TRTAB+C'A'
         DC    C'abcdefghi'
         ORG   TRTAB+C'J'
         DC    C'jklmnopqr'
         ORG   TRTAB+C'S'
         DC    c'stuvwxyz'
         ORG   ,
Back to top
View user's profile Send private message

View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler All times are GMT + 6 Hours
Page 1 of 1


Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Need help with TRANSLATE() Harold Barnes CLIST & REXX 7 Thu Sep 17, 2020 8:28 am
No new posts usage of CASE in WHERE clause abdulrafi DB2 10 Wed Mar 18, 2020 4:25 pm
No new posts COBOL -DB2 SQL code to have GROUP BY ... vinu78 DB2 21 Wed Oct 23, 2019 7:00 pm
No new posts RFE: DB2 support for mixed case names. Pedro DB2 0 Tue Jul 04, 2017 1:32 am
No new posts VALIDATE NULL VALUE IN DB2 CASE STATE... useit DB2 5 Thu Feb 09, 2017 4:34 pm

Back to Top
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us