# WORDSORT

## Syntax:

    WORDSORT(string[,diropt])

## Arguments:

string
  the character string that contains the blank-delimited words to be sorted. The string may contain any number of words, and the words may be of any size (up to the limits of the machine). The words may contain any EBCDIC characters, including those in the unprintable range.
diropt
  the direction option. This string specifies direction of the sort. The valid values are:
  A
    the words are to be sorted in ascending collating sequence. (e.g., a b c d...) This is the default.
  D
    the words are to be sorted in descending collating sequence. (e.g., ...d c b a)

## Module Name:

SWXWSORT

## Service Description:

The WORDSORT function is used to sort the blank-delimited words of a string into either ascending or descending collating sequence.

Notes:

1. The standard EBCDIC collating sequence is used for both ascending and descending sorts.
2. WORDSORT performs only character sorts. It does not recognize special data types such as packed decimal or floating point.
3. If string is null, the returned string will also be null. No sorting can be performed.
4. If string contains one or zero blank-delimited words, the returned string is an identical copy of string. No sorting can be performed.
5. If string contains 2 or more blank-delimited words, the sort is performed. The returned string will contain the sorted words with one blank between each word.

## Returned Information:

The WORDSORT function returns the sorted string. If you CALL the WORDSORT function, the returned value is contained in the RESULT special variable. The RC special variable is unchanged.

## Examples:

1. Call the WORDSORT function to sort the blank-delimited words, contained in NAMES, into ascending sequence:

       Names = 'zelnik  yong xillery wilder'
       Names = wordsort(Names)
       /* Names = 'wilder xillary yong zelnik' */

   Diropt is not coded in this example because the desired order, ascending, is the default value for this argument.

© Copyright 1998 by Open Software Technologies, Inc.