Multiple qualification statements with secondary indexes

When you qualify a call using the name of an indexed field, you can include multiple qualification statements.

You can use two AND operators to connect the qualification statements:
* or &
When used with secondary indexing, this AND is called the dependent AND. To satisfy the call, IMS scans the index once and searches for one pointer segment in the index that satisfies both qualification statements.
#
This is called the independent AND. You use it only with secondary indexing. When you use the independent AND to satisfy the call, IMS scans the index twice and searches for two or more different pointer segments in the index that point to the same target segment.

The distinction between the two ANDs applies only when the indexed field (the one defined as XDFLD in the DBD) is used in all qualifications. If one of the qualification statements uses another field, both ANDs work like the dependent AND.

The next two topics give examples of the dependent and independent AND. Although the examples show only two qualification statements in the SSA, you can use more than two. No set limit exists for the number of qualification statements you can include in an SSA, but a limit on the maximum size of the SSA does exist. You specify this size on the SSASIZE parameter of the PSBGEN statement. For information on this parameter, see IMS Version 15.4 System Utilities.

The dependent AND

When you use the dependent AND, IMS scans the index only once. To satisfy the call, it must find one pointer segment that satisfies both qualification statements.

For example, suppose you want to list patients whose bills are between $500 and $1000. To do this, you index the PATIENT segment on the BILLING segment, and specify that you want IMS to use the secondary index as the processing sequence. The following figure shows the three secondary indexing segments.

Figure 1. Example of using the dependent AND
begin figure description - This figure is described in the surrounding text. end figure description.
You then use this call:
GU   PATIENT (XBILLING>=00500*XBILLING<=01000)

To satisfy this call, IMS searches for one pointer segment with a value between 500 and 1000. IMS returns the PATIENT segment that is pointed to by that segment.

The independent AND

For example, suppose you want a list of the patients who have had both tonsillitis and strep throat. To get this information, you index the PATIENT segment on the ILLNAME field in the ILLNESS segment, and specify that you want IMS to use the secondary index as the processing sequence. In this example, you retrieve the PARENT segments based on a dependent's (the ILLNESS segment's) qualification. The following figure shows the four secondary indexing segments.

Figure 2. Example of using the independent AND
begin figure description - This figure is described in the surrounding text. end figure description.
You want IMS to find two pointer segments in the index that point to the same PATIENT segment, one with ILLNAME equal to TONSILLITIS and one with ILLNAME equal to STREPTHRT. Use this call:
GU   PATIENTb(XILLNAME=TONSILITIS#XILLNAME=bSTREPTHRT)

This call retrieves the first PATIENT segment with ILLNESS segments of strep throat and tonsillitis. When you issue the call, IMS searches for an index entry for tonsillitis. Then it searches for an index entry for strep throat that points to the same PATIENT segment.

When you use the independent AND with GN and GNP calls, a special situation can occur. If you repeat a GN or a GNP call using the same qualification, it is possible for IMS to return the same segment to your program more than once. You can check to find out whether IMS has already returned a segment to you by checking the key feedback area.

If you continue issuing a GN call until you receive a not-found (GE) status code, IMS returns a segment occurrence once for each independent AND group. When IMS returns a segment that is identical to one that was already returned, the PCB key feedback area is different.