TSO-ISPF JCL COBOL VSAM DB2 CICS IMS-DB Tools Articles Forum Quiz Interview Q&A

Source and Target Segments are Root Segments


In the Customer DBD defined earlier, the customer segment is having unique key field as CUSTNUM, which means the CUSTOMER segment can be accessed in Ascending order of CUSTNUM sequence. To access the CUSTOMER segment in CUSTNAME sequence, can be done using the secondary index.

In order to establish any secondary index, a DBD for that index is required together with entries in the DBD for the database being indexed to indicate the field the index is to be based on and other details. The index will then automatically be maintained as the database is subsequently updated. To define the secondary index, two additional statements in the DBD are required.

LCHILD    NAME=(XCSTMER1,XCSTDBD1),POINTER=INDX
XDFLD     NAME=XCSTNAME,SRCH=CUSTNAME

These two statements must appear together as shown in the CUSTDBD1 below. They may appear anywhere after the SEGM statement for the CUSTOMER, and before the next SEGM statement. In this example, the Source segment is CUSTOMER (CUSTNAME is a part of this segment), and CUSTOMER segment itself is the target segment. The LCHILD statement specifies that the CUSTOMER segment is indexed by the segment XCSTMER1 in the database defined in the DBD called XCSTDBD1 which defines the secondary index database.

The "POINTER=INDX" entry specifies that the link between CUSTOMER and XCSTMER1 is really an index connection rather than a logical-child/logical-parent connection. The XDFLD statement specifies the field on which the secondary index is to be built. The DL/I call which forces IMS to use the secondary index in searching for the CUSTOMER with CUSTNAME ‘RELIANCE PETROLEUM’ is

 GU   CUSTOMER(XCSTNAME=‘RELIANCE PETROLEUM’)

The GU will cause IMS to fetch the ‘RELIANCE PETROLEUM’ index segment and then to fetch the CUSTOMER segment this index points to. Note that the retrieved segment is exactly as usual - specifically it does not include an extra field corresponding to XCSTNAME. The CUSTDBD1 is as follows:

PRINT   NOGEN
DBD     NAME=CUSTDBD1,ACCESS=HIDAM
DATASET	DD1=CUST1,DEVICE=3350

SEGM    NAME=CUSTOMER,PARENT=0,BYTES=128
FIELD   NAME=(CUSTNUM,SEQ,U),BYTES=6,START=1,TYPE=C
FIELD   NAME=CUSTNAME,BYTES=31,START=7,TYPE=C
LCHILD  NAME=(XCSTMER1,XCSTDBD1),POINTER=INDX
XDFLD   NAME=XCSTNAME,SEARCH=CUSTNAME
FIELD   NAME=CSTADD1,BYTES=31,START=38,TYPE=C
FIELD   NAME=CSTADD2,BYTES=31,START=69,TYPE=C
........
SEGM    NAME=SHIPTO,PARENT=CUSTOMER,BYTES=124
FIELD   NAME=(SHPTOSEQ,SEQ,U),BYTES=2,START=1,TYPE=C
........
DBDGEN
FINISH
END

The DBD for Secondary Index is as follows:

PRINT   NOGEN
DBD     NAME=XCSTDBD1,ACCESS=INDEX
DATASET DD1=XCUST1,DEVICE=3350
SEGM    NAME=XCSTMER1,PARENT=0,BYTES=128
FIELD   NAME=(CUSTNAME,SEQ),BYTES=31,START=1,TYPE=C
LCHILD  NAME=(CUSTOMER,CUSTDBD1),INDEX=XCSTNAME
DBDGEN
FINISH
END

The PSB required for this example is:

PRINT   NOGEN
PCB     TYPE=DB,DBDNAME=CUSTDBD1,KEYLEN=30,PROCOPT=L,
        PROCSEQ=XCSTDBD1
SENSEG  NAME=CUSTOMER
SENSEG  NAME=SHIPTO,PARENT=CUSTOMER
PSBGEN  PSBNAME=CUSTPSB1,LANG=COBOL
END

Note that PROCSEQ parameter is added to the PCB macro so that the program uses the secondary index defined. Also note that there will not be any change in the hierarchy. In other words, this secondary sequence will not cause the restructuring of the hierarchy of the data base.



If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on IBMMainframer Community!

Are you looking for Job Change? Job Portal