Nested Loop Example

Restriction: This topic applies only when the AppMaster Builder AddPack has been installed, and applies only to Windows platforms.

In the sample IMS database program in the figure below, a nested loop obtains all detail records of each order record that is obtained by the previous program loop. In addition, the call following the nested loop obtains the part master record for each detail record. Fields from all three records display on the program screen, as shown below.

Figure 1. Nesting Database Calls
Nesting Database Calls

The sample programs in the above figure execute as follows:

Call 01 Obtains the customer record. It is qualified on the customer record key, which is the customer number.
Call 02 The outer loop. It loops on the order record, which is qualified on the order record key, the customer number.
Call 03 The nested loop. It positions the database pointer on the currently-obtained first order record record and loops on the detail record.
Call 04 An obtain call, nested within the second loop. It obtains the part master record associated with the detail record that was obtained by call 03.
Call 03 and Call 04 Execute repeatedly until no more detail and part master records are found for the first order record.
Call 02 Executes again, obtaining the second order record.
Call 03 and Call 04 Execute repeatedly until no more detail and part master records are found for the second order record.
Call 02 and Call 04 Execute repeatedly until no more order, detail, or part master records are found for the customer number specified in the customer record call, Call 01.