Presentation is loading. Please wait.

Presentation is loading. Please wait.

RPG IV V5R1 Enhancements Presented by Barry Diehl.

Similar presentations


Presentation on theme: "RPG IV V5R1 Enhancements Presented by Barry Diehl."— Presentation transcript:

1 RPG IV V5R1 Enhancements Presented by Barry Diehl

2 At a Glance Built-In Functions (BIFs) Free-format Runtime Control of Files and Members Improved Error Control Increased Java support Miscellaneous Changes

3 How did it happen? George Farr of IBM Toronto surveys users giving them a list of possible enhancements. Each enhancement is priced Survey participants can spend $100

4 What didnt make it? Multiple dimension arrays Keylists in D specs More H-Spec Keywords Bitwise operations in expressions

5 Built-In Functions

6 Taking time %TIME{(expression{:time-format})} %TIMESTAMP{(expression{:*ISO|*ISO0})} %DATE{(expression{:date-format})} If no value specified, current system values are retrieved When the expression is *DATE, UDATE or a timestamp, dont use the format - the system knows the format

7 One More Time %SECONDS(number) %MINUTES(number) %HOURS(number) %DAYS(number) %MONTHS(number) %YEARS(number) Determine date in 3 years newdate = date + %YEARS(3) Determine date 6 months ago loandate = date - %MONTHS(6)

8 Whats the Difference? %DIFF(op1:op2:*MS|*S|*MN|*H|*D|*M|*Y) Determine the number of days between 2 dates NumDays = %Diff(LoanDate:DueDate:*D) Add number of minutes between the start and end TotalTime = TotalTime + %Diff(StartTime:EndTime:*MN)

9 Parts Is Parts Extract a subset of a date, time or timestamp with %SUBDT %SUBDT(value:*MS|*S|*MN|*H|*D|*M|*Y) date = d1999-02-17; time = t01.23.45; num = %SubDt(date:*Y); // num = 1999 num = %SubDt(time:*MN); // num = 23

10 A Well-Defined Search %LOOKUPxx(arg:array{:startindex{:numelems}}) - returns array index of the element in array that matches Where xx = – blank an exact match – LT value closest to arg, but less than arg – LE an exact match or the value closest to arg, but less than arg – GT value closest to arg, but greater than arg – GE an exact match or the value closest to arg, but greater than arg Zero is returned if no match found %Found and %Equal dont work on this function Use %TLOOKUPxx for tables

11 Other Functions %ALLOC and %REALLOC %CHECK and %CHECKR %XLATE %SHTDN %SQRT

12 Free-Format RPG

13 Free-format Rules /FREE and /END-FREE Write code between columns 8 and 80 General form: opcode(extenders) Factor 1 Factor 2 Result Statements end with semi-colon End-of-line comments marked with // Compiler directives can be used Cant define fields or have result indicators Free and fixed can be mixed

14 Function Replacements ADDDUR %YEARS, %MONTHS ALLOC %ALLOC CHECK %CHECK CHECKR %CHECKR EXTRCT %SUBDT LOOKUP %LOOKUPxx, %TLOOKUPxx MVR %REM OCCUR %OCCUR REALLOC %REALLOC

15 Function Replacements SCAN %SCAN SHTDN %SHTDN SQRT %SQRT SUBDUR %DIFF or minus sign SUBST %SUBST TIME %DATE, %TIME, %TIMESTAMP XFOOT %XFOOT XLATE %XLATE

16 Operator Replacement ADD + CAT + DIV / MULT * SUB -

17 Generalize ANDxx AND DOUxx DOU DOWxx DOW IFxx IF ORxx OR WHENxx WHEN

18 Social Engineering - Obsolete BITOFF use MOVE BITON use MOVE CABxx CAS and ENDCS COMP GOTO MHHZO MHLZO MLHZO MLLZO TAG

19 Social Engineering – Moving to New CALL and CALLB CALLP DEFINE D spec – use LIKE or DTAARA keywords DO FOR END need to qualify the type now MOVE EVALR or built-in functions MOVEA MOVEL EVAL or built-in functions PARM and PLIST use prototype definition SETOFF and SETON EVAL TESTN and TESTZ Z-ADD and Z-SUB

20 Free-Form Details KLIST and KFLD not included EVAL is optional Debug works fine Most examples in Reference are free-form Macro in CODE/400 performs one-way conversion Mix of Free and Fixed-formats is ok Compiler directives ok - but no SQL

21 Fixed-format (page 1)

22 Free-format (page 1)

23 Fixed-format (page 2)

24 Free-format (page 2)

25 Fixed-format (page 3)

26 Free-format (page 3)

27 Fixed-format (page 4)

28 Free-format (page 4)

29 Runtime Control of Files and Members

30 Use EXTFILE(file name) and EXTMBR(member name) as keywords in F Spec Need USROPN keyword too OVRDBF still has control

31 Improved Error Control

32 Current Checking Error indicator or Extender (E) – doesnt handle all situations *PSSR or INFSR subroutines – cant easily return to the statement that caused the problem

33 Monitor Group MONITOR - marks beginning of code to trap errors ON-ERROR {exception-id1 {:exception-id2…}} Begins the group for one or more status codes. Can also use: – *PROGRAM - all program errors – *FILE - all file errors – *ALL - all errors ENDMON - marks the end of the group

34 Monitor Group Example

35 Monitor Group Example - page 2

36 New Error Processing Order Statement indicators Opcode extenders, %STATUS, %ERROR MONITOR group INFSR *PSSR

37 Increased Java Support (Many thanks to George Farr of IBM - these are his examples)

38 RPG Calling JAVA: 3 options 1. Use QCMDEXC to launch the JVM for the Java class 2. Use system C-APIs to instantiate Java objects and call methods in them (Java Native Invocation or JNI) 3. Use V5R1 RPG enhancements that mask the JVN complexity

39 Calling Java from RPG Declare Objects Prototype Java Methods Instantiate an Object

40 Declare Objects D Test S O CLASS(*JAVA:java.lang.String) Must declare a field to hold the object reference – First parameter must be *JAVA – Fields of type O cannot be DS subfields – Arrays of objects are allowed – Fields of type O are NOT pointers, they only store references to objects

41 Prototype Java Methods D trimstring PR O EXTPROC(*JAVA:java.lang.String:trim) DCLASS(*JAVA:java.lang.String) DSTATIC EXTPROC accepts 3 parameters – *JAVA keyword – package.class name of class containing method – Name of method or *CONSTRUCTOR Specify return type – Use CLASS keyword if it returns a Java object (O type) – Specify STATIC for static methods

42 Instantiate an Object D crtBigDec PR OEXTPROC(*JAVA:java.math.BigDecimal:*CONSTRUCTOR) DCLASS(*JAVA:java.math.BigDecimal) D Parm1 8FVALUE D* D refflt S OCLASS(*JAVA:java.math.BigDecimal) D* D DblField S 8F INZ(0) C* Instantiate the class C* CEVALrefflt = crtBigDec(dblField) Prototype the desired constructor method Declare the object reference variable Call the constructor method, store result

43 Calling Methods Example D fldS 10A INZ( Farr ) D strS O CLASS(*JAVA:java.lang.String) D* D makestringPR O EXTPROC(*JAVA:java.lang.String:*CONSTRUCTOR) D CLASS(*JAVA:java.lang.String) D parm 10A D* D makealpha PR 10A EXTPROC(*JAVA:java.lang.String:getBytes) D* D trimstring PR O EXTPROC(*JAVA:java.lang.String:trim) D CLASS(*JAVA:java.lang.String) CEVALstr = makestring(fld) CEVALstr = trimstring(str) CEVALfld = makeslpha(str)

44 Miscellaneous Changes

45 ELSEIF Can combine an ELSE and IF together If A = 1; X = X + 1; ElseIf A = 2; X = X + 2; ElseIf A = 3; X = X + 3; EndIf; Reduce number of ENDIFs and nesting levels Dont forget about SELECT

46 Qualified Data Structure Names New keyword QUALIFIED - allows names to be reused in the program Useful in prototyped parameter definitions New keyword LIKEDS(data structure) - will have the same structure

47 Qualified Data Structures Example

48 Summary Built-In Functions (BIFs) Free-format Runtime Control of Files and Members Improved Error Control Increased Java support Miscellaneous Changes


Download ppt "RPG IV V5R1 Enhancements Presented by Barry Diehl."

Similar presentations


Ads by Google