48
RPG IV V5R1 RPG IV V5R1 Enhancements Enhancements Presented by Barry Diehl

RPG IV V5R1 Enhancements Presented by Barry Diehl

Embed Size (px)

Citation preview

Page 1: RPG IV V5R1 Enhancements Presented by Barry Diehl

RPG IV V5R1 EnhancementsRPG IV V5R1 Enhancements

Presented by

Barry Diehl

Page 2: RPG IV V5R1 Enhancements Presented by Barry Diehl

At a GlanceAt a Glance

Built-In Functions (BIFs)Free-formatRuntime Control of Files and MembersImproved Error ControlIncreased Java supportMiscellaneous Changes

Page 3: RPG IV V5R1 Enhancements Presented by Barry Diehl

How did it happen?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

Page 4: RPG IV V5R1 Enhancements Presented by Barry Diehl

What didn’t make it?What didn’t make it?

Multiple dimension arraysKeylists in D specsMore H-Spec KeywordsBitwise operations in expressions

Page 5: RPG IV V5R1 Enhancements Presented by Barry Diehl

Built-In FunctionsBuilt-In Functions

Page 6: RPG IV V5R1 Enhancements Presented by Barry Diehl

Taking timeTaking 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, don’t use the format - the system knows the format

Page 7: RPG IV V5R1 Enhancements Presented by Barry Diehl

One More TimeOne 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)

Page 8: RPG IV V5R1 Enhancements Presented by Barry Diehl

What’s the Difference?What’s the Difference?

%DIFF(op1:op2:*MS|*S|*MN|*H|*D|*M|*Y)

Determine the number of days between 2 datesNumDays = %Diff(LoanDate:DueDate:*D)

Add number of minutes between the start and endTotalTime = TotalTime + %Diff(StartTime:EndTime:*MN)

Page 9: RPG IV V5R1 Enhancements Presented by Barry Diehl

Parts Is PartsParts Is Parts

Extract a subset of a date, time or timestamp with %SUBDT

%SUBDT(value:*MS|*S|*MN|*H|*D|*M|*Y)

date = d’1999-02-17’;time = t’01.23.45’;num = %SubDt(date:*Y); // num = 1999num = %SubDt(time:*MN); // num = 23

Page 10: RPG IV V5R1 Enhancements Presented by Barry Diehl

A Well-Defined SearchA 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 don’t work on this function Use %TLOOKUPxx for tables

Page 11: RPG IV V5R1 Enhancements Presented by Barry Diehl

Other FunctionsOther Functions

%ALLOC and %REALLOC%CHECK and %CHECKR%XLATE%SHTDN%SQRT

Page 12: RPG IV V5R1 Enhancements Presented by Barry Diehl

Free-Format RPGFree-Format RPG

Page 13: RPG IV V5R1 Enhancements Presented by Barry Diehl

Free-format RulesFree-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 Can’t define fields or have result indicators Free and fixed can be mixed

Page 14: RPG IV V5R1 Enhancements Presented by Barry Diehl

Function ReplacementsFunction Replacements

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

Page 15: RPG IV V5R1 Enhancements Presented by Barry Diehl

Function ReplacementsFunction Replacements

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

Page 16: RPG IV V5R1 Enhancements Presented by Barry Diehl

Operator ReplacementOperator Replacement

ADD +CAT +DIV /MULT *SUB -

Page 17: RPG IV V5R1 Enhancements Presented by Barry Diehl

GeneralizeGeneralize

ANDxx ANDDOUxx DOUDOWxx DOWIFxx IFORxx ORWHENxx WHEN

Page 18: RPG IV V5R1 Enhancements Presented by Barry Diehl

Social Engineering - ObsoleteSocial Engineering - Obsolete

BITOFF use MOVE BITON use MOVE CABxx CAS and ENDCS COMP GOTO MHHZO MHLZO MLHZO MLLZO TAG

Page 19: RPG IV V5R1 Enhancements Presented by Barry Diehl

Social Engineering – Moving to NewSocial 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

Page 20: RPG IV V5R1 Enhancements Presented by Barry Diehl

Free-Form DetailsFree-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

Page 21: RPG IV V5R1 Enhancements Presented by Barry Diehl

Fixed-format (page 1)Fixed-format (page 1)

Page 22: RPG IV V5R1 Enhancements Presented by Barry Diehl

Free-format (page 1)Free-format (page 1)

Page 23: RPG IV V5R1 Enhancements Presented by Barry Diehl

Fixed-format (page 2)Fixed-format (page 2)

Page 24: RPG IV V5R1 Enhancements Presented by Barry Diehl

Free-format (page 2)Free-format (page 2)

Page 25: RPG IV V5R1 Enhancements Presented by Barry Diehl

Fixed-format (page 3)Fixed-format (page 3)

Page 26: RPG IV V5R1 Enhancements Presented by Barry Diehl

Free-format (page 3)Free-format (page 3)

Page 27: RPG IV V5R1 Enhancements Presented by Barry Diehl

Fixed-format (page 4)Fixed-format (page 4)

Page 28: RPG IV V5R1 Enhancements Presented by Barry Diehl

Free-format (page 4)Free-format (page 4)

Page 29: RPG IV V5R1 Enhancements Presented by Barry Diehl

Runtime Control of Files and Runtime Control of Files and MembersMembers

Page 30: RPG IV V5R1 Enhancements Presented by Barry Diehl

Runtime Control of Files and Runtime Control of Files and MembersMembers

Use EXTFILE(file name) and EXTMBR(member name) as keywords in F Spec

Need USROPN keyword tooOVRDBF still has control

Page 31: RPG IV V5R1 Enhancements Presented by Barry Diehl

Improved Error ControlImproved Error Control

Page 32: RPG IV V5R1 Enhancements Presented by Barry Diehl

Current CheckingCurrent Checking

Error indicator or Extender (E) – doesn’t handle all situations

*PSSR or INFSR subroutines – can’t easily return to the statement that caused the problem

Page 33: RPG IV V5R1 Enhancements Presented by Barry Diehl

Monitor GroupMonitor 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

Page 34: RPG IV V5R1 Enhancements Presented by Barry Diehl

Monitor Group ExampleMonitor Group Example

Page 35: RPG IV V5R1 Enhancements Presented by Barry Diehl

Monitor Group Example - Monitor Group Example - page 2page 2

Page 36: RPG IV V5R1 Enhancements Presented by Barry Diehl

New Error Processing OrderNew Error Processing Order

Statement indicatorsOpcode extenders, %STATUS, %ERRORMONITOR groupINFSR*PSSR

Page 37: RPG IV V5R1 Enhancements Presented by Barry Diehl

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

Page 38: RPG IV V5R1 Enhancements Presented by Barry Diehl

RPG Calling JAVA: 3 optionsRPG Calling JAVA: 3 options

Use QCMDEXC to launch the JVM for the Java class

Use system C-APIs to instantiate Java objects and call methods in them (Java Native Invocation or JNI)

Use V5R1 RPG enhancements that mask the JVN complexity

Page 39: RPG IV V5R1 Enhancements Presented by Barry Diehl

Calling Java from RPGCalling Java from RPG

Declare ObjectsPrototype Java MethodsInstantiate an Object

Page 40: RPG IV V5R1 Enhancements Presented by Barry Diehl

Declare ObjectsDeclare 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

Page 41: RPG IV V5R1 Enhancements Presented by Barry Diehl

Prototype Java MethodsPrototype Java Methods D trimstring PR O EXTPROC(*JAVA:’java.lang.String’:’trim’)

D CLASS(*JAVA:’java.lang.String’)D STATIC

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

Page 42: RPG IV V5R1 Enhancements Presented by Barry Diehl

Instantiate an ObjectInstantiate an Object D crtBigDec PR O

EXTPROC(*JAVA:’java.math.BigDecimal’:*CONSTRUCTOR)D CLASS(*JAVA:’java.math.BigDecimal’)D Parm1 8F VALUED*D refflt S O CLASS(*JAVA:’java.math.BigDecimal’)D*D DblField S 8F INZ(‘0’)

C* Instantiate the classC*C EVAL refflt = crtBigDec(dblField)

Prototype the desired constructor method Declare the object reference variable Call the constructor method, store result

Page 43: RPG IV V5R1 Enhancements Presented by Barry Diehl

Calling Methods ExampleCalling Methods Example

D fld S 10A INZ(‘ Farr ‘)D str S O CLASS(*JAVA:’java.lang.String’)D*D makestring PR O EXTPROC(*JAVA:’java.lang.String’:*CONSTRUCTOR)D CLASS(*JAVA:’java.lang.String’)D parm 10AD*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’)C EVAL str = makestring(fld)C EVAL str = trimstring(str)C EVAL fld = makeslpha(str)

Page 44: RPG IV V5R1 Enhancements Presented by Barry Diehl

Miscellaneous ChangesMiscellaneous Changes

Page 45: RPG IV V5R1 Enhancements Presented by Barry Diehl

ELSEIFELSEIFCan 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 levelsDon’t forget about SELECT

Page 46: RPG IV V5R1 Enhancements Presented by Barry Diehl

Qualified Data Structure Qualified Data Structure NamesNames

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

Page 47: RPG IV V5R1 Enhancements Presented by Barry Diehl

Qualified Data Structures Qualified Data Structures ExampleExample

Page 48: RPG IV V5R1 Enhancements Presented by Barry Diehl

SummarySummary

Built-In Functions (BIFs)Free-formatRuntime Control of Files and MembersImproved Error ControlIncreased Java supportMiscellaneous Changes