| Sets in 4D V6 | |
| By Raymond E. Manley, ACI Technical Support | |
| Technical Note 97-37 |
Technical Notes for 97-10-October 1997
Introduction
Sets are an excellent way to maintain a compact representation of record selections in memory. They also enable extremely fast logical operations between selections. This technical note discusses the powerful new way sets are created and maintained in 4th Dimension version 6 and addresses any compatibility issues that might arise with routines created in version 3 databases.
Types of Sets
There are two types of sets in version 3:
Process set: a set that can only be accessed by the process in which it was created. Process sets do not require any special prefix to identify them as such.
Interprocess set: a set shared among all processes. Interprocess sets are identified by the preceding "<>" (less than followed by greater than symbol) or by the diamond symbol "<>" (Macintosh only; created by Option-Shift-V on a US keyboard).
Version 6 introduces a new type of set:
Local set: a set created and maintained in memory locally on the client, not the server. A Local/Client set is identified by a dollar sign "$" preceding its name.
Additionally, 4th Dimension creates and maintains two system sets named "LockedSet" and "UserSet". In version 3, both of these are process sets.
The LockedSet is useful in a multi-process environment and contains a reference to records that were locked during the execution of the following commands: APPLY TO SELECTION, ARRAY TO SELECTION and DELETE SELECTION.
The UserSet contains a reference to each of the currently highlighted (user selected) records. This provides easy access to the selection made by a user while in a form (layout) displayed with MODIFY SELECTION or DISPLAY SELECTION.
Prior to version 6, sets were always created on the client and sent to the server. Now, by default, sets are created on the server, except for the "UserSet". This is because a UserSet can only be created on the client. This difference can be very significant to those converting version 3 databases to version 6. (Note: Page 1016 of the current Version 6 4th Dimension Language Reference manual erroneously states that UserSet and LockedSet are both process sets.)
Let's look at this through a simplified example. Imagine that you have an output form that has a few buttons related to the use of sets, such as "Load", "Save" and "Merge". Assume that the user wants to merge a selection of 10 records (highlighted on screen) with 20 records contained in a previously saved set. So, after selecting and highlighting the 10 records, the user clicks the "Merge" button at the bottom of the output form. An object method for the "Merge" button would look something like this:
LOAD SET ([Customers]; "SavedSet";"")
`An Open Dialog is presented so a previously saved set can be loaded
UNION ("SavedSet";"UserSet";"SavedSet")
USE SET ("SavedSet")
In a version 3 database, if none of the 10 "UserSet" records were not already present in the "SavedSet" selection, the result of the UNION of the two sets would be a new selection containing 30 records.
In a version 6 database, an error will be generated because "UserSet" is in memory locally on the client, while "SavedSet" is residing in memory on the server. This breaks the cardinal rule that UNION requires that all the sets be on the same machine. Here is the revised method:
COPY SET ("UserSet";"Choices") `Copy the UserSet to a process set
LOAD SET ([Customers]; "SavedSet";"")
`An Open Dialog is presented so a previously saved set can be loaded
UNION ("SavedSet";"Choices";"SavedSet") `Choices is a process set so this will work
USE SET("SavedSet")
The above method is really intended to illustrate using the new COPY SET command to move a local set over to a process set. Another way to accomplish our objective in this case would be:
LOAD SET ([Customers]; "$SavedSet";"") `Load the set into a Local Set
`An Open Dialog is presented so a previously saved set can be loaded
UNION ("$SavedSet";"UserSet";"$SavedSet") `UserSet is a local so this will work
USE SET("$SavedSet")
Summary
This technical note discusses the powerful new way sets are created and maintained in 4D V6 and addresses compatibility issues that might arise with routines created in version 3 databases.
Version 6 has added new power to the use of sets. Now, since sets are created and maintained on the server rather than the client, all logical operations such as UNION, DIFFERENCE and INTERSECTION can be performed on the server. Only the result set needs to be moved over the network to the client — if at all. However, some procedures originally created in a version 3 database may need slight modification to maintain compatibility with the methodology employed in 4D V6.