Introduction:
Overview:
This module enables the student to get
basic concept of RPG/400.
Outline:
Topics covered,
- RPG/400
Introduction.
- Indicators
in RPG programming
- Program
Specification.
- Assignment operators.
- Arithmetic
Operators.
Objective:
By the end of this module, the student should be
able to:
- Understand the Calculation
Specification.
- Understand
the Assignment operators.
- Understand
the Arithmetic Operators.
RPG/400
RPG/400 is a
programming language designed to process data for business and commercial
applications. This language is unique in nature from other programming
languages as it uses a number of specifications that are position oriented to
write a program. RPG/400 is a predecessor of RPG-II (used on system /36) and
RPG –III (used on system/38).
The following is
the specification sequence to code an RPG/400 program.
·
Control specification (H)
·
File specification (F)
·
Extension specification (E)
·
Line counter specification (L)
·
Input specification (I)
·
Calculation specification (C)
·
Output specification (O)
The specification if present in the program needs to be
defined in the sequence H-F-E-L-I-C-O
An each type
specification of line is broken in various parts. Specific values/verbs are
required in these positions.
RPG program is
run with CL command CALL <filename> on command line.
Indicators:
Definition:
Indicators in RPG
and CL programs are the memory position (memory variables) which contain value
“0 or 1”, “*ON or *OFF”. Indicator may be compared with a Boolean variable in
any other language with value “True” or “False”.
Indicator names
are specific in nomenclature and have particular usage in the program.
Name
|
Nomenclature
|
Purpose
|
General Purpose Indicator
|
01-99
|
Programmer can
use these indicators for setting a particular condition.
|
Overflow
Indicator
|
OA-OG, OV
|
This indicator
is assigned to printer file and signal the end of the a printed page
|
Last Record
Indicator
|
LR
|
LR indicator
when on cause the termination of the program.
|
Matching Record Indicator
|
M1-M9 (MR)
|
This Indicator is used for Doing
conditional calculations and Outputs for any 2 records, if they match or do
not match.
|
Control Level
Indicator
|
L1-L9
|
These Indicators are used for Defining
various Control Breaks.
|
We will discuss more on the Indicators at
the point of the usage in the course.
First we will study the calculation
specification.
Calculations
Specifications
Calculation specifications describe the calculations to be done in the
data and the order of the calculations. Calculation specifications can also be
used to control certain input operations.
The information includes:
·
Control-level and conditioning for the operation specified
·
Fields or constants to be used in the operation
·
The operation processed
·
Whether resulting indicators are used in the operation or not
Step 1. Press F6
Following screen is displayed
Start Source Entry
Utility (STRSEU)
Type choices, press Enter.
Source file
. . . . . . . . . . > MYRPG
Name, *PRV
Library . . . . . . . . . . .
> PB01U01S Name, *LIBL, *CURLIB,
*PRV
Source member
. . . . . . . . . RPG1 Name, *PRV, *SELECT
Source type
. . . . . . . . . . RPG Name, *SAME, BAS, BASP...
Text 'description' . . . . . . . My first program
Bottom
F3=Exit
F4=Prompt F5=Refresh F12=Cancel
F13=How to use this display
F24=More keys
Step 2. Press Enter
Start Source Entry
Utility (STRSEU)
Type choices, press Enter.
Source file
. . . . . . . . . . > MYRPG
Name, *PRV
Library . . . . . . . . . . .
> PB01U01S Name, *LIBL, *CURLIB,
*PRV
Source member
. . . . . . . . . RPG1 Name, *PRV, *SELECT
Source type
. . . . . . . . . . RPG Name, *SAME, BAS, BASP...
Text 'description' . . . . . . . My first program
Bottom
F3=Exit
F4=Prompt F5=Refresh F12=Cancel
F13=How to use this display
F24=More keys
Columns
. . . : 1 71
Edit
PB01U01S/MYRPG
SEU==>
RPG1
FMT H
.....H........1..CDYI....S..............1.F............................
*************** Beginning of data
*************************************
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
****************** End of data
****************************************
F3=Exit
F4=Prompt F5=Refresh F9=Retrieve
F10=Cursor F11=Toggle
F16=Repeat find F17=Repeat change F24=More keys
Member
RPG1 added to file PB01U01S/MYRPG. +
Columns
. . . : 1 71
Edit
PB01U01S/MYRPG
SEU==>
RPG1
FMT H
.....H........1..CDYI....S..............1.F............................
*************** Beginning of data
*************************************
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
****************** End of data
****************************************
F3=Exit
F4=Prompt F5=Refresh F9=Retrieve
F10=Cursor F11=Toggle
F16=Repeat find F17=Repeat change F24=More keys
Member
RPG1 added to file PB01U01S/MYRPG. +
Step 3. Press Enter
Columns
. . . : 1 71
Edit
PB01U01S/MYRPG
SEU==>
RPG1
FMT H
.....H........1..CDYI....S..............1.F............................
*************** Beginning of data
*************************************
****************** End of data
****************************************
F3=Exit
F4=Prompt F5=Refresh F9=Retrieve
F10=Cursor F11=Toggle
F16=Repeat find F17=Repeat change F24=More keys
Columns
. . . : 1 71
Edit
PB01U01S/MYRPG
SEU==>
RPG1
FMT H
.....H........1..CDYI....S..............1.F............................
*************** Beginning of data
*************************************
****************** End of data
****************************************
F3=Exit
F4=Prompt F5=Refresh F9=Retrieve
F10=Cursor F11=Toggle
F16=Repeat find F17=Repeat change F24=More keys
Step 4. Type IPC then Press Enter
Columns . . . : 1
71 Edit PB01U01S/MYRPG
SEU==>
RPG1
FMT
H
.....H........1..CDYI....S..............1.F............................
IPC
*************** Beginning of data *************************************
****************** End of data ****************************************
F3=Exit
F4=Prompt F5=Refresh F9=Retrieve
F10=Cursor F11=Toggle
F16=Repeat find F17=Repeat change F24=More keys
Columns . . . : 1
71 Edit PB01U01S/MYRPG
SEU==>
RPG1
FMT
H
.....H........1..CDYI....S..............1.F............................
*************** Beginning of data *************************************
'''''''
****************** End of data ****************************************
Prompt type . . . C
Sequence number . . .
'''''''
Level
N01N02N03 Factor 1 Operation Factor 2 Result
Decimal
Length
Positions H/N/P HI
LO EQ Comment
F3=Exit
F4=Prompt F5=Refresh F11=Previous record
F12=Cancel F23=Select prompt F24=More keys
Columns . . . : 1
71 Edit PB01U01S/MYRPG
SEU==>
RPG1
FMT
H
.....H........1..CDYI....S..............1.F............................
IPC
*************** Beginning of data *************************************
****************** End of data ****************************************
F3=Exit
F4=Prompt F5=Refresh F9=Retrieve
F10=Cursor F11=Toggle
F16=Repeat find F17=Repeat change F24=More keys
Columns . . . : 1
71 Edit PB01U01S/MYRPG
SEU==>
RPG1
FMT
H
.....H........1..CDYI....S..............1.F............................
*************** Beginning of data *************************************
'''''''
****************** End of data ****************************************
Prompt type . . . C
Sequence number . . .
'''''''
Level
N01N02N03 Factor 1 Operation Factor 2 Result
Decimal
Length
Positions H/N/P HI
LO EQ Comment
F3=Exit
F4=Prompt F5=Refresh F11=Previous record
F12=Cancel F23=Select prompt F24=More keys
C Specification line is broken
into following parts.
Positions
|
Name
|
Entry
|
1-2
|
Page
|
Page number
|
3-5
|
Line
|
Line number
|
6
|
Form type
|
C
|
7-8
|
Control level
|
Blank
L0
L1-L9
LR
SR
AN,OR
|
9-17
|
Conditioning Indicators
|
Blank
01-99
KA-KN, KP-KY
L1-L9
LR
MR
H1-H9
RT
U1-U8
OA-OG,OV
|
18-27
|
Factor 1
|
Symbolic name or literal
|
28-32
|
Operation
|
Operation code
|
33-42
|
Factor 2
|
Symbolic name or literal
|
43-48
|
Result field
|
Field name
|
49-51
|
Field length
|
Blank
1-15
1-30
1-256
|
52
|
Decimal positions
|
Blank
0-9
|
53
|
Operation Extender
|
Blank
P
H
N
|
54-59
|
Resulting indicators
|
Blank
01-99
KA-KN, KP –KY
H1-H9
L1-L9
LR
QA-OG, OV
U1-U8
RT
|
60-74
|
Comments
|
Comments
|
75-80
|
|
Optional
|
Factor1:
Factor 1 can be symbolic or literal or actual data on which operation is to be
performed. it may or may not be present its usage depends on the operation code
used.
Operation: An operation code (Opcode) describes the
operation to be performed using factor 1 and factor 2 and the result field.
This entry is compulsory for the calculation spec.
Factor2: Factor 2 can be symbolic or literal or actual
data on which operation is to be performed. it may or may not be present its
usage depends on the operation code used.
Result: this
entry specifies the name of the result field that contains the result of the
calculation operation. it may or may not be present . Its usages depend on the operation
code used.
H/N/P: This entry specifies operation extender.
Operation extender are simple char whose purpose is to provides additional
attribute to the operation that they accompany
Resulting Indicators (HI LO EQ): These indicator values will
be set on or off depending on the opcode used and are used to check the result
of the operation.
Assignment operators
Z-ADD (Zero and Add):
Value Type
|
Permissible values
|
N01N02N03
|
Optional
|
Factor1
|
Not
required
|
Factor2
|
Value to be assign to variable
|
Result
|
Name of Variable
|
Length
|
Length of Variable
|
Decimal Positions
|
Specifies Decimal Position
|
Resulting Indicator
|
Optional
|
It is an assignment operation for numeric
fields. It zeros out the result field and adds Factor2 to it. The effect of
this operation is to assign the value of factor2 to the result field.
Columns . . . : 1
71 Edit PB01U01S/MYRPG
SEU==>
EXA1
FMT C
.....CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++
*************** Beginning of data
*************************************
0002.00 C Z-ADD20 MAX
50
****************** End of data ****************************************
Prompt type . . . C
Sequence number . . .
0002.00
Level N01N02N03
Factor 1 Operation Factor 2 Result
Z-ADD 20 MAX
Decimal
Length
Positions H/N/P HI
LO EQ Comment
5 0
F3=Exit
F4=Prompt F5=Refresh F11=Previous record
F12=Cancel F23=Select prompt F24=More keys
Here
variable MAX with length 5 and decimal positions 0 initialized with value
20.
Z-SUB (Zero and Sub):
Value Type
|
Permissible values
|
N01N02N03
|
Optional
|
Factor1
|
Not
required
|
Factor2
|
Value to be assign to variable
|
Result
|
Name of Variable
|
Length
|
Length of Variable
|
Decimal Positions
|
Specifies Decimal Position
|
Resulting Indicator
|
Optional
|
Z-SUB
operator works similarly to Z-ADD except that after zeroing out the result
field it subtracts the value of factor2 from result field. Hence it is used for
reversing the sign of a field.
Columns . . . : 1
71 Edit PB01U01S/MYRPG
SEU==>
EXA2
FMT
C
.....CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++
*************** Beginning of data
*************************************
0002.00 C Z-SUB30 MIN
****************** End of data
****************************************
Prompt type . . . C
Sequence number . . .
0002.00
Level
N01N02N03 Factor 1 Operation Factor 2 Result
Z-SUB 30 MIN
Decimal
Length
Positions H/N/P HI
LO EQ Comment
5 0
F3=Exit
F4=Prompt F5=Refresh F11=Previous record
F12=Cancel F23=Select prompt F24=More keys
Here
variable MAX with length 5 and decimal positions 0 initialized with value -30.
Size
of the veriable mustbe defines at least once in the program (or in files used).
Size definition can be done repeatedly but it cannot be different than other
definition. Good practice is to be defining the variable size only once. For
numeric variables the decimal size must be defined (even if it is zero).
Arithmetic Operations
Arithmetic operations can be done only on
numeric fields. Factor 1 and Factor 2 are not changed by an arithmetic
operation. Any data placed in the result field replaces the data that was
there. Half adjust can be specified for all arithmetic operations except MOVER.
ADD (Addition)
Value Type
|
Permissible values
|
N01N02N03
|
Optional
|
Factor1
|
First
Variable (optional)
|
Factor2
|
Second Variable/constant
|
Result
|
Variable to store the Sum of First
variable and Second Variable or Factor2 added to result variable
|
Length
|
Length of Variable which store the
sum of First variable and Second Variable
|
Decimal Positions
|
Specifies Decimal Position of Variable
which store the sum of First variable and Second Variable
|
Resulting Indicator
|
Optional
|
Adds
the values of Factor1 and Factor2 and stores the result in a result field.
Factor1 and Factor2 can be numeric fields or numeric literal.
Eg.
ABC ADD 1 CNT
More recent versions of RPG allow you to
omit Factor1 entry.
Eg.
ADD 1 CNT
Both the statements produce the same
result.
Columns .
. . : 1 71
Browse
PB01U01S/MYRPG
SEU==>
EXA3
FMT C
.....CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++
*************** Beginning of data
*************************************
0001.00 C
Z-ADD3 N1
20
0002.00 C Z-ADD2 N2
20
0003.00 C Z-ADD0 N3
40
0004.00 C N1 ADD
N2 N3
0005.00 C N3 DSPLY
0006.00 C SETON LR
0007.00 ************** End of data ****************************************
F3=Exit
F5=Refresh F9=Retrieve F10=Cursor
F11=Toggle F12=Cancel
F16=Repeat find F24=More keys
(C)
COPYRIGHT IBM CORP. 1981, 2002.
Compile above program using
option 14 and call it using CALL <filename> on command line.
SUB (Subtract)
Value Type
|
Permissible values
|
N01N02N03
|
Optional
|
Factor1
|
First
Variable
|
Factor2
|
Second Variable
|
Result
|
Variable to store the Difference of First
variable and Second Variable
|
Length
|
Length of Variable which store the Difference of First variable and Second Variable
|
Decimal Positions
|
Specifies Decimal Position of Variable
which store the Difference of First variable and Second Variable
|
Resulting Indicator
|
Optional
|
Subtracts
the value of Factor2 from Factor1 and stores the result in the result field.
Factor1 and Factor2 can be numeric fields or numeric literal. This operation
would be expressed as
Result = factor2 – Factor1
Eg.
ABC SUB 1 CNT
(Subtract 1 from ABC)
More
recent versions of RPG allow you to omit Factor1 entry.
SUB 1 CNT (Subtract 1 from ABC)
Which
means subtract Factor2 from result field and stores the result in the result
field. Both the statements produce the same result.
Columns . . . : 1
71 Browse PB01U01S/MYRPG
SEU==>
EXA4
FMT
C
.....CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++
*************** Beginning of data *************************************
0001.00 C Z-ADD3 N1
20
0002.00 C Z-ADD2 N2
20
0003.00 C Z-ADD0 N3
40
0004.00 C N1 SUB
N2 N3
0005.00 C N3 DSPLY
0006.00 C SETON LR
****************** End of data
****************************************
F3=Exit
F5=Refresh F9=Retrieve F10=Cursor
F11=Toggle F12=Cancel
F16=Repeat find F24=More keys
(C)
COPYRIGHT IBM CORP. 1981, 2002.
Columns . . . : 1
71 Browse PB01U01S/MYRPG
SEU==>
EXA4
FMT
C
.....CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++
*************** Beginning of data *************************************
0001.00 C Z-ADD3 N1
20
0002.00 C Z-ADD2 N2
20
0003.00 C Z-ADD0 N3
40
0004.00 C N1 SUB
N2 N3
0005.00 C N3 DSPLY
0006.00 C SETON LR
****************** End of data
****************************************
F3=Exit
F5=Refresh F9=Retrieve F10=Cursor
F11=Toggle F12=Cancel
F16=Repeat find F24=More keys
(C)
COPYRIGHT IBM CORP. 1981, 2002.
MULT (Multiplication)
Value Type
|
Permissible values
|
N01N02N03
|
Optional
|
Factor1
|
First
Variable
|
Factor2
|
Second Variable
|
Result
|
Variable to store the Result of
multiplication of First variable and Second Variable
|
Length
|
Length of Variable which store the Result of multiplication of First variable and Second Variable
|
Decimal Positions
|
Specifies Decimal Position of Variable
which store the Result of multiplication of First variable and Second
Variable
|
Resulting Indicator
|
Optional
|
The
MULT operation allows you to multiply the contents of Factor1 and Factor2
and Store the result in the result
field.
60 MULT HRS MIN
A
second format for the MULT operation exists in which we omit Factor1. Factor2
multiplies the value of the result field and the product is stored in the
result field.
Columns . . . : 1
71 Browse PB01U01S/MYRPG
SEU==>
EXA5
FMT
C .....CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++
*************** Beginning of data *************************************
0001.00 C Z-ADD3 N1
20
0002.00 C Z-ADD2 N2
20
0003.00 C Z-ADD0 N3
40
0004.00 C N1 MULT N2 N3
0005.00 C DSPLY N3
0006.00 C SETON LR
****************** End of data
****************************************
F3=Exit
F5=Refresh F9=Retrieve F10=Cursor
F11=Toggle F12=Cancel
F16=Repeat find F24=More keys
(C)
COPYRIGHT IBM CORP. 1981, 2002.
DIV
Value Type
|
Permissible values
|
N01N02N03
|
Optional
|
Factor1
|
Dividend (Variable to be divided)
|
Factor2
|
Divisor (Variable by which Dividend is divided)
|
Result
|
Store the quotient
|
Length
|
Length of Variable which store the quotient
|
Decimal Positions
|
Specifies Decimal Position of Variable
which store the quotient
|
Resulting Indicator
|
Optional
|
The DIV
operation is used to divide Factor1 by factor2, storing the quotient in the
result field. This operation would be expressed as
Result = Factor1/factor2
Eg.
TOTAMT DIV CNT AMT
A
second format for the DIV operation exists in which we omit Factor1.In this
case, the result field is divided by Factor2 and the quotient is the result
field.
MVR (Move Remainder)
Value Type
|
Permissible values
|
N01N02N03
|
Optional
|
Factor1
|
Not
required
|
Factor2
|
Not
required
|
Result
|
Store the remainder
|
Length
|
Length of Variable which store the remainder
|
Decimal Positions
|
Specifies Decimal Position of Variable
which store the remainder
|
Resulting Indicator
|
Optional
|
Occasionally
when dividing we would need remainder value for further calculations.
Factor1
and Factor2 is not used with this operation. The remainder value is stored in a
result field, which must be an integer field.
If we
use MVR, it must immediately follow a DIV operation.
TOTMIN DIV 60 HRS
MVR RM
Columns . . . : 1
71 Browse PB01U01S/MYRPG
SEU==>
EXA6
FMT
C
.....CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++
*************** Beginning of data *************************************
0001.00 C
Z-ADD3 N1
20
0002.00 C Z-ADD2 N2
20
0003.00 C Z-ADD0 N3
40
0004.00 C N1 DIV
N2 N3
0005.00 C MVR N4 20
0006.00 C 'DIV = ' DSPLY
N3
0007.00 C 'RIM = ' DSPLY
N4
0008.00 C SETON LR
0009.00 ****************** End of data
****************************************
F3=Exit
F5=Refresh F9=Retrieve F10=Cursor
F11=Toggle F12=Cancel
F16=Repeat find F24=More keys
(C)
COPYRIGHT IBM CORP. 1981, 2002.
Note : if the size of resulting value of a
arithmetic operation is longer than the size specified then value is right
justified.
No comments:
Post a Comment