AMT Help Files

REPLACE with Sort

Syntax

Command
Mandatory parameter
Optional parameter
Mandatory keyword
Optional keyword

REPLACE (<Destination>, <Sort order>, <Source>)

Description

Divides the destination value up in chunks of the size of the source value. Then includes the source value itself in the chunks and sorts all these chunks in the sort order specified. The chunks are then concatenated and written back the destination variable. In case of a fixed length alpha variable the result is truncated to fit the length of the variable.

Diagram

Returned value type

None

Parameters

Parameter Description
<Destination>
The variable to be manipulated
<Sort order>
SORTA for ascending or SORTD for descending.
<Source>
Expression giving an alpha value to move into the destination variable.

Remarks

It is assumed that the destination value is already sorted before using the replace on it. If the destination has not been sorted correctly, the result is unpredictable.

When the source is an alpha variable the exact length of the variable will be used, not the length of the contents of the variable.

When the source is a single copy function then the length specified in the copy function will be used as the length of the source.

Examples


sa-6 := 'ABCGHI'
src  := 'DEF'
replace (sa-6sortasrc)
sme ('sa-6 sorted asc is: ' + sa-6)
// sa-6 will be 'ABCDEF'

sa-6 := 'IHGCBA'
src  := 'FED'
replace (sa-6sortdsrc)
sme ('sa-6 sorted desc is: ' + sa-6)
// sa-6 will be 'IHGFED'

sa-8 := 'ABCGHI'
src  := 'DEF'
replace (sa-8sortasrc)
sme ('sa-8 sorted asc is: ' + sa-8)
// sa-8 will be 'ABCDEFGH'

sa-8 := 'IHGCBA'
src  := 'FED'
replace (sa-8sortdsrc)
sme ('sa-8 sorted desc is: ' + sa-8)
// sa-8 will be 'IHGFEDCB'
    
str := 'ABCGHI'
src := 'DEF'
replace (strsortasrc)
sme ('str sorted asc is: ' + str)
// str will be 'ABCDEFGHI'

str := 'IHGCBA'
src := 'FED'
replace (strsortdsrc)
sme ('str sorted desc is: ' + str)
// str will be 'IHGFEDCBA'