Operation Codes - IBM - RPG

The RPG IV programming language allows you to do many different types of operations on your data. Operation codes, entered on the calculation specifications, indicate what operations will be done. For example, if you want to read a new record, you could use the READ operation code. The following is a list of the types of operations available.

  • Arithmetic operations
  • Array operations v Bit operations
  • Branching operations
  • Call operations
  • Compare operations
  • Conversion operations
  • Data-area operations
  • Date operations
  • Declarative operations
  • Error-handling operations
  • File operations
  • Indicator-setting operations
  • Information operations
  • Initialization operations
  • Memory management operations
  • Move operations
  • Move zone operations
  • Result operations
  • Size operations
  • String operations
  • Structured programming operations
  • Subroutine operations
  • Test operations

Example of an ILE RPG Program
This section illustrates a simple ILE RPG program that performs payroll calculations.

Problem Statement

The payroll department of a small company wants to create a print output that lists employees’ pay for that week. Assume there are two disk files, EMPLOYEE and TRANSACT, on the system.

The first file, EMPLOYEE, contains employee records. This shows the format of an employee record:

DDS for Employee physical file

DDS for Employee physical file

The second file, TRANSACT, tracks the number of hours each employee worked for that week and any bonus that employee may have received. This shows the format of a transaction record:

DDS for TRANSACT physical file

DDS for TRANSACT physical file

Each employee’s pay is calculated by multiplying the ″hours″ (from the TRANSACT file) and the ″rate″ (from the EMPLOYEE file) and adding the ″bonus″ from the TRANSACT file. If more than 40 hours were worked, the employee is paid for for 1.5 times the normal rate.

Control Specifications

Control Specifications

Example of an ILE RPG Program
Today's date will be printed in day, month, year format with ″/″ as the separator.

File Description Specifications

File Description Specifications

There are three files defined on the file description specifications:

  • The TRANSACT file is defined as the Input Primary file. The ILE RPG program cycle controls the reading of records from this file.
  • The EMPLOYEE file is defined as the Input Full-Procedure file. The reading of records from this file is controlled by operations in the calculation specifications.
  • The QSYSPRT file is defined as the Output Printer file.

Definition Specifications

Definition Specifications

Using the definition specifications, declare a variable called ″Pay″ to hold an employees’ weekly pay and two constants ″Heading1″ and ″Heading2″ to aid in the printing of the
report headings.

Calculation Specifications

Calculation Specifications

The coding entries on the calculation specifications include:

  • Using the CHAIN operation code, the field TRN_NUMBER from the transaction file is used to find the record with the same employee number in the employee file.
  • If the CHAIN operation is successful (that is, indicator 99 is off), the pay for that employee is evaluated. The result is ″rounded″ and stored in the variable called Pay.

Output Specifications

Output Specifications

The output specifications describe what fields are to be written on the QSYSPRT output:

  • The Heading Lines that contain the constant string ’PAYROLL REGISTER’ as well as headings for the detail information will be printed if indicator 1P is on. Indicator 1P is turned on by the ILE RPG program cycle during the first cycle.
  • The Detail Lines are conditioned by the +indicators 1P and 99. Detail Lines are not printed at 1P time. The N99 will only allow the Detail lines to be printed if indicator 99 is off, which indicates that the corresponding employee record has been found. If the indicator 99 is on, then the employee number and the constant string ’** NOT ON EMPLOYEE FILE **’ will be printed instead.
  • The Total Line contains the constant string ’END OF LISTING’. It will be printed during the last program cycle.

A Subprocedure

The subprocedure calculates the pay for the employee using the parameters passed to it. The resulting value is returned to the caller using the RETURN statement.

The procedure specifications indicate the beginning and end of the procedure. The definition specifications define the return type of the procedure, the parameters to the procedure, and the local variable Overtime.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

IBM - RPG Topics