1 / 34

SEQUENTIAL FILES

SEQUENTIAL FILES. FILE-CONTROL ENTERIES FOR SEQUENTIAL FILES:. The characteristics of each of the file handled in a program are specified in the ENVIRONMENT DIVISION and DATA DIVISION.

laban
Download Presentation

SEQUENTIAL FILES

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SEQUENTIAL FILES

  2. FILE-CONTROL ENTERIES FOR SEQUENTIAL FILES: • The characteristics of each of the file handled in a program are specified in the ENVIRONMENT DIVISION and DATA DIVISION. • The characteristics that depend primarily on the input-output device and the computer system are described in the ENVIRONMENT DIVISION, while characteristics that are of a general nature are described in the DATA DIVISION

  3. SEQUENTIAL FILES: • The characteristics specified in the ENVIRONMENT DIVISION are described by means of the clause in the select entry of the FILE-CONTROL paragraph. • The remaining specifications are placed in the I-O CONTROL paragraph. The general syntax of the select entry for sequential files is as follows,

  4. SYNTAX ------ SELECT entry for sequential File SELECT [ OPTIONAL ] File-name ASSIGN TO Hardware-name [; RESERVE ] Integer-1 { AREA , AREAS } ] [; ORGANIZATION IS SEQUENTIAL ] [; ACCESS MODE IS SEQUENTIAL ] [; FILE STATUS IS Data-name-1 ]

  5. There must be one SELECT entry for each file. • The word OPTIONAL may be used only for input files. • When the object program is executed, the optional files need not be present on every occasion. • If the OPTIONAL clause is omitted for a particular file, the file must be present during the execution of the program. If the file is absent, an execution error will occur.

  6. If the OPTIONAL is coded, then if the optional file is absent ( not mapped in JCL ), any attempt to open the file for reading will not result in an error, but the absent file will be considered to be an empty file which means that the file does not contain any record. • The ASSIGN clause assigns a particular physical peripheral device name to a file. TAPE and DISK will be used to specify the hardware names for the Tape and Disk files respectively. • The RESERVE clause specifies the number of buffer to be used for the file, Integer-1 indicates the number.

  7. Thus, RESERVE 1 AREA means that only one buffer is to be used. The syntax of this clause can vary depending on the implementation. • If it is not specified (RESERVE clause), two buffers are assumed in all systems. • This ORGANIZATION clause indicates that the said file is organized as a SEQUENTIAL FILE, INDEXED FILE or RELATIVE FILE. Default is SEQUENTIAL. • This ACCESS clause indicates how the records are accessed. Sequential is default access mode and it used to access the records only in sequential order.

  8. FILE STATUS codes are used by cobol system to indicate the success or otherwise, of any file operation carried out by the program. • File status is a 2 byte code that indicates how a file operation completed , either successfully or with some form of error. If an error occurs , then file status indicates the cause of the error.

  9. For Example, • To read 100th record, first 99 records need to be read and skipped. It can also be RANDOM or DYNAMIC. • The RESERVE, ORGANIZATION, ACCESS and STATUS clause can be specified in any order. The Clause may be written starting from the B margin or any position after it.

  10. FILE DESCRIPTION – FIXED-LENGTH RECORDS • The general characteristics of a file are described in the File Description (FD) entry of the DATA DIVISION. For simplicity, only files with fixed-length records will be assumed. • The syntax of the FD entry for a tape or disk file with fixed-length records is as follows,

  11. FD file-name [; BLOCK CONTAINS integer-1 { RECORDS } ] CHARACTERS [; RECORD CONTAINS integer-2 CHARACTERS ] [; LABEL { RECORD IS } { STANDARD} ] RECORDS ARE OMITTED [; VALUE OF implementor-name-1 IS { data-name-1} Literal-1 [ implementor-name-2 IS { data-name-2}] …… ] Literal-2 [; DATA { RECORD IS } data-name-3 [, data-name-4] ……..] RECORDS ARE [; CODE-SET is alphabet-name]

  12. The FILE SECTION must contain a file description entry followed by one or more record description entries for each of the file used in a program. • The file description entry must begin with the level indicator FD followed by the file name. This file name must be identical with the file name specified in the select clause of the ENVIRONMENT DIVISION. • All these clauses are optional except one (namely, the LABEL RECORDS clause). The clauses can be written starting from the B margin or any position after it.

  13. BLOCK CONTAINS CLAUSE: • Interger-1 of the BLOCK CONTAIN clause specifies the block size either in terms of records or in terms of characters. E.g.; BLOCK CONTAINS 50 RECORDS. • If each of the record contains 150 characters, then BLOCK CONTAINS 7500 CHARACTERS. • If the BLOCK CONTAINS clause is not used, one record per block is assumed.

  14. RECORD CONTAINS CLAUSE: • This clause specifies the record size. Interger-2 specifies the number of characters in a record. Thus RECORD CONTAINS 65 CHARACTERS • means that each record of this file consists of 65 characters. The record is described completely in the record-description entries that follow the FD entry. The compiler determines the size of the record from these descriptions.

  15. LABEL RECORD CLAUSE: • This clause specifies whether or not the standard header and trailer labels should be present in the magnetic tape files. • The word STANDARD indicates that the file should have standard header and trailer labels, while the word OMITTED specifies that the file is unlabelled. • The LABEL RECORD clause for disk files should be specified with the standard option while in the case of card reader and printer, the clause should use the OMITTED option. • If the option is not specified STANDARD is assumed.

  16. VALUE OF CLAUSE: • The VALUE OF clause is entirely implementation-dependent. In most compliers this clause is used to specify the file title. The clause in such cases has the form, VALUE OF { ID } IS { data-name} IDENTIFICATION literal • The VALUE OF clause can also describe certain other items in the label records/disk directory associated with a file. A typical VALUE OF clause may be VALUE OF { ID } IS { data-name} IDENTIFICATION literal [ SAVE-FACTOR IS { data-name-1} ] literal-1

  17. DATA RECORD Clause • This clause documents the record names defined for the file. • DATA RECORDS ARE REC-1, REC-2 means that there are 2 different record description following the FD entry in which this DATA RECORDS clause is used. • The purpose of this clause is to provide for better documentation.

  18. CODE-SET Clause • The CODE-SET clause is used to describe the code in which the data is recorded on the external medium. • The CODE-SET clause is usually used for reading magnetic-tape files created on the other computer systems which can perhaps record data on files in a specific code only. • Similarly, the clause can also be used for creating a file to be read on a different system using a different code.

  19. STATEMENTS FOR SEQUENTIAL FILES: • Basic Operation on a file involves the reading and writing of its records. When the file sequential, there are three verbs READ, WRITE and REWRITE. In addition there are OPEN and CLOSE verbs. • The REWRITE verb is a special form of the WRITE verb and is only applicable to the disk files.

  20. OPEN STATEMENT: • The processing of a file should begin with the execution of an OPEN statement. A file can be opened in any one of the four open modes, INPUT, OUTPUT, EXTEND and I-O • When a file is opened in the INPUT MODE, it becomes an input file. There must be an existing file available on the specified medium. • The records in the file can be read sequentially through subsequent executions of READ statements on the file.

  21. OPEN • When a file should be created for the first time, it must be opened in the OUTPUT MODE. • Records can be placed onto the file through subsequent executions of the WRITE statements. • The EXTEND mode also opens a file for output, but the file is positioned following the last record on the existing file. • The subsequent executions of the WRITE statements on the file add more records to it.

  22. OPEN • The EXTEND mode is useful when an existing file should be appended by adding new records as its end. • The three modes are valid for both tape as well as disk files, but the I-O mode is only available for disk files. • When the file is opened in the I-O mode, records can be read through the READ statements and can be written on the file through the REWRITE statement. The WRITE statement cannot be used for files opened in the I-O mode. The syntax,

  23. OPEN-SYNTAX OPEN { INPUT } file-name-1 [ file-name-2]… OUTPUT EXTEND I-O [ { INPUT } file-name-3 [ file-name-4]…….. OUTPUT EXTEND I-O

  24. OPEN • As a result of the execution of the OPEN statement the IOCS performs certain tasks that include the testing of the availability of the file, header-label processing, allocation of buffer areas etc.

  25. CLOSE STATEMENT: The syntax, CLOSE file-name-1 [ WITH LOCK] [file-name-2 [ WITH LOCK ]]…… • The CLOSE statement terminates the processing of the file. As a result of the execution of the CLOSE statement, the IOCS performs the end of file processing. When a CLOSE statement is executed, the file must be open. A simple CLOSE statement releases the file from the program.

  26. CLOSE • The function of the CLOSE statement with the LOCK option is exactly similar to the CLOSE statement except that the file cannot be opened in the same program. • If the file is shared the locking and unlocking can be done using LOCK statement.

  27. WRITE STATEMENT: The syntax, WRITE record -name [ FROM IDENTIFIER ] • As a result of the execution of the WRITE statement, the record is released from the record area and is written onto the file. • The first execution of the WRITE statement writes the first record and subsequent executions write the record sequentially. • It may be noted that once a record has been written, the record is no longer available in the area denoted by the record name. • The file must be opened in the OUTPUT mode. The FROM option has the same meaning as in the case of line-printer files.

  28. REWRITE STATEMENT: • The REWRITE statement is used to update an existing record in the disk file. The syntax is, REWRITE record-name [ FROM IDENTIFIER ] • The REWRITE statement can only be used if the file is opened in the I-O mode and its execution must be preceded by the execution of a successful READ statement on the file. • After the execution of the REWRITE statement, the record is no longer available.

  29. Simple Program—to create SEQ file IDENTIFICATION DIVISION. PROGRAM-ID. SEQ. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT EMPFILE ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL.

  30. DATA DIVISION. FILE SECTION. FD EMPFILE LABEL RECORDS ARE STANDARD VALUE OF FILE-ID IS "EMP.DAT". 01 EMPREC. 02 EMPNAME PIC X(5). 02 EMPID PIC X(10). 02 SAL PIC 9(5). WORKING-STORAGE SECTION. 77 LAST1 PIC X VALUE "Y".

  31. PROCEDURE DIVISION. MAINPARA. OPEN OUTPUT EMPFILE. PERFORM ACC-PARA UNTIL LAST1 = "N". CLOSE EMPFILE. STOP RUN.

  32. ACC-PARA. DISPLAY “Enter Emp NAME". ACCEPT EMPNAME. DISPLAY “Enter Emp ID". ACCEPT EMPID. DISPLAY “Enter Emp SAL". ACCEPT SAL. WRITE EMPREC. DISPLAY “Do u want to give more records”. ACCEPT LAST1.

  33. FILLER CLAUSE • The FILLER clause is used for writing the information into a file in the formatted form. • Here the FILLER clause is used as a group data time and can be written as a group item with the level numbers given as usual for a group item. The syntax for writing the filler clause is Level-no FILLER PIC datatype(size).

  34. FILLER • This is a reserved word meant for writing the characters, special symbols etc needed for formatting the data in the file. Example: 01 Heads. 02 FILLER PIC X(10) “ COBOL LAB”. 02 FILLER PIC X(20) “----------------”.

More Related