rpg iv at v5r1 big changes in rpg land! - partner400 ... ?· rpg iv at v5r1 big changes in rpg...

Download RPG IV at V5R1 Big Changes in RPG Land! - Partner400 ... ?· RPG IV at V5R1 Big Changes in RPG Land!…

Post on 23-Jul-2018




0 download

Embed Size (px)


  • Your Partner in AS/400 and iSeries Education

    RPG IV at V5R1

    Big Changes in RPG Land!

    Jon Paris jon.paris @ partner400.comwww.Partner400.com

    OCEAN Technical ConferenceCatch the Wave

    If you thought that RPGIV had changed over the years well "You ain't seen nothin' yet!!"

    The latest release of the language brings:Tighter integration with JavaAny number of new Built-In FunctionsA completely new and greatly improved method of error handlingAnd to top it all - completely free-format RPG IV calc specs!

    The author, Jon Paris, is co-founder of Partner400, a firm specializing in customized education and mentoring services for AS/400 and iSeries developers. Jon's career in IT spans 30+ years including a 10 year period with IBM's Toronto Laboratory. Jon now devotes his time to educating developers on techniques and technologies to extend and modernize their applications and development environments.

    Together with his partner, Susan Gantner, Jon authors regular technical articles for the IBM publication, eServer Magazine, iSeries edition, and the companion electronic newsletter, iSeries EXTRA. You may view articles in current and past issues and/or subscribe to the free newsletter at: eservercomputing.com/iseries.

    Feel free to contact the authors at: Jon.Paris @ Partner400.com and Susan.Gantner @ Partner400.com

    (c) 2002 by Partner400 RPG IV - V5R1 Features - Page - 1-2

  • Agenda

    New Built-Ins Error CheckingJava EnablementFree Form Calcs Run-Time File OpenOther Enhancements

    In this unit, we will study the very significant features added to RPG IV in Version 5, Release 1. Some of these features will dramatically change the way RPG programs are written in the future.

    We suggest you read the article entitled "New Language? No, It's RPG IV" by Hans Boldt and Barbara Morris in IBM Rochester's iSeries Magazine, the May 2001 issue. You can review the article on the web at:


    Take the link for Previous Issues and select May 2001. Then link to the article. It provides insight into the importance of some of these new features from the perspective of the primary RPG IV compiler developers.

    In case you are interested, you can also find articles written by Jon Paris and Susan Gantner at this same web site. In particular you might find those in the February, March and July 2001 issues of interest as they discuss programming for the web in RPG.

    (c) 2002 by Partner400 RPG IV - V5R1 Features - Page - 3-4

  • Date Durations in Expressions!%DIFF( Date1 : Date2 : DurationType )

    Calculates a duration between date, time or timestamp valuesThat is, it replaces that function of SUBDUR

    Other duration calculations are performed by simple + and - operatorsIn conjunction with new duration Built-Ins

    More on this in the next chart

    Duration types are as per ADDDUR/SUBDURThat is *MS, *S, *MN, *H, *D, *M, *Y

    And the long-winded versions *MSECONDS, *SECONDS, *MINUTES, etc.

    * Is the loan due within the next 6 months ?C DueDate SUBDUR Today MonthsToRun:*MC IF MonthsToRun < 6

    C IF %Diff(DueDate : Today : *M ) < 6New version

    Hurray! Finally date duration support in expressions! This is a feature that RPG IV programmers have been wanting since V3R1. Most RPG IV programmers much prefer using the free-form type operation codes, but the powerful date duration operations still required the fixed format to use ADDDUR and SUBDUR.

    The code example here illustrates the ability to replace the ADDDUR and SUBDUR operation codes we saw in the Dates unit earlier with expressions using either %DIFF or a simple arithmetic add (+) operation in combination with the duration BIF (%Years, in this example).

    Most RPG IV programmers quickly became addicted to the free form operation codes (e.g., EVAL, IF, etc.) and were dismayed to discover that in order to use the powerful date duration support built in to RPG IV from the beginning, they were forced to revert to the Factor 1, Factor 2, etc. format.

    On the next chart, we will show how to also replace the requirement for a MOVE operation code to get numeric data to a date or time field.

    Now, all date data type operations can be done with free form operation codes. The significance of this will be even greater when we look at the new "completely" free-format C specs later in this unit.

    (c) 2002 by Partner400 RPG IV - V5R1 Features - Page - 5-6

  • Other Duration FunctionsAdding a duration to a date, time or timestamp

    This function can now be performed by simple additionThe duration is supplied via the appropriate BIF

    e.g. %MINUTES, %HOURS, %DAYS, %MONTHS, %YEARS, etc.

    Multiple durations can be handled in a single statement

    Subtracting a duration is similari.e. It is achieved through the use of simple subtraction

    * These original duration calculationsC ContractDate AddDur Cyears:*Y ExpiryDateC ExpiryDate AddDur CMonths:*M ExpiryDateC ExpiryDate AddDur 1:*D ExpiryDate

    C ExpiryDate SubDur 90:*D WarningDate

    * Can be replaced by these calculations using the new duration BIFs C Eval ExpiryDate = ContractDate +%Years(CYears)C +%Months(CMonths) +%Days(1)

    C Eval WarningDate = ExpiryDate - %Days(90)

    The new duration calculations on the previous chart were taken from the program below. It demonstrates the use of the duration BIFs and displays the results of the calculations.

    D ContractDate S D Inz(D'2000-03-30') D ExpiryDate S D D WarningDate S D

    D CMonths S 3P 0 Inz(6) D CYears S 3P 0 Inz(1)

    C Eval ExpiryDate = ContractDate +%Years(CYears) C +%Months(CMonths) +%Days(1)

    C ExpiryDate Dsply

    C Eval WarningDate = ExpiryDate - %Days(90)

    C WarningDate Dsply

    C Eval *InLr = *On

    (c) 2002 by Partner400 RPG IV - V5R1 Features - Page - 7-8

  • %Date - Convert to Date%Date( { expression { : date format } } )

    Converts a character or numeric field to a datei.e. It performs the same function as a MOVE to a date

    Second parameter specifies the format of the source fieldAlso works with TimestampsIf first parameter is omitted then the system date is returned

    D CharDate1 S 6A Inz('011549')D CharDate2 S 6A Inz('031954')

    D ISODate S D DatFmt(*ISO)D USADate S D DatFmt(*USA)

    * Loading a date field from a character field prior to V5R1C *MDY0 MOVE CharDate ISODateC *MDY0 MOVE CharDate USADate

    * The equivalent code in V5R1C EVAL ISODate = %Date(CharDate1: *MDY0)C EVAL USADate = %Date(CharDate2: *MDY0)

    The %DATE, %TIME and %TIMESTAMP BIFs are used to remove the requirement for a MOVE or MOVEL operation to convert data from character or numeric fields to date/time/timestamp fields. Much like %CHAR will format date data into a character field, %DATE will do the reverse for character fields. The second (format) parameter specifies the format of the data being converted (the data in the first parameter). If the format is not specified, the default format for the program is used. If you recall from the Dates and Times unit, the default format for the program is the format specified with DATFMT (or TIMFMT for time fields) on the H spec or, if not specified on an H spec, it will be *ISO.

    Note that the format of the date (or time) returned will always be *ISO.

    You may specify either *DATE or UDATE as the first parameter to get the job date into a date field. And you may omit the parameters altogether to retrieve the current system date (or time) - much like the TIME operation code.

    Note the difference between job date and system date (*DATE or UDATE vs. %Date with no parameters). Also note that initializing a date field to *SYS using the D spec keyword only sets the INITIAL value for the field. So if a program runs over midnight, the initialized value in a date field defined with INZ(*SYS) will be different from that returned by %DATE without parameters.

    (c) 2002 by Partner400 RPG IV - V5R1 Features - Page - 9-10

  • * Determine if payment is more than 90 days overdue - prior to V5R1

    C *MDY0 MOVE DueDate WorkDate C TIME Today

    C Today SubDur WorkDate Temp:*DC If Temp > 90C : ...... : ..............................C EndIf

    * And the same calculation in V5R1C If %Diff(%Date(): %Date(DueDate: *MDY0) C : *Days) > 90C : ...... : ..............................C EndIf

    Combining %Diff with %DateThe power of the new BIFs comes when combining them

    In the example below it has significantly reduced the amount of codeIn fact the difference is even greater than shown since in the new version there is no need to define the work fields Temp, Today and WorkDate

    Returns the system date

    In this example, you can see how m


View more >