5 choices in procedure division statements – Compaq COBOL AAQ2G1FTK User Manual

Page 498

Advertising
background image

Optimizing Your Compaq COBOL Program
15.4 Other Ways to Improve the Performance of Operations on Numeric Data

intermediate data items will have very large PICTUREs, which will adversely
affect performance.

If you can break complex arithmetic expressions into two or more simpler
expressions, performance can be greatly improved. Try to break expressions
to make any divide or exponentiation operation the last operation in the
subexpression. Store the results of each subexpression in data items you declare,
and ensure that such data items have PICTUREs just sufficient to hold the
expected partial results.

15.4.4 Selection of Data Types (OpenVMS)

The Alpha architecture provides a full set of arithmetic operations for G-FLOAT.
When your program operates upon G-FLOAT data items, the arithmetic
operations are carried out at maximum native speed and with full precision.
When D-FLOAT data types are encountered in your program source the Compaq
COBOL compiler must perform a conversion to G-FLOAT. Similarly, data
returned from an arithmetic operation must be converted from G-FLOAT to your
declared data type.

While these operations are actually transparent to you, there is a cost in both
performance and accuracy, as some data can be lost in the two conversions.
Wherever you have the luxury of choice, Compaq suggests you use G-FLOAT data
types in your programs.

15.5 Choices in Procedure Division Statements

Some Procedure Division statements make better use of the Compaq COBOL
compiler than others. This section describes these statements and shows how to
use them.

15.5.1 Using GO TO DEPENDING ON Instead of IF, GO TO

The GO TO DEPENDING ON statement generates fewer instructions than
a sequence of IF and GO TO statements; it can also improve a program’s
readability. For example:

GO TO 100-PROCESS-MARRIED

200-PROCESS-SINGLE
300-PROCESS-DIVORCED
400-PROCESS-WIDOWED

DEPENDING ON MARITAL-STATUS.

The previous example generates fewer instructions and is easier to read than the
following:

IF MARITAL-STATUS = 1

GO TO 100-PROCESS-MARRIED.

IF MARITAL-STATUS = 2

GO TO 200-PROCESS-SINGLE.

IF MARITAL-STATUS = 3

GO TO 300-PROCESS-DIVORCED.

IF MARITAL-STATUS = 4

GO TO 400-PROCESS-WIDOWED.

Remember, data items referenced by the DEPENDING ON clause must contain
a numeric value that is: ( 1 ) greater than zero, and ( 2 ) not greater than the
number of procedure names in the statement. Otherwise, control passes to the
next executable statement.

15–8 Optimizing Your Compaq COBOL Program

Advertising