• Embed Doc
  • Readcast
  • Collections
  • CommentGo Back
Download
 
1
RPG IV Best Practices
Presented by Bryan Meyers
 ©Copyright 2004, Bryan Meyerswww.bmeyers.net
Worst Practices
“I want to use RPG IV, but I don’t need ILE“I’ll use RPG IV, but not free format”“I don’t have the time…“If it ain’tbroke…
Best Practices
Enforce RPG IV style standardsUse free-format RPG IVEmbrace ILEEncourage modular design
Style Goals
Accelerate development process
 –Write with reuse in mind
Facilitate program maintenance
 –Write with standards in mind
Reduce errors
 –Write smaller, single-function compile units –Test smaller compile units
Style Goals
Eliminate duplicate code
 –Even little bits of it –Use procedures instead
Eliminate conditional logic
 –Hide it in procedures
Eliminate complex routines
 –Hide them in procedures
Eliminate old code
Free-Format Specification
V5R1 alternative to C-specs
 –May be interspersed with C-specs
....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8/FREEChain(ne) EmployeeIDEmployees;Select;When %Error;Return;When %Found;Eval(h) TotalPay= (RegHours* Rate) + (OvtHours* Rate * 1.5);Endsl;/END-FREE
 
2
Free-Format Specification
Code free-format statements between /FREE and /END-FREE directives
....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8/FREEChain(ne) EmployeeIDEmployees;Select;When %Error;Return;When %Found;Eval(h) TotalPay= (RegHours* Rate) + (OvtHours* Rate * 1.5);Endsl;/END-FREE
Column 7
....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8/FREEChain(ne) EmployeeIDEmployees;Select;When %Error;Return;When %Found;Eval(h) TotalPay= (RegHours* Rate) + (OvtHours* Rate * 1.5);Endsl;/END-FREE
Free-Format Specification
Code goes in columns 8-80
 –Columns 6-7 must be blank –Indenting is allowed
/FREEChain(ne) EmployeeIDEmployees;Select;When %Error;Return;When %Found;Eval(h) TotalPay= (RegHours* Rate) + (OvtHours* Rate * 1.5);Endsl;/END-FREE
Free-Format Specification
Statement can span several lines
 –Semicolon ends each logical line –Multiple statements per line not allowed
Free-Format Specification
Statement begins with opcode
 –OpcodeFactor1 Factor2 Result;
/FREEChain(ne) EmployeeIDEmployees;Select;When %Error;Return;When %Found;Eval(h) TotalPay= (RegHours* Rate) + (OvtHours* Rate * 1.5);Endsl;/END-FREE
Free-Format Specification
If statement doesn’t begin with opcode…
 –EVAL is assumed for assignment expressions –CALLP is assumed otherwise
/FREEEmpNbrErr= *OFF;CalcTaxes(EmployeeID:TotalPay);Eval(h) TotalPay= (RegHours* Rate) + (OvtHours* Rate * 1.5);/END-FREE
EVAL assumedCALLP assumed
/FREEEmpNbrErr= *OFF;CalcTaxes(EmployeeID:TotalPay);Eval(h) TotalPay= (RegHours* Rate) + (OvtHours* Rate * 1.5);/END-FREE
Free-Format Specification
Opcoderequired when extender isnecessary
 –E.g., EVAL(H) or CALLP(E)
EVAL required
 
3
Free-Format Specification
Indicator columns not supported
 –No conditioning indicators
Use structured opcodesinstead
 –No resulting indicators
Use BIFsinstead
 –No level indicators
Revert to fixed format to specify indicator
Free-Format Specification
Free-format comments begin with // 
 –May start anywhere from columns 8-80 –Inline comments allowed
....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8/FREE// Calculate total pay for employeeChain(ne) EmployeeIDEmployees;If %Found; // If employee active, calculate total payEval(h) TotalPay= (RegHours* Rate) + (OvtHours* Rate * 1.5);Endsl;/END-FREE
Comments
Free-Format Specification
Fixed-format comments may also begin with // 
 –Anywhere from columns 6-80 –Inline comments not allowed
CL0N01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq// Calculate tax for total transactionC TotTaxableMULT TaxRateTaxAmount
Comment
Comments
Convert to // comments
 –Eliminate all * comments
Avoid right-hand "end-line" comments incolumns 81-100
 –But use inline // comments where appropriate
Comments
Use comments to clarify not echo —yourcode
 –Brief program or procedure summary –Title for subroutine, procedure, or other sectionof code –Explain an obscure technique
Comments
Always include a brief summary at thebeginning of a program or procedure
 –Program or procedure title –Brief description of purpose –Chronology of changes –Summary of indicator usage (if any) –Description of the procedure interface –Example of how to call the procedure
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...
You must be to leave a comment.
Submit
Characters: ...