Compaq COBOL
DBMS Database Programming Manual
FIND
Function
The FIND statement locates a specific record in the database and 
establishes it as the current record of the run unit. The FIND ALL 
statement locates zero or more records in the database and inserts them 
into the named keeplist.
 
database-record
represents a record selection expression. References are made to a 
record in the database according to the rules for Record Selection 
Expressions (see Section 4.6).
set-name
names a subschema set type.
stment
is an imperative statement executed for an at end or on error condition.
stment2
is an imperative statement executed for a not at end or not on error 
condition.
keeplist-name
names a list of database keys used by a run unit to lock records for 
later reference.
record-name
names a subschema record type.
realm-name
names a subschema realm.
rec-key
is a key data item within the subschema record occurrence.
bool-expres
is a conditional expression that involves data items of the object 
record.
General Rules
Format 1
  - database-record must reference a record stored in a realm 
  that is in ready mode.
  
- Execution of the FIND statement causes database-record to 
  become the current record of the run unit.
  
- The Database Control System (DBCS) does not make a copy of the 
  database record available to the program. To retrieve the record you 
  must use a FETCH or GET statement.
  
- The FOR UPDATE option puts a no-read lock on the specified record.
  
- Unless otherwise specified by the RETAINING clause (see 
  Section 4.9.1, RETAINING Clause), the successful FIND statement causes the DBCS to update 
  these currency indicators to point to the selected record:
  
    - Run unit.
    
- Realm.
    
- Record type.
    
- Set type. If the record is an owner record of the set type, this 
    currency indicator points to the selected record even if the set is 
    empty. If the record is a member record of the set type, this currency 
    indicator points to the selected record only if it is currently a 
    member of some set of that record type.
  
 
Format 2
  - keeplist-name identifies the object keeplist for the 
  statement.
  
- Using FIND ALL puts the database key values corresponding to each 
  qualifying record at the end of the object keeplist.
  
- When FIND ALL keeplist-name is used, no currency 
  indicators are affected.
  
- The same rec-key can appear only once in a given USING 
  phrase.
  
- The bool-expres expression is used to specify additional 
  requirements of a qualifying record.
  
- When FOR UPDATE is used, no-read locks may be placed on more than 
  one record.
All Formats
  - If a database exception condition occurs during the execution of a 
  FIND statement, the DBCS places a database exception condition code in 
  the special register DB-CONDITION (see Technical Note). This code 
  identifies the condition.
  
-  The DBCS places the database key of the record found in the 
  special register DB-KEY.
  
- [NOT]ON ERROR and [NOT]AT END cannot be used concurrently in a Find 
  statement.
  
- If either AT END or ON ERROR is used, it must precede USE.
  
- If ON ERROR and NOT ON ERROR are used concurrently in a Find 
  statement, USE procedures will not be activated.
Technical Note
FIND statement execution can result in the database exception 
conditions associated with the evaluation of the record selection 
expression.
Additional References
  -  Section 2.2, on reserved words (database special registers)
  
- Compaq COBOL Reference Manual, Chapter 6, section on scope of statements
  
- Compaq COBOL Reference Manual, Chapter 6, section on AT END phrase
  
-  Section 4.6, on record selection expressions
  
-  Section 4.8.1, on database On Error condition
  
-  Section 5.14.1, on RETAINING clause
  
- USE statement
Examples
  - Currency indicator access. To locate the following items, use the 
  statement listed with each item:
  
    - Current record of the run unit
 
- Current record of the MAKE realm
 
  
    | 
 
FIND CURRENT WITHIN MAKE. 
 |  
 
- Current record of the CLASS_PART set
 
  
    | 
 
FIND CURRENT WITHIN CLASS_PART. 
 |  
 
- Current PART record
 
  
    | 
 
FIND CURRENT WITHIN PART. 
 |  
 
 
- Keeplist access. To locate the following items, use the statement 
  listed with each item:
  
    - (ALL) PART records with a PARTSTATUS OF H and put their dbkey 
    values in keeplist THREE
 
  
    | 
 
FIND ALL THREE PART USING PARTSTATUS 
PARTSTATUS [X(1)] = H 
 |  
 
- First entry in the keeplist
 
  
    | 
 
FIND FIRST WITHIN KEEPLIST-A. 
 |  
 
- Last entry in the keeplist
 
  
    | 
 
FIND LAST WITHIN KEEPLIST-B. 
 |  
 
- N(th) entry in the keeplist
 
  
    | 
 
FIND OFFSET RECORD-COUNT 
WITHIN KEEPLIST-C. 
 |  
 
 
- Set owner access. To locate the owner (PART) of the PART_USES set:
 
  
    | 
 
FIND OWNER WITHIN PART_USES. 
 |  
 
- Record search access. To locate the following items, use the 
  statement listed with each item:
  
    - NEXT DEALER record whose DEAL-PHONE item begins with the area code 
    numbers 617
 
  
    | 
 
FIND NEXT DEALER WHERE DEAL-PHONE MATCHES "617" 
 |  
 
- First member within the PART_USES set
 
  
    | 
 
FIND FIRST WITHIN PART_USES. 
 |  
 
- Last member within the BUY realm
 
- Next COMPONENT record in the PART_USED_ON set
 
  
    | 
 
FIND NEXT COMPONENT WITHIN PART_USED_ON. 
 |  
 
- Prior COMPONENT record in the PART_USES set (uses COMP_SUB_PART and 
    COMP_OWNER_PART as record keys)
 
  
    | 
 
FIND PRIOR COMPONENT WITHIN PART_USES 
       USING COMP_SUB_PART, COMP_OWNER_PART. 
 |  
 
- A record relative to the current record (this statement starts from 
    the current position to the position defined by this offset)
 
  
    | 
 
FIND RELATIVE SEARCH-NUMBER 
      ON ERROR PERFORM 300-FIND-IN-ERROR-ROUTINE 
      END-FIND. 
 |  
 
- PART record with PART_STATUS equal to "G" from the 
    CLASS_PART set
 
  
    | 
 
MOVE "G" TO PART_STATUS. 
FIND NEXT CLASS WITHIN ALL_CLASS. 
FIND NEXT PART WITHIN CLASS_PART USING PART_STATUS 
                 AT END ...
 |  
 
- All PART records with PART_STATUS OF G (this statement puts their 
    dbkey values in KEEPLIST-4)
 
  
    | 
 
FIND ALL KEEPLIST-4 PART USING PART_STATUS 
 |  
 
- DB-KEY access. To locate the item referred to by the DB-KEY special 
    register:
 
 
FREE
Function
The FREE statement empties selected keeplists or removes a database key 
value from a keeplist or currency indicator.
 
database-key-id
represents a database key identifier. References are made to a keeplist 
entry or a currency indicator according to the rules for Database Key 
Identifiers.
keeplist-name
names a keeplist in the Subschema Section.
stment
is an imperative statement executed for an on error condition.
stment2
is an imperative statement executed for a not on error condition.
Syntax Rule
Keeplist-name cannot be specified more than once in a given 
FREE statement.
General Rules
  - If database-key-id references a keeplist entry, the DBCS 
  deletes that keeplist entry from the keeplist containing it. Removing 
  an entry from a keeplist changes the position of all subsequent entries 
  in the keeplist.
  
- If database-key-id references a currency indicator, the 
  DBCS sets that currency indicator to null.
  
- If ALL is specified and the FROM phrase is omitted, the DBCS 
  empties all keeplists in the program.
  
- If ALL CURRENT is specified, the DBCS nulls all of your currencies. 
  It does not free entries in a keeplist.
  
- If the FROM phrase is specified, the DBCS empties each 
  keeplist-name.
  
- The FREE statement releases retrieval update locks on the target 
  record.
  
- If a database exception condition occurs during the execution of a 
  FREE statement, the DBCS places a database exception condition code in 
  the special register DB-CONDITION (see Technical Note). This code 
  identifies the condition.
Technical Note
FREE statement execution can result in these database exception 
conditions and those associated with a Database Key Identifier:
  
    | DBM$_BADZERO | Integer-exp is zero. | 
  
    | DBM$_END | You accessed a keeplist with fewer entries than you expected. | 
Additional References
  -  Section 2.2, on reserved words (database special registers)
  
- Compaq COBOL Reference Manual, Chapter 6, section on scope of statements
  
-  Section 4.4, on database key identifiers
  
-  Section 4.8.1, on database On Error condition
  
- USE statement
Examples
  - Currency indicator access
  
    - To free the current record of the run unit:
 
- To free the currency indicator for the PART record:
 
  
    | 
 
FREE CURRENT WITHIN PART. 
 |  
 
- To free all currencies:
 
 
- Keeplist access
  
    - To free the first keeplist entry in KEEPLIST-A:
 
  
    | 
 
FREE FIRST WITHIN KEEPLIST-A. 
 |  
 
- To free the last keeplist entry in KEEPLIST-A:
 
  
    | 
 
FREE LAST WITHIN KEEPLIST-A. 
 |  
 
- To free the second keeplist entry relative to the current position 
    in the keeplist:
 
  
    | 
 
FREE OFFSET 2 WITHIN KEEPLIST-B. 
 |  
 
- To empty a keeplist:
 
- To empty all keeplists:
 
 
GET
Function
The GET statement moves the contents of the current database record of 
the run unit to your user work area.
 
record-name
names a subschema record type.
record-item
is a group or elementary data item in a subschema record type. 
Record-item may be qualified.
stment
is an imperative statement executed for an on error condition.
stment2
is an imperative statement executed for a not on error condition.
Syntax Rules
  - Each record-item must reference a data item in the same 
  subschema record type.
  
- If record-item is a group item, its subordinate group and 
  elementary items cannot be referenced in the same GET statement.
General Rules
  - The GET statement references the current record of the run unit.
  
- If you use the record-name option, or if you do not 
  specify either the record-item or the record-name 
  option, the DBCS makes a copy of the entire current record of the run 
  unit available to the program in the user work area.
  
- If you use the record-item option, only those items in the 
  current record of the run unit are made available to the program in the 
  user work area.
  
- Any change made to the user work area does not affect the record in 
  the database. You must execute a MODIFY and a COMMIT statement to make 
  permanent changes to the database.
  
- Use record-name to check that the record type of the 
  current record is identical to the record type specified by 
  record-name.
  
- The GET statement has no effect on currency indicators.
  
- If a database exception condition occurs during the execution of a 
  GET statement, the DBCS places a database exception condition code in 
  the special register DB-CONDITION (see Technical Note). This code 
  identifies the condition.
Technical Note
GET statement execution can result in these DB-CONDITION database 
exception condition codes:
  
    | DBM$_CRUN_NULL | The currency indicator for the run unit is null. | 
  
    | DBM$_CRUN_POS | The currency indicator for the run unit points to a vacated position in 
      the database. | 
  
    | DBM$_WRONGRTYP | The record type for record-name is not identical to the current record 
      type, or a record-item is not a group or elementary item in the current 
      record. | 
  
    | DBM$_CONVERR | A data conversion error occurred in the GET operation. | 
  
    | DBM$_ILLNCHAR | An invalid character was found in a numeric field. | 
  
    | DBM$_NONDIGIT | A nonnumeric character was found in a numeric field. | 
  
    | DBM$_OVERFLOW | A data overflow error occurred in the GET operation. | 
  
    | DBM$_TRUNCATION | A data truncation error occurred in the GET operation. | 
  
    | DBM$_UNDERFLOW | A data underflow error occurred in the GET operation. | 
Additional References
  -  Section 2.2, on reserved words (database special registers)
  
- Compaq COBOL Reference Manual, Chapter 6, section on scope of statements
  
-  Section 4.8.1, on database On Error condition
  
- USE statement
Examples
  - This example gets the current record of the run unit:
 
- This example gets a PART record only if it is the current record of 
  the run unit:
 
- This example gets these items only if they are part of the current 
  record of the run unit:
 
KEEP
Function
The KEEP statement inserts a database key value from a currency 
indicator or keeplist into a keeplist.
 
database-key-id
represents a database key identifier. References are made to a keeplist 
entry or a currency indicator according to the rules for Database Key 
Identifiers.
destination-keeplist
names a keeplist in the Subschema Section to receive the database key 
value.
stment
is an imperative statement executed for an on error condition.
stment2
is an imperative statement executed for a not on error condition.
General Rules
  - If database-key-id references a database key value in 
  either a currency indicator or a keeplist, the DBCS:
  
    - Inserts that value as the last entry in 
    destination-keeplist
    
- Sets a lock on the associated record to prevent concurrent run 
    units from accessing it
  
 
- If the program does not specify database-key-id, the DBCS 
  inserts the database key value of the current record of the run unit as 
  the last entry of destination-keeplist.
  
- The KEEP statement has no effect on currency indicators.
  
- If a database exception condition occurs during the execution of a 
  KEEP statement, the DBCS places a database exception condition code in 
  the special register DB-CONDITION (see Technical Note). This code 
  identifies the condition.
Technical Note
KEEP statement execution can result in the database exception 
conditions associated with the evaluation of the database key 
identifier.
Additional References
  -  Section 2.2, on reserved words (database special registers)
  
- Keeplist Description entry
  
- Compaq COBOL Reference Manual, Chapter 6, section on scope of statements
  
-  Section 4.4, on database key identifiers
  
-  Section 4.8.1, on database On Error condition
  
- USE statement
Examples
  - Currency indicator access
  
    - To insert the database key value of the current record of the run 
    unit into KEEPLIST-A:
 
  
    | 
 
KEEP CURRENT USING KEEPLIST-A. 
 |  
 
- To insert the database key value of the current record of the 
    CLASS_PART set into KEEPLIST-B:
 
  
    | 
 
KEEP CURRENT WITHIN CLASS_PART USING KEEPLIST-B. 
 |  
 
- To insert the database key value of the current record of the BUY 
    realm into KEEPLIST-B:
 
  
    | 
 
KEEP CURRENT WITHIN BUY USING KEEPLIST-B. 
 |  
 
- To insert the database key value of PART record into KEEPLIST-B:
 
  
    | 
 
KEEP CURRENT WITHIN PART USING KEEPLIST-B. 
 |  
 
 
- Keeplist access
  
    - To insert the first keeplist entry from KEEPLIST-A as the last 
    entry in KEEPLIST-B:
 
  
    | 
 
KEEP FIRST WITHIN KEEPLIST-A USING KEEPLIST-B. 
 |  
 
- To insert the last keeplist entry in KEEPLIST-A as the last entry 
    in KEEPLIST-B:
 
  
    | 
 
KEEP LAST WITHIN KEEPLIST-A USING KEEPLIST-B. 
 |  
 
- To insert the fourth keeplist entry relative to the current 
    position in KEEPLIST-A as the last entry in KEEPLIST-B:
 
  
    | 
 
KEEP OFFSET 4 WITHIN KEEPLIST-A USING KEEPLIST-B. 
 |  
 
 
MODIFY
Function
The MODIFY statement changes the contents of specified data items in a 
database record.
 
record-name
names a subschema record type.
record-item
is a group or elementary data item in a subschema record type. 
Record-item can be qualified.
set-name
names a subschema set type.
stment
is an imperative statement executed for an on error condition.
stment2
is an imperative statement executed for a not on error condition.
Syntax Rules
  - Each record-item must reference a data item in the same 
  subschema record type.
  
- If record-item is a group item, its subordinate group and 
  elementary data items cannot be referenced as a record-item in 
  the same MODIFY statement.
  
- Use record-name to check that the current record of the 
  run unit is a record type identical to the record-name record 
  type.
General Rules
  - Changes are made to a database record by:
  
    - Locating the target record (FIND and GET, or FETCH)
    
- Moving the new data to the data-name references in the user work 
    area
    
- Executing the MODIFY statement
  
 
- The DBCS changes the contents of the entire database record:
  
    - If you specify record-name
    
- If you specify neither record-name nor record-item
  
 
- Using record-item limits the changes to the database 
  record to only those items you specify.
  
- If you modify any data item that is the sort key for that record's 
  position in a sorted set, the DBCS automatically repositions the record 
  in that set in accordance with the set-ordering criteria of the set 
  type. 
 If the value of the sort key is identical to another record 
  of this type, and if duplicates are not allowed for this sorted set, 
  the DBCS does not perform the MODIFY operation, and a database 
  exception condition occurs.
- Currency indicator update rules for record insertion and removal 
  are as follows:
  
    - If the MODIFY statement removes a record from the current set, the 
    currency indicator for that set points to the position in the set 
    vacated by the record. (At this position the record is no longer 
    accessible.)
    
- If the MODIFY statement reinserts a record in a set in another 
    location, the set currency indicator changes to point to the record in 
    this new location.
    
- If you do not include the RETAINING clause (see Section 4.9.1, RETAINING Clause), the 
    currency indicator for the set is modified to the current record of the 
    run unit.
  
 
- The current record of the run unit must be in a realm in ready 
  update mode and all records required by the DBCS to execute the MODIFY 
  statement must be in realms in one of the appropriate READY modes.
  
- The contents of the user work area (UWA) do not change after the 
  successful or unsuccessful execution of a MODIFY statement.
  
- If the execution of a MODIFY statement results in an exception 
  condition, the record is not changed.
  
- If a database exception condition occurs during the execution of a 
  MODIFY statement, the DBCS places a database exception condition code 
  in the special register DB-CONDITION (see Technical Notes). This code 
  identifies the condition.
Technical Notes
MODIFY statement execution can result in these DB-CONDITION database 
exception condition codes:
  
    | DBM$_CRUN_NULL | The currency indicator for the run unit is null. | 
  
    | DBM$_CRUN_POS | The currency indicator for the run unit specifies the position of a 
      vacated record in a record collection. | 
  
    | DBM$_WRONGRTYP | The record type of record-name is not the same type as the current 
      record of the run unit, or the record-item is not a group or elementary 
      item of the current record type. | 
  
    | DBM$_DUPNOTALL | A sort key data item is modified creating a duplicate value in a 
      DUPLICATES NOT ALLOWED set. | 
  
    | DBM$_NOT_UPDATE | A realm is not in ready update usage mode. | 
  
    | DBM$_CHKITEM | A modified data item failed to pass the schema CHECK ITEM condition. | 
  
    | DBM$_CHKMEMBER | A modified data item failed to pass the schema CHECK MEMBER condition. | 
  
    | DBM$_CHKRECORD | A modified data item failed to pass the schema CHECK RECORD condition. | 
  
    | DBM$_CONVERR | A data conversion error occurred in the MODIFY operation. | 
  
    | DBM$_ILLNCHAR | An invalid character was found in a numeric field. | 
  
    | DBM$_NONDIGIT | A nonnumeric character was found in a numeric field. | 
  
    | DBM$_OVERFLOW | A data overflow error occurred in the MODIFY operation. | 
  
    | DBM$_TRUNCATION | A data truncation error occurred in the MODIFY operation. | 
  
    | DBM$_UNDERFLOW | A data underflow error occurred in the MODIFY operation. | 
Additional References
  -  Section 2.2, on reserved words (database special registers)
  
- Compaq COBOL Reference Manual, Chapter 6, section on scope of statements
  
-  Section 4.8.1, on database On Error condition
  
-  Section 5.14.1, on RETAINING clause
  
- USE statement
Examples
  - This example modifies an entire database record. It is a partial 
  update routine. Except for the PART_ID number in PARTS, the set was 
  originally created with empty parts records. As new information for a 
  part is made available, it is included in the record.
 
  
    | 
 
150-UPDATE-PARTS-RECORD. 
 
    DISPLAY "ENTER A PART-ID NUMBER - X(8): " 
             WITHOUT ADVANCING. 
    ACCEPT PART_ID. 
 
    IF PART_ID NOT = "TERMINAL" 
       FIND FIRST PART WITHIN ALL_PART USING PART_ID 
            ON ERROR DISPLAY "ERROR IN FIND " 
                     PERFORM 200-PARTS-RECORD-ERROR 
                     GO TO 150-UPDATE-PARTS-RECORD 
       END-FIND 
       PERFORM VERIFY-PART-ROUTINE 
    ELSE 
       PERFORM TERMINAL-ROUTINE. 
 
    DISPLAY "ENTER PART DESCRIPTION - X(50): " 
            WITHOUT ADVANCING. 
    ACCEPT PART_DESC. 
       . 
       . 
       . 
    MODIFY PART 
       ON ERROR DISPLAY "ERROR MODIFYING PARTS_RECORD..." 
                PERFORM 200-PARTS-RECORD-ERROR-ROUTINE. 
 
    GO TO 150-UPDATE-PARTS-RECORD. 
 |  
 
- In this example, PART_ID in the PART record is modified. PART_ID is 
  a sort key for the CLASS_PART set. This routine will retain the current 
  position in the CLASS_PART set after you modify the record.