In this section: |
How to: |
When you join two data sources, you can access any or all of the segments in the cross-referenced data source, not just the cross-referenced segment itself. These other segments are sometimes called linked segments. From the perspective of the host data source, all of the linked segments are descendants of the cross-referenced segment. It is as though an alternate view had been taken on the cross-referenced data source to make the cross-referenced segment the root. To access a linked segment, you only need to declare it in the Master File of the host data source.
SEGNAME = segname, SEGTYPE = {KL|KLU}, PARENT = parentname, CRFILE = db_name, [CRSEGNAME = crsegname,] [DATASET = physical_filename,] $
where:
Is the name assigned to the cross-referenced segment in the host data source.
Indicates that this segment is a descendant segment in a cross-referenced data source (as viewed from the perspective of the host data source), and has a one-to-many relationship to its parent. KL stands for keyed through linkage.
Indicates that this segment is a descendant segment in a cross-referenced data source (as viewed from the perspective of the host data source), and has a one-to-one relationship to its parent. KLU stands for keyed through linkage, unique.
Is the name of the segment parent in the cross-referenced data source, as viewed from the perspective of the host data source.
Is the name of the cross-referenced data source. You can change the name without rebuilding the data source.
Is the name of the cross-referenced segment. If you do not specify this, it defaults to the value assigned to SEGNAME.
Optionally, is the platform-dependent physical name of the data source for the CRFILE.
SEGNAME = SECSEG, SEGTYPE = KLU, PARENT = JOBSEG, CRFILE = JOBFILE, $ SEGNAME = SKILLSEG, SEGTYPE = KL, PARENT = JOBSEG, CRFILE = JOBFILE, $
Note that you do not use the CRKEY attribute in a declaration for a linked segment, since the common join field (which is identified by CRKEY) needs to be specified only for the cross-referenced segment.
Consider our EMPLOYEE example. JOBFILE is a multi-segment data source:
In your EMPLOYEE data source application, you may need the security information stored in the SECSEG segment and the job skill information stored in the SKILLSEG segment. After you have created a join, you can access any or all of the other segments in the cross-referenced data source using the SEGTYPE value KL for a one-to-many relationship (as seen from the host data source), and KLU for a one-to-one relationship (as seen from the host data source). KL and KLU are used to access descendant segments in a cross-referenced data source for both static (KM) and dynamic (DKM) joins.
When the JOBSEG segment is retrieved from JOBFILE, it also retrieves all of the children for JOBSEG that were declared with KL or KLU SEGTYPEs in the EMPLOYEE Master File:
Remember that you can retrieve all of the segments in a cross-referenced data source, including both descendants and ancestors of the cross-referenced segment. Ancestor segments should be declared in the host Master File with a SEGTYPE of KLU, as a segment can have only one parent and so, from the perspective of the host data source, this is a one-to-one relationship.
Consider the EDUCFILE data source used in our example. The COURSEG segment is the root and describes each course. ATTNDSEG is a child and includes employee attendance information:
When you join EMPINFO in EMPLOYEE to ATTNDSEG in EDUCFILE, you can access course descriptions in COURSEG by declaring it as a linked segment.
From this perspective, COURSEG is a child of ATTNDSEG, as shown in the following diagram.
The sections of the EMPLOYEE Master File used in the examples follow (nonessential fields and segments are not shown).
FILENAME = EMPLOYEE, SUFFIX = FOC, $ SEGNAME = EMPINFO, SEGTYPE = S1, $ FIELDNAME = EMP_ID, ALIAS = EID, FORMAT = A9, $ . . . SEGNAME = PAYINFO, SEGTYPE = SH1, PARENT = EMPINFO, $ FIELDNAME = JOBCODE, ALIAS = JBC, FORMAT = A3, $ . . . SEGNAME = JOBSEG, SEGTYPE = KU, PARENT = PAYINFO, CRFILE = JOBFILE, CRKEY = JOBCODE, $ SEGNAME = SECSEG, SEGTYPE = KLU,PARENT = JOBSEG, CRFILE = JOBFILE, $ SEGNAME = SKILLSEG,SEGTYPE = KL, PARENT = JOBSEG, CRFILE = JOBFILE, $ SEGNAME = ATTNDSEG,SEGTYPE = KM, PARENT = EMPINFO, CRFILE = EDUCFILE, CRKEY = EMP_ID, $ SEGNAME = COURSEG, SEGTYPE = KLU,PARENT = ATTNDSEG, CRFILE = EDUCFILE, $
A KL segment may lead to other KL segments. Graphically, this can be illustrated as:
The letters on the arrows are the SEGTYPEs.
Note that segment G may either be a unique descendant of B or the parent of B.