Using
Lists for Retrieve Profiles
The Problem:
The customisation of retrieve
profiles is used throughout UNIFACE development to retrieve specific
occurrences into an entity. When the occurrences to be retrieved are
related by the value of one or more particular fields, constructing
the profile is fairly straight forward. Indeed with the use of
logical and relational operators (& | != <= etc.) the
majority of specific retrievals are catered for. However, when the
occurrences to be retrieved are unrelated the use of operators will
sometimes not cover all requirements.
We are going to look at an example where the
user from one form selects a random selection of occurrences which
are then required to be retrieved in another form. From the first selection
form we shall build a list of primary key values with
putlistitems and use this list to retrieve the same occurrences in
another form.
The Solution:
When it is known which
occurrences are to be retrieved, there are a number of possible ways
to ensure that they appear in a particular form.
You might use a discard to remove those
occurrences that are not required to appear in the form, or, you may
build up a retrieve profile that makes use of the logical OR
operator to include only those that are needed.
In fact, however, a list of values, each
separated by <GOLD> ; (;) can be used as the retrieve
profile. The ; behaves just like an OR operator in a retrieve
profile.
Example:
A. The Selection
Form
From this screen a list of names is
displayed for the user to select those that are to be maintained by
checking the checkbox featured on the right-hand side. Once selected
the maintain button is pressed to open a maintenance form containing
the chosen. In following good practice we will generate a list of
primary key values (ID) for those names that have been selected
without completing any more of the hitlist. The following code is
used:
<WRITE> of Entity
; The write command is removed
from the main entity
; and since this only a selection screen and has no repercussions
; write
<DETAIL> for Maintain Button
; This will remove those items
that have not appeared in the hitlist as yet
; and thus have not been selected. No write to the database will
occur following
; the removal of the write command from the <WRIT> trigger
store/e/truncate 'PEOPLE'
; Only those items in the already retrieved hitlist are kept and
sorted so the
; selected items appear at the end of the list
sort 'PEOPLE', "SELECTED"
; We then find the first item occurrence that is selected
while ($status > 0 & SELECTED.PEOPLE != 'T')
setocc 'PEOPLE', $curocc(PEOPLE) + 1
endwhile
; Using putlistitems will copy the primary key from successive
occurrences to a list
putlistitems $$THE_CHOSEN, ID.PEOPLE
; call the maintenance form or another operation.
activate "MPEOPLE"
end ; <DTLF>
The list ($$THE_CHOSEN)
will now look something like this once the script is executed 5;8;9;12;14.
B. The Maintenance
Form
<EXECUTE> for form
; set up the retrieve profile
by simply using the list as the primary key value
ID.PEOPLE/init = $$THE_CHOSEN
retrieve
edit
Only those items that were selected
from the previous form will be retrieved into this one.
Notes:
The list of primary keys in the
retrieve profile can be used in conjunction with other items in the
retrieve profile, for example, if we also set DRIVING_LICENSE = ‘T’
we would only retrieve those people who had both been selected and
hold a licence. (Note that if there is one item in the list it would
invoke an exact match on the key value and retrieve that occurrence
only without any regard to the remainder of the contents of the
retrieve profile).
The use of lists in profiles can be used in
any fields in an entity, not just the primary key.
As far as we can tell this is not a documented
feature of UNIFACE but works in version 6 as well as version 7.
|