putlistitems

Copy data from a group of fields or variables into a list.

putlistitems   IndexedList, Source

putlistitems/id  AssociativeList  {, Source}

where Source can be:

  • Field
  • IdField
  • {IdField}, ValueField

putlistitems/id {/field | /component | /global}   AssociativeList

putlistitems/occ {/modonly}  AssociativeList,Entity

Example: putlistitems vItem, FLD1.ENT

Qualifiers

Qualifiers
Qualifier Description
/id Copies the content of the specified sources into an associative list. For more information, see Using /id to Build an Associative List from Fields.
/field

/component

/global

Copies the values of fields, components, or global variables (which are identified by the id part of each item in an associative list), into the corresponding value part of that item. For more information, see Updating the Value Part of Associative List Items.
/occ Copies the name and content of all fields of the specified component entity into an associative list. For more information, see Using /occ to Build an Associative List.
/modonly Loads the values from a field only if the field data has been modified.

Parameters

Parameters
Parameter Data Type Description
IndexedList

AssociativeList

String Variable or field containing an indexed or associative list
Source String Field name, entity name, or variable name containing data to be added to the list. The way that Source is interpreted depends on the qualifiers used.
Field
IdField
ValueField
String Name of a field. If the field name is unqualified (the entity and model are not specified), the current entity is used.
Entity String Name of the entity whose fields will be added to an associative list

Return Values

Values returned in $status
Value Meaning
0 No data was copied to the list
>0 Number of the items copied

Use

Allowed in all component types.

putlistitems/id/global is not allowed in self-contained Service and Report components.

Description

Use the putlistitems statement to add or replace multiple items into an indexed list of values or an associative list of ID=value pairs. For more information, see Lists and Sublists.

Used without qualifiers, putlistitems copies the contents of a field from successive occurrences of its entity into items of an indexed list. Starting with an empty IndexedList, each item is copied from the field named by Field from successive occurrences in the component of its entity.

putlistitems/id can be used to copy:

  • The contents of the fields IdField and ValueField from successive occurrences of the current entity into the ID and value parts of items in an associative list.
  • The contents of a group of fields and variables (that are identified by the ID part of items in an associative list) into the corresponding value part of that item.

putlistitems/occ can be used to copy the names and contents of the fields in the field list of the component field Entity into the ID and value parts of items in an associative list.

Copying from Successive Occurrences

When items are copied into a list from a field or pair of fields in successive occurrences of an entity, the first item of the list is copied from the current occurrence of the entity in the component and remaining items from the following occurrences of the entity in the component. The hitlist is completed, if necessary.

Note:  To ensure that the entire set of occurrences in the component is being addressed, make the first occurrence the current occurrence.

When copying data from successive occurrences, if one of the fields specified occurs in an Up entity, then the nearest outer Down entity is used to control the movement of data from occurrences. If both specified fields are Up entities, the nearest outer entity of the first field controls the movement.

Building an Indexed List

The current component contains three occurrences of the entity CALENDAR. The field DAY in these three occurrences contains 'Monday', 'Tuesday', and 'Wednesday'. The following example copies the contents of the field DAY from these occurrences into an indexed list contained in the local variable vList:

; make first occurrence of CALENDAR current
setocc "CALENDAR", 1

putlistitems vItem, DAY.CALENDAR
; vList is "Monday;Tuesday;Wednesday"

Using /id to Build an Associative List from Fields

To copy the contents of one or two fields from successive occurrences into the items of an associative list, use putlistitems/id and at least one of IdField and ValueField. The fields named by IdField and ValueField are used to build a new list in AssociativeList.

  • If both IdField and ValueField are specified, the contents of IdField, the values these fields in successive occurrences of the current entity are used to populate the ID and value parts of items in the associative list.

    For example, consider a case where there are three occurrences of entity ENT in a component. Field FLD1 in the three occurrences contains 'day1', 'day2', and 'day3', and FLD2 contains 'Mon', 'Tue', and 'Wed'. The following statements build a list that contains those IDs and values:

    setocc "ENT", 1
    putlistitems/id vList, FLD1, FLD2
    ;Result: vList is "day1=Mon;day2=Tue;day3=Wed"
  • If IdField is omitted, only the values are copied. For example, if field FLD2 in three occurrences of entity ENT in a component contains 'Mon', 'Tue', and 'Wed', the following statements build a list that contains those values:
    setocc "ENT", 1
    putlistitems/id vList,, FLD2 
    ; Result: vList is "Mon;Tue;Wed"
    Note:  This is equivalent to:
    setocc "ENT", 1
    putlistitems vList, FLD2 
    ;Result: vList is "Mon;Tue;Wed"
  • If ValueField is omitted, only the IDs are copied. For example, Field FLD1 in the three occurrences contains 'day1', 'day2', and 'day3':
    setocc "ENT", 1
    putlistitems/id vList, FLD1 
    ;Result: vList is "day1=;day2=;day3="

Updating the Value Part of Associative List Items

To update the value part of items in an associative list, you can use putlistitems/idAssociativeList with no further arguments. The value part of each item is updated from the source specified in the ID part of that item. The ID part of a list item can contain the name of a field, a component variable, a global variable, or a general variable. For example:

NAME = "Frodo"    ; field name
$CPT_TOT$ = 14    ; component variable
$$GLOB_TOT = 329  ; global variable
$1 = -8           ; general variable

vList = "NAME;$CPT_TOT$;$$GLOB_TOT;$1"
putlistitems/id vList 
;Result: vList is "NAME=Frodo;$LOC_TOT$=14;$$GLOB_TOT=329;$1=-8"

For each item in AssociativeList, if the field or variable named by the item ID cannot be found, the associated values remains unchanged.

The source is assumed to be a field if the ID part of a list item does not contain a dollar sign ($). If a name includes a dollar sign, it is treated as the variable type specified. However, if one of the source qualifier /field, /component, or /global is specified, names that do not include a dollar sign are treated as the selected source type.

For example, a field NAME, a component variable $NAME$, and a global variable $$NAME are all available, as well as a field TOTAL and a component variable $TOTAL$:

NAME = "Field"
$NAME$ = "Component"
$$NAME = "Global"
TOTAL = 987.65
$TOTAL$ = 123.45

; Initialize a list 
vList = "name;$total$"

; Update the value part of list items:
putlistitems/id vList 
;Result: vList is "NAME=Field;$TOTAL$=123.45"

; Another way to update the value part of list items
putlistitems/id/field vList 
;Result: vList is "NAME=Field;$TOTAL$=123.45"

; Update associative list items from component variables
putlistitems/id/component vList 
;Result: vList is "NAME=Component;$TOTAL$=123.45"

; Update associative list items from global variables
putlistitems/id/global vList 
;Result: vList is "NAME=Global;$TOTAL$=123.45"

Note:  Although it is usually good practice to include the dollar signs ($) that form part of the variable name in each list item’s value, these must be omitted to take advantage of the power of the source switches.

Because the list argument is evaluated at runtime, you should consider the following points when you create the component:

  • The existence of the referenced objects (fields and variables) cannot be verified by the compiler
  • Any referenced fields cannot be included in an Automatic field list

Be sure that all the fields that will be referenced are included in the entity's field list and that all the component and global variables are defined.

Using /occ to Build an Associative List

To build an associative list that contains the names and contents of all fields in the field list of Entity in the current component, use putlistitems/occ.

For example, if the component entity WEEK contains three fields (DAY1, DAY2, and DAY3), the name of the field is mapped to the ID part of item and field data is mapped to the value part of the list Item:

DAY1.WEEK = "Mon"
DAY2.WEEK = "Tue"
DAY3.WEEK = "Wed"
putlistitems/occ vList,"WEEK"
; Result: vList is "day1=Mon;day2=Tue;day3=Wed"

If the /modonly switch is also used, the values will only be loaded from a field if the field data has been modified (that is, if $fieldmod=1). Field IDs from fields that have not been modified are removed from the list.

Using putlistitems

In the examples, the underlined semicolon ( ;) represents the Uniface subfield separator.

Building an Associative List from a Pair of Fields

The current component contains three occurrences of the entity CALENDAR. The field NUM in these three occurrences contains 'd1', 'd2', and 'd3', while the field NAME contains 'Mon', 'Tue', and 'Wed'. The following example copies those values into an associative list contained in the component variable $LIST$:

; make first occurrence current
setocc "CALENDAR", 1

putlistitems/id vList, NUM.CALENDAR, NAME.CALENDAR
; Result: vList is "d1=Mon;d2=Tue;d3=Wed"

Filling an Associative List from Fields in the Current Occurrence

For each item in an associative list, the following example copies the value part of the item from the field (in the current entity) identified by the ID part of the item:

day1 = "Sun"
day2 = "Tue"
day3 = "Wed"

vList = "day1;day2;day3"
putlistitems/id/field vList
; vList is "day1=Sun;day2=Tue;day3=Wed"

Filling an Associative List from Fields and Variables

For each item in an associative list, the following example copies the value part of the item from the source identified by the ID part. The type of the source (that is, whether it is a field, component variable, or global variable) is derived from the Id part of the item.

day1 = "Mon"
$day2$ = "Fri"
$$day3 = "Wed"
$9="Thu"

vList = "day1;$day2$;$$day3;$9"
putlistitems/id vList
; vList is "day1=Mon;$day2$=Fri;$$day3=Wed;$9=Thu"

Filling an Associative List from Component Variables

For each item in an associative list, the following example copies the value part of the item from the component variable identified by the ID part of the item:

$day1$ = "Sun"
$day2$ = "Tue"
$day3$ = "Wed"

vList = "day1;$day2;day3"
putlistitems/id/component vList
; $LIST$ is "day1=Sun;day2=Tue;day3=Wed"

Copying Fields from One Occurrence to Another

The following example copies the fields from the first occurrence of MYENT to a new occurrence. You can use this technique to create a copy corresponding feature in your ProcScript.

; make first occurrence current
setocc "MYENT", 1

; put field values into the list
putlistitems/occ vList, "MYENT"

; create new occurrence
creocc "MYENT", -1

; put values into fields of new occ
getlistitems/occ vList, "MYENT"

Related Topics