[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP COBOL
DBMS Database Programming Manual


Previous Contents Index

5.8 Set Types

A set type is a named relationship between two or more record types. The major characteristic of a set type is a relationship that relates one or more member records to an owner record. The owner and members of a set are called tenants of the set. For example, the PART record type could own a SUPPLIER record type in the set PART_INFO.

As with records, the DBA describes set types in the schema; set occurrences exist in the database. The unqualified term set implies set occurrence. A set occurrence is the actual data in the set, not its definition, which is the set type. Figure 5-1 illustrates a set relationship using a Bachman diagram.

Figure 5-1 Bachman Diagram


A Bachman diagram shows how member records are linked with owner records by arrows that point toward the members. It is a graphic representation of the set relationships between owner and member records used to analyze and document a database design. This simple format can be extended to describe many complex set relationships. The Oracle CODASYL DBMS documentation on data manipulation contains a complete Bachman diagram of the PARTS database.

Most of the examples in this chapter use the set types in the PARTSS1 and PARTSS3 subschemas (see the subschema compiler listings in Section 7.3, and the Bachman diagrams in this chapter, Figure 5-2 and Figure 5-3). Figure 5-4 and Figure 5-5 contain three PART records, two VENDOR records, and six SUPPLY records. The SUPPLY records show suppliers' lag times. Lag time starts when an item is ordered and ends when the item is received.

The examples assume the records are in the following order:

  1. PART record type: LABEL, CASSETTE, TAPE
  2. SUPPLY record type: 4-DAYS, 2-DAYS, 1-MONTH, 1-WEEK, 2-WEEKS, 5-DAYS
  3. VENDOR record type: MUSICO INC., SOUND-OFF CO.

Note

All occurrence diagrams display member records within a set in counterclockwise order.

Figure 5-2 Partial Bachman Diagram of the PARTSS1 Subschema


Figure 5-3 Bachman Diagram of the PARTSS3 Subschema


Figure 5-4 Sample Occurrence Diagram 1


Figure 5-5 Sample Occurrence Diagram 2


5.9 Sets

Sets are the basic structural units of a database. A set occurrence has one owner record occurrence and zero, one, or several member record occurrences. Figure 5-6 shows one occurrence of PART_SUPPLY set where PART A owner record occurrence owns two SUPPLY member record occurrences.

Set types establish a logical relationship between two or more types of records. A subschema usually includes one or more set types. Each set type has one record type that participates as the owner record and one or more record types that participate as members. These owner and member records are grouped into set occurrences.

Figure 5-6 One Occurrence of Set PART_SUPPLY


The DBA can specify a set type where each PART record occurrence can own SUPPLY record occurrences. Figure 5-7 is a Bachman diagram that shows the relationship between PART record types and SUPPLY record types. Bachman diagrams give you a picture of the schema or a portion of the schema. Each record type is enclosed in a box. Each set type is represented by an arrow pointing from the owner record type to the member record type or types. Thus, in Figure 5-7, PART is the owner record type of the PART_SUPPLY set type, and SUPPLY is the member record type.

Figure 5-7 Set Relationship


You can have many set relationships in a subschema. Figure 5-8 shows a set relationship where vendor records are also owners of supply records. You would use this relationship when many parts are supplied by one vendor, and many vendors supply one part. For example, Figure 5-9 shows a gasket supplied by three vendors. The supply records show the minimum quantity each vendor is willing to ship.

Figure 5-8 Set Relationships


Figure 5-9 Occurrence Diagram of a Relationship Between Two Set Types


5.9.1 Simple Set Relationships

A simple set relationship contains one owner record type and one or more member record types. Simple relationships are used to represent a basic one-to-many relationship where one owner record occurrence owns zero, one, or several member record occurrences. Simple relationships are created with a single set type. There are three kinds of sets in simple relationships: system-owned sets, simple sets, and forked sets.

5.9.1.1 System-Owned Sets

By definition, a set contains one owner record and may contain zero or more member records. Sets owned by the system, however, have only one occurrence in the database and are called system-owned sets. System-owned sets are used as entry points into the database. You cannot access the owner of a system-owned set (the system), but you can access its member records. System-owned sets are also called singular sets. Figure 5-10 is an example of a system-owned set type.

Figure 5-10 Bachman Diagram of a System-Owned Set Type


5.9.1.2 Simple Sets

In simple sets, each set contains only one type of member record. Figure 5-11 is a Bachman diagram of a simple set type where similar parts are grouped by class code. For example, plastic parts could be member records owned by a class record with a class code PL.

Figure 5-11 Bachman Diagram of a Simple Set Type


Example 5-1 prints a listing of all parts with a class code of PL.

Example 5-1 Printing a Listing of a Simple Set

PROCEDURE DIVISION.
   .
   .
   .
100-GET-PLASTICS-CLASS.
    MOVE "PL" TO CLASS_CODE
    FIND FIRST CLASS USING CLASS_CODE.
200-GET-PLASTICS-PARTS.
    FETCH NEXT PART WITHIN CLASS_PART
      AT END GO TO 900-DONE-PLASTIC-PARTS.
   *****************************************************
   *   Plastic parts print routine.
   *****************************************************
      GO TO 200-GET-PLASTICS-PARTS.

5.9.1.3 Forked Sets

A forked set has one owner record type and members of two or more different member record types. In most forked sets, the member record types have common data characteristics. One such example is the set type PART_INFO in Figure 5-12, where member record types SUPPLY and PR_QUOTE both contain information about parts.

Figure 5-12 Bachman Diagram of a Forked Set Type


One advantage of a forked set type is the ability to connect many different record types to one set type. Another advantage is that owner records need only one set of pointers to access more than one member record type. Example 5-2 uses the forked set type shown in Figure 5-12 and the forked set occurrence in Figure 5-13 to perform a part analysis.

Example 5-2 Using Forked Sets

PROCEDURE DIVISION.
    .
    .
    .
100-GET-PART.
    DISPLAY "TYPE PART ID".
    ACCEPT PART_ID.
    IF PART_ID = "DONE"
       GO TO 900-DONE-PART-INQUIRY.
    FETCH FIRST PART USING PART_ID
       ON ERROR
       DISPLAY "PART " PART_ID " NOT IN DATABASE"
       GO TO 100-GET-PART.
200-GET-SUPPLY-INFO.
    FETCH NEXT SUPPLY WITHIN PART_INFO
       AT END
       FETCH OWNER WITHIN PART_INFO
       GO TO 300-GET-QUOTE-INFO.
 *****************************************************
 * The FETCH OWNER statement resets currency to      *
 * point to the owner. This allows the search for    *
 * PR_QUOTE records to begin with the first member  *
 * record occurrence rather than after the           *
 * last SUPPLY record occurrence.                    *
 *****************************************************
    PERFORM 500-SUPPLY-ANALYSIS.
    GO TO 200-GET-SUPPLY-INFO.
300-GET-QUOTE-INFO.
    FETCH NEXT PR_QUOTE WITHIN PART_INFO
       AT END
       GO TO 100-GET-PART.
    PERFORM 600-QUOTE-ANALYSIS.
    GO TO 300-GET-QUOTE-INFO.

Figure 5-13 is an occurrence diagram of a forked set. The figure shows a part record owning five PART_INFO member records.

Figure 5-13 Forked Set Occurrence



Previous Next Contents Index