Processing Databases with Secondary Indexes


Access to segments through a secondary index allows a program to process segments in an order that is not the physical sequence of the database. The order segment in Figure 7-6 on page 76 is a good example of how secondary indexes can be used. To process an order when only the customer order number is known, the ORDER segment can be accessed by using the customer order number. This is the simplest form of a secondary index.

Another basic use for a secondary index is to provide a method of processing a subset of the segments in a database without having to read the entire database. An example of this would be to provide a secondary index on a Balance-owing field in the customer database. The secondary index database could be defined to only contain those database records for which a non-zero balance is owing.

Accessing Segments by Using a Secondary Index

The format of the CALL statement parameters for accessing segments through a secondary index are identical to those used to access segments through the primary path. The difference is in how the PCB is coded in the PSB. The second PCB in the PSB in Figure 15-14 shows how to define a PCB that can be used to access a segment through a secondary index.

Figure 15-14. Example of a PSB with a Secondary Index Defined
 * * PSB with Secondary index PCB *          PCB TYPE=DB,PROCOPT=G,                   DBDNAME=BE2CUST,,KEYLEN=6          PCB TYPE=DB,PROCOPT=G,                   DBDNAME=BE2CUST,,PROCSEQ=FE2CNAM,,KEYLEN=20 *                   SENSEG NAME=SE2PSCUST   PSBGENG,LANG=COBOL,PSBNAME=SE2PCUST,CMPAT=YES  END 

Retrieving Segments Using a Secondary Index

The same calls are used as described in "Retrieving Segments" on page 248. However, the index search field, which is defined by an XDFLD statement in the DBD, is used in the SSA for the get unique call of the root segment. The index search field defines the secondary processing sequence.

After the successful completion of this get unique call, the PCB and IOAREA look the same as after the basic get unique call in Figure 15-2 on page 248, except that the key feedback area now starts with the Customer name field.

When using the secondary processing sequence, consecutive get next calls for the CUSTOMER ORDER segment present the CUSTOMER ORDER segments in Customer name sequence.

If both the primary and the secondary processing sequence are needed in one program, you should use two PCBs, as shown in Figure 15-15.

Figure 15-15. Example of a Get Unique Call Using a Secondary Index
 77  GU-FUNC                        PICTURE XXXX VALUE 'GU 01  SSA002-GU-SE2PCUST.     02  SSA002-BEGIN            PICTURE x(19) VALUE 'SE2PCUST(FE2PCNAM='.     02  SSA002-FE2PCNAM PICTURE X(20).     02  SS1002-END                 PICTURE X VALUE ')'. 01  IOAREA                           PICTURE X(256). -------------------------------------------------------------------------- MOVE CUSTOMER-NAME TO SSA002-FE2PCNAM. CALL 'CBLTDLI' USING GU-FUNC,PCB-NAME,IOAREA,SSA002-GU-SE2PCUST. -------------------------------------------------------------------------- STATUS CODES: -------------     :   succesfull call      GE:   exceptional but correct condition   other:   error condition 

Replacing Segments Using a Secondary Index

To replace segments in the indexed database, you can use a combination of get hold and replace calls, but you cannot change sequence fields. However, you can change index search fields. If you change an index search field, DL/I automatically updates the index database by deleting the old pointer segment and inserting a new pointer segment.

Note:

When you use a secondary processing sequence, you might need to access the database record again later.


Deleting Segments Using a Secondary Index

When using a secondary processing sequence, you cannot delete the index target segment (the root segment that depends on the definitions). If you must delete the index target segment, use a separate PCB with a primary processing sequence.

Inserting Segments Using a Secondary Index

When you use a secondary processing sequence, you cannot insert the index target segment. In all other cases, the insert call will work as described in "Inserting Segments" on page 254.

Creating Secondary Indexes

You can create a secondary index during the initial load of the indexed database, or later. The secondary index database is created by the DL/I reorganization utilities. No application programs are required.



Introduction to IMS. Your Complete Guide to IBM's Information Management System
An Introduction to IMS: Your Complete Guide to IBMs Information Management System
ISBN: 0131856715
EAN: 2147483647
Year: 2003
Pages: 226

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net