REVERSE

Start of changeThe REVERSE function returns a character value of the same length as the argument, whose characters are the same as those specified in the argument except that they are in reverse order. For arguments of type national, character positions are reversed; UTF-16 characters that are surrogate pairs are treated as one character and UTF-16 characters that are not surrogate pairs are treated as one character.End of change

The function type depends on the type of the argument, as follows:

Argument type Function type
Alphabetic Alphanumeric
Alphanumeric Alphanumeric
National National

Format

Read syntax diagramSkip visual syntax diagramFUNCTION REVERSE(argument-1 )
argument-1
Must be class alphabetic, alphanumeric, or national and must be at least one character in length. Start of changeargument-1 must contain valid UTF-8 or UTF-16 encoded characters:End of changeStart of change
  • If argument-1 is of class alphabetic or alphanumeric, it must contain valid UTF-8 data.
  • If argument-1 is of class national, it must contain valid UTF-16 data.
End of change

The returned value is a character string of the same length as argument-1, with the characters of argument-1 in reversed order. For example, if argument-1 contains ABC, the returned value is CBA.

Start of change

Example 1

If argument-1 is an alphanumeric data item that contains the UTF-8 value x'4BC3A4666572' ('Käfer'), the returned value is x'726566C3A44B' ('refäK').

End of change
Start of change

Example 2

If argument-1 is a national data item that contains the UTF-16 value x'0054 00F6 D847DDF3 0062 0075 0072 D858DC6B 0073' ('Tö𡷳ber𦁫s'), the returned value is x'0073 D858DC6B 0072 0075 0062 D847DDF3 00F6 0054' ('s𦁫reb𡷳öT').

End of change
Start of change

Example 3

If argument-1 is a UTF-8 encoded item and the UTF-8 argument contains composed characters, the combining characters are counted individually. For example, when encoded in UTF-8, the Unicode character ä can be x'C3A4' or x'61CC88'. With either of the UTF-8 characters in argument-1, the returned values of the REVERSE function are different. See the following table for details.

Table 1. REVERSE function of character Kä
Character Unicode encoding UTF-8 encoding Returned values of the REVERSE function
U+004B + U+00E4
(precomposed form,
latin capital letter K + latin small letter a with diaeresis)
x'4BC3A4' () x’C3A44B’ (äK)
U+004B + U+0061 + U+0308
(canonical decomposition,
latin capital letter K + latin small letter a + combining diaeresis)
x'4B61CC88' () x’CC88614B’ (äK)
End of change