Getting Started Chapter 2 Presentation © Copyright 2002, Bryan Meyers 4/21/2017 Getting Started Chapter 2 Presentation © Copyright 2002, Bryan Meyers
Objectives Describe the RPG Specification forms 4/21/2017 Objectives Describe the RPG Specification forms Create a simple read/write RPG program Explain how to include comment lines in a program Explain how to do output editing to control the appearance of a report Programming in RPG IV Third Edition
Specifications in RPG IV 4/21/2017 Specifications in RPG IV Different specifications for different purposes File Description Specifications Describe files used by program Definition Specifications Describe working variables, structures Input Specifications Describe input fields in files Calculation Specifications Processing instructions Output Specifications Describe program output (reports, files, etc.) Programming in RPG IV Third Edition
File Description Specifications 4/21/2017 File Description Specifications File Name File Type File Designation File Format Record Length Device *.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 FFilename++IPEASFRlen+LKlen+AIDevice+.Keywords+++++++++++++++++++++++++++++ FSalesMast IF F 63 DISK FQPRINT O F 132 PRINTER Programming in RPG IV Third Edition
Input Specifications Record Identification Entries 4/21/2017 Input Specifications Record Identification Entries File Name Sequence Field Description Entries Field Location Decimal Positions Field Name *.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 IFilename++SqNORiPos1+NCCPos2+NCCPos3+NCC.................................. I........................Fmt+SPFrom+To+++DcField+++++++++L1M1FrP1MnZr...... ISalesMast NS I 1 4 0SlspNumber I 5 34 SlspName I 35 50 ItemNumber I 51 56 0DateOfSale I 57 63 2Price Programming in RPG IV Third Edition
Output Specifications 4/21/2017 Output Specifications Record Identification Entries File Name Type Exception Name Space and Skip Entries Field Description Entries Field Name Constants End Position in Output Record Edit Codes *.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 OFilename++DF..N01N02N03Excnam++++B++A++Sb+Sa+............................. O..............N01N02N03Field+++++++++YB.End++PConstant/editword/DTformat++ OQPRINT E Headings 2 2 O 8 ‘PAGE ’ O PAGE 13 O 50 ‘WEEKLY SALES REPORT ’ O 64 ‘DATE ’ O *DATE Y 75 Programming in RPG IV Third Edition
Pseudocode for Program 4/21/2017 Pseudocode for Program WRITE report headings READ a record WHILE there are more records WRITE a detail line READ the next record ENDWHILE END Program Programming in RPG IV Third Edition
Calculation Specifications 4/21/2017 Calculation Specifications Except Read Dow Enddo Eval Return *.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 /FREE EXCEPT Headings; READ SalesMast; DOW NOT %EOF; EXCEPT Detail; ENDDO; EVAL *INLR =*ON; RETURN; /END-FREE Programming in RPG IV Third Edition
Fixed-Format C-Specifications 4/21/2017 Fixed-Format C-Specifications Before Version 5, compiler did not support free-format calculations Fixed-format C spec required *.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 CL0N01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq.... CL0N01Factor1+++++++Opcode(E)+Extended-factor2+++++++++++++++++++++++++++++ C EXCEPT Headings C READ SalesMast C DOW NOT %EOF C EXCEPT Detail C ENDDO C EVAL *INLR =*ON C RETURN Programming in RPG IV Third Edition
Internal Documentation 4/21/2017 Internal Documentation Comment lines begin with // Starting at Version 5 Free format specifications Comment can make up entire line or a portion of the line, after the code // can be anywhere from 8-80 Fixed format specifications Comment must make up entire line // Can be anywhere from 7-80 Fixed format also supports comments that start with * in column 7 Used exclusively before Version 5 Blank lines are also allowed Programming in RPG IV Third Edition
Completed Program - F & I 4/21/2017 Completed Program - F & I *.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 // *********************************************************************** // This program produces a weekly sales report. The report data comes // directly from input file SalesMast. // Author: J.Yaeger Date Written: 12/10/1994. // Date Modified: 12/20/2001. FSalesMast IF F 63 DISK FQPRINT O F 132 PRINTER ISalesMast NS I 1 4 0SlspNumber I 5 34 SlspName I 35 50 ItemNumber I 51 56 0DateOfSale I 57 63 2Price Programming in RPG IV Third Edition
Completed Program - C Spec 4/21/2017 Completed Program - C Spec *.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 /FREE EXCEPT Headings; READ SalesMast; DOW NOT %EOF; EXCEPT Detail; ENDDO; EVAL *INLR =*ON; RETURN; /END-FREE *.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 C EXCEPT Headings C READ SalesMast C DOW NOT %EOF C EXCEPT Detail C ENDDO C EVAL *INLR =*ON C RETURN (Before V5) Programming in RPG IV Third Edition
Completed Program - O Spec 4/21/2017 Completed Program - O Spec *.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 OQPRINT E Headings 2 2 O 8 'PAGE' O PAGE 13 O 50 'WEEKLY SALES REPORT' O 64 'DATE' O *DATE Y 75 O E Headings 1 O 7 'SLSPSN.' O 48 'DATE OF' O 77 'SALE' O E Headings 2 O 3 'NO.' O 21 'NAME' O 46 'SALE' O 61 'ITEM SOLD' O 77 'PRICE' Programming in RPG IV Third Edition
Completed Program - O Spec 4/21/2017 Completed Program - O Spec *.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 O E Detail 1 O SlspNumber 4 O SlspName 37 O DateOfSale Y 48 O ItemNumber 67 O Price 1 79 Programming in RPG IV Third Edition
Edit Codes Commas Print Zero No Sign CR Right - Floating - Yes 1 A J N 4/21/2017 Edit Codes Commas Print Zero No Sign CR Right - Floating - Yes 1 A J N No 2 B K O 3 C L P 4 D M Q Programming in RPG IV Third Edition
Edit Words Value Edit Word Prints 999999999 ‘bbb-bb-bbbb’ 999-99-9999 4/21/2017 Edit Words Value Edit Word Prints 999999999 ‘bbb-bb-bbbb’ 999-99-9999 ‘bbb&bb&bbbb’ 999 99 9999 1234123412 ‘0(bbb)bbb-bbbb’ (123)412-3412 00012^14 ‘bbb$0.bb’ $12.14 ‘$bbbb0.bb’ $ 12.14 05612^14 ‘$bb,bb0.bb’ $ 5,612.14 Programming in RPG IV Third Edition
4/21/2017 Points to Remember RPG programs are written as fixed form specifications Different specification forms convey different kinds of information to the RPG compiler File specifications contain descriptions of all files used within a program Programming in RPG IV Third Edition
4/21/2017 Points to Remember Input specifications provide detail information about each program described input file used by a program Calculation specifications center on operations, or processing steps, to be accomplished by the computer Output specifications provide details about each program-described output file Programming in RPG IV Third Edition
4/21/2017 Points to Remember It generally is customary to edit numeric values that are printed Comment lines, which begin with //, can appear almost anywhere within a program Programming in RPG IV Third Edition