$ListRep: Difference between revisions
mNo edit summary |
m (1 revision) |
(No difference)
|
Revision as of 21:21, 22 November 2011
Replace a $list item with a string
Most Sirius $functions have been deprecated in favor of Object Oriented methods. The OO equivalent for the $ListRep function is the Replace (Stringlist function).
This function replaces an existing $list item with a string. Generally, this $list would have been created with the $ListNew function.
The $ListRep function accepts four arguments and returns a numeric result. It is a callable $function (see Calling Sirius Mods $functions).
The first argument is a $list identifier. This is a required argument.
The second argument is the item number which is to be replaced. This is a required argument.
The third argument is a string that is to replace the $list item indicated by the second argument. This is a required argument.
The fourth argument is a number that indicates the length of the new $list item. This is an optional argument. Its minimum valid value is 0 and the maximum is 6124 under Sirius Mods Version 6.2 and later, and 4096 before. If this value is longer than the length of the third argument, the third argument is padded on the right with blanks. If this value is shorter than the length of the third argument, the third argument is truncated. If this argument is not specified, the new length of the $list item is the length of the replacement string.
Syntax
<section begin="syntax" /> [%RESULT =] $ListRep(list_id, item_num, string, length) <section end="syntax" />
-3 - No room to add item (if LISTFC $SirParm parameter not set) All other errors cause request cancellation
The following code illustrates how $ListRep might be used to insert a number of blanks in front of a range of $list items, say to do indentation.
%BLANKS = $PAD(, ' ', %INDENT) FOR %I FROM %START TO %END %DATA = $ListInf(%LIST, %I) %DATA = %BLANKS WITH %DATA %RC = $ListRep(%LIST, %I, %DATA) END FOR
The length (fourth) argument makes it possible to create $list items that are longer than 255 bytes. This can be most easily accomplished in conjuction with the $ListOvl function. In the following example, several field values are placed into a $LIST item with a length of 512.
FIND1: FIND ALL RECORDS FOR WHICH NAME = SONDHEIM END FIND FOR EACH RECORD IN FIND1 %RC = $ListRep(%LIST, %NUM, SSN, 512) %RC = $ListOvl(%LIST, %NUM, 10, LNAM) %RC = $ListOvl(%LIST, %NUM, 50, FNAM) %RC = $ListOvl(%LIST, %NUM, 90, MNAM) %RC = $ListOvl(%LIST, %NUM, 110, ADD1) %RC = $ListOvl(%LIST, %NUM, 170, ADD2) %RC = $ListOvl(%LIST, %NUM, 230, ADD3) %RC = $ListOvl(%LIST, %NUM, 290, CITY) %RC = $ListOvl(%LIST, %NUM, 310, ST) END FOR
$ListRep is extremely efficient if the $list item size is not being changed (return value for $ListRep of 0), fairly efficient when a $list item is being replaced with a shorter string (return value of 1) and can be fairly expensive when a $list item is being replaced with a longer string (return value of 2). The latter case can be expensive because such a $ListRep can result in the splitting of a $list leaf page. Once a leaf page is split, it will not be merged back together, even if subsequent $ListRems makes this possible. Because of this, heavy use of $ListReps that increase $list item size (and $ListIns and $ListRem) can result in "sparse" $lists which place an unnecessary burden on the buffer pool and CCATEMP. $List compression can be done using the $List_Copy_Items function.