Special Uses for Synonym Fields
Because synonym fields permit you to access data in physical fields with alternative field names and sequence numbers, they provide additional capabilities. These capabilities include such things as resequencing key numbers to match those assigned by non-APPX databases, creating noncontiguous or overlapping group fields, and providing an alternative key order for online data retrieval.
Resequencing key numbers
The APPX dictionary permits you to establish one primary key and up to 16 alternate keys to a file. APPX automatically assigns key number 0 to a primary key when the data dictionary is processed. Alternate keys are assigned key numbers based upon their position in a record (their sequence number). The alternate key field with the lowest sequence number is key number 1, the alternate key field with the next lowest sequence number is key number 2, and so on. You cannot change the assigned key numbers. If you subsequently modify the sequence numbers of key fields, the assigned key numbers are not changed.
If an APPX data dictionary is created for an application that was developed in another third or fourth generation language, the APPX-assigned key numbers may not match the key numbers that were assigned during development. Synonym fields can be used to resequence key number assignments, forcing a match between APPX’s key numbers and the key numbers that were assigned by the development software.
Creating noncontiguous groups
A group field in APPX must be comprised of fields with contiguous sequence numbers. You cannot include a field with a noncontiguous sequence number in a group field.
If for any reason you cannot change the sequence number of a noncontiguous field to satisfy this requirement, you can use a synonym field. Simply define a synonym for the noncontiguous field, and assign the synonym a sequence number that falls between the sequence number of the group header field and group trailer field. The synonym automatically becomes part of the group.
A synonym field occupies the same physical space and accesses the same data as the (noncontiguous) field it references. A synonym’s sequence number, however, is contiguous with that of other fields in the group, satisfying the group requirement.
Creating overlapping group fields
A group field cannot incorporate a field that is part of another group unless it incorporates all fields from the other group. In other words, groups can be nested but they cannot overlap.
You can circumvent this restriction by defining a synonym for a field that participates in more than one group. For example, suppose you create group A, which includes a customer number and an invoice number field. You wish to define group B, which also includes the customer number. You must first define a synonym of the customer number, and include the synonym field in group B.
A synonym field occupies the same physical space and accesses the same data as the field it references. However, because APPX considers the synonym to be a separate field, group A and group B do not share a common field and are therefore not considered as overlapping.
Providing an alternative key order for online retrieval
Many times, a group is designated as a key, solely to establish an order or sequence for online data retrieval. Under some circumstances, however, it may be necessary to provide for online retrieval of the same information by the same fields, but in different orders. (Remember that the retrieval order is deermined by the relative sequence numbers of fields within a group, and the ascending/descending specifications for those fields.)
Take, for example, a history file that contains a customer number and an annual activity amount for each customer. In one instance, you may wish to retrieve records based on customer activity, sequenced in descending order, from highest-volume customer to lowest. In another, you may wish to reverse the sequence. To provide for online retrieval in both an ascending and descending sequence, you need a synonym field.
Now, assume your application includes a Products by Customer file that identifies the range of products each customer is authorized to purchase. In one instance, you are required to retrieve, in product number order, all the products a specific customer is authorized to buy. Such an operation requires a group field key consisting of customer number and product number, in that order. In another instance, your user needs to retrieve all the customers who are authorized to buy a specific product. This operation requires a group field key consisting of product number and customer number, in that order. To establish this second key, incorporating the same fields as the first key but in a different sequence, you must first create synonyms of the customer number and product number fields. For these synonym fields, the customer synonym’s sequence number must be larger than that of the product synonym.