Assuming an application that use the CUSTOMER database, requires direct access to receivable segments based on invoice number of RECVABLE segment. The existing structure forces us to go through the customer path to retrieve a RECVABLE segment. This can be avoided by defining a secondary index for it.
CUSTOMER database needs to be indexed in sequence by invoice number - the sequence field not of the root segment, but of the RECVABLE segment. As a result this secondary index allows to access the RECVABLE segments in invoice number sequence. In this example the source segment is RECVABLE segment (RSINVNUM is a field of this segment) and, RECVABLE segment itself is the target segment.
The CUSTDBD needs to be defined as shown below.
PRINT NOGEN DBD NAME=CUSTDBD3,ACCESS=HIDAM DATASET DD1=CUST3,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 .......... SEGM NAME=RECVABLE,PARENT=SHIPTO,BYTES=57 FIELD NAME=(RSINVNUM,SEQ,U),BYTES=6,START=1,TYPE=C LCHILD NAME=(XRECVBL1,XCSTDBD3),POINTER=INDX XDFLD NAME=XINVNUM,SEARCH=RSINVNUM FIELD NAME=RSINDATE,BYTES=6,START=7,TYPE=C FIELD NAME=RSPONUM,BYTES=25,START=13,TYPE=C FIELD NAME=RSPRDTOT,BYTES=4,START=38,TYPE=P .......... DBDGEN FINISH END |
The DBD for Secondary Index is as follows:
PRINT NOGEN DBD NAME=XCSTDBD3,ACCESS=INDEX DATASET DD1=XCUST3,DEVICE=3350 SEGM NAME=XRECVBL1,PARENT=0,BYTES=57 FIELD NAME=(RSINVNUM,SEQ),BYTES=6,START=1,TYPE=C LCHILD NAME=(RECVABLE,CUSTDBD3),INDEX=XINVNUM DBDGEN FINISH END |
The PSB required for this example is:
PRINT NOGEN PCB TYPE=DB,DBDNAME=CUSTDBD3,KEYLEN=30,PROCOPT=L, PROCSEQ=XCSTDBD3 SENSEG NAME=RECVABLE SENSEG NAME=SHIPTO,PARENT=RECVABLE SENSEG NAME=CUSTOMER,PARENT=SHIPTO SENSEG NAME=BUYER,PARENT=SHIPTO SENSEG NAME=PAYMENT,PARENT=RECVABLE SENSEG NAME=ADJSTMNT,PARENT=RECVABLE SENSEG NAME=LINEITEM,PARENT=RECVABLE PSBGEN PSBNAME=CUSTPSB3,LANG=COBOL END |
The Secondary index defined changes the apparent hierarchical structure of the database, as because when data is accessed using secondary index, the index target segment (RECVABLE) is presented to the program as if it were a root segment, even if it is not the root segment of the database.
The Figure below shows the secondary data structure for the customer database when accessed by the secondary index.
If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on IBMMainframer Community!