INDICATORS


Indicators are logical variables or switches that are either on or off; that is, they contain a value of 1 or 0. Indicators are used to control program logic, program termination, output, signal conditions, and to communicate with device files.

For example, when an indicator is used to condition the ADD operation, the indicator is tested before the ADD operation is performed. If the indicator test is true, the ADD operation is performed. If the indicator test is false, the ADD operation is bypassed and the program goes to the next statement. Figure 1.5 shows an example.

start figure

 .....CSRn01Factor1+++++++OpCode(ex)Factor2+++++++Result++++++++Len++DcHiLoEq....      C     AREA          COMP      '1401'                                 38      C   38              ADD       100           COST      C     SALES         SUB       COST          PROFIT 

end figure

Figure 1.5: Example of indicator usage.

Logically, this program is illustrated as shown in Figure 1.6.

start figure

         Clear Indicator(38)         If AREA = '1401' Set On Indicator(38) Test1:  If Indicator(38) is OFF, Goto EndTest1;         Add 100 to COST; EndTest1:        Subtract COST from SALES giving PROFIT; 

end figure

Figure 1.6: Logic of the program code shown in Figure 1.5.

In early versions of RPG (RPG and RPG II), structured programming constructs did not v exist. Consequently, the indicator usage proliferated. However, the modern RPG programmer avoids the use of indicators except where it is impossible to ignore them (such as in accessing files). In place of indicators, structured operations are used to control program logic. Today, the use of the numeric indicators is all but eliminated.

Indicatorless RPG Code

The example code shown in Figure 1.5, if rewritten with structured RPG operations, would appear as shown in Figure 1.7.

start figure

 .....CSRn01Factor1+++++++OpCode(ex)Factor2+++++++Result++++++++Len++DcHiLoEq      C                    IF        Area = '1401'      C                    Add      100           Cost      C                    EndIF      C                    Eval     Profit = Sales - Cost 

end figure

Figure 1.7: Rewriting code without indicators.

In pseudocode, the program (Figure 1.7) is illustrated by Figure 1.8.

start figure

         If AREA = '1401' Then                Add 100 to COST;         EndIf         Subtract COST from SALES giving PROFIT; 

end figure

Figure 1.8: Pseudocode for Figure 1.7.

Notice how concise and readable the program becomes when structured operations are used properly. A side effect of the use of structured operations is that programs tend to run more efficiently than they do when indicators control the logic. This is a by-product of the OS/400 RPG compilers and not inherent of compilers in general. Table 1.7 lists definitions of the various types of indicators supported by RPG.

Table 1.7: Indicator Definitions

Indicator

Description

1P

First Page Indicator. This indicator is set on as part of the "first time through" routine and is set off just prior to the first detail time routine. It is traditionally used to print a forms alignment character.

01 to 99

General Purpose Indicators. Used for various tasks.

H1 to H9

Halt Indicators. These indicators are used to signal a severe error. When a halt indicator is set on and the program ends, an "abnormal termination" message is issued.

KA to KY

Function Key Indicators. These indicators correspond to 24 function keys on most key- boards. KA to KN represent keys F1 to F14 respectively. KP to KY represent keys F15 to F24 respectively. Avoid the use of these indicators. If possible, use the Attention Identification Byte. See Table 1.8.

L1 to L9

Level-Break Indicators. These indicators are used in conjunction with the RPG cycle. They are set on when the value of their corresponding input field changes when a record is read via the RPG cycle.

L0

Level Zero Indicator. This indicator is, by definition, always on and, therefore, never tested at runtime. It is occasionally used during the "total-time" phase of the RPG cycle.

LR

Last Record Indicator. When this indicator is set on, and the end of program is caused by the return operation or the end of cycle, the program terminates, and its storage is released. If LR is off and the program ends, the program's storage is saved, and the program is still considered to be active. If the program is actually a module or a larger program, certain resources are not released.

M1 to M9

Match Field Identifiers. These identifiers are not indicators. They are flags used to control the sequencing of primary/secondary file processing, and to signal a matching record condition (which sets on the MR indicator). Matching record processing is part of the RPG cycle.

MR

Matching Record Indicator. This indicator is set on when all the match fields of a secondary file match all the match fields of the primary file. This function is part of the RPG cycle.

OA to OG, and OV

Overflow Indicators. These indicators are normally associated with a specific printer file. They are set on when printed output reaches the designated overflow line (normally line 60 for a 66-line form or line 80 for an 88-line form).

RT

Return Indicator. When this indicator is set on, the RPG program returns to its caller, but remains active (provided that indicator LR is off). This occurs after the ending calculation specification is reached (i.e., the end of this RPG cycle) or the RETURN operation is performed.

U1 to U8

External User Indicators. These indicators, or switches, are used to communicate between the RPG program and the external operating environment. They can be used to condition the opening of a file or to control calculations.

User-defined

Named indicators. These indicators are programmer specified names that have a data-type of N (named indicator). They may be used similar to any of the original 99 indicators and, along with the INDDS (indicator data structure) may overlay those original indicators when communicating with a device file.

Table 1.8: Attention Identification Byte

Function Key

Value in Hex

F1

X'31'

F2

X'32'

F3

X'33'

F4

X'34'

F5

X'35'

F6

X'36'

F7

X'37'

F8

X'38'

F9

X'39'

F10

X'3A'

F11

X'3B'

F12

X'3C'

F13

X'B1'

F14

X'B2'

F15

X'B3'

F16

X'B4'

F17

X'B5'

F18

X'B6'

F19

X'B7'

F20

X'B8'

F21

X'B9'

F22

X'BA'

F23

X'BB'

F24

X'BC'

CLEAR

X'BD'

ENTER

X'F1'

HELP

X'F3'

Roll Down

X'F4'

Roll Up

X'F5'

Print

X'F6'

Rec'd Bksp

X'F8'

Auto Enter

X'3F'




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