You are on page 1of 10

How do I declare a table or array in RPG IV?

Where can I buy copies of Bob Cozzi's boos on RPG IV and other topics?
How do I declare an array with a dyna!ic nu!ber of ele!ents?
How do I do concatenation in RPG IV lie I do in C"?
What #ood are the $%RI&' $%RI&" and $%RI&R built(in functions?
)re there any useful C runti!e functions that I can call fro! RPG IV? )nd what are they?
What's the difference between CH)I* and +,%""? Is there a perfor!ance ad-anta#e?
Can you clear up the confusion in the different releases of RPG IV and .+/011 and I",?
How does the C.*+% eyword wor with Procedure para!eters?
What is the current list of a-ailable built(in functions in Version 0' Release 0 of .+/011?
Why doesn't the new $CH)R built(in function wor with nu!eric -alues?
How do I use the new 2ile Built(in 2unctions?
What is the new , operation e3tender used for by the operation codes?
What is the R4*+5"+%& 6run +5" +tate!ent7 co!!and and how do I use it?
What's new in V0R0 and RPG IV?
How do I handle the ,rror and "R indicator on a C)""' when usin# C)""P?
How do I enable a 8worstation ti!e(out8 feature in RPG?
What is the ran#e of the 'I' 6inte#er7 data types in RPG IV?
What ser-ice pro#ra! do I need to bind to when usin# CGI RPG IV?
How do I debu# a re!ote 6i9e9 8batch87 :ob fro! an interacti-e :ob?
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
How do I declare a table or array in RPG IV?
%o declare an array or table' use the RPG IV definition specification9 %he 8; spec8 allows
you to code the array or table on a sin#le line9 %he eyword to use is ;I& 6di!ension79 %his
is where you specify the nu!ber of ele!ents in the table or array9 2or e3a!ple' to create an
array na!ed I%,&+ with <11 ele!ents' each =1 characters in len#th' the followin# ;efinition
spec can be used>
99999;*a!e???????????,4;+9999999"en#th?%;B92unctions????????
; Ite!s + =1) ;i!6<117
%o declare an array that is also used as a data structure subfield' you !ust declare the
array within the data structure9 4nlie RPGIII' RPG IV does not allow the array to be
declared' and then used as a data structure subfield9 %he followin# techni@ue illustrates
declarin# an array as a data structure subfield>
99999;*a!e???????????,4;+9999999"en#th?%;c92unctions????????
; &y;s ;+
; Cust*o AP 1
; &onthly+ls ==P < ;i!6=<7
Bou cannot code the sa!e array as a stand(alone field and as a data structure subfield in
the sa!e pro#ra! in RPG IV9
Bac to %op
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
Where can I buy copies of Bob Cozzi's boos on RPG IV and other topics?
)ll of Bob Cozzi's boos are a-ailable throu#h retail stores' or directly fro! &idran#e
Co!putin# !a#azine9 Ha-e you boo store order any title 6fro! &idran#e Co!putin#7 or call
+heila Gou#h at &idran#e Co!putin# at>
49+9 .rders> 6C117 0AA(DEED or 6E=F7 FG=(CE=D ,3t9 <1C
.utside the 4+>
In ,urope' dial> 00 617 =A=(G00(GCEG
In the )sia Pacific re#ion please call> E=(<(FFAE(G=DG
&idran#e Co!putin#
DED1 ,l Ca!ino Real' H<<D
Carlsbad' C) F<11C' 4+)
Voice> E=F(FG=(CE=D 2a3> E=F(FG=(FFGD
Clic here to lin to the &C web pa#e for orderin# and infor!ation>
1
Bou can also order directly fro! the web' by searchin# )!azon9co! for !y boos' and then
orderin# the!9 Clic here to #o to our pa#e that si!plifies searchin# )!azon9co! for Cozzi's
RPG boos9
Bac to %op
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
How do I declare an array with a dynamic number of elements?
In RPG IV' the new 6VG RA7 )"".C' R,)"".C and ;,)"".C operation codes can be used to
allocate !e!ory9 %his !eans that at run ti!e' you can #o out to the syste! and as it to
assi#n stora#e to the pro#ra! that was not allocated to the pro#ra! when it was e-oed9
%hese operation codes can be used to allocate !e!ory up to =E&B9 %he allocation can be
assi#ned to a pointer -ariable9 In RPG IV' pointers ha-e the data(type of asteris 6I79 )ll
that is needed is to allocate !e!ory to a pointer that is used with the B)+,; eyword of the
desired dyna!ic array9 %he e3a!ple that follows illustrates this techni@ue>
99999;*a!e???????????,4;+9999999"en#th?%;c92unctions??????????????????
; ;yno)rr + AP 1 ;i!6=11117 based6 p;yno)rr7
; n+ize + =1i 1
99999C+Rn1=99999999999999.pCode6e37,3tended(factor<??????????????????
C ,-al nsize J $size6;ino)rr7 I E0
99999C+Rn1=2actor=???????.pCode6e372actor<???????Result????????"en??;cHi"o,@
C )lloc n+ize p;yno)rr
II We now ha-e enou#h stora#e allocated for E0 ele!ents9
C ,-al nsize J $size6;ino)rr7 I A1
C Re)lloc n+ize p;yno)rr
II We ha-e chan#ed the allocation to enou#h stora#e for A1 ele!ents
CI 999 code to use the array #oes here999
C ;ealloc6*7 p;yno)rr
II We ha-e :ust returned the stora#e to the syste!9
%o increase or decrease the nu!ber of ele!ents in the dyna!ic array' use the R,)"".C
operation code9 +i!ply chan#e the nu!ber of bytes that need to be allocated' and call
R,)"".C with the new size in 2actor < and the ori#inal pointer -ariable in the Result field9
R,)"".C allocates new stora#e of the size specified' and copies the ori#inal data to that
new location9 %hen it frees 68deallocates87 the ori#inal stora#e9
I&P.R%)*%> )lways re!e!ber to ;,)"".C anythin# you )"".C9 %hat is always free up !e!ory that
you ha-e allocated otherwise !e!ory leas will be created9
If you are not on VG RA' you can still use dyna!ic !e!ory by callin# one of the syste! )PIs
or linin# into the 5C<", bindin# directory and callin# the C runti!e &)"".C and ;,)"".C
functions9
Bac to %op
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
How do I do concatenation in RPG IV, like I do in CL?
In the initial release of RPG IV' the plus si#n can be used to do si!ple concatenation9 When
the e3pression of any of the enhanced operation codes includes strin# e3pressions' then the
plus si#n is considered a concatenation operator9 In later release of RPG IV' the built(in
function $,;I%C can be used to allow nu!eric fields to participate in si!ple concatenation9
%he e3a!ple below illustrates the basic concatenation 6line 07 and the enhance!ent
introduced in .+/011 VG RA9
9999922I",*)&,??I2,)+2Rlen?"KeylnK2;,VIC,?92unctions????
111= 2C4+%&)+% I2 , K ;is
99999C+Rn1=99999999999999.pCode6e37,3tended(factor<???????????????????????????
99999CCRn1=2actor=???????.pCode6e372actor<???????Result????????"en??;cHi"o,@
111< II RPG IV on .+/011 VG R= and later999
111G C Cust*o Chain Cust&ast AG
1110 C ,-al &s# J Cust*a!e ? ' is ' ? C&L+tatus

111D II RPG IV on .+/011 VG R< and VG RA and later999
2
111E C ,-al &s# J 'Custo!er> ' ? $,ditC6Cust*o>'M'7 ?
111A C ' is ' ? C&L+tatus
In addition' the traditional RPG IV C)% operation code can be used for concatenation9
Bac to %op
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
What ood are the !"RI#, !"RI#L and !"RI#R built$in functions?
%he use of the %RI& functions is -ery li!ited' in that they support only the use of
character -ariables and data structures9 *u!eric fields' and zero(fill -alues are not
supported9 %hey do' howe-er' pro-ide so!e useful function for strin# handlin#9 2or e3a!ple'
in RPG IV' one line of code is all that's needed to left(ad:ust a -alue within a field9 2or
e3a!ple>
99999CCRn1=2actor=???????.pCode6e372actor<???????Result????????"en??;cHi"o,@
C ,32!tCust&aint
C ,-al Cust*a!eJ$%ri!"6Cust*a!e7
%ypically' the $%RI& function is the only one of the three that #et used9 %he other two'
howe-er' do ha-e their place9
$%RI& re!o-es trailin# and leadin# blans fro! a field' and returns the re!ainin# -alue' in
place' within the e3pression9 %he returned -alue is treated si!ilar to a constant -alue with
leadin# or trailin# blans9
$%RI&" re!o-es leadin# blans 6tri!(left7 fro! a field' and returns the -alue in place'
within the e3pression9
$%RI&R re!o-es trailin# blans 6tri!(ri#ht7 fro! a field' and returns the -alue in place'
within the e3pression9
%he table below illustrates the !echanics of the %RI& functions9
Built(In
2unction .ri#inal Value Returned Value
$%RI&6co!pna!e7
' %he IB& Corp9 '
'%he IB& Corp9'

$%RI&"6co!pna!e7
' %he IB& Corp9 '
'%he IB& Corp9 '

$%RI&R6co!pna!e7
' %he IB& Corp9 '
' %he IB& Corp9'

It would be wonderful if the %RI&3 functions also supported a second para!eter that
indicated the character to be tri!!ed9 It could default to blans' but would accept any
-alue9 %he internal &I instruction %RI&" actually does this already' but %RI&" and %RI&R do
not directly !ap to this &I instruction9 In addition' it would be e-en nicer if the second
para!eter supported !ultiple characters9 %hat is you would be able to specify
$%RI&R6Co!p*a!e > ' 9'7 and it would strip off blans and periods fro! the end of the
C.&P*)&, field9 (( ;rea!er999
Bac to %op
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
%re there any useful C Runtime %PIs that I can call from RPG IV?
%here are se-eral C runti!e )PIs a-ailable to the RPG IV de-eloper9 In .+/011 -ersion G'
release = the scope of these )PIs is li!ited9
%he C)""B operation code can be used to directly call the C runti!e )PIs' pro-ided they
don't re@uire 8pass by -alue8 para!eters9
In VG R< and later' para!eters can be passed by reference or by -alue9 In addition'
Prototypes are supporte for callin# procedures written in RPG IV or other lan#ua#es9
3
%he current list of C(related runti!e functions is lar#e9 %o support these functions in your
RPG IV pro#ra!s you need to co!pile the pro#ra! so that it runs in a nor!al acti-ation
#roup' and binds to the C runti!e library9 ) bindin# director is con-eniently pro-ided for
:ust this purpose9 2or e3a!ple>
CR%B*;RPG p#!6!yP#!7 ;2%)C%GRP6I*.7 B*;;IR65C<",7
By specifyin# ;2%)C%GRP6I*.7 and B*;;IR65C<",7' you open up your RPG IV pro#ra! to the world
of C runti!e functions9 %hese functions include hi#h(le-el !ath and ti!e for!attin#
routines9 +ee the RPG ;e-eloper *etwor *ews articles on inte#rated these functions in RPG
IV for !ore infor!ation9
)nother cool thin# about 5C<", is that the I", C/011 runti!e includes the full set of open
)+/011 &I instructions9 %hat is the )+/011 asse!bly lan#ua#e can be called directly fro! RPG
IV by prototypin# their C/011 functions9 2or e3a!ple' to call the Con-ert Characters to
He3adeci!al +y!bols &I instruction' you would call the 'c-thc' C runti!e function9 2or
e3a!ple>
%he followin# RPG IV code should co!pile on any -ersion of .+/011 that includes RPG IV9
99999;*a!e???????????,4;+9999999"en#th?%;c92unctions??????????????????
; szCharVal + <1) Inz6')BC;,2G'7
; szHe3Val ;+
; szHe3= "IK,6szCharVal7
; szHe3< "IK,6szCharVal7
; nChar"en + FB 1
99999C+Rn1=99999999999999.pCode6e37,3tended(factor<??????????????????
II if you want to a-oid con-ertin# trailin# blans' use this st!t9
C ' ' ChecR szCharVal nChar"en
II or if you want to con-ert trailin# blans' use this st!t9
C ,-al nChar"en J $size6szCharVal7 I <
99999C+Rn1=2actor=???????.pCode6e372actor<???????Result????????"en??;cHi"o,@
II %his con-erts '=<G' to '2=2<2G'
C C)""B 'c-thc'
C Par! szHe3Val
C Par! szCharVal
C Par! nChar"en
II %his con-erts '2=2<2G' to '=<G'
C C)""B 'c-tch'
C Par! szCharVal
C Par! szHe3Val
C Par! nChar"en
Nust a few thin#s to re!e!ber when usin# the C runti!e )PIs9
%he na!es are case(sensiti-e9 %hat is 'c-thc' !ust be specified in lower case or it will not
be found9
%hese functions are located in the .+/011 C(runti!e library and !ust be bound usin# the
5C<", bindin# directory9
Para!eters that re@uire pass(by(-alue restrict the )PI to bein# called with newer releases
of RPG IV' -ia procedure prototypes9
C functions that ha-e return -alues cannot be called by RPG IV under .+/011 -ersion G'
release =9
4ntil you !o-e to VG R< or' e-en better' VG RA' the nu!ber of interfaces that can be
accessed by RPG IV is li!ited9 In fact' the He3%oChar' Char%oHe3 functions are about all
that are useful9
4nder later releases of RPG IV' procedure prototypes allow access to all of the C runti!e
functions9 %his includes those nice little date and ti!e for!attin# functions' such as
ascti!e9
2or !ore details and e3a!ples of usin# procedure prototypes with the C runti!e library' see
the article on interfacin# RPG IV with the C/011 lan#ua#e runti!e library on the RPG
;e-eloper *etwor *ews pa#e9
Bac to %op
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
4
Can you clear u& the confusion in the different releases of RPG IV and '()*++ and IL,?
RPG IV is the ne3t #eneration of the RPG lan#ua#e9 RPG III is the ori#inal -ersion of )+/011
RPG/0119 %he na!e 8)+/011 RPG/0118 is that #i-en to the IB& co!piler paca#e for
distribution on the )+/0119 %his co!piler paca#e co!piles -arious -ersions of RPG'
includin# RPGII and at least two releases of RPGIII9
)s of .+/011 Version G release =' IB& chan#ed the na!e of this co!piler paca#e to 8)+/011
I", RPG/01189 %he reason for this na!e chan#e was to identify that fact that the co!pile now
includes a -ersion of RPG that tar#ets the Inte#rated "an#ua#e ,n-iron!ent 6I",7' that is
RPG IV9
I", was first shipped in .+/011 Version <' Release G9 Howe-er' only the C lan#ua#e co!piler
produced code that tar#eted this en-iron!ent9 2irst' a word about I",9
I", is the new' 8nati-e8 runti!e en-iron!ent for Pro#ra!s' on the )+/0119 4nder .+/011
Version < Release G' IB& introduced a new pro#ra! !odel9 %his basically !eans that new
features and interfaces beca!e a-ailable9 Howe-er' IB& did not :ust port so!e runti!e
en-iron!ent to the .+/011 operatin# syste!' it actually re(wrote code' and wrote new code
that' essentially' chan#ed the way .+/011 wors9 %his new code pro-ides support for a !i3ed
set of hi#h(le-el lan#ua#es9
Pre-iously' RPG and C" had their own little runti!e en-iron!ent' C.B." had it's own' C had
it's own' and so on9 4nder I",' all pro#ra!!in# lan#ua#es run in I",9 %he sa!e 8en-iron!ent8
is used for C.B."' C' RPG and C"9
Howe-er' to tae ad-anta#e of I",' new co!pilers needed to be created9 )s for RPG' rather
than con-ert the e3istin# RPGII and RPGIII co!pilers' IB&' who was desi#nin# a new -ersion
of RPG anyway' decided to tar#et I", with the new co!piler9 %his would si!ultaneously
pro-ide a new -ersion of RPG and an I", tar#eted co!piler9
*a!es )re I!portant
) #ood friend of !ine once said' 8na!es are i!portant8 in the pro#ra!!in# world9 If a field
is called 8Rhinoceros8' does it represent its use or purpose? .ay' so perhaps in
traditional RPG 8I#uana8 is a better choice for this e3a!ple9 6+horter na!e97
;urin# the de-elop!ent of RPG IV' two distinct issues arose9 2irst' the internal na!e for
RPG IV' was 8I", RPG89 %his was not a code na!e' but rather the na!e IB& used to refer to
the new co!piler9 )fter all' it was tar#etin# I",' why not refer to it as 8I", RPG8? +econd'
the re(architecture of RPG ca!e into @uestion9
4nfortunately' the internal na!e 8I", RPG8 be#an to be leaed out to the public9 +e-eral
!a#azine writers and IB&ers not in-ol-ed in the de-elop!ent of RPG IV continued to use the
ter! 8I", RPG8 when referrin# to RPG IV9 I suppose these people still refer to the )+/011 as
+il-er"ae or perhaps e-en .ly!pic9
%hen when IB& announced the co!piler paca#e or product na!e as 8)+/011 I", RPG/0118 it only
added to the confusion9 IB& dropped the ball when pro!otin# the RPG IV na!e9 %hey are' after
all' set up to !aret their products with their product na!es9 %he na!e of one pro#ra!!in#
lan#ua#e included in a product that contains nearly se-en full co!pilers isn't hi#h
priority9
RPG IV is the -ersion of RPG that tar#ets I",9 .+/011 VGR= co!patible RPG IV can also tar#et
what is now called 8the ori#inal pro#ra! !odel8 or si!ply .P&9 .P& is :ust a na!e that has
been #i-en to the ori#inal runti!e en-iron!ent of RPG and C" under .+/0119 %his is the
en-iron!ent in which RPGIII and C" run9 4nder I",' howe-er' the ori#inal nati-e en-iron!ent
is e!ulated' that is' I", isn't an en-iron!ent at all' it is nati-e .+/011' whereas' .P& is
now an en-iron!ent under I",9 +o!e -ery cle-er pro#ra!!in# and desi#n went into this' don't
you thin? *ot -ery !any other operatin# syste!s' if any' pro-ide this ind of continuity9
RPG IV $$ Release what?
RPG IV was first shipped with .+/011 Version G' Release =9 %his is now referred to as RPG IV
release =9 But don't worry about re!e!berin# releases of RPG IV9
4nder .+/011 Version G' Release E' IB& enhanced RPG with procedures' !any !ore built(in
functions' and se-eral new data types9 %his is referred to as RPG IV release <9
%hen' .+/011 Version G' Release < was announced9 It brou#ht the ori#inal release of RPG IV
6on the CI+C bo3es7 up to the sa!e le-el as RPG IV under VGRE9 )re you confused yet? &e tooO
5
4nder .+/011 Version G' Release A' IB& added a couple of enhance!ents' !ost notably they
increased the len#th of a field na!e to a nu!ber so lar#e not e-en !a#azine authors that
don't write real(world code could co!plain about it any!ore9 %hey also added one or two new
data types' roundin# out RPG IV so that it supports all )+/011 data types' e3cept -ariable
len#th fields9 %his -ersion of RPG IV is nown as RPG IV Release G9
%he followin# table identifies the current releases of RPG IV9 *ote that RPG IV releases do
not necessarily coincide with releases of the operatin# syste!9
RPG IV
Release .+/011 Version/Release CI+C or RI+C

= VG R= CI+C
< VG RE RI+C
< VG R< CI+C
G VG RA RI+C
0 V0 R< RI+C
0 VG RD 6speculation7
+ee note = CI+C
D V0 RG RI+C
D V0 R0 62ebruary =FFF7 RI+C
E V0 RD 6+u!!er <1117 RI+C
*.%, => It is speculated that IB& !ay ship a final 8clean up8 release of .+/011 for CI+C
that would included a lar#e le-el of co!patibility with .+/011 V0 RD9
%he release le-els of RPG IV are only i!portant if you want to eep trac of that ind of
thin#9 .ne disappointin# issue is that unless you stay on the !ost current release of
.+/011' you don't #et all the cool new features in RPG IV9 ,-en if you stay current' you
can't tar#et prior releases if you use any of the new features9 In fact' e-en if you use a
new feature that doesn't depend on an operatin# syste! enhance!ent' it can't be used for
bac releases9 %his is because of the way the %G%R"+ 6tar#et release7 feature has been
i!ple!ented9 Basically' if you're on V0 R< and you do a %G%R"+6VGR<&17 the co!piler calls
the actual co!piler for VG R<9 It doesn't ha-e a built(in synta3 checer that says 8%his
feature re@uires an .+/011 up#rade so don't allow it' or this one is oay so accept it98 It
iscallin# the sa!e 8binary8 co!piler code that is on any old VG R< syste!9
Which !eans' for e3a!ple' that if you want to tae ad-anta#e of the new co!piler directi-es'
but you often ha-e to tar#et a prior release' you can't use those directi-es9 2or
e3a!ple' /I2 ;,2I*,; does nothin# for the e3ecutable code that's #enerated' but is not
supported when %G%R"+6VGR<&17 is specified9 P6 Bu!!erO
+o now we now about RPG IV release le-els and how the ter! 8I", RPG8 #ot into our
-ocabulary9 +o let's clear up another ter!' the na!e of the RPG lan#ua#e9 %he bi# one is the
ter! 8RPG/01189 %here is not pro#ra!!in# lan#ua#e called 8RPG/01189 %he lan#ua#e !ost often
called 8RPG/0118 is RPGIII9 Howe-er' bac in the +yste!/GC days' the +yste!/GC RPG lan#ua#e
was called RPGIII9 When the )+/011 was announced' pro#ra!!ers wanted to #i-e the!sel-es an
ad-anta#e on their rQsu!Q9 +o they be#an callin# )+/011 RPGIII' 8RPG/01189 %hen to !ae
!atter worse' when RPG IV was announced' pro#ra!!ers thou#ht that the nu!ber 8IV8 in 8RPG
IV8 was less than the 80118 in 8RPG/01189 +o they decided to call RPG IV' 8I", RPG89 Well
let's set the record strai#ht9 %he table below lists the RPG lan#ua#e na!es' their incorrect
na!e' and the proper na!e9
Co!!only used Wron# *a!e 2or!al *a!e Proper 6correct7 *a!e
RPG/GE +yste!/GE(co!patible RPGII RPGII
RPG/GC +yste!/GC(co!patible RPGIII RPGIII
RPG/011 RPGIII RPGIII
I", RPG RPG IV RPG IV
Bac to %op
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
How does the C'-(" keyword work with Procedure &arameters?
If you are certain that the called procedure will *.% !odify a para!eter' the C.*+% eyword
can pro-ide se-eral benefits9
It auto!atically con-erts a field of a si!ilar data type' to the len#th and type re@uired by
the para!eter9
6
What this !eans' is say a para!eter is a =D position pac field' with D deci!als9 *or!ally'
you'd ha-e to specify a Pd6=D'D7 field for the para!eter9 Howe-er' if the para!eter is
read(only' you can specify C.*+% on the Prototype and Procedure Interface for the para!eter9
When you do this' the co!piler auto!atically con-erts the -alue 6say it's a literal of <A7
to the size and type re@uired by the para!eter9 %his wors really cool with ;)%, fields9 )
date for any for!at can be passed as a para!eter -alue when that para!eter -alue is C.*+%9
Perfor!ance is i!pro-ed because the co!piler can #enerate !ore opti!ized code for the C.*+%
para!eter9
C.*+% can be used on calls to procedures or pro#ra!s9 We use it all the ti!e when callin#
5C&;,RC fro! within RPG IV9 )ll three para!eters of the 5C&;,RC pro#ra! are C.*+% -alues9
%he e3a!ple code below can be used as the PR.%.%BP, to call 5C&;,RC fro! within RPG IV9 %o
call it usin# this prototype' specify so!ethin# lie> C)""P run6'addlible !y"ib' =07 in your
calculation specs9
99999;*a!e???????????,4;+9999999"en#th?%;c92unctions??????????????
; Run PR ,3tP#!6'5C&;,RC'7
; c!dstr G111) Const .ptions6IVar+ize7
; c!dlen =DP D Const
; c!d;bcs G) Const .ptions6I*.P)++7
*ote> if you're usin# Code+tudio or IB&'s Code/011 as your RPG IV editor under Windows' you
could si!ply hi#hli#ht the abo-e source code within your Internet Browser' and copy it to
the Windows clipboard9 %hen acti-ate Code+tudio 6or Code/0117 and use the Paste function to
insert the code directly into the editor9 Pretty cool' huh? S#T
Bac to %op
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
Why doesn't the $CH)R built(in function wor with nu!eric -alues?
4nder the initial release of .+/011 Version 0' Release <' the $CH)R built(in function was
introduced9 Howe-er' the function' as desi#ned' only con-erted ;)%, -alues to character
-alues9 %his pro-ed to be too restricti-e a use for this function9 In the ne3t release of
.+/011 6V0R07 IB& will add function to $CH)R allowin# it to con-ert all for!s of non(
character data to character9 In that release $CH)R will function with nu!eric -alues9
; )!ount AP < Inz6=<G90D7
C ,-al te3t J '%he a!ount is> ' ? $Char6 a!ount 7
%he %,R% field would contain the followin# after the ,V)" operation is perfor!ed>
'%he a!ount is> =<G90D'
4nlie $,;I%C' the $CH)R built(in function tri!s off leadin# blans9 Howe-er' $,;I%C
pro-ides !uch !ore editin# power than $CH)R9 4se $CH)R for basic nu!ber to character
con-ersion9
Bac to %op
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
How do I use the new .ile /uilt$in .unctions?
.+/011 Version 0' Release < RPG IV supports the eli!ination of the Resultin# Indicators9 In
their place' se-eral new built(in functions ha-e been introduced9 &ost of these new built(in
function pro-ide infor!ation about the result of 2ile operations si!ilar to the Result
indicators9 But instead of codin# Resultin# indicator G' for e3a!ple' to chec for the end(
of(file condition' you si!ply chec the -alue of the $,.2 built(in function9
%he built(in functions that replace the Resultin# Indicators include>
$2.4*;' $,.2' $,54)"9 In addition' there are $.P,*' $+%)%4+' and $,RR.R9 &ysteriously
!issin# is $".CK to chec for a record loc condition9
$2.4*; returns an I.* or I.22 condition if the pre-ious 2ile operation returns a record(
found condition9 %his is particularly useful on the CH)I* operation9 Realize' howe-er' that
when CH)I* sets on Resultin# indicator =' a not(found condition is si#naled9 Whereas'
without codin# Resultin# Indicator =' the $2.4*; built(in function returns the found
condition9
$,.2 can be used to chec for end(of file' be#innin# of file' or subfile full conditions9 )
R,); and R,);, return $,.2JI.* if the end of file is reached9 R,);P and R,);P, return
7
$,.2JI.* if the be#innin# of file is reached9 %he WRI%, operation returns $,.2JI.* if the
WRI%, operation to a subfile detail record returned a subfile(full condition9
$,54)" is used by the +,%"" operation to indicate that it detected a record in the file with
a ey e@ual to that of the -alue specified in 2actor =9 +ince +,%"" does not read the
record' does not loc the record' and does not copy the data into the input buffer' +,%"" is
!uch faster and less of an i!pact on the perfor!ance of the application than other
operations' such as CH)I*9 4se CH)I* when you need to retrie-e the record' use +,%"" and
$,54)" when you need to only chec for the e3istence of a record9
$.P,* is used to chec to see if a file has already been opened9 %he built(in function
returns I.* if the file is opened' otherwise it returns I.229
Bac to %op
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
What is the new , o&eration e0tender used for?
%he new 6,7 operation e3tender is used to cause the $,RR.R and $+%)%4+ built(in functions to
be initialized after an operation is perfor!ed9 %hat is' these built(in functions and the ,
operation e3tender are used in place of Resultin# Indicator < on all operation codes that
currently support Resultin# Indicator < as an error condition9
2or e3a!ple' to chec to see if a record is loced' you would code the followin#>
99999C+Rn1=2actor=???????.pCode6e372actor<???????Result????????"en??;cHi"o,@
C Cust*. Chain6,7 Cust&ast
C if $,RR.R J I.*
C +elect
C When $+%)%4+ J =<<=
C e3sr 4pdate*oRead
C When $+%)%4+ J =<=C
C e3sr Recd"oced
C end+"
C ,"+,
C if $2.4*;6 Cust&ast 7
C e3sr whate-er999
C endif
C endif
%he concept is to first chec $,RR.R for a #eneralized error condition' and then chec
$+%)%4+ for the specific error9 *ote that no resultin# indicators are used in the pre-ious
e3a!ple9 %he nor!al not(found condition is checed usin# the $2.4*; built(in function rather
than testin# Resultin# Indicator =9
Bac to %op
What1s new in V*R* and RPG IV?
%here are a few si#nificant enhance!ents in RPG IV in .+/011 Version 0' Release 09
%he $CH)R built(in function has be fi3ed9 It now functions lie it was supposed to in the
first place9 Bou can wrap a nu!eric -alue in $CH)R and a nicely edited character for! of the
nu!ber is returned9 %he edited for! includes the deci!al' tri!!ed off leadin# blans' and a
ne#ati-e si#n9
%he 2.R loop pro-ides a free(for!at -ersion of the ;. operation code9 With the 2.R
operation' you can be#in a loop operation and continue iteratin# throu#h the loop until a
-ariable e@uals a li!it -alue9 %he synta3 for the 2.R operation is enhanced with the %.' BB
and ;.W*%. eywords9 %he %. operation indicators the upper li!it for the loopin#' while the
BB eyword identifies the incre!ent -alue for the loop counter9 )lternati-ely' you can
specify the ;.W*%. eyword to loop bacwards fro! a lar#e -alue to a s!all -alue9
%he .P,*.P% eyword is added to the Header specification9 %his eyword can be used alon#
with its one and only eyword II*M.2" to cause o-erflow indicators to be set off when their
correspondin# printer file is closed and then re(opened durin# the pro#ra!9
In subroutines' the ",)V,+R operation can now be used to e3it a subroutine i!!ediately9
,ffecti-ely this is a 8#lorified #oto8 operation that branches to the ,*;+R state!ent of a
subroutine9
Bac to %op

How do I handle the error and LR indicator on a C%LL, when usin C%LLP?
%he short answer is' you can't9 %he lon# answer is' it depends on the .+/011 release le-el9
8
In releases prior to .+/011 V0 R<' there is no way to detect the "R situation9 ,rrors are
trapped either by specifyin# the P++R subroutine' or usin# an I", error/e-ent handlin# )PI9
In V0R< and later' its a little easier9 RPG IV supports the $,RR.R built(in function9 %his
built(in allows you to test the result of the C)""P operation9 4nfortunately' we ha-e to use
a silly 8,8 operation e3tender9 )pparently it is easier to code C)""P6,7 and then chec the
status of $,RR.R for a I.* or I.22 condition than it is to not use 6,7 and still chec
$,RR.R9 $,RR.R is only set when the , operation e3tender is used9 P6
)s for checin# if the called pro#ra! set on "R before returnin#' the use of C)""P does not
pro-ide this capability9
Bac to %op
How do I enable a 8worstation ti!e(out8 feature in RPG?
%here are fi-e thin#s re@uired to pro-ide a ti!e(out option on any interacti-e worstation
file9 %his capability allows an RPG pro#ra! to recei-e control before an end(user presses a
2unction ey or ,nter9 +o!e of the uses for this ind of function include>
Pro-idin# a !ar@uee for a schedule -ia a subfile
4pdate the ti!e displayed on the worstation at re#ular inter-als
Refresh the infor!ation' such as a news display' periodically
)s !entioned' there are fi-e thin#s re@uired to achie-e worstation ti!e(out9 %hose fi-e
thin#s are>
)dd the I*VI%, eyword to the Worstation display file ;;+9 %his is a file(le-el eyword9
4se the W)I%RC; para!eter of CR%;+P2 to set the desired ti!e(out period9
)dd the &)R;,V6I2I",7 eyword to the 2ile specification for the Worstation de-ice file9
Write the desired display file for!ats to the display usin# the nor!al !ethods9
4se the R,); operation code to read ;isplay 2ile na!e' not the Record for!at na!e9
Bou !ust a-oid usin# ,R2&% to the display file as this operation code does not support
worstation ti!e(out9
2&ar@uee C2 , W.RK+%* &)R;,V6I2I",7
2 +2I",6detail>rrn7

C Write Header
C Write 2ooter
C ;o =< rrn
C Write ;etail
C enddo
C Write +2"C%"2&%
C Read &ar@uee
Bac to %op
What Bindin# ;irectory ;o I need to bind to when usin# CGI RPG IV?
%he 5%CP library contains the ser-ice pro#ra! na!ed 5%&HCGI which includes access to all the
necessary ob:ects to accessin# any 5t!hI )PI9 +o set the B*;+RVPG& para!eter to 5%&HCGI in
5%CP9
If V0R< or earlier use 5%&HCGI ser-ice pro#ra!>
TT B*;+RVPG&65%CP/5%&HCGI7
If later than V0R< use>
TT B*;+RVPG&65H%%P+VR/5MHBCGI7
Bac to %op

9
How do I debu a remote 2i3e3 4batch45 6ob from an interacti7e 6ob?
%he ability to debu# another :ob has been a lon# standin# re@uire!ent for )+/011' now
i+eries pro#ra!!ers9 It isn't as difficult as it !ay see!9 Whether you need to debu# a batch
:ob' another interacti-e :ob' or an H%%P ser-er :ob 6browser/CGI pro#ra!7' the followin#
steps can #et you started9
+tartin# ;ebu# for a Re!ote Nob
;eter!ine the :ob na!e of nu!ber for the :ob you need to debu#9
4se WRK)C%N.B and note the Nob na!e' nu!ber and user profile I;9
If debu##in# a CGI pro#ra!' loo in the :oblo# of the :ob for CP2 !essa#e H%P<11=9
Run the +tart +er-ice Nob 6+%R+RVN.B7 co!!and specifyin# the :ob to be debu##ed
e9#9' +%R+RVN.B N.B61=<G0D/usrid/:obna!e7
Run +tart ;ebu# 6+%R;BG7 on the pro#ra! to be debu##ed
e9#9' +%R;BG PG&6libna!/p#!na!e7 4P;PR.;6IB,+ U I*.7
)t this point the pro#ra! in the re!ote :ob is under debu# control fro! your :ob
Bou can now set brea points 6if you're debu##in# an RPG IV pro#ra!' the source will ha-e
already been displayed79
Press 2=< fro! within the debu##er to return to C&; entry after settin# your brea points9
,-oe the pro#ra! in the re!ote :ob9 If you you're doin# a web browser session' hit the
+4B&I% button9
Bou interacti-e :ob will 8brea8 at the debu# brea points and you can debu# application
nor!ally9
,ndin# ;ebu# for a Re!ote Nob
,ndin# the debu# session should be done in the followin# se@uence9
2ro! your debu##in# session' run the ,nd ;ebu# 6,*;;BG7 co!!and
%hen run the 6,nd +er-ice Nob7 ,*;+RVN.B co!!and
Bour session is no lon#er controllin# the re!ote :ob9 %he re!ote :ob continues nor!ally9
+pecial Considerations when ;ebu##in# a Web Browser/CGI Pro#ra!
%o debu# a CGI pro#ra! that is e-oed fro! a Web Browser session runnin# fro! the standard
IB& H%%P Web +er-er' you need to do the followin# in addition to the abo-e9
Before +tartin# ;ebu# for a Web Browser/CGI +ession/Pro#ra!
,nd the H%%P +er-er usin# the followin# C" co!!and>
,*;%CP+VR IH%%P
W)R*I*GOOO (( Bou &4+% include IH%%P as the para!eter for ,*;%CP+VR otherwise all %CP/IP
ser-er :obs 6includin# telnet' ftp' s!tp' etc97 will be ended9 )nd this is a bad thin#9 IB&
sucs for !ain# I)"" the default for ,*;%CP+VR9
Restart the H%%P +er-er usin# the followin# C" co!!and>
+%R%CP+VR IH%%P H%%P+VR6;,2)4"% '(!inat = (!a3at ='7
%his restarts the H%%P ser-er with once instance of each :ob type 6one for CGI' one for
Na-a' etc97
4sin# WRK)C%N.B in the 5H%%P+VR subsyste! location the :obs runnin#9
%he :ob whose :oblo# contains the CP2 !essa#e H%P<11= is the one to be debu##ed9
)fter 2inishin# the ;ebu# +ession
,nd the H%%P ser-er usin# the followin# C" co!!and>
,*;%CP+VR IH%%P
Restart the H%%P ser-er usin# the followin# C" co!!and' unless your shop has another process
for startin# the H%%P ser-er>
+%R%CP+VR IH%%P
Bour syste! should be bac to nor!al9
10

You might also like