You are on page 1of 26

Introduction To RPG IV

Day 27
Introduction To RPG IV
Overview:
This module enables the student to understand the concept of RPG IV.

Outline:
Topics covered,
a. Introduction to RPG IV
b. uilt !in functions
c. Date and Time Data Types
Objective:
y the end of this module, the student should be able to"
a. #nderstandin$ %f asic &oncepts RPG IV
b. uilt In 'unction
c. Date and Time Data Types
( Du)e*tar Technolo$ies Pvt. +td.
,-2.
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction To RPG IV
Day 27
Introduction to RPG IV
RPG IV is the latest version of RPG lan$ua$e. RPG IV is a synta/ that participates in I01s
Inte$rated +an$ua$e 2nvironment 3I+24 architecture or pro$rammin$ model. RPG IV
diver$es from its predecessor RPG III, in si$ni5cant 6ays. This latest release is bac)6ard
compatible. That means pro$ram 6ritten before ,778 can easily be converted to RPG IV
and subse9uently modi5ed 6ithout complete pro$ram re6rite.
RPG III 6as critici:ed as di;cult to understand because of its short data names,
abbreviated operation codes and ri$idly 5/ed format. The critics contended that the
lan$ua$e 6as sho6in$ a$e in its limited choice of data types 3e.$. no direct support date
data types4 and its inability to handle multidimensional arrays etc.
To address some of these shortcomin$s in RPG, I0 introduced in ,77<, concurrent 6ith
the release of Version = Release of %*-<>>, improved version of RPG and named it RPG
IV.
RPG IV rela/es many of the strict 5/ed format re9uirements imposed by previous RPG
versions, allo6in$ free!format e/pressions and )ey6ord notation in its speci5cations.
Data namin$ limits have been e/tended and many other arti5cial limits have been
e?ectively removed from the lan$ua$e. RPG IV adds several ne6 or$ani:ational concepts
li)e a central data de5nition speci5cation and procedure prototypin$.
In 2>>>, I0 created a ne6 all inclusive eServer family@ the A*-<>> became the eServer,
iSeries 400 (iSeries in short4. Recent release of RPG IV has focused on enablin$ the RPG
IV architecture to co!e/ist 6ith Internet!based applications and obBect!oriented
lan$ua$es li)e Cava.
Summary of RPG III to RPG IV Change:
o A source mi$ration tool is provided to convert RPG III source code to RPG IV
source code. The default source!5le name has chan$ed from DRPG*R& to
DRPG+2*R& and the record len$th has been e/panded from 72 to ,,2 bytes.
The e/istin$ *2# date and se9uence number 5elds remain unchan$ed. The
increase of the source statement len$th from E> to ,>> characters
accommodates the ne6 synta/ 6ith lon$er 5le and 5eld names as 6ell as the
e/panded comment len$th 3positions E, to ,>>4.
o The ne6 De5nition speci5cations. 3P!spec4 allo6 you to de5ne sub!procedures.
In RPG terms, sub!procedures are similar to sub!routines e/cept"
Fou can pass parameters to them.
They do not use RPG cycle
They can be prototyped 36hich causes the compiler to chec)
parameters for consistency4.
They allo6 you to de5ne local variables.
They can be invo)ed in e/pressions, similar to I0 supplied built!in
functions.
Fou can call them outside the source module in 6hich they are de5ned
if they are e/ported.
RPG IV no6 supports ,>!character 5le, format, 5eld, constant, data structure,
)ey!list, subroutine label and other symbolic names.
The underscore3G4 is no6 valid in symbolic name but it cannot be the 5rst
character. Thus 20PGHA02 is a valid 5eld name but GHA02 is not.
Array subscripts are speci5ed usin$ parentheses 34 instead of a comma1,1.
( Du)e*tar Technolo$ies Pvt. +td.
2-2.
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction To RPG IV
Day 27
ARR,I in RPG III becomes ARR3I4 in RPG IV.
o #ppercase and lo6ercase characters can be used any6here in an I+2 RPG
pro$ram. The 5eld names 2mpHame and 2mp+oc are no6 valid. The
operation codes J&KAIH1, J&hain1 all perform the same function. The 3I+2
RPG compiler converts the lo6ercase characters to uppercase. &omments,
literals 36ith the e/ception of he/adecimal literals4, compile time array and
table data are not translated to uppercase. &urrency symbol 3L4, date and
time!edit values on the &ontrol speci5cations 3K!spec4, date and time
separator characters on the Input speci5cation 3I!spec4 and comparison
characters on Record Identi5cation entries on I!spec are also not converted
to uppercase.
o lan) lines are permitted in RPG IV. *ource statements that are blan) in
positions . to E> are treated as comments. An asteris) 3M4 in position 7
also forces a statement to be a comment Bust as it does in RPG III. In
$eneral, positions E, to ,>> are treated as comments in source
statements e/cept for compile!time table and array data.
o 'reeform mathematical e/pressions and lo$ical e/pressions are available.
Nith the 2VA+ operation you area no6 able to use natural mathematical
e/pressions as follo6s"
2VA+ *+*T%TO*+*A0T,P*+*A0T2
o uilt!in functions are similar to operation codes as they perform operation
on $iven data. Ko6ever, built!in functions can be embedded into an
e/pression. 2.$.
2VA+ +*THA02OQ*#*T3'#++HA02",."2>4
o Nith ne6er V<R2 built!in functions, you can eliminate resultin$ indicators
on operation such as &KAIH, *2TA++ or +%%R#P. 2.$. you can use the
Q'%#HD function determine if a &KAIH 6as successful as sho6n in
follo6in$ statement"
&#*TS&KAIH &#*TR2&
I' Q'%#HD3&#*T0*T4
o Ho6 you have more po6erful date manipulation capabilities throu$h date,
time and time!stamp data type support includin$ ne6 date and time
operation such as Add Duration 3ADDD#R4 and *ubtract Duration
3*#D#R4.
o 0any operation code names such as +%R#P, D2+2T, #PDAT, #H+&R and
R2DP2 have been chan$ed to lon$er and more meanin$ful names as
+%%R#P, D2+2T2, #PDAT2, #H+%&R and R2ADP2.
Com!arion between RPG III and RPG IV"
*r.H
o
RPG III RPG IV
,. &ompilation of source members creates an
e/ecutable obBect called MPG0 usin$ command
&RTIIIPG0 36here III is a pro$ram type4
RPG III
&ompile
MPG0
&ompilation of source
member, 5rst creates a non!
e/ecutable obBect M0%D#+2
usin$ command
&RTIII0%D. 3Nhere III is
a pro$ram type4. Various
( Du)e*tar Technolo$ies Pvt. +td.
=-2.
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction To RPG IV
Day 27
2.$. &RTRPGPG0" RPG pro$ram obBect.
&RT&+PG0" &+ pro$ram obBect
modules are bound to$ether
to create pro$ram obBect
MPG0 usin$ command
&RTPG0. 3It is not any
particular type of pro$ram,
Bust MPG04.
2. RPG III provides dynamic calls. 3&all to e/ternal
pro$rams are resolved at run time4
RPG IV provides static
3&ompile time4 as 6ell as
dynamic 3run!time4 call.
=. RPG III supports %P0 debu$$er. RPG IV supports source!level
debu$$er.
<. Record +en$th of the source codeO72 Record +en$th of the source
code O,,2
8 'ield names are restricted up to . chars. RPG IV supports ,>!character
5eld len$th.
.. &onstants can be de5ned up to 28. bytes &onstants can be de5ned up
to ,>2< bytes.
7. Decimal places up to 7 di$its Decimal places up to =>
di$its
E &haracter variables and array elements are
restricted up to 28. bytes
&haracter variables and array
elements are of =27.7 bytes
7 0a/imum 8> 5les can be opened. Ho limits.
,> +en$th of 'actor , and 'actor 2O,> +en$th of 'actor , and 'actor
2O,<
,, %pcode len$th O8 %pcode len$th O,>
,2 'i/ed format 'ree 'ormat only for 'actor 2
,= Indicators are compulsory Hot compulsory
,< Variables scope is limited to pro$ram only. Ho
concept of +ocal Variable
Introduces a concept of +ocal
Variables
Introduction to RPG IV !eci#cation in brief
RPG IV pro$rams are 6ritten as 5/ed!format or free!format speci5cations. Di?erent
speci5cation forms convey di?erent )inds of information to the RPG IV compiler, 6hich
translates the pro$ram into machine lan$ua$e.
The 2 specs in RPG III have been removed in RPG IV. The 2 specs and I specs to$ether
are de5ned by ne6 D speci5cations. A P spec is one more specs introduced in RPG IV.
$ S!eci#cation
S!eci#cation %ame
Identi#er in &
th
!oition
Keader *peci5cations
'
'ile Description *peci5cations
(
De5nition *peci5cations
)
Input *peci5cations 3for pro$ram
described input 5les4
I
&alculation *peci5cation
C
Procedure *peci5cation
P
%utput *peci5cations
O
S!eci#cation in detail
' S!eci#cation
( Du)e*tar Technolo$ies Pvt. +td.
<-2.
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction To RPG IV
Day 27
In I+2 RPG III, Keader speci5cation is used for 6ritin$ header information in a
pro$ram. Ko6ever, instead of enterin$ values in speci5c positions 3'i/ed!format4,
as in RPG III, I+2 RPG uses )ey6ords notations. 0any &ompile options can be
speci5ed throu$h Rey6ords in K specs. Positions 7 throu$h E> are used for
enterin$ control speci5cation )ey6ords.
o )*T(+T ,)ate (ormat-: DAT2'0T speci5es the format of date literals
and date 5elds 6ithin the pro$ram. This )ey6ord accepts t6o parameters.
I" Date format 3Re9uired4 and 2" separator character 3optional4. Default
date format is MI*% and the default separator character is 3!4.
2.$. )*T(+T ,./01-
The possible values of date formats are as belo6"
M0DFO300-DD-FF4
MD0FO3DD-00-FF4
MF0DO3FF-00-DD4
MC#+O3FF-DD4
M#*AO300-DD-FFFF4
M2#RO3DD.00.FFFF4
MCI*O3FFFF!00!DD4
o )*T2)IT ,)ate 2dit-: DAT22DIT speci5es the separator character for the
Date format used. This )ey6ord accepts 2 parameters ,. Date format 2.
*eparator &haracter. 3Default is -4. Ne can specify various date separator
character as J!J Jand1. 2. $" )*T2)IT ,.3+)4-
o C0RS3+ ,Current Symbol-: &#R*F0 speci5es the format of time literals
and time 5elds 6ithin the pro$ram. The default is MI*% format 6ith default
separator as 3.4. This )ey6ord accepts 2 parameters" ,. Time format
3re9uired4 and 2" *eparator 3optional4. The possible values are as follo6s"
.I*%O3KK.00.**4
MK0*O3KK"00"**4
M#*AO3KK"00" A0 or KK"00" P04
2"g"TI+(+T ,.0S*-"
( S!eci#cation
'ile *peci5cation is used for declarin$ 5les in the pro$ram. It also describes ho6 the 5les
6ill be used 6ithin a pro$ram. In I+2 RPG, '!specs use a combination of 5/ed notation
and )ey6ord notation. The 5/ed notation portion e/tends from position 7 to <2. The '!
specs of I+2 RPG have been modi5ed to accommodate e/panded len$th. The 5le name is
e/panded from E characters to,> characters and record!len$th is e/panded from <
characters to 8 characters.
'unctions de5ned in RPG III are de5ned in terms of )ey6ords in I+2 RPG. *ome of the
e/amples are as belo6"
o R2%*+2 ,Old Record (ormat: %ew Record (ormat-!The R2HA02
)ey6ords allo6 you to chan$e a record!format name used in an e/ternally
described 5le. 2/ample is as follo6s"
o PR2(I5 ,!re#67tring: nbr7of7char7re!laced-: The PR2'II )ey6ord is
used to partially rename the 5elds in e/ternally described 5les. Pre5/
( Du)e*tar Technolo$ies Pvt. +td.
8-2.
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
FMBMLO2 IF E K DISK RENAME (IPM500BM:IPM50r)
Here record format IPM500BM is renamed to IPM50R.
Introduction To RPG IV
Day 27
strin$ is the strin$ 6e 6ant to use as a pre5/ and nbrGofGcharGreplaced
speci5es the number of characters to be replaced.
o S(I12 ,name7of7ub#le: #eld7RR%-: The *'I+2 )ey6ord identi5es any
sub5les used in a display 5le included in a pro$ram. This )ey6ord has 2
parameters"
*ub5le name
'ield, 6hich stores Relative Record Humber.
o 0SROP%: The #*P%RH )ey6ord speci5es that 5le is #ser &ontrolled.
Nhen this )ey6ord is used, 5le must be opened 6ith %P2H operation.
) S!eci#cation
It is the ne6 speci5cation introduced by I+2 for data de5nition. D specs can be
used to de5ne"
o *tandalone 5elds includin$ arrays and tables
o Hamed &onstant
o Data *tructures and their sub5elds.
) !ec re!lace 24!ec of RPG III" (ollowing table e6!lain )4S!ec (ormat"
Statement
Poition
Pur!oe Valid Value
. De5nition *peci5cation D
7!2, Hame of 5eld, array, table, named
constant8 data structure or data
structure sub5eld.
Any valid symbol name
22 Data *tructure Identi5cation
2/ternally described data structures
Hon!e/ternally described data
structures
2
lan)s
2= Type of Data *tructure"
Pro$ram *tatus data structure
Data Area data *tructure
Hon!pro$ram status data structure or
non data area data structure.
*
#
lan)
2<!28 Type of De5nition"
Data structure *ub5eld
Hame constant
Data *tructure
*tandalone 5eld or array
Prototype
Procedure Interface
lan)
&
D*
*
PP
PI
( Du)e*tar Technolo$ies Pvt. +td.
.-2.
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
FMBMLO2 IF E K DISK PREFIX($L:2)
Fields of file MBMLO2 now will be starting from $L.
FTEMP CF E WORKSTN SFILE(subf!":f"!#$RRN)
FITBAL IF E K DISK %SROPN
Introduction To RPG IV
Day 27
2.!=2 'rom Position-)ey6ord"
Rey6ords for 5le information and
pro$ram status data structure.
lan)
I throu$h 7777777
PR%&, M*TAT#*
==!=7 To position-len$th
Data structure de5nition
'ield de5ne +IR2 another 5eld
Absolute end position
Increase or decrease 5eld si:e 6hen
de5nin$ a 5eld +IR2 another 5eld
lan)
, throu$h 7777777
P-!, throu$h 77777
<> Internal type of 5eld, sub5eld or
array element
Data, Time, Timestamp
*i$ned and #nsi$ned Inte$er,
'loatin$ point
Pac)ed, Tone, &haracter
D,T,T
I,#,'
P,*,A
<,!<2 Decimal Positions > throu$h=>
<<!E> Rey6ords 2.$. A+T,DI0,IHT,+IR2
E,!,>> &omments %ptional
26am!le:
D *pecs permit us to consolidate data de5nition in a sin$le place in your pro$ram.
The ) !ec 25TPG+ 9eyword: The 2ITPG0 )ey6ord indicates the e/ternal
name of the pro$ram 6hose prototype is bein$ de5ned. The name can be a
character constant or a character variable. If 2ITPG0 is not speci5ed, then the
compiler assumes that you are de5nin$ a prototype for a procedure, and assi$ns
it the e/ternal name found in positions 7!2,.
Any parameters de5ned by a prototype 6ith 2ITPG0 must be passed by reference@ in
addition you cannot de5ne a return value. If the )ey6ord 2ITPG0 is speci5ed on the
( Du)e*tar Technolo$ies Pvt. +td.
7-2.
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
&.C'(s)*()
!MP"M ! !O"#$ %&Midrange !om'(ting)*
L+R ! &abcdefg,-.lmno'/rs0
$(1w234)
$went3 ! !O"#$ %20*
2+S)*(#*!'(" F"!#
$flag # 25 I"6 %7Blan.s*
and"ame # LI89 %PR"5M9*
,+ D*)* S)ru-)ur"
!:M ; <
:: 5 =
> ?
.+Arr*/s
9P$ # 2 IM%;0* !$5$5 P9RR! %;* 5#!9"
5+T*b!"s
$5B9P # 2 IM%;0* P9R! %;* 5#!9"
$5B$O$ # ? IM%;00* P9RR!%;* 5#!9"
Introduction To RPG IV
Day 27
prototype, the call 6ill be a dynamic e/ternal call@ other6ise it 6ill be a bound procedure
call.
In the $iven e/ample, 6hen you perform a call to the &md+inAPI prototype, the API 3built!
in system pro$ram4 D#*&0D+H 6ill actually be called. API D#*&0D+H presents an
%*-<>> system command line for use 6ithin a pro$ram.
I S!eci#cation
In RPG III, I specs are mainly used for 5eld and record information and also de5nin$ data
structures, data areas and named constant. In I+2 RPG, all the data de5nition is
consolidates in D specs at one area of pro$ram. *till I specs are used for de5nin$
pro$ram described 5les. In I+2 RPG, there are many chan$es to the 5eld entry I *pecs"
o 2/panded 'ile name 3up to ,> chars4
o 2/panded Record len$th 3up to =27..4
o 2/ternal date-time format speci5er3for pro$ram described 5le 5eld4
o Date-time separator character.
C S!eci#cation
I+2 RPG & *pecs provides free!form e/pression capabilities to some RPG operations. 'or
e/ample 6ith the use of ne6 2VA+ operation 6e can perform free!form arithmetic
e/pressions. Ne can also perform lo$ical e/pression such as &onditional ranchin$ and
In I+2 RPG, 'A&T%R,, 'A&T%R2 and R2*#+T 5elds have all been increased to ,<
NK2H2D, #PDAT2, D2+2T2, #H+%&R, R2T#RH, R2ADP2, &K2&RR2 etc4
lan) lines are allo6ed and treated as a comment line.
P S!eci#cation
I+2 RPG introduces concept of subprocedures. P!specs are used to de5ne such
*ubprocedures and they denote the be$innin$ and the end of the subprocedure. If 6e
are passin$ any parameters to procedures, such parameter de5nition 3i.e. procedure
interface de5nition4 ta)es place in D *pecs.
( Du)e*tar Technolo$ies Pvt. +td.
E-2.
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
7
cmdLin5P; Pr 9@$PAM%&BC#!MLM)*
!7
! !5IIP !mdLin5PI
! 91al InlrDOn
9E5L O'erationF
91al Bname D Pate2t; G Pate2t2
$,e e2'ression for e1al(ation can contain t,e arit,metic o'erators G
%addition*H 0%s(btraction*H 7%m(lti'lication*H I%di1ision* and
77%e2'onentiation* as well as 'arent,esisH relational s3mbols%e.g.JHK*H
logical o'erators %e.gH 5"H OR* and b(ilt0in f(nctions.
"oteFIn t,e e2am'le gi1en abo1eH G sign indicates !oncatenation.
IF
If %$L9"KL*
91al !nt D $!nt G ;
9ndif
Introduction To RPG IV
Day 27
Nhen you describe P!specs, you describe prototyped procedures or sub!procedures. P!
spec is the simplest I+2 RPG speci5cation. The P!specs 6ere introduced 6hen I+2 RPG
6as enhanced to support sub!procedures.
RPG IV )ecri!tion S!eci#cation Poition
. 'orm Type 3P4
7!2, *ub!procedure Hame
2< e$in-2nd Procedure &ode
<<!E> Rey6ords
Nhen a sub!procedure is de5ned, the main source section of the module containin$ the
sub!procedure de5nition must contain a procedure prototype. *ub!procedure contain the
follo6in$"
o A be$in!procedure speci5cation 3b in position 2< of a procedure
speci5cation4
o A procedure!interface de5nition 3if the procedure returns value or any
parameters4. The procedure interface must match the correspondin$
prototype.
o %ther de5nition speci5cations of variables, constants and prototypes
needed by the sub!procedure. These de5nitions are local de5nitions.
o Any calculation speci5cation needed to perform the tas) of the procedure
If the sub!procedure returns a value, then a return operation must be
coded 6ithin the sub!procedure.
o An end!procedure speci5cation 3c in position 2< of a procedure
speci5cation4.
The Procedure!interface de5nition may be placed any6here 6ithin the de5nition
speci5cations. ut a sub!procedure must be coded in the order stated above.
Procedure name is re9uired in be$in!procedure speci5cation. ut the procedure name is
optional in the end!procedure speci5cation.
The P4S!ec 25PORT :eyword
2IP%RT is the only )ey6ord for the P!spec. 2/port is used to indicate that this procedure
can be invo)ed from another module in the pro$ram. Nith the 2IP%RT )ey6ord
speci5ed, the sub!procedure can be bound to and can be called by any pro$ram.
If a module is entirely self!contained, 2IP%RT )ey6ord is not re9uired. Hormally a sub!
procedure is to encoura$e the reuse of code. De5nin$ the sub!procedures outside of
mainline code and usin$ the 2IP%RT )ey6ord enables this use.
O S!eci#cation
The maBor di?erences bet6een RPG III % specs and I+2 RPG % specs are chan$es to"
o Accommodates ,> character 5le and 5eld names.
o The continuation of literals 3both JP1 or J!J4 and edit 6ords
o *upports for lar$er space before and after values 3 values from > to288are
supported for space before and space after, s)ip before and s)ip after4 and
o *upports for additional data formats 3T,D,T4.
)ate and Time )ata Ty!e
Three data types deal 6ith date and time related information" date, time and timestamp.
Date and Time are self!e/planatory. A timestamp is a combination of a date and time.
RPG supports these data types in calendar!related operations, usin$ certain operation
codes and built in functions.
( Du)e*tar Technolo$ies Pvt. +td.
7-2.
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction To RPG IV
Day 27
To de5ne standalone 5elds 6ith the date-time data types, you specify a D3for dates4 T
3for times4 or T 3for time!stamps4 in column <>. 2ach data type has a default len$th and
display format 3MI*%4.U
The default display format for type date 3D4 is a ,>!byte!lon$ 5eld 6ith format yyyy!mm!
dd. Time 3T4 has a default len$th of E bytes, 6ith format hh. mm. ss. The default display
format for timestamp 3T4 has a len$th of 2. bytes, 6ith format yyy!mm!dd!
hh.mm.ss.mmmmmm.
The date and time data types allo6 alternative display formats 36ith the )ey6ord
DAT'0T4 to the defaults. Date supports ei$ht di?erent formats and Time supports 5ve.
(ollowing table lit the valid )ate and Time format:
)*T(+T
)ecri!tion Re!reentati
on
26am!le
MI*% International *tandards %r$ yyyy!mm!dd 7777!,2!=,
M#*A I0 #*A standard mm-dd-yyy ,2-=,-7777
M2#R I0 2uropean standard dd.mm.yyy =,.,2.7777
MCI* Capanese Industrial *tandard yyy!mm!dd 7777!,2!=,
MF0D Fear-month-day Fy-mm-dd 77-,2-=,
M0DF 0onth-day-year mm-dd-yy ,2-=,-77
MD0F Day-month-year Dd-mm-yy =,-,2-77
MC#+ Culian Fy-ddd 77-=.8
TI+(+T )ecri!tion Re!reentati
on
26am!le
MI*% International *tandard %r$ hh.mm.ss 2=.87.87
M#*A I0 #*A standard hh.mm./0 ,,.87 P0
M2#R I0 2uropean standard hh.mm.ss 2=.87.87
MCI* Capanese Industrial *tandard hh.mm.ss 2=.87.87
MK0* Kours-minutes-seconds hh.mm.ss 2=.87.87
Fou can chan$e default display format of date and time 5elds for a pro$ram as a 6hole
by specifyin$ the DAT'0T and-or TI0'0T 6ithin the &ontrol *peci5cation. The separator
is optional. If you specify an ampersand 3and4 as the separator, a blan) is used as the
separator character.
Related OPCO)2S:
ADDD#R
*#D#R
2ITRA&T
%ew and enhanced O!code
The fre9uency used %pcodes, 6hich are supported only in RPG+2, are as follo6s"
2V*1 ,2valuate e6!reion-
The 2VA+ operation code evaluates an assi$nment statement of the form result
e/pression. The e/pression is evaluated and the result placed in result. Therefore,
result cannot be a literal or constant but must be a 5eld name, array name, array
element, data structure data structure sub5eld, or a strin$ usin$ the Q*#*T
built!in function.
!ol(mns . . . F = >= 9dit PB0;C0;#IM:RPAL9
#9CDDK L9;2
FM$ "ameGGGGGGGGGGG9$sFromGGG$oILGGGIc.8e3wordsGGGGGGGGGGGGGGGGGGGGGGGGG
( Du)e*tar Technolo$ies Pvt. +td.
,>-2.
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction To RPG IV
Day 27
777777777777777 Beginning of data 7777777777777777777777777777777777777
000;.00 str; s 20a
000;.0; str2 s 20a
000L.00 ! e1al str;DM(.estar $ec,nologiesM
000<.00 c 9E5LR str2DM(.estar $ec,nologiesM
000=.00 ! str; #PL:
000=.0; ! str2 #PL:
000>.00 ! e1al 7I"LR D 7on
777777777777777777 9nd of data 7777777777777777777777777777777777777777









FLD92it F<DProm't F5DRefres, FNDRetrie1e F;0D!(rsor F;;D$oggle
F;=DRe'eat find F;>DRe'eat c,ange F2<DMore .e3s
%!* !OP:RIAH$ IBM !ORP. ;N?;H 2002.
%utput of above function 2VA+ and 2VA+R is"
( Du)e*tar Technolo$ies Pvt. +td.
,,-2.
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction To RPG IV
Day 27
is'la3 Program Messages

Oob 0N0555IPB0;C0;#5LIBP59E000N started on 0<I0>I05 at ;0F;NF;0 in s(bs3stem B
DSPL0 Du1"s)*r T"-2('!'3"
DSPL0 u1"s)*r T"-2('!'3"s











Press 9nter to contin(e.



FLD92it F;2D!ancel

%utput of 2VA+ is )u9etar Technologie 6here is i$nored and 2VA+R is u9etar
Technologie where ) i ignored"
25TRCT ,26tract )ate;Time;Timetam!-
The 2ITR&T operation code 6ill return one of"
o The year, month or day part of a date or timestamp 5eld.
o The hours, minutes or seconds part of a time or timestamp 5eld
o The microseconds part of the timestamp 5eld.
The Date Time or Timestamp from 6hich the information is re9uired is speci5ed in factor
2, follo6ed by the duration code. The entry speci5ed in factor2 can be a 5eld, 'actor ,
must be blan).
The result 5eld can be any numeric or character 5eld, sub5eld, array-table element. The
result 5eld is cleared before the e/tracted data is assi$ned. 'or a character result 5eld,
the data is put left adBusted into the result 5eld.
!ol(mns . . . F = >= 9dit PB0;C0;#IM:RPAL9
#9CDDK BIF5;
FM$ "ameGGGGGGGGGGG9$sFromGGG$oILGGGIc.8e3wordsGGGGGGGGGGGGGGGGGGGGGGGGG
777777777777777 Beginning of data 7777777777777777777777777777777777777
000;.00 L$ #
000L.00 7
000<.00 ! 7C#5 MOE9 75$9 L$
0005.00 7"4)r*-) 5'()2 fr'5 *b'6" #*)"
000=.00 ! 9@$R!$ L$F7M LM"$H 2 0
000=.0; c LM"$H ds'l3
000=.02 7"4)r*-) #*)" fr'5 *b'6" #*)"
000>.00 ! 9@$R!$ L$F7 L: 2 0
000>.0; c L: ds'l3
000>.02 7"4)r*-) /"*r fr'5 *b'6" #*)"
000>.0L ! 9@$R!$ L$F7: L:R < 0
000>.05 c L:R ds'l3
000?.00 ! 9E5L 7I"LR D M;M
( Du)e*tar Technolo$ies Pvt. +td.
,2-2.
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction To RPG IV
Day 27
777777777777777777 9nd of data 7777777777777777777777777777777777777777



FLD92it F<DProm't F5DRefres, FNDRetrie1e F;0D!(rsor F;;D$oggle
F;=DRe'eat find F;>DRe'eat c,ange F2<DMore .e3s
%!* !OP:RIAH$ IBM !ORP. ;N?;H 2002.
*)))0R ,*)) )uration-
The ADDD#R operation adds the duration speci5ed in factor 2 to a date or time and
places the resultin$ Date. Time or Timestamp in the result 5eld.
'actor , is optional and may contain a Date, Time or Timestamp 5eld, sub5eld,
array ,array element, literal or constant. If factor, contains a 5eld name, array or
array element then its data type must be the same data type as the 5eld speci5ed in
the result 5eld. If factor , is not speci5ed the duration is added to the 5eld speci5ed
in the result 5eld.
'actor 2 is re9uired and contains t6o subfactors. The 5rst is duration and may be a
numeric 5eld, array element or constant 6ith :ero decimal positions. If the duration is
ne$ative then it is subtracted from the date. The second sub factor must be a valid
duration code indicatin$ the type of duration. The duration code must be consistent
6ith the result 5eld data type. Fou can add a year, month or day duration but not a
minute duration to a data 5eld.
The result 5eld must be a date, time or timestamp data type 5eld, array or array
element if the result 5eld is s time 5eld, the result 6ill al6ays be a valid Time. 'or
e/ample addin$ 87 minutes to 2="87"87 6ould $ive 2<"8E"87. *ince this time is not
valid, the compiler adBusts it to >>"8E"87. If factor , is blan), the duration is added to
the value in the result 5eld.
!ol(mns . . . F = >= 9dit PB0;C0;#IM:RPAL9
#9CDDK BIFN
FM$ H H8e3wordsGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
777777777777777 Beginning of data 7777777777777777777777777777777777777
000;.00 L$ #
000L.00 7
000<.00 ! 7C#5 MOE9 75$9 L$
0005.00 7
0005.0; c ldt ds'l3
0005.02 c addd(r LF7m ldt
000=.0; c ldt ds'l3
000=.02 c addd(r LF7d ldt
000=.0L c ldt ds'l3
000=.0< c addd(r LF73 ldt
000=.05 c ldt ds'l3
000?.00 ! 9E5L 7I"LR D M;M
777777777777777777 9nd of data 7777777777777777777777777777777777777777

FLD92it F<DProm't F5DRefres, FNDRetrie1e F;0D!(rsor F;;D$oggle
F;=DRe'eat find F;>DRe'eat c,ange F2<DMore .e3s
%!* !OP:RIAH$ IBM !ORP. ;N?;H 2002.
The output of above pro$ram is,
( Du)e*tar Technolo$ies Pvt. +td.
,=-2.
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction To RPG IV
Day 27
is'la3 Program Messages

Oob 0N0555IPB0;C0;#5LIBP59E000N started on 0<I0>I05 at ;0F;NF;0 in s(bs3stem B
#PL: 0>.0<.2005
#PL: 0>.0>.2005
#PL: ;0.0>.2005
#PL: ;0.0>.200?



Press 9nter to contin(e.



FLD92it F;2D!ancel
S0<)0R ,Subtract )uration-
The *#D#R operation has been provided to"
o *ubtract a duration to establish a ne6 Date, Time or Timestamp
o &alculate a duration.
The *#D#R operation can also be used to calculate duration bet6een"
o T6o dates
o A date and a timestamp
o T6o times
o A time and a timestamp
o T6o timestamps
'actor , is re9uired and must contain a Date, Time or Timestamp 5eld, sub5eld, array,
array element, constant or literal.
'actor 2 is re9uired and must also contain a Date, Time or Timestamp 5eld, array ,array
element, literal or constant. The duration code must be consistent 6ith one of the
follo6in$"
o 'actor , and factor 2
o Fears 3MF4, 0onths 3M04 and Days 3D4 if factor , and-or factor2 is a Date
o Timestamp, MKours ,.K4,M0inutes3M0H4 and M*econds,.*4 6hen factor,
and-or factor 2 is a Time or Timestamp.
The result of the calculation is a complete units@ any roundin$, 6hich is done, is
do6n6ards. The calculation of duration includes microseconds.
'or e/ample, if the actual duration is =E< days, and the result is re9uested in years, the
result 6ill be , complete year because there are ,.>8 years in =E< days. A duration of 87
minutes re9uested in hours 6ill result in > hours.
( Du)e*tar Technolo$ies Pvt. +td.
,<-2.
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
%utput of 5rst ldt
%utput of 5rst
Introduction To RPG IV
Day 27
!ol(mns . . . F = >= 9dit PB0;C0;#IM:RPAL9
#9CDDK BIFN
FM$ H H8e3wordsGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
777777777777777 Beginning of data 7777777777777777777777777777777777777
000;.00 L$ #
000L.00 7
000<.00 ! 7C#5 MOE9 75$9 L$
0005.00 7
0005.0; c ldt ds'l3
0005.02 c s(bd(r LF7m ldt
000=.0; c ldt ds'l3
000=.02 c s(bd(r LF7d ldt
000=.0L c ldt ds'l3
000=.0< c s(bd(r LF73 ldt
000=.05 c ldt ds'l3
000?.00 ! 9E5L 7I"LR D M;M
777777777777777777 9nd of data 7777777777777777777777777777777777777777

FLD92it F<DProm't F5DRefres, FNDRetrie1e F;0D!(rsor F;;D$oggle
F;=DRe'eat find F;>DRe'eat c,ange F2<DMore .e3s
%!* !OP:RIAH$ IBM !ORP. ;N?;H 2002.
The output of above pro$ram is,
is'la3 Program Messages

Oob 0N0555IPB0;C0;#5LIBP59E000N started on 0<I0>I05 at ;0F;NF;0 in s(bs3stem B
#PL: 0>.0<.2005
#PL: 0>.0;.2005
#PL: 0<.0;.2005
#PL: 0<.0;.2002



Press 9nter to contin(e.



FLD92it F;2D!ancel

1it of (re=uently ued e6tended O!code
Sr"no" RPGIII RPGIV
, R2DP2 R2ADP2
2 +%R#P +%%R#P
= #PDAT #PDAT2
< D2+2T D2+2T2
8 #H+&R #H+%&R
. *2+2& *2+2&T
7 NKII NK2HII
E &A*II &A*2II
7 D2'H D2'IH2
,> R2TRH R2T#RH
,, &K2RR &K2&RR
,2 2I&PT 2I&2PT
,= *2T%' *2T%''
,< %&&#R %&&#R
( Du)e*tar Technolo$ies Pvt. +td.
,8-2.
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
%utput of 5rst ldt
%utput of second
Introduction To RPG IV
Day 27
<uilt4 In (unction:
RPG IV supports many built!in functions to return 5le!operation results, simplify comple/
calculations, perform strin$ operations, and perform data!type conversions. I'
al6ays be$in 6ith a Q si$n. They are coded 6ithin free!form e/pressions. To pass
value to a built in function, enclose the values 6ithin parentheses immediately
follo6in$ the name of the I', separate multiple values 6ith colon 3@4 separators.
Q *<S ,*bolute Value of 26!reion-
QA* 3numeric e/pression4
QA* returns the absolute value of the numeric e/pression speci5ed as the parameter. If
the value of the numeric e/pression is non! ne$ative, the value is returned unchan$ed. If
the value is ne$ative, the value returned is the value of the e/pression but 6ith the
ne$ative si$n removed.
QA* may be used either in e/pressions or as parameters to )ey6ords. Nhen used 6ith
)ey6ords, the operand must be a numeric literal, a constant name representin$ a
numeric value, or a built!in function 6ith a numeric value )no6n at compile Vtime.
!ol(mns . . . F = >= 9dit PB0;C0;#IM:RPAL9
#9CDDK I;
777777777777777 Beginning of data 7777777777777777777777777777777777777
000;.00 f? # ?f in4%0;*
0002.00 i;0 # ;0i 0 in4%0;2L*
000L.00 '> # >' L in4%0;2L<.5=>*
000<.00 ! e1al f?DPabs%f?*
000<.0; 7 $,e 1al(e of Qf?Q is now ;.000000000000G9000
0005.00 ! e1al i;0DPabs%i;00L2;*
0005.0; 7 $,e 1al(e of Qi;0Q is now <<<.
000=.00 ! e1al '>DPabs%'>*
000=.0; 7 $,e 1al(e of Q'>Q is now ;2L<.5=>.
000>.00 ! e1al 7inlrD7on
777777777777777777 9nd of data 7777777777777777777777777777777777777777









%!* !OP:RIAH$ IBM !ORP. ;N?;H 2002.

>)2C ,Convert to Pac9ed )ecimal (ormat-
Q Dec 3numeric e/pression W"precision" decimal placesX4
QD2& converts the value of the numeric e/pression to decimal 3pac)ed4 format 6ith
precision di$its and decimal pYlaces decimal positions.
> )ec'
QD2&K 3numeric e/pression" precision" decimal places4
QD2&K is same as the QDec built!in function, e/cept half!adBust is applied to the value
of numeric e/pression 6hen convertin$ to the desired precision. Ho messa$e is issued if
half adBust cannot be performed.
( Du)e*tar Technolo$ies Pvt. +td.
,.-2.
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction To RPG IV
Day 27
!ol(mns . . . F = >= 9dit PB0;C0;#IM:RPAL9
#9CDDK I2
777777777777777 Beginning of data 7777777777777777777777777777777777777
000;.00 '> # >' L in4%;2L<.5=>*
0002.00 sN # Ns 5 in4%>L.>L<<2*
000L.00 f? # ?f in4%;2L.<5=>?N*
000L.0; res; # ;5' 5
000L.02 res2 # ;5' 5
000L.0L resL # ;5' 5
000<.00 ! e1al res;DPdec%'>*G0.0;;
000<.0; 7 $,e 1al(e of Qres;Q is now ;2L<.5>?00
0005.00 ! e1al res2DPdec%sNF5F0*
0005.0; 7 $,e 1al(e of Qres2Q is now >L.00000
000=.00 ! e1al resLDPdec,%f?F5F2*
000=.0; 7 $,e 1al(e of QresLQ is now >L.00000
000>.00 ! e1al 7inlrD7on
777777777777777777 9nd of data 7777777777777777777777777777777777777777






%!* !OP:RIAH$ IBM !ORP. ;N?;H 2002.

>)2CPOS ,Get %umber of decimal Poition4
QDecPost3numeric e/pression4
QD2&P%* returns the number of decimal positions in the numeric e/pression.

!ol(mns . . . F = >= 9dit PB0;C0;#IM:RPAL9
#9CDDK IL
777777777777777 Beginning of data 7777777777777777777777777777777777777
000;.00 P> # >P L I"6%?2L=.5=>*
0002.00 #N # NP 5 I"6%2L.>L<<2*
000L.00 R9#; # 5I 0
000<.00 R9#2 # 5I 0
0005.00 R9#L # 5I 0
000=.00 ! 9E5L R9#;DP9!PO#%P>*
000=.0; 7 $,e 1al(e of QR9#;Q is now L.
000>.00 ! 9E5L R9#2DP9!PO#%#N*
000>.0; 7 $,e 1al(e of QR9#2Q is now 5.
000?.00 ! 9E5L R9#LDP9!PO#%P>7#N*
000?.0; 7 $,e 1al(e of QR9#2Q is now ?.
000N.00 ! 9E5L 7I"LRD7O"
777777777777777777 9nd of data 7777777777777777777777777777777777777777







%!* !OP:RIAH$ IBM !ORP. ;N?;H 2002.

( Du)e*tar Technolo$ies Pvt. +td.
,7-2.
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction To RPG IV
Day 27
>2)ITC ,2dit Value 0ing an 2ditcode-
Q2DIT& 3numeric" edit code4
Q2DIT& Returns a character result representin$ the numeric value edited accordin$ to
the edit code.
Q2)ITC 26am!le:
!ol(mns . . . F = >= 9dit PB0;C0;#IM:RPAL9
#9CDDK I<
777777777777777 Beginning of data 7777777777777777777777777777777777777
000;.00 msg # ;005
0002.00 salar3 # NP 2 in4%;000*
0002.0; 7
0002.02 7 If t,e 1al(e of salar3 is ;000H t,en t,e 1al(e of salar3 7 ;2
0002.0L 7 is ;2000.00. $,e edited 1ersion of salar3 7 ;2 (sing t,e 5 edit
0002.0< 7 code wit, floating c(rrenc3 is M$;2H000.00M.
0002.05 7 $,e 1al(e of msg is M$,e ann(al salar3 is $;2H000.00M
0002.0= 7
000L.00 ! e1al msgDM$,e ann(al salar3 isM
000<.00 ! GPtrim%Peditc%salar3 7 ;2
0005.00 ! FM5MF7!CR#:M**
0005.0; 7
0005.02 7 In t,e ne2t e2am'leH t,e 1al(e of msg is M$,e an((al salar3 is
0005.0L 7 and;2H000.00M
0005.0< 7
000=.00 ! e1al msgDM$,e ann(al salar3 isM
000>.00 ! GPtrim%Peditc%salar3 7 ;2
000?.00 ! FM5MFMandM**
000?.0; 7
000?.02 7 In t,e ne2t e2am'leH t,e 1al(e of msg is M#alar3 is
000?.0L 7 $77777;2H000.00M
000?.0< 7
000N.00 ! e1al msgDM#alar3 is $M
00;0.00 ! GPtrim%Peditc%salar3 7 ;2
00;;.00 ! FMBMF 75#$FILL**
00;;.0; 7
00;;.02 7 In t,e ne2t e2am'leH t,e 1al(e of msg is M$,e date is
00;;.0L 7 ;I;<I;NNNM
00;2.00 ! e1al msgDM$,e date isM
00;L.00 ! GPtrim%Peditc%7dateFM:M**
00;<.00 ! e1al 7inlrD7on
777777777777777777 9nd of data 7777777777777777777777777777777777777777

%!* !OP:RIAH$ IBM !ORP. ;N?;H 2002.

>2)IT? ,2dit Value 0ing an 2dit ?ord-
Q2DITN 3numeric" edit6ord4
Q2DITN Returns a character result representin$ the numeric value edited accordin$ to
the edit 6ord.
( Du)e*tar Technolo$ies Pvt. +td.
,E-2.
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction To RPG IV
Day 27
!ol(mns . . . F = >= 9dit PB0;C0;#IM:RPAL9
#9CDDK I5
777777777777777 Beginning of data 7777777777777777777777777777777777777
000;.00 amo(nt # 505
0002.00 salar3 # NP 2 in4%2<5;.5L*
000L.00 editwd ! M$ H H 7ollarsand and!entsM
000L.0; 7
000L.02 7 If t,e 1al(e of salar3 is 2<5;.5LH t,en t,e edited 1ersion of
000L.0L 7 %#alar3 7 ;2* is M$7772NH<;?7ollars L= !entsM. $,e 1al(e of
000L.0< 7 amo(nt is M$,e ann(al salar3 is $7772NH<;?7ollars L= !entsM
000L.05 7
000<.00 ! e1al amo(ntDM$,e ann(al salar3 isM
0005.00 ! GPeditw%salar3 7 ;2Feditwd*
0005.0; ! amo(nt ds'l3
000=.00 ! e1al 7inlrD7on
000>.00 7 %In t,e constant MeditedMH %MbM stands for blan. s'aces**
777777777777777777 9nd of data 7777777777777777777777777777777777777777






%!* !OP:RIAH$ IBM !ORP. ;N?;H 2002.

>212+, Get %umber of 2lement-
Q2+203tableGname4
Q2+203arrayGname4
Q2+20 returns the number of elements in the speci5ed array or table.
Q2+20 2/ample"
!ol(mns . . . F = >= 9dit PB0;C0;#IM:RPAL9
#9CDDK I=
777777777777777 Beginning of data 7777777777777777777777777777777777777
000;.00 arrld # 20 IM%;0*
0002.00 table # ;0 IM%20*ctdata
000L.00 n(m # 5P 0
000L.0; 7
000L.02 7 li.eRarra3 will be defined wit, a dimension of ;0.
000L.0L 7 arra3Rdims will be defined wit, a 1al(e of ;0.
000L.0< 7
000<.00 li.eRarra3 # li.e%arrld*dim%Pelem%arrld**
0005.00 arra3Rdims ! const%Pelem%arrld**
0005.0; 7
0005.02 7 In t,e following e2am'les n(m will be e/(al to ;0H 20H and L0.
0005.0L 7
000=.00 ! e1al n(mDPelem%arrld*
000>.00 ! e1al n(mDPelem%table*
000?.00 ! e1al 7inlrD7on
777777777777777777 9nd of data 7777777777777777777777777777777777777777




%!* !OP:RIAH$ IBM !ORP. ;N?;H 2002.


( Du)e*tar Technolo$ies Pvt. +td.
,7-2.
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction To RPG IV
Day 27
>(1O*T ,Convert to (loating (ormat-
Q'+%AT 3numeric e/pression4
Q'+%AT converts the value of the numeric e/pression to Zoat format. This built! in
function may only be used in e/pressions.
!ol(mns . . . F = >= 9dit PB0;C0;#IM:RPAL9
#9CDDK I>
777777777777777 Beginning of data 7777777777777777777777777777777777777
000;.00 '; s ;5' 0 in4%;*
0002.00 '2 s 25';L in4%L*
000L.00 res; s ;5' 5
000<.00 res2 s ;5' 5
0005.00 resL s ;5' 5
000=.00 ! e1al res;D';I'2
000=.0; 7 $,e 1al(e of Mres;M will be 0.LLL00
000>.00 ! e1al res2DPfloat%';*I'2
000>.0; 7 $,e 1al(e of Mres2M will be 0.LLLLL
000?.00 ! e1al resLDPfloat%';I'2*
000?.0; 7 $,e 1al(e of MresLM will be 0.LLLLL
000N.00 ! e1al 7inlrD7on
777777777777777777 9nd of data 7777777777777777777777777777777777777777







%!* !OP:RIAH$ IBM !ORP. ;N?;H 2002.


>I%T ,convert to integer-
QIHT 3numeric e/pression4
QIHT converts the value of the numeric e/pression to inte$er. Any decimal di$its are
truncated. This built V in function may only be used in e/pressions. QIHT can be used to
truncate the decimal positions from a Zoat or decimal value allo6in$ it to be used as an
array inde/.
>I%T'
QIHTK 3numeric e/pression4
QIHTK I* same as QInt, e/cept half!adBust is applied to the value of the numeric
e/pression 6hen convertin$ to inte$er type.
( Du)e*tar Technolo$ies Pvt. +td.
2>-2.
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction To RPG IV
Day 27
!ol(mns . . . F = >= 9dit PB0;C0;#IM:RPAL9
#9CDDK I?
777777777777777 Beginning of data 7777777777777777777777777777777777777
000;.00 '= s 5' 0
0002.00 '> s >' L in4%;2L<.5=>*
000L.00 sN s Ns 5 in4%>L.>L<<2*
000<.00 f? s ?f in4%;2L.>?N*
0005.00 res; s ;5' 5
000=.00 res2 s ;5' 5
000>.00 resL s ;5' 5
000?.00 arra3 s ;a dim%200*
000N.00 a s ;a
00;0.00 ! e1al '=DPint%'>*
00;;.00 7 $,e 1al(e of Q'=Q is now ;2L<.
00;2.00 ! e1al res;DPint%'>*G0.0;;
00;2.0; 7 $,e 1al(e of Qres;Q is now ;2L<.0;;00
00;<.00 c e1al res2DPint%sN*
00;<.0; 7 $,e 1al(e of Qres2Q is now >L.00000.
00;=.00 ! e1al resLDPint%f?*
00;=.0; 7 $,e 1al(e of QresLQ is now ;2<.00000.
00;?.00 ! e1al aDarra3%Pint,%f?**
00;?.0; 7 PI"$ and PI"$H can be (sed as arra3 inde2es.
00;N.00 ! e1al 7inlrD7on
777777777777777777 9nd of data 7777777777777777777777777777777777777777







%!*
!OP:RIAH$ IBM !ORP. ;N?;H 2002.

>12% ,Get 1ength-
Q+2H3e/pression4
!ol(mns . . . F = >= 9dit
PB0;C0;#IM:RPAL9
#9CDDK IN
777777777777777 Beginning of data 7777777777777777777777777777777777777
000;.00 n(m; s >' 2
0002.00 n(m2 s 5s ;
000L.00 n(mL s 5i 0 in4%2*
000<.00 c,r; s ;0a in4%M$oronto M*
0005.00 c,r2 s ;0a in4%MM(nic, M*
000=.00 'tr s 7
000=.0; 7 "(meric e2'ressions F
000>.00 ! e1al n(m;DPlen%n(m;*
000N.00 ! e1al n(m;DPdec'os%n(m2*
00;;.00 ! e1al n(m;DPlen%n(m;7n(m2*
00;L.00 ! e1al n(m;DPdec'os%n(m;7n(m2*
00;L.0; 7 !,aracter e2'ressions F
00;5.00 ! e1al n(m;DPlen%c,r;*
00;>.00 ! e1al n(m;DPlen%c,r;Gc,r2*
00;N.00 ! e1al n(m;DPlen%Ptrim%c,r;**
002;.00 ! e1al n(m;DPlen%Ps(bst%c,r;F;Fn(mL*
0022.00 ! GMMGPtrim%c,r2**
002<.00 ! e1al 7inlrD7on
0025.00 7 Plen and Pdec'os can be (sef(l wit, ot,er b(ilt0in f(nctions F
002=.00 7 defloating 'oint data t3'es
%!* !OP:RIAH$ IBM !ORP. ;N?;H 2002.
( Du)e*tar Technolo$ies Pvt. +td.
2,-2.
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction To RPG IV
Day 27
Q+2H &an be used to $et the len$th of a variable e/pression or to set the current len$th
of a variable!len$th 5eld.
>SC*% ,Scan for Character-
Q *&AH 3search ar$ument " source strin$ W"startX4
!ol(mns . . . F = >= 9dit PB0;C0;#IM:RPAL9
#9CDDK I;0
777777777777777 Beginning of data 7777777777777777777777777777777777777
000;.00 so(rce s ;5a in4%Mr. oolittleM*
0002.00 'os s 5( 0
000L.00 ! e1al 'osDPscan%MooMFso(rce*
000<.00 ! 'os ds'l3
000<.0; 7 5fter t,e 9E5LH 'os D = beca(se MooM begins at 'osition = in
000<.02 7 Mr. oolittleM
0005.00 ! e1al 'osDPscan%MMFso(rceF2*
000=.00 ! 'os ds'l3
000=.0; 7 5fter t,e 9E5LH 'os D 5 beca(se t,e first MM fo(nd starting from
000=.02 7 'osition 2 is in 'osition 5.
000>.00 ! e1al 'osDPscan%MabcMFso(rce*
000?.00 ! 'os ds'l3
000?.0; 7 5fter t,e 9E5LH 'os D 0 beca(se MabcM is not fo(nd in
000?.02 7 Mr. oolittleM
000N.00 ! e1al 'osDPscan%MrMFso(rceF2*
00;0.00 ! 'os ds'l3
00;0.0; 7 5fter t,e 9E5LH 'os D 0 beca(se MrM is not fo(nd in
00;0.02 7 Mr. oolittleMH if t,e searc, starts at 'osition 2.
00;;.00 ! e1al 7inlrD7on
777777777777777777 9nd of data 7777777777777777777777777777777

%!* !OP:RIAH$ IBM !ORP. ;N?;H 2002
Q*can returns the 5rst position of the search ar$ument in the source strin$, or > if it 6as
not found. If the start position is speci5ed, the search be$ins at the startin$ position.
>SI@2 ,Get SiAe in <yte-
Q*IT2 3variable4
Q*IT2 3literal4
Q*IT2 3array4
Q*IT2 3table4
Q *IT2 Returns the number of bytes occupied by the constant or 5eld. The a$reement
may be a literal, a named constant, a data structure sub5eld, a 5eld an array or a table
name. It cannot, ho6ever, contain an e/pression.
!ol(mns . . . F = >= 9dit PB0;C0;#IM:RPAL9
#9CDDK I;;
777777777777777 Beginning of data 7777777777777777777777777777777777777
000;.00 arr; s ;0 dim%<*
0002.00 table; s 5 dim%20*
000L.00 field; s ;0
000<.00 field2 s Nb 0
0005.00 fieldL s 5' 2
000=.00 n(m s 5' 0
000>.00 cit3 s <0a in4%M"ort, :or.M*
000>.0; 7
000>.02 7 calc(lation
000?.00 ! e1al n(mDPsi4e%field;*
00;0.00 ! e1al n(mDPsi4e%MHHM*
00;2.00 ! e1al n(mDPsi4e%;2L.<*
( Du)e*tar Technolo$ies Pvt. +td.
22-2.
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction To RPG IV
Day 27
00;<.00 ! e1al n(mDPsi4e%00L.00*
00;=.00 ! e1al n(mDPsi4e%5RR;*
00;?.00 ! e1al n(mDPsi4e%5RR;F75LL*
0020.00 ! e1al n(mDPsi4e%$5BL9;*
0022.00 ! e1al n(mDPsi4e%$5BL9;F75LL*
002<.00 ! e1al n(mDPsi4e%field2*
002=.00 ! e1al n(mDPsi4e%fieldL*
002?.00 ! e1al n(mDPsi4e%!I$:*
00L0.00 c e1al 7inlrD7on
777777777777777777 9nd of data 7777777777777777777777777777777777777777










%!* !OP:RIAH$ IBM !ORP. ;N?;H 2002.
>S0<ST ,get Subtring-
Q*#*T3strin$ startW"len$thX4
Q*#*T returns a portion of ar$ument strin$. The start parameter represents the
startin$ position of the sub strin$. The len$th parameter represents the len$th of
substrin$. If it is not speci5ed, the len$th of the strin$ parameter less starts value plus
one.
!ol(mns . . . F = >= 9dit PB0;C0;#IM:RPAL9
#9CDDK I;2
777777777777777 Beginning of data 7777777777777777777777777777777777777
000;.00 M#A # 505
000;.0; 7
0002.00 ! 9E5L M#A D M$H9 E5LC9 OF P#CB#$ I# F M
000L.00 ! G P#CB#$%MH9LLO +ORLMF5G2*
000<.00 ! M#A #PL:
000<.0; 7
000<.02 ! 9E5L M#A D M$H9 E5LC9 OF P#CB#$ I# F M
000<.0L ! G P#CB#$%MH9LLO +ORLMF5G2F;00>*
000<.0< ! M#A #PL:
000<.05 7
000<.0= ! 9E5L M#A D M$H9 E5LC9 OF P#CB#$ I# F M
000<.0> ! G P#CB#$%M5B!MGM9FAHMF5FL*
000<.0? ! M#A #PL:
000<.0N 7
0005.00 ! 9E5L 7I"LRD7O"
777777777777777777 9nd of data 7777777777777777777777777777777777777777




%!* !OP:RIAH$ IBM !ORP. ;N?;H 2002.
>TRI+ ,trim <lan9 at 2dge-
QTRI0 3strin$4
( Du)e*tar Technolo$ies Pvt. +td.
2=-2.
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction To RPG IV
Day 27
QTRI0 Returns a strin$ 6ithout leadin$ and trailin$ spaces.
( Du)e*tar Technolo$ies Pvt. +td.
2<-2.
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction To RPG IV
Day 27
>TRI+1 ,trim 1eading <lan9-
QTRI0+ 3strin$4
QTRI0+ returns a strin$ 6ithout leadin$ spaces.
>TRI+R ,Trim Trailing <lan9-
Q TRI0R 3strin$4
QTRI0R returns a strin$ 6ithout trailin$ spaces.
!ol(mns . . . F = >= 9dit PB0;C0;#IM:RPAL9
#9CDDK I;L
777777777777777 Beginning of data 7777777777777777777777777777777777777
000;.00 LO!5$IO" # ;=5
000;.0; "5M9 # 205
0002.00 7
000L.00 7 LO!5$IO" +ILL H5E9 $H9 E5LC9 M$ORO"$OM O"$5RIOM.
000<.00 7
0005.00 ! 9E5L LO!5$IO" D P$RIM%M $ORO"$OH O"$5RIO M*
000=.00 7
000>.00 7 "5M9 +ILL H5E9 $H9 E5LC9 M!HRI# #MI$HM.
000?.00 7
000N.00 ! MOE9%P* M!HRI#M FIR#$"5M9 ;0
00;0.00 ! MOE9%P* M#MI$HM L5#$"5M9 ;0
00;;.00 ! 9E5L "5M9 DP$RIM%FIR#$"5M9*GM MGP$RIM%L5#$"5M9
00;;.0; 7
00;;.02 7 LO!5$IO" +ILL H5E9 $H9 E5LC9 M$ORO"$OM O"$5RIOM.
00;;.0L 7
00;;.0< ! 9E5L LO!5$IO" D P$RIML%M $ORO"$OH O"$5RIO
00;;.05 7
00;;.0= 7 LO!5$IO" +ILL H5E9 $H9 E5LC9 M$ORO"$OM O"$5RIOM.
00;;.0> 7
00;;.0? ! 9E5L LO!5$IO" D P$RIMR%M $ORO"$OH O"$5RIO M*
00;L.00 ! 9E5L 7I"LRD7O"
777777777777777777 9nd of data 7777777777777777777777777777777777777777





%!* !OP:RIAH$ IBM !ORP. ;N?;H 2002.
Converting RPG III !rogram to RPG IV !rogram
The process is carried out throu$h the use of RPG-<>> source member of a speci5ed
source physical 5le to the I+2 RPG-<>> format. &VTRPG*R& converts each source
member on a line!by! line basis. The conversion tool presumes that the RPG source code
is free of any compile error. efore you run the &VTRPG*R& command, there are fe6
thin$s you should understand and that you need to do"
The &VTRPG*R& command operates on the source physical 5le member.
&reate a source 5le to receive the I+2 RPG source members. The name I0
uses for I+2 RPG source members is DRPG+2*R&. The record len$th of the
DRPG+2*R& source 5le should be ,,2 bytes lon$. The basic format of an RPG
IV statement is"
o ,!,2" se9uence number and date.
( Du)e*tar Technolo$ies Pvt. +td.
28-2.
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Introduction To RPG IV
Day 27
o ,=!72" the e/ecutable portion of the RPG IV source code.
o 7=!,,2" the comments section of RPG IV source.
0a)e sure the source 5les containin$ your RPG-<>> source members contain
only RPG member types and no non!RPG [un!typed\ source member. As
&VTRPG*R& attempts to convert source member 6ith a blan) member type,
you could end up 6astin$ time.
o (RO+(I12" *peci5es the name of the source 5le that contains the RPG III
or RPG-<>> source code to be converted and the library 6here the source
5le is stored. This is a re9uired parameter@ there is no default 5le name.
o (RO++<R: *peci5es the name3s4 of the member to be converted. This is
a re9uired parameter@ there is no default name.
o TO(I12: *peci5es the name of the source 5le that contains converted
source member and the library 6here the converted source 5le is stored.
The converted source 5le must e/ist and should have a should have a
record len$th of ,,2 characters.
o TO+<R: *peci5es the name3s4 of the converted source member3s4 in the
converted source 5le. If the value speci5ed on the 'R%00R. Parameter is
M*11 or $enericM, then T%0R must be e9ual to M'R%00R.
o CVTRPT" *peci5es 6hether or not a conversation report is printed.
MFes" The conversion report is printed.
MHo" The conversion report is not printed.
Summary
The &VTRPG*R& tool is by no means the most e/citin$ part of I+2 RPG, but it is
probably the 5rst step that many 6ill ta)e 6hen they enter the ne6 6orld of I+2.
( Du)e*tar Technolo$ies Pvt. +td.
2.-2.
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.

You might also like