PROCEDURE DIVISION STATEMENTS
PROCEDURE DIVISION
statements must begin with a reserved word called a verb.
General Format:
{ procedure-sect SECTION [segment-no] .
[ procedure-para.
[ procedure-statement ] ... ] ... } ...
General Rules:
The General Rules for the different Procedure Division statements are described below.
Common General Rules are General Rules that apply to more than one Statement.
Common General Rules
ROUNDED
- The effect of the
ROUNDED
clause is to cause the least significant digit to be increased by 1 if the next least significant digit of the intermediate result is greater than or equal to 5. - When there is no
ROUNDED
clause specified, the next least significant digit, and all subsequent digits in the intermediate result are truncated.
ON SIZE ERROR
- The
SIZE ERROR
exception is triggered if theON SIZE ERROR
clause is present and if the receiving field is not large enough to acco mmodate the result of an arithmetic function. - In the absence of an
ON SIZE ERROR
clause, if the receiving field is not large enough to accommodate the result of theADD
function, the high order digits that cannot be accommodated are truncated. For example, if youADD
6 TO 6, and attempt to store the result in aPIC 9
field, the result will be 2. - The
ON SIZE ERROR
clause provides the programmer with a way to respond to theSIZE ERROR
exception by performing a statement, or a series of statements. - The
NOT ON SIZE ERROR
condition exists if theNOT ON SIZE ERROR
clause is present, and aSIZE ERROR
exception is not triggered. - The
NOT ON SIZE ERROR
clause provides the programmer with a way to respond to theNOT ON SIZE ERROR
condition by performing a statement, or a series of statements.
ARITHMETIC ORDER OF EVALUATION
- Arithmetic expressions within parentheses are evaluated first.
- Within nested sets of parentheses, the innermost set of parentheses is evaluated first. Sets of parentheses inside a nested set of parentheses then are evaluated from innermost to outermost.
- Inside parentheses, or following the complete evaluation of all expressions within parentheses, or in expressions where there are no parentheses, arithmetic expressions evaluate arithmetic operators in the following order:
- Unary. The Sign (+ or -) is applied The minus
“ “--“
sign has the effect of causing the expression to be multiplied by 1. The plus “+
” sign has the effect of causing the expression to be multiplied by +1. - Exponents. Exponentiation is applied. The exponentiation “
**
” sign has the effect of raising the expression to the exponential value expressed after the exponentiation sign. - Multiplication and Division. Where there are no parentheses to establish order of execution, an arithmetic expression containing successive multiplication and division operators is evaluated from left to right.
- Addition and Subtraction . Where there are no parentheses to establish order of execution, an arithmetic expression containing successive addition and subtraction operators is evaluated from left to right.
- Unary. The Sign (+ or -) is applied The minus
- The number of left parentheses in an arithmetic expression must equal the number of right parentheses in the arithmetic expression.
ARITHMETIC CALCULATIONS
- Certain common general rules apply to each of the arithmetic statements
ADD
,COMPUTE
,DIVIDE
,MULTIPLY
, andSUBTRACT
. - The maximum size of a numeric field is 36 digits.
- The compiler constructs data items as needed to hold intermediate results in an arithmetic operation.
- The final operation in an arithmetic expression transfers the final value to the receiving field. If the receiving field is too small to accommodate the result, and if there is no
ON SIZE ERROR
clause, then truncation occurs on the high-order digits before the decimal point, and on the low-order digits after the decimal point.
Rules for identifying CORRESPONDING data elements
- A data element cannot be considered a
CORRESPONDING
data element if:- The data element name is not matched.
- The data element is described as
FILLER
. - The data element is described as a
REDEFINES
of another data item. - The data element is described as a
RENAMES
of another data item. - The data element has an
OCCURS
clause.
- If none of the above apply, then a data element in a target group is considered a
CORRESPONDING
data element if:- It has the same name as a data element in the src group item, and, if it is has one or more parent data items that are not the
src-group-item
, then all of the parent data items in thesrc-group-item
andtarget-group-item
also have the same names.
- It has the same name as a data element in the src group item, and, if it is has one or more parent data items that are not the