This
cobol example will show the basics for reading a file. It shows how to open the file, define the file, and read the file. It also shows the cobol variables and how they are defined, but of course some things are left out like how you want to loop through to read all the input data, etc., and of course you will want to close the file when done. This example will use cobol to open and read a variable length file that has 4000 bytes per row max. It also shows how to check the open and read to make sure it was successfull.
In your I/O section:
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT FILE-IN ASSIGN TO FILE-NAME-IN
FILE STATUS IS WS-STATUS-IN.
In your data division:
DATA DIVISION.
FILE SECTION.
FD FILE-IN
RECORDING MODE IS V.
01 SAMPLE-INPUT-PROF PIC X(4000).
In working storage, define:
05 WS-STATUS-IN PIC 9(02) VALUE ZERO.
In your cobol code:
OPEN INPUT SAMPLE-FILE
IF WS-STATUS-IN = 0
(You will loop through the reads)
READ FILE-IN INTO WS-I-REC
AT END
(Do something like close the file when done)
END-READ
EVALUATE WS-STATUS-IN
(Do something with various conditions)
END-EVALUATE
ELSE
(Do something if you had an open error)
END-IF
This site provides a list of interesting subjects, tips, and tricks. Although it is mostly computer tips,
there are also tips and tricks related to various other helpful topics besides just computers.
If you have an important tip that you think should be listed, feel free to post it below.
Although I still take tips via email, I often scan and review posts on the page below and prefer that method.