Example of defining secondary indexes
The secondary index in this example is used to retrieve COURSE segments based on student names.
The example is for a full-function database and uses direct, rather than symbolic, pointers.
For additional examples, including examples of defining secondary indexes for Fast Path DEDB databases, see Examples with secondary indexes.
Figure 1 shows the EDUC database and its secondary index. The code samples that follow show the two DBDs required for the databases.
The pointer segment in the secondary index contains a student name in the search field and a system related field in the subsequence field. Both of these fields are defined in the STUDENT segment. The STUDENT segment is the source segment. The COURSE segment is the target segment.
The DBDs in the code samples highlight the statements and parameters coded when a secondary index is used. (Wherever statements or parameters are omitted the parameter in the DBD is coded the same regardless of whether secondary indexing is used.)
DBD for the EDUC database
An LCHILD and XDFLD statement are used to define the secondary index. These statements are coded after the SEGM statement for the target segment.
- LCHILD statement. The LCHILD statement specifies the name of the secondary index SEGM statement and the name of the secondary index database in the NAME= parameter. The PTR= parameter is always PTR=INDX when a secondary index is used.
- XDFLD statement. The XDFLD statement defines the contents of the pointer segment and the options used in the secondary index. It must appear in the DBD input deck after the LCHILD statement that references the pointer segment.
In the example, shown in Figure 1, a system-related field (/SX1) is used on the SUBSEQ parameter. System-related fields must also be coded on FIELD statements after the SEGM for the source segment.

The following code shows the EDUC DBD for the example in Figure 1.
DBD NAME=EDUC,ACCESS=HDAM,...
SEGM NAME=COURSE,...
FIELD NAME=(COURSECD,...
LCHILD NAME=(XSEG,SINDX),PTR=INDX
XDFLD NAME=XSTUDENT,SEGMENT=STUDENT,SRCH=STUDNM,SUBSEQ=/SX1
SEGM NAME=CLASS,...
FIELD NAME=(EDCTR,...
SEGM NAME=INSTR,...
FILED NAME=(INSTNO,...
SEGM NAME=STUDENT,...
FIELD NAME=SEQ,...
FIELD NAME=STUDNM,BYTES=20,START=1
FIELD NAME=/SX1
DBDGEN
FINISH
ENDThe following code shows the SINDX DBD for the example in Figure 1.
DBD NAME=SINDX,ACCESS=INDEX
SEGM NAME=XSEG,...
FIELD NAME=(XSEG,SEQ,U),BYTES=24,START=1
LCHILD NAME=(COURSE,EDUC),INDEX=XSTUDENT,PTR=SNGL
DBDGEN
FINISH
ENDDBD for the SINDX database
- DBD statement
- The DBD statement specifies the name of the secondary index database in the NAME= parameter. The ACCESS= parameter is always ACCESS=INDEX for the secondary index DBD.
- SEGM statement
- You choose what is used in the NAME= parameter. This value is used when processing the secondary index as a separate database.
- FIELD statement
- The NAME= parameter specifies the sequence field of the secondary index. In this case, the sequence field is composed of both the search and subsequence field data, the student name, and the system-related field /SX1. You specify what is chosen by NAME=parameter.
- LCHILD statement
- The LCHILD statement specifies the name of the target, SEGM, and the name of the target database in the NAME= parameter. The INDEX= parameter has the name on the XDFLD statement in the target database. If the pointer segment contains a direct-address pointer to the target segment, the PTR= parameter is PTR=SNGL. The PTR= parameter is PTR=SYMB if the pointer segment contains a symbolic pointer to the target segment.