Académique Documents
Professionnel Documents
Culture Documents
is used to monitor the processing of each I/O request for the file. When
specified system moves a value (which indicates the status of execution of
the statement) into the data item after each input output that implicitly
orexplicitly refers to the file.
File Status Codes :
02 -- Duplicate key was detected on READ statement was successfully
executed . This is not an error when our program includes WITH DUPLICATES
for the Key RECORD KEY clause)
04 -- Length of the record didnt confirm to the File Description
Specifications.
(fixed length attributes )
10 --No more input records . A Sequential READ statement ( READ
AT END) has been attempted , but there are no more input records.
(INVALID KEY)
21 Sequence error exists for a sequentially accessed Keyed file .
The keys are not in the correct order .
22 An attempt was made to write a record that would create a
Duplicate Primary Record key in a Keyed file.
23 An attempt was made to randomly access a record that does not
exist in the file . The required record was not found during a READ.
24 A boundary error has occurred . An attempt has been made to
write beyond the preestablished boundaries of a Keyed file. Space
not found to WRITE.
30- A Permanent hardware problem has occurred and no further
information is available .
34 A boundary error for a Sequential file has occurred . An attempt
was made to write beyond the externally described boundaries of a
sequential file.
37 An OPEN statement was attempted on a file that would not
support the mode specified in the OPEN statement ( Eg : Keyed file is
opened as OUTPUT when ACCESS IS RANDOM has been specified
Logic error condition
41 An OPEN statement has been attempted on a file that is already
open .
42 A CLOSE statement has been attempted on a file that has not
been opened
43 - An attempt was made to DELETE or REWRITE a record after an
unsuccessful READ (eg there is no record in memory to DELETE or
REWRITE .
47 The execution of a READ or START statement was attempted on a
file not opened as Input or I-O.
48 The execution of a WRITE statement was attempted on a Keyed
file not opened as I-O or OUTPUT.
ENVIRONMENT DIVISION
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT DISPLAY-FILE ASSIGN TO WORKSTATION-RBSF
ORGANIZATION IS TRANSACTION
ACCESS MODE IS DYNAMIC
RELATIVE KEY IS SUBFILE-REL-NO
FILE STATUS IS STATUS-RB
WORKING-STORAGE SECTION.
01 ERRHDL-PARAM.
05 STATUS-RB PIC X(2).
88 SUBFILE-IS-FULL VALUE 9M
4
PROCEDURE DIVISION.
DECLARATIVES.
TRANSACTION-ERROR SECTION.
USE AFTER STANDARA ERROR PROCEDURE DISPLAY-FILE
ERROR-HANDLER.
IF SUBFILE-IS-FULL THEN
NEXT SENTENCE
ELSE
DISPLAY WORK-STATION ERROR STATUS-DSP.
END-DECLARATIVES.
I-O Control : It specifies when check points to be taken and storage areas that are
shared by different files.
Journaling is a function which records the changes in a file in a Journal .
These record images are used to recover the changes in the files should the
system end abnormally .
When need Commintemetn Control : Two situations present special
problems in database applications 1) Transactiions that update multiple
records and2) concurrent updating of database files by multiple jobs .
Journaling helps avoid lost updates .
Commitment control is used to protect the integrity of database and help
recover from abnormal system termination.
COMIT operation guarantees that the group of operations is completed .
Rollback operation guarantees that the group of operations is backed out.
LOCAL DATA AREA :The system automatically creates a local data area for each job.
The local data area is defined outside the COBOL program as an area of 1024 bytes.
A COBOL program can access the Local Data Area for its job with the ACCEPT and
DISPLAY statements , using a mnemonic name associated with the function-name
LOCAL-DATA.
when a job is submitted , the submitting jobs Local data area is copied into the
submitted Jobs local data area ..if there is no submitting job, the local data area is
initialized to blanks.
There is only one local data area associated with each job . Even if several workstations
are acquired by a single job , only one data area exists for that job . there is not a local
data area for each workstation.
It is used to pass any desired information between programs in a job . This information
may be free-form data , such as information messages , or may consist of a fully
structured or formatted set of fields.
ENVIRONMENT DIVISION.
SPECIAL-NAMES.
LOCAL-DATA IS LOCAL-DATA-AREA.
WORKING-STORAGE SECTION.
01 WS-DATA-AREA PIC X(20).
PROCEDURE DIVISION.
To Read the data area and store the values in a data item.
ACCEPT WS-DATA-AREA FROM LOCAL-DATA-AREA.
To Write into the Local Data area
DISPLAY WS-DATA-AREA UPON LOCAL-DATA-AREA.
SPECIAL-NAMES.
LOCAL-DATA IS LOCAL-DATA-AREA
REQUESTOR IS OPERATOR
WORKING-STORAGE SECTION.
77
WK-LOCAL
PIC X(1024)
PROCEDURE DIVISION.
ACCEPT WK-LOCAL FROM LOCAL-DATA-AREA
ENVIRONMENT DIVISION
FILE-CONTROL
SELECT temp-file ASSIGN TO device-type file-name
ORGANIZATION IS {1. INDEXED
2. SEQUENTIAL
3. RELATIVE
4. TRANSACTION}
ACCESS MODE IS {
1. SEQUENTIAL
2. RANDOM
3. DYNAMIC}
FILE STATUS IS identifier-1.
FILE SECTION
FD TEMP-FILE.
BLOCK CONTAINS 150 CHARACTERS (USED ONLY FOR TAPE FILES)
RECORD CONTAINS 50 CHARACTERS (SIZE OF EACH RECORD)
LABEL RECORDS ARE STANDARD (ONLY FOR DOCUMENTATION)
DATA RECORD IS RECORD-FORMAT.
01 RECORD-FORMAT.
02
ITEMS PIC
.
Instead of defining the record-format we can even copy the record-format from the database file
itself using COPY statement.
FILE HANDLING
1) OPEN
OPEN
mode
file-name-1
7
mode
Ex :
OPEN INPUT
file-name-2
NEW-FILE.
2 ) CLOSE
CLOSE file-name-1, file-name-2 .
3) READ
SEQUENTIAL RETRIEVAL USING SEQUENTIAL ACCESS
Syntax:
READ file-name NEXT RECORD [INTO identifier-1]
[WITH NO LOCK]
[FORMAT IS {1. identifier-2
2. literal-1}]
[AT END imperative-statement-2]
[NOT AT END imperative-statement-2]
[END-READ]
Example:
READ
8
Example:
READ TEMP-FILE
KEY IS STUID OF TEMP-FILE
INVALID KEY DISPLAY not present
NOT INVALID KEY DISPLAY present
END-READ.
WRITE
SEQUENTIAL
Syntax:
WRITE record-name-1 FROM identifier-1
{1. BEFORE
ADVANCING {1. identifier-2
{1. LINE
2. AFTER}
2. mnemonic-name-1 2. LINES}
3. integer-1
4. PAGE}
AT {1. END-OF-PAGE imperative-statement-1
2. EOP}
NOT AT {1. END-OF-PAGE imperative-statement-1
2. EOP}
END-WRITE.
Example:
WRITE NEWREC FROM TEMPREC
AT END-OF-PAGE DISPLAY page overflow
NOT AT EOP DISPLAY continue u can still write more records
END-WRITE.
INDEXED FILES
Syntax:
WRITE record-name-1 FROM identifier-1
FORMAT IS {1. identifier-2
2. literal-1}
INVALID KEY imperative-statement-1
NOT INVALID KEY imperative-statement-2
END-WRITE.
Example:
WRITE NEW-REC FROM TEMP-REC
FORMAT IS ADDREC
INVALID KEY DISPLAY error in write statement
END-WRITE.
RELATIVE FILES
Syntax:
WRITE record-name-1 FROM identifier-1
FORMAT IS {1. identifier-2
2. literal-1}
{1. INDICATORS
{1. IS
identifier-3
2. INDICATOR 2. ARE}
3. INDIC}
9
AT {1. EOP
2. END-OF-PAGE}
NOT AT {1. EOP
2. END-OF-PAGE}
imperative-statement-1
imperative-statement-2
Example:
WRITE NEW-REC
FORMAT IS ADDREC
INDICATORS ARE INDIC-AREA.
START
Syntax:
START file-name KEY IS {1. EQUAL TO
2. =
3. GREATER THAN
4. >
5. NOT LESS THAN
6. NOT <
7. GREATER THAN OR EQUAL TO
8. >=}
{1. EXTERNALLY-DESCRIBED KEY
2. data-item-1}
FORMAT IS {1. identifier-1
2. literal-1}
INVALID KEY imperative-statement-1
NOT INVALID KEY imperative-statement-2
Example:
START EMPLOYEE KEY IS EQUAL TO
EXTERNALLY-DESCRIBED KEY
INVALID KEY DISPLAY Employee does not exist
NOT INVALID KEY DISPLAY Employee found
END-START.
REWRITE
Syntax:
REWRITE record-name-1 FROM identifier-1
FORMAT IS {1. identifier-2
2. literal-1}
INVALID KEY imperative-statement-1
NOT INVALID KEY imperative-statement-2
END-REWRITE.
Example:
REWRITE NEW-REC
FORMAT IS EDTREC.
DELETE
Syntax:
10
DELETE filename RECORD
FORMAT IS identifier-1
INVALID KEY imperative-statement-1
NOT INVALID KEY imperative-statement-2
END-DELETE.
Example:
DELETE TEMP-FILE
FORMAT IS TEMP-REC
INVALID KEY DISPLAY DELETION NOT DONE
NOT INVALID KEY DISPLAY DELETED SUCCESSFUL
END-DELETE.
SUBFILES
READ
Syntax:
READ SUBFILE filename
NEXT MODIFIED RECORD
INTO indentifier-1
FORMAT IS {1. identifier-2
2. literal-1}
TERMINAL IS {1. identifier-3
2. literal-2}
{1. INDICATORS
{1. IS
identifier-4
2. INDICATOR 2. ARE}
3. INDIC}
INVALID KEY imperative-statement-1
NOT INVALID KEY imperative-statement-2
AT END imperative-statement-3
NOT AT END imperative-statement-4
END-READ
Example:
READ SUBFILE EMPLOYEE
NEXT MODIFIED RECORD
FORMAT IS EMPSFL
INDICATORS ARE INDIC-AREA
END-READ.
WRITE
Syntax:
WRITE SUBFILE record-name-1 FROM I dentifier-1
FORMAT IS {1. identifier-2
2. literal-1}
TERMINAL IS {1. identifier-3
2. literal-1}
{1. INDICATORS
{1. IS
identifier-4
2. INDICATOR 2. ARE}
3. INDIC}
INVALID KEY imperative-statement-1
NOT INVALID KEY imperative-statement-2
END-WRITE.
11
Example:
WRITE SUBFILE EMPREC
FORMAT IS EMPSFL
INDICATORS ARE INDIC-AREA
INVALID KEY DISPLAY ERROR IN RRN VALUE
END-WRITE.
REWRITE
Syntax:
REWRITE SUBFILE record-name-1 FROM identifier-1
FORMAT IS {1. identifier-2
2. literal-1}
TERMINAL IS {1. identifier-3
2. literal-2}
{1. INDICATORS
{1. IS
identifier-4
2. INDICATOR 2. ARE}
3. INDIC}
INVALID KEY imperative-statement-1
NOT INVALID KEY imperative-statement-2
END-REWRITE.
Example:
REWRITE SUBFILE EMPREC
FORMAT IS EMPSFL
INDICATORS ARE INDIC-AREA
INVALID KEY DISPLAY ERROR IN RRN
END-REWRITE.
file-name
is used to release a device which has been acquired by the ACQUIRE statement.
Syntax:
DROP {1. identifier
2. literal}
FROM
file-name
12
05 AMOUNT-IN
PIC 9(3)V99.
01 MONTHLY-TOTAL-ARRAY.
05 MONTH-TOTAL
OCCURS 12 TIMES LIKE AMOUNT-IN(+2)
39