[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP COBOL
DBMS Database Programming Manual


Previous Contents Index

6.6 CONNECT and DISCONNECT

When the set membership class is MANUAL, use the CONNECT statement to link a member record to its set occurrence. You can also use CONNECT for AUTOMATIC sets, provided that the retention class is OPTIONAL and you have disconnected the record.

When you use the CONNECT statement, specify the set or sets where the record is to be connected. Executing a CONNECT statement without the set list clause connects the record to all sets in which it can be, but is not yet, a member.

Before you execute a CONNECT statement, be sure that currency for the specified set type points to the correct set occurrence. If not, the member record will participate in the wrong set occurrence. (For more information on currency, see Section 5.13 and Section 5.14.) You cannot execute a CONNECT for a record that participates as an owner of the specified set.

If the set retention class is OPTIONAL, use the DISCONNECT statement to remove a member record from a specified set. The DISCONNECT statement does not delete a record from the database.

When you use the DISCONNECT statement, specify the sets from which the record will be disconnected. Executing a DISCONNECT without the set list clause disconnects the record from all the sets in which it participates as an optional member. You cannot execute a DISCONNECT for a record that participates as an owner of the specified set or that has a set retention class of FIXED or MANDATORY. Refer to the Section 4.7 for an explanation of how set membership class affects certain DML verbs.

6.7 RECONNECT

Use the RECONNECT statement to remove a member record from one set occurrence and connect it to another occurrence of the same set type, or to a different position within the same set. To transfer a member record:

  1. Use the FETCH (or FIND) statement to select a record in the set occurrence. This can be either a member or an owner of the set occurrence you want to connect to.
  2. Use the FETCH (or FIND) statement with the RETAINING clause to transfer the member record you want. This keeps the currency for the targeted record.
  3. Execute a RECONNECT statement using the WITHIN clause.

The RECONNECT statement is useful in applications such as production control where manufactured items move down an assembly line from one work station to another. In Figure 6-5, work stations are the owner records and assemblies are the member records.

Figure 6-5 Occurrence Diagram Prior to RECONNECT


Example 6-3 transfers ASSEMBLY R, a machine base, to WORK STATION 2 for electrical assembly. The order of insertion is LAST.

Example 6-3 RECONNECT Statement

    .
    .
    .
GET-WORK-STATION.
    MOVE 2 TO WORK_STATION_ID.
    FIND FIRST WORK_STATION USING WORK_STATION_ID.
    MOVE "R" TO ASSEMBLY_ID.
    FIND FIRST ASSEMBLY USING ASSEMBLY_ID
         RETAINING ASSEMBLY_SET.
 *********************************************************
 * The RETAINING clause retains work station 2 as        *
 * current of ASSEMBLY_SET. Otherwise, the found member  *
 * would be current of set and the RECONNECT would fail. *
 *********************************************************
    RECONNECT ASSEMBLY WITHIN ASSEMBLY_SET.
    .
    .
    .

Figure 6-6 shows the ASSEMBLY_SET after execution of the RECONNECT statement. Notice the ASSEMBLY A record replaces the R record's position in the WORK STATION 1 set occurrence. Also, execution of the RECONNECT makes the ASSEMBLY R record current for the ASSEMBLY_SET.

Figure 6-6 Occurrence Diagram After RECONNECT


6.8 ERASE ALL

The ERASE statement deletes one or more records from the database. However, it can delete more than you intended. Accidental deletes can occur because of the ERASE statement's cascading effect. The cascading effect can happen whenever the erased record is the owner of a set. Thus, if the current record is an owner of a set type, an ERASE ALL deletes:

  • The current record.
  • All records in sets owned by the current record.
  • Any records in sets owned by those members. Note that this is a repetitive process.

This is called a cascading delete.

The occurrence diagrams in Figure 6-7 show the results of using the ERASE ALL statement.

Figure 6-7 Results of an ERASE ALL


The ERASE ALL statement is the only way to erase an owner of sets with MANDATORY members.

6.9 ERASE Record-Name

If you do not use the ERASE ALL statement but use the ERASE record-name, and the erased record is the owner of a set, the ERASE statement deletes:

  • The current record.
  • All FIXED members of sets owned by the current record.
  • All FIXED members of sets owned by records in rule 2. Note that this is a repetitive process.

If the current record owns sets with OPTIONAL members, these records are disconnected from the set, but remain in the database.

The occurrence diagrams in Figure 6-8 show the results of using the ERASE record-name statement when affected members have an OPTIONAL set membership. In this figure, B records are FIXED members of the SET_B set and C records are OPTIONAL members of the SET_C set. Notice that records C1 and C2 are disconnected from the set, but remain in the database while B1 through B3 are erased.

Figure 6-8 Results of an ERASE Record-Name (with Both OPTIONAL and FIXED Retention Classes)


Remember, records removed from a set but not deleted from the database can still be accessed.

6.10 Freeing Currency Indicators

Use the FREE database-key-id statement to release the currency indicators for realms, records, sets, or the run unit. You use the FREE statement: (1) to establish a known currency condition before executing a program routine, and (2) to release record locks.

6.10.1 Establishing a Known Currency Condition

Establishing a known currency condition is helpful in many situations---for example, if you have a program that performs a customer analysis and prints three reports. The first report prints all customers with a credit rating greater than $1,000, the second report prints all customers with a credit rating greater than $5,000, and the third report prints all customers with a credit rating greater than $10,000. Because some customers will appear on more than one report, you want each report routine to start its customer analysis with the first customer in the database.

By using the FREE CURRENT statement at the end of a report routine, as shown in Example 6-4, you null the currency and allow the next print routine to start its analysis at the first customer.

Example 6-4 FREE CURRENT Statement

     .
     .
     .
MAIN-ROUTINE.
    READY TEST_REALM CONCURRENT RETRIEVAL.
    PERFORM FIRST-REPORT-HEADINGS.
    PERFORM PRINT-FIRST-REPORT THRU PFR-EXIT
            UNTIL AT-END = "Y".
    MOVE "N" TO AT-END.
    PERFORM SECOND-REPORT-HEADINGS.
    PERFORM PRINT-SECOND-REPORT THRU PSR-EXIT
            UNTIL AT-END = "Y".
    MOVE "N" TO AT-END.
    PERFORM THIRD-REPORT-HEADINGS.
    PERFORM PRINT-THIRD-REPORT THRU PTR-EXIT
            UNTIL AT-END = "Y".
    MOVE "N" TO AT-END.
     .
     .
     .
    STOP RUN.
PRINT-FIRST-REPORT.
    FETCH NEXT CUSTOMER_MASTER
          AT END FREE CURRENT
                 MOVE "Y" TO AT-END.
    IF AT-END = "N" AND
       CUSTOMER_CREDIT_RATING IS GREATER THAN 1000
           PERFORM PRINT-ROUTINE.
PFR-EXIT.
    EXIT.
PRINT-SECOND-REPORT.
    FETCH NEXT CUSTOMER_MASTER
          AT END FREE CURRENT
                 MOVE "Y" TO AT-END.
    IF AT-END = "N" AND
          CUSTOMER_CREDIT_RATING IS GREATER THAN 5000
          PERFORM PRINT-ROUTINE.
PSR-EXIT.
    EXIT.
PRINT-THIRD-REPORT.
    FETCH NEXT CUSTOMER_MASTER
          AT END MOVE "Y" TO AT-END.
    IF AT-END = "N" AND
       CUSTOMER_CREDIT_RATING IS GREATER THAN 10000
       PERFORM PRINT-ROUTINE.
PTR-EXIT.
    EXIT.

The FREE CURRENT statement in the PRINT-FIRST-REPORT paragraph nulls the default run-unit currency, thereby providing a starting point for the PRINT-SECOND-REPORT paragraph. The FREE CURRENT statement in the PRINT-SECOND-REPORT paragraph does the same for the PRINT-THIRD-REPORT paragraph. Thus, by nullifying the default run-unit currency, the FREE CURRENT statements allow the first execution of the FETCH NEXT CUSTOMER_MASTER statement to fetch the first customer master in TEST_REALM.


Previous Next Contents Index