$Field_ListI

From m204wiki
Revision as of 21:21, 22 November 2011 by Dme (talk | contribs)
Jump to navigation Jump to search

Return field values into a $list mapped to an image

Most Sirius $functions have been deprecated in favor of Object Oriented methods. The OO equivalent for $Field_ListI is the Stringlist AppendFieldImages function

This function retrieves fields in repeating groups into $list items mapped to an IMAGE. It provides an alternative to PAI INTO.

The $Field_ListI function accepts six arguments and returns a number indicating the success of the function.

Syntax

<section begin="syntax" /> %RC = $Field_ListI(olist, image_id, start, num, options, - null_value) <section end="syntax" />

$Field_ListI Function

%RC is the number of items added to olist.

  • The first argument is the output $list identifier or a -1. If the output $list is not empty, data is added to the end of the output $list. If -1 is specified, the record is scanned as if data would be added to the $list, but no data is actually added. This can be useful for validating the integrity of or number of occurrences of a repeating group without actually loading its values. This is a required argument.
  • The second argument must be a string containing the name of an image and, optionally an item in the image separated from the image name with a colon. The image and optional item name can be separated with a blank from an optional fieldname prefix. If an image item name is specified, that item will be set to the occurrence number retrieved. If this parameter is not specified, or is null, or is simply a colon followed by an image item name, the image bound to the output $list via $ListImg is used as the mapping image. The specified image must have been defined with the NAMESAVE option. Also, the image is not allowed to have arrays, cannot have more than 255 items, and cannot be more than the maximum length of $list items (6124 bytes long in Sirius Mods Version 6.2 and later, and 4096 bytes long before). The names of the image items in the specified image are mapped to fields in the current record context and then the values of those fields are moved into the image.
  • The third argument is the first occurrence number of the repeating group to return. This is an optional argument, and it defaults to 1, meaning that the first ocurrence of the repeating group will be returned.
  • The fourth argument is the maximum number of occurrences of the repeating group to return. This is an optional argument, and it defaults to 0, meaning that all occurrences of the repeating group, including and after the one specified by argument three, will be returned.
  • The fifth argument is a set of blank-delimited options to affect $LIST_FIELDI processing. The only valid options are:
    MissCan Cancel the request if not all image items map to field names. If an occurrence count item is specified in the second argument, that item does not have to map to a field name (if it does the field value will not be retrieved anyway). This is the default.
    NoMissCan Don't cancel the request if not all image items map to field names. Specify NoMissCan if there are image items in the image that are not associated with fields.
    PartCan Cancel the request if not all image items that map to fields return the same number of occurrences. This is the default.
    NoPartCan Don't cancel the request if not all image items that map to fields return the same number of occurrences. If NoPartCan is set and some image items that map to field occurrences return different numbers of occurrences, the return code from $Field_ListI will be the negative of the number of occurrences returned minus 100. For example, if a partial group is found but 55 occurrences were returned, the return code would be set to -155.

    In group context, the MissCan/NoMissCan setting applies based on whether the fields are defined in the group, that is, in any file in the group. If some fields that map to image items are not found in all files in group context, NoPartCan must be specified if any fields are to be retrieved.

  • The sixth argument is a value to be converted to null when populating the target $list. This argument is only available in Sirius Mods Version 6.3 and later, and it is discussed at the end of this section.

>= 0 - Number of repeating group occurrences extracted -3 - CCATEMP full < -100 - Negative number of repeating group occurrences extracted minus 100 when partial groups found All other errors result in request cancellation

The template image must be PREPARE'd at the time of the $Field_ListI call. If the NoPartCan or NoMissCan option is specified, the contents of the parts of the $list that are associated with image items that are not set from fields will be whatever they are in the actual image at the time of the $Field_ListI call. The actual contents of the template image are not modified by the $Field_ListI call.

Except in rare cases, NoPartCan is probably a bad idea since it suggests that the fields being extracted are not really a repeating group and so shouldn't be grouped. One case where NoPartCan might be useful is in validating the integrity of repeating groups, that is, making sure that all fields in the group have the same number of occurrences. The most efficient way to do this is to set the output $list identifier to -1, specify the NoPartCan parameter, and then check for a negative return code from $Field_ListI.

If -1 is specified for the output $list identifier, no data movement or validation is performed, which means that if the same operation is performed with a valid output $list identifier, a VARIABLE TOO SMALL FOR RESULT or some other image assignment type error might occur, even if the call with a -1 $list identifier produced no such errors.


In the following example, a repeating group with 3 fields is extracted into a $list:

IMAGE CHILD NAMESAVE LNAME IS STRING LEN 16 FNAME IS STRING LEN 16 SSN IS PACKED LEN 5 END IMAGE . . . . %OLIST = $ListNew PREPARE IMAGE CHILD IN GROUP FAMILIES FRN %RECNO %RC = $Field_ListI(%OLIST, 'CHILD') END FOR


$ListInfI could then be used to extract the individual occurrences of the repeating group into the image. And in the following example the occurrence number is placed into the $list at the position of image item NUMBER in each $list item:

IMAGE CHILD NAMESAVE LNAME IS STRING LEN 16 FNAME IS STRING LEN 16 SSN IS PACKED LEN 5 NUMBER IS BINARY LEN 4 END IMAGE . . . . %OLIST = $ListNew PREPARE IMAGE CHILD IN GROUP FAMILIES FRN %RECNO %RC = $Field_ListI(%OLIST, 'CHILD:NUMBER') END FOR

$Field_ListI behaves much as if each individual field value were assigned individually to its corresponding image item. This means that assignments of non-numeric field values to a numeric target image item cause the target item to be set to 0. It also means that in certain cases a "M204.0552: VARIABLE TOO SMALL FOR RESULT" might be issued.

If the image name and possibly the occurrence number item are specified as literals or static variables the mapping of image item names to field names is performed at compile-time and so can be considerably more efficient at evaluation time than a $Field_ListI call with a variable image name. Unfortunately, since the binding of an image to a $list is done at evaluation time there is no way to take advantage of compile-time image item to field mapping when using this binding with $Field_ListI.

Under Sirius Mods Version 6.3 and later the second argument to $Field_ListI can have a blank after the image name (and optional occurrence item name) followed by a prefix to be prepended to each image item name in generating field names. For example, before Sirius Mods Version 6.3, if a file had fields in a repeating group called ORDERDATA.PRODID, ORDERDATA.QUANTITY and ORDERDATA.PRICE an image definition used with $Field_ListI would need to look something like

IMAGE ORDERINFO ORDERDATA.PRODID IS STRING LEN 8 ORDERDATA.QUANTITY IS BINARY LEN 4 ORDERDATA.PRICE IS BINARY LEN 4 END IMAGE

so you could do

%RC = $Field_ListI(%OLIST, 'ORDERINFO')

which means you'd have "ugly" looking image item names like %ORDERINFO:ORDERDATA.PRODID. By specifying a prefix in the $Field_ListI call

%RC = $Field_ListI(%OLIST, 'ORDERINFO ORDERDATA.')

the image definition could be simplified to

IMAGE ORDERINFO PRODID IS STRING LEN 8 QUANTITY IS BINARY LEN 4 PRICE IS BINARY LEN 4 END IMAGE

so that the image item references like %ORDERINFO:PRODID are much "nicer".

Under Sirius Mods Version 6.3 and later, $Field_ListI has argument 6 which indicates a special value to be treated as a null when populating the target $list. This is useful because storing nulls in fields is problematic on many fronts in Model 204 so most sites have a special value that acts as a placeholder for a null. Without the sixth argument to $FIELD_LISTI, an application would have to go through the $list items to find these placeholder values and convert them to real nulls. Obviously, this is tedious, error-prone and can be CPU intensive.

By specifying the null_value argument to $FIELD_LISTI, this function will automatically convert the null placeholder to a real null. For example, if the string "_NULL_" is used to indicate a null value in a file, the following will convert all values of "_NULL_" to a null before populating the target $list.

%RC = $Field_ListI(%OLIST, 'ORDERINFO', , , , '_NULL_')

$Field_ListI is only available in Version 6.2 and later of the Sirius Mods.

Starting with Version 7.1, the options argument can be specified in any combination of uppercase and lowercase letters; prior to that, it must be specified in all uppercase letters.