HP 3000 Manuals

Ch 5. Files [ HP COBOL II/XL Programmer's Guide ] MPE/iX 5.0 Documentation


HP COBOL II/XL Programmer's Guide

Chapter 5  Files 

Introduction 

Files are the basis for input and output.  Your COBOL program reads input
from files and writes output to them.

Files are also a means of interprogram communication.  Two or more
programs can communicate using a shared file.  See "DATA DIVISION: GLOBAL
Data Items and Files" in Chapter 3  and "EXTERNAL Data Items and
Files" in Chapter 4 .

Files that your program declares are called logical files.  Files that
exist outside your program are called physical files.  When you associate
a logical file with a physical file, everything that your program does to
the logical file happens to the physical file.  Before your program can
access a logical file and its associated physical file, the program must
open the file with the OPEN verb.
[REV BEG]


NOTE You should not use intrinsics to access a file opened by the COBOL OPEN statement. When you OPEN a file, the HP COBOL II/XL run-time system assumes all accesses to that file are done with COBOL statements. If you use intrinsics to access the file before closing it with the CLOSE statement, the results are unpredictable.
[REV END] This chapter presents the following: * Lists the input and output statements and which can be used with each of the four types of logical files. * Explains the four types of logical files that your program can use. * Explains how you can use variable length records. * Explains how physical files are created and associated with logical files. * Gives information on overwriting, updating, and appending to files. * Gives the status codes for file errors. Table 5-1 lists each I-O statement and how each statement is used with each file type. The following explains what each entry in Table 5-1 means: Meanings of Entries in Table 5-1 -------------------------------------------------------------- | | | | Table Entry | Meaning | | | | -------------------------------------------------------------- | | | | Comment | This verb or clause is treated as a | | | comment. | | | | -------------------------------------------------------------- | | | | Illegal | This verb or clause is illegal for this | | | file type. | | | | -------------------------------------------------------------- | | | | Optional | This verb or clause is optional. Use it if | | | you want the functionality it provides. | | | | -------------------------------------------------------------- | | | | Required | This verb or clause is required. | | | | -------------------------------------------------------------- | | | | Select one | Select any one of the items in the box with | | | this entry. | | | | -------------------------------------------------------------- | | | | Blank | This verb or clause is not applicable to | | | this file type. | | | | -------------------------------------------------------------- Table 5-1. I-O Statements and File Types ----------------------------------------------------------------------------------------------------- | I-O | I-O | How the | How the | How the | How the | | Statement | Statement | Statement | Statement | Statement | Statement | | | | Can Be Used | Can Be Used | Can Be Used | Can Be Used | ----------------------------------------------------------------------------------------------------- | Verb | Clause/Phrase | Sequential\ | Relative\ | Indexed\ Or- | Random\ | | | | Organiza- | Organiza- | ganization\ | Access\ File | | | | tion\ | tion\ | File | | | | | File | File | | | ----------------------------------------------------------------------------------------------------- - CLOSE - - - - - - - - REEL FOR REMOVAL - Comment (1) - Illegal - Illegal - Illegal - - - UNIT FOR REMOVAL - Comment (1) - Illegal - Illegal - Illegal - - - WITH NO REWIND - Optional - Illegal - Illegal - Illegal - - - WITH LOCK - Optional - Optional - Optional - Optional - ----------------------------------------------------------------------------------------------------- - FD - - Required - Required - Required - Required - - - BLOCK - Optional - Optional - Optional - Optional - - - RECORDING MODE - Optional - Optional - Optional - Optional - - - RECORD CONTAINS - Optional - Optional - Optional - Optional - - - LABEL RECORDS - Optional - Optional - Optional - Optional - - - VALUE OF - Optional - Optional - Optional - Optional - - - DATA RECORDS - Comment - Comment - Comment - Comment - - - LINAGE - Optional - Illegal - Illegal - Illegal - - - WITH FOOTING - Optional - - - - - - LINES AT TOP - Optional - - - - - - LINES AT BOTTOM - Optional - - - - - - CODE-SET - Optional - Illegal - Illegal - Illegal - ----------------------------------------------------------------------------------------------------- - OPEN - - - - - - - - INPUT - Select one - Select one - Select one - Select one - - - REVERSED - Comment - Illegal - Illegal - Illegal - - - NO REWIND - Comment - Illegal - Illegal - Illegal - - - OUTPUT - Select one - Select one - Select one - Select one - - - NO REWIND - Comment - Illegal - Illegal - Illegal - - - I-O - Select one - Select one - Select one - Select one - - - EXTEND - Optional - Optional - Optional - Illegal - ----------------------------------------------------------------------------------------------------- - READ - - - - - - - - NEXT RECORD - Optional - Optional - Optional - Optional - - - INTO IDENTIFIER - Optional - Optional - Optional - Optional - - - AT END - Optional - Optional - Optional - Optional - - - NOT AT END - Optional - Optional - Optional - Optional - - - INVALID KEY - Illegal - Optional - Illegal - Optional - - - NOT INVALID KEY - Illegal - Optional - Illegal - Optional - - - KEY IS - Illegal - Illegal - Optional - Illegal - - - INVALID KEY - Illegal - Illegal - Optional - Illegal - - - NOT INVALID KEY - Illegal - Illegal - Optional - Illegal - ----------------------------------------------------------------------------------------------------- Table 5-1. I-O Statements and File Types (cont.) ----------------------------------------------------------------------------------------------------- | I-O | I-O | How the | How the | How the | How the | | Statement | Statement | Statement | Statement | Statement | Statement | | | | Can Be Used | Can Be Used | Can Be Used | Can Be Used | ----------------------------------------------------------------------------------------------------- - REWRITE - - - - - - - - FROM IDENTIFIER - Optional - Optional - Optional - Optional - - - INVALID KEY - Illegal - Optional - Optional - Optional - - - NOT INVALID KEY - Illegal - Optional - Optional - Optional - ----------------------------------------------------------------------------------------------------- - SELECT - - Required - Required - Required - Required - - - OPTIONAL - Optional - Optional - Optional - Optional - - - ASSIGN - Required - Required - Required - Required - - - RESERVE - Optional - Optional - Optional - Optional - - - ORGANIZATION - Optional - Required - Required - Illegal - - - RELATIVE - Illegal - Required - Illegal - - - - SEQUENTIAL - Optional - Illegal - Illegal - - - - INDEXED - Illegal - Illegal - Required - - - - ACCESS MODE - Optional - Optional - Optional - Required - - - SEQUENTIAL - Optional - Optional - Optional - Illegal - - - RELATIVE KEY - Illegal - Optional - Illegal - - - - RANDOM - Illegal - Optional - Optional - Required - - - RELATIVE KEY - Illegal - Optional - Optional - Illegal - - - ACTUAL KEY - Illegal - Illegal - Illegal - Optional - - - DYNAMIC - Illegal - Optional - Optional - Illegal - - - RELATIVE KEY - - Required - Illegal - - - - RECORD KEY - Illegal - Illegal - Required - Illegal - - - WITH DUPLICATES - - - Optional - - - - ALTERNATE KEY - Illegal - Illegal - Optional - Illegal - - - WITH DUPLICATES - - - Optional - - - - FILE STATUS - Optional - Optional - Optional - Optional - - - ACTUAL KEY - Illegal - Illegal - Illegal - Required - ----------------------------------------------------------------------------------------------------- - SD - - Illegal - Illegal - Illegal - Illegal - - - RECORD CONTAINS - - - - - - - DATA RECORD - - - - - ----------------------------------------------------------------------------------------------------- - WRITE - - - - - - - - FROM IDENTIFIER - Optional - Optional - Optional - Optional - - - BEFORE ADVANCING - Optional - Illegal - Illegal - Illegal - - - AFTER ADVANCING - Optional - Illegal - Illegal - Illegal - - - AT END OF PAGE - Optional - Illegal - Illegal - Illegal - - - NOT AT END OF PAGE - Optional - Illegal - Illegal - Illegal - - - INVALID KEY - Illegal - Optional - Optional - Optional - - - NOT INVALID KEY - Illegal - Optional - Optional - Optional - ----------------------------------------------------------------------------------------------------- (1) This phrase causes the CLOSE statement to be treated as a comment. The file is left open.


MPE/iX 5.0 Documentation