COBOL file operation

xiaoxiao2021-03-06  19

To use files in COBOL, put information on 3 different parts.

The Ministry of Environment, the file control project (file-control) for each file used by the program. This project links the file name used in the program to the actual file outside the program. These projects also define the organization and access of the file.

The data department, the file descriptor (FD) project for each file is data definition.

The process department puts the top handling statement, Open, Read, Write, Delete, etc.

The Ministry is mainly used by File-Control and I-O-Control.i-O-Control rarely. Select [optional] file-name assign to dev / file [reserve n [area / allas]] [File Status is var] select must be the first sentence, other order is independent. File-name is the file name delivered in the program, which is equivalent to an alias of the actual file. Optional is used to perform files that may not exist. Assign connects file-name to the actual external device or file. (TO seems to be omitted.) RESERVE Specifies the file buffer. File status Specifies a variable to store file status, which should have been defined in Working-Storage Section.

For sequential files, there is also a declaration: [Organization IS Sequential] Optional, default to sequential organization file [Access Mode Is Sequential] optional. Sequential files only allow sequential access [Padding Character IS Char] Specify the character used by the file on the fixed block long device, char as a character's data item. [RECORD DELIMITER IS Standard / USR-Define] Specifies how to determine the length of the growing record. Order file example: select file-name assign to "/ usr / file1" file status is file-status

For relative files, there is a declaration as follows: [Organization is relative] is 3 kinds of relative files must be required [Access Mode Is Data]] or [Access Mode Is Random / Dynamic Relative Key IS Data]. The default is Sequential. Relative Key is optional. If there is, the file read operation is complete, and the data updated with the keyword read by the record. Data should be an integer data item that is not in the record area of ​​the file. Example of relative file: select file-name assign to "/ usr / file2" Organization is Relative Access Mode Is Dynamic Relative Key Is Day-Number File Status is file-status

For index files, there is also the following: [Organization is indexed] is the index file must be required [Access Mode Is Sequential / Random / Dynamic] Record Key Is Data1 [Alternate Record Key Is Data2 [with duplicates]] There are 3 ways. The default is Sequential. Record Key Specifies the main record keyword of the file, DATA1 should be an alphanumeric data item that defines a record area of ​​the file. The description of this keyword and its location in the data record should be consistent with the keywords used when generating files. Alternate Record Key If the file has replaces the keyword, its keyword is specified by this slave phrase, and the DUPLICATES.COBOL is required to define DATA2 when repeating the keywords in the index. Repeating keywords and its location in data records should be consistent with generated files, all replacement keywords should be placed in the file control item. Examples of the index file: SELECT file-name ASSIGN TO "/ usr / file3" ORGANIZATION IS INDEXED ACCESS MODE IS RANDOM RECORD KEY IS NUMBER OF EMPLOYEE-RECORD ALTERNATE RECORD KEY IS LAST-NAME OF EMPLOYEE-RECORD WITH DUPLICATES ALTERNATE RECORD KEY IS SS -Number of Employee-Record File Status is file-status Here the file name used in the program is file-name, the actual file name is file3. File-name defines in the file section of the data unit behind the program. The file is an index file, and the program can be randomly accessed. The main keyword of the file is Number of Employee-Record, replacing the keyword is Last-Name and SS-NUMBER, all fields of the file record area. Last-name allows you to repeat.

File status: (return file status to the file status to the defined file status variable) Any 00 successfully ANY 02 The index file is successful but found that the keyword read 04 is successful, but the record length does not meet the specified length Open 05 success, but the file It is optional, there is no Open, Close 07 to the order file, success, but the medium is not the tray Read 10 files have arrived at the end of the READ 14 pairs of relative files, the relative record number is more than the relative keyword data item allowed by the relative keyword data item ReWrite 21 pairs of index files, sequential error Write 22 pairs of indexes and relative files, with this keyword record already exists in START, READ 23 to index and relative files, with this keyword record does not exist Write 24 pair of relative files, relative Record number valid bits exceed bit ANY 30 I / O Error Write 34 for the relative keyword data item, the sequential file, the hyperbide error Open 35, the order and relative file, did not find non-optional file Open 37 to the order and relative Document, the file does not support the specified open mode Open 38 pairs of order and relative files, files have been used to turn off the Open 39 to the order and relative file, file attributes do not support the properties specified in the program Open 41 file has been opened. Close 42 file is not open. DELETE, REWRITE 43 The recent operation is not Read Write, the Rewrite 44 Record Length Illegal illegal READ 46 does not have a valid next record read, Start 47 file is not open in the Input or IO method to open the WRITE 48 file in Output or Extend to open Delete, The REWRITE 49 file does not open the ANY 90 ~ 99 definition in the IO method, and the file is incorrect, and COBOL is provided. Check the public location for errors and recovery I / O errors. The beginning of the process should include a Declaratives section, placing the statement to be executed when an error occurs. PROCEDURE DIVISION. DECLARATIVES. Section-name SECTION. USE statement (section called when an error occurs). Paragraph-name. Sentence ... END DECLARATIVES. Section-name SECTION. Paragraph-name. Sentence ... USE AFTER STANDARD EXCEPTION / ERROR Procedure ON file-name / input / output / IO / extend can only specify a file in the USE statement, and one way can only have a USE statement. If the file is specified, the file is also specified, then the file is preferred.

All files used by the program are defined in the first quarter of the data unit --- Document section. FD File-Name [Block Contains Int-1 [To INT-2] Records / Characters] [Record (Contains INT-3 [To Int-4] Characters / (is varying in size [from int-5] [to int -6] Characters / (Depending On Data1) [Label (Records Are) Standard / OMIMTED] [Value of (Implementor-Name ID-LIT-1) ...] [Data (Record IS) / (RECORDS Are) DATA2] Block ContainS Specifies the specific length or maximum logical record number or number of blocks with the minimum length of the actual record. Generally there are operating systems and file systems designation. Record specifies the maximum length of the minimum length or a fixed-length record recorded in a file that contains the growing record. Record Contains If not to take, INT-3 is the length of each record; if the TO is tou, between INT-3 and INT-4. Record is varying Specifies the minimum INT-5 and maximum INT-6 in record length. Depending On is required, you need to save record lengths in DATA1. Label Record specifies whether the file is labeled. (Outtime, the next version does not include) Value and Label check the different parts of the label. (Out of time, the next version does not include) Data Record specifies a documentary description item belonging to a file (01 layer item after the FD) and as a program document. (Outtime, the next version does not include) General definition files Using only the first sentence: fd file-name sequential file LINAGE declaration to sequential file, the Linage declaration can specify some print details when the file output is a printer or printer compatible file. [Linage Is Body Lines [WITH FOOTING AT FOOT] [Lines At Bottom Bottom]] [Code-Set IS Alphabet-Name] The entire file is divided into top, body, bottom. Where the body contains the character set used in the FOOT. Code-Set specified file.

The process is mainly operated on the Open, Close, Read, Write, Start, Rewrite, Delete, etc. of the file. Open open files have 4 ways: (if the file declares as optional, the file does not exist if the file will be created, otherwise the error will be reported) Open INPUT FILE-name. Only the file can be read. Open output file-name. Generate a write record file that reads the file error. If the file already exists, the already record will be removed. Open i-o file-name. Readable file. Open extend file-name. Generate a write file. The difference from UOTPUT is that if the file already exists, Extend adds a record at the end of the file. If the Open is unsuccessful, perform a USE statement. The USE statement does not exist, then the program ends. The OPEN of the sequential file can have the following way: Open input file-name [(with no rewind) / reverse]. Open output file-name [with no shutind]. Reverse can be in reverse sequence, that is, the rearward process. (Out of time, the next version does not include) with no shutind For single volume tape files, if the specified file is ignored on the medium that does not apply to Rewind, ignore. Specifying the Linage sequential file in the file description item cannot be opened in an extend. Close method for all files: Close file-name. Close the file. Close file-name with lock. Close the file, no exit program can no longer open this file. There are other options, such as closing volumes or units, and continuing to process files: close file-name [reel / unit] [for removal] / with no rain

Read sequence access to the file. Be sure to have a NEXT word. Read file-name [Next] Record [INTO DATA1] [At end "] [NOT-READ] If Read is successful and INTO, the read data is written to DATA1. If there is no record in the file, execute At endStatements, if you don't do it. If Read is successful, the Not at STATEments are performed.

Dynamic access method read files. (The opposite or index file) uses the Open statement to set the file pointer at the beginning. Make a variety of successful READ operations. There is a record in the START statement identification file.

Random access is read. Read file-name record [INTO DATA1] [INVALID Key Statements] [NOT-RALID Key Statements] [end-read] If read successfully and INTO, the read data is written to DATA1. If there is no record in the file, execute the Invalid Key Statements, if you don't do it. If Read is successful, do Not Invalid Key Statements. If it is a relative file, you want to set the integer keyword value specified in the file control Item Relative Key to execute the read. If it is an index file, you want to set the current index keyword value to execute the READ.

Write order. Write data [from data1] [before / after advancing mnemonic-name / page / n line (line)] [at end-of-page (eop) statements] [NOT End-of-Page (ED) Statements] [end -Write] If you specify from FROM, copy DATA1 to DATA and write to files. Before / after advancing n line (lines) inserts N of N spaces in a record. At end-of-page (EOP) is valid for files with Linage, when Write enters footer (FOOT), execute WRITE, and then execute at end-of-page (EOP) statements. Relative and index file mode. Write data [from data1] [invalid key statements] [not invalid key statements] [end-write]

The ReWrite replaces a record in the file. Sequential mode: REWRITE DATA [From Data1] [end-shutrite] Relative and index mode: REWRITE DATA [from data1] [invalid key statements] [not invalid key statements] [end-shutie]

DELETE deletes a record in the file. Only files that can only be used for opposite or index tissue. DELETE File-Name Record [Invalid Key Statements] [end-delete] [end-delete] If the previous read record is deleted. If random or dynamically accessed, the contents of the Relative Key or the record represented by the primary keyword are removed from the file.

Start positions a relative or index file to a record to sequentially access it. Only valid for the relative and index files. Start file-name [key is (equal to) / = / greater than /> / not length than / not

转载请注明原文地址:https://www.9cbs.com/read-49560.html

New Post(0)