Вы находитесь на странице: 1из 67

An Introduction to ILE RPG: Part 1 Written by Charlie Massoglia Monday, 2 !

ebruary 1""#

$rie%: Early last year, I$M o%%icially announced the Integrated Language En&iron'ent (ILE) and *lans %or a ne+ generation o% A,-#.. languages/ E&en be%ore the ILE announce'ent, the RPG *rogra''ing co''unity +as a+are o% 'a0or changes being considered by I$M1s language de&elo*ers/ 2o+, a ne+ RPG language is close to co'*letion in I$M1s 3oronto laboratory +ith a *ro0ected deli&ery date during the third 4uarter o% 1""#/ ,tarting +ith this article, Midrange Co'*uting +ill *resent a co'*rehensi&e tutorial on the ne+ %eatures and %unctions that de%ine ILE RPG/ 3his 'onth1s article *ro&ides an o&er&ie+ o% the changes that *er&ade the ne+ language and an in5de*th loo6 at changes to Control and !ile descri*tion s*eci%ications/ ,ince the announce'ent o% the A,-#.., +e ha&e seen 'any signi%icant enhance'ents 'ade to RPG-#.., including the addition o% string5handling ca*abilities, a nu'ber o% ne+ structured o*eration codes, na'ed and he7adeci'al constants, read +ith no u*date, and 'ore/ 8es*ite these enhance'ents, RPG-#.. still has its critics/ ,i75character %ield na'es can result in cry*tic, di%%icult5to5understand abbre&iations/ Co'*le7 %or'ulas are di%%icult at best to code +ith a single o*eration *er Calculation s*eci%ication/ 9ther criticis's abound/ We are about to see enhance'ents +hich +ill 'a6e RPG-#.. see' as archaic and di%%icult to use as RPG II 'ay no+ see' to e7*erienced RPG-#.. *rogra''ers/ 3he *rogra''ing language that +ill deli&er these enhance'ents is Integrated Language En&iron'ent RPG (ILE RPG)/ ILE RPG should be announced as *art o% :;R1M. o% 9,-#../ <ou 'ay also hear ILE RPG re%erred to as RPG I: or 2PM (2e+ Progra' Model) RPG/ An i'*ortant bene%it o% the ne+ ILE *rogra' 'odel is the ability to bind *rogra's/ $inding *rogra's 'eans co'*iling *rogra's se*arately as none7ecutable 'odules +hich can be co'bined (bound together) to %or' a single, e7ecutable *rogra' ob0ect/ 3his %acilitates 'odularity and 'a6es it *ossible to create reusable co'*onents +ithout the *er%or'ance *enalty o% e7ternal *rogra' calls/ Calls to a *rogra' +hich is bound to the calling *rogra' can e7ecute +ith the s*eed o% a subroutine/ <ou no longer ha&e to code the sa'e subroutine in 'ulti*le *rogra's because you are a%raid o% the *er%or'ance hit associated +ith calling an e7ternal *rogra'/ Progra's +ritten in one language can call *rogra's +ritten in a di%%erent language +ith consistent o*eration and error handling/ A co''on source5le&el debugger +ill ser&ice all ILE languages/ Resources can be better controlled by *artitioning a 0ob into acti&ation grou*s and controlling %ile o*ens, %ile sharing and *rogra' loads +ithin an acti&ation grou*/ All o% these bene%its are *art o% the underlying ILE enhance'ents included in :2R;M./ 3hey +ill be a&ailable %or each ne+ ILE language as it is released/ ILE C-#.. is the %irst ILE language and +as introduced in :2R;M./ In addition to all o% the ILE bene%its, the RPG language itsel% has been substantially enhanced/ It +ill ta6e so'e ti'e and *erha*s so'e education to beco'e as co'%ortable +ith the ne+ ILE RPG as you no+ are +ith RPG II, RPG III or RPG-#../ =Why>= you as6/ 8o you use arrays> Guess +hat> Arrays and tables still e7ist, but there are no E7tension s*eci%ications (E5s*ecs) in ILE RPG? !or that 'atter, there are no longer any Line Counter

s*eci%ications (L5s*ecs) either/ 8o you thin6 you 6no+ the e7ternal %ile in*ut-out*ut o*eration codes> 3he 8ELE3, @P8A3, @2LCA and RE8PE o*eration codes no longer +or6/ 3hey1&e been changed to 8ELE3E, @P8A3E, @2L9CA and REA8PE/ And i% you1re a real long5ti'e e7*ert, re'e'ber the 8 s*eci%ication %ro' ,yste'-; RPG> Well, as +e1ll see, it doesn1t 'ean du'* in ILE RPG? E&en +ith these changes, there1s no need to +orry/ An RPG-#..5to5ILE RPG source con&ersion utility +ill be *ro&ided/ 3his utility should co'*letely auto'ate con&ersion unless you use -C9P< in RPG-#.. or Auto Re*ort/ (More about this in a later article/) All you really need is a little education/ 3his series o% articles *ro&ides so'e concentrated education about ILE RPG to 'a6e you co'%ortable +ith the ne+ language/ While the ILE RPG language de%inition is still sub0ect to change, any changes 'ade subse4uent to the +riting o% this article +ill *robably be 'inor/ At %irst glance, ILE RPG 'ight see' &ery di%%erent %ro' the current &ersion o% RPG-#../ Bo+e&er, &ery shortly you1ll understand +hy the changes +ere 'ade and learn ho+ the ne+ ILE RPG +ill 'a6e *rogra''ing easier and 'ore e%%icient/ General Changes o 9ne o% the 'ost %re4uent co'*laints about RPG is its si75character li'it %or %ield na'es/ ILE RPG no+ su**orts 1.5character %ile, %or'at, %ield, constant, data structure, 6ey list, subroutine, label and other sy'bolic na'es/ ILE RPG has generated so'e criticis' because it only su**orts 1.5character %ield na'es, +hile 9,-#.. su**orts longer %ield na'es/ In %act, 88, directly su**orts only 1.5character %ield na'es/ Longer %ield na'es are su**orted only through the ALIA, 6ey+ord/ !or e7a'*le, +hen de%ining 88, %or a %ile, the %ield na'e EMPC2@M 'ight ha&e an ALIA, o% EMPL9<EEC2@M$ER/ While ILE RPG +ill not su**ort alias %ield na'es, it +ill su**ort nati&e %ield na'es %or any %ile on the A,-#../ o 3he underscore (C) is no+ &alid in a sy'bolic na'e but cannot be the %irst character/ EMPC2AME is a &alid %ield na'e, but C2AME is not/ o Array subscri*ts are s*eci%ied using *arentheses instead o% a co''a/ ARR,D in RPG-#.. beco'es ARR(D) in ILE RPG/ o @**er5 and lo+ercase characters can be used any+here in an ILE RPG *rogra'/ 3he %ield na'es E'*2a'e and location are no+ &alid/ 3he o*eration codes CBAI2, Chain, and chain all *er%or' the sa'e %unction/ 3he use o% lo+ercase is o*tional/ 3he co'*iler +ill translate all source5+ith a %e+ e7ce*tions5%ro' lo+ercase characters (=a= to =E=) to u**ercase characters/ Co''ents, literals (+ith the e7ce*tion o% he7adeci'al literals) and co'*ile5ti'e array and table data +ill not be translated/ Also not translated are: the currency sy'bol, date and ti'e edit &alues on the Control s*eci%ication (B5s*ec), date and ti'e se*arator characters on In*ut s*eci%ications (I5s*ecs) (+e1ll address se*arator characters in a later article), and co'*arison characters on Record Identi%ication entries on I5s*ecs/ Be7adeci'al literals +ill be translated, so coding 71%.1 is the sa'e as coding D1!.1/ Co'*ile listings +ill sho+ u**er5 and lo+ercase as entered by the user/ 3he cross5re%erence listing +ill a**ear in u**ercase only/

o 3he 'a7i'u' length o% na'ed constants has increased %ro' 2FG to 1,.2# characters/ 2u'eric &ariables +ill no+ su**ort u* to ;. deci'al *ositions, u* %ro' "/ 3he %ield length o% character &ariables has also increased, in ans+er to criticis' o% RPG-#..1s 2FG5character li'itation/ Character &ariables and array ele'ents can no+ be u* to ;2,HGH characters in length/ o 9ther li'its ha&e also been in5creased/ 3he 'a7i'u' record length o% a *rogra'5described %ile has been increased %ro' ",""" bytes to "",""" bytes/ E7ternally described %iles can ha&e e&en larger record lengths/ 3he nu'ber o% ele'ents in a table or array has been increased %ro' ",""" to ;2,HGH/ 3he 'a7i'u' length o% a single5occurrence data structure has changed %ro' ",""" to ",""",""" +hile the 'a7i'u' nu'ber o% occurrences in a 'ulti*le5occurrence data structure has changed %ro' ",""" to ;2,HGH/ !inally, the length o% co'*ile5ti'e table and array data has increased %ro' . to 1.. characters/ o ,o'e li'its ha&e been &irtually eli'inated/ In RPG-#.., the nu'ber o% %iles is li'ited to F./ 3he 'a7i'u' nu'ber o% arrays is 2../ And, belie&e it or not, there is a 'a7i'u' *rogra' siEe/ In ILE RPG, there are no *ractical li'its %or these &alues/ 1 su''ariEes changes to li'its/ !igure 1 su''ariEes changes to li'its/ o ,ource state'ents +hich are blan6in *ositions G to . +ill be treated as co''ents/ An asteris6 (I) in *osition H +ill also %orce a state'ent to be a co''ent 0ust as it does in RPG-#../ In general, *ositions 1 to 1.. are treated as co''ents in source state'ents e7ce*t %or co'*ile5ti'e table and array data de%ined as longer than . characters/ o 3he de%ault source %ile na'e has changed %ro' JRPG,RC to JRPGLE,RC and the record length has e7*anded %ro' "2 to 112 bytes/ 3he e7isting si75character date and ,E@ se4uence5nu'ber %ields re'ain unchanged/ 3he increase o% the source state'ent length %ro' . to 1.. characters +ill acco''odate the longer %ile and %ield na'es as +ell as the co''ents in *ositions 1 to 1../ Ba&ing re&ie+ed general changes +hich a%%ect all s*eci%ications in ILE RPG, +e no+ can ta6e a loo6 at the details/ In the balance o% this article, +e +ill address the B5s*ecs and !ile descri*tion s*eci%ications (!5s*ecs)/ 3he ne7t article +ill address the ne+ 8ata s*eci%ication (85s*ec) and built5 in %unctions/ !uture articles +ill round u* our re&ie+ +ith In*ut, Calculation, and 9ut*ut s*eci%ications (I5s*ecs, C5s*ecs and 95s*ecs) together +ith e7*ressions, ne+ o*eration codes and date 'ani*ulation/ Control ,*eci%ications (B5s*ecs) A 4uic6 loo6 at an B5s*ec (2) introduces ILE RPG 6ey+ord notation +hich you1ll see re*eatedly as +e co&er each s*eci%ication ty*e/ 3he 6ey+ord notation used in ILE RPG is &ery si'ilar to the 6ey+ord notation %ound in CL/ A 4uic6 loo6 at an B5s*ec (!igure 2) introduces ILE RPG 6ey+ord notation +hich you1ll see re*eatedly as +e co&er each s*eci%ication ty*e/ 3he 6ey+ord notation used in ILE RPG is &ery si'ilar to the 6ey+ord notation %ound in CL/ !or e7a'*le, instead o% s*eci%ying a 8 in *osition 1F o% the B5s*ec, the 6ey+ord 8E$@G is no+ used to enable 8E$@G and 8@MP o*erations/ 3he use o% 8E$@G or 8E$@G(I<E,) enables

8E$@G and 8@MP o*erations/ 2ot s*eci%ying the 8E$@G 6ey+ord at all or s*eci%ying 8E$@G(I29) disables 8E$@G and 8@MP o*erations/ 3he currency sy'bol in *osition 1 is no+ s*eci%ied using the C@R,<M 6ey+ord +ith a single character enclosed in 4uotes/ I% C@R,<M is not s*eci%ied, the currency sy'bol de%aults to 1K1/ 3he date %or'at and date edit in *ositions 1" and 2. are re*laced +ith the 8A3E8I3 6ey+ord to s*eci%y the order o% 'onth, day and year o% @8A3E and I8A3E as +ell as the se*arator character %or the < edit5code/ IM8<, I8M< and I<M8 %or'ats can be s*eci%ied/ An o*tional se*arator character 'ay be s*eci%ied %or I8M<, I<M8 and IM8< %or'at dates/ 3he se*arator character is added to the date %or'at/ !or e7a'*le, s*eci%ying 8A3E8I3(IM8</) causes dates to a**ear as MM/88/<< +hen the < edit5 code is used/ 3he 8ECE8I3 6ey+ord re*laces the deci'al notation in *osition 21/ Alternate collating se4uence is no+ s*eci%ied +ith the AL3,EJ 6ey+ord instead o% an A in *osition 2G/ 3he !9RM,ALIG2 *ara'eter re*laces the 1 in *osition #1 to re4uest %irst5*age %or's align'ent/ !9RM,ALIG2 and !9RM,ALIG2(I<E,) enable %irst5*age %or's align'ent/ 2ot s*eci%ying the !9RM,ALIG2 6ey+ord, or s*eci%ying !9RM,ALIG2(I29), disables %irst5*age %or's align'ent/ A %ile translation table is indicated using the !3RA2, 6ey+ord instead o% the 1!1 in *osition #;/ 3he trans*arency (gra*hic) chec6 in *osition FH is no longer re4uired/ 3he de%ault *rogra' na'e is no+ s*eci%ied using the 8!32AME 6ey+ord instead o% using *ositions HF to ./ I% 8!32AME is not s*eci%ied or i% the s*eci%ied na'e is in&alid, RPG9$L +ill be used as the de%ault *rogra' na'e/ At co'*ile ti'e, a *rogra' na'e is nor'ally s*eci%ied as the sa'e na'e as the source 'e'ber, so 8!32AME does not need to be s*eci%ied in 'ost cases/ 3he 8A3!M3 6ey+ord is used to indicate the %or'at and se*arator %or date literals +hich are re4uired to su**ort the ne+ date and ti'esta'* data ty*es/ (8ate, ti'e and ti'esta'* data ty*es and o*erations +ill be described in a later article/) IM8<, I8M< and I<M8 su**ort the traditional, eight5character MM-88-<<, 88-MM-<< and <<-MM-88 date %or'ats/ A nu'ber o% other %or'ats are also su**orted/ 3he 3IM!M3 6ey+ord is used to indicate the %or'at and se*arator %or ti'e literals +hich are used to su**ort the ne+ ti'e and ti'esta'* data ty*es/ ; su''ariEes the changes in the B5s*ec/ 3he 3IM!M3 6ey+ord is used to indicate the %or'at and se*arator %or ti'e literals +hich are used to su**ort the ne+ ti'e and ti'esta'* data ty*es/ !igure ; su''ariEes the changes in the B5s*ec/ What1s in the %uture %or B5s*ecs> It is easy to see that the ne+ 6ey+ord notation has eli'inated any %or'at or length restrictions since 'ulti*le lines o% s*eci%ications can be used/ What about co'*ile o*tions> Aren1t they s*eci%ied in 6ey+ord notation on the co'*ile co''ands> Wouldn1t it be nice to include co'*ile o*tions in the source and ne&er again ha&e to *ro'*t and

change *ara'eters on a co'*ile co''and> Perha*s +e1ll see this ca*ability in a later release o% ILE RPG/ !ile 8escri*tion ,*eci%ications (!5s*ecs) A si'*le !5s*ec sa'*le in # sho+s %urther use o% 6ey+ord notation in ILE RPG/ 3he %ile in%or'ation data structure 8,M$I8 is no+ de%ined as a *ara'eter o% the I2!8, 6ey+ord: I2!8,(8,M$I8) A si'*le !5s*ec sa'*le in !igure # sho+s %urther use o% 6ey+ord notation in ILE RPG/ 3he %ile in%or'ation data structure 8,M$I8 is no+ de%ined as a *ara'eter o% the I2!8, 6ey+ord: I2!8,(8,M$I8) In a si'ilar 'anner, the in%or'ation subroutine ,@$RER is no+ s*eci%ied as a *ara'eter on the I2!,R 6ey+ord: I2!,R(,@$RER) 3he rena'e o% a record %or'at is a t+o5*art *ara'eter o% the RE2AME 6ey+ord: RE2AME(C9PM$1:C9LM$I81) 3he !5s*ec in ILE RPG has been 'odi%ied to acco''odate e7*anded lengths/ !or e7a'*le, the eight5character %ile na'e in *ositions H to 1# has been e7*anded to 1. characters in *ositions H to 1G/ 3he %our5character record length in *ositions 2# to 2H has been e7*anded to %i&e characters in *ositions 2; to 2H/ And the t+o5character 6ey length in *ositions 2" to ;. has been e7*anded to %i&e characters in *ositions 2" to ;;/ 3here are 'any other changes o% this ty*e/ F su''ariEes all the !5 s*ec changes/ 3he !5s*ec in ILE RPG has been 'odi%ied to acco''odate e7*anded lengths/ !or e7a'*le, the eight5character %ile na'e in *ositions H to 1# has been e7*anded to 1. characters in *ositions H to 1G/ 3he %our5character record length in *ositions 2# to 2H has been e7*anded to %i&e characters in *ositions 2; to 2H/ And the t+o5character 6ey length in *ositions 2" to ;. has been e7*anded to %i&e characters in *ositions 2" to ;;/ 3here are 'any other changes o% this ty*e/ !igure F su''ariEes all the !5s*ec changes/ 8ate, ti'e and ti'esta'* 6eys are no+ su**orted by s*eci%ying a 8, 3 or M/ 3hese 6ey %or'ats are indicated using the 8A3!M3 and 3IM!M3 6ey+ords in !5s*ecs +ith &alues si'ilar to those that can be s*eci%ied in the 8A3!M3 and 3IM!M3 6ey+ords in the B5s*ecs/ 3he @,R9P2 and ED3I28 6ey+ords sho+n in G are no+ used to condition the o*ening o% %iles/ 3he @C in *ositions H1 to H2 has been changed to the @,R9P2 6ey+ord %or the %ile C9LM$8,/ 3he @ e7ternal indicator %or C9LM$I8 has been changed to ED3I28(@ )/ <ou s*eci%y that a %ile allo+s additions +ith an A in *osition 2. rather than *osition GG/ 3his +ill *robably ta6e a +hile to get used to? 3he @,R9P2 and ED3I28 6ey+ords sho+n in !igure G are no+ used to condition the o*ening o% %iles/ 3he @C in *ositions H1 to H2 has been changed to the @,R9P2 6ey+ord %or the %ile C9LM$8,/ 3he @ e7ternal indicator %or C9LM$I8 has been changed to ED3I28(@ )/ <ou s*eci%y that a %ile allo+s additions +ith an A in *osition 2. rather than *osition GG/ 3his +ill *robably ta6e a +hile to get used to? Pre%i7 Aey+ord

9ne o% the 'ost signi%icant !5s*ec enhance'ents in&ol&es the use o% the sa'e record %or'at 'ulti*le ti'es in a *rogra'/ In ILE RPG, as in RPG-#.., i% you +ant to use a *hysical %ile and a logical %ile based on the *hysical %ile in the sa'e *rogra', you ha&e to rena'e the record %or'at o% one o% the %iles/ Bo+e&er, in RPG-#.., i% you +ant to read a record %ro' the *hysical %ile and then read a record %ro' the logical %ile +ithout altering the &alues o% the %ields %ro' the *hysical %ile, you ha&e to rena'e the %ields in the I5s*ecs/ 3his is no longer true in ILE RPG/ In our sa'*le in H, +e ha&e rena'ed the record %or'at C9PM$1 to C9LM$I81 %or the %ile C9LM$I8 in both RPG-#.. and ILE RPG/ $ut +e only changed the %ields M$8EL3 to M28EL3, M$I8 to M2I8, and M$2AME to M22AME in the RPG-#.. sa'*le/ Instead o% ha&ing to indi&idually list each %ield in the %ile, ILE RPG no+ su**orts the PRE!ID 6ey+ord to *er%or' a global %ield rena'e %unction/ $y s*eci%ying PRE!ID(M2C), +e ha&e i'*licitly rena'ed M$8EL3 to M2CM$8EL3, M$I8 to M2CM$I8 and M$2AME to M2CM$2AME/ In our sa'*le in !igure H, +e ha&e rena'ed the record %or'at C9PM$1 to C9LM$I81 %or the %ile C9LM$I8 in both RPG-#.. and ILE RPG/ $ut +e only changed the %ields M$8EL3 to M28EL3, M$I8 to M2I8, and M$2AME to M22AME in the RPG-#.. sa'*le/ Instead o% ha&ing to indi&idually list each %ield in the %ile, ILE RPG no+ su**orts the PRE!ID 6ey+ord to *er%or' a global %ield rena'e %unction/ $y s*eci%ying PRE!ID(M2C), +e ha&e i'*licitly rena'ed M$8EL3 to M2CM$8EL3, M$I8 to M2CM$I8 and M$2AME to M2CM$2AME/ !ields that are e7*licitly re5na'ed on I5s*ecs are not a%%ected by the PRE!ID 6ey+ord/ Also, i% the addition o% the *re%i7 to the %ield na'e results in a %ield na'e +hich e7ceeds 1. characters, a co'*ile error +ill occur/ 2ot only +ill the PRE!ID global rena'e ca*ability sa&e a tre'endous a'ount o% coding ti'e, it +ill also eli'inate the need to chec6 your *rogra's +hen you add a %ield to a %ile/ 3he added %ield +ill auto'atically be *re%i7ed (e/g/, M2C2EW!L8) +hen the *rogra' is reco'*iled/ 2ice 0ob, I$M? ,electing Record !or'ats 3he IG29RE 6ey+ord can be used to ignore a record %or'at %ro' an e7ternally de%ined %ile in both RPG-#.. and ILE RPG/ Each %or'at to be ignored 'ust be s*eci%ied in RPG-#../ 9ur sa'*le in sho+s %or'ats !9RMA32, !9RMA3; and !9RMA3# being ignored/ In addition to the IG29RE 6ey+ord in ILE RPG, an I2CL@8E 6ey+ord is also *ro&ided/ Any record %or'at not s*eci%ied using the I2CL@8E 6ey+ord is ignored/ I% you do not s*eci%y I2CL@8E or IG29RE, all records %or'ats +ill be included/ In our ILE RPG sa'*le, +e included !9RMA31 instead o% e7*licitly ignoring !9RMA32, !9RMA3; and !9RMA3#/ 3he IG29RE 6ey+ord can be used to ignore a record %or'at %ro' an e7ternally de%ined %ile in both RPG-#.. and ILE RPG/ Each %or'at to be ignored 'ust be s*eci%ied in RPG-#../ 9ur sa'*le in !igure sho+s %or'ats !9RMA32, !9RMA3; and !9RMA3# being ignored/ In addition to the IG29RE 6ey+ord in ILE RPG, an I2CL@8E 6ey+ord is also *ro&ided/ Any record %or'at not s*eci%ied using the I2CL@8E 6ey+ord is ignored/ I% you do not s*eci%y I2CL@8E or IG29RE, all records %or'ats +ill be included/ In our ILE RPG sa'*le, +e included !9RMA31 instead o% e7*licitly ignoring !9RMA32, !9RMA3; and !9RMA3#/ Co''it'ent Control

3he C9MI3 6ey+ord in RPG-#.. has been changed to C9MMI3 in ILE RPG/ Co''it'ent5 control *rocessing has been substantially enhanced through the ability to s*eci%y a single5character %ield as a *ara'eter on the C9MMI3 6ey+ord to condition the use o% co''it'ent control/ I% the %ield contains a 1, the %ile +ill be o*ened +ith co''it'ent control/ 9ther+ise, the %ile +ill be o*ened +ithout co''it'ent control/ 3he %ield &alue 'ust be set *rior to o*ening the %ile and can be *assed as an IE23R< *ara'eter/ I% the %ile is shared and is already o*en, this 6ey+ord has no e%%ect/ In the co''it'ent5control sa'*le in ", the %ile C9LM$I8 is al+ays o*ened under co''it'ent control in RPG-#../ 3he %ield CCC9LM$I8 is i'*licitly de%ined as a one5byte character %ield in the ILE RPG sa'*le/ I% *assed as an IE23R< *ara'eter +ith a &alue o% 111, the %ile C9LM$I8 is o*ened under co''it'ent control/ 9ther+ise, the %ile C9LM$I8 +ill be o*ened but co''it'ent control +ill not be used/ !or %iles o*ened under user control, the &alue o% CCC9LM$I8 could be set in the RPG *rogra' *rior to o*ening the %ile/ In the co''it'ent5control sa'*le in !igure ", the %ile C9LM$I8 is al+ays o*ened under co''it'ent control in RPG-#../ 3he %ield CCC9LM$I8 is i'*licitly de%ined as a one5byte character %ield in the ILE RPG sa'*le/ I% *assed as an IE23R< *ara'eter +ith a &alue o% 111, the %ile C9LM$I8 is o*ened under co''it'ent control/ 9ther+ise, the %ile C9LM$I8 +ill be o*ened but co''it'ent control +ill not be used/ !or %iles o*ened under user control, the &alue o% CCC9LM$I8 could be set in the RPG *rogra' *rior to o*ening the %ile/ A88R9@3 !iles ,ince E5s*ecs ha&e been eli'inated, coding A88R9@3 %iles in ILE RPG has changed/ 3he A88R9@3 %ile record length +hich +as coded in *ositions 2# to 2H is no+ coded in *ositions 2; to 2H/ 3he 6ey length has been 'o&ed %ro' *ositions 2" to ;. and e7*anded to %i&e characters in *ositions 2" to ;;/ 3he 3 re*resenting %ile organiEation in *osition ;2 has been 'o&ed to *osition ;F/ 3he 39!ILE 6ey+ord re*laces the E5s*ec/ In our sa'*le in 1., 39!ILE(9,GMA,3R) relates the %ile A88R9@3 to the %ile 9,GMA,3R/ ,ince E5s*ecs ha&e been eli'inated, coding A88R9@3 %iles in ILE RPG has changed/ 3he A88R9@3 %ile record length +hich +as coded in *ositions 2# to 2H is no+ coded in *ositions 2; to 2H/ 3he 6ey length has been 'o&ed %ro' *ositions 2" to ;. and e7*anded to %i&e characters in *ositions 2" to ;;/ 3he 3 re*resenting %ile organiEation in *osition ;2 has been 'o&ed to *osition ;F/ 3he 39!ILE 6ey+ord re*laces the E5s*ec/ In our sa'*le in !igure 1., 39!ILE(9,GMA,3R) relates the %ile A88R9@3 to the %ile 9,GMA,3R/ Line Counter !unctions 3he L5s*ec has also been eli'inated %ro' ILE RPG and its %unction has been 'o&ed to !5s*ecs using the !9RMLE2 and !9RM9!L 6ey+ords/ In the sa'*le in 11, the o&er%lo+ indicator is no+ coded using 9!LI28(9!)/ 3he %or's length o% F1 lines and o&er%lo+ line nu'ber o% ##, both o% +hich used to be coded in the L5s*ec, are coded in the !5s*ec using !9RMLE2(F1) and !9RM9!L(##)/ 3he L5s*ec has also been eli'inated %ro' ILE RPG and its %unction has been 'o&ed to !5s*ecs using the !9RMLE2 and !9RM9!L 6ey+ords/ In the sa'*le in !igure 11, the o&er%lo+ indicator is no+ coded using 9!LI28(9!)/ 3he %or's length o% F1 lines and o&er%lo+ line nu'ber o% ##, both o% +hich used to be coded in the L5s*ec, are coded in the !5s*ec using !9RMLE2(F1) and !9RM9!L(##)/

3he PR3C3L 6ey+ord is still used to de%ine a data structure to access the current line &alue and dyna'ically control a *rogra'5described *rinter %ile, but it has been e7*anded to acco''odate longer %ields/ Instead o% coding s6i* and s*ace be%ore and a%ter in 9ut*ut s*eci%ications (95s*ecs), these &alues can be set in a PR3C3L data structure/ ,*eci%ying PR3C3L(8,na'e:IC9MPA3) +ill retain the RPG-#.. de%initions/ 2ot s*eci%ying IC9MPA3 +ill change the %or'at o% PR3C3L as su''ariEed in 12/ 3he PR3C3L 6ey+ord is still used to de%ine a data structure to access the current line &alue and dyna'ically control a *rogra'5described *rinter %ile, but it has been e7*anded to acco''odate longer %ields/ Instead o% coding s6i* and s*ace be%ore and a%ter in 9ut*ut s*eci%ications (95s*ecs), these &alues can be set in a PR3C3L data structure/ ,*eci%ying PR3C3L(8,na'e:IC9MPA3) +ill retain the RPG-#.. de%initions/ 2ot s*eci%ying IC9MPA3 +ill change the %or'at o% PR3C3L as su''ariEed in !igure 12/ 9ther !ile Continuation Aey+ords 3he PGM2AME 6ey+ord s*eci%ies the na'e o% the *rogra' +hich gets control %or a ,PECIAL %ile/ 3he PLI,3 6ey+ord is still used to s*eci%y a *ara'eter list %or the *rogra' to handle a ,PECIAL %ile/ Changes ha&e also been 'ade to other %ile continuation 6ey+ords/ 3he I8 6ey+ord that de%ines a %ield to contain the na'e o% the *rogra' de&ice has been changed to 8E:I8/ ,a&ed indicators are no+ s*eci%ied using the ne+ ,A:EI28 6ey+ord instead o% the old I28 6ey+ord/ 3he ,A:8, (sa&e data structure) 6ey+ord has been changed to ,A:E8,/ 3he 2@M *ara'eter used to s*eci%y the 'a7i'u' nu'ber o% ac4uired de&ices %or a W9RA,32 %ile has been changed to MAD8E: and has been substantially enhanced/ Instead o% ha&ing to reco'*ile the *rogra' to increase the 'a7i'u' nu'ber o% ac4uired de&ices, MAD8E:(I!ILE) can be s*eci%ied to cause this &alue to be ta6en %ro' the dis*lay %ile at run ti'e/ In this case, ,A:E8, and ,A:EI28 s*ace allocation ta6e *lace at run ti'e/ MAD8E:(I92L<) is the de%ault +hich indicates a single de&ice %ile/ 3he actual nu'ber o% de&ices can no longer be s*eci%ied5 only I!ILE and I92L< are &alid/ ,o'e 6ey+ords re'ain the sa'e/ 3he PA,, 6ey+ord used to control *assing o% indicators to data 'anage'ent, the REC29 6ey+ord used to s*eci%y a relati&e record nu'ber %or %iles *rocessed by relati&e record nu'ber and the ,L2 6ey+ord used to s*eci%y a starting line nu'ber %or a W9RA,32 %ile are all unchanged/ What1s 2e7t> As you can see, nu'erous 'odi%ications +ere re4uired 0ust to handle the change %ro' si75character to 1.5character sy'bolic na'es/ Introducing 6ey+ord notation has not only %reed u* s*ace to acco''odate longer %ields in !5s*ecs, it has also 'ade the coding o% B5 and !5s*ecs 'uch easier %or us and 'uch easier %or I$M to enhance in the %uture/ As you1ll see in the re'aining articles in this series, the changes to acco''odate longer na'es are 'inor co'*ared to other changes in ILE RPG/ In our ne7t article, +e +ill tac6le I5s*ecs and the ne+ly reincarnated 85s*ecs/

Charlie Massoglia is *resident o% Massoglia 3echnical Consulting, Inc/ in 96e'os, Michigan/ Author o% a nu'ber o% 'idrange boo6s, Charlie is a %re4uent s*ea6er throughout the @nited ,tates, Canada, Euro*e and Australia/
An Introduction to ILE RPG: Part 1

Figure 1 Changes to Limits


Description of Changed Limit Field name a!le and arra" name File name File record format name RPG/400 Limit 6 6 # # ILE RPG Limit 10 10 10 10 %&'( 0&)( *( +( , and -

$alid characters in %&'( 0&)( *( + and , s"m!olic name .First character ma" not !e 0&) or -/ 0se of 1pper& and lo2ercase Length of character field and arra" element Length of named constants 71m!er of decimal positions 71m!er of files 71m!er of arra"s Program si8e Program&descri!ed file record length 71m!er of elements in ta!le or arra" Length of single&occ1rrence data str1ct1re 71m!er of occ1rrences in a m1ltiple&occ1rrence data str1ct1re Length of compile&time ta!le and arra" data 0ppercase 346 346 ) 40 300 $aries )())) )())) )())) )())) #0

0pper& and lo2ercase 53(666 1(034 50 7o practical limit 7o practical limit 7o practical limit ))())) 53(666 )()))())) 53(666 100

An Introduction to ILE RPG: Part 1

Figure

2 H-spec Sample Code

RPG/400 9:: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 10 <::::::::1::CD=I::::>::::::::::::::1:F:::::::::::::::::::::::::::::::Pgm&id < D *? D % 1 F ILE RPG 9:: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 10 <F1nctions;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Comm ents;;;;;;;;;;;; < DE@0G.9=E>/ C0R>=?.A*A/ D% EDI .9?D=/ DECEDI .A:A/ < %L >EB.9>RC/ FCR?>%LIG7.9=E>/ F R%7>.9>RC/ DF 7%?E.name/ < D% F? .9?D=// I?F? .9I>C/

An Introduction to ILE RPG: Part 1

Figure

C!anges to H-specs

RPG/400 Position 14 1# 1) 30 31 7e2 7e2 36 41 45 46 64&#0

>E0 Format %!!reDiation 1 C D = I > 1 F Pgm&id

EEplanation De!1g and D1mp C1rrenc" >"m!ol Date Format 0D% E Edit Decimal 7otation Date Literals Format ime Literals Format %lternate Collating >eG1ence First&page Forms %lignment File ranslation ransparenc" ChecH Defa1lt Program 7ame

ILE RPG Fe"2ord DE@0G C0R>=? D% EDI D% EDI DECEDI D% F? I?F? %L >EB FCR?>%LIG7 F R%7> 7o longer needed DF 7%?E

An Introduction to ILE RPG: Part 1

Figure

" I#F$S% I#FSR and RE#A&E

RPG/400 9:: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 10 FFilenameIPE%F::::RlenLF1%ICDFlocEDeDice;::::::FEEit;;Entr";%::::01::::::: FCCL?@ID 0F E F DI>F FI7FD> D>?@ID

F::::::::::::EEt&recfmt::::::::::::::::::Recno;FCptionEntr";::::::::::::::: F FI7F>R >0@RER F CCP?@1 FRE7%?ECCL?@ID1 ILE RPG 9:: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 10 FFilename;;IPE%>FRlen;LFlen;%IDeDice;:File contin1ation;;;;;;;;;;;;;;;;;;;;Comments;;;;;;;;;;;; FCCL?@ID 0F E F DI>F I7FD>.D>?@ID/ I7F>R.>0@RER/ F RE7%?E.CCP?@1ICCL?@ID1/

An Introduction to ILE RPG: Part 1

Figure

' C!anges to F-specs

RPG/400 Position 6&14 14 16 16 1# 1) 34&36 3# 3)&50 51 53 55&54 54&5# 5) 40&46 45&64 66 61&63 64&#0

ILE RPG Position 6&16 16 1# 1) 31 33 35&36 3# 3)&55 54 54 Fe"2ord Fe"2ord Fe"2ord 56&43 44&#0 30 Fe"2ord #1&100

>E0 Format %!!reDiation Filename I P E % F Rlen L F1 % I CD Floc E DeDice FEEit;;Entr"; % 01 Comments

EEplanation

7e2 Fe"2ord

File name File t"pe File designation End of file control ?atch field seG1ence File format Record length Limits processing Fe" field length Record address t"pe File organi8ation CDerflo2 indicator Fe" field starting location EEtension code

CFLI7D FE=LCC CFILE FCR?LE7 FCR?CFL

DeDice t"pe File contin1ation He"2ords File addition File condition EJ I7D 0>RCP7 Comments

An Introduction to ILE RPG: Part 1

Figure

( )SR*P# and E+,I#$

RPG/400 9:: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: #

:::;::: ) :::;::: 10 FFilenameIPE%F::::RlenLF1%ICDFlocEDeDice;::::::FEEit;;Entr";%::::01::::::: FCCL?@D> IF E F DI>F 0C FCCL?@ID 0F E F DI>F % 0# ILE RPG 9:: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 10 FFilename;;IPE%>FRlen;LFlen;%IDeDice;:File contin1ation;;;;;;;;;;;;;;;;;;;;Comments;;;;;;;;;;;; FCCL?@D> IF E F DI>F 0>RCP7 FCCL?@ID 0F % E F DI>F EJ I7D.0#/

An Introduction to ILE RPG: Part 1

Figure

- RE#A&E and PREFI+

RPG/400 9:: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 10 FFilenameIPE%F::::RlenLF1%ICDFlocEDeDice;::::::FEEit;;Entr";%::::01::::::: FCCP?@ 0F E F DI>F FCCL?@ID IF E F DI>F F::::::::::::EEt&recfmt::::::::::::::::::Recno;FCptionEntr";::::::::::::::: F CCP?@1 FRE7%?ECCL?@ID1 IFilename>G7CRiPos17CCPos37CCPos57CC::::::::::::::::::::::::::::::::::::::: ICCL?@ID I::::::::::::::EEt&field;::::::::::::::::::::::Field;L1?1::Pl?n'r:::::::::: I ?@DEL ?3DEL I ?@ID ?3ID I ?@7%?E ?37%?E ILE RPG 9:: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 10 FFilename;;IPE%>FRlen;LFlen;%IDeDice;:File contin1ation;;;;;;;;;;;;;;;;;;;;Comments;;;;;;;;;;;; FCCP?@ 0F E F DI>F FCCL?@ID IF E F DI>F RE7%?E.CCP?@1ICCL?@ID1/ PREFIJ.?3-/

An Introduction to ILE RPG: Part 1

Figure

. IG#*RE and I#CL)$E

RPG/400 9:: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 10 FFilenameIPE%F::::RlenLF1%ICDFlocEDeDice;::::::FEEit;;Entr";%::::01::::::: F%LL?@ID IF E F DI>F FIG7CREFCR?% 3

F F

FIG7CREFCR?% 5 FIG7CREFCR?% 4

ILE RPG 9:: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 10 FFilename;;IPE%>FRlen;LFlen;%IDeDice;:File contin1ation;;;;;;;;;;;;;;;;;;;;Comments;;;;;;;;;;;; F%LL?@ID IF E F DI>F I7CL0DE.FCR?% 1/

An Introduction to ILE RPG: Part 1

Figure

/ C*&&I,

RPG/400 9:: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 10 FFilenameIPE%F::::RlenLF1%ICDFlocEDeDice;::::::FEEit;;Entr";%::::01::::::: FCCL?@ID 0F E F DI>F FCC?I ILE RPG 9:: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 10 FFilename;;IPE%>FRlen;LFlen;%IDeDice;:File contin1ation;;;;;;;;;;;;;;;;;;;;Comments;;;;;;;;;;;; FCCL?@ID 0F % E F DI>F CC??I .C-CCL?@ID/

An Introduction to ILE RPG: Part 1

Figure

10 ,*FILE

RPG/400 9:: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 10 FFilenameIPE%F::::RlenLF1%ICDFlocEDeDice;::::::FEEit; ;Entr";%::::01:::::::FC>6? %> RIP E DI>F F%DDRC0 IR F 5 5 EDI>F E::::Fromfile ofile;;%rrnam7/r7/r!LenPD>%rrnamLenPD>Comments::::::::::::::: E %DDRC0 C>6?%> R ILE RPG 9:: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 10 FFilename;;IPE%>FRlen;LFlen;%IDeDice;:File contin1ation;;;;;;;;;;;;;;;;;;;;Comments;;;;;;;;;;;; FC>6?%> R IP E DI>F F%DDRC0 IR F 5 5 DI>F CFILE.C>6?%> R/

An Introduction to ILE RPG: Part 1

Figure

11 *FLI#$% F*R&LE# and F*R&*FL

RPG/400 9:: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 10 FFilenameIPE%F::::RlenLF1%ICDFlocEDeDice;::::::FEEit;;Entr";%::::01::::::: FI7$CICE>C F 153 CF LPRI7 ER LFilenameFlnFlClnCl:::::::::::::::::::::::::::::::::::::::::::::::::::::::: LI7$CICE> 41FL 44CL ILE RPG 9:: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 10 FFilename;;IPE%>FRlen;LFlen;%IDeDice;:File contin1ation;;;;;;;;;;;;;;;;;;;;Comments;;;;;;;;;;;; FI7$CICE> C F 153 PRI7 ER CFLI7D.CF/ FCR?LE7.41/ FCR?CFL.44/

An Introduction to ILE RPG: Part 1

Figure

12 C!anges to t!e PR,C,L $ata Structure

RPG/400 Description >pace !efore >pace after >Hip to line n1m!er !efore >Hip to line n1m!er after C1rrent line co1nt Positions 1&1 3&3 5&4 4&6 6&) Length 1 1 3 3 5 Positions 1&5 4&6 6&) 10&15 15&14

ILE RPG Length 5 5 5 5 5

An Introduction to ILE RPG: Part 2 3his is the second article in a 'ulti*art series on the ILE RPG language *lanned %or release later this year/ In each article, +e +ill co&er s*eci%ic changes to RPG coding and so'e o% the broader design issues resulting %ro' the ne+ %eatures and underlying ILE %acilities/ I2 3BI, AR3ICLE/// 3he ne+ 8e%inition ,*eci%ications/

C9MI2G 2ED3 M923B/// I5s*ecs, C5s*ecs and 95s*ecs/ $rie%: In the second install'ent o% our inde*th co&erage o% ILE RPG, +e1ll loo6 at the ne+ 8e%inition ,*eci%ications (85s*ecs)/ 85s*ecs consolidate de%initions %or arrays, data structures, na'ed constants, data areas and +or6 %ields that are not *art o% any %ile/ 3hey re*lace E5s*ecs and ta6e o&er so'e %unctions %ro' RPG-#.., I5s*ecs and C5s*ecs/ In addition, 85s*ecs *ro&ide ne+ +ays to de%ine so'e data constructs/ Last 'onth, +e introduced the ne+ ILE (Integrated Language En&iron'ent) RPG +hich should be announced as *art o% :;R1M./ We sa+ that a lot o% changes are in store %or the RPG *rogra''er/ !ield, %ile and other sy'bolic na'es can no+ be u* to 1. characters long/ @**er5 and lo+ercase %ield na'es are no+ su**orted/ Many li'its ha&e been increased and others &irtually eli'inated/ Control ,*eci%ications (B5s*ecs) ha&e been trans%or'ed %ro' %i7ed %or'at to 6ey+ord notation/ Line Counter ,*eci%ications (L5s*ecs) ha&e been eli'inated and their %unction 'o&ed to !ile 8escri*tion ,*eci%ications (!5s*ecs)/ And the !5s*ecs the'sel&es ha&e undergone 'a0or changes, not 0ust to acco''odate longer %ile na'es and larger record and 6ey lengths, but also due to the use o% 6ey+ord notation %or %ile continuation 6ey+ords and other %ile attributes/ We1re about to see e&en 'ore radical changes/ E7tension ,*eci%ications (E5 s*ecs) ha&e been eli'inated entirely/ Array and table de%initions ha&e been 'o&ed to the ne+ 8e%inition ,*eci%ications (85s*ecs)/ 2a'ed constant and data structure de%initions ha&e been 'o&ed %ro' In*ut ,*eci%ications (I5s*ecs) to the 85s*ecs/ 8e%initions %or LIAE %ields and data areas are also su**orted in 85s*ecs/ 1 illustrates the o&erall design o% a 85s*ec and +here each entry is coded/ We1re about to see e&en 'ore radical changes/ E7tension ,*eci%ications (E5 s*ecs) ha&e been eli'inated entirely/ Array and table de%initions ha&e been 'o&ed to the ne+ 8e%inition ,*eci%ications (85s*ecs)/ 2a'ed constant and data structure de%initions ha&e been 'o&ed %ro' In*ut ,*eci%ications (I5s*ecs) to the 85s*ecs/ 8e%initions %or LIAE %ields and data areas are also su**orted in 85s*ecs/ !igure 1 illustrates the o&erall design o% a 85s*ec and +here each entry is coded/ Let1s ta6e a loo6 at 85s*ecs and see ho+ they can i'*ro&e your *roducti&ity/ 8e%inition ,*eci%ications (85s*ecs) 3he 85s*ecs are designed to consolidate all data de%initions in one section o% your *rogra'/ Although you can still de%ine %ields in C5s*ecs, your code +ill be easier to 'aintain i% you de%ine all your +or6 %ields and literals in 85 s*ecs/ <ou 'ay hear so'e *eo*le re%er to 85s*ecs as 8ata ,*eci%ications/ While 85s*ecs do de%ine data, the *ro*er ter'inology is 8e%inition ,*eci%ic5ation so that1s +hat +e1ll try to re'e'ber to use/ In the %ollo+ing sections, +e1ll begin by loo6ing at si'*le data constructs such as na'ed constants and +or6 %ields/ 3hen, +e1ll loo6 at 'ore co'*le7 e7a'*les such as data structures and arrays/ $oth an RPG-#.. and an ILE RPG solution are sho+n +hene&er *ossible/ Bo+e&er, the e7*lanation o% each e7a'*le concentrates on the ILE RPG i'*le'entation/ 2a'ed Constants

In RPG-#.., na'ed constants can a**ear any+here in I5s*ecs, e&en +ithin a data structure de%inition/ 3his is not true in ILE RPG/ 2a'ed constants cannot a**ear +ithin a data structure de%inition/ I% the RPG-#..5to5ILE RPG source5 con&ersion utility %inds na'ed constants e'bedded in a data structure, it 'o&es the na'ed constants outside o% the data structure as *art o% the source5 con&ersion *rocess/ 2 sho+s the de%inition o% se&eral na'ed constants: the character constants CMP2< and LWR, the nu'eric constant 3WE23<, and the he7adeci'al constant 8@P/ 9nly a %e+ entries are re4uired: !igure 2 sho+s the de%inition o% se&eral na'ed constants: the character constants CMP2< and LWR, the nu'eric constant 3WE23<, and the he7adeci'al constant 8@P/ 9nly a %e+ entries are re4uired: o 3he C in *osition 2# de%ines a na'ed constant/ o 3he &alue you enter %or the C92,3 6ey+ord de%ines the &alue o% the constant/ Although a &alue is re4uired %or the constant, you do not ha&e to *re%ace the &alue +ith the C92,3 6ey+ord/ 3he %irst constant, CMP2<, uses the C92,3 6ey+ord to de%ine a character string/ 3he second e7a'*le includes se&eral &ariations: o 3he C92,3 6ey+ord is o'itted and the character constant is de%ined by enclosing the literal &alue in single 4uotes/ o 3he trailing hy*hen indicates that the &alue continues on the ne7t line, starting +ith the %irst character o% the %unctions section (*osition ##)/ 3he %inal t+o e7a'*les sho+ the de%inition o% noncharacter constants/ 3he nu'eric constant 3WE23< is de%ined by s*eci%ying a nu'eric &alue not enclosed in single 4uotes/ Be7adeci'al constants can be de%ined by s*eci%ying an D %ollo+ed by a &alid he7adeci'al &alue enclosed in single 4uotes/ In the e7a'*le, 8@P is de%ined as a he7adeci'al constant +ith a &alue o% D11C1 to re*resent the character returned +hen the 8@P 6ey is *ressed/ 3he actual C92,3 6ey+ord is o*tional %or all constants, regardless o% their data ty*e/ ,tand5alone !ields 3raditionally, RPG *rogra''ers ha&e de%ined +or6 %ields in C5s*ecs/ Although this is still *ossible using ILE RPG, you can de%ine stand5alone %ields that are not *art o% any %ile or data structure in 85 s*ecs/ We1ll loo6 at se&eral e7a'*les in ;/ 9ne s*ecial entry is re4uired %or stand5alone %ields: We1ll loo6 at se&eral e7a'*les in !igure ;/ 9ne s*ecial entry is re4uired %or stand5alone %ields: o An , in colu'n 2# o% the 85s*ec de%ines a stand5alone %ield/ 3he %irst e7a'*le is a se&en5digit, +or6 %ield (PACAH2)/ It is stored in *ac6ed5deci'al %or'at and has t+o deci'al *laces/ In RPG-#.. you are %orced to 'a6e this %ield *art o% a data structure e&en though it does not logically need to be associated +ith any other %ield/

o 3he length o% the %ield is coded in *ositions ;; to ;" rather than using starting and ending *ositions/ 3he *ositions +ithin the 85s*ecs are di%%erent than those %or I5,*ecs but contain the sa'e ty*e o% entries/ 9ur second e7a'*le de%ines LRGR9, based on the %ield PRGR9,/ LRGR9, is de%ined as t+o characters larger than PRGR9,/ ILE RPG *er'its you to use either the LIAE 6ey+ord in 85s*ecs or the ILIAE 8E!I2E o*eration in C5s*ecs to de%ine a %ield based on the characteristics o% another %ield/ 3he %inal e7a'*le o% a stand5alone %ield illustrated in ; de%ines DD2AME +ith the sa'e characteristics as the %ield PR2AME/ 9ne ne+ 6ey+ord is added %or this e7a'*le: 3he %inal e7a'*le o% a stand5alone %ield illustrated in !igure ; de%ines DD2AME +ith the sa'e characteristics as the %ield PR2AME/ 9ne ne+ 6ey+ord is added %or this e7a'*le: o 3he I2M 6ey+ord s*eci%ies the &alue to +hich a %ield is initialiEed/ InitialiEing %ields using this 'ethod is 'ore e%%icient than initialiEing the' in the C5s*ecs/ When the I2M 6ey+ord is not s*eci%ied, the de%ault &alue is blan6 %or character %ields and Eero %or nu5'eric %ields/ 8ata ,tructures Co'*le7 data organiEations are one o% the *ri'ary reasons %or adding 85s*ecs to the RPG language de%inition/ 3he %irst o% these 'ore co'*le7 %or's that +e1ll e7a'ine is the data structure/ # illustrates t+o +ays to code a data structure in ILE RPG/ In the %irst e7a'*le, the ILE RPG code is &ery si'ilar to the RPG-#.. code/ It uses absolute notation to designate the starting and ending *ositions o% each sub%ield/ 3he di%%erences bet+een the RPG-#.. e7a'*le and this ILE RPG e7a'*le are based on general rules %or %or'ating ILE RPG/ !igure # illustrates t+o +ays to code a data structure in ILE RPG/ In the %irst e7a'*le, the ILE RPG code is &ery si'ilar to the RPG-#.. code/ It uses absolute notation to designate the starting and ending *ositions o% each sub%ield/ 3he di%%erences bet+een the RPG-#.. e7a'*le and this ILE RPG e7a'*le are based on general rules %or %or'ating ILE RPG/ o 3he sub%ields 'ay be indented to 'a6e the data structure easier to understand/ o <ou can use lo+ercase or u**ercase %ield na'es at your discretion/ As +e 'entioned last 'onth, lo+ercase %ield na'es +ill be auto'atically translated to u**ercase by the co'*iler/ 3he second ILE RPG sa'*le ta6es ad&antage o% a se&eral ne+ %eatures/ o Length notation is used instead o% s*eci%ying the starting and ending *ositions %or each %ield/ 3he length o% each sub%ield is s*eci%ied in *ositions ;; to ;"/ 3he rest o% the synta7 is identical to absolute notation (e/g/, coding a 1P1 %or *ac6ed data, s*eci%ying deci'al *ositions, and so %orth)/ o 3he 9:ERLA< 6ey+ord %urther subdi&ides a sub%ield +ithin a data structure/ 3he %irst *ara'eter indicates the na'e o% the sub%ield +hose storage is to be o&erlaid/ 3his sub%ield 'ust ha&e been *re&iously de%ined in the sa'e data structure/ 3he second *ara'eter s*eci%ies the starting *osition +ithin the %ield/ 3he starting *osition is o*tional and de%aults to 1/

As sho+n in this e7a'*le, 9:ERLA<(GL2@M) is s*eci%ied %or the %ield glc'*y/ ,ince glc'*y has a length o% 2 and the starting *osition de%aults to 1, the %ield glc'*y is de%ined as the %irst t+o *ositions o% the %ield glnu'/ !or the %ield gl'ain, +e s*eci%ied 9:ERLA<(GL2@M:;)/ ,ince gl'ain has a length o% # and the starting *osition is ;, the %ield gl'ain is de%ined as *ositions ; to G o% the %ield glnu'/ !inally, the %ield glsub is de%ined as *ositions H to 11 o% the %ield gl'ain/ When using the 9:ERLA< 6ey+ord, the sub%ield being de%ined 'ay not e7tend beyond the end o% the %ield being o&erlaid/ In our sa'*le, s*eci%ying 9:ERLA<(GL2@M: ) %or the %ield glsub +ould cause an error/ $ecause glsub is a %i&e5character %ield, starting in *osition +ould e7tend this %ield to *osition 12/ ,ince glnu' is only 11 characters in length, an error +ould occur/ I% length notation is used, any changes to starting *osition +ithin the %ield glnu' +ill not a%%ect subse4uent %ields that aren1t *art o% glnu'/ 9&erlaid %ields, ho+e&er, +ill be a%%ected/ !or e7a'*le, i% you increase the length o% glnu' to 1; and o% gl'ain to G, you should change the starting *osition o% glsub so that gl'ain and glsub do not o&erla*/ $ut no changes are re4uired %or the %ields glclas and glcat/ Length notation can 'a6e %uture 'odi%ications easier than using absolute notation/ When the length o% a %ield changes, the subse4uent %ields do not ha&e to be 'odi%ied/ In this e7a'*le, the %ield gldesc could be e7*anded to #. *ositions +ithout 'a6ing any changes to the de%inition o% glnu' or its sub%ields/ 2ice 0ob, I$M? F illustrates an e7ternally de%ined data structure/ 3he ILE RPG *ortion o% this e7a'*le uses se&eral 6ey+ords that +ere sho+n in *re&ious e7a'*les or in last 'onth1s article on B5s*ecs and !5s*ecs/ 9ne ne+ 6ey+ord is introduced/ !igure F illustrates an e7ternally de%ined data structure/ 3he ILE RPG *ortion o% this e7a'*le uses se&eral 6ey+ords that +ere sho+n in *re&ious e7a'*les or in last 'onth1s article on B5s*ecs and !5 s*ecs/ 9ne ne+ 6ey+ord is introduced/ o 3he E in colu'n 22 s*eci%ies that this is an e7ternally de%ined data structure/ o 3he ED32AME 6ey+ord indicates that the data structure is de%ined based o the de%inition o% the %irst (or only) record %or'at o% the %ile 9ELPM2M/ 3o e7*licitly de%ine the record to be used, you 'ight code ED32AME (9ELPM2M:9ELPM2M"), indicating the record %or'at 9ELPM2M" should be used e&en i% it is not the %irst record %or'at in the %ile/ o 3he PRE!ID 6ey+ord i'*licitly rena'es the %ields in the data structure/ 3his global rena'e %unction is si'ilar to +hat +e co&ered in !5s*ecs last 'onth/ PM!2@M is rena'ed P2CPM!2@M, PM32@M is rena'ed P2CPM32@M, PM!MIP is rena'ed P2CPM!MIP, and PM3MIP is rena'ed P2CPM3MIP/ o 3he I2M 6ey+ord +as s*eci%ied %or the data structure 8,,EL to initialiEe nu'eric sub%ields to Eero and character sub%ields to blan6/ 3he I2M 6ey+ord on the sub%ield lines %or P2CPM32@M and P2CPM3MIP o&errides the de%ault initialiEation %or the data structure 8,,EL/ !inally, +e ha&e e7*licitly rena'ed the %ield PM!LAG to DDPM!LAG/ 3he PRE!ID 6ey+ord does not a%%ect an e7*licitly rena'ed %ieldN so there +ill be a %ield na'ed DDPM!LAG in the *rogra', but there +ill not be %ields na'ed P2CPM!LAG or PM!LAG unless they are de%ined else+here/

3he e7a'*le in G associates a data structure +ith an e7ternal data area/ It uses one ne+ 6ey+ord/ 3he e7a'*le in !igure G associates a data structure +ith an e7ternal data area/ It uses one ne+ 6ey+ord/ o 3he @ in *osition 2; indicates the data structure is a data area/ o 3he 83AARA 6ey+ord can be used to s*eci%y the na'e o% a data area/ ,*ecial *ara'eter &alues %or this 6ey+ord are IL8A %or the local data area and IP8A %or the PIP (*rogra' initialiEation *ara'eters) data area/ ILE RPG *er'its you to use either the 83AARA 6ey+ord in 85s*ecs or the I83AARA 8E!I2E o*eration in C5s*ecs to associate e7ternal data areas +ith internal *rogra' structures/ 3ables and Arrays In this section, +e1ll loo6 at se&eral e7a'*les o% arrays and tables and the ne+ ca*abilities that ILE RPG *ro&ides %or the'/ 3he essential de%inition o% arrays has not changed/ ILE RPG su**orts the three ty*es o% arrays (co'*ile5ti'e, *rerun5ti'e and run5ti'e) currently a&ailable +ith RPG-#.., and the sa'e basic rules a**ly/ Bo+e&er, ILE RPG uses 6ey+ords to de%ine the nu'ber o% ele'ents, %ro' and to %iles, and the ty*e o% array/ As in RPG-#.., an array beco'es a table i% its na'e begins +ith the letters 3A$/ We1ll re%er to tables and arrays generically as arrays unless an e7a'*le s*eci%ically uses a table/ H sho+s a run5ti'e array coded in RPG-#.. using an E5s*ec, and coded in ILE RPG using a 85 s*ec/ 3his e7a'*le illustrates the ne+ structure o% array de%initions/ !igure H sho+s a run5ti'e array coded in RPG-#.. using an E5s*ec, and coded in ILE RPG using a 85s*ec/ 3his e7a'*le illustrates the ne+ structure o% array de%initions/ o 3he , in *osition 2# o% the 85s*ec has the sa'e 'eaning as it has %or stand5alone %ields/ It indicates that the array is not *art o% a data structure/ o 3he length %or each ele'ent is coded in *ositions ;; to ;"/ o 3he 8IM 6ey+ord de%ines the di'ension (the nu'ber o% ele'ents) o% the array/ sho+s a co'*ile5ti'e array/ ,e&eral ne+ 6ey+ords are re4uired to de%ine ho+ the co'*ile5ti'e array data is included in the source code/ !igure sho+s a co'*ile5ti'e array/ ,e&eral ne+ 6ey+ords are re4uired to de%ine ho+ the co'*ile5ti'e array data is included in the source code/ o 3he C38A3A 6ey+ord indicates the array +ill be loaded %ro' co'*ile5ti'e data included at the end o% the source 'e'ber/ o 3he PERRC8 6ey+ord is used %or co'*ile5ti'e and *rerun5ti'e arrays to s*eci%y the nu'ber o% ele'ents loaded %ro' each record/ 3he de%ault is PERRC8(1) +hen C38A3A is s*eci%ied, so this *ara'eter does not ha&e to be coded/ It is included here to 'a6e the code easier to understand/

o !inally, the A,CE28 6ey+ord signi%ies that the array is in ascending se4uence/ @se o% the 8E,CE28 6ey+ord +ould designate descending se4uence/ " introduces se&eral additional conce*ts/ 3his e7a'*le loads t+o tables (e&erything in this e7a'*le is &alid %or arrays as +ell as tables) %ro' a %ile at *rerun5ti'e/ 3he data is loaded the %irst ti'e the *rogra' is called/ 3here are three ne+ 6ey+ords: !igure " introduces se&eral additional conce*ts/ 3his e7a'*le loads t+o tables (e&erything in this e7a'*le is &alid %or arrays as +ell as tables) %ro' a %ile at *rerun5ti'e/ 3he data is loaded the %irst ti'e the *rogra' is called/ 3here are three ne+ 6ey+ords: o 3he AL3 6ey+ord is s*eci%ied to associate the alternating table 3A$393 +ith the *ri'ary table 3A$8P3/ o !R9M!ILE(9L88EP3) causes the tables 3A$8P3 and 3A$393 to be loaded %ro' the %ile 9L88EP3 +hen the *rogra' is called %or the %irst ti'e/ o 3he ED3!M3 6ey+ord can be used to s*eci%y the e7ternal data %or'at %or co'*ile5ti'e and *rerun5ti'e arrays/ In this e7a'*le, ED3!M3(P) s*eci%ied %or the table 3A$393 indicates that data ele'ents o% this table are stored in *ac6ed, deci'al %or'at in the %ile 9L88EP3/ 9ther %or'ats, including the ne+ date and ti'esta'* %or'ats, are also &alid/ In this e7a'*le, the PERRC8(1) 6ey+ord 'ust be coded/ PERRC8(1) s*eci%ies that one ele'ent o% each table is loaded %ro' each record o% the %ile 9L88EP3/ 3he 6ey+ords %or the table 3A$8P3 continue on a second line/ I% *ositions H to #; o% a 85s*ec are blan6, the co'*iler assu'es the line is a continuation o% the *re&ious line/ In %act, a 6ey+ord can be coded on one line and its *ara'eter coded on the ne7t line, as in the case o% the 6ey+ord !R9M!ILE and its *ara'eter 9L88EP3/ Bo+e&er, you should not code in this 'anner since it can be con%usingN the code is included here %or illustration *ur*oses only/ ILE RPG also *er'its s*aces bet+een the 6ey+ord and its *ara'eter, as sho+n +ith the PERRC8 6ey+ord/ 1. sho+s the run5ti'e array ,R3/ $ecause this is a run5ti'e array, the PERRC8 6ey+ord is not used/ 3here is one ne+ 6ey+ord in this e7a'*le: !igure 1. sho+s the run5ti'e array ,R3/ $ecause this is a run5ti'e array, the PERRC8 6ey+ord is not used/ 3here is one ne+ 6ey+ord in this e7a'*le: o 3he I2M 6ey+ord *er'its di%%erent initialiEation &alues to be s*eci%ied %or the array/ In the ILE RPG e7a'*le, +e ha&e s*eci%ied a de%ault &alue o% IBI:AL at co'*ile ti'e, instead o% using a M9:E in C5s*ecs at run ti'e as you see in the RPG-#.. sa'*le/ 3he I2M 6ey+ord causes the array to be initialiEed +ith the s*eci%ied &alue the %irst ti'e the *rogra' is called/ I% the *rogra' returns +ithout setting on LR and is called again, the I2M 6ey+ord has no e%%ect the second ti'e the *rogra' is called so the array still has the sa'e &alue it had +hen the *rogra' last returned/ $y de%ault, the initialiEation &alues are based on the data ty*e5 blan6s %or character data and Eeroes %or nu'eric data/ 3o illustrate this *oint, the sa'*le e7*licitly de%ines ,R3 as a character array +ith the data ty*e o% A in *osition #./ 3he data ty*e is o*tional because, as in 88,, a %ield +ith no deci'al *ositions s*eci%ied de%aults to a character %ield/

With the constraints o% RPG-#.. E5s*ecs re'o&ed, +hat1s in the %uture %or arrays in ILE RPG> Bo+ about a t+o5di'ensional array coded +ith a techni4ue such as 8IM("":12)> In our sa'*le, this 'ight indicate "" ele'ents in the %irst di'ension and 12 in the second/ Perha*s +e1ll see this su**ort in a %uture ILE RPG release/ What1s 2e7t> 3he ne+ 85s*ecs *er'it us to consolidate data de%initions in a single *lace in our *rogra's, +hich can 'a6e the' easier to understand and 'odi%y/ In addition, the 9:ERLA<, PRE!ID and length notations *ro&ide substantial usability i'*ro&e'ents in ILE RPG/ What does the %uture hold> ,ince +e can de%ine any %ield or array in 85s*ecs, ho+ about *er'itting 85s*ecs at the start o% a subroutine to de%ine local &ariables> Wouldn1t it be nice to be able to use %ields or arrays in a subroutine and not ha&e to +orry i% they are used else+here in the *rogra'> Perha*s +e1ll see local &ariables i'*le'ented in a %uture ILE RPG release/ In our ne7t article, +e +ill tac6le I5s*ecs, C5s*ecs, 95s*ecs, and introduce $uilt5In !unctions ($I!s)/ Charlie Massoglia, *resident o% Massoglia 3echnical Consulting, Inc/ in 96e'os, Michigan, has authored a nu'ber o% 'idrange boo6s/ Bis co+boy hat is his trade'ar6 %or his %re4uent s*ea6ing tours throughout the @nited ,tates, Canada, Euro*e and Australia/ Charlie can be reached at F1H5 GHG5"H../
An Introduction to ILE RPG: Part 2

Figure 1 D-spec Layout


07%@LE C REPRCD0CE GR%P<IC>

An Introduction to ILE RPG:

Part 2

Figure

2 #amed Constants

::: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 0 I::::::::::::::7amedconstant;;;;;;;;;C:::::::::Fldnme:::::::::::::::::::::: I A?idrange Comp1tingA C C?P7= I Aa!cdefghiKHlmnopGrs& C LLR I At1D2E"8A I 30 C LE7 = I JA1CA C D0P

An Introduction to ILE RPG:

Part 2

Figure

Stand-alone Fields

::: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 0 IDsname::::7CDsEEt&file;;:::::::::::::CccrLen;::::::::::::::::::::::::::::: I D> I::::::::::::::EEt&field;::::::::::::PFrom o;;DField;:::::::::::::::::::::: I P 1 43P%CF63 CL0701703705Factor1;;;CpcdeFactor3;;;Res1ltLenD<<iLoEGComments;;;;;;;:::::: C 9LIFE DEF7 PRGRC> LRGRC>; 3 C 9LIFE DEF7 PR7%?E JJ7%?E C ?C$ELA?issingA JJ7%?E P PMPad 2ith !lanHs

An Introduction to ILE RPG:

Part 2

Figure

" $ata Structures

::: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 0 IDsname::::7CDsEEt&file;;:::::::::::::CccrLen;::::::::::::::::::::::::::::: IGLD> D> I::::::::::::::EEt&field;::::::::::::PFrom o;;DField;:::::::::::::::::::::: I 1 50 GLDE>C I 51 41 GL70? I 51 53 GLC?P= I 55 56 GL?%I7 I 56 41 GL>0@ I 43 44 GLCL%>> I 44 4# GLC%

An Introduction to ILE RPG:

Part 2

Figure

' E1ternall2 $e3ined $ata Structures

::: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 0 IDsname::::7CDsEEt&file;;:::::::::::::CccrLen;::::::::::::::::::::::::::::: ID>>EL EID>CELP?7? I::::::::::::::EEt&field;::::::::::::PFrom o;;DField;:::::::::::::::::::::: I P?F70? P3F70? I P? 70? P3 70? I P?F'IP P3F'IP I P? 'IP P3 'IP CL0701703705Factor1;;;CpcdeFactor3;;;Res1ltLenD<<iLoEGComments;;;;;;;:::::: C 9I7'>R @EG>R

C C C

?C$E 9%LLA)A ?C$E 9%LLA)A E7D>R

P3 70? P3 'IP

An Introduction to ILE RPG:

Part 2

Figure

( $ata Areas

::: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 0 IDsname::::7CDsEEt&file;;::::::::::::::CccrLen;:::::::::::::::::::::::::::: II7$+D> D> I::::::::::::EEt&field;::::::::::::::PFrom o;;DField;L1?1::Pl?n'r:::::::::: I 1 60*I7$+ I # # *I> > CL0701703705Factor1;;;CpcdeFactor3;;;Res1ltLenDE<iLoEGComments;;;;;;;:::::: C 97%?$%R DEF7 I7$+D> CE%I7 InDoice + D %%R%

An Introduction to ILE RPG:

Part 2

Figure

- Run-time Arra2

::: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 0 E::::Fromfile ofile;;7ame;;7/r7/t!LenPD>%rrnamLenPD>Comments;;;;;;;;;:::::: E DEP 10 3

An Introduction to ILE RPG:

Part 2

Figure

. Compile-time Arra2

::: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 0 E::::Fromfile ofile;;7ame;;7/r7/t!LenPD>%rrnamLenPD>Comments;;;;;;;;;:::::: E DEP 1 10 3 %

An Introduction to ILE RPG:

Part 2

Figure

/ Prerun-time Arra2s

::: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 0 E::::Fromfile ofile;;7ame;;7/r7/t!LenPD>%rrnamLenPD>Comments;;;;;;;;;:::::: E CLDDEP %@DP 1 100 5 0% %@ C )P3

An Introduction to ILE RPG:

Part 2

Figure

10 Initiali4ing an Arra2

::: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 0 E::::Fromfile ofile;;7ame;;7/r7/t!LenPD>%rrnamLenPD>Comments;;;;;;;;;:::::: E >R )) 10 CL0701703705Factor1;;;CpcdeFactor3;;;Res1ltLenDE<iLoEGComments;;;;;;;:::::: C 9I7'>R @EG>R C ?C$E 9<I$%L >R C E7D>R

An Introduction to ILE RPG: Part ; $rie%: 9ur third install'ent on ILE RPG co&ers changes to I5s*ecs, C5s*ecs and 95s*ecs/ All three ha&e been 'odi%ied to acco''odate the longer %ield na'e, %ield length and deci'al *osition entries/ We1ll %ocus on C5s*ecs +here %ree5 %or' e7*ressions can greatly si'*li%y the code %or both logical and arith'etic co'*arisons and calculations/ <ou1ll see that the basic co'*onents o% RPG-#.. ha&e been retained but signi%icant ne+ %unction has been added to the language +ith these changes/ Last 'onth +e continued our re&ie+ o% the ne+ Integrated Language En&iron'ent RPG (ILE RPG) +hich +ill be announced as *art o% :;R1M./ We sa+ the eli'ination o% E7tension s*eci%ications (E5s*ecs) +ith array and table de%inition 'o&ed to the ne+ 8e%inition s*eci%ications (85s*ecs)/ 2a'ed constant and data structure de%inition has been 'o&ed %ro' In*ut s*eci%ications (I5s*ecs) to 85s*ecs/ 9ur *rogra's should be 'ore 'aintainable +ith the ability to consolidate all data de%inition into a single location585s*ecs/

,ubstantial *roducti&ity gains should result %ro' the introduction o% the 9:ERLA< and PRE!ID 6ey+ords and the ability to use length notation in data structures/ What1s le%t> We1ll see 'inor changes to I5s*ecs and 9ut*ut s*eci%ications (95 s*ecs)/ Bo+e&er, radical changes abound in Calculation s*eci%ications (C5 s*ecs)/ !or e7a'*le, ILE RPG C5s*ecs can use sy'bolic o*erators that 'ay not be %a'iliar to RPG *rogra''ers/ Co'bine this +ith lo+ercase &ariable na'es and %ree5%or' e7*ressions5C5s*ecs don1t loo6 the sa'e/ Let1s ta6e a 4uic6 loo6 at I5s*ecs and then 'o&e on to e7*lore the tre'endous *roducti&ity gains o%%ered by the changes in C5s*ecs/ We1ll %inish +ith a re&ie+ o% 95s*ecs/ In*ut ,*eci%ications (I5s*ecs) ,e&eral 'a0or changes ha&e been 'ade to I5s*ecs in ILE RPG/ Most ob&ious are the changes re4uired to acco''odate 1.5character %ile and %ield na'es, longer %ield lengths, and t+o *ositions %or the nu'ber o% deci'al digits/ While ad0usting to these changes +ill be al'ost intuiti&e, other changes +ill re4uire so'e education/ 3he ability to s*eci%y date and ti'e %or'at and se*arator characters has been added to I5s*ecs %or *rogra' described %iles/ As +e discussed last 'onth, data structures, data structure sub%ields and na'ed constants are no longer de%ined in I5s*ecs/ 3heir de%inition has been 'o&ed to the ne+ 85s*ecs/ E7ternally 8escribed !iles Most nati&e RPG-#.. *rogra's do not re4uire I5s*ecs %or %iles/ 3he sa'e is true o% ILE RPG *rogra's/ 3he only ti'e you need to code I5s*ecs %or e7ternally described %iles is +hen you +ant to assign indicators or rena'e %ields/ When you start using ILE RPG, ho*e%ully your %iles +ill all be e7ternally described so you do not ha&e to use *rogra' described %iles/ Contrary to con&entional +isdo', our sho* does use control le&el indicators %or re*orts since there is no easier +ay to *roduce subtotals and +e ha&e %ound negligible *er%or'ance di%%erences bet+een in*ut *ri'ary and %ull *rocedural %iles/ Without getting into a debate about +hether or not control le&el indicators should be used, let1s re%er to 1 %or a sa'*le o% assigning these indicators in RPG-#.. and ILE RPG/ Contrary to con&entional +isdo', our sho* does use control le&el indicators %or re*orts since there is no easier +ay to *roduce subtotals and +e ha&e %ound negligible *er%or'ance di%%erences bet+een in*ut *ri'ary and %ull *rocedural %iles/ Without getting into a debate about +hether or not control le&el indicators should be used, let1s re%er to !igure 1 %or a sa'*le o% assigning these indicators in RPG-#.. and ILE RPG/ In this si'*le e7a'*le, +e ha&e assigned record identi%ying indicator .1 to record %or'at ARPCM1 in our ARPCM custo'er 'aster %ile/ In addition, control le&el indicator LG has been assigned to the custo'er nu'ber %ield ARC@,3/ E7ce*t %or *ositioning and the ability to s*eci%y 1.5character record %or'at and %ield na'es, the RPG-#.. and ILE RPG I5s*ec record and %ield layouts are identical %or e7ternally described %iles/

I% you are using I5s*ecs to rena'e all o% the %ields in a record %or'at, you can acco'*lish this globally by s*eci%ying the ne+ PRE!ID 6ey+ord on the !5 s*ecs/ (,ee Part 1 o% this series i% you need a re%resher/) Also, %ield na'es +ith lengths that e7ceed si7 characters no longer need to be rena'ed since ILE RPG su**orts 1.5character %ield na'es/ Progra' 8escribed !iles 2 sho+s that the only changes to the I5s*ec record layout %or a *rogra' described %ile are su**ort %or a 1.5character %ile na'e and "","""5byte record length/ In the e7a'*le, +e ha&e assigned record identi%ying indicator .1 to records +ith the character A in *osition 1 and record identi%ying indicator .2 to records +ith the character C in *osition 1/ !igure 2 sho+s that the only changes to the I5s*ec record layout %or a *rogra' described %ile are su**ort %or a 1.5character %ile na'e and "","""5byte record length/ In the e7a'*le, +e ha&e assigned record identi%ying indicator .1 to records +ith the character A in *osition 1 and record identi%ying indicator .2 to records +ith the character C in *osition 1/ 3he I5s*ec %ield layout sho+s si'ilar changes to acco''odate 1.5character %ield na'es, %ro' and to *ositions u* to "",""", and deci'al *ositions u* to ;./ 3he 1# *ositions %or the %ield na'e +ill 'a6e it easier to s*eci%y array indices/ In the RPG-#.. e7a'*le, the %ield 3R8A3E is de%ined as a character %ield +ith a length o% eight/ In the ILE RPG e7a'*le, +e ha&e 'odi%ied the de%inition o% this %ield by adding IM8< in *ositions ;1 to ;# to denote an e7ternal date-ti'e ty*e o% MM88<<, a slash (-) in *osition ;F to indicate the date-ti'e se*arator character, and a 8 in *osition ;G to de%ine the data ty*e o% date/ 3hese additions de%ine the %ield 3R8A3E as a date %ield in MM88<< %or'at +ith a slash (-) as the se*arator character/ ILE RPG no+ directly su**orts date (8), ti'e (3) and ti'esta'* (M) data ty*es/ I8M<, I<M8, IL@L, IBM, and se&eral other %or'ats can be s*eci%ied/ We1ll go into 'ore detail on the use o% these data ty*es ne7t 'onth/ !igures ; and # su''ariEe changes to I5s*ecs %or *rogra' described %iles/ Calculation ,*eci%ications (C5s*ecs) C5s*ecs ha&e undergone 'a0or 'odi%ication in ILE RPG/ Many changes +ere re4uired to acco''odate rela7ed li'its in ILE RPG, +hile other changes *ro&ide substantial usability i'*ro&e'ents/ F sho+s %actor 1, %actor 2 and the result %ield ha&e all been increased to 1# characters to handle 1.5 character sy'bolic na'es +ith e7tra s*ace %or an array inde7 +hen needed/ 9ther changes are also a**arent/ !igure F sho+s %actor 1, %actor 2 and the result %ield ha&e all been increased to 1# characters to handle 1.5character sy'bolic na'es +ith e7tra s*ace %or an array inde7 +hen needed/ 9ther changes are also a**arent/ 3he o*eration code has been increased to si7 characters, but the i'*le'entation is not consistent/ RE8PE has been changed to REA8PE but, %or so'e reason, the 8I: o*eration has not been

changed to 8I:I8E/ ,o'e+hat con%using, isn1t it> 3he old %i&e5character o*eration codes +ill no longer +or6 in C5s*ecs/ G su''ariEes changes to o*eration codes/ 3he o*eration code has been increased to si7 characters, but the i'*le'entation is not consistent/ RE8PE has been changed to REA8PE but, %or so'e reason, the 8I: o*eration has not been changed to 8I:I8E/ ,o'e+hat con%using, isn1t it> 3he old %i&e5character o*eration codes +ill no longer +or6 in C5s*ecs/ !igure G su''ariEes changes to o*eration codes/ 3he o*eration e7tender has been 'o&ed to %ollo+ the o*eration code and 'ust be enclosed in *arentheses ()/ 9*eration e7tenders include B %or hal% ad0ust, 2 %or read +ith no loc6 and P %or *ad +ith blan6s/ As in I5s*ecs, deci'al *ositions u* to ;. are no+ su**orted in C5s*ecs/ In our ILE RPG sa'*le (F), +e ha&e 'odi%ied the nu'ber o% deci'al *ositions %or the %ield DRA3I9 %ro' " to 1F and its length %ro' 1" to 2;/ As in I5s*ecs, deci'al *ositions u* to ;. are no+ su**orted in C5s*ecs/ In our ILE RPG sa'*le (!igure F), +e ha&e 'odi%ied the nu'ber o% deci'al *ositions %or the %ield DRA3I9 %ro' " to 1F and its length %ro' 1" to 2;/ 9nly a single conditioning indicator is *er'itted/ I% you ha&e old code +hich uses 'ore than one conditioning indicator, the RPG-#..5to5ILE RPG source5 con&ersion utility +ill auto'atically *ut each indicator on a se*arate state'ent/ Ba&ing to *ut resulting indicators such as the end5o%5%ile indicator in *ositions HF to HG is going to cause so'e *roble's %or those o% us +ith .5 character ter'inals/ 3he only +ay to 6ey so'ething beyond *osition H1 in ,E@ on an .5character ter'inal is to *ro'*t the state'ent or +indo+ to the right/ And re'e'ber, co''ents are in *ositions 1 to 1.. %or all ILE RPG s*eci%ications/ Perha*s no+ is the ti'e to start thin6ing about budgeting to re*lace those .5 colu'n clun6ers +ith 1;25 colu'n ter'inals or PCs/ !ree5%or' Arith'etic E7*ressions ILE RPG su**orts %ree5%or' e7*ressions in C5s*ecs/ Instead o% ha&ing to code a co'*le7 %or'ula a single ste* at a ti'e, the ne+ E:AL o*eration code can be used +ith an e7tended %actor 2/ ,tandard arith'etic o*erators su**orted include:
; & 9 / 99 %ddition >1!traction ?1ltiplication DiDision EEponentiation

!actor 1 'ust be blan6/ 3he hal% ad0ust o*eration code e7tender (B) 'ay be used +ith E:AL but 2 and P are not &alid/ While conditioning indicators 'ay be used, as +ith all C5s*ecs they should be a&oided i% *ossible/ I% you1re using control le&el indicators in your I5s*ecs, use a single, control le&el indicator in your C5s*ecs to control e7ecution o% a subroutine/ $ecause RPG is not an indicator5 o*ti'iEed co'*iler, indicators should be re%erenced as little as *ossible/ $lan6s can be %reely inters*ersed bet+een o*erands and o*erators to 'a6e the code easier to understand/ In so'e cases, blan6s are re4uired5%or e7a'*le to di%%erentiate bet+een e7*onentiation

and 'ulti*lication o% a reser&ed +ord beginning +ith an asteris6/ Consider the %ollo+ing e7*ression: AII3IME 3his e7*ression is inter*reted as the %ield A raised to the *o+er o% the %ield 3IME/ I% 'ulti*lication by the ne+ reser&ed +ord, I3IME, is intended, the e7*ression should be coded in one o% these t+o +ays: AI I3IME A I I3IME We1ll address date and ti'e data ty*es including the I3IME reser&ed +ord ne7t 'onth/ We1ll loo6 at so'e si'*le sa'*les o% E:AL in H/ 3he %irst sa'*le re*laces a single calculation/ 3he %ield oecost is co'*uted as the &alue o% the %ield oe4ty ti'es the %ield i'*ric/ 3he hal% ad0ust o*eration e7tender has been enclosed in *arentheses and 'o&ed ne7t to the o*eration code/ We1ll address date and ti'e data ty*es including the I3IME reser&ed +ord ne7t 'onth/ We1ll loo6 at so'e si'*le sa'*les o% E:AL in !igure H/ 3he %irst sa'*le re*laces a single calculation/ 3he %ield oecost is co'*uted as the &alue o% the %ield oe4ty ti'es the %ield i'*ric/ 3he hal% ad0ust o*eration e7tender has been enclosed in *arentheses and 'o&ed ne7t to the o*eration code/ 3he second sa'*le is a t+o5*art calculation/ 3he %ield oe+ght is co'*uted as the &alue o% the %ield oe4ty ti'es the %ield i'+ght, +ith the %ield *6+ght added to the result/ $ased u*on the rules o% *recedence, the use o% *arentheses is o*tional/ Re'e'ber high school algebra> It %inally has so'e &alue/ 3he order o% *recedence %or arith'etic o*erations in ILE RPG %ree5%or' e7*ressions is the sa'e as it +as in high school algebra:
o o o o parentheses eEponentiation m1ltiplication and diDision addition and s1!traction

In the last sa'*le in H, the %ield oesta7 is co'*uted as the &alue o% the %ield oecost 'inus the %ield oedisc, +ith the %ield stta7 'ulti*lied by the result/ 3he *arentheses in this case are re4uired/ Without the', the %ield oedisc +ould be 'ulti*lied by the %ield stta7 and the result +ould be subtracted %ro' the %ield oecost, yielding erroneous results/ In the last sa'*le in !igure H, the %ield oesta7 is co'*uted as the &alue o% the %ield oecost 'inus the %ield oedisc, +ith the %ield stta7 'ulti*lied by the result/ 3he *arentheses in this case are re4uired/ Without the', the %ield oedisc +ould be 'ulti*lied by the %ield stta7 and the result +ould be subtracted %ro' the %ield oecost, yielding erroneous results/ 3o 'a6e your code 'ore readable, %eel %ree to use *arentheses e&en i% they are not re4uired/ ,o'e co'*le7 %or'ulae can re4uire se&eral lines o% code/ 9r so'eti'es it1s con&enient to brea6 u* your code into se&eral lines to 'a6e the' 'ore readable/ sho+s such an e7a'*le/

,o'e co'*le7 %or'ulae can re4uire se&eral lines o% code/ 9r so'eti'es it1s con&enient to brea6 u* your code into se&eral lines to 'a6e the' 'ore readable/ !igure sho+s such an e7a'*le/ We +ant to co'*ute the total o% %irst5, second5 and third5shi%t *ay, re'e'bering to add in shi%t *re'iu' be%ore 'ulti*lying rate ti'es hours/ We can re*lace se&en RPG-#.. calculations +ith a single ILE RPG e7*ression/ 2ice 0ob, I$M? I% the %ield t'*ay is not large enough to hold the result, a nu'eric o&er%lo+ e7ce*tion occurs and the status code in the *rogra' status data structure is set to 1.;/ 3his *roduces a run5ti'e halt/ I% nu'eric o&er%lo+ occurs in ILE RPG in arith'etic o*erations such as M5A88 +hich do not in&ol&e e7*ressions, truncation +ithout a halt +ill occur 0ust as it does in RPG-#../ ,*eci%ying 3R@2C2$R(I29) +hen co'*iling an ILE RPG *rogra' +ill %orce a run5ti'e halt any ti'e nu'eric o&er%lo+ occurs/ Continued Literals 3he ILE RPG e7a'*le in " contains t+o e7*ressions +ith continued literals/ 3he %irst uses a *lus sign (O) continuation character +hich 'eans the literal is continued +ith the %irst non5blan6 character in *ositions ;G to . o% the ne7t line/ 3he second e7a'*le uses a hy*hen (5) continuation character +hich 'eans the literal is continued in *osition ;G o% the ne7t line e&en i% it contains a blan6/ 3he %ields des1 and des2 +ill both ha&e the sa'e &alue/ 3he ILE RPG e7a'*le in !igure " contains t+o e7*ressions +ith continued literals/ 3he %irst uses a *lus sign (O) continuation character +hich 'eans the literal is continued +ith the %irst non5blan6 character in *ositions ;G to . o% the ne7t line/ 3he second e7a'*le uses a hy*hen (5) continuation character +hich 'eans the literal is continued in *osition ;G o% the ne7t line e&en i% it contains a blan6/ 3he %ields des1 and des2 +ill both ha&e the sa'e &alue/ An e7*ression can be continued o&er 'ulti*le lines/ Continued lines 'ust be blan6 in *ositions H to ;F/ 2o s*ecial continuation character is re4uired unless a literal is being continued/ Co''ent lines +ith an asteris6 (I) in *osition H can be inters*ersed bet+een continued lines/ $lan6 lines can also be used/ !ree5%or' Logical E7*ressions In addition to the E:AL o*eration, ILE RPG also su**orts %ree5%or' e7*ressions %or the ne+ 89@, 89W, I! and WBE2 o*erations/ 3hese o*erations are %unctionally e4ui&alent to the 89@77, 89W77, I!77 and WBE277 o*erations e7ce*t instead o% co'*aring %actor 1 to %actor 2, the e7tended %actor 2 entry is used %or the co'*arison/ :alid o*erators include:
M NM N OM O ON EG1al to Greater than or eG1al to Greater than Less than or eG1al to Less than 7ot eG1al

3he RPG-#.. e7a'*le in 1. sho+s a 89W loo* +ith t+o tests/ !irst, < 'ust be less than F./ ,econd, the s*eci%ied ele'ent (inde7ed by D) o% the array I2 'ust not be blan6/ As long as both o% these tests are true, the loo* continues/ I% either is not true, the loo* ends/ 3he ILE RPG e7a'*le

co'bines both o% these tests into a single 89W state'ent +ith the tests se*arated by an A28/ Probably the 'ost di%%icult *art o% this e7a'*le is re'e'bering to use PQ in ILE RPG instead o% the I2E you +ould ha&e used in CL/ 3he RPG-#.. e7a'*le in !igure 1. sho+s a 89W loo* +ith t+o tests/ !irst, < 'ust be less than F./ ,econd, the s*eci%ied ele'ent (inde7ed by D) o% the array I2 'ust not be blan6/ As long as both o% these tests are true, the loo* continues/ I% either is not true, the loo* ends/ 3he ILE RPG e7a'*le co'bines both o% these tests into a single 89W state'ent +ith the tests se*arated by an A28/ Probably the 'ost di%%icult *art o% this e7a'*le is re'e'bering to use PQ in ILE RPG instead o% the I2E you +ould ha&e used in CL/ Co'*le7 e7*ressions can be constructed using A28 and 9R/ Bo+ +ill you 6no+ the di%%erence bet+een the %ield 9R and the o*eration 9R> <ou 'ight not 6no+ at %irst, but the co'*iler +ill/ While &ariables na'ed A28 and 9R are &alid in ILE RPG, they should be a&oided at all costs to *re&ent 'isunderstanding/ Control le&el and conditioning indicators 'ay be used/ !actor 1 'ust be blan6/ 2o o*eration e7tenders are *er'itted/ 3he RPG-#.. sa'*le in 11 is a little 'ore co'*le7 than our *re&ious e7a'*les/ It utiliEes 'ulti*le WB77 o*erations +ithin a ,ELEC grou*/ 3he %irst WBEJ o*eration tests %or 3RC98E e4ual to A +hile the second tests %or 3RC98E e4ual to C or 8/ An a**ro*riate action descri*tion *added +ith blan6s is 'o&ed to the %ield KAC32/ 3he RPG-#.. sa'*le in !igure 11 is a little 'ore co'*le7 than our *re&ious e7a'*les/ It utiliEes 'ulti*le WB77 o*erations +ithin a ,ELEC grou*/ 3he %irst WBEJ o*eration tests %or 3RC98E e4ual to A +hile the second tests %or 3RC98E e4ual to C or 8/ An a**ro*riate action descri*tion *added +ith blan6s is 'o&ed to the %ield KAC32/ 3he ILE RPG e7a'*le again co'bines 'ulti*le tests into a single state'ent using the WBE2 o*eration +ith the tests se*arated by an 9R/ 3han6 you, I$M? We ha&e also changed the M9:EL o*eration to an E:AL in this e7a'*le/ I% only the hal% ad0ust o*eration e7tender is &alid +ith E:AL, +hat ha**ened to the *ad +ith blan6s> When the E:AL o*eration is used to set the &alue o% a character %ield, it %unctions the sa'e as a M9:EL(P)/ 3he result is le%t5ad0usted and *added +ith blan6s on the right/ I% the e7*ression is longer than the &ariable, the &alue is truncated +ith no error gi&en/ ,o'eti'es inter'ediate results 'ust be calculated to *er%or' a test/ When doing a credit chec6 on an order, you +ould add the order a'ount to the custo'er1s Accounts Recei&able balance and co'*are the su' to the custo'er1s credit li'it/ 3his re4uires t+o se*arate o*erations in RPG-#../ ILE RPG re4uires only a single state'ent as illustrated in 12/ ,o'eti'es inter'ediate results 'ust be calculated to *er%or' a test/ When doing a credit chec6 on an order, you +ould add the order a'ount to the custo'er1s Accounts Recei&able balance and co'*are the su' to the custo'er1s credit li'it/ 3his re4uires t+o se*arate o*erations in RPG-#../ ILE RPG re4uires only a single state'ent as illustrated in !igure 12/ 12 sho+s the I! o*eration su**orts arith'etic e7*ressions as *art o% the e7tended %actor 2 in ILE RPG/ As +e1&e sho+n, so do the 89@, 89W and WBE2 o*erations/ 3he %ield oecost is %irst added to the %ield c'bal and the su' co'*ared to the %ield c'cred/ Co'*arison o*erators such as greater

than (Q) ha&e a lo+er order o% *recedence than arith'etic o*eratorsN conse4uently, the arith'etic is done %irst, %ollo+ed by the co'*arison/ I% A28 or 9R is used, these logical o*erations are *er%or'ed last because they are lo+est in order o% *recedence/ !igure 12 sho+s the I! o*eration su**orts arith'etic e7*ressions as *art o% the e7tended %actor 2 in ILE RPG/ As +e1&e sho+n, so do the 89@, 89W and WBE2 o*erations/ 3he %ield oecost is %irst added to the %ield c'bal and the su' co'*ared to the %ield c'cred/ Co'*arison o*erators such as greater than (Q) ha&e a lo+er order o% *recedence than arith'etic o*eratorsN conse4uently, the arith'etic is done %irst, %ollo+ed by the co'*arison/ I% A28 or 9R is used, these logical o*erations are *er%or'ed last because they are lo+est in order o% *recedence/ 1; su''ariEes changes to C5s*ecs/ !igure 1; su''ariEes changes to C5s*ecs/ 9ut*ut ,*eci%ications (95s*ecs) Many o% the changes to 95s*ecs are &ery si'ilar to +hat +e sa+ in I5s*ecs/ 1# sho+s the e7*anded s*ace to su**ort ending *ositions u* to "",""" and na'es %or 1.5character %iles, record %or'ats, %ields and e7ce*t labels/ @nli6e C5s*ecs, all three conditioning indicators ha&e been retained in 95 s*ecs/ Many o% the changes to 95s*ecs are &ery si'ilar to +hat +e sa+ in I5s*ecs/ !igure 1# sho+s the e7*anded s*ace to su**ort ending *ositions u* to "",""" and na'es %or 1.5character %iles, record %or'ats, %ields and e7ce*t labels/ @nli6e C5s*ecs, all three conditioning indicators ha&e been retained in 95s*ecs/ In the ILE RPG e7a'*le, +e ha&e also 'odi%ied the de%inition o% our %ield 3R8A3E by adding a 8 in *osition F2 and IM8<- in *ositions F; to FH to denote an e7ternal date data ty*e o% 'onth-day-year +ith a slash (-) se*arator character/ 1F sho+s so'e o% the changes in 95s*ecs %or coding *rogra' described *rinter %iles/ RPG-#.. only su**orts Eero to three s*ace be%ore or s*ace a%ter lines/ 9ur RPG-#.. e7a'*le there%ore re4uires t+o e7ce*tion out*ut state'ents to s*ace %i&e lines be%ore *rinting5one state'ent to s*ace three lines and another to s*ace t+o lines/ !igure 1F sho+s so'e o% the changes in 95s*ecs %or coding *rogra' described *rinter %iles/ RPG-#.. only su**orts Eero to three s*ace be%ore or s*ace a%ter lines/ 9ur RPG-#.. e7a'*le there%ore re4uires t+o e7ce*tion out*ut state'ents to s*ace %i&e lines be%ore *rinting5one state'ent to s*ace three lines and another to s*ace t+o lines/ ILE RPG re4uires only a single line since &alues %ro' . to 2FF are su**orted %or s*ace be%ore and s*ace a%ter lines/ In addition, s6i* be%ore and s6i* a%ter line nu'bers can no+ be %ro' . to 2FF/ Constants or edit +ords can be continued on 'ulti*le lines in *ositions F; to ./ 3he line being continued 'ust end +ith a *lus sign (O) or hy*hen (5)/ A *lus sign (O) 'eans continuation starts +ith the %irst nonblan6 character in or *ast *osition F; o% the ne7t line/ A hy*hen (5) 'eans continuation starts in *osition F; o% the ne7t line e&en i% it is blan6/ 3he continuation line 'ust contain an 9 in *osition G and be blan6 in *ositions H to F2/ $lan6 se*arator lines and co''ent lines are *er'itted bet+een continued lines/

1G su''ariEes changes to 95s*ecs/ !igure 1G su''ariEes changes to 95s*ecs/ What1s 2e7t> We1&e seen 'any o% the changes to the I5s*ecs, C5s*ecs and 95s*ecs +ere re4uired to acco''odate the change %ro' G5character to 1.5character sy'bolic na'es and the su**ort o% increased %ile record lengths, %ield lengths and nu'ber o% deci'al *ositions/ 3he ne+ E:AL, 89@, 89W, I! and WBE2 o*erations and the introduction o% e7*ressions to C5s*ecs *ro&ide e&en 'ore usability i'*ro&e'ents to ILE RPG/ In our ne7t article, +e introduce built5in %unctions ($I!) and tac6le date-ti'e data ty*es including the ne+ date-ti'e arith'etic o*eration codes/ Charlie Massoglia, *resident o% Massoglia 3echnical Consulting, Inc/ in 96e'os, Michigan, has authored a nu'ber o% 'idrange boo6s/ Bis co+boy hat is his trade'ar6 %or his %re4uent s*ea6ing tours throughout the @nited ,tates, Canada, Euro*e and Australia/ Charlie can be reached at F1H5 GHG5"H../
An Introduction to ILE RPG: Part

Figure 1 I-spec E!terna""y Descri#ed Fi"e

9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # FFilenameIPE%F::::RlenLFl%ICDFlocEDeDice;::::::FeEit;;Entr";%::::01:::::::: F%RPC? IP E DI>F IRcdname;::::In:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: I%RPC?1 01 I::::::::::::::EEt&field;::::::::::::::::::::::Field;L1?1::Pl?n'r:::::::::: I %RC0> L6 9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::

FFilename;;IPE%>FRlen;LFlen;%IDeDice;:File-contin1ation;;;;;;;;;;;;;;;;;;; ;Comme F%RPC? IP E DI>F IRcdname;; ;::::Ri::::::::::::::::::::::::::::::::::::::::::::::::::::::::::Comme I%RPC?1 01 I::::::::::::::EEt&field;::::::::::::::::::Field;;;;;;;; ;L1?1::Pl?n'r::::::Comme I %RC0> L6

An Introduction to ILE RPG: Part

Figure

2 I-spec Program $escri5ed File

9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # IFilename>G7CRiPos17CCPos37CCPos57CC::::::::::::::::::::::::::::::::::::::: I%R R%7 7> 01 1 C% I CR 03 1 CC I::::::::::::::::::::::::::::::::::::PFrom o;;DFldnmeL1?1FrPl?n'r::::::::: I 1 1 RCCDE I 3 #0 RC0> I ) 16 RD% E I P 16 313 R%? 9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::

IFilename; ;>G7CRiPos1;7CCPos3;7CCPos5;7CC::::::::::::::::::::::::::::::::::Comme I%R R%7 7> 01 1 C% I CR 03 1 CC I::::::::::::::::::::::::Fmt;>PFrom; o;;;DcField;;;;;;;; ;L1?1FrPl?n'r::::::Comme I 1 1 RCCDE I 3 # 0 RC0> I 9?D=/D ) 16 RD% E I P 16 31 3 R%?

An Introduction to ILE RPG: Part

Figure C!anges to I-spec Record La2out 3or Program $escri

RPG/400 PP ILE RPG PP >E0 Format Position PP Position PP %!!reDiation PP EEplanat &&&&&&&&&&;&&&&&&&&&&&&&;&&&&&&&&&&&&&&&&&&;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 6&14 PP 6&16 PP Filename PP File n 14&16 PP 16&1# PP >G PP >eG1ence checH 16 PP 1) PP 7 PP 71m 1# PP 30 PP C PP Cpt 1)&30 PP 31&33 PP Ri PP Record identif"ing indica 31&34 PP 35&36 PP Pos1 PP Posit 3#&51 PP 51&54 PP Pos3 54&5# PP 5)&45 PP Pos5 34 PP 3# PP 7 PP 53 PP 56 PP 5) PP 44 PP 36 PP 3) PP C PP C 55 PP 56 PP 40 PP 44 PP 36 PP 50 PP C PP Charac

54 41 64&#0

PP PP PP

5# 46 #1&100

PP PP PP

PP

Comme

An Introduction to ILE RPG: Part

Figure " C!anges to I-spec Field La2out 3or Program $escri5

RPG/400 PP ILE RPG PP >E0 Format Position PP Position PP %!!reDiation PP EEplanat &&&&&&&&&&;&&&&&&&&&&&&&;&&&&&&&&&&&&&&&&&&;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 7e2 PP 51&54 PP Fmt PP EEternal date/time for 7e2 PP 54 PP > PP Date/ ime separator charac 45 PP 56 PP P PP EEternal data for 44&46 PP 56&41 PP From PP From posit 4#&41 PP 43&46 PP o PP o posit 43 PP 46&4# PP D PP Decimal positi 45&4# PP 4)&63 PP Field PP Field n 4)&60 PP 65&64 PP L1 PP Control leDel indica 61&63 PP 64&66 PP ?1 PP ?atching record indica 65&64 PP 66&6# PP Fr PP Field record relation indica 64&66 PP 6)&60 PP Pl PP PositiDe field indica 66&6# PP 61&63 PP ?n PP 7egatiDe field indica 6)&60 PP 65&64 PP 'r PP 'ero field indica 64&#0 PP #1&100 PP PP Comme

An Introduction to ILE RPG: Part

Figure

' C-spec *peration E1tender and $ecimal Positions

9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # CL0701703705Factor1;;;CpcdeFactor3;;;Res1ltLenD<<iLoEGComments;;;;;;;:::::: C F+D> REDPE%RPD> 40 C 9I740 IF7E 9C7 C CECC> DI$ D>%? JR% IC 1))< C E7DIF 9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::

CL0701Factor1;;;;;;;Cpcode.E/;Factor3;;;;;;;Res1lt;;;;;;;;Len; ;D;<iLoEG::::Comme C F+D> RE%DPE %RPD> C 9I740 IF7E 9C7 C CECC> DI$.</ D>%? JR% IC 3514 C E7DIF

40

An Introduction to ILE RPG: Part

Figure

( Renamed and E1panded *peration Codes

RPG/400 PP ILE RP &&&&&&&&&&&&&&;&&&&&&&&&&&&&& @I CF PP @I CF C<EFR PP C<ECF CC?I PP CC??I DEF7 PP DEFI7 DELE PP DELE EJCP PP EJCEP LCF0P PP LCCF0 CC0R PP CCC0 REDPE PP RE%DP RE R7 PP RE 0R >ELEC PP >ELEC >E CF PP >E CF 07LCF PP 07LCC 0PD% PP 0PD% L<EE PP L<E7E

An Introduction to ILE RPG: Part

Figure

- C-spec Free-Form E1pressions

9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # CL0701703705Factor1;;;CpcdeFactor3;;;Res1ltLenD<<iLoEGComments;;;;;;;:::::: C CEB = ?0L I?PRIC CECC> < Get eEtended cost 9 C CEB = ?0L I?LG< CELG< Get Item Leight C %DD PFLG< CELG< %dd PacHage Leight 9 C CECC> >0@ CEDI>C JJCC> Get Disco1nted Cost C JJCC> ?0L > %J CE> %J Get >ales aE

9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # ::: ; ::: ) :::;::: 0 CL0701Factor1;;;;;;;Cpcode.E/;EEtended&factor3;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Comme nts;;;;;;;;;;;; C eDal.h/ oecost M oeGt" 9 impric Get eEtended cost

C line item 2eight C as preD ine C taE on disc cost C Incorrect res1lt

eDal eDal eDal eDal

oe2ght M .oeGt" 9 im2ght/ ; pH2ght oe2ght M oeGt" 9 im2ght ; pH2ght oestaE M .oecost & oedisc/ 9 sttaE oestaE M oecost & oedisc 9 sttaE

Get >ame Get

An Introduction to ILE RPG: Part

Figure

. C-spec Continuation

9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # CL0701703705Factor1;;;CpcdeFactor3;;;Res1ltLenD<<iLoEGComments;;;;;;;:::::: C ?>F 1 ?0L E?R% E ?P%= >hift 1 pa" 9 C E?R% E %DD E?PRE3 JR% E >hift3 rate ; premi1m C ?>F 3 ?0L JR% E JL%GE >hift3 2ages C %DD JL%GE ?P%= >hift1;3 pa" 9 C E?R% E %DD E?PRE5 JR% E >hift5 rate ; premi1m C ?>F 5 ?0L JR% E JL%GE >hift5 2ages C %DD JL%GE ?P%= >hift1;3;5 pa"

9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :# ::::;::::) CL0701Factor1;;;;;;;Cpcode.E/;EEtended&factor3;;;;;;;;;;;;;;;;;;;;;;Comments;;; ; C 2ages C 2ages 9 premi1m C 2ages 9 premi1m eDal tmpa" M tmsft1 9 emrate ; .emrate ; empre3/ 9 tmsft3 >hift1 >hift3

incl1ding ; .emrate ; empre5/ 9 tmsft5 >hift5

incl1ding

An Introduction to ILE RPG: Part

Figure

/ Literals Continuation

9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # ::: ;

CL0701Factor1;;;;;;;Cpcode.E/;EEtended&factor3;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Comme C eDal des1 M A7otice the difference !et2een pl1s ; C sign and h"phen contin1ation for ; C literals:A C eDal des3 M A7otice the difference !et2een pl1s & C sign and h"phen contin1ation for literals:A

An Introduction to ILE RPG: Part

Figure

10 C-spec $*6 and 6HE#

9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # CL0701703705Factor1;;;CpcdeFactor3;;;Res1ltLenD<<iLoEGComments;;;;;;;:::::: C = DCLL 40 C I7(J %7D7E9@L%7F> C ?C$E I7(J C0 (= C %DD 1 J C %DD 1 = C E7DDC 9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::

CL0701Factor1;;;;;;;Cpcode.E/;EEtended&factor3;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Comme C do2 " O 40 %7D in.E/ ON A A CL0701Factor1;;;;;;;Cpcode.E/;Factor3;;;;;;;Res1lt;;;;;;;;Len; ;D;<iLoEG::::Comme C moDe in.E/ o1t.E/ C add 1 E C add 1 " C enddo

An Introduction to ILE RPG: Part

Figure

11 Comple1 Logical E1pressions

9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # CL0701703705Factor1;;;CpcdeFactor3;;;Res1ltLenD<<iLoEGComments;;;;;;;:::::: C >ELEC C RCCDE L<EB A%A %dd transaction C ?C$ELA%ddA *%C 7 P C RCCDE L<EB ACA Change transaction C RCCDE CREB ADA Delete transaction C ?C$ELA0pdateA *%C 7 P C C <ER Error transaction C ?C$ELAErrorA *%C 7 P

C 0

E7D>L

9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::::6 :: # :::;::: ) :::;::: CL0701Factor1;;;;;;;Cpcde.E/;EEtended&factor3;;;;;;;;;;;;;;;Comments C select C 2hen trcode M A%A %dd transaction C eDal *actn M A%ddA C 2hen trcode M ACA CR trcode M ADA Change or delete C eDal *actn M A0pdateA transaction C other C eDal *actn M AErrorA Error transaction C endsl

An Introduction to ILE RPG: Part

Figure

12 C-spec IF

9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # CL0701703705Factor1;;;CpcdeFactor3;;;Res1ltLenD<<iLoEGComments;;;;;;;:::::: C CECC> %DD C?@%L JC<ECF %dd order cost to %R C JC<ECF IFG C?CRED !alance: If credit C ?C$E A7A CECF%= limited eEceeded( C E7DIF reKect order 9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::

::: ) :::;::: 0 CL0701Factor1;;;;;;;Cpcode.E/;Factor3;;;;;;;Res1lt;;;;;;;;Len; ;D;<iLoEG::::Comme nts;;;;;;;;;;;; C if oecost ; cm!al N cmcred order cost ; !al C eDal oeoHa" M A7A eEceeds credit limit C endif reKect order:

If

An Introduction to ILE RPG: Part

Figure

C!anges to C-specs

RPG/400 PP ILE RPG PP >E0 Format Position PP Position PP %!!reDiation &&&&&&&&&&;&&&&&&&&&&&&;&&&&&&&&&&&&&&&& ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 6&# PP 6&# PP L0

PP PP

EEplanat Control le

)&16 1#&36 3#&53 55&43 45&4# 4)&41 43 45 44&44 46&46 4#&4) 60&64

PP PP PP PP PP PP PP PP PP PP PP PP PP PP PP

)&11 13&34 36&54 56&4) 40&65 64&6# 6)&60 36&54 61&63 65&64 64&66 56&6) #1&100

PP PP PP PP PP PP PP PP PP PP PP PP PP PP PP

701703705 Factor1 Cpcde Factor3 Res1lt Len D < <i Lo EG Comments

PP PP PP PP PP PP PP PP PP PP PP PP PP PP PP

Conditioning indicat .red1ced to a single indicat Facto Cperation and eEten Facto Res1lt fi Field len Decimal positi Cperation eEten .e:g:( half adK1 <igh/7o record fo1nd indica Lo2/Error indica EG1al/End&of&file indica EEtended facto Comme

An Introduction to ILE RPG: Part

Figure

1" *-spec Program $escri5ed $is7 File

9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # C7ame;;;;DF@%>!>a701703705EEcnam::::::::::::::::::::::::::::::::::::::::::: C%R R%7 E%DD %DD R7 C::::::::::::::::701703705Field;=@End;PConstant/edit2ord;;;;;;;;;:::::::::: C RCCDE 1 C RC0> # C RD% E 16 C R%? 31P 9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # ::: ; CFilename;;DF::701703705EEcnam;;;;@;;%; ;>!;>a;:::::::::::::::::::::::::::::Comme C%R R%7 E%DD %DD R7 C::::::::::::::701703705Field;;;;;;;;;=@:End;;PConstant/edit2ord/D format; ;Comme C RCCDE 1 C RC0> # C RD% E 16D9?D=/ C R%? 31P

An Introduction to ILE RPG: Part

Figure

1' *-spec Program $escri5ed Printer File

9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # C7ame;;;;DF@%>!>a701703705EEcnam::::::::::::::::::::::::::::::::::::::::::: CB>=>PR E 5 PR R7 CB>=>PR E 31 PR R7 C::::::::::::::::701703705Field;=@End;PConstant/edit2ord;;;;;;;;;:::::::::: C RCCDE 1 C RC0> ' 10 C RD% E 30 C R%? 5 53 C 46 A his constant contin1esA C #0 AoDer a n1m!er of linesA C 104 AreG1iring m1ltiple linesA C 114 Aof code:A 9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # ::: ; CFilename;;DF::701703705EEcnam;;;;@;;%; ;>!;>a;:::::::::::::::::::::::::::::Comme CB>=>PR E PR R7 4 3 C::::::::::::::701703705Field;;;;;;;;;=@:End;;PConstant/edit2ord/D format; ;Comme C RCCDE 1 C RC0> ' 10 C RD% E 30 C R%? 5 53 C 115 A his constant contin1es ; C oDer a n1m!er of lines ; 9 Comment lines are permitted 9 in !et2een contin1ation lines: C 1sing the ne2 contin1a& C tion feat1re:

An Introduction to ILE RPG: Part

Figure

1( C!anges to *-specs

RPG/400 PP ILE RPG PP >E0 Format Position PP Position PP %!!reDiation &&&&&&&&&&;&&&&&&&&&&&&;&&&&&&&&&&&&&&&& ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 6&14 PP 6&16 PP 7ame 14 PP 16 PP D to PP PP 16 PP 1# PP F PP PP 16 PP 40&43 PP @ 1# PP 45&44 PP % 1)&30 PP 46&4# PP >! 31&33 PP 4)&41 PP >a 35&51 PP 31&3) PP 701703705 53&56 PP 50&5) PP EEcnam

PP PP PP PP PP PP PP PP PP PP PP PP

EEplanat Filename or Record format n "pe of line .header(detail( or eEce Fetch oDerflo2 or release deD after o1t >pace !efore.0&3 >pace after.0&3 >Hip !ef >Hip af C1tp1t indicat EJCP n

53&56 5# 5) 40&45 44 44&60 64&#0

PP PP PP PP PP PP PP PP

50&45 44 44 46&41 43 45&#0 #1&100

PP PP PP PP PP PP PP PP

Field = @ End P Constant/ edit2ord

PP PP PP PP PP PP PP

Field n Edit c @lanH af Ending posit Field for Constant or edit2 Comme

An Introduction to ILE RPG: Part # Last 'onth +e sa+ 'inor changes to In*ut s*eci%ications (I5s*ecs) and 9ut*ut s*eci%ications (95 s*ecs) necessary to acco''odate 1.5character %ile and %ield na'es, longer %ield lengths, and t+o *ositions %or the nu'ber o% deci'al digits/ We re&ie+ed 'a0or changes to Calculation s*eci%ications (C5s*ecs) including si75character o*eration codes and %ree5%or' arith'etic and logical e7*ressions/ 9ur *rogra's should be easier to code and 'aintain +ith the ability to code co'*le7 logic in a single E:AL, 89W or 89@ calculation continued o&er 'ulti*le lines as necessary/ What no+> We continue our co&erage o% C5s*ecs and 8e%inition s*eci%ications (85 s*ecs) +ith the introduction o% built5in %unctions/ 3hen ne7t 'onth +e1ll loo6 at the ne+ date, ti'e and ti'esta'* data ty*es and arith'etic o*erations/ $uilt5in !unctions CL has su**orted built5in %unctions %or so'e ti'e/ 3hese CL %unctions ser&e as a re%erence *oint that can hel* you understand ILE RPG built5in %unctions/ In CL, R,,3 *er%or's a substring %unction, R$I2 *ro&ides a binary con&ersion, and R,WI3CB tests 0ob s+itches/ ,i'ilar %unctions are a&ailable in ILE RPG/ $uilt5in %unctions in ILE RPG begin +ith a *ercent sign (R) and are %ollo+ed by one or 'ore argu'ents enclosed in *arentheses/ In ILE RPG, 'ulti*le argu'ents are se*arated by a colon (:), consistent +ith other 6ey+ords +e ha&e e7a'ined/ (Why Rochester1s CL is s'art enough to use a blan6 as a deli'iter %or argu'ents +hile 3oronto1s ILE RPG re4uires you to 6ey in a colon re'ains a 'ystery?)

$uilt5in %unctions are su**orted in 85s*ecs in the 6ey+ord entry in *ositions ## to ./ 9nly co'*ile5ti'e &alues can be used %or argu'ents/ :ariables that are co'*uted at run ti'e cannot be used in an argu'ent/ When used in con0unction +ith the 6ey+ords 8IM, 9CC@R,, 9:ERLA< and PERRC8, all argu'ents 'ust be *re&iously de%ined in the *rogra'/ C5s*ecs also su**ort built5in %unctions in the e7tended %actor 2 entry/ !ree5 %or' e7*ressions 'ay be used as the argu'ent o% a built5in %unction and 'ay include other built5in %unctions/ ,o +hat does a built5in %unction really do> Let1s ta6e a loo6 at a co'*arison o% the substring built5in %unction in CL, RPG-#.. and ILE RPG/ R,@$,3 @sed to Retrie&e a ,tring 3he substring built5in %unction in CL can be used to retrie&e or 'odi%y a *ortion o% a character string contained in a CL character &ariable or in the local data area/ Either R,,3 or R,@$,3RI2G can be used in an e7*ression or as the :AR or :AL@E *ara'eter o% the Change :ariable (CBG:AR) co''and/ 3he character &ariable na'e or IL8A, starting *osition and length 'ust be s*eci%ied as argu'ents/ In the CL sa'*le in 1, %our characters are e7tracted %ro' the &ariable S$EG, starting in *osition 2/ 3he &ariable SE28 contains a &alue o% 1$C8E1 i% the &ariable S$EG has the &alue 1A$C8E!1/ $ecause it e7ceeds the nu'ber o% characters in the substring, the &ariable SE28 is auto'atically *added +ith blan6s/ In the CL sa'*le in !igure 1, %our characters are e7tracted %ro' the &ariable S$EG, starting in *osition 2/ 3he &ariable SE28 contains a &alue o% 1$C8E1 i% the &ariable S$EG has the &alue 1A$C8E!1/ $ecause it e7ceeds the nu'ber o% characters in the substring, the &ariable SE28 is auto'atically *added +ith blan6s/ RPG-#.. and ILE RPG su**ort the substring o*eration in C5s*ecs/ 3he character &ariable %ro' +hich a &alue is to be e7tracted is s*eci%ied in %actor 2/ 3he start *osition can o*tionally be s*eci%ied in %actor 2 %ollo+ing the &ariable/ A colon (:) se*arates these t+o ele'ents in %actor 2/ I% not s*eci%ied, the start *osition de%aults to one/ 3he length to be e7tracted can o*tionally be s*eci%ied in %actor 1/ I% not s*eci%ied, it de%aults to the length o% the string %ro' the start *osition/ 3he &ariable to contain the substring is s*eci%ied in the result %ield/ In the RPG-#.. sa'*le in 1, %our characters are e7tracted %ro' the &ariable $EG starting in *osition 2/ 3he &ariable E28 contains the &alue 1$C8E1 i% the &ariable $EG has the &alue 1A$C8E!1/ $ecause the length o% the &ariable E28 is greater than the substring length, the o*eration e7tender P is s*eci%ied to *ad +ith blan6s/ ILE RPG su**orts the ,@$,3 o*eration code +hich is identical in %unction to the RPG-#.. &ersion/ In the RPG-#.. sa'*le in !igure 1, %our characters are e7tracted %ro' the &ariable $EG starting in *osition 2/ 3he &ariable E28 contains the &alue 1$C8E1 i% the &ariable $EG has the &alue 1A$C8E!1/ $ecause the length o% the &ariable E28 is greater than the substring length, the o*eration e7tender P is s*eci%ied to *ad +ith blan6s/ ILE RPG su**orts the ,@$,3 o*eration code +hich is identical in %unction to the RPG-#.. &ersion/ In contrast, the ILE RPG sa'*le in 1 uses the substring built5in %unction and is a close co'*arison to the CL sa'*le/ R,@$,3 is used in ILE RPG instead o% the R,,3 or R,@$,3RI2G used in

CL/ A colon (:) is used to se*arate the &ariable, start *osition and length argu'ents instead o% the blan6 used in CL/ In contrast, the ILE RPG sa'*le in !igure 1 uses the substring built5in %unction and is a close co'*arison to the CL sa'*le/ R,@$,3 is used in ILE RPG instead o% the R,,3 or R,@$,3RI2G used in CL/ A colon (:) is used to se*arate the &ariable, start *osition and length argu'ents instead o% the blan6 used in CL/ E&en though the o*eration e7tender P is not s*eci%ied (and cannot be s*eci%ied +ith the E:AL o*eration code), the &ariable end still has the &alue 1$C8E1/ When used +ith character %ields, the E:AL o*eration %unctions si'ilar to a M9:EL(P)/ When using the substring built5in %unction, the *ad +ith blan6s is i'*lied +ith the E:AL o*eration in ILE RPG as it is +ith the CBG:AR co''and in CL/ R,@$,3 @sed to Modi%y a ,tring While the ,@$,3 o* code has *ro&ed &aluable in RPG-#.., it is li'ited because it only *er'its you to retrie&e a substring, not 'odi%y one/ Although the substring o*eration has the sa'e restriction in ILE RPG, the E:AL o* code allo+s you to o&erco'e the li'itation/ 3he *re&ious e7a'*les o% R,@$,3 +ere used to retrie&e a substring/ Let1s ta6e a loo6 at ho+ to change a substring/ A substring can be 'odi%ied in CL by using the substring built5in %unction in the :AR *ara'eter o% the CBG:AR co''and/ In the CL sa'*le in 2, *art o% the &ariable SM98 (starting in *osition ; and e7tending %or a length o% t+o characters) is re*laced +ith the &alue o% the &ariable SC92/ E&en though the length o% the &ariable SC92 is longer than 2, only the %irst t+o characters are used/ @*on e7ecution o% the CBG:AR, the &alue o% the &ariable SM98 changes to 1:WabM1/ A substring can be 'odi%ied in CL by using the substring built5in %unction in the :AR *ara'eter o% the CBG:AR co''and/ In the CL sa'*le in !igure 2, *art o% the &ariable SM98 (starting in *osition ; and e7tending %or a length o% t+o characters) is re*laced +ith the &alue o% the &ariable SC92/ E&en though the length o% the &ariable SC92 is longer than 2, only the %irst t+o characters are used/ @*on e7ecution o% the CBG:AR, the &alue o% the &ariable SM98 changes to 1:WabM1/ 2 illustrates a si'ilar ca*ability %or ILE RPG/ A substring can be changed in ILE RPG using the E:AL o*eration code +ith the R,@$,3 built5in %unction s*eci%ied on the le%t side o% the e4ual sign (T)/ Identical to the CL sa'*le, the &alue o% the &ariable 'od changes to 1:WabM1/ !igure 2 illustrates a si'ilar ca*ability %or ILE RPG/ A substring can be changed in ILE RPG using the E:AL o*eration code +ith the R,@$,3 built5in %unction s*eci%ied on the le%t side o% the e4ual sign (T)/ Identical to the CL sa'*le, the &alue o% the &ariable 'od changes to 1:WabM1/ 3he second ILE RPG sa'*le in 2 sho+s the use o% the E:AL o*eration code +ith the R,@$,3 built5in %unction s*eci%ied on both sides o% the e4ual sign/ 3his *er'its the &alue o% a substring to be set e4ual to the &alue o% another substring/ 3he third and %ourth characters in the &ariable 'od are re*laced +ith the %ourth and %i%th characters o% the &ariable con/ @*on co'*letion o% the e7ecution o% the E:AL o*eration, the &ariable 'od contains a &alue o% 1:WdeM1/ 3he second ILE RPG sa'*le in !igure 2 sho+s the use o% the E:AL o*eration code +ith the R,@$,3 built5in %unction s*eci%ied on both sides o% the e4ual sign/ 3his *er'its the &alue o% a substring to be set e4ual to the &alue o% another substring/ 3he third and %ourth characters in the

&ariable 'od are re*laced +ith the %ourth and %i%th characters o% the &ariable con/ @*on co'*letion o% the e7ecution o% the E:AL o*eration, the &ariable 'od contains a &alue o% 1:WdeM1/ I% desired, blan6s can be used be5t+een the argu'ents in a built5in %unction to 'a6e the code 'ore readable/ Coding Rsubst('od:;:2) is the sa'e as coding Rsubst('od: ;: 2)/ :ariables can be used %or the start *osition and length as sho+n in the third ILE sa'*le in 2/ 3he results +ill be identical to the *re&ious e7a'*leN i/e/, the &ariable 'od +ill ha&e a &alue o% 1:WdeM1/ :ariables can be used %or the start *osition and length as sho+n in the third ILE sa'*le in !igure 2/ 3he results +ill be identical to the *re&ious e7a'*leN i/e/, the &ariable 'od +ill ha&e a &alue o% 1:WdeM1/ Any &alid e7*ression is *er'itted %or the start *osition and length +hen the R,@$,3 built5in %unction is used as a target as sho+n in the %ourth ILE RPG sa'*le/ Part o% the &ariable 'od (starting in *osition 2 and e7tending %or a length o% three characters) is re*laced +ith the second, third and %ourth characters %ro' the &ariable con/ @*on co'*letion o% the e7ecution o% the E:AL o*eration, the &ariable 'od has a &alue o% 1:bcdM1/ As +e sho+ed last 'onth, an e7*ression can be continued o&er 'ulti*le lines/ Continued lines 'ust be blan6 in *ositions H to ;F/ 2o s*ecial continuation character is re4uired unless a literal is being continued/ Run5ti'e errors can occur +hen using the R,@$,3 built5in %unction i% the start *osition is less than or e4ual to Eero, the length is less than Eero, or a co'bination o% the start *osition and length +ould cause the substring to e7ceed the length o% the %ield in the %irst argu'ent/ When used as a target, the %irst argu'ent o% the R,@$,3 built5in %unction 'ust re%er to a storage location/ In other +ords, it 'ust be a %ield, data structure sub%ield, array na'e, array ele'ent or table ele'ent/ 3he ability to use the R,@$,3 built5in %unction as a target to change a *ortion o% the &alue o% a %ield is a substantial i'*ro&e'ent to ILE RPG/ 3hin6 o% ho+ 'uch code this +ould ta6e in RPG-#.. i% the start *osition and length +ere &ariables &s/ one line o% code in ILE RPG/ 9nce again, nice 0ob I$M? R3RIM ,e&eral built5in %unctions are a&ailable in ILE RPG to tri' blan6s %ro' character &ariables/ R3RIMR tri's trailing blan6s %ro' the right side o% a character &ariable/ R3RIML tri's leading blan6s %ro' the le%t side o% a character &ariable/ R3RIM tri's leading and trailing blan6s %ro' a character &ariable/ As illustrated in ;, the argu'ent o% the R3RIMR, R3RIML and R3RIM built5 in %unctions can s*eci%y a character &ariable or a &alid character e7*ression/ 3he *lus sign (O) used in con0unction +ith character &ariables 'eans concatenation (co'bining), not addition/ As illustrated in !igure ;, the argu'ent o% the R3RIMR, R3RIML and R3RIM built5 in %unctions can s*eci%y a character &ariable or a &alid character e7*ression/ 3he *lus sign (O) used in con0unction +ith character &ariables 'eans concatenation (co'bining), not addition/

,ince the a&ailability o% the CA3 o*eration code, concatenating a %irst na'e +ith a last na'e has been si'*le/ In the RPG-#.. sa'*le in #, the %ield !IR,3 is concatenated +ith the %ield LA,3, +ith one blan6 in bet+een/ 3he co'bined na'e is *laced in the %ield D2AME and *added +ith blan6s/ I% the %ield !IR,3 contains the &alue =Charles= and the %ield LA,3 contains the &alue =Massoglia=, the %ield D2AME +ould contain the &alue =Charles Massoglia=/ ILE RPG su**orts the CA3 o*eration code +hich is identical in %unction to the RPG-#.. &ersionN it also can acco'*lish the concatenation +ith the built5in tri' %unction as sho+n/ ,ince the a&ailability o% the CA3 o*eration code, concatenating a %irst na'e +ith a last na'e has been si'*le/ In the RPG-#.. sa'*le in !igure #, the %ield !IR,3 is concatenated +ith the %ield LA,3, +ith one blan6 in bet+een/ 3he co'bined na'e is *laced in the %ield D2AME and *added +ith blan6s/ I% the %ield !IR,3 contains the &alue =Charles= and the %ield LA,3 contains the &alue =Massoglia=, the %ield D2AME +ould contain the &alue =Charles Massoglia=/ ILE RPG su**orts the CA3 o*eration code +hich is identical in %unction to the RPG-#.. &ersionN it also can acco'*lish the concatenation +ith the built5in tri' %unction as sho+n/ 3he %irst ILE RPG sa'*le in # uses the E:AL o*eration in con0unction +ith an e7*ression containing a built5in %unction/ 3he R3RIMR tri's the trailing blan6s %ro' the right side o% the character &ariable5in this case, the %ield !IR,3/ $ecause the %ield D2AME is a character &ariable, the *lus sign (O) 'eans concatenation/ ,o the %ield !IR,3 +ith the blan6s tri''ed %ro' the right is concatenated +ith a single blan6/ 3he result is concatenated +ith the %ield LA,3/ 3his %irst ILE RPG E:AL sa'*le yields the sa'e results as the RPG-#.. sa'*le/ 3he %irst ILE RPG sa'*le in !igure # uses the E:AL o*eration in con0unction +ith an e7*ression containing a built5in %unction/ 3he R3RIMR tri's the trailing blan6s %ro' the right side o% the character &ariable5in this case, the %ield !IR,3/ $ecause the %ield D2AME is a character &ariable, the *lus sign (O) 'eans concatenation/ ,o the %ield !IR,3 +ith the blan6s tri''ed %ro' the right is concatenated +ith a single blan6/ 3he result is concatenated +ith the %ield LA,3/ 3his %irst ILE RPG E:AL sa'*le yields the sa'e results as the RPG-#.. sa'*le/ $oth the CA3 o*eration and the E:AL o*eration +ith R3RIMR +or6 +ell unless there are any leading blan6s in the %irst or last na'e/ I% the %ield !IR,3 contains the &alue =Charles= and the %ield LA,3 contains the &alue = Massoglia= +ith t+o leading blan6s, the %ield D2AME +ould contain the &alue =Charles Massoglia= +ith three blan6s bet+een =Charles= and =Massoglia=/ 3he second ILE RPG sa'*le in # sol&es this *roble' using the R3RIM built5in %unction +hich causes the blan6s to be tri''ed %ro' both sides o% the s*eci%ied &ariable/ It no+ 'a6es no di%%erence +hether or not the %ields !IR,3 and LA,3 ha&e leading or trailing blan6s/ 3he second ILE RPG sa'*le in !igure # sol&es this *roble' using the R3RIM built5in %unction +hich causes the blan6s to be tri''ed %ro' both sides o% the s*eci%ied &ariable/ It no+ 'a6es no di%%erence +hether or not the %ields !IR,3 and LA,3 ha&e leading or trailing blan6s/ 3he R3RIM built5in %unction in ILE RPG reduces the a'ount o% code re4uired to co'bine t+o or 'ore %ields +hile eli'inating leading and trailing blan6s/ ILE RPG re4uires a single state'ent to *er%or' the sa'e %unction +hich 'ight ha&e been coded as a co'*le7 subroutine or called *rogra' in RPG-#../ Way to go, I$M? RELEM +ith Arrays

When arrays are used in RPG-#.., the nu'ber o% ele'ents and the ele'ent length and deci'al *ositions 'ust be indi&idually coded in E5s*ecs/ 3his 'eans i% you need to change the nu'ber o% ele'ents %or these arrays, you ha&e to 'odi%y 'ulti*le E5s*ecs/ In addition, i% the nu'ber o% ele'ents is s*eci%ied as a literal in %actor 2 o% 89 loo*s in C5s*ecs, these also ha&e to be 'odi%ied/ E&en i% you use a &ariable in %actor 2, you still ha&e to 'odi%y at least one state'ent/ In the RPG-#.. sa'*le in F, the arrays 3931, 3932 and 393; are all de%ined +ith nine ele'ents o% se&en digits +ith t+o deci'al *ositions/ I% you need to increase the nu'ber o% ele'ents to 11, you 'ust 'odi%y all three E5 s*ecs/ In addition, you need to 'odi%y %actor 2 o% all three o% the 89 o*erations in the C5s*ecs/ In the RPG-#.. sa'*le in !igure F, the arrays 3931, 3932 and 393; are all de%ined +ith nine ele'ents o% se&en digits +ith t+o deci'al *ositions/ I% you need to increase the nu'ber o% ele'ents to 11, you 'ust 'odi%y all three E5 s*ecs/ In addition, you need to 'odi%y %actor 2 o% all three o% the 89 o*erations in the C5s*ecs/ 3he ILE RPG sa'*le in F re4uires changing only a single line o% code/ 3he RELEM built5in %unction returns the nu'ber o% ele'ents in an array/ Attributes are coded only %or the array total1 in the 85s*ecs/ 3he LIAE 6ey+ord is used to cause the data ty*e, length and nu'ber o% deci'al *ositions %or the ele'ents in the arrays total2 and total; to be the sa'e as in the array total1/ 3he RELEM built5in %unction is used on the 8IM 6ey+ord to cause the arrays total2 and total; to ha&e the sa'e nu'ber o% di'ensions (ele'ents) as the array total1/ 3he ILE RPG sa'*le in !igure F re4uires changing only a single line o% code/ 3he RELEM built5in %unction returns the nu'ber o% ele'ents in an array/ Attributes are coded only %or the array total1 in the 85s*ecs/ 3he LIAE 6ey+ord is used to cause the data ty*e, length and nu'ber o% deci'al *ositions %or the ele'ents in the arrays total2 and total; to be the sa'e as in the array total1/ 3he RELEM built5in %unction is used on the 8IM 6ey+ord to cause the arrays total2 and total; to ha&e the sa'e nu'ber o% di'ensions (ele'ents) as the array total1/ 3his 'eans i% you need to 'odi%y the nu'ber o% ele'ents %or these arrays, you only need to change the 85s*ec de%ining the array total1/ When you reco'*ile your *rogra', the arrays total2 and total; are auto'atically de%ined the sa'e as the array total1/ 3he nu'eric constant nu'ele' is de%ined as the &alue o% the nu'ber o% ele'ents in the array total1 using the RELEM built5in %unction in 85s*ecs/ Instead o% coding a " in %actor 2 o% the 89 loo*s in C5s*ecs, nu'ele' is coded instead/ 2o+ i% the nu'ber o% ele'ents in the arrays changes, no changes are re4uired to C5s*ecs/ When the *rogra' is reco'*iled, the nu'eric constant nu'ele' auto'atically re%lects the ne+ &alue/ 3he +ay the RELEM built5in %unction +or6s +ith tables is si'ilar to the +ay it is used +ith arrays/ Whene&er identically de%ined arrays or tables are de%ined in ILE RPG, they should be de%ined based u*on the 'ain array or table using the RELEM built5in %unction/ Any ti'e an array is used in a 89 loo* in C5s*ecs, the nu'ber o% ele'ents should also be coded in %actor 2 using the RELEM built5in %unction/ @sing these techni4ues can i'*ro&e *rogra' 'aintainability and reduce debugging ti'e/ RELEM +ith Multi*le 9ccurrence 8ata ,tructures 3he nu'ber o% occurrences o% a 'ulti*le occurrence data structure is coded in I5s*ecs in RPG-#../ When the 'ulti*le occurrence data structure is used in a 89 loo* in C5s*ecs, the nu'ber o%

occurrences is generally coded in %actor 2/ 3his 'eans i% the nu'ber o% occurrences changes, you 'ust change 'ulti*le lines o% code/ In the RPG-#.. sa'*le in G, the 'ulti*le occurrence data structure GL8, is de%ined in I5s*ecs +ith F.. occurrences/ 3he nu'ber F.. is also hard5coded in %actor 2 o% the 89 loo* in C5s*ecs/ $oth s*eci%ications ha&e to be 'odi%ied i% the nu'ber o% occurrences is changed/ In the RPG-#.. sa'*le in !igure G, the 'ulti*le occurrence data structure GL8, is de%ined in I5 s*ecs +ith F.. occurrences/ 3he nu'ber F.. is also hard5coded in %actor 2 o% the 89 loo* in C5 s*ecs/ $oth s*eci%ications ha&e to be 'odi%ied i% the nu'ber o% occurrences is changed/ 3he ILE RPG sa'*le in G re4uires changing only a single line o% code/ 3he RELEM built5in %unction returns the nu'ber o% occurrences in a 'ulti*le occurrence data structure/ 3he 9CC@R, 6ey+ord 'a6es the data structure glds a 'ulti*le occurrence data structure +ith F.. occurrences/ 3he ILE RPG sa'*le in !igure G re4uires changing only a single line o% code/ 3he RELEM built5in %unction returns the nu'ber o% occurrences in a 'ulti*le occurrence data structure/ 3he 9CC@R, 6ey+ord 'a6es the data structure glds a 'ulti*le occurrence data structure +ith F.. occurrences/ 3he nu'eric constant nu'occ is de%ined as the &alue o% the nu'ber o% occurrences in the 'ulti*le occurrence data structure glds using the RELEM built5in %unction in 85s*ecs/ Instead o% coding a F.. in %actor 2 o% the 89 loo* in C5s*ecs, nu'occ is coded instead/ 2o+ i% the nu'ber o% occurrences in the 'ulti*le occurrence data structure changes, the C5s*ecs re4uire no alteration/ When the *rogra' is reco'*iled, the nu'eric constant nu'occ auto'atically re%lects the ne+ &alue/ 3he RELEM built5in %unction can be used any+here a nu'eric constant is &alid +ithin the %unctions colu'n o% the 85s*ecs or the e7tended %actor 2 o% the C5 s*ecs/ R,IME $uilt5in !unction 3he R,IME built5in %unction returns the nu'ber o% bytes o% storage occu*ied by a literal, na'ed constant, data structure, data structure sub%ield, %ield, array or table na'e s*eci%ied as the %irst argu'ent/ When used +ith a character or he7adeci'al literal, R,IME returns the nu'ber o% bytes occu*ied by that literal/ !or nu'eric literals, the nu'ber o% digits including leading and trailing Eeroes is returned/ I% R,IME is used +ith a nu'eric &ariable stored in *ac6ed %or'at, the *ac6ed length is returned (e/g/, a se&en5digit, *ac6ed %ield +ould return a siEe o% # since it ta6e %our bytes to store the nu'ber in *ac6ed %or'at)/ !or binary nu'bers, the binary length (# or 2) is returned/ When the %irst argu'ent o% the R,IME built5in %unction is an array na'e or table na'e, the siEe o% a single ele'ent is returned/ I% a 'ulti*le occurrence data structure is used, the siEe o% a single occurrence is returned/ I% IALL is s*eci%ied as the second argu'ent, the siEe o% all ele'ents or occurrences is returned/ H illustrates so'e e7a'*les o% &alues returned +hen the R,IME built5in %unction is used/ R,IME can be used any+here a nu'eric constant is &alid +ithin the %unctions colu'n o% the 85s*ecs or the e7tended %actor 2 o% the C5s*ecs/

!igure H illustrates so'e e7a'*les o% &alues returned +hen the R,IME built5in %unction is used/ R,IME can be used any+here a nu'eric constant is &alid +ithin the %unctions colu'n o% the 85 s*ecs or the e7tended %actor 2 o% the C5s*ecs/ Pointer ,u**ort <ou 'ay ha&e heard about *ointers, *articularly i% you are a C *rogra''er/ While RPG-#.. does not su**ort *ointers, ILE RPG no+ *ro&ides *ointer su**ort/ 3+o other built5in %unctions +or6 +ith this data ty*e/ RA88R returns a basing *ointer containing the address o% the &ariable s*eci%ied as the argu'ent/ RPA88R returns a *rocedure *ointer containing the return address o% the entry *oint s*eci%ied as the argu'ent/ Pointer su**ort *er'its ILE RPG to easily use a**lication *rogra' inter%aces (APIs) but is an ad&anced to*ic beyond the sco*e o% this article/ !or %urther in%or'ation on *ointers and APIs, *lease consult the ,yste' Progra''er1s Inter%ace Re%erence/ What1s 2e7t> We1&e seen ho+ built5in %unctions can substantially reduce *rogra' de&elo*'ent and 'aintenance ti'e, in so'e cases reducing co'*le7 routines or called *rogra's in RPG-#.. to a single line o% code in ILE RPG/ In our ne7t article, +e +ill tac6le date and ti'e data ty*es including the ne+ date-ti'e arith'etic o*eration codes/ Charlie Massoglia, *resident o% Massoglia 3echnical Consulting, Inc/ in 96e'os, Michigan, has authored a nu'ber o% 'idrange boo6s/ Bis co+boy hat is his trade'ar6 %or his %re4uent s*ea6ing tours throughout the @nited ,tates, Canada, Euro*e, and Australia/ Charlie can be reached at F1H5 GHG5"H../ Re%erence ,yste' Progra''er1s Inter%ace Re%erence (,C215 22;, C85R9M J$AA #.2)/
An Introduction to ILE RPG: Part $

Figure 1 %&'(&) 'sed to Retrie*e a &tring


DCL DCL C<G$%R $%R.Q@EG/ =PE.9C<%R/ LE7.6/ $%L0E.A%@CDEFA/ $%R.QE7D/ =PE.9C<%R/ LE7.#/ $%L0E.AJJJJJJJJA/ $%R.QE7D/ $%L0E.R>> .Q@EG 3 4// /9 QE7D M A@CDE

9/

9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # CL0701703705Factor1;;;CpcdeFactor3;;;Res1ltLenD<<iLoEGComments;;;;;;;:::::: C ?C$E A%@CDEFA @EG 6 C ?C$E AJJJJJJJJAE7D # C 4 >0@> @EGI3 E7D P E7D M A@CDE A 9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 0 CL0701Factor1;;;;;;;Cpcode.E/;Factor3;;;;;;;Res1lt;;;;;;;;Len; ;D;<iLoEG::::Comm

ents;;;;;;;;;;;; C C preD defined C 2/!lanH implied

eDal eDal eDal

!eg M A%@CDEFA end M AJJJJJJJJA end M Rs1!st.!egI3I4/

end Pad

An Introduction to ILE RPG: Part "

Figure

8S)9S, )sed to &odi32 a String

DCL DCL C<G$%R

$%R.Q?CD/ =PE.9C<%R/ LE7.4/ $%L0E.A$LJ='A/ $%R.QCC7/ =PE.9C<%R/ LE7.4/ $%L0E.Aa!cdeA/ $%R.R>> .Q?CD 5 3// $%L0E.QCC7/ /9 Q?CD M A$La!'A 9/

9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 0 D7ame;;;;;;;;;;;E DsFrom;;; o/L;; ;IDc:F1nctions::::::::::::::::::::::::::::Comm ents;;;;;;;;;;;; D mod > 4 I7'.A$LJ='A/ D con > 4 I7'.Aa!cdeA/ D start1 > 4 0 I7'.5/ D length > 4 0 I7'.3/ D start3 > 4 0 I7'.4/ CL0701Factor1;;;;;;;Cpcode.E/;EEtended& factor3;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Comments;;;;;;;;;;;; C eDal Rs1!st.modI5I3/ M con M A$La!'A C M A$Lde'A C same as preDio1s C M A$Lde'A C modI3I5 conI3I5 C M A$!cd'A eDal eDal Rs1!st.modI 5I 3/ M Rs1!st.conI 4I 3/ Rs1!st.modI start1I length/ M Rs1!st.conI start3I length/ eDal Rs1!st.modI start1&1I length;1/ M Rs1!st.conI start3/3I length;1/ mod mod

mod mod

An Introduction to ILE RPG: Part "

Figure

8,rim Function E1amples

F1nction Rtriml Rtrimr Rtrim Rtriml Rtrimr Rtrim Rtriml Rtrimr Rtrim Rtriml Rtrimr Rtrim A A A

$al1e

Res1lt A ACharlie ?assoglia A A A Charlie ?assogliaA A ACharlie ?assogliaA

Charlie ?assoglia Charlie ?assoglia Charlie ?assoglia AsameA AsameA AsameA

AsameA AsameA AsameA

A a! A ; A cd A Aa! cd A A a! A ; A cd A A a! cdA A a! A ; A cd A Aa!cdA A A A A A A AA AA AA

An Introduction to ILE RPG: Part "

Figure

"

8,RI& Function

9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # CL0701703705Factor1;;;CpcdeFactor3;;;Res1ltLenD<<iLoEGComments;;;;;;;:::::: C FIR> C% L%> I1 J7%?E P Com!ine first Q last 9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 0 CL0701Factor1;;;;;;;Cpcode.E/;Factor3;;;;;;;Res1lt;;;;;;;;Len; ;D;<iLoEG::::Comm ents;;;;;;;;;;;; C eDal J7%?E M R RI?R.FIR> / ; A A ; L%> Com!ine first/last C rim !lanHs eDal J7%?E M R RI?.FIR> / ; A A ; R RI?.L%> /

An Introduction to ILE RPG: Part "

Figure

'

8ELE& Function :it! Arra2s

9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # E::::Fromfile ofile;;7ame;;7/r7/t!LenPD>%rrnamLenPD>Comments::::::::::::::: E C 1 ) 6 3 E C 3 ) 6 3 E C 5 ) 6 3

CL0701703705Factor1;;;CpcdeFactor3;;;Res1ltLenD<<iLoEGComments;;;;;;;:::::: C 9LIFE DEF7 C 1 C0 C DC ) J 40 C ?C$E C 1(J C0 C EJCP PRI7 1 C E7DDC C DC ) J 40 C ?C$E C 3(J C0 C EJCP PRI7 1 C E7DDC C DC ) J 40 C ?C$E C 5(J C0 C EJCP PRI7 1 C E7DDC 9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 0 D7ame;;;;;;;;;;;E DsFrom;;; o/L;;;IDc:F1nctions;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Comm ents;;;;;;;;;;;; D total1 > 6 3 dim.)/ D total3 > liHe.total1/ dim.Relem.total1// D total5 > liHe.total1/ dim.Relem.total1// D o1t > liHe.total1/ D n1melem C const.Relem.total1// M ) D E > 4 0 CL0701Factor1;;;;;;;Cpcode.E/;Factor3;;;;;;;Res1lt;;;;;;;;Len; ;D;<iLoEG::::Comm ents;;;;;;;;;;;; C do n1melem E C moDe tot1.E/ o1t C eEcept print1 C enddo C do n1melem E C moDe tot3.E/ o1t C eEcept print1 C enddo C do n1melem E C moDe tot5.E/ o1t C eEcept print1 C enddo

An Introduction to ILE RPG: Part "

Figure ( Struc

8ELE& Function :it! &ultiple *ccurrence $ata

9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # IDsname::::7CDsEEt&file;;::::::::::::::CccrLen;:::::::::::::::::::::::::::: IGLD> D> 400 I::::::::::::EEt&field;::::::::::::::PFrom o;;DField;:::::::::::::::::::::: I 1 ) GL70? I 10 1#3GL%?

CL0701703705Factor1;;;CpcdeFactor3;;;Res1ltLenD<<iLoEGComments;;;;;;;:::::: C DC 400 J 40 C J CC0R GLD> C EJCP PRI7 C E7DDC 9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 0 D7ame;;;;;;;;;;;E DsFrom;;; o/L;;;IDc:F1nctions;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Comm ents;;;;;;;;;;;; D glds D> occ1rs.400/ D gln1m ) D glamt ) 3 D n1mocc C const.Relem.glds// M 400 D E > 4 0 CL0701Factor1;;;;;;;Cpcode.E/;Factor3;;;;;;;Res1lt;;;;;;;;Len; ;D;<iLoEG::::Comm ents;;;;;;;;;;;; C do n1mocc E C E occ1r glds C eEcept print C enddo

An Introduction to ILE RPG: Part "

Figure

8SI;E Function

9: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 0 D7ame;;;;;;;;;;;E DsFrom;;; o/L;;;IDc:F1nctions;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Comm ents;;;;;;;;;;;; D pacHn1m > 15P 4 D !inn1m > )@ 0 D signn1m > 14> 0 D charDar > 40% D pacHarr > 4P 0 DI?.10/ D signarr > 4> 0 DI?.10/ D chararr > 11 DI?.4/ D m1ltoccds D> # CCC0R>.30/ D charcon C Aa!cdefghA D n1mcon C 400 D si8e-of-ds C const.Rsi8e.m1ltoccdsI9all// M 160 CL0701Factor1;;;;;;;Cpcode.E/;EEtended& factor3;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Comments;;;;;;;;;;;; C eDal n1m M Rsi8e.&004:00/ C eDal n1m M Rsi8e.004:00/ C eDal n1m M Rsi8e.ACharlie ?assogliaA/

16

M 4 M 4 M

C 31 C .pacHed length/ C .!inar" length/ C C C .single element/ C .2hole arra"/ C .single element/ C .2hole arra"/ C 11 44 .single element/ C .2hole arra"/ C .single occ1r/ C 160 .all occ1r/ C C

eDal eDal eDal eDal eDal eDal eDal eDal eDal eDal eDal eDal eDal eDal eDal

n1m M Rsi8e.A

Charlie ?assoglia

A/

M M 6 M 4 M M M 5 M M 4 M M M M # M M # M 5

n1m M Rsi8e.pacHn1m/ n1m M Rsi8e.!inn1m/ n1m M Rsi8e.signn1m/ n1m M Rsi8e.charDar/ n1m M Rsi8e.pacHarr/ n1m M Rsi8e.pacHarrI 9all/ n1m M Rsi8e.signarr/ n1m M Rsi8e.signarrI 9all/ n1m M Rsi8e.chararr/ n1m M Rsi8e.chararrI 9all/ n1m M Rsi8e.m1ltoccds/ n1m M Rsi8e.m1ltoccdsI 9all/ n1m M Rsi8e.charcon/ n1m M Rsi8e.n1mcon/

14 40

50

40

An Introduction to ILE RPG: Part F $rie%: In our %inal install'ent o% this introductory ILE RPG series, +e e7a'ine the su**ort %or date data ty*es/ ILE RPG can de%ine date, ti'e and ti'esta'* %ields corres*onding +ith the 88, su**ort %or these data ty*es/ It also *ro&ides su**ort %or date arith'etic, con&ersion %ro' one date ty*e to another, and con&ersion to and %ro' nu'eric and character %ields/ Last 'onth +e sa+ the introduction o% built5in %unctions, +hich can substantially reduce *rogra' de&elo*'ent and 'aintenance ti'e, in so'e cases reducing co'*le7 routines or called *rogra's in RPG-#.. to a single line o% code in ILE RPG/ In this article, +e loo6 at one o% the 'ost e7citing %eatures o% ILE RPG5 su**ort %or date data ty*es/ 8ate data ty*es ha&e been a&ailable on the A,-#.. since :2R2N but because they cannot be directly *rocessed in RPG-#.., their use%ulness has been li'ited/ ILE RPG *ro&ides %ull su**ort %or date data ty*es and date arith'etic/ 3his su**ort 'a6es it easy to calculate the di%%erence bet+een t+o dates or to incre'ent a date by a nu'ber o% days, ta6ing into account the &arying nu'ber o% days in each 'onth/ !or e7a'*le, 1""2 is a lea* year/ I% you add ;. days to Lanuary ;1, 1""2, ILE RPG correctly calculates the result as March 1, 1""2N i% you add ;. days to Lanuary ;1, 1"";, the result is March 2, 1"";/

3he =8ate, 3i'e and 3i'esta'* 8ata 3y*es= sidebar (*age 1..) co&ers the *ossible %or'ats %or date %ields in 9,-#../ Within ILE RPG, you can de%ine %ields or constants as date (8), ti'e (3) or ti'esta'* (M) data ty*es/ !or the rest o% this article, +e1ll re%er to such %ields generically as date %ields unless an e7a'*le s*eci%ically a**lies to ti'e or ti'esta'* %ields/ 3he length o% a date %ield is deter'ined by the data ty*e and the date %or'at5it should not be coded as *art o% the de%inition/ 3he de%ault %or'at %or date %ields in an ILE RPG *rogra' can be s*eci%ied in the Beader s*eci%ication (B5s*ec) using the 8A3!M3 and 3IM!M3 6ey+ords/ (!or 'ore in%or'ation on B5 s*ec 6ey+ords, see =An Introduction to ILE: Part 1,= MC, March 1""#/) I% these 6ey+ords are not used, the de%ault %or'at is International ,tandards 9rganiEation (II,9) %or'at/ 8ate !ield 8e%initions 1 sho+s sa'*les o% de%ining date and ti'e %ields +ith initialiEed &alues/ ,ince no B5s*ec e7ists in the *rogra', date %ields that do not include a 8A3!M3 or 3IM!M3 6ey+ord de%ault to II,9 %or'atN and the II,9 %or'at 'ust be used to initialiEe all date %ields regardless o% their %or'at/ !igure 1 sho+s sa'*les o% de%ining date and ti'e %ields +ith initialiEed &alues/ ,ince no B5s*ec e7ists in the *rogra', date %ields that do not include a 8A3!M3 or 3IM!M3 6ey+ord de%ault to II,9 %or'atN and the II,9 %or'at 'ust be used to initialiEe all date %ields regardless o% their %or'at/ In the %irst e7a'*le in 1, the 8 in *osition #. de%ines the %ield eurCdate as a date %ield/ ,ince IE@R is s*eci%ied %or the 8A3!M3 6ey+ord, the date is internally re*resented in I$M Euro*ean ,tandard %or'at (i/e/, dd/''/yyyy) and is auto'atically de%ined as 1. characters in length/ 3he I2M *ara'eter initialiEes the %ield to 1G/12/1""# (8ece'ber 1G, 1""#)/ E&en though the %ield eurCdate is de%ined as a IE@R %or'at date %ield, the &alue on the I2M *ara'eter 'ust be in II,9 %or'at (i/e/, 1""#51251G)/ ,e&eral other e7a'*les o% date %ield de%initions are included in 1/ In the %irst e7a'*le in !igure 1, the 8 in *osition #. de%ines the %ield eurCdate as a date %ield/ ,ince IE@R is s*eci%ied %or the 8A3!M3 6ey+ord, the date is internally re*resented in I$M Euro*ean ,tandard %or'at (i/e/, dd/''/yyyy) and is auto'atically de%ined as 1. characters in length/ 3he I2M *ara'eter initialiEes the %ield to 1G/12/1""# (8ece'ber 1G, 1""#)/ E&en though the %ield eurCdate is de%ined as a IE@R %or'at date %ield, the &alue on the I2M *ara'eter 'ust be in II,9 %or'at (i/e/, 1""#51251G)/ ,e&eral other e7a'*les o% date %ield de%initions are included in !igure 1/ 3he 3 in *osition #. de%ines the %ield h'sCti'e as a ti'e %ield/ ,ince IBM, is s*eci%ied %or the 3IM!M3 6ey+ord, the ti'e is internally re*resented in Bours:Minutes:,econds %or'at (i/e/, hh/''/ss)/ 3he I2M *ara'eter initialiEes the %ield to ;. seconds a%ter G:.G */'/ In a si'ilar 'anner, the %ield usaCti'e is de%ined as a I@,A %or'at ti'e %ield +ith an i'*lied length o% eight/ While the internal %or'at o% this %ield is hh:'' AM or hh:'' PM, the &alue on the I2M *ara'eter 'ust be in II,9 %or'at (i/e/, hh/''/ss)/ Literals cannot be s*eci%ied in a date %or'at di%%erent %ro' the de%ault %or the *rogra'/ 3here%ore, the &alue %or all date and ti'e literals 'ust be re*resented in the %or'at s*eci%ied in the B5s*ec or II,9 %or'at i% no %or'at is s*eci%ied/ 8ate literals should be *re%i7ed by 8, 3 and M %or date, ti'e and ti'esta'* &alues/ @sing the II,9 %or'at, 811""#51251G1 de%ines a date literal +ith a length o% 1. and a &alue o% 8ece'ber 1G, 1""#/ 311 /.G/;.1 de%ines a ti'e literal +ith a length o% eight and a &alue o% ;. seconds a%ter G:.G */'/ M11""#51251G51 /.G/;.1 de%ines a ti'esta'* literal +ith a length o% 2G and a &alue o% ;. seconds a%ter G:.G */'/ on 8ece'ber 1G, 1""#/ (I% the 'icroseconds *ortion o% a ti'esta'* literal is not s*eci%ied, it de%aults to 1......1 and its length re'ains 2G)/

2 sho+s another sa'*le o% de%ining date and ti'e %ields +ith initialiEed &alues/ In this sa'*le, a 8A3!M3 o% I@,A and 3IM!M3 o% IBM, are s*eci%ied on the B5s*ec/ !igure 2 sho+s another sa'*le o% de%ining date and ti'e %ields +ith initialiEed &alues/ In this sa'*le, a 8A3!M3 o% I@,A and 3IM!M3 o% IBM, are s*eci%ied on the B5s*ec/ As in the *rior sa'*le, the %ield eurCdate is de%ined as a 1.5character, IE@R5 %or'at (dd/''/yyyy) date %ield/ $ut this ti'e the initialiEation &alue 'ust be *ro&ided in I@,A %or'at (''-dd-yyyy) because o% the 8A3!M3 6ey+ord s*eci%ied in the B5s*ec/ When the LIAE 6ey+ord is used, the 8A3!M3 and 3IM!M3 6ey+ords are not allo+ed/ 3he %ield eurCdate2 is de%ined as a 1.5character, IE@R5%or'at (dd/''/yyyy) date %ield that ta6es its %or'at (but not its &alue) %ro' the %ield eurCdate/ 3he %ield usaCdate is de%ined as an eight5character, I@,A5%or'at date %ield +ith a %or'at o% I@,AS/ 3he a'*ersand (S) changes the de%ault se*arator character %ro' a slash (-) to a blan6/ 3he &alue o% the %ield usaCdate +ill be 12 1G 1""#, +hile the &alue o% the %ield usaCdate2 +ill be 12-1G-1""#/ 8e%ault :alues We1&e already sho+n ho+ date %ields can be initialiEed to a s*eci%ic &alue using the I2M 6ey+ord in the 85s*ecs/ <ou can also initialiEe a date %ield using the CLEAR o*eration code in the C5s*ecs/ 3he de%ault initialiEation and CLEAR &alue is not all Eeros, as 'ight be e7*ected/ !or date %ields, the de%ault &alue is Lanuary 1, ...1N %or ti'e %ields, the de%ault &alue is 'idnightN and %or ti'esta'* %ields, the de%ault &alue is 'idnight on Lanuary 1, ...1/ In all cases, the %or'at includes se*arator characters and is based on the 8A3!M3 and 3IM!M3 *ara'eters or the de%ault II,9 %or'at/ I% the 8A3!M3 and 3IM!M3 6ey+ords are not s*eci%ied in either the B5s*ec or the 85s*ec, the cleared &alue o% a date %ield is ...15.15.1N the cleared &alue o% a ti'e %ield is ../../..N and the cleared &alue o% a ti'esta'* %ield is ...15.15.15 ../../../....../ 3he &alue set by IL9:AL is the sa'e as the CLEAR &alue/ 3he &alue set by IBI:AL is 8ece'ber ;1, """" %or a date %ield, one second be%ore 'idnight (2;/F"/F") %or a ti'e %ield, and one 'icrosecond be%ore 'idnight on 8ece'ber ;1, """" %or a ti'esta'* %ield (""""5125;15 2;/F"/F"/"""""")/ Co'*aring 8ate !ields 8ate data ty*es can be used in %actor 1 and %actor 2 %or 'any ILE RPG o*eration codes/ As +ith other ty*es o% %ields, you can co'*are date %ields only i% they ha&e the sa'e data ty*e5date, ti'e or ti'esta'*/ ILE RPG +ill auto'atically handle di%%erent %or'ats5an II,95%or'at ti'e %ield +ith a &alue o% 1F/;./.. +ill co'*are e4ual to a I@,A5%or'at ti'e %ield +ith a &alue o% .;:;. PM/ In the sa'e res*ect, a IM8<5%or'at date %ield +ith a &alue o% 12-1G-"# +ill co'*are e4ual to a I<M85 %or'at date %ield +ith a &alue o% "#-12-1G/ 8ate Arith'etic Arith'etic o*erations are +here the ne+ date data ty*es really shine/ Many RPG-#.. *rogra's use a co'*le7 subroutine that accounts %or lea* years and the &arying nu'ber o% days in each 'onth to calculate the di%%erence bet+een t+o dates or to incre'ent a date by a s*eci%ic nu'ber o% days/ <ou can get the sa'e results +ith 'uch less e%%ort using date %ields and se&eral ne+ o*eration codes/

3he Add 8uration (A888@R) o*eration code can be used to add a duration to a date, ti'e or ti'esta'* %ield, resulting in a %ield o% the sa'e ty*e/ !actor 1 is o*tional and, i% not s*eci%ied, de%aults to the result %ield/ !actor 1 and the result %ield 'ust be the sa'e data ty*e/ !actor 2 is re4uired and contains t+o *arts se*arated by a colon (:)/ 3he %irst *art 'ust be a nu'eric %ield, array ele'ent or constant +ith Eero deci'al *ositions/ 3he second *art is a code indicating the ty*e o% duration/ 3he duration code 'ust be &alid %or the data ty*e o% the %ield s*eci%ied in the result %ield/ !or e7a'*le, you cannot add a 'inute duration to a date ty*e %ield/ 3he &alid duration codes are I<EAR, or I<N IM923B, or IMN I8A<, or I8N IB9@R, or IBN IMI2@3E, or IM2N I,EC928, or I,N and IM,EC928, or IM,/ An error indicator can be s*eci%ied in the less5than colu'ns (H;5H#)/ 3he &alue o% the result %ield re'ains unchanged and this indicator is set on i%: o 3he date, ti'e or ti'esta'* %ield in %actor 1 contains in&alid data/ o !actor 1 is not s*eci%ied and the date, ti'e or ti'esta'* %ield in the result %ield contains in&alid data/ o 3he result o% the o*eration is in&alid/ ; sho+s so'e sa'*les o% using the A888@R o*eration code/ ,ince no B5s*ec is *resent, all date and ti'e &alues are s*eci%ied in II,9 %or'at/ !igure ; sho+s so'e sa'*les o% using the A888@R o*eration code/ ,ince no B5s*ec is *resent, all date and ti'e &alues are s*eci%ied in II,9 %or'at/ 3he %irst C5s*ec adds ;. days to the %ield startCdate and stores the result in the %ield endCdate/ $oth startCdate and endCdate are de%ined as date %ields +ith an II,9 %or'at and an i'*lied length o% 1./ ,ince the %ield startCdate is initialiEed to 1""#51251G, the %ield endCdate +ill ha&e a &alue o% 1""F5 .151F a%ter e7ecution o% the A888@R o*eration code/ I% an error occurs, indicator F. +ill be turned on/ Indicator F. +ill be turned o%% i% no error occurs/ In the second sa'*le in ;, one 'onth is being added to the I@,A %or'at date %ield 'onthCend/ 3he %ield 'onthCend is initialiEed to a &alue o% 1.-;1-1""# in 85s*ecs/ Adding one 'onth to the 'onth *ortion o% this date +ould result in an in&alid date o% 11-;1-1""#N but the result o% the A888@R o*eration is auto'atically ad0usted to the last &alid day o% the 'onth/ 3he %ield 'onthCend +ill ha&e the &alue 11-;.-1""# a%ter e7ecution o% the A888@R o*eration code/ In the second sa'*le in !igure ;, one 'onth is being added to the I@,A %or'at date %ield 'onthCend/ 3he %ield 'onthCend is initialiEed to a &alue o% 1.-;1-1""# in 85s*ecs/ Adding one 'onth to the 'onth *ortion o% this date +ould result in an in&alid date o% 11-;1-1""#N but the result o% the A888@R o*eration is auto'atically ad0usted to the last &alid day o% the 'onth/ 3he %ield 'onthCend +ill ha&e the &alue 11-;.-1""# a%ter e7ecution o% the A888@R o*eration code/ In the ne7t e7a'*le, one year is added to the %ield e'*loyCdat and the result is stored in the %ield anni&Cdat/ 3he %ield e'*loyCdat is initialiEed to a &alue o% .2-2"-1""2 in 85s*ecs/ Adding one year to this date +ithout any ad0ust'ent +ould result in an in&alid date o% .2-2"-1""; since 1""; is not a lea* yearN but the result o% the A888@R o*eration is again auto'atically ad0usted to the last &alid day o% the 'onth/ 3he %ield anni&Cdat +ill ha&e the &alue .2-2 -1""; a%ter e7ecution o% the A888@R o*eration code/

3he ne7t sa'*le de'onstrates the use o% the A888@R o*eration code +ith ti'e %ields/ 3he %irst calculation adds three hours to the literal in %actor 1, +hich is set to 'idnight/ 3he ti'e constant is e7*ressed in II,9 %or'at using a *eriod (/) as a se*arator character e&en though the result %ield endCti'e is de%ined in IBM, %or'at using a colon (:) as a se*arator character/ 3he ne7t t+o lines o% code add 22 'inutes and F. seconds to endCti'e, gi&ing a result o% .;:22:F./ 3he ,ubtract 8uration (,@$8@R) o*eration code %ollo+s the sa'e rules as A888@R to subtract durations %ro' date %ields/ 3he result %ield is re4uired and 'ust be the sa'e data ty*e as %actor 1 i% %actor 1 is s*eci%ied/ ,e&eral e7a'*les are sho+n in #/ 3he ,ubtract 8uration (,@$8@R) o*eration code %ollo+s the sa'e rules as A888@R to subtract durations %ro' date %ields/ 3he result %ield is re4uired and 'ust be the sa'e data ty*e as %actor 1 i% %actor 1 is s*eci%ied/ ,e&eral e7a'*les are sho+n in !igure #/ 3he ,@$8@R o*eration can also be used to calculate the duration (or di%%erence) bet+een: o 3+o dates/ o A date and a ti'esta'*/ o 3+o ti'es/ o A ti'e and a ti'esta'*/ o 3+o ti'esta'*s/ When calculating a duration, both %actor 1 and %actor 2 'ust be s*eci%ied and 'ust contain the sa'e or co'*atible data ty*es/ A date and a ti'esta'* are co'*atible as are a ti'e and a ti'esta'*/ Bo+e&er, ILE RPG +ill handle any con&ersion bet+een date or ti'e %or'ats (i/e/, a I@,A date subtracted %ro' a II,9 date)/ 3he result %ield is also re4uired and contains t+o *arts/ 3he %irst 'ust be a nu'eric %ield, array ele'ent or constant +ith Eero deci'al *ositions in +hich the result +ill be *laced/ 3he second is se*arated %ro' the %irst by a colon (:) and 'ust be a &alid duration code indicating the ty*e o% duration/ 3he result +ill be negati&e i% the date or ti'e in %actor 1 is earlier than the date or ti'e in %actor 2/ # sho+s so'e sa'*les o% using the ,@$8@R o*eration code/ ,ince 8A3!M3(I@,A) is s*eci%ied on the B5s*ec, all date literals 'ust be *ro&ided in I@,A %or'at/ $ecause 3IM!M3(IBM,) is also s*eci%ied, all ti'e literals 'ust be *ro&ided in IBM, %or'at/ !igure # sho+s so'e sa'*les o% using the ,@$8@R o*eration code/ ,ince 8A3!M3(I@,A) is s*eci%ied on the B5s*ec, all date literals 'ust be *ro&ided in I@,A %or'at/ $ecause 3IM!M3(IBM,) is also s*eci%ied, all ti'e literals 'ust be *ro&ided in IBM, %or'at/ 3he %irst three e7a'*les are &ery si'ilar to the e7a'*les %or A888@R in the *re&ious section/ A duration is subtracted %ro' a date, resulting in a ne+ dateN i% necessary, ILE RPG auto'atically ad0usts the result to a &alid date, ta6ing into account lea* year and the nu'ber o% days in each 'onth/ 3he %ourth sa'*le de'onstrates the use o% the ,@$8@R o*eration code +ith ti'esta'* %ields to deter'ine the di%%erence bet+een t+o ti'esta'* &alues/ 3he %ield startCti'e is de%ined as a ti'esta'* %ield +ith a &alue o% 1""#5.F5125 .2/F"/#., and the %ield endCti'e is de%ined as a ti'esta'* %ield +ith a &alue o% 1""#5.F5125.;/22/F./ Micro5seconds de%ault to all Eeros/ ,ince the duration code I,EC, is s*eci%ied on the result %ield, the %ield nu'Csec +ill ha&e a &alue o% 1,;". seconds a%ter e7ecution o% the ,@$8@R o*eration code/ In the last sa'*le, the date %ield loanCdate, +hich has a &alue o% 12-1G-1"";, is subtracted %ro' the date %ield dueCdate, +hich has a &alue o% 12-1G-2.. / ,ince the duration code IM ('onths) is s*eci%ied on the result %ield, the %ield nu'C'on +ill ha&e a &alue o% 1 . 'onths/

ED3RC3 9*eration Code 3he E7tract (ED3RC3) o*eration code can be used to e7tract a *ortion o% a date %ield/ !actor 1 'ust be blan6/ !actor 2 is re4uired and contains t+o *arts se*arated by a colon (:)/ 3he %irst *art 'ust be a date, ti'e or ti'esta'* %ield/ 3he second *art 'ust be a duration code that is &alid %or the data ty*e o% the %ield s*eci%ied in the %irst *art o% %actor 2/ !or e7a'*le, you can e7tract hours %ro' a ti'e or ti'esta'* %ield but not %ro' a date %ield/ 3he result %ield 'ay be a nu'eric or character %ield/ $e%ore the ED3RC3 o*eration is e7ecuted, the result %ield is cleared/ 2u'eric result %ields are right50usti%ied +hile character result %ields are le%t5 0usti%ied/ 3he %irst three sa'*les in F e7tract in%or'ation %ro' the %ield dueCdate +hich is de%ined as an II,9 %or'at date %ield and initialiEed to 2.. 51251G/ 3he 'onth is e7tracted into the character %ield charC'onth +ith a result o% 1121/ 3he day is e7tracted into the character %ield charCday +ith a result o% 11G1/ 3he year is e7tracted into the nu'eric %ield nu'Cyear +ith a result o% 1""#/ 3he %irst three sa'*les in !igure F e7tract in%or'ation %ro' the %ield dueCdate +hich is de%ined as an II,9 %or'at date %ield and initialiEed to 2.. 51251G/ 3he 'onth is e7tracted into the character %ield charC'onth +ith a result o% 1121/ 3he day is e7tracted into the character %ield charCday +ith a result o% 11G1/ 3he year is e7tracted into the nu'eric %ield nu'Cyear +ith a result o% 1""#/ 3he second grou* o% e7a'*les uses the %ield startCti'e, +hich is de%ined as a ti'esta'* %ield and initialiEed to a &alue o% 1""#51.5225.2/F"/#./ 3he 'onth is e7tracted into the character %ield charC'onth +ith a result o% 11.1, and the hour is e7tracted into the nu'eric %ield nu'Chour +ith a result o% 2/ Con&erting 8ate !or'ats 3he M9:E and M9:EL o*eration codes can be used to con&ert date, ti'e and ti'esta'* %ields %ro' one data ty*e or %or'at to another/ 3he &alid con&ersions are: o 8ate to date, ti'esta'*, character or nu'eric/ o 3i'e to ti'e, ti'esta'*, character or nu'eric/ o 3i'esta'* to date, ti'e, character or nu'eric/ o Character or nu'eric to date, ti'e or ti'esta'*/ <ou can use the Mo&e Array (M9:EA) o*eration code only to 'o&e date data ty*e %ields to a characterty*e %ield, array or array ele'ent/ As +ith any 'o&e o*eration, +hen you use one o% the M9:E o*eration codes to con&ert %ro' one data ty*e to another, the &alue in %actor 2 +ill be 'o&ed to the result %ield/ !actor 1 is o*tional and is used to s*eci%y the %or'at o% %actor 2, +hen %actor 2 is not a date data ty*e/ Alternati&ely, %actor 1 can be used to s*eci%y the %or'at o% the result %ield +hen the result %ield is not a date data ty*e/ All o% the date %or'ats are &alid and, in addition, IL9$R@2 can be used to indicate that the date %or'at &alues %ro' the 0ob should be used/ I% %actor 1 is not s*eci%ied, then the 8A3!M3 and 3IM!M3 &alues in the B5s*ec are used i% s*eci%iedN other+ise, II,9 %or'at is assu'ed/ !actor 1 'ust be blan6 i% both %actor 2 and the result %ield are date data ty*es/ In this case, ILE RPG +ill auto'atically con&ert %ro' one date %or'at to another/ When a M9:E o*eration code is used to con&ert a character %ield to a date ty*e %ield, the character %ield 'ust include the se*arators re4uired by the %or'at s*eci%ied in %actor 1/ Con&ersely, +hen a

date %ield is 'o&ed to a character %ield, the character %ield +ill contain se*arators based u*on the %or'at s*eci%ied in %actor 1/ ,e*arators are not *er'itted +hen 'o&ing a nu'eric %ield to a date %ield, nor are they inserted +hen 'o&ing a date %ield to a nu'eric %ield/ G sho+s so'e sa'*les o% con&erting dates using the M9:E o*eration code/ In the %irst sa'*le, the %ield startCnu' is de%ined as a Eoned deci'al %ield in +hich +e are storing a date in <<MM88 %or'at ("#121G)/ We +ant to add ;. days to the &alue in startCnu'/ In RPG-#.., this re4uires a subroutine that accounts %or lea* years and the nu'ber o% days in each 'onthN but, as G illustrates, it is a si'*le *rocess in ILE RPG/ !igure G sho+s so'e sa'*les o% con&erting dates using the M9:E o*eration code/ In the %irst sa'*le, the %ield startCnu' is de%ined as a Eoned deci'al %ield in +hich +e are storing a date in <<MM88 %or'at ("#121G)/ We +ant to add ;. days to the &alue in startCnu'/ In RPG-#.., this re4uires a subroutine that accounts %or lea* years and the nu'ber o% days in each 'onthN but, as !igure G illustrates, it is a si'*le *rocess in ILE RPG/ !irst, +e use the M9:E o*eration code to con&ert the Eoned deci'al %ield startCnu' to the II,9 date startCdate/ !actor 1 indicates the %ield startCnu' is in I<M8 %or'at (e/g/, <<MM88)/ 3hen all +e ha&e to do is use the A888@R o*eration code to add ;. days to startCdate and M9:E the II,9 date %ield startCdate bac6 to the Eoned deci'al %ield startCnu'/ Again, %actor 1 indicates the %ield startCnu' is to be %or'atted in I<M8 %or'at/ 3he %ield startCnu' +ill ha&e the &alue "F.11F/ In the ne7t sa'*le, the 'o&e o*eration code is used to con&ert a date %ro' I@,A to IE@R %or'at/ 3he %ield usaCdate is de%ined as a I@,A5%or'at %ield +ith a &alue o% .#-1G-1"1G/ 3he %ield eurCdate is de%ined as a IE@R5%or'at %ield/ Mo&ing the %ield usaCdate to the %ield eurCdate +ill result in eurCdate ha&ing the &alue 1G/.#/1"1G/ 3he %inal sa'*le de'onstrates a *otentially serious *roble' %or those +ho store their dates in MM88<<, 88MM<< or <<MM88 %or'at/ 8ates in these %or'ats 'ust be in the range o% 1"#. to 2.;"/ Atte'*ting to 'o&e a &alue outside o% this range to this %or'at date +ill result in a run5 ti'e error/ ,ince the I@,A5%or'at date usaCdate has a &alue o% .#-1G-1"1G, +hich is be%ore 1"#., atte'*ting to 'o&e this date to the I<M85%or'at date y'dCdate +ill cause a run5ti'e error/ Many *eo*le store their dates in *ac6ed deci'al %ields in C<<MM88 %or'at +here C re*resents the century (e/g/, ."#121G re*resents 12-1G-1""# and 1"#121G re*resents 12-1G-2."#)/ IC<M8 is not currently su**orted as a con&ert5%ro' or con&ert5to date %or'at/ 3his is one o% the 'ost serious de%iciencies in the ILE RPG language de%inition/ Bo*e%ully, I$M 3oronto +ill recogniEe the 'a0or *roble's this +ill cause/ Bo*e%ully, this su**ort +ill be added to ILE RPG be%ore general a&ailability o% :;R1M. or, +orst case, be 'ade a&ailable in the ne7t release (or &ersion>)/ ,u''ary In this series o% articles, +e1&e only had ti'e to ta6e a loo6 at so'e o% the enhance'ents I$M has 'ade to RPG in :;R1M./ !or e7a'*le, +e ha&en1t co&ered bound *rogra' callsN CLEAR and RE,E3 o*eration code enhance'entsN date, ti'e and ti'esta'* built5in %unctionsN and 'uch 'ore/ <et, +e ha&e seen that ILE RPG has introduced 'any radical changes to the RPG language de%inition:

o 2u'erous 'odi%ications +ere re4uired to handle the change %ro' G5 to 1.5 character sy'bolic na'es/ o Aey+ord notation has not only %reed u* s*ace to acco''odate longer %ields in !5s*ecs, it has also 'ade the coding o% B5s*ecs and !5s*ecs 'uch easier %or us and 'uch easier %or I$M to enhance in the %uture/ o E5s*ecs ha&e been eli'inated +ith array and table de%inition 'o&ed to 85 s*ecs/ 2a'ed constant and data structure de%inition has been 'o&ed %ro' I5s*ecs to 85s*ecs/ o 3he ne+ 85s*ecs *er'it us to consolidate our data de%initions in a single *lace in our *rogra's/ ,ubstantial *roducti&ity gains should result %ro' the introduction o% the 9:ERLA< and PRE!ID 6ey+ords and the ability to use length notation in data structures/ o Ma0or changes to C5s*ecs include si75character o*eration codes and %ree5%or' arith'etic and logical e7*ressions/ 9ur *rogra's should be easier to code and 'aintain +ith the ability to code co'*le7 logic in a single E:AL, I!, WBE2, 89W or 89@ calculation continued o&er 'ulti*le lines as necessary/ o $uilt5in %unctions can substantially reduce *rogra' de&elo*'ent and 'aintenance ti'e, in so'e cases reducing co'*le7 routines or called *rogra's in RPG-#.. to a single line o% code in ILE RPG/ o 3he introduction o% date, ti'e and ti'esta'* data ty*es +ill %inally let us easily address the year 2.../ 3he A888@R and ,@$8@R o*eration codes +ill enable us to re*lace entire subroutines or sub*rogra's +ith a single line o% code/ ILE RPG is not the sa'e old RPG/ It o%%ers the ho*e o% 'a6ing RPG a &iable language into the t+enty5%irst century/ Charlie Massoglia, *resident o% Massoglia 3echnical Consulting, Inc/ in 96e'os, Michigan, has authored a nu'ber o% 'idrange boo6s/ Bis co+boy hat is his trade'ar6 %or his %re4uent s*ea6ing tours throughout the @nited ,tates, Canada, Euro*e and Australia/ Charlie can be reached at F1H5 GHG5"H../ 8ate, 3i'e and 3i'esta'* 8ata 3y*es 88, has su**orted date, ti'e and ti'esta'* data ty*es %or so'e ti'e/ $ecause these data ty*es are not directly su**orted in RPG-#.., they ha&e been o% little *ractical &alue %or RPG *rogra''ers/ ILE RPG is about to change that/ A1 sho+s the eight date %or'ats currently su**orted %or date %ields/ 3he date %or'at controls the order and length o% the 'onth, day and year/ In addition, the date %or'at s*eci%ies the de%ault se*arator character o% slash (-), hy*hen (5) or *eriod (/)/ 3he year can be re*resented in t+o5byte (yy) and %our5byte (yyyy) character %or'at/ 3he day o% 'onth (dd) is re*resented in t+o5 byte %or'at, +hile Lulian day (ddd) is re*resented in three5byte %or'at/ 3he 'onth ('') is al+ays re*resented in t+o5byte %or'at/ !igure A1 sho+s the eight date %or'ats currently su**orted %or date %ields/ 3he date %or'at controls the order and length o% the 'onth, day and year/ In addition, the date %or'at s*eci%ies the de%ault se*arator character o% slash (-), hy*hen (5) or *eriod (/)/ 3he year can be re*resented in t+o5byte (yy) and %our5byte (yyyy) character %or'at/ 3he day o% 'onth (dd) is re*resented in t+o5 byte

%or'at, +hile Lulian day (ddd) is re*resented in three5byte %or'at/ 3he 'onth ('') is al+ays re*resented in t+o5byte %or'at/ 3he e7ternal length is the nu'ber o% bytes o% storage re4uired to store the date %ield on dis6 +ithout the se*arator characters/ All date %ields, regardless o% date %or'at, re4uire %our bytes o% storage/ 3he internal length is the nu'ber o% bytes o% storage re4uired to re*resent the date in a *rogra', on a screen or in a re*ort including the se*arator characters/ 8ate %ields re4uire bet+een si7 and ten characters o% storage %or internal re*resentation, de*ending u*on the date %or'at s*eci%ied/ Leading Eeros are re4uired %or all date %or'ats e7ce*t I@,A/ ILE RPG su**orts %i&e ti'e %or'ats, as sho+n in A2/ 3he ti'e %or'at designates +hether 125 or 2#5hour %or'at is used and +hether seconds are sho+n/ In addition, the ti'e %or'at s*eci%ies the de%ault se*arator character o% colon (:) or *eriod (/)/ Bours (hh) and 'inutes ('') are re*resented in t+o5byte %or'at/ Either the seconds (ss) are re*resented in t+o5byte %or'at %or 2#5hour ti'e, or AM or PM is re*resented in t+o5byte %or'at %or 125hour ti'e/ ILE RPG su**orts %i&e ti'e %or'ats, as sho+n in !igure A2/ 3he ti'e %or'at designates +hether 125 or 2#5hour %or'at is used and +hether seconds are sho+n/ In addition, the ti'e %or'at s*eci%ies the de%ault se*arator character o% colon (:) or *eriod (/)/ Bours (hh) and 'inutes ('') are re*resented in t+o5byte %or'at/ Either the seconds (ss) are re*resented in t+o5byte %or'at %or 2#5 hour ti'e, or AM or PM is re*resented in t+o5byte %or'at %or 125hour ti'e/ 3he e7ternal length o% a ti'e %ield is al+ays three bytes/ 3i'e %ields al+ays re4uire eight bytes %or internal re*resentation regardless o% the ti'e %or'at s*eci%ied/ Leading Eeros are re4uired %or all ti'e %or'ats e7ce*t I@,A/ !ields +ith a ti'esta'* data ty*e al+ays ha&e the sa'e %or'at as sho+n in A;/ <ear (yyyy) is al+ays %our bytes, %ollo+ed by 'onth (''), day (dd), hours (hh), 'inutes ('') and seconds (ss) +hich are al+ays t+o bytes/ Microseconds (uuuuuu) is last +ith si7 bytes/ 3he se*arator characters are al+ays a co'bination o% hy*hens (5) %or the date and *eriods (/) %or the ti'e/ !ields +ith a ti'esta'* data ty*e al+ays ha&e the sa'e %or'at as sho+n in !igure A;/ <ear (yyyy) is al+ays %our bytes, %ollo+ed by 'onth (''), day (dd), hours (hh), 'inutes ('') and seconds (ss) +hich are al+ays t+o bytes/ Microseconds (uuuuuu) is last +ith si7 bytes/ 3he se*arator characters are al+ays a co'bination o% hy*hens (5) %or the date and *eriods (/) %or the ti'e/ 3he e7ternal length o% a ti'e5sta'* %ield is al+ays 1. bytes/ 3i'esta'* %ields al+ays re4uire 2G bytes %or internal re*resentation/ I% 'icroseconds is not s*eci%ied +hen a ti'esta'* &alue is used in ILE RPG, the co'*iler *ads the &alue +ith Eeros/
An Introduction to ILE RPG: Part +

Figure 1 De,ining Date and )ime Fie"ds -ith Initia"i.ed /a"


Format 9:: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 10

<F1nctions;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Comm ents;;;;;;;;;;;; < D7ame;;;;;;;;;;;E DsFrom;;; o/L;; ;IDc:F1nctions::::::::::::::::::::::::::::Comm ents;;;;;;;;;;;; D e1r-date > D D% F? .9E0R/ I7'.DA1))4&13&16A/ 16:13:1))4 D 1sa-date > D D% F? .90>%/ I7'.DA1))4&13&16A/ 13/16/1))4 D iso-date > D I7'.DA1))4&13&16A/ 1))4&13&16 D hms-time 1#I06I50 D 1sa-time 6I06 P? D iso-time 1#:06:50 > > > I?F? .9<?>/ I7'. A1#:06:50A/ I?F? .90>%/ I7'. A1#:06:50A/ I7'. A1#:06:50A/

An Introduction to ILE RPG: Part '

Figure <al

$e3ining $ate and ,ime Fields :it! Initiali4ed

9<?> Format 9:: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 10 <F1nctions;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Comm ents;;;;;;;;;;;; < D% F? .90>%/ I?F? .9<?>/ D7ame;;;;;;;;;;;E DsFrom;;; o/L;; ;IDc:F1nctions::::::::::::::::::::::::::::Comm ents;;;;;;;;;;;; D e1r-date > D D% F? .9E0R/ I7'.DA13/16/1))4A/ 16:13:1))4 D e1r-date3 > LIFE.e1r-date/ I7'.DA04/1#/1))4A/ 1#:04:1))4 D 1sa-date > D D% F? .90>%Q/ I7'.DA13/16/1))4A/ 16 1))4 D 1sa-date3 > D I7'.DA13/16/1))4A/ 13/16/1))4 D iso-date > D D% F? .9I>C/ I7'.DA13/16/1))4A/ 1))4&13&16 D 1sa-time 6I06 P? D hms-time 1#I06I50 D iso-time > > > I?F? .90>%/ I7'. A1#I06I50A/ I7'. A1#I06I50A/ I?F? .9I>C/ I7'. A1#I06I50A/

13

1#:06:50

An Introduction to ILE RPG: Part '

Figure

A$$$)R-Add $uration *peration Code

9:: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 10 D7ame;;;;;;;;;;;E DsFrom;;; o/L;; ;IDc:F1nctions::::::::::::::::::::::::::::Comm ents;;;;;;;;;;;; D start-date > D D% F? .9I>C/ I7'.DA1))4&13&16A/ D end-date > D D% F? .9I>C/ D month-end > D D% F? .90>%/ I7'.DA1))4&10&51A/ D emplo"-dat > D D% F? .90>%/ I7'.DA1))3&03&3)A/ D anniD-dat > D D% F? .90>%/ D end-time > I?F? .9<?>/ D total-time > ' CL0701Factor1;;;;;;;Cpcode.E/;Factor3;;;;;;;Res1lt;;;;;;;;Len; ;D;<iLoEG::::Comm ents;;;;;;;;;;;;; 9 9 %dd 50 da"s to date 9 C start-date addd1r 50I9da"s end-date 9 9 %dd 1 month to date 9 C addd1r 1I9months month-end 9 9 %dd 1 "ear to date 9 C emplo"-dat addd1r 1I9"ears anniD-dat 9 9 %dd 5 ho1rs( 33 min1tes and 40 seconds to midnight 9 C A00:00:00A addd1r 5I9ho1rs end-time C addd1r 33I9min end-time C addd1r 40I9seconds end-time 9 9 %dd 1000 microseconds to a timestamp 9 C addd1r 1000I9ms total-time

40

An Introduction to ILE RPG: Part '

Figure

"

S)9$)R-Su5tract $uration *peration Code

9:: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: #

:::;::: ) :::;::: 10 <F1nctions;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Comm ents;;;;;;;;;;;; < D% F? .90>%/ I?F? .9<?>/ D7ame;;;;;;;;;;;E DsFrom;;; o/L;; ;IDc:F1nctions::::::::::::::::::::::::::::Comm ents;;;;;;;;;;;; D start-date > D D% F? .9I>C/ D end-date > D D% F? .9I>C/ I7'.DA01/04/1))4A/ D month-end > D D% F? .90>%/ I7'.DA10/51/1))4A/ D emplo"-dat > D D% F? .90>%/ D anniD-dat > D D% F? .90>%/ I7'.DA03/3)/1))3A/ D start-time > ' I7'.'A1))4&04&13&03:4):40A/ D end-time > ' I7'.'A1))4&04&13&05:33:40A/ D loan-date > D I7'.DA13/16/1))5A/ D d1e-date > D I7'.DA13/16/300#A/ CL0701Factor1;;;;;;;Cpcode.E/;Factor3;;;;;;;Res1lt;;;;;;;;Len; ;D;<iLoEG::::Comm ents;;;;;;;;;;;;; 9 9 >1!tract 50 da"s from date 9 C end-date s1!d1r 50I9da"s start-date 9 9 >1!tract 1 month from date 9 C s1!d1r 1I9months month-end 9 9 >1!tract 1 "ear from date 9 C anniD-date s1!d1r 1I9"ears emplo"-dat 9 9 Calc1late n1m!er of seconds !et2een start and stop timestamps 9 C end-time s1!d1r start-time n1m-secI9secs 6 0 9 9 Calc1late n1m!er of da"s !et2een dates 9 CL0701Factor1;;;;;;;Cpcode.E/;Factor3;;;;;;;Res1lt;;;;;;;;Len; ;D;<iLoEG::::Comm ents;;;;;;;;;;;;; C d1e-date s1!d1r loan-date n1m-monI9m 5 0

40

An Introduction to ILE RPG: Part '

Figure

'

E+,RC,-E1tract *peration Code

9:: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 10 D7ame;;;;;;;;;;;E DsFrom;;; o/L;; ;IDc:F1nctions::::::::::::::::::::::::::::Comm ents;;;;;;;;;;;; D d1e-date > D I7'.DA300#&13&16A/

D start-time

>

'

I7'.'A1))4&10&33&03:4):40A/

CL0701Factor1;;;;;;;Cpcode.E/;Factor3;;;;;;;Res1lt;;;;;;;;Len; ;D;<iLoEG::::Comm ents;;;;;;;;;;;;; 9 9 EEtract month( da" and "ear 9 C eEtrct d1e-dateI9m char-month 3 C eEtrct d1e-dateI9d char-da" 3 C eEtrct d1e-dateI9" n1m-"ear 4 0 9 9 EEtract month and ho1rs 9 C eEtrct start-timeI9m char-month C eEtrct start-timeI9h n1m-ho1r 3 0

An Introduction to ILE RPG: Part '

Figure

&*<E :it! $ates% ,imes and ,imestamps

9:: 1 :::;::: 3 :::;::: 5 :::;::: 4 :::;::: 4 :::;::: 6 :::;::: 6 :::;::: # :::;::: ) :::;::: 10 9 7o <&spec so dates and times defa1lt to 9I>C format: D7ame;;;;;;;;;;;E DsFrom;;; o/L;; ;IDc:F1nctions::::::::::::::::::::::::::::Comm ents;;;;;;;;;;;; D start-n1m > 6> 0 I7'.)41316/ D start-date > D D% F? .9I>C/ D 1sa-date > D D% F? .90>%/ I7'.DA1)16&04&16A/ 04/16/1)16 D e1r-date > D D% F? .9E0R/ D "md-date > D D% F? .9=?D/ CL0701Factor1;;;;;;;Cpcode.E/;Factor3;;;;;;;Res1lt;;;;;;;;Len; ;D;<iLoEG::::Comm ents;;;;;;;;;;;;; 9 9 %dd 50 da"s to date stored as a n1m!er in ==??DD format 9 C 9=?D moDe start-n1m start-date start-dateM1))4&13&16 C addd1r 50I9da"s start-date start-dateM1))4&01&14 C 9=?D moDe start-date start-n1m start-n1mM)40114 9 9 ConDert a date from 90>% to 9E0R format 9 C moDe 1sa-date e1r-date e1r-dateM16:04:1)16 9 9 Cannot conDert a date !efore 1)40 or after 305) to 9=?D format 9 C moDe 1sa-date "md-date

r1n

time error

An Introduction to ILE RPG: Part '

Figure

A1

$ate Formats and $e3ault Separators

Date Format Parameter 9?D= 9D?= 9=?D 9S0L 9I>C 90>% 9E0R 9SI>

Date Format Description

Internal and >eparator

EEternal Length Length 4 4 4 10 10 10 10 13/16/)4 16/13/)4 )4/13/16 4 4 4 4

EEample

?onth/Da"/=ear mm/dd/"" # Da"/?onth/=ear dd/mm/"" # =ear/?onth/Da" ""/mm/dd # S1lian ""/ddd 6 4 )4/540 International >tandards """"&mm&dd Crgani8ation I@? 0>% >tandard mm/dd/"""" I@? E1ropean >tandard dd:mm:"""" Sapanese Ind1strial """"&mm&dd >tandard Christian Era

1))4&13&16 13/16/1))4 16:13:1))4 1))4&13&16

An Introduction to ILE RPG: Part '

Figure

A2

,ime Formats and $e3ault Separators

ime Format Parameter 9<?> 9I>C 90>% 9E0R 9SI>

ime Format Description

Internal and >eparator

EEternal Length Length # # # # # 5 5 5 5 5

EEample 1#I06I50 1#:06:50 6I06 P? 1#:06:50 1#I06I50

<o1rsI?in1tesI>econds hhImmIss International >tandards hh:mm:ss Crgani8ation I@? 0>% >tandard hhImm %? or hhImm P? I@? E1ropean >tandard hh:mm:ss Sapanese Ind1strial hhImmIss >tandard Christian Era

An Introduction to ILE RPG: Part '

Figure

,imestamp Format and Separator C!aracters

Format

Internal Length Length

EEternal EEample

""""&mm&dd&hh:mm:ss:111111

36

10

1))4&13&16:1#:06:50:000001

Вам также может понравиться