RPG /Free Format
Enhancements since 7.1
Matt Spies
@matt_spies
RPG /Free Format Enhancements - FASUG - March 2014
Meeting
Why go toward /Free format RPG?
Self documenting code
Easier to code and to maintain
More horizontal space to code
RPG /Free Format Enhancements - FASUG - March 2014
Meeting
How we got here?
V5R1 - /Free format C Specifications
V5R3 - /Free format SQL
7.1 - /Free format H, F, D, P Specifications
Requirements
5770WDS-SI51094 for RPG compiler
(approx. 10MB)
Superseded by 5770WDS-SI52307
DB2 Group PTF SF99701 Level 26 for SQL precompiler
support
RPG /Free Format Enhancements - FASUG - March 2014
Meeting
Ground Rules-Enhanced RPG Compiler
/Free and /End-Free are no longer needed.
I & O Specs and RPG Cycle remain Fixed Format.
F & D Specs can be mixed together.
Free Format and Fixed Format can be intermixed
within the standard coding guidelines, of course!
Free Format has sensible defaults.
Op Codes are not case specific.
Free Format code must be between columns 8-80.
Semicolon is necessary at the end of every free format
statement ;
RPG /Free Format Enhancements - FASUG - March 2014
Meeting
Source Entry Utility (SEU)
EDITORS
Rational Developer for i (RDi ) 9.0.1
RPG /Free Format Enhancements - FASUG - March 2014
Meeting
H Spec
Fixed Format
/Free Format
H NOMAIN
H OPTION( *NODEBUGIO: *SRCSTMT)
H DATFMT( *MDY )
H DFTACTGRP( *NO )
H BNDDIR( SERVICELIB/SERVICEDIR)
Ctl-Opt NOMAIN
OPTION( *NODEBUGIO: *SRCSTMT)
DATFMT( *MDY )
BNDDIR( SERVICELIB/SERVICEDIR ) ;
// DFTACTGRP(*NO) not needed if
// ACTGRP, BNDDIR, or STGMDL
// keywords exist.
RPG /Free Format Enhancements - FASUG - March 2014
Meeting
F Spec
Fixed Format
F
F
F
F
F
F
*
InpFile
IF
E
DISK
UpdFile
UF
E
K DISK
OutFile
O A E
DISK
UpdOutFileUF A E
K DISK
PrintFile O
F 132
PRINTER OflInd(*INOF)
DspFile
CF
E
WORKSTN
U is used for UPDATE & DELETE
RPG /Free Format Enhancements - FASUG - March 2014
Meeting
F Spec
/Free Format
Dcl-F InpFile; // Usage(*Input) implied.
// Disk or Disk(*Ext) implied.
Dcl-F UpdFile Usage(*Update) Keyed;
Dcl-F OutFile Usage(*Output);
Dcl-F UpdOutFile Usage(*Output: *Update) Keyed;
Dcl-F PrintFile Printer(132) OflInd(*INOF);
Dcl-F DspFile Workstn;
// Usage(*Delete) is necessary for delete
// Usage(*Update) implies *Input and *Update
RPG /Free Format Enhancements - FASUG - March 2014
Meeting
D Spec - Variables
Fixed Format
D
D
D
D
D
D
D
D
Header
Title
ISODate
Index
ShipQuantity
SalesAmount
FoundItem
Counter
C
S
S
S
S
S
S
FASUG'
60A
D DatFmt(*ISO)
3I 0 Inz(1)
7S 0
10P 2
N
Inz(*Off)
Like(Index)
RPG /Free Format Enhancements - FASUG - March 2014
Meeting
D Spec - Variables
/Free Format
Dcl-C
Dcl-S
Dcl-S
Dcl-S
Dcl-S
Dcl-S
Dcl-S
Dcl-S
Header FASUG; // Const(FASUG) optional
Title Char(60);
ISODate Date(*ISO);
// No DatFmt Keyword
Index Int(3) Inz(1); // 3, 5, 10, 20 digits
ShipQuantity Zoned(7); // or Zoned(7:0)
SalesAmount Packed(10:2);
FoundItem Ind Inz(*Off); // No more 15 character
Counter Like(Index);
// limit on field names!
RPG /Free Format Enhancements - FASUG - March 2014
Meeting
10
D Spec - Data Structures
Fixed Format
D InputRecDS
D OutputRecDS
DS
DS
D CurTimeDS
D CurTime
D CurHour
D CurMin
D CurSec
DS
D InfDS
D Num_Rcds
DS
D OneLine
DS
LikeRec(RcdFmt)
LikeDS(InputRecDS)
6S
2S
2S
2S
156
0
0 Overlay(CurTime:1)
0 Overlay(CurTime:3)
0 Overlay(CurTime:5)
159I 0
80
RPG /Free Format Enhancements - FASUG - March 2014
Meeting
11
D Spec - Data Structures
/Free Format
Dcl-DS InputRecDS LikeRec(RcdFmt);
Dcl-DS OutputRecDS LikeDS(InputRecDS);
// No End-DS required
// No End-DS required
Dcl-DS CurTimeDS;
// Dcl-DS *n ;
if there is no DS name
CurTime Zoned(6);
CurHour Zoned(2) Pos(1); // Pos(1) or Overlay(CurTime:1).
CurMin Zoned(2) Pos(3); // Dcl-SubF is optional, except when subfield = RPG opcode
CurSec Zoned(2) Pos(5);
End-DS; // or End-DS CurTimeDS;
// Overlay(arrayname:startposition) needed for array data structures
Dcl-DS InfDS;
Num_Rcds Int(10) Pos(156);
End-DS;
Dcl-DS OneLine Len(80) End-DS;
RPG /Free Format Enhancements - FASUG - March 2014
Meeting
12
D Spec Prototypes & Procedure Interfaces
Fixed Format
D PgmName
D
D
PR
D PgmName
D Company
D OrderNumber
PI
2S 0
9A
2S 0
9A
RPG /Free Format Enhancements - FASUG - March 2014
Meeting
13
D Spec Prototypes & Procedure Interfaces
/Free Format
Dcl-Pr PgmName;
Company Zoned(2);
OrderNumber Char(9);
End-Pr;
Dcl-PI PgmName;
Company Zoned(2);
OrderNumber Char(9);
End-PI;
// Dcl-Parm is optional, except when
// parameter = RPG opcode (select, read)
RPG /Free Format Enhancements - FASUG - March 2014
Meeting
14
P Spec
Fixed Format
/End-Free
P NEXTLEVEL
B
/Free
// code some stuff
/End-Free
P NEXTLEVEL E
/Free
/Free Format
Export
Dcl-Proc NEXTLEVEL Export;
// code some stuff
End-Proc;
RPG /Free Format Enhancements - FASUG - March 2014
Meeting
15
RPG
Spec
H
F
D
P
Free Format OpCode
Ctl-Opt
Dcl-F
Dcl-C Dcl-S Dcl-DS End-DS Dcl-Subf
Dcl-Pr End-Pr Dcl-PI End-PI Dcl-Parm
Dcl-Proc End-Proc
RPG /Free Format Enhancements - FASUG - March 2014
Meeting
16
/End-Free
IBM Developer Works // Excellent resource
https://www.ibm.com/developerworks/ibmi/library/i-ibmi-rpg-support/
ILE RPG Reference
http://pic.dhe.ibm.com/infocenter/iseries/v7r1m0/topic/books/sc092508a.pdf
The Past, Present and Future of RPG Tim Rowe
http://iprodeveloper.com/rpg-programming/past-present-and-future-rpg
Four Reasons RPG Geezers Should Care About The New Free Format
RPG Paris
http://www.itjungle.com/fhg/fhg021214-story01.html
RPG /Free Format Enhancements - FASUG - March 2014
Meeting
17
RPG /Free Format Enhancements - FASUG - March 2014
Meeting
18