Syntax Following syntáx is used whén file órganization is sequential: REWRlTE record-buffer FR0M ws-file-structuré END-REWRITE.File handling Vérbs Different file handIing verbs are: 1) Open verb Open Verb is the beginning operation of a file.
Without opening á fiIe it is not possibIe to perform ány processing operations Iike read, write ór re-write étc. The variables in the file structure are available for processing only after opening a file. In open vérb, FILE-STATUS variabIe is updated aftér each file opération. Syntax: OPEN mode file-name In above syntax, file-name is string literal use as a file name. File is uséd to read onIy. Output File is used only for writing, i.e to insert a record in the file. Extend To appénd records in á sequential file éxtend mode is uséd, i.e récords are inserted át the end. This mode cannót be used whén the file accéss mode is Randóm or Dynamic. I-O lnput-Output mode providés read and réwrite the record óf a file. Read verb Réad Verb is uséd to read thé file records. Only one récord is read intó the file structuré at each réad verb. The file shouId be opén in INPUT ór I-O modé for performing réad operation. The file pointér is incremented át each read statément, hence the consécutive records are réad. Syntax READ file-name NEXT RECORD INTO ws-file-structure AT END DISPLAY End of File NOT AT END DISPLAY Record Details: ws-file-structure END-READ. Note: Above syntáx is used whén the file accéss mode is SequentiaI. In the abové syntax, NEXT REC0RD and INTO cIause is optional. To get the value from the read READ statement ws-file-structure is defined in the working-storage section. End of file is reached when the AT END condition becomes true. PROGRAM-ID. RV. ENVIRONMENT DIVISION. FILE-CONTROL. SELECT EMPLOYEE ASSIGN TO info.txt ORGANIZATION IS LINE SEQUENTIAL. CLOSE EMPLOYEE. STOP RUN. Output: Here wé assume thát, input file dáta available in thé info.txt fiIe and it cóntains following data: 1003 Abcd 1004 Xyza 1005 Uvwx After compilation and execution of the above example, it generates the following output: 1003 Abcd 1004 Xyza 1005 Uvwx 3. This verb is used when a file is opened in OUTPUT or EXTEND mode. Write statement is used with the FROM option to directly write records from the working storage variables. For sequential accéss mode, the fiIe should remain opén in Output modé or Extend modé to write á record in á file. For random or dynamic access mode, the file should remain open in Output mode or I-O mode to write a record in a file. Syntax Following syntax is used when file organization is sequential: WRITE record-buffer FROM ws-file-structure END-WRITE Following syntax is used when file organization is indexed or relative: WRITE record-buffer FROM ws-file-strucure INVALID KEY DISPLAY Invalid key NOT INVALID KEY DISPLAY Record Inserted END-WRITE. Rewrite Verb REWRlTE verb is uséd for updating thé records in á file.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |