$ListRepI: Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
(No difference)

Revision as of 01:28, 19 October 2012

Replace $list item with an image

Most Sirius $functions have been deprecated in favor of Object Oriented methods. The OO equivalent for the $ListRepI function is the ReplaceImage (Stringlist function).

This function replaces a $list item with the contents of an image. Generally, this $list would have been created with the $ListNew function.

The $ListRepI 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 the image is to replace. This is a required argument.

The third argument can either be a string containing the name of an image or any image item from the required image. This is an optional argument if an image has been associated with the $list with a $ListImg function. Otherwise, it is a required argument.

The fourth argument is a number that indicates the length of the $list item after the replacement. 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 image, the image is padded on the right with blanks. If this value is shorter than the length of the image, the image is truncated. If this argument is not specified, the new length of the $list item is the length of the replacement image.

Syntax

<section begin="syntax" /> [%RESULT =] $ListRepI(list_id, item_num, image_id, length) <section end="syntax" />

$ListRepI Function

%RESULT is set to 0 if the new item length is the same as the replaced item length, 1 if it is shorter, 2 if it is longer, or a negative number if an error has occurred.

-3 - No room to add item (if LISTFC $SirParm parameter not set) All other errors cause request cancellation

$ListRepI Error Codes

The following example demonstrates how $ListRepI can be used to maintain the last copy of an image for a particular ID in a $list.

IMAGE CUST SSN IS STRING LEN 10 NAME IS STRING LEN 20 BDATE IS STRING LEN 8 END IMAGE . . . . %LIST = $ListNew REPEAT FOREVER READ IMAGE CUST IF $STATUS THEN LOOP END END IF %N = $ListLoc(%LIST, ,%CUST:SSN, 'SSN') IF %N LT 0 THEN %RC = $ListAddI(%LIST, 'CUST') ELSE %RC = $ListRepI(%LIST, %N, 'CUST') END IF END REPEAT

The above example can be made more efficient by coding the $ListRepI as follows.

%RC = $ListRepI(%LIST, %CUST:NAME)

The specific image item is irrelevant in this call but is more efficient than specifying the image name in quotes because in the first example, the image name must be hashed and looked up (in NTBL) in each invocation of $ListRepI while in the second example, the hashing of the image name and lookup happens only once; at compile time.

An even neater and equally efficient way of coding this would be

%RC = $ListImg(%LIST, %CUST:BDATE) REPEAT FOREVER . . . IF %N LT 0 THEN %RC = $ListAddI(%LIST) ELSE %RC = $ListRepI(%LIST, %N) END IF

In this last example, $ListImg associates the image with the $list, eliminating the need to specify the image name on the $ListRepI. This association is also useful in many other function calls in that it provides a structure to be associated with the $list that is useful for column oriented functions such as $ListLoc and $ListSrt.

$ListRepI 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 $ListRepI 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 make this possible. Because of this, heavy use of $LISREPIs that increase $list item size (and $ListIns and $ListRem) can result in "sparse". $lists, which places an unnecessary burden on the buffer pool and CCATEMP. It can also result in an inability to add an item to the end of the $list (via $ListAdd) because of a full pointer page, even though the $list is nowhere near the theoretical capacity for a $list. $List compression can be done using the $List_Copy_Items function.

Products authorizing $ListRepI