f337b398d1607b2035be6095a8e72807.ppt
- Количество слайдов: 19
Getting Started Chapter 2 Presentation © Copyright 2002, Bryan Meyers
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 2
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 3
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+++++++++++++++ FSales. Mast IF F 63 DISK FQPRINT O F 132 PRINTER Programming in RPG IV Third Edition 4
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++Sq. NORi. Pos 1+NCCPos 2+NCCPos 3+NCC. . . . I. . . Fmt+SPFrom+To+++Dc. Field+++++L 1 M 1 Fr. P 1 Mn. Zr. . . ISales. Mast NS I 1 4 0 Slsp. Number I 5 34 Slsp. Name I 35 50 Item. Number I 51 56 0 Date. Of. Sale I 57 63 2 Price Programming in RPG IV Third Edition 5
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. . N 01 N 02 N 03 Excnam++++B++A++Sb+Sa+. . . . O. . . N 01 N 02 N 03 Field+++++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 6
Pseudocode for Program • WRITE report headings • READ a record • WHILE there are more records – WRITE a detail line – READ the next record • ENDWHILE • END Programming in RPG IV Third Edition 7
Calculation Specifications • • • Except Read Dow Enddo Eval Return *. . 1. . . +. . . 2. . . +. . . 3. . . +. . . 4. . . +. . . 5. . . +. . . 6. . . +. . . 7. . . +. . . 8 /FREE EXCEPT Headings; READ Sales. Mast; DOW NOT %EOF; EXCEPT Detail; READ Sales. Mast; ENDDO; EVAL *INLR =*ON; RETURN; /END-FREE Programming in RPG IV Third Edition 8
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 CL 0 N 01 Factor 1+++++++Opcode(E)+Factor 2+++++++Result++++Len++D+Hi. Lo. Eq. . CL 0 N 01 Factor 1+++++++Opcode(E)+Extended-factor 2+++++++++++++++ C EXCEPT Headings C READ Sales. Mast C DOW NOT %EOF C EXCEPT Detail C READ Sales. Mast C ENDDO C EVAL *INLR =*ON C RETURN Programming in RPG IV Third Edition 9
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 10
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 Sales. Mast. Author: J. Yaeger Date Written: 12/10/1994. Date Modified: 12/20/2001. ************************************ FSales. Mast IF FQPRINT O ISales. Mast NS I I I Programming in RPG IV Third Edition F F 63 132 DISK PRINTER 1 5 35 51 57 4 0 Slsp. Number 34 Slsp. Name 50 Item. Number 56 0 Date. Of. Sale 63 2 Price 11
Completed Program - C Spec *. . 1. . . +. . . 2. . . +. . . 3. . . +. . . 4. . . +. . . 5. . . +. . . 6. . . +. . . 7. . . +. . . 8 /FREE EXCEPT Headings; READ Sales. Mast; DOW NOT %EOF; EXCEPT Detail; READ Sales. Mast; ENDDO; EVAL *INLR =*ON; RETURN; /END-FREE (Before V 5) *. . 1. . . +. . . 2. . . +. . . 3. . . +. . . 4. . . +. . . 5. . . +. . . 6. . . +. . . 7. . . +. . . 8 C EXCEPT Headings C READ Sales. Mast C DOW NOT %EOF C EXCEPT Detail C READ Sales. Mast C ENDDO C EVAL *INLR =*ON C RETURN Programming in RPG IV Third Edition 12
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 O E O O O E Headings 1 7 'SLSPSN. ' 48 'DATE OF' 77 'SALE' Programming in RPG IV Third Edition Headings 2 3 21 46 61 77 'NO. ' 'NAME' 'SALE' 'ITEM SOLD' 'PRICE' 13
Completed Program - O Spec *. . 1. . . +. . . 2. . . +. . . 3. . . +. . . 4. . . +. . . 5. . . +. . . 6. . . +. . . 7. . . +. . . 8 O E Detail 1 O Slsp. Number 4 O Slsp. Name 37 O Date. Of. Sale Y 48 O Item. Number 67 O Price 1 79 Programming in RPG IV Third Edition 14
Edit Codes Commas Print Zero No Sign CR Right - Floating - Yes 1 A J N Yes No 2 B K O No Yes 3 C L P No No 4 D M Q Programming in RPG IV Third Edition 15
Edit Words Value Edit Word Prints 99999 ‘bbb-bb-bbbb’ 999 -99 -99999 ‘bbb&bb&bbbb’ 999 99 9999 123412 ‘ 0(bbb)bbb-bbbb’ 00012^14 ‘bbb$0. bb’ 00012^14 ‘$bbbb 0. bb’ $ 05612^14 ‘$bb, bb 0. bb’ $ 5, 612. 14 Programming in RPG IV Third Edition (123)412 -3412 $12. 14 16
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 17
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 18
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 19


