Describing a Secondary Index Without Auto Index Selection

Starting in FOCUS Release 7.0.6, you can create one Master File and FOCPSB that describe the primary index and multiple secondary indexes for a database. The adapter Auto Index Selection feature can then determine the appropriate index to use for each request. For information on this feature, see IMS Overview and Mapping Concepts, and Creating FOCUS Descriptions.

In prior releases, each Master File was limited to describing either the primary index or one secondary index. The application programmer then had to decide which index to use for each request and implement that decision by referencing the appropriate Master File in each request. This technique is still supported, and this section describes it.

Using IMS secondary indexes, you can retrieve records in order of a field other than the key field. (A secondary index is itself a database with its own DBD.) The DBD for a database that uses a secondary index includes an XDFLD statement that assigns a field name to the index.

If a PCB includes the parameter PROCSEQ=indexname, the named index is used as the main entry point into the database.

The adapter can take advantage of one secondary index for each Master File if either of the following conditions exists:

To use the index, in the Master File you must do the following:

When the adapter generates SSAs for retrieval, it will use the XDFLD as the key. It can still use the real key field in DL/I calls since the real key is defined as a search field (suffix IMS).

The following diagram illustrates how to describe a secondary index in the Master File:

  1. Is the IMS PCB. It is sensitive to SEG1 and SEG2. PROCSEQ=SINDEX means that a secondary index is used as the main entry point into the database, and that the DBD describing this index is named SINDEX.
  2. Shows the DBDs for the database and the index:

    The index DBD specifies that the index is for SEG1 in DBD1 (the root, as required) and that its name is XNAME.

    The database DBD contains the XDFLD statement in the root segment. It specifies the name XNAME. The key for the root segment is SSN.

  3. Is the Master File. The index is the last field specified in the root segment, SEG1, and it is described as the key to the segment (ALIAS=XNAME.KEY). XNAME is the name from the XDFLD statement in the DBD.

    The field that is the actual key to the root segment, SSN from the DBD, is described as a search field (ALIAS=SSN.IMS).

If necessary, you can add an additional PCB to the PSB for use with a secondary index. Include the parameter PROCSEQ=indexDBDname in this PCB, and create a corresponding Master File according to the previous instructions. You can create a separate PCB and Master File for each secondary index you need.

The following example shows a secondary index defined in the PATDB01 DBD. The DBD for the secondary index, PATDBIX1, is as follows:

  PRINT NOGEN
  DBD      NAME=PATDBIX1,ACCESS=INDEX
  DATASET  DD1=PATDBIX1,DEVICE=3380
*
  SEGM NAME=SEGIX1,PARENT=0,BYTES=28
    FIELD NAME=(IXNAMEIX,SEQ,U),BYTES=28,START=1
    LCHILD NAME=(PATINFO,PATDB01),INDEX=IXNAME,PTR=SNGL
  DBDGEN
  FINISH
  END

In the TSTPSB01 PSB, the PCB that accesses this index includes the parameter PROCSEQ=PATDBIX1:

PCB       TYPE=TP,MODIFY=YES,EXPRESS=YES
PCB       TYPE=TP,EXPRESS=NO,MODIFY=YES,SAMETRM=YES
PCB       TYPE=DB,DBDNAME=PATDB01,PROCOPT=GO,KEYLEN=9
SENSEG    NAME=PATINFO,PARENT=0
PCB       TYPE=DB,DBDNAME=PATDB01,PROCOPT=GO,KEYLEN=28,PROCSEQ=PATDBIX1
SENSEG    NAME=PATINFO,PARENT=0
PSBGEN    LANG=COBOL,PSBNAME=TSTPSB01,CMPAT=YES
END

In the FOCPSB, the corresponding PCB record assigns the name PATINIX to the Master File:

FOCPSB=EXTENDED,$
PCBNAME=        ,PCBTYPE=TERM,$
PCBNAME=        ,PCBTYPE=TERM,$
PCBNAME=        ,PCBTYPE=TERM,$
PCBNAME=PATINFO ,PCBTYPE=DB,$
PCBNAME=PATINIX ,PCBTYPE=DB,$

The DBD for the PATDB01 database includes an XDFLD record that assigns the name IXNAME to index PATDBIX1. The index searches the database in order of last name and first name and is targeted to the root segment:

  PRINT NOGEN
  DBD      NAME=PATDB01,ACCESS=(HIDAM,VSAM)
  DATASET  DD1=PATDB01,DEVICE=3380,BLOCK=4096,SCAN=5
*
  SEGM NAME=PATINFO,PTR=H,PARENT=0,BYTES=233
    FIELD NAME=(SSN,SEQ,U),BYTES=9,START=26,TYPE=C
    LCHILD NAME=(SEGIX,PATDBIX),PTR=INDX
    FIELD NAME=SEQFIELD,BYTES=6,START=1,TYPE=C
    FIELD NAME=REVSEQ,BYTES=6,START=7,TYPE=C
    FIELD NAME=SSNALPHA,BYTES=9,START=35,TYPE=C
    FIELD NAME=EMPID,BYTES=12,START=44,TYPE=C
    FIELD NAME=LNAME,BYTES=12,START=56,TYPE=C
    FIELD NAME=FNAME,BYTES=12,START=68,TYPE=C
    FIELD NAME=ADMDATE,BYTES=8,START=89,TYPE=C
    FIELD NAME=PATID,BYTES=10,START=176,TYPE=C
    FIELD NAME=/SX1
*
    LCHILD NAME=(SEGIX1,PATDBIX1),PTR=INDX
    XDFLD  NAME=IXNAME,SRCH=(LNAME,FNAME),                             X
               SUBSEQ=/SX1,NULLVAL=BLANK
*
    LCHILD NAME=(SEGIX2,PATDBIX2),PTR=INDX
    XDFLD  NAME=IXCOMP,SRCH=(SSNALPHA,EMPID,LNAME)
*
    LCHILD NAME=(SEGIX3,PATDBIX3),PTR=INDX
    XDFLD  NAME=IXADMD,SRCH=(ADMDATE),                                 X
               SUBSEQ=/SX1,NULLVAL=BLANK
*
  DBDGEN
  FINISH
  END

In the PATINIX Master File, the last field described is the index field, and it has ALIAS=IXNAME.KEY. Notice that the real key to the segment, SSN, is defined as a search field (ALIAS=SSN.IMS):

FILE=PATDB01,SUFFIX=IMS,$
SEGNAME=PATINFO,PARENT=,SEGTYPE=S1,$
FIELD=SEQFIELD      ,ALIAS=SEQFIELD.IMS   ,USAGE=A06   ,ACTUAL=A06,$
FIELD=REVSEQ        ,ALIAS=REVSEQ.IMS     ,USAGE=A06   ,ACTUAL=A06,$
FIELD=SALARY        ,ALIAS=               ,USAGE=A08   ,ACTUAL=A08,$
FIELD=OT_HR_PAY     ,ALIAS=               ,USAGE=A05   ,ACTUAL=A05,$
FIELD=SSN           ,ALIAS=SSN.IMS        ,USAGE=A09   ,ACTUAL=A09,$
FIELD=SSNALPHA      ,ALIAS=SSNALPHA.IMS   ,USAGE=A09   ,ACTUAL=A09,$
FIELD=EMPLOYEEID    ,ALIAS=EMPID.IMS      ,USAGE=A12   ,ACTUAL=A12,$
FIELD=LAST_NAME     ,ALIAS=LNAME.IMS      ,USAGE=A12   ,ACTUAL=A12,$
FIELD=FIRST_NAME    ,ALIAS=FNAME.IMS      ,USAGE=A12   ,ACTUAL=A12,$
FIELD=DATE_OF_BIRTH ,ALIAS=               ,USAGE=A08   ,ACTUAL=A08,$
FIELD=RACE          ,ALIAS=               ,USAGE=A01   ,ACTUAL=A01,$
FIELD=ADMIT_DATE    ,ALIAS=ADMDATE.IMS    ,USAGE=A08   ,ACTUAL=A08,$
FIELD=ADMIT_TYPE    ,ALIAS=               ,USAGE=A01   ,ACTUAL=A01,$
FIELD=DISPOSITION   ,ALIAS=               ,USAGE=A02   ,ACTUAL=A02,$
FIELD=TRANSFER_DATE ,ALIAS=               ,USAGE=A08   ,ACTUAL=A08,$
FIELD=ALLERGY1      ,ALIAS=               ,USAGE=A15   ,ACTUAL=A15,$
FIELD=ALLERGY2      ,ALIAS=               ,USAGE=A15   ,ACTUAL=A15,$
FIELD=ALLERGY3      ,ALIAS=               ,USAGE=A15   ,ACTUAL=A15,$
FIELD=ALLERGY4      ,ALIAS=               ,USAGE=A15   ,ACTUAL=A15,$
FIELD=HOUSING       ,ALIAS=               ,USAGE=A03   ,ACTUAL=A03,$
FIELD=RPR           ,ALIAS=               ,USAGE=A01   ,ACTUAL=A01,$
FIELD=URIN          ,ALIAS=               ,USAGE=A01   ,ACTUAL=A01,$
FIELD=PRACTITIONAR  ,ALIAS=               ,USAGE=A02   ,ACTUAL=A02,$
FIELD=SHIFT         ,ALIAS=               ,USAGE=A01   ,ACTUAL=A01,$
FIELD=PATINET_ID    ,ALIAS=PATID.IMS      ,USAGE=A12   ,ACTUAL=A12,$
FIELD=WHO_ADDED     ,ALIAS=               ,USAGE=A10   ,ACTUAL=A10,$
FIELD=DATE_ADDED    ,ALIAS=               ,USAGE=A08   ,ACTUAL=A08,$
FIELD=WHO_EDITED    ,ALIAS=               ,USAGE=A10   ,ACTUAL=A10,$
FIELD=DATE_EDITED   ,ALIAS=               ,USAGE=A08   ,ACTUAL=A08,$
FIELD=STATION_ID    ,ALIAS=               ,USAGE=A12   ,ACTUAL=A12,$
FIELD=DIABETIC      ,ALIAS=               ,USAGE=A01   ,ACTUAL=A01,$
FIELD=DIALYSIS      ,ALIAS=               ,USAGE=A01   ,ACTUAL=A01,$
FIELD=IXNAME        ,ALIAS=IXNAME.KEY     ,USAGE=A28   ,ACTUAL=A28,$

Information Builders