$ListSort and $ListSrt: Difference between revisions
(Automatically generated page update) |
mNo edit summary |
||
Line 2: | Line 2: | ||
<span class="pageSubtitle">$ListSort and $ListSrt : Sort $list</span> | <span class="pageSubtitle">$ListSort and $ListSrt : Sort $list</span> | ||
<p class="warning">Most Sirius $functions have been deprecated in favor of Object Oriented methods. The OO equivalent for the $ListSort and $ListSrt function is the [[Sort (Stringlist subroutine)]].</p> | <p class="warning">Most Sirius $functions have been deprecated in favor of Object Oriented methods. The OO equivalent for the $ListSort and $ListSrt function is the <var>[[Sort (Stringlist subroutine)|Sort]]</var> subroutine.</p> | ||
Each of these functions sorts a $list and builds a new $list containing the sorted data from the input $list. The difference between <var>$ListSort</var> and <var>$ListSrt</var> is that, if the input $list is empty, <var>$ListSort</var> returns an empty $list while <var>$ListSrt</var> returns a -11 error code. Because of this, it is generally recommended that <var>$ListSort</var> be used, instead of <var>$ListSrt</var>. The $list can be sorted in ascending or descending EBCDIC order for specified ranges of columns. | Each of these functions sorts a $list and builds a new $list containing the sorted data from the input $list. The difference between <var>$ListSort</var> and <var>$ListSrt</var> is that, if the input $list is empty, <var>$ListSort</var> returns an empty $list while <var>$ListSrt</var> returns a -11 error code. Because of this, it is generally recommended that <var>$ListSort</var> be used, instead of <var>$ListSrt</var>. The $list can be sorted in ascending or descending EBCDIC order for specified ranges of columns. | ||
Line 9: | Line 9: | ||
==Syntax== | ==Syntax== | ||
<p class="syntax"><span class="term">%result</span> = <span class="literal">$ListSort</span>(<span class="term">list_identifier, sort_order) | <p class="syntax"><span class="term">%result</span> = <span class="literal">$ListSort</span>(<span class="term">list_identifier</span>, <span class="term">sort_order</span>) | ||
%result = $ListSrt(list_identifier, sort_order) | <span class="term">%result</span> = <span class="literal">$ListSrt</span>(<span class="term">list_identifier</span>, <span class="term">sort_order</span>) | ||
</p> | </p> | ||
Line 20: | Line 20: | ||
<tr><th>list_identifier</th> | <tr><th>list_identifier</th> | ||
<td>The identifier of the input $list | <td>The identifier of the input $list. | ||
<tr><th>sort_order</th> | <tr><th>sort_order</th> | ||
Line 34: | Line 34: | ||
A format in the quadruplets can be one of these: | A format in the quadruplets can be one of these: | ||
<table> | <table> | ||
<tr><th>CH</th> | <tr><th><var>CH</var></th> | ||
<td>Character format. The default.</td></tr> | <td>Character format. The default.</td></tr> | ||
<tr><th>FI</th> | |||
<tr><th><var>FI</var></th> | |||
<td>Fixed point format. Must have length 1, 2, 3 or 4.</td></tr> | <td>Fixed point format. Must have length 1, 2, 3 or 4.</td></tr> | ||
<tr><th>FL</th> | |||
<tr><th><var>FL</var></th> | |||
<td>Floating point format. Must have length 4, 8 or 16.</td></tr> | <td>Floating point format. Must have length 4, 8 or 16.</td></tr> | ||
<tr><th>PD</th> | |||
<tr><th><var>PD</var></th> | |||
<td>Packed decimal format. Must have length between 1 and 16, inclusive.</td></tr> | <td>Packed decimal format. Must have length between 1 and 16, inclusive.</td></tr> | ||
<tr><th>ZD</th> | |||
<tr><th><var>ZD</var></th> | |||
<td>Zoned decimal format. Must have length between 1 and 16, inclusive. | <td>Zoned decimal format. Must have length between 1 and 16, inclusive. | ||
</td></tr></table> | </td></tr></table> | ||
Line 51: | Line 55: | ||
===$ListSort and $ListSrt error codes=== | ===$ListSort and $ListSrt error codes=== | ||
<p class="code">-3 | <p class="code">-3 — No room in CCATEMP | ||
-5 — Required argument not specified | -5 — Required argument not specified | ||
-6 — $List identifier invalid | -6 — $List identifier invalid | ||
-10 — Invalid sort order | -10 — Invalid sort order | ||
-11 — Input $list is empty ($ListSrt only) | -11 — Input $list is empty ($ListSrt only) | ||
Line 90: | Line 94: | ||
%RC = $ListImg(%LIST, %SURGERY:CODE) | %RC = $ListImg(%LIST, %SURGERY:CODE) | ||
. . . | |||
%OUTLIST = $ListSort(%LIST, 'DEPT,A COST,D') | %OUTLIST = $ListSort(%LIST, 'DEPT,A COST,D') | ||
Line 98: | Line 102: | ||
<ul> | <ul> | ||
<li>If the input $list was created by the invoked <var>$ListSort</var> or <var>$ListSrt</var> function, the input $list is not deleted if you get a -3 error code from LISTSORT or <var>$ListSrt</var>. | <li>If the input $list was created by the invoked <var>$ListSort</var> or <var>$ListSrt</var> function, the input $list is not deleted if you get a -3 error code from LISTSORT or <var>$ListSrt</var>. | ||
<li>If you are sorting 2-digit year dates, you can use a CENTSPAN of 1975 to sort the dates by appending the letter <tt>C</tt> to the third item (<tt>A</tt> or <tt>D</tt>) in the sort field specification. This could be used, for example, with output of $PRCLEX, based on the assumption that all procedures were created since 1974. However, a better approach is to use $PROC_LIST, which returns 4-digit year dates. | <li>If you are sorting 2-digit year dates, you can use a CENTSPAN of 1975 to sort the dates by appending the letter <tt>C</tt> to the third item (<tt>A</tt> or <tt>D</tt>) in the sort field specification. This could be used, for example, with output of $PRCLEX, based on the assumption that all procedures were created since 1974. However, a better approach is to use $PROC_LIST, which returns 4-digit year dates. | ||
<li>$ListSrt and <var>$ListSort</var> use any specified image item's format for comparison. For example, if the image item WEIGHT is specified as part of the sort criteria and WEIGHT is defined as a FLOAT type image item, a floating point comparison of the values will be performed. Type specific comparison is done for FLOAT, BINARY, PACKED, and ZONED image items. Generally, the type specific comparisons produce the same results as a character comparison unless the some of the values are negative. | <li>$ListSrt and <var>$ListSort</var> use any specified image item's format for comparison. For example, if the image item WEIGHT is specified as part of the sort criteria and WEIGHT is defined as a FLOAT type image item, a floating point comparison of the values will be performed. Type specific comparison is done for FLOAT, BINARY, PACKED, and ZONED image items. Generally, the type specific comparisons produce the same results as a character comparison unless the some of the values are negative. | ||
<li>$LISTSRT's and $LISTSORT's output $list identifiers are associated with the same image as their input $lists (as associated with $ListImg). | <li>$LISTSRT's and $LISTSORT's output $list identifiers are associated with the same image as their input $lists (as associated with $ListImg). | ||
</ul> | </ul> | ||
==Products authorizing $ListSort and $ListSrt== | ==Products authorizing $ListSort and $ListSrt== | ||
Line 116: | Line 122: | ||
</ul> | </ul> | ||
[[Category:$Functions|$ListSort and $ListSrt]] | [[Category:$Functions|$ListSort and $ListSrt]] |
Revision as of 14:37, 11 April 2013
$ListSort and $ListSrt : Sort $list
Most Sirius $functions have been deprecated in favor of Object Oriented methods. The OO equivalent for the $ListSort and $ListSrt function is the Sort subroutine.
Each of these functions sorts a $list and builds a new $list containing the sorted data from the input $list. The difference between $ListSort and $ListSrt is that, if the input $list is empty, $ListSort returns an empty $list while $ListSrt returns a -11 error code. Because of this, it is generally recommended that $ListSort be used, instead of $ListSrt. The $list can be sorted in ascending or descending EBCDIC order for specified ranges of columns.
The $ListSort and $ListSrt functions accept two arguments and return a numeric result.
Syntax
%result = $ListSort(list_identifier, sort_order) %result = $ListSrt(list_identifier, sort_order)
Syntax terms
%result | The identifier of the created $list, or an error code if the new $list was not created. $List identifiers are always positive integers and error codes are always negative integers. |
---|---|
list_identifier | The identifier of the input $list. |
sort_order | A string that specifies the sort order. The sort order is a character string that contains blank separated triplets and/or quadruplets.
|
Specifying the sort order
A format in the quadruplets can be one of these:
CH | Character format. The default. |
---|---|
FI | Fixed point format. Must have length 1, 2, 3 or 4. |
FL | Floating point format. Must have length 4, 8 or 16. |
PD | Packed decimal format. Must have length between 1 and 16, inclusive. |
ZD | Zoned decimal format. Must have length between 1 and 16, inclusive. |
The entities in a triplet or quadruplet must be separated by commas. For example, specifying a sort order of 1,10,A 18,4,FI,D would result in a $list being sorted in ascending order based on columns 1 through 10 and descending order based on a signed fixed point comparison of columns 18 through 21.
For $lists that have been associated with an image via $ListImg, the start column and length in any triplet and the start column, length, and format in any quadruplet can be replaced by the name of an image item in the associated image.
$ListSort and $ListSrt error codes
-3 — No room in CCATEMP -5 — Required argument not specified -6 — $List identifier invalid -10 — Invalid sort order -11 — Input $list is empty ($ListSrt only) -12 — Sort specification is too complex
Usage notes
- All invocations of a particular call to $ListSort or $ListSrt will always return the same $list identifier. Each time a call is executed, if the function is successful then any previous $list created by that call is deleted, and a new list is created. For example:
REPEAT 4 TIMES %A = $ListSort(%LIST,'1,24,D 39,255,A') END REPEAT
Would produce only one valid $list. On the other hand, the following
%A = $ListSort(%LIST,'1,24,D 39,255,A') %A = $ListSort(%LIST,'1,24,D 39,255,A')
would produce two $lists, though the identifier of the first $list would have been replaced in
%A
by the identifier of the second $list.
Example
The following is an example of using an image item name in a sort criterion:
IMAGE SURGERY PROCEDURE IS STRING LEN 16 DEPT IS STRING LEN 5 CODE IS STRING LEN 6 COST IS BINARY END IMAGE PREPARE IMAGE SURGERY %LIST = $ListNew %RC = $ListImg(%LIST, %SURGERY:CODE) . . . %OUTLIST = $ListSort(%LIST, 'DEPT,A COST,D')
Example notes:
- If the input $list was created by the invoked $ListSort or $ListSrt function, the input $list is not deleted if you get a -3 error code from LISTSORT or $ListSrt.
- If you are sorting 2-digit year dates, you can use a CENTSPAN of 1975 to sort the dates by appending the letter C to the third item (A or D) in the sort field specification. This could be used, for example, with output of $PRCLEX, based on the assumption that all procedures were created since 1974. However, a better approach is to use $PROC_LIST, which returns 4-digit year dates.
- $ListSrt and $ListSort use any specified image item's format for comparison. For example, if the image item WEIGHT is specified as part of the sort criteria and WEIGHT is defined as a FLOAT type image item, a floating point comparison of the values will be performed. Type specific comparison is done for FLOAT, BINARY, PACKED, and ZONED image items. Generally, the type specific comparisons produce the same results as a character comparison unless the some of the values are negative.
- $LISTSRT's and $LISTSORT's output $list identifiers are associated with the same image as their input $lists (as associated with $ListImg).