The following DL/I call represents a possible solution to this problem: To find Customer numbers for all customers who have the SHIPCITY as ‘BANGALORE’.
GN CUSTOMER*D SHIPTO(SHIPCITY=‘BANGALORE’)
To get the required results following assumptions are to be made:
Pointer is initially placed at the start of the database. Ignore the question of eliminating duplicate customer numbers from the result. In the above call SHIPTO segment is also retrieved, though it is not necessary.
An efficient solution to this problem can be achieved using secondary index, indexing CUSTOMER segment on the basis of SHIPTO values. In which case SHIPTO segment becomes the Source segment and CUSTOMER segment is the Target segment. The CUSTDBD needs to be defined as shown below.
PRINT NOGEN DBD NAME=CUSTDBD2,ACCESS=HIDAM DATASET DD1=CUST2,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 FIELD NAME=CSTADD1,BYTES=31,START=38,TYPE=C .......... LCHILD NAME=(XCSTMER2,XCSTDBD2),POINTER=INDX XDFLD NAME=XSHPCITY,SEARCH=SHIPCITY,SEGMENT=SHIPTO SEGM NAME=SHIPTO,PARENT=CUSTOMER,BYTES=124 FIELD NAME=(SHPTOSEQ,SEQ,U),BYTES=2,START=1,TYPE=C FIELD NAME=SHIPADD1,BYTES=31,START=34,TYPE=C FIELD NAME=SHIPADD2,BYTES=31,START=65,TYPE=C FIELD NAME=SHIPCITY,BYTES=18,START=96,TYPE=C FIELD NAME=SHPSTATE,BYTES=2,START=114,TYPE=C FIELD NAME=SHIPZIP,BYTES=9,START=116,TYPE=C SEGM NAME=BUYER,PARENT=SHIPTO,BYTES=72 FIELD NAME=BUYRNAME,BYTES=31,START=1,TYPE=C ........ DBDGEN FINISH END
The DBD for Secondary Index is as follows:
PRINT NOGEN DBD NAME=XCSTDBD2,ACCESS=INDEX DATASET DD1=XCUST2,DEVICE=3350 SEGM NAME=XCSTMER2,PARENT=0,BYTES=128 FIELD NAME=(SHIPCITY,SEQ),BYTES=18,START=1,TYPE=C LCHILD NAME=(CUSTOMER,CUSTDBD2),INDEX=XSHPCITY DBDGEN FINISH END
The secondary Index will contain one index segment for each SHIPTO occurrence in the customer database. Each such index segment will point to the corresponding CUSTOMER occurrence (the parent of the SHIPTO concerned). The secondary processing sequence for the customer database is defined by ascending values of SHIPTO segment.
The PSB required for this example is:
PRINT NOGEN PCB TYPE=DB,DBDNAME=CUSTDBD2,KEYLEN=30,PROCOPT=L, PROCSEQ=XCSTDBD2 SENSEG NAME=CUSTOMER SENSEG NAME=SHIPTO,PARENT=CUSTOMER SENSEG NAME=RECVABLE,PARENT=SHIPTO SENSEG NAME=PAYMENT,PARENT=RECVABLE PSBGEN PSBNAME=CUSTPSB2,LANG=COBOL END
Now the DL/I call can be written as
In the above call, it looks as if XSHPCITY is a field within the CUSTOMER segment. Each Iteration of this code causes IMS to fetch the next index segment for ‘BANGALORE’ and then to fetch the CUSTOMER segment that this index segment points to.
Note that there will not be any change in the hierarchy. In other words, the 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!