Sequential Organization Input-Output COBOL

The sequential organization input-output statements in the Procedure Division are the CLOSE, DELETE FILE, OPEN, READ, REWRITE, UNLOCK and WRITE statements.

Function

Sequential organization input-output provides a capability to access records of a file in an established sequence. The sequence is established as a result of writing the records to the file.

Organization

Sequential files are organized such that each record in the file except the first has a unique predecessor record, and each record except the last has a unique successor record. These predecessor-successor relationships are established by the order of WRITE statements when the file is created. Once established, these relationships do not change except when records are added to the end of the file.

Access Mode

Only the sequential access mode is available for files whose organization is sequential. In the sequential access mode, the sequence in which records are accessed is the order in which the records were originally written.

File Position Indicator

The file position indicator is a concept used to facilitate specification of the next record to be accessed within a given file during certain sequences of input-output operations. The concept of the file position indicator has no meaning for a file opened in the output or extend mode. The setting of the file position indicator is affected only by the CLOSE, OPEN and READ statements.

I-O Status

If the FILE STATUS clause is included in a file control entry, it defines a two-character file status data item for that file. During the execution of each input-output statement that refers to such a file, the runtime system stores a value into the file status data item. Storage of the value is done before the execution of any associated imperative statement and before any applicable USE procedure is executed. The value can be used by the program to determine the status of that input-output operation. The value that is stored into the file status data item is called the I-O status value.

The I-O status value indicates the status of an input-output operation.It also determines whether an applicable USE procedure should be executed if one of the conditions listed under the heading “Successful Completion” results, an applicable USE procedure is not executed; if any other condition results, such a procedure may be executed depending on rules stated in the section of this chapter that discusses the USE statement.

Certain classes of I-O status values indicate critical error conditions. They are the ones that begin with the digits 3, 4 and 9. When such conditions arise, certain system- standard error correction procedures may be tried first, depending on the nature of the problem. If they are not successful in clearing the problem, either a user-specified USE procedure is executed (if one is applicable) and execution of the program continues, or a runtime error message is produced and execution of the run unit terminates.

Upon completion of the input-output operation, the I-O status value expresses one of the following conditions:

  • Successful Completion.The input-output statement was executed successfully and no exceptional conditions arose. The left character of the I-O status value is 0 for these cases.
  • At End.A sequential READ statement was not executed successfully because of an at end condition. The left character of the I-O status value is 1 for this case.
  • Permanent Error.The input-output statement was not executed successfully because of an error that precludes further processing of the file. The problem could be a violation of an external boundary, or a hardware input-output error such as a data check, parity error, transmission error, and so forth. The left character of the I-O status value is 3 for these cases.
  • Logic Error.The input-output statement was not executed successfully because an improper sequence of input-output statements was performed on the file, or because of a violation of a user-defined limit. The left character of the I-O status value is 4 for these cases.
  • General Error. The input-output statement was not executed successfully because of a condition that is specified by the right character of the I-O status value. The left character of the I-O status value is 9 for these cases.

It should be noted that the I-O status values specified here differ in many respects from the ones defined in earlier versions of RM/COBOL. The new values comply with the American National Standard COBOL 1985 whereas the old values comply with ANSI COBOL 1974. In the following list, the old values are shown in square brackets following the new values when the two values are not the same. In situations where it is necessary to preserve compatibility with earlier versions of RM/COBOL in this respect, two courses of action are possible: either modify the text of the source program to use the new set of status values, or make use of the Compile Command option that causes the compiler to treat the entire program as an ANSI COBOL 1974 program.

The following list shows the possible I-O status values that can arise as a result of executing an input-output statement that refers to a sequential file:

  • Successful Completion
  • I-O Status Value=00.The input-output statement is successfully executed and no further information is available concerning the operation.
  • - I-O Status Value=04 [97].A READ statement executed successfully but the length of the record being processed does not conform to the fixed file attributes for the file.

    - I-O Status Value=05.The input-output statement is successfully executed but the file is not present at the time the input-output statement is executed.

  • For a DELETE FILE statement, the referenced file is not available.
  • For an OPEN statement, the referenced optional file is not present. If the open mode is I-O or extend, the file has been created.
  • - I-O Status Value=07.The input-output statement executed successfully. However, for a CLOSE statement with the NO REWIND, REEL/UNIT, or FOR REMOVAL phrase or for an OPEN statement with the NO REWIND phrase, the referenced file is on a non-reel/unit medium.

  • At End Condition with Unsuccessful Completion
  • I-O Status Value=10.A sequential READ statement is attempted and no next logical record exists in the file because the end of the file has been reached, or a sequential READ statement is attempted for the first time on an optional input file that is not present.

  • Permanent Error Condition with Unsuccessful Completion
  • - I-O Status Value=30.A permanent error exists and no further information is available concerning the input-output operation.

    - I-O Status Value=34.A permanent error exists because of an attempt to write beyond the externally defined boundaries of a sequential file.

    - I-O Status Value=35 [94].A permanent error exists because an OPEN statement with the INPUT, I-O, or EXTEND phrase is attempted on a nonoptional file that is not present.

    - I-O Status Value=37 [90, 95].A permanent error exists because an OPEN statement is attempted on a file that does not support the open mode specified in the OPEN statement, or a DELETE FILE statement refers to a protected file. For OPEN statements, the possible violations are as follows:

  • The EXTEND or OUTPUT phrase is specified but the file does not support write operations.
  • The I-O phrase is specified but the file does not support the input and output operations that are permitted for a sequential file when opened in the I-O mode.
  • The INPUT phrase is specified but the file does not support read operations.
  • - I-O Status Value=38 [93].A permanent error exists because an OPEN or DELETE FILE statement is attempted on a file previously closed with lock.

    - I-O Status Value=39 [94].An OPEN or DELETE FILE statement is unsuccessful because of an incompatibility between the fixed file attributes and the attributes specified for the file in the program.

  • Logic Error Condition with Unsuccessful Completion
  • - I-O Status Value=41 [92].An OPEN statement is attempted for a file that is already open, or a DELETE FILE statement is attempted for an open file.

    - I-O Status Value=42 [91].A CLOSE statement is attempted for a file that is not open.

    - I-O Status Value=43 [90].A REWRITE statement is attempted for a mass storage file, and the last input-output statement executed for the file was not a successfully executed READ statement.

    - I-O Status Value=44 [97].A boundary violation exists either because of an attempt to write or rewrite a record whose length is longer or shorter than the limits established by the RECORD IS VARYING clause, or because of an attempt to rewrite a record that is not the same size as the record being replaced.

    - I-O Status Value=46 [96].A sequential READ statement is attempted on a file open in the input or I-O mode and no valid next record has been established either because the preceding READ statement caused an at end condition, or because the preceding READ statement was unsuccessful for some other reason.

    - I-O Status Value=47 [90, 91].A READ statement is attempted on a file not open in the input or I-O mode.

    - I-O Status Value=48 [90, 91].A WRITE statement is attempted on a file not open in the output or extend mode.

    - I-O Status Value=49 [90, 91]. A REWRITE statement is attempted on a file not open in the I-O mode.

  • General Error
  • - I-O Status Value=93.An OPEN statement is attempted on a file that is not available. The availability of a file is determined by several factors, including the lock mode.

    - I-O Status Value=94.An OPEN statement is attempted at a time when there is insufficient available memory to provide the required supplementary input-output areas and control structures, or an OPEN statement is attempted for a file that has an attribute that is not supported, or an OPEN statement is attempted for a file that has file attributes that are inconsistent among themselves.

    - I-O Status Value=97.A REWRITE or WRITE statement is attempted while the record area contains one or more characters that are not legal for a line sequential file after mapping through the applicable code set.

    - I-O Status Value=98.Defective record structure has been found in the file.

    - I-O Status Value=99.A READ or REWRITE statement is attempted that refers to a record locked by another concurrent user. ThisI-O status value is returned only when the referenced file has an associated file status data item and there is an applicable USE procedure; when this is not the case, the program waits for the record to become available.

At End Condition

The at end condition can occur as a result of the execution of a Format 1 READ statement. Details regarding the circumstances that cause an at end condition are presented in the discussion of the Format 1 READ statement.

If the at end condition arises, execution of the READ statement is unsuccessful and the positioning of the file is not changed. The NOT AT END phrase and its imperative statement, if present, are ignored, and the following actions occur:

  1. If there is a file status data item associated with the file, the appropriate I-O status value (10) is stored into it.
  2. If the AT END phrase is specified in the READ statement, any USE procedure associated with the file is not executed. Control is transferred to the imperative statement specified in the AT END phrase. The imperative statement is executed according to the rules for each statement encountered in that imperative statement. If a procedure branching or conditional statement that causes explicit transfer of control is executed, control is transferred in accordance with the rules for that statement. If control reaches the end of the imperative statement in the AT END phrase, control is transferred to the end of the READ statement.
  3. If the AT END phrase is not specified in the READ statement, but an applicable USE procedure is specified either explicitly or implicitly, that procedure is performed and control is transferred to the end of the READ statement.
  4. If the AT END phrase is not specified in the READ statement and no applicable USE procedure is specified, a runtime error message is produced and execution of the run unit terminates. The runtime can be configured, as described for the DEFAULT-USE-PROCEDURE keyword of the COMPILER-OPTIONS record in Chapter Configuration, of the RM/COBOL User’s Guide, to assume that a default empty USE procedure is applicable, thus causing execution to continue at the next executable statement after the READ statement.

If the at end condition does not arise for the execution of a READ statement, the AT END phrase and its associated imperative statement, if present, are ignored, and the following actions occur in the order shown:

  1. If there is a file status data item associated with the file, the appropriate I-O status value is stored into it.
  2. If there is an error or exception condition and an applicable USE procedure is specified, either explicitly or implicitly, that procedure is performed and control is transferred to the end of the READ statement.
  3. If there is an error or exception condition and no applicable USE procedure is specified, a runtime error message is produced and execution of the run unit terminates. The runtime can be configured, as described for the DEFAULT-USE- PROCEDURE keyword of the COMPILER-OPTIONS record in Chapter Configuration, of the RM/COBOL User’s Guide, to assume that a default empty USE procedure is applicable, thus causing execution to continue at the next executable statement after the READ statement.
  4. If no error or exception condition exists and a NOT AT END phrase is present, the imperative statement in the phrase is executed according to the rules for each statement encountered in that imperative statement. If a procedure branching or conditional statement that causes explicit transfer of control is executed, control is transferred in accordance with the rules for that statement; otherwise, control is transferred to the end of the READ statement.


Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

COBOL Topics