How can we help you?

We have hundreds of highly-qualified, experienced experts working in 70+ technologies.

IBM i e-Book

A Developer’s Guide to Mastering IBM i Concepts

Report Program Generator (RPG)

Indicators

An indicator is a one-byte character field which contains either ‘1’ (on) or ‘0’ (off) that helps to guide or control the processing of an operation. In RPGLE, Indicators play a pivotal role in controlling program flow and handling exceptional conditions.
Below are the indicators that we discuss.

  • Indicators defined on the RPG/400 specifications.
  • Indicators not defined on the RPG/400 specifications.

1. Indicators defined on the RPG/400 specifications.

1. Indicators defined as variable in RPGLE program –

Fix-format syntax for standalone indicator:

Name Declaration Type To / Length Internal Data Type
Name-of-Indicator S 1 N

Declaration type ‘S’ can be ignored if it is not a standalone variable.

Free format syntax:

dcl-s Name-of-Indicator ind;

Code Examples –

Fix-format:



In above screenshot –

On line 17.00: We are turning on isExist indicator if record is found on line 16.00.

On line 21.00: We have used isExist indicator, if record was found in EMPPF file and also found in EMPDEPT file then processing the file on line 22.00.

Free format:


2. Overflow indicator –

The PRINTER file lines that will be produced when there is an overflow are determined by the overflow indicator specified by the OFLIND keyword.

OFLIND keyword only works with PRINTER devices.

Automatic page ejection upon overflow (default overflow processing) takes place in the absence of the OFLIND keyword.

Syntax:

OFLIND(indicator-name);

In OFLIND, we can use below valid indicators –

*INOA to *INOF, *INOV:

These indicators we can use in a program described printer file to handle conditions when overflow line is reached. These indicators not valid for externally described files.

*IN01 to *IN99:

These indicators we can use, when the overflow line is reached or passed during a space or skip operation.

Name:

This can be a variable name which has indicator type. We can use this indicator when the overflow line is reached. The program must handle the overflow condition.

It has same behaviour as for indicators *IN01 to *IN99.

Code Examples –

Fix-format:


In above screenshot, there is an externally described printer file CUSREPORT declared with OFLIND keyword which has indicator *IN99

*IN99 will be turn on when overflow occurs in respective printer files CUSREPORT.


In above screenshot, we are handling overflow with *IN99 indicator. When overflow occurs, it will print the heading again.

Free format:


3. Display file indicator integration using address of indicators –

By assigning variables to the address of indicators, we can utilize readable names instead of indicators in RPG programs.

To do this –

  • There should be INDARA keyword at file level in display file. It provides the functionality to use indicator data structure in RPG program.
  • Declare display file in RPG program with INDDS keyword with indicator data structure name.
  • Declare a pointer variable by initializing with address of indicators.
  • Declare indicator data structure with based on pointer variable.
  • Now, we can use subfields of indicator data structure in RPG program.

Code Examples –

INDARA keyword declared at file level in display file –


RPGLE Program declaration to use indicator data structure –

Line 0003.00 is a display file declaration, we have used INDDS keyword to give name of the indicator data structure which is indicatorDs in this example.

Line 4.00 is a declaration of pointer variable initialized with the address of indicators.

Line 5.00 is an indicator data structure which is based on pointer variable declared in line 4.00.

Line 6.00 is a subfield of indicatorDs, it has indicator data type, it relies on position 5, so it can be used in place of *IN05.

In Line 31.00, we have a variable ‘previous’ which is a subfield of indicator data structure, it is pointing to the address of indicator ‘*IN12’.

So, when previous will be turned on, then *IN12 will also turn on automatically.

4. Control Level Indicators (L1-L9)

The control level indicators (L1 to L9) are used to manage program flow, especially within loops and conditional statements. These indicators are set and checked during the execution of the program.

Certainly! Here’s an example that demonstrates how you can use control level indicators with physical and logical files in RPG on an IBM i system. In this example, we’ll create a simple program that reads records from a physical file, applies some conditions using control level indicators, and writes the selected records to a logical file.

Assuming you have two files:

There are 2 logical files EMPIOREC and EMPIOTIM.


Here’s an RPG program that increase the count of the variable when level break occurs.

  • A comment indicates that when a level break occurs on `L2` (PIO_DIVSON), it should add 1 to the `PIOCNT` variable.
  • The line ‘L2 PIOCNT ADD 1 PIOCNT 40’ suggests that if a level break occurs on ‘L2’, it will add 1 to the ‘PIOCNT’ variable.
5. Function Key Indicator

Function keys are specified in the DDS with the CFxx (command function) or CAxx (command attention) keyword. For example, the keyword CF01 allows function key 1 to be used. When you press function key 1, function key indicator KA is set on in the RPG program. If you specify the function key as CF01 (99), both function key indicator KA and indicator 99 are set on in the RPG program. If the work-station user presses a function key that is not specified in the DDS, the IBM® i system informs the user that an incorrect key was pressed.

Certainly! Below is an example RPGLE program and DDS source code that follows the specified requirements. In this example, the program reads the display file, and when the user presses Function Key F1 or F2, it sets the corresponding indicators in the RPG program. If the user presses an incorrect key, an error message is displayed.

RPGLE code.

DDS code

In this example, the display file (MyDisplay) has two input fields (FIELD1 and FIELD2). The indicators KA and KB are associated with Function Keys F1 and F2, respectively. The program (MyProgram) reads the display file and checks the values of KA and KB to determine which function key was pressed. If an incorrect key is pressed, an error message is displayed. Adjust the logic inside the ProcessF1 and ProcessF2 subroutines based on your specific requirements for handling each function key.

Below is the table for the function key indicator with its corresponding key.

Function Key Indicator Corresponding Function Key Function Key Indicator Corresponding Function Key
KA 1 KM 13
KB 2 >KN 14
KC 3 KP 15
KD 4 KQ 16
KE 5 KR 17
KF 6 KS >18</td
KG 7 KT 19
KH 8 KU 20
KI 9 KV 21
KJ 10 KW 22
KK 11 KX 23
KL 12 KY 24
6. Halt Indicator (H1-H9)

The Halt indicators are used to handle the error while running of a program. It can be used with record identifying indicators, field indicators, or resulting indicators.

Certainly! In RPG II, you can use the H1 indicator as a halt indicator. Below is a simple example:

The H1 indicator is used as a halt indicator. When H1 is turned on, the program will stop processing.

The program goes through the usual sequence of input, processing, and output operations.

The PROCESSDATA subroutine checks the condition (*IN99) and increments a counter (NUMOFRECORDS) for demonstration purposes. If the condition is met (in this case, *IN99 is on), the program moves a message to the MSG field, displays it, and sets *INLR to halt the program.

2. Indicators not defined on the RPG/400 specifications.

  • Internal IndicatorsThe internal indicators, often referred to as “I” indicators, are special variables used to control the flow of a program and handle various operations and conditions. These indicators are used for decision-making, error handling, and controlling the logic of a program.
    1. First Page Indicator (1P): – Definition: The first page (1P) indicator is set on by the RPG IV program when the program starts running and is set off by the RPG IV program after detail time output.-Usage: The first record will be processed after detail time output. The 1P indicator can be used to condition heading or detail records that are to be written at 1P time.
    2. Last Record Indicator (LR): – Definition: The Last Record Indicator (LR) is used to identify the last record in a report or file. – Usage: Typically, LR is set to *ON for the last record in a report or file to indicate the end of the report or file. Example:

      or

      or

      In this example, the LR indicator is specified in the printer file’s output specification. It is automatically set to *ON for the last record in the output.

    3. Matching Record Indicator (MR): – Definition: The Matching Record Indicator (MR) is used to indicate that two or more fields in a record match specified criterion.– Usage: MR is often used in program logic to identify matching records based on specified conditions.Example:

      Three files are used in matching records. All the files have three match fields specified, and all use the same values (M1, M2, M3) to indicate which fields must match. The MR indicator is set on only if all three match fields in either of the files EMPMAS and DEPTMS are the same as all three fields from the WEEKRC file.

      The three match fields in each file are combined and treated as one match field organized in the following descending sequence:

      DIVSON
      M3
      DEPT
      M2
      EMPLNO
      M1

    4. Return Indicator (RT):– Definition: The Return Indicator (RI) is used to determine whether a subroutine or called program has executed successfully and returned a result.– Usage: The test to determine if RT is on is made after the test for the status of LR and before the next record is read. If RT is on, control returns to the calling program. RT is set off when the program is called again.
  • External Indicators used as JOB Indicators –There are 8 external indicators, U1 through U8 which can be set in a CL program or in an RPGLE program.In a CL program, they can be set by the SWS (switch-setting) parameter on the CL commands CHGJOB (Change Job) or CRTJOBD (Create Job Description).In an RPGLE program, they can be set by direct assignment or using any assignment opcodes.

    Code examples –

    In above screenshot, it is a CL program logic.

    On line 2, Indicator U8 is set to turn on by SWS parameter on CL command CHGJOB.

In SWS parameter of CL command CHGJOB, we can set 8 indicators (U1 through U8).

  1. Type ‘1’ on corresponding position to turn on the indicator.
  2. Type ‘0’ on corresponding position to turn off the indicator.
  3. Type ‘X’ on corresponding position for no change of the indicator.

On line 3, it is calling GETCUSTDTL program. In this program we can handle the program flow by conditioning with these indicators.

Fix format:

Above is the screenshot for the logic of GETCUSTDTL program, which is handling *INU8 indicator. If it is turned on, then process only ENG customers otherwise process all customer.

Free format:

CL program example to turn on U8 indicator by SWS parameter of CRTJOBD CL command.

In RPGLE program, job indicators can be set and use in other calling/called program as well to maintain the program flow.

It can be set by any assignment opcodes like Eval, Move.

Fix format:

Free format:

How can we help you?

We have hundreds of highly-qualified, experienced experts working in 70+ technologies.

share_iconShare
X

Awards and Certifications

company-logo
company-logo
company-logo
company-logo
company-logo
company-logo
company-logo
company-logo
company-logo
company-logo