TRANSLATE stage v1.0

Pipelines v2.0

 

Purpose, Operands, Streams used, Usage notes, Examples, See also

Home

 

Syntax

 

                    _1-*_________________    _UPper_____________________________
>>__ _TRANSlate_ __|_____________________|__|___________________________________|_______>
    |_XLATE_____|  |_inputrange__________|  |__| Transtable |__| Modifytable |__|
                   |   <____________     |
                   |_(__inputrange__|__)_|
 
Transtable:
 
|__ ______________ ____________________________________________________________________><
   |  <_________  |
   |__ _UPper_ _|_|
      |_LOWer_|
 
Modifytable:
 
|__ _________________________________ __________________________________________________|
   |  <____________________________  |
   |____fromcharrange__tocharrange_|_|

 

Purpose

 

Use the XLATE stage to replace characters according to a translate table. XLATE reads records from its primary input stream, compares and replaces characters according to the translation specification, and writes the resulting records to its primary output stream. The output record has the same length as the input record.

 

If no translate table operands or modify table operands are specified; XLATE defines the translate table as the uppercase table, otherwise XLATE defines the table according to the operands. Each operand specified has a cumulative effect on the translate table; the first operand defines the table and any following operands modify the table. Then any fromcharrange and tocharrange operands modify the translate table by mapping a from character or range of characters to a to character or range of characters. If no translate table is defined, any fromcharrange and tocharrange operands modify the neutral table.

 

You can use XLATE to translate entire records or specified locations of the input data in the record. You can specify locations of the input data in terms of columns, words, or fields. By default, words and fields are defined as space-delimited character strings. Input data that is outside all specified locations; remain unchanged. When more than one input data location is specified; the contents of each location are translated in the order they are specified (left to right operand order).

 

Operands

 

    

inputrange

is an integer column, word or field range on which to operate.

 

    

Upper

specifies that lowercase alphabetic characters are converted to uppercase; uppercase letters remain unchanged. If you do not specify any operands or you specify only column ranges, characters in the input records are translated to uppercase.

 

    

LOWer

specifies that uppercase alphabetic characters are converted to lowercase; lowercase letters remain unchanged. When the uppercase translate table translates two or more characters to a particular uppercase character; when translating from uppercase to lowercase, the character with the lower value is used.

 

    

fromcharrange and tocharrange

are a pair of characters or range of characters that modify the translate table. The character or range of characters specified by fromcharrange is converted to the character or range of characters specified by tocharrange. For example; specifying A-B as fromcharrange and 1-2 as tocharrange translates A to 1 and B to 2. The order of characters in the range follows the standard collating sequence. If you specify fromcharrange and tocharrange without specifying a translate table, the neutral table (no translation at all) is in effect for the characters not specified by fromcharrange

 

If any of the characters specified in fromcharrange or tocharrange are a B, b, X, x, H, or h, you must specify the inputrange operand.

 

Streams used

 

The following streams are used by the XLATE stage:

 

Stream

Action

 

 

Primary input stream

XLATE reads records from its primary input stream.

Primary output stream

XLATE writes translated records to its primary output stream.

 

Usage notes

 

     1)

XLATE does not delay the records.

 

     2)

If the XLATE stage discovers that its primary input or primary output streams are not connected, the XLATE stage ends.

 

     3)

You can specify a character in fromcharrange more than once, however XLATE only uses the last (rightmost) translation; it ignores earlier definitions. For example:

 

**** Top of file ****
01 Address Rxpipe
02
03 ‘pipe literal /JKLMNOP/ | xlate J R K Y L Z J 1 | console
04
05 Exit 0
**** End of file ****
 
Output:
1YZMNOP

 

Here, J is specified in fromcharrange twice, but only the translation from J to 1 is performed.

 

     4)

If you specify a translation of characters where J is translated to K and K is translated to L, it does not follow that J is translated to L, as shown in the following example:

 

**** Top of file ****
01 Address Rxpipe
02 
03 ‘pipe literal /JKLMNOP/ | xlate J K K L | console’
05
05 Exit 0
**** End of file ****
 
Output:

KLLMNOP

 

Note. This is ONLY true for column ranges which do not overlap.

 

     5)

When you specify ranges that overlap one another, as in the following example, the resulting translations are cumulative:

 
**** Top of file ****
01 Address Rxpipe
02
03 ‘pipe literal /JKLMNOP/ | xlate (1-7 5-7) O P P Q | console’
04
05 Exit 0
**** End of file ****
 
Output:
JKLMNQQ

 

The first number range which specifies (1-7) translates O to P and P to Q, and the second number range (5-7) goes through the same two translations.

 

     6)

When you use the fromcharrange and tocharrange operands where tocharrange is shorter than fromcharrange, the last part of fromcharrange is translated to the last character of tocharrange. For example, the following maps A to 1, B to 2, C to 3, D to 3 and E to 3.

 

**** Top of file ****
01 Address Rxpipe
02
03 ‘pipe literal /ABCDE/ | xlate A-E 1-3 | console’
04
05 Exit 0
**** End of file ****
 
Output:
12333

 

     7)

Conversely, when fromcharrange is shorter than tocharrange, only the part of fromcharrange that tocharrange specifies is translated. For example, the following maps only F to 1 and G to 2:

 

**** Top of file ****
01 Address Rxpipe
02
03 ‘pipe literal /FGHIJ/ | xlate *-* F-G 1-5 | console’
04
05 Exit 0
**** End of file ****
 
Output:
12HIJ
 

     8)

XLATE verifies that its secondary input and output streams are not connected and then begins execution.

 

Examples

 

     1)

**** Top of file ****
01 Address Rxpipe
02 
03 ‘pipe literal /a-b-c/ | xlate wordsep /–/ word 3 | console’
04
05 Exit 0
**** End of file ****
 
Output:
a-b-C
 

     2)

**** Top of file ****
01 Address Rxpipe
02
03 ‘pipe literal /a?b?c/ | xlate (fieldsep /?/ fields 2-3) | console’
04
05 Exit 0
**** End of file ****
 
Output:
a?B?C
 

     3)

**** Top of file ****
01 Address Rxpipe
02
03 ‘pipe literal /abc def ghi jkl/ | xlate words 2-4 | console’
04
05 Exit 0
**** End of file ****
 
Output:
abc DEF GHI JKL
 

     4)

**** Top of file ****
01 Address Rxpipe
02
03 ‘pipe literal /?ab?cd??ef/ | xlate (ws /?/ word 1 word 3) | console’
04
05 Exit 0
**** End of file ****
 
Output:
?AB?cd??EF
 

     5)

**** Top of file ****
01 Address Rxpipe
02
03 ‘pipe literal /abc def ghi jkl mno/ | xlate words -3;-2 | console’
04
05 Exit 0
**** End of file ****
 
Output:
abc def GHI JKL mno
 

     6)

**** Top of file ****
01 Address Rxpipe
02
03 ‘pipe literal /BE OBSCURE CLEARLY/ | xlate (2 5.6 13-*) lower | console’
04
05 Exit 0
**** End of file ****
 
Output:
Be Obscure Clearly
 

See also

 

Reference the following link for additional information:

 

SPECS

 

History of change

 

None.