The TRANSLATE function in REXX and PL/1 share the same characteristics; they work the same way and they have the same parameters in the same order. Such shared qualities are rarely seen when it comes to functions like TRANSLATE. Many of you may be familiar with TRANSLATE and this tip will only deal with a tiny detail for which TRANSLATE can be used very successful.
TRANSLATE understands three parameters. The first one is the character string you wish to translate from. The second parameter states what to translate to and the third parameter states what to translate from. An example:
w, v and s from the first parameter are converted to W, V and S. All other characters remain unchanged. This is the preferred way of using TRANSLATE and the manuals are full of examples like the above. But what if you do like this:
Hey, wait a minute..., what happened here. Well precisely the same as before, but the result was quite unexpected. Using the second parameter as input you are able to shift around the placements of characters. In the above example a date in standard DB2 format is translated to a quite different format.
When you have grasped the concept of this idea the possibilities seems to explode. What about shuffling around some bytes:
Hey, something went wrong. No, thinking of it, it is OK. And you can also...