Connecting Your Program to a File
The Select Statement is marked with color.
The File Description marked with color.
When a file that does not
exist is opened for Output, it is created. If it does exist, it is replaced by an empty
file. This concept is very important. When you Open a file for Output, you should
intend to create a new file.
Opening the file I-O is
covered in following section, “Updating the File.” The statement required to Open
the file for Input is
000110
Open Input Name-File
To update the file, you must Open it for I-O. The File Status values returned by the
Open are the same as those reported for opening the file for Input.
Open I-O Name-File
The example is as below
1 identification division.
2 program-id. seqwrite.
3 environment division.
4 input-output section.
5 file-control.
6 select studentfile assign to "mystudents.dat"
7 organization is line sequential.
8 data division.
9 file section.
10 fd studentfile.
11 01 studentdetails.
12 88 endofstudentfile value high-values.
13 02 studentid pic 9(7).
14 02 studentname.
15 03 surname pic x(8).
16 03 initials pic xx.
17 02 gender pic x.
18 procedure division.
19 begin.
20 open output studentfile.
21 display "please enter the student record using the temple"
22 display "press the enter key with no data to stop."
23 display "nnnnnnnssssssssiig"
24 accept studentdetails
25 perform until studentdetails = spaces
26 write studentdetails
27 accept studentdetails
28 end-perform
29 close studentfile
30 open input studentfile
31 display "stud-id student name gender"
32 read studentfile
33 at end set endofstudentfile to true
34 end-read
35 perform until endofstudentfile
36 display studentid " " surname space initials " " gender
37 read studentfile
38 at end set endofstudentfile to true
39 end-read
40 end-perform
41 close studentfile
42 stop run.
阅读(686) | 评论(0) | 转发(0) |