CALCULATION SPECIFICATION


Calculation specifications are used to write the program instructions that are run when the program is called. The majority of an RPG program is made up of calculation specifications and definition specifications. All operations, including but not limited to, file processing, computations, and data manipulation, are performed with calculation specifications.

There are two formats for calculation specifications: the standard calculation specification and the alternate calculation specification. The standard calculation specification is used for most operations (i.e., program instructions). Although the alternate calculation specification is used by fewer operations, these operations control the program logic and most data manipulation. Consequently, RPG programs consist mostly of alternate calculation specifications.

There is no order or priority to either specification. The standard calculation specification can be intermixed with the alternate calculation specification. The layout of the two formats is designed to allow this transparency. Figures 2.13 and 2.14 illustrate the calculation specifications.

start figure

 .....CSRn01Factor1+++++++OpCode(ex)Factor2+++++++Result++++++++Len++DcHiLoEq.... 

end figure

Figure 2.13: Standard calculation specification.

start figure

 .....CSRn01..............OpCode(ex)Extended-factor2+++++++++++++++++++++++++++++ 

end figure

Figure 2.14: Alternate calculation specification with extended factor 2.

Calculation Specification Summary

Table 2.16 summarizes the calculation specifications.

Table 2.16: Calculation Specification Summary

Column

Title

Values

Description

6

Form type

C

Identifies this statement as a calculation specification.

7

Control code

*

The statement is ignored (it is a comment).

/

The statement contains either a compiler directive, such as /COPY, /IF DEFINED, or a preprocessor directive, such as /EXEC SQL.

+

The statement is a preprocessor continuation specification that began with /EXEC SQL on a previous line.

7 – 8

Control level indicator or subroutine notation

Blank

The statement is a normal statement or normal subroutine statement. No special control is specified.

Control-level indicators cannot be specified within a subprocedure.

AN/OR

The indicator conditioning on the previous statement is continued onto this line. The indicator condition of the previous line and/or the indicator condition of this line must be met before the operation can be performed. When AN/OR Is used, the operation must be specified on the last statement of the AN/OR group. There is no limit to the number of AN/OR continuations that can be specified for each operation.

L0

Total-time calculation. Because level zero (L0) is always on, this controlling level indicator always tests true.

L1 to L9

Total-time calculation. The control-level indicators are tested at total time (level break).

LR

Total-time and last-record processing. The calculation statement is performed during total-time processing—after the last record indicator is set on.

SR

Optional documentary notation to indicate a subroutine statement. Typically, SR is used only on the first and last statements of each subroutine to better identify the beginning and ending of the subroutine.

9 – 11

Conditioning indicators

Blank

No conditioning indicators are used to control whether or not this statement is performed. There should never be an entry in these columns if proper programming practices are followed.

Any valid indicator(s)

The specified indicator(s) control the running of this calculation. If more than one indicator is required, the conditioning can be continued on subsequent calculation specifications by specifying an AN or an OR in the control level positions of the next calculation line. All valid indicators are allowed.

12 – 25

Factor 1

Blank

No factor 1 entry is specified. Several operations support an entry in factor 1, while others do not require factor 1.

Any characters

The entry is used by the operation. The entry must match the requirements of the operation. All entries in factor 1 must be left-justified.

26 – 35

Operation code and operation extender

The name of the RPG instruction (operation) that is to be performed. Most operations use factor 1, factor 2, or the result field.

Operation [(ex)]

The operation extender is optional for operations that support an extender. The extender must be enclosed in parentheses. It can appear anywhere following the operation. Typical operation extenders include P (pad), N (no record lock), and H (half-adjust). See Table 5.8 for operation extender rules.

Extender

Description

D

Pass operation descriptors.

D

Test for valid date.

E

Activate %ERROR and %STATUS.

H

Half-adjust (round) result field.

M

Use max-digits precision rules.

N

Reset pointer to NULL.

N

Avoid locking the record.

P

Pad result field.

R

Use result-field length precision rules.

T

Test for valid time.

Z

Test for valid timestamp.

36 – 49

Factor 2

Blank

No factor 2 entry is specified. Several operations support an entry in factor 2, while others do not require factor 2.

Any characters

The entry is used by the operation. The entry must match the requirements of the operation. All entries in factor 2 must be left justified.

36 – 80

Extended Factor 2

Any characters

Any natural expression is specified.

It can span multiple lines by continuing the expression onto addition lines in the extended factor 2 area. Only certain operations support the extended factor 2, including the following:

Op Code

Description

CALLP

Call a prototyped procedure.

DOU

Do until.

DOW

Do while.

ELSEIF

Combined ELSE and IF operation

EVAL

Evaluate an expression.

EVALR

Evaluate, right adjust.

FOR

Iterative FOR loop

IF

Conditional IF.

RETURN

Return value to caller.

WHEN

Select/WHEN CASE.

50 – 63

Result field

Blank

No result field entry is specified. Several operations support an entry in the result field, while others do not require the result field.

Variable name

The entry is used as the target of the operation. The entry must match the requirements of the operation. All entries in the result field must be left justified. The result field is normally used as the target of the operation. For example, if it is the target of a MOVE operation, the content of factor 2 is copied to the result-field entry.

64 – 68

Result field length

Blank

The result field is defined elsewhere in the program or it is not a definable value (e.g., a label or subroutine name).

1 to 30

For numeric fields, the length of the result field.

1 to 65535

For character fields, the length of the result field.

-65534 to +65534

Relative length of the result field based on the field specified for factor 2 for a *LIKE DEFINE operation. The result field's length is the length of the field specified in factor 2, plus or minus the value specified.

69 – 70

Decimal positions

Blank

If the result field is specified and a result field length is also specified, the new field's data-type is character. If the result field length is blank, then these columns must also be blank. For the *LIKE DEFINE operation, the result field decimal positions must be blank.

0 to 30

Number of decimal positions for the result field. (Valid only for numeric result fields.)

71 – 76

Resulting indicators

Blank

No resulting indicators are set on as a result of the operation.

Any valid indicator

The resulting indicators are set according to the results of the operation. All but the following can be specified as resulting indicators: 1P, MR.

77 – 80

Not used.




The Modern RPG IV Language
The Modern RPG IV Language
ISBN: 1583470646
EAN: 2147483647
Year: 2003
Pages: 156
Authors: Robert Cozzi

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net