Overview:: © Dukestar Technologies Pvt. Ltd. 1/16
Overview:: © Dukestar Technologies Pvt. Ltd. 1/16
Day 6
Introduction:
Overview:
This module enables the student to get basic concept of RPG/400.
Outline:
Topics covered
RPG/400 !ntroduction.
!ndicators in RPG programming
Program "peci#cation.
$ssignment operators.
$rithmetic %perators.
Objective:
&y the end of this module the student should be able to'
(nderstand the Calculation "peci#cation.
(nderstand the $ssignment operators.
(nderstand the $rithmetic %perators.
) Du*e"tar Technologies Pvt. +td.
,/,6
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction
Day 6
RPG/400
RPG/400 is a programming language designed to process data for business and
commercial applications. This language is uni-ue in nature from other programming
languages as it uses a number of speci#cations that are position oriented to .rite a
program. RPG/400 is a predecessor of RPG/!! 0used on system /162 and RPG 3!!! 0used on
system/142.
The follo.ing is the speci#cation se-uence to code an RPG/400 program.
5ontrol speci#cation (H)
6ile speci#cation (F)
78tension speci#cation (E)
+ine counter speci#cation (L)
!nput speci#cation (I)
5alculation speci#cation (C)
%utput speci#cation (O)
The speci#cation if present in the program needs to be de#ned in the se-uence 9/6/7/+/!/
5/%
$n each type speci#cation of line is bro*en in various parts. "peci#c values/verbs are
re-uired in these positions.
RPG ro!r"# i$ run wit% CL co##"nd C&LL '(len"#e) on co##"nd line*
Indic"tor$:
+e(nition:
!ndicators in RPG and 5+ programs are the memory position 0memory variables2 .hich
contain value :0 or ,; :<%= or <%66;. !ndicator may be compared .ith a &oolean
variable in any other language .ith value :True; or :6alse;.
!ndicator names are speci#c in nomenclature and have particular usage in the program.
,"#e ,o#encl"tu
re
Puro$e
General Purpose
!ndicator
0,/>> Programmer can use these indicators for setting a
particular condition.
%ver?o. !ndicator %$/%G %@ This indicator is assigned to printer #le and signal
the end of the a printed page
+ast Record
!ndicator
+R +R indicator .hen on cause the termination of the
program.
Aatching Record
!ndicator
A,/A> 0AR2 This !ndicator is used for Doing conditional
calculations and %utputs for any B records if they
match or do not match.
5ontrol +evel
!ndicator
+,/+> These !ndicators are used for De#ning various
5ontrol &rea*s.
Ce .ill discuss more on the !ndicators at the point of the usage in the course.
6irst .e .ill study the calculation speci#cation.
) Du*e"tar Technologies Pvt. +td.
B/,6
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction
Day 6
C"lcul"tion$ -eci(c"tion$
5alculation speci#cations describe the calculations to be done in the data and the order
of the calculations. 5alculation speci#cations can also be used to control certain input
operations.
The information includes'
5ontrol/level and conditioning for the operation speci#ed
6ields or constants to be used in the operation
The operation processed
Chether resulting indicators are used in the operation or not
-te .* Pre$$ F/
6ollo.ing screen is displayed
Start Source Entry Utility (STRSEU)
Type choices, press Enter.
Source file . . . . . . . . . . > MYRPG Nae, !PR"
#i$rary . . . . . . . . . . . > P%&'U&'S Nae, !#(%#, !)UR#(%, !PR"
Source e$er . . . . . . . . . RPG' Nae, !PR", !SE#E)T
Source type . . . . . . . . . . RPG Nae, !S*ME, %*S, %*SP...
Te+t ,-escription, . . . . . . . My first pro.ra
%otto
/01E+it /21Propt /31Refresh /'41)ancel /'015o6 to use this -isplay
/421More 7eys
) Du*e"tar Technologies Pvt. +td.
1/,6
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction
Day 6
-te 0* Pre$$ Enter
)oluns . . . 8 ' 9' E-it P%&'U&'S:MYRPG
SEU11> RPG'
/MT 5 .....5........'..);Y(....S..............'./............................
!!!!!!!!!!!!!!! %e.innin. of -ata !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
,,,,,,,
,,,,,,,
,,,,,,,
,,,,,,,
,,,,,,,
,,,,,,,
,,,,,,,
,,,,,,,
,,,,,,,
,,,,,,,
,,,,,,,
,,,,,,,
,,,,,,,
,,,,,,,
,,,,,,,
!!!!!!!!!!!!!!!!!! En- of -ata !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/01E+it /21Propt /31Refresh /<1Retrie=e /'&1)ursor /''1To..le
/'>1Repeat fin- /'91Repeat chan.e /421More 7eys
Me$er RPG' a--e- to file P%&'U&'S:MYRPG. ?
-te 1* Pre$$ Enter
)oluns . . . 8 ' 9' E-it P%&'U&'S:MYRPG
SEU11> RPG'
/MT 5 .....5........'..);Y(....S..............'./............................
!!!!!!!!!!!!!!! %e.innin. of -ata !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!! En- of -ata !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/01E+it /21Propt /31Refresh /<1Retrie=e /'&1)ursor /''1To..le
/'>1Repeat fin- /'91Repeat chan.e /421More 7eys
) Du*e"tar Technologies Pvt. +td.
4/,6
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction
Day 6
-te 4* 23e IPC t%en Pre$$ Enter
)oluns . . . 8 ' 9' E-it P%&'U&'S:MYRPG
SEU11> RPG'
/MT 5 .....5........'..);Y(....S..............'./............................
(P) !!!!!!!!!!!!!!! %e.innin. of -ata !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!! En- of -ata !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/01E+it /21Propt /31Refresh /<1Retrie=e /'&1)ursor /''1To..le
/'>1Repeat fin- /'91Repeat chan.e /421More 7eys
)oluns . . . 8 ' 9' E-it P%&'U&'S:MYRPG
SEU11> RPG'
/MT 5 .....5........'..);Y(....S..............'./............................
!!!!!!!!!!!!!!! %e.innin. of -ata !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
,,,,,,,
!!!!!!!!!!!!!!!!!! En- of -ata !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Propt type . . . ) Se@uence nu$er . . . ,,,,,,,
#e=el N&'N&4N&0 /actor ' Aperation /actor 4 Result
;ecial
#en.th Positions 5:N:P 5( #A EB )oent
/01E+it /21Propt /31Refresh /''1Pre=ious recor-
/'41)ancel /401Select propt /421More 7eys
) Du*e"tar Technologies Pvt. +td.
D/,6
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction
Day 6
5 "peci#cation line is bro*en into follo.ing parts.
Po$ition$ ,"#e Entr3
,/B Page Page number
1/D +ine +ine number
6 6orm type 5
E/4 5ontrol level &lan*
+0
+,/+>
+R
"R
$=%R
>/,E 5onditioning !ndicators &lan*
0,/>>
F$/F= FP/FG
+,/+>
+R
AR
9,/9>
RT
(,/(4
%$/%G%@
,4/BE 6actor , "ymbolic name or literal
B4/1B %peration %peration code
11/4B 6actor B "ymbolic name or literal
41/44 Result #eld 6ield name
4>/D, 6ield length &lan*
,/,D
,/10
,/BD6
DB Decimal positions &lan*
0/>
D1 %peration 78tender &lan*
P
9
=
D4/D> Resulting indicators &lan*
0,/>>
F$/F= FP 3FG
9,/9>
+,/+>
+R
H$/%G %@
(,/(4
RT
60/E4 5omments 5omments
ED/40 %ptional
) Du*e"tar Technologies Pvt. +td.
6/,6
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction
Day 6
F"ctor.: 6actor , can be symbolic or literal or actual data on .hich operation is to be
performed. it may or may not be present its usage depends on the operation code used.
Oer"tion: $n operation code 0%pcode2 describes the operation to be performed using
factor , and factor B and the result #eld. This entry is compulsory for the calculation
spec.
F"ctor0: 6actor B can be symbolic or literal or actual data on .hich operation is to be
performed. it may or may not be present its usage depends on the operation code used.
Re$ult: this entry speci#es the name of the result #eld that contains the result of the
calculation operation. it may or may not be present . !ts usages depend on the operation
code used.
H/,/P: This entry speci#es operation e8tender. %peration e8tender are simple char
.hose purpose is to provides additional attribute to the operation that they accompany
Re$ultin! Indic"tor$ (HI LO E4): These indicator values .ill be set on or oI
depending on the opcode used and are used to chec* the result of the operation.
) Du*e"tar Technologies Pvt. +td.
E/,6
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction
Day 6
&$$i!n#ent oer"tor$
56&++ (5ero "nd &dd):
7"lue 23e Per#i$$ible v"lue$
=0,=0B=01 %ptional
6actor, =ot re-uired
6actorB @alue to be assign to variable
Result =ame of @ariable
+ength +ength of @ariable
Decimal
Positions
"peci#es Decimal Position
Resulting
!ndicator
%ptional
!t is an assignment operation for numeric #elds. !t Jeros out the result #eld and adds
6actorB to it. The eIect of this operation is to assign the value of factorB to the result
#eld.
)oluns . . . 8 ' 9' E-it P%&'U&'S:MYRPG
SEU11> EC*'
/MT ) .....)#&N&'N&4N&0/actor'???Apc-e/actor4???Result#en;55i#oE@)oents????
!!!!!!!!!!!!!!! %e.innin. of -ata !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
&&&4.&& ) DE*;;4& M*C 3&
!!!!!!!!!!!!!!!!!! En- of -ata !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Propt type . . . ) Se@uence nu$er . . . &&&4.&&
#e=el N&'N&4N&0 /actor ' Aperation /actor 4 Result
DE*;; 4& M*C
;ecial
#en.th Positions 5:N:P 5( #A EB )oent
3 &
/01E+it /21Propt /31Refresh /''1Pre=ious recor-
/'41)ancel /401Select propt /421More 7eys
9ere variable A$K .ith length D and decimal positions 0 initialiJed .ith value B0.
) Du*e"tar Technologies Pvt. +td.
4/,6
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction
Day 6
56-89 (5ero "nd -ub):
7"lue 23e Per#i$$ible v"lue$
=0,=0B=01 %ptional
6actor, =ot re-uired
6actorB @alue to be assign to variable
Result =ame of @ariable
+ength +ength of @ariable
Decimal
Positions
"peci#es Decimal Position
Resulting
!ndicator
%ptional
L/"(& operator .or*s similarly to L/$DD e8cept that after Jeroing out the result #eld it
subtracts the value of factorB from result #eld. 9ence it is used for reversing the sign of a
#eld.
)oluns . . . 8 ' 9' E-it P%&'U&'S:MYRPG
SEU11> EC*4
/MT ) .....)#&N&'N&4N&0/actor'???Apc-e/actor4???Result#en;55i#oE@)oents????
!!!!!!!!!!!!!!! %e.innin. of -ata !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
&&&4.&& ) DESU%0& M(N
!!!!!!!!!!!!!!!!!! En- of -ata !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Propt type . . . ) Se@uence nu$er . . . &&&4.&&
#e=el N&'N&4N&0 /actor ' Aperation /actor 4 Result
DESU% 0& M(N
;ecial
#en.th Positions 5:N:P 5( #A EB )oent
3 &
/01E+it /21Propt /31Refresh /''1Pre=ious recor-
/'41)ancel /401Select propt /421More 7eys
9ere variable A$K .ith length D and decimal positions 0 initialiJed .ith value /10.
"iJe of the veriable mustbe de#nes at least once in the program 0or in #les used2. "iJe
de#nition can be done repeatedly but it cannot be diIerent than other de#nition.
Good practice is to be de#ning the variable siJe only once. 6or numeric variables the
decimal siJe must be de#ned 0even if it is Jero2.
) Du*e"tar Technologies Pvt. +td.
>/,6
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction
Day 6
&rit%#etic Oer"tion$
$rithmetic operations can be done only on numeric #elds. 6actor , and 6actor B are
not changed by an arithmetic operation. $ny data placed in the result #eld replaces
the data that .as there. 9alf adMust can be speci#ed for all arithmetic operations
e8cept A%@7R.
&++ (&ddition)
7"lue 23e Per#i$$ible v"lue$
=0,=0B=01 %ptional
6actor, 6irst @ariable 0optional2
6actorB "econd @ariable/constant
Result @ariable to store the "um of 6irst variable and "econd @ariable or
6actorB added to result variable
+ength +ength of @ariable .hich store the sum of 6irst variable and "econd
@ariable
Decimal
Positions
"peci#es Decimal Position of @ariable .hich store the sum of 6irst
variable and "econd @ariable
Resulting
!ndicator
%ptional
$dds the values of 6actor, and 6actorB and stores the result in a result #eld. 6actor, and
6actorB can be numeric #elds or numeric literal.
7g.
$&5 $DD , 5=T
Aore recent versions of RPG allo. you to omit 6actor, entry.
7g.
$DD , 5=T
&oth the statements produce the same result.
)oluns . . . 8 ' 9' %ro6se P%&'U&'S:MYRPG
SEU11> EC*0
/MT ) .....)#&N&'N&4N&0/actor'???Apc-e/actor4???Result#en;55i#oE@)oents????
!!!!!!!!!!!!!!! %e.innin. of -ata !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
&&&'.&& ) DE*;;0 N' 4&
&&&4.&& ) DE*;;4 N4 4&
&&&0.&& ) DE*;;& N0 2&
&&&2.&& ) N' *;; N4 N0
&&&3.&& ) N0 ;SP#Y
&&&>.&& ) SETAN #R
&&&9.&& !!!!!!!!!!!!!! En- of -ata !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/01E+it /31Refresh /<1Retrie=e /'&1)ursor /''1To..le /'41)ancel
/'>1Repeat fin- /421More 7eys
) Du*e"tar Technologies Pvt. +td.
,0/,6
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction
Day 6
()) )APYR(G5T (%M )ARP. '<F', 4&&4.
) Du*e"tar Technologies Pvt. +td.
,,/,6
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction
Day 6
5ompile above program using option ,4 and call it using 5$++ N#lenameO on command
line.
-89 (-ubtr"ct)
7"lue 23e Per#i$$ible v"lue$
=0,=0B=01 %ptional
6actor, 6irst @ariable
6actorB "econd @ariable
Result @ariable to store the DiIerence of 6irst variable and "econd @ariable
+ength +ength of @ariable .hich store the DiIerence of 6irst variable and
"econd @ariable
Decimal
Positions
"peci#es Decimal Position of @ariable .hich store the DiIerence of 6irst
variable and "econd @ariable
Resulting
!ndicator
%ptional
"ubtracts the value of 6actorB from 6actor, and stores the result in the result #eld.
6actor, and 6actorB can be numeric #elds or numeric literal. This operation .ould be
e8pressed as
Result P factorB 3 6actor,
7g.
$&5 "(& , 5=T 0"ubtract , from $&52
Aore recent versions of RPG allo. you to omit 6actor, entry.
"(& , 5=T 0"ubtract , from $&52
Chich means subtract 6actorB from result #eld and stores the result in the result #eld.
&oth the statements produce the same result.
)oluns . . . 8 ' 9' %ro6se P%&'U&'S:MYRPG
SEU11> EC*2
/MT ) .....)#&N&'N&4N&0/actor'???Apc-e/actor4???Result#en;55i#oE@)oents????
!!!!!!!!!!!!!!! %e.innin. of -ata !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
&&&'.&& ) DE*;;0 N' 4&
&&&4.&& ) DE*;;4 N4 4&
&&&0.&& ) DE*;;& N0 2&
&&&2.&& ) N' SU% N4 N0
&&&3.&& ) N0 ;SP#Y
&&&>.&& ) SETAN #R
!!!!!!!!!!!!!!!!!! En- of -ata !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/01E+it /31Refresh /<1Retrie=e /'&1)ursor /''1To..le /'41)ancel
/'>1Repeat fin- /421More 7eys
) Du*e"tar Technologies Pvt. +td.
,B/,6
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction
Day 6
()) )APYR(G5T (%M )ARP. '<F', 4&&4.
) Du*e"tar Technologies Pvt. +td.
,1/,6
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction
Day 6
:8L2 (:ultilic"tion)
7"lue 23e Per#i$$ible v"lue$
=0,=0B=01 %ptional
6actor, 6irst @ariable
6actorB "econd @ariable
Result @ariable to store the Result of multiplication of 6irst variable and "econd
@ariable
+ength +ength of @ariable .hich store the Result of multiplication of 6irst
variable and "econd @ariable
Decimal
Positions
"peci#es Decimal Position of @ariable .hich store the Result of
multiplication of 6irst variable and "econd @ariable
Resulting
!ndicator
%ptional
The A(+T operation allo.s you to multiply the contents of 6actor, and 6actorB and "tore
the result in the result #eld.
60 A(+T 9R" A!=
$ second format for the A(+T operation e8ists in .hich .e omit 6actor,. 6actorB
multiplies the value of the result #eld and the product is stored in the result #eld.
)oluns . . . 8 ' 9' %ro6se P%&'U&'S:MYRPG
SEU11> EC*3
/MT ) .....)#&N&'N&4N&0/actor'???Apc-e/actor4???Result#en;55i#oE@)oents????
!!!!!!!!!!!!!!! %e.innin. of -ata !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
&&&'.&& ) DE*;;0 N' 4&
&&&4.&& ) DE*;;4 N4 4&
&&&0.&& ) DE*;;& N0 2&
&&&2.&& ) N' MU#T N4 N0
&&&3.&& ) ;SP#Y N0
&&&>.&& ) SETAN #R
!!!!!!!!!!!!!!!!!! En- of -ata !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/01E+it /31Refresh /<1Retrie=e /'&1)ursor /''1To..le /'41)ancel
/'>1Repeat fin- /421More 7eys
()) )APYR(G5T (%M )ARP. '<F', 4&&4.
) Du*e"tar Technologies Pvt. +td.
,4/,6
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction
Day 6
+I7
7"lue 23e Per#i$$ible v"lue$
=0,=0B=01 %ptional
6actor, Dividend 0@ariable to be divided2
6actorB Divisor 0@ariable by .hich Dividend is divided2
Result "tore the -uotient
+ength +ength of @ariable .hich store the -uotient
Decimal
Positions
"peci#es Decimal Position of @ariable .hich store the -uotient
Resulting
!ndicator
%ptional
The D!@ operation is used to divide 6actor, by factorB storing the -uotient in the result
#eld. This operation .ould be e8pressed as
Result P 6actor,/factorB
7g.
T%T$AT D!@ 5=T $AT
$ second format for the D!@ operation e8ists in .hich .e omit 6actor,.!n this case the
result #eld is divided by 6actorB and the -uotient is the result #eld.
:7R (:ove Re#"inder)
7"lue 23e Per#i$$ible v"lue$
=0,=0B=01 %ptional
6actor, =ot re-uired
6actorB =ot re-uired
Result "tore the remainder
+ength +ength of @ariable .hich store the remainder
Decimal
Positions
"peci#es Decimal Position of @ariable .hich store the remainder
Resulting
!ndicator
%ptional
%ccasionally .hen dividing .e .ould need remainder value for further calculations.
6actor, and 6actorB is not used .ith this operation. The remainder value is stored in a
result #eld .hich must be an integer #eld.
!f .e use A@R it must immediately follo. a D!@ operation.
T%TA!= D!@ 60 9R"
A@R RA
) Du*e"tar Technologies Pvt. +td.
,D/,6
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction
Day 6
)oluns . . . 8 ' 9' %ro6se P%&'U&'S:MYRPG
SEU11> EC*>
/MT ) .....)#&N&'N&4N&0/actor'???Apc-e/actor4???Result#en;55i#oE@)oents????
!!!!!!!!!!!!!!! %e.innin. of -ata !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
&&&'.&& ) DE*;;0 N' 4&
&&&4.&& ) DE*;;4 N4 4&
&&&0.&& ) DE*;;& N0 2&
&&&2.&& ) N' ;(" N4 N0
&&&3.&& ) M"R N2 4&
&&&>.&& ) ,;(" 1 , ;SP#Y N0
&&&9.&& ) ,R(M 1 , ;SP#Y N2
&&&F.&& ) SETAN #R
&&&<.&& !!!!!!!!!!!!!!!!!! En- of -ata !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/01E+it /31Refresh /<1Retrie=e /'&1)ursor /''1To..le /'41)ancel
/'>1Repeat fin- /421More 7eys
()) )APYR(G5T (%M )ARP. '<F', 4&&4.
=ote ' if the siJe of resulting value of a arithmetic operation is longer than the siJe
speci#ed then value is right Musti#ed.
) Du*e"tar Technologies Pvt. +td.
,6/,6
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.