$Field ListI: Difference between revisions
m (→Usage notes: wordsmithing for image_id prefix) |
m (minor wordsmithing) |
||
Line 4: | Line 4: | ||
<p class="warn"><b>Note:</b> Many $functions have been deprecated in favor of Object Oriented methods. The OO equivalent for <var>$Field_ListI</var> is the <var>Stringlist</var> <var>[[AppendFieldImages (Stringlist function)|AppendFieldImages]]</var> function. </p> | <p class="warn"><b>Note:</b> Many $functions have been deprecated in favor of Object Oriented methods. The OO equivalent for <var>$Field_ListI</var> is the <var>Stringlist</var> <var>[[AppendFieldImages (Stringlist function)|AppendFieldImages]]</var> function. </p> | ||
This $function retrieves fields | This $function retrieves fields from field groups into [[$lists|$list]] items, according to the mapping specified in a <var class="product">SOUL</var> [[Images|image]]. The image describes where the fields are positioned in each $list item. <var>$Field_ListI</var> provides an alternative to <var>[[Record loops#paiInto|PAI Into]]</var>. | ||
The <var>$Field_ListI</var> function accepts six arguments, and it returns a number indicating the success of the function. | The <var>$Field_ListI</var> function accepts six arguments, and it returns a number indicating the success of the function. | ||
Line 52: | Line 52: | ||
If <var class="term">image_id</var> 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 <var>[[$ListImg]]</var> is used as the mapping image. The specified image must have been defined with the <var>[[Images#Syntax|Namesave]]</var> 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). </p> | If <var class="term">image_id</var> 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 <var>[[$ListImg]]</var> is used as the mapping image. The specified image must have been defined with the <var>[[Images#Syntax|Namesave]]</var> 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). </p> | ||
<p> | <p> | ||
The names of the image items in the specified image must be exactly the same as the | The names of the image items in the specified image must be exactly the same as the names of the fields in the field group that are being retrieved in the current record context. The values of those fields are then moved into the $list, as mapped by the image; nothing is moved into the image. </p></td></tr> | ||
<tr><th>start</th> | <tr><th>start</th> | ||
<td>The number of the | <td>The number of the field group occurrence to return. This is an optional argument, and it defaults to 1, meaning that the first occurrence of the field group will be returned. </td></tr> | ||
<tr><th>num</th> | <tr><th>num</th> | ||
<td>The maximum number of occurrences of the | <td>The maximum number of occurrences of the field group to return. This is an optional argument, and it defaults to 0, meaning that all occurrences of the field group, including and after the one specified by the <var class="term">start</var> argument, are to be returned. </td></tr> | ||
<tr><th>options</th> | <tr><th>options</th> | ||
Line 81: | Line 81: | ||
<tr><th>null_value</th> | <tr><th>null_value</th> | ||
<td>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 <var class="product">Model 204</var>, so most sites have a special value that acts as a placeholder for a null. Without the <var class="term">null_value</var> argument, 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. | <td>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 <var class="product">Model 204</var>, so most sites have a special value that acts as a placeholder for a null. Without the <var class="term">null_value</var> argument, 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. | ||
<p> | <p> | ||
By specifying the <var class="term">null_value</var> argument to <var>$Field_ListI</var>, this function | By specifying the <var class="term">null_value</var> argument to <var>$Field_ListI</var>, this function automatically converts the null placeholder to a real null. For example, if the string <code>_NULL_</code> is used to indicate a null value in a file, the following statement converts all values of <code>_NULL_</code> to a null before populating the target $list: </p> | ||
<p class="code">%rc = $Field_ListI(%olist, 'ORDERINFO', , , , '_NULL_') | <p class="code">%rc = $Field_ListI(%olist, 'ORDERINFO', , , , '_NULL_') | ||
</p></td></tr> | </p></td></tr> |
Revision as of 21:41, 12 June 2018
Return field values into a $list mapped to an image
Note: Many $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 from field groups into $list items, according to the mapping specified in a SOUL image. The image describes where the fields are positioned in each $list item. $Field_ListI provides an alternative to PAI Into.
The $Field_ListI function accepts six arguments, and it returns a number indicating the success of the function.
Syntax
%rc = $Field_ListI(olist, [image_id], [start], [num], [options], [null_value])
Syntax terms
%rc | The number of items added to olist, or a status code:
| ||||||||
---|---|---|---|---|---|---|---|---|---|
olist | This required argument is either the output $list identifier or -1. If the output $list is not empty, data is added to the end of it.
If -1 is specified, the record is scanned as if data is to 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. | ||||||||
image_id | The name, or a reference to the name, of the mapping image. This can be a quoted string, a %variable, an image-item name, or even a Model 204 field name. For example:
%rc = $Field_ListI(%olist, 'ORDERINFO', , , , '_NULL_') Or: %var = 'ORDERINFO' %rc = $Field_ListI(%olist, %var, , , , '_NULL_') If you specify an image name followed by a colon followed by the name of an item in the image, then that item, mapped in the $list, gets set to the occurrence number retrieved. For example: %rc = $Field_ListI(%olist, 'ORDERINFO:PRICE', , , , '_NULL_') The image and optional item name can be separated with a blank from an optional fieldname prefix to simplify field name references in the field group. See the example below in Usage notes. If image_id 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). The names of the image items in the specified image must be exactly the same as the names of the fields in the field group that are being retrieved in the current record context. The values of those fields are then moved into the $list, as mapped by the image; nothing is moved into the image. | ||||||||
start | The number of the field group occurrence to return. This is an optional argument, and it defaults to 1, meaning that the first occurrence of the field group will be returned. | ||||||||
num | The maximum number of occurrences of the field group to return. This is an optional argument, and it defaults to 0, meaning that all occurrences of the field group, including and after the one specified by the start argument, are to be returned. | ||||||||
options | A set of blank-delimited options to affect $List_FieldI processing. The valid options are shown below. They can be specified in any combination of uppercase and lowercase letters.
| ||||||||
null_value | 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 null_value argument, 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 automatically converts the null placeholder to a real null. For example, if the string %rc = $Field_ListI(%olist, 'ORDERINFO', , , , '_NULL_') |
Usage notes
- You must Prepare the template image 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. - $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.
- The second argument to $Field_ListI can have a blank after the image name followed by a prefix term. This prefix will be implicitly prepended to each image item name to identify the field-group fields whose values are to be extracted to the $list.
For example, for a file that has fields in a field group called
ORDERDATA.PRODID
,ORDERDATA.QUANTITY
andORDERDATA.PRICE
, the definition of an image to be used with $Field_ListI might validly be:IMAGE ORDERINFO ORDERDATA.PRODID IS STRING LEN 8 ORDERDATA.QUANTITY IS BINARY LEN 4 ORDERDATA.PRICE IS BINARY LEN 4 END IMAGE
And you might validly use this $Field_ListI call:
%rc = $Field_ListI(%olist, 'ORDERINFO')
However, the result of these specifications is lengthy image-item names, like
%ORDERINFO:ORDERDATA.PRODID
.But if instead you specify a prefix in the $Field_ListI call:
%rd = $Field_ListI(%olist, 'ORDERINFO ORDERDATA.')
The image definition can be trimmed to:
IMAGE ORDERINFO PRODID IS STRING LEN 8 QUANTITY IS BINARY LEN 4 PRICE IS BINARY LEN 4 END IMAGE
And the resulting image-item references are simplified; for example,
%ORDERINFO:PRODID
.
Examples
- In the following example, a repeating group with three 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.
- 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