Académique Documents
Professionnel Documents
Culture Documents
Field
16
7
8 11
12 72
72 80
Sequence
Indicator (*, /, -)
Area A / Margin A
Area B / Margin B
Identification
Page 1 of 30
Arithmetic Operators
Binary Operators
Addition (+)
Subtraction (-)
Multiplication (*)
Division (/)
Exponentiation (**)
Unary Operators
Positive (+)
Negative (-)
Conditional Expressions
Simple Conditions
Class Condition
To determine the type of the data-item
Syntax:
identifier [IS [NOT]] {1. NUMERIC
2. ALPHABETIC
3. ALPABETIC-LOWER
4. ALPHABETIC-UPPER
5. class-name}
Example:
NAME IS ALPHABETIC-UPPER
TOTAL IS NOT ALPHABETIC
Condition Name Condition
A condition-name condition tests a conditional variable to determine whether its
value is equal to any value(s) associated with the condition-name.
Example:
01 GENDER PIC X.
88 MALE
VALUE
M.
88 FEMALE
VALUE
F.
..
..
PROCEDURE DIVISION
..
..
IF MALE THEN
Page 2 of 30
Relation Condition
A relation condition compares two operands
Syntax:
Operand1 [IS [NOT]] {1. GREATER THAN [OR EQUAL TO] operand2
2. >[=]
3. LESS THAN [OR EQUAL TO]
4. <[=]
5. EQUAL TO
6. =}
Example:
MARK IS GREATER THAN 40
NAME IS = VANI
Sign Condition
Syntax:
Operand1 [IS NOT]] {1. POSITIVE
2. NEGATIVE
3. ZERO}
Example:
MARK IS POSITIVE
DIVIDENT IS NOT ZERO
Switch-Status Condition
The switch-status condition determines the on or off status of an UPSI switch.
The condition has to be specified in the SPECIAL NAMES para.
Complex Conditions
Negated Simple Conditions
NOT of a simple condition
Syntax:
NOT <simple-condition>
Example:
NOT A IS > B
Combined Conditions
Two or more conditions can be logically connected to form a combined condition.
Syntax:
Condition-1 {1. AND Condition-2
2. OR}
Page 3 of 30
Equivalent
A NOT > B OR C
NOT A = B OR C
NOT (A = B OR < C)
NOT (A NOT = B AND C AND NOT D)
ENVIRONMENT DIVISION
FILE-CONTROL
Example:
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.
DATA DIVISION
LEVEL NUMBER
LEVEL NO.
01
02 49
66
USAGE
GROUP ITEM
SUB ITEMS
RENAMES
Page 4 of 30
CONDITION-NAME-CONDITION
ELEMETARY DATA ITEM
Example:
01 GROUP-ITEM
02
SUB-ITEM1 PIC X(5).
02
SUB-ITEM2 PIC X(5).
02
SUB-ITEM3 PIC X(5).
02
SUB-ITEM4 PIC X(5).
02
SUB-ITEM5 PIC X(5).
02
SUB-ITEM6.
03
SUB-SUB-ITEM1 PIC 9(2).
03
SUB-SUB-ITEM2 PIC 9(2).
66
NEW-ITEM RENAMES SUB-ITEM1
THROUGH SUB-ITEM4.
77
ELEMENTARY-ITEM
PIC 9(2).
77
MARITAL-STATUS PIC X.
88
MARRIED VALUE
M.
88
SINGLE
VALUE
S.
FILE SECTION
Example:
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.
REDEFINES
Using REDEFINES statement we can change the format or name of a particular dataitem provided the length is same in both the case. Both the data-items will share the
same memory but they can be referred with 2 different names.
Example:
05 REGULAR-EMPLOYEE.
10 LOCATION
10 GRADE
PICTURE
PICTURE
Page 5 of 30
A(8).
X(4).
999V999.
ARITHMETIC VERBS
ADD
Syntax1:
ADD {1. identifier-1 [, {1. identifier-2 .. TO identifier-3 [, identifier-4].....
2. literal-1}
2. literal-2}]
Example1:
ADD A, 10 TO B, C
Before Add: A = 5
B=5
C = 10
After Add: A = 5
B = 20
C = 25
Syntax2:
ADD {1. identifier-1 {1. identifier-2 [, {1. identifer-3.
2. literal-1}
2. literal-2}
2. literal-3}]
GIVING identifier-4 [, identifier-5]..
Example2:
ADD A , 10 GIVING B, C.
Before Add: A = 5
B=5
C = 10
After Add: A = 5
Page 6 of 30
SUBTRACT
Syntax:
SUBTRACT {1. identifier-1 [, {1. identifier-2
2. literal-i}
2. literal-2}]
FROM identifier-3 [, identifier-4]..
[GIVING identifier-5 [,identifier-6]]
Example:
Before Subtract: A = 5
B=3
C = 10
D = not defined
SUBTRACT A, B FROM C
After Subtract: A = 5
B=3
C = 2 (10 5 3)
D = not defined
SUBTRACT A, B FROM C GIVING D.
After Subtract: A = 5
B=3
C = 10
D = 2 ( 10 5 3)
MULTIPLY
Syntax:
MULTIPLY { 1. identifier-1 BY identifier-2 [, identifier-3]..
2. literal-1}
[GIVING identifier-4 [, identifier-5].]
Example
Before Multiply: A = 5
B=3
C = 10
D = not defined
E = not defined
MULTIPLY A BY B, C.
After Multiply: A= 5
B = 15 (A*B)
C = 50 (A*C)
D = not defined
E = not defined
MULTIPLY A BY B, C GIVING D, E
After Multiply: A = 5
Page 7 of 30
DIVIDE
Syntax1:
DIVIDE {1. identifier-1 INTO identifier-2 [, identifier-3] .
2. literal-1}
[GIVING identifier-4 [, identifier-5]]
Example1:
Before Divide: A = 10
B = 20
C = not defined
D = not defined
DIVIDE 2 BY A, B.
After Divide: A = 5
B = 10
C = not defined
D = not defined
DIVIDE 2 BY A, B GIVING C, D.
After Divide: A = 10
B = 20
C=5
D = 10
Syntax2:
DIVIDE {1. identifier-1 BY {1. identifier-2
Literal-1}
literal-2}
GIVING identifier-3 [,identifier-4].
Example2:
DIVIDE A BY B GIVING C.
Before Divide: A = 20
B = 10
C = not defined
After Divide: A = 20
B = 10
C=2
Syntax3:
DIVIDE {1. identifier-1 {1. INTO {1. identifier-2
2. literal-1}
2. BY}
literal-2}
GIVING identifier-3 [REMAINDER identifier-4]
Example3:
DIVIDE A BY B GIVING C REMAINDER D
Before Divide: A = 20
Page 8 of 30
COMPUTE
Syntax:
COMPUTE identifier-1 [ROUNDED] = arithmetic expression
[[ON] SIZE ERROR imperative-statement-1]
[NOT [ON] SIZE ERROR imperative-statement-2]
[END-COMPUTE]
Example:
COMPUTE A ROUNDED = (A + B) * 3.5 / 2
ON SIZE ERROR DISPLAY ERROR.
Page 9 of 30
DISPLAY
Syntax:
DISPLAY {1. identifier-1 [, {1. identifier-2 . [UPON mnemonic-name]
2. literal-1}
2. literal-2}]
Refer the ACCEPT verb for explanation for mnemonic-name
Example:
DISPLAY THE TOTAL IS TOTAL.
NESTED IF
If an IF Statement occurs within another IF Statement, its referred as Nested IF.
Example:
IF A > B
IF A > C
DISPLAY A IS GREATEST
END-IF
END-IF.
CONTINUE
The CONTINUE statement may be used anywhere a conditional statement or an
imperative statement may be used. It has no effect on the execution of
the program.
Example:
IF A > B
CONTINUE
ELSE
COMPUTE A = A + 1
END-IF.
Page 10 of 30
GO TO
Syntax:
GO TO procedure-name-1 [, procedure-name-2procedure-name-n]
DEPENDING ON identifier
Example1:
GO TO exit-para
Example2:
GO TO FIRST-PARA, SECOND-PARA, THIRD-PARA
DEPENDING ON VALUE.
This statement is equivalent to the set of IF conditions
IF VALUE = 1 GO TO FIRST-PARA.
IF VALUE = 2 GO TO SECOND-PARA.
IF VALUE = 3 GO TO THIRD-PARA.
ALTER STATEMENT
ALTER Statement can be used to modify the targets of GO TO statements written
elsewhere.
Syntax:
ALTER procedure-name-1 TO [PROCEED TO] procedure-name-2
[, procedure-name-3 TO [PROCEED TO] procedure-name-4].
Example:
MODIFIED-TRANSFER.
GO TO FIRST-TIME.
Suppose this GO TO Statement is to be modifier after its first execution so
that the subsequent execution of the sentence transfers control to the procedure named
OTHER-TIMES we have to code as follows
ALTER MODIFIED-TRANSFER TO PROCEED TO OTHER-TIMES.
After the execution of this ALTER Statement, the GO TO sentence
becomes
MODIFIED-TRANSFER.
GO TO OTHER-TIMES.
PERFORM STATEMENT
Syntax1:
PERFORM procedure-name-1 [{1. THRU
2. THROUGH}
Example1:
PERFORM FIRST-PARA THRU LAST-PARA.
Syntax2:
PERFORM procedure-name-1 [{1. THRU
2. THROUGH}
{1. identifier TIMES
Page 11 of 30
procedure-name-2]
procedure-name-2]
Page 12 of 30
{1. identifier-9
2. literal-6}
UNTIL
2. index-name-6
3. literal-5}
condition-3].]
Example6:
PERFORM READ-MATRIX-PARA
VARYING I FROM 1 BY 1 UNTIL I > 3
AFTER J FROM 1 BY 1 UNTIL J > 3.
This is equivalent to
For (i=1; I <= 3; i++)
For (j=1; j<=3; j++)
{
...
...
}
EVALUATE
Syntax:
EVALUATE { 1. identifier-1
[ALSO {1. identifier-2
2. literal-1
2. literal-2
3. expression-1
3. expression-2
4. TRUE
4. TRUE
5. FALSE}
5. FALSE}]
WHEN phrase-1 [ALSO phrase2.] imperative-statement-1
[WHEN OTHER imperative-statement-2]
[END-EVALUATE]
where phrase-1 and phrase-2 are defined as
{1. ANY
2. condition
3. TRUE
4. FALSE
5. [NOT] {1. identifier
[{1. THRU
{1. identifier
2. literal
2. THROUGH} 2. literal
3. arithmetic-expression}
3. arithmeticexp.}]
Example1:
EVALUATE VALUE
WHEN 1
DISPLAY ONE
WHEN 2
DISPLAY TWO
WHEN 3
DISPLAY THREE
WHEN OTHER
Page 13 of 30
Main Program
Non operational
Return to calling
program(may be the OS)
Return to the calling
Page 14 of 30
Sub Program
Return to calling program
Return to the calling
program
Return to calling program
EXIT
identifier-2]
3. literal-2
4. file-name-1}]]
{1. [[ON] OVERFLOW imperative-statement-1]
2. [[ON] EXCEPTION imperative-statement-2]
[NOT [ON] EXCEPTION imperative-statement-3]}
[END-CALL]
Using
To pass the parameters to the called program.
Reference BY
To pass the parameters as pointers(address of the variables)
Content BY
To pass the parameters as value(pass by value)
ADDRESS OF
To get the address of a data-item
LENGTH OF
Returns the no. of bytes required for the particular data-item
ON EXCEPTION
When the call to the sub-program cannot be made
NOT ON EXCEPTION
If there is no exception
OVERFLOW
Same as ON EXCEPTION
Page 15 of 30
CANCEL
The cancel statement ensures the next time the program is called it will be entered in its
initial state. (ie) It disconnects the logical connection between the calling program and
called program. (ie) closes all files, re-initialize the variable to its initial state and so on.
Syntax:
CANCEL {1. identifier-1
2. literal-1}
INSPECT
This is similar to the EXAMINE verb except for it doesnt maintain a special register
TALLY instead it stores the count in a separate variable. The tally count value will be
added to the identifier.
Syntax1:
INSPECT identifier-1 TALLYING
[identifier-2 FOR {1. {1. ALL
{1. identifier-3
2. LEADING}
2. literal-1}
2. CHARACTERS}
[{1. BEFORE
INITIAL
{1. identifier-4
2. AFTER}
2. literal-2}]]
Example:
77 MY-STRING PIC X(20) VALUE ANANTA KUMAR MAITY
77 TALLY-COUNT PIC 9(2) VALUE 0.
INSPECT MY-STRING TALLYING TALLY-COUNT FOR ALL A.
TALLY-COUNT = 5
INSPECT MY-STRING TALLYING TALLY-COUNT FOR LEADING A.
TALLY-COUNT = 1
INSPECT MY-STRING TALLYING TALLY-COUNT FOR CHARACTERS.
TALLY-COUNT = 20
INSPECT MY-STRING TALLYING TALLY-COUNT FOR ALL A
AFTER INTIAL A AND BEFORE INTIAL T.
TALLY-COUNT = 3 (NAN)
Syntax2:
INSPECT identifier-1 REPLACING
{1. CHARACTERS BY {1. identifier-5 {1. BEFORE INITIAL {1. identifier-6
2. literal-3}
2. AFTER}
2. lieral-4}
2. {1. ALL
{1. identifier-7 BY {1. identifier-8
2. LEADING
2. literal-5}
2. literal-6}}
3. FIRST}
[{1. BEFORE
INITIAL
{1. identifier-9
2. AFTER}
2. literal-7}]
Example:
INSPECT AMOUNT REPLACING LEADING BY 0.
INSPECT KARD REPLACING ALL % BY (, < BY ),
BY +.
Syntax3:
Page 17 of 30
STRING
Used to combine 2 or more strings to a single string.
Syntax:
STRING {1. identifier-1
[{1. identifier-2
2. literal-1}
2. literal-2}]
DELIMITED BY {1. identifier-3
2. literal-3
3. SIZE}
[{1. identifier-4 [{1. identifier-5
2. literal-4}
2. literal-5}]
DELIMITED BY {1. identifier-6
2. literal-6
3. SIZE}]
INTO identifier-7 [WITH POINTER identifier-5]
[ON OVERFLOW imperative-statement]
Example:
77 FIELD-1 PIC X(4) VALUE
RAIN.
77 FIELD-2 PIC X(4) VALUE
SPACES.
STRING FIELD-1 DELIMITED BY I INTO FIELD-2
FIELD2 = RA
Example:
77 FIELD-1 PIC X(4) VALUE
ABCD.
77 FIELD-2 PIC X(6) VALUE
MA IN .
77 FIELD-3 PIC X(9) VALUE
121,34,56.
77 FIELD-4 PIC X(14) VALUE
SPACES.
STRING FIELD-1, FIELD2, FIELD3 DELIMITED BY , ,,
INTO FIELD-4.
FIELD-4 = ABCDMA121 .
Example:
77 FIELD-1 PIC X(4) VALUE
ABCD.
77 FIELD-2 PIC X(6) VALUE
MA IN .
77 FIELD-3 PIC X(9) VALUE
121,34,56.
77 FIELD-4 PIC X(14) VALUE
SPACES.
77 CHARACTER-POSITION PIC 9(2) VALUE 3.
STRING FIELD-1, FIELD-2, FIELD-3 DELIMITED BY
Page 18 of 30
NAME.
03
FIRST-NAME
PIC X(10).
03
MIDDLE-NAME
PIC X(6).
03
SURNAME
PIC X(20).
Suppose we want to store the name in the order as surname+first+middle,
Define the following also,
77
OUTPUT-REC
PIC X(39).
77
A
PIC X
VALUE
SPACE.
STRING SURNAME DELIMITED BY SPACES
A DELIMITED BY SIZE
FIRST-NAME DELIMITED BY SPACES
A DELIMITED BY SIZE
MIDDLE-NAME DELIMITED BY SPACES
INTO OUTPUT-REC.
UNSTRING
Syntax:
UNSTRING identifier-1
[DELIMITED BY [ALL] {1. identifier-2 [OR [ALL] {1. identifier-3
2. literal-1}
2. literal-2}]]
INTO identifier-4 [DELIMITER IN identifier-5]
[COUNT IN identifier-6]
[identifier-7 [DELIMITER IN identifier-7]
[COUNT IN identifier-8]]
[WITH POINTER identifier-9]
[TALLYING IN identifier-11]
[ON OVERFLOW imperative-statement]
Example:
77 FIELD-1 PIC X(10).
77 FIELD-2 PIC X(10).
77 FIELD-3 PIC X(15).
77 DATA-FIELD
PIC X(38) VALUE A.K. KRISHNAMURTHY.
UNSTRING DATA-FIELD DELIMITED BY .
INTO FIELD-1, FIELD-2, FIELD-3.
FIELD-1 = A
FIELD-2 = K
FIELD-3 = KRISHNAMURTHY
Example:
Page 19 of 30
Page 20 of 30
D1=
D2=-
D3=-
D4=
C1=5
C2=3
C3=2
C4=4
Page 21 of 30
TABLE HANDLING
Static Array:
01 TABLE-ONE.
05 ELEMENT-1
OCCURS
3
10
ELEMENT-2 OCCURS
15
VALUE1
PIC
15
VALUE2
PIC
TIMES.
3
TIMES.
X(10).
9(5).
Dynamic Array:
01 TABLE-ONE.
05 LEN
PIC 9(2 ).
05 ELEMENT-1 OCCURS 1 TO 25 TIMES DEPENDING ON LEN.
10
ELEMENT-2 OCCURS
3
TIMES.
15
VALUE1
PIC X(10).
15
VALUE2
PIC 9(5).
Search:
Linear Search:
Syntax:
SEARCH identifier-1 VARYING {1. identifier-2
2. index-name-1}
AT END imperative-statement-1
WHEN condition-1 {1. imperative-statement-1
2. NEXT SENTENCE}
WHEN condition-2 {1. imperative-statement-2
2. NEXT SENTENCE}.
END-SEARCH.
Example:
01
TABLE-ONE.
02
ELEMENT-1 OCCURS 5 TIMES INDEXED BY INDX.
03
VALUE
PIC 9(2).
SET INDX TO 1.
SEARCH TABLE-ONE VARYING INDX
AT END DISPLAY not found
WHEN ELEMENT-1(INDX) <= 10
DISPLAY ELEMENT-1(INDX)
END-SEARCH.
Page 22 of 30
Binary Search:
Syntax:
SEARCH ALL identifier-1
AT END imperative-statement-1
WHEN condition-1 [AND condition-2]
{1. imperative-statement-2
2. NEXT SENTENCE}
END-SEARCH.
Example:
SEARCH ALL TABLE-ONE
AT END DISPLAY not found
FILE HANDLING
OPEN
Syntax:
OPEN mode file-name-1
mode file-name-2
Example:
OPEN INPUT NEW-FILE.
CLOSE
Syntax:
CLOSE file-name-1, file-name-2 .
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 TEMP-FILE NEXT RECORD INTO RECORD-1
AT END MOVE B1 TO EOF.
Page 23 of 30
RANDOM RETRIEVAL
Syntax:
READ file-name RECORD INTO identifier-1
[WITH NO LOCK]
[KEY IS data-name-1]
[FORMAT IS {1. identifier-2
2. literal-1}
[INVALID KEY imperative-statement-1]
[NOT INVALID KEY imperative-statement-2]
[END-READ]
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
Page 24 of 30
{1. LINE
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}
AT {1. EOP
imperative-statement-1
2. END-OF-PAGE}
NOT AT {1. EOP
imperative-statement-2
2. END-OF-PAGE}
Page 25 of 30
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.
Page 26 of 30
DELETE
Syntax:
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 identifier-1
FORMAT IS {1. identifier-2
Page 27 of 30
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.
ACQUIRE
Syntax:
ACQUIRE {1. identifier
FOR file-name
2. literal}
This statement is used to acquire a device for the specified transaction file.
Page 28 of 30
DROP
Syntax:
DROP {1. identifier FROM
file-name
2. literal}
This statement is used to release a device which has been acquired by the ACQUIRE
statement.
COMMITMENT CONTROL
To make the commitment control work we need to define the file in I-O-CONTROL.
When all the changes can be made permanent to the file, we issue a COMMIT or else if
all the changes should not reflect in the physical file, we issue a ROLLBACK.
Example:
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT ACCOUNT-FILE ASSIGN TO DATABASE-ACCTMST
ORGANIZATION IS INDEXED
ACCESS IS DYNAMIC
RECORD IS EXTERNALLY-DESCRIBED-KEY
FILE STATUS IS ACCOUNT-FILE-STATUS.
.
.
.
I-O-CONTROL.
COMMITMENT CONTROL FOR ACCOUNT-FILE.
.
.
.
PROCEDURE DIVISION.
MAIN-PARA.
OPEN I-O ACCOUNT-FILE.
.
.
.
IF <condition> THEN
COMMIT
ELSE
ROLLBACK
END-IF.
Page 29 of 30
DECLARATIVES
Declaratives is used to specify the set of statements which is to be performed when an
error occurred while operating on the specified file.
The USE statement can contain either the file-name itself or the mode of file ie INPUT,
OUTPUT, etc.
Example:
.
.
.
PROCEDURE DIVISION.
DECLARATIVES.
INPUT-FILE-ERROR SECTION.
USE AFTER STANDARD ERROR PROCEDURE ON INPUT-FILE.
INPUT-FILE-ERROR-PARA.
MOVE INPUT-FILE-STATUS TO SK.
MOVE "INPUT-FILE" TO FILE-NAME.
DISPLAY "FILE PROCESSING ERROR".
DISPLAY ERROR-INFO.
DISPLAY "PROCESSING TERMINATED DUE TO I-O ERROR".
STOP RUN.
I-O-FILE-ERROR SECTION.
USE AFTER STANDARD ERROR PROCEDURE ON MASTER-FILE.
MASTER-FILE-ERROR-PARA.
MOVE MASTER-FILE-STATUS TO SK.
MOVE "MASTER-FILE" TO FILE-NAME.
DISPLAY "FILE PROCESSING ERROR".
DISPLAY ERROR-INFO.
DISPLAY "PROCESSING TERMINATED DUE TO I-O ERROR".
STOP RUN.
END DECLARATIVES.
Page 30 of 30