1 / 48

RPG IV

RPG IV. Top-Down, Structured Program Design - Chapter 5. Objectives :. Determine how to design and write structured RPG programs Use structured RPG operations that perform sequence, selection, and iteration Use subroutines Design a control break program. Structured Design.

lexiss
Download Presentation

RPG IV

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. RPG IV Top-Down, Structured Program Design - Chapter 5

  2. Objectives: • Determine how to design and write structured RPG programs • Use structured RPG operations that perform sequence, selection, and iteration • Use subroutines • Design a control break program

  3. Structured Design • A methodology that limits its control to 3 basic structures: • Sequence • Selection • Iteration • Each of these control structures has a single entry point and a single exit point

  4. Sequence Control Structure

  5. Selection Control Structure

  6. Iteration Control Structure

  7. Relational Codes Symbol Code Meaning > GT Greater than < LT Less than = EQ Equal to <> NE Not equal to <= LE Less than or equal to >= GE Greater than or equal to

  8. Collating sequence • Character by character comparison • EBCDIC • Digits are compared based on algebraic value • Letters are smaller than digits • Lowercase letters are smaller then uppercase letters • A blank is smaller than any other displayable character

  9. Selection Operations • IF Conditional expression - ENDIF • IF Conditional expression - ELSE - ENDIF • AND - OR • Nested Ifs (Case logic) • SELECT - ENDSL • CASxx - ENDCS

  10. IF - ENDIF • If the comparison is true all statements between the IF and ENDIF are performed • If the comparison is false the statements are bypassed

  11. IF - ELSE - ENDIF • If the comparison is true all statements between the IF and ELSE are performed • If the comparison is false all the statements between the ELSE and the ENDIF are performed

  12. AND - OR • AND, both relationships must be true • OR, one or the other or both relationships must be true

  13. Nested IFs • Build IFs within Ifs

  14. IF and Page Overflow • Built in indicators called overflow indicators • OA thru OG and OV • Use the Keyword OFLIND in the File Specification to make the association between the indicator and report file • The indicator will automatically come on when the printer reaches the overflow line at the bottom of the page

  15. SELECT • Appears on a line alone to identify the start of a case construct • The SELECT is followed by one or more WHEN, each of which specifies a conditions to be tested • Each WHEN is followed by one or more statements to be performed • WHEN conditions can be coupled with AND and/or OR operations

  16. SELECT cont • OTHER means ‘in all other cases’ • OTHER should be the final catch all • As soon as it encounters a true condition, the computer executes the operation(s) following a WHEN • Control is then sent to the end of SELECT, signaled by an ENDSL

  17. CASxx • Nearly identical to SELEC • CASxx operation sends control to subroutines • Use ENDCS to signal end of CASxx

  18. Iteration Operations • DOW Conditional expression - ENDDO • DOU Conditional expression - ENDDO • DO - ENDDO • FOR - ENDFOR

  19. Do While Loop

  20. DOW • This operation establishes a loop, based on a comparison • Test is made at the beginning of loop • All operations coded between this operator and ENDDO are repeated as long as the condition specified in the relational comparison remains true • The DOW allows you to use AND and OR to form compound conditions

  21. Do Until Loop

  22. DOU • The DOU is a structure iteration operation very similar to DOW • The DOW repeats while the specified conditions remains true • The DOU repeats until the condition becomes true • DOU the comparison is made after the instructions in the loop have been executed

  23. DO • Designed specifically for count-controlled loops • Specify four things: • starting value of counter • limit value of counter • counter • increment value to be added to counter • You can omit any of the four, default value is 1

  24. DO cont • Factor 1 on the DO is the starting value of counter • Factor 2 on the DO is the limit value of counter • Result on the DO is the counter • Factor 2 on the ENDDO is the increment value to be added to counter

  25. FOR • FOR is a free-form replacement for the DO operation • Like DO, FOR is a count-controlled loop instruction

  26. Early Exits from Loops • ITER • When ITER is encountered within a loop, control skips past the remaining instructions in the loop and causes the next repetition to begin • LEAVE • Terminates the looping process and sends the control to the statements following the ENDDO

  27. Subroutines • BEGSR/ENDSR • EXSR

  28. BEGSR/ENDSR • Block of code with an identifiable beginning and end • Subroutines are identified by the (optional) letters SR in positions 7-8 of a line, • The name of the subroutine in factor 1 and the operation BEGSR • The last line of a subroutine is a line containing ENDSR in the operation

  29. BEGSR/ENDSR cont • Subroutines must have a unique name formed with the same rules that apply to fields • Subroutines may execute other subroutines, but a subroutine should never execute itself • Subroutines cannot contain other subroutines

  30. EXSR • Execute subroutine • Enter the name of the subroutine to be performed in factor 2

  31. Control Break IPO

  32. Control Break Hierarchy 0000-Mainline 1000-Initial 3000-SlspBreak 5000-Detail 7000-Terminate 3000-SlspBreak

  33. Control Break Logic:0000-MainLine Do Initialization Routine WHILE not end-of file IF change in salesperson Do SlspBreak Routine ENDIF Do Detail Process Routine Read next record ENDWHILE Do Termination Routine END Program

  34. Control Break Logic: 1000-Initial Read first record Set up hold area Print Headings END routine

  35. Control Break Logic:3000-Slspbreak Print salesperson line Add salesperson’s total to grand total Zero out salesperson’s total Move new value to hold area END routine

  36. Control Break Logic:5000-Detail IF page overflow Print headings ENDIF Print detail line Accumulate sales in salesperson’s total END routine

  37. Control Break Logic: 7000-Terminate Do Slspbreak Routine Print grand total END Routine

  38. Sample Program - F Specs *..1....+....2....+....3....+....4....+....5....+....6....+....7....+....8 F************************************************************************** F* Program :R0400HOK * F* Name :Yeager, Meyers & Kronholm * F* Description :This program produces a Sales Report Listing subtotal * F* for each salesman * F* Indicators :OF - Overflow * F* LR - Last Record * F* * F************************************************************************** *..1....+....2....+....3....+....4....+....5....+....6....+....7....+....8 F*ilename++IP FRlen+ Device * FSalesFile IF F 19 DISK FQPRINT O F 132 PRINTER OFLIND(*INOF)

  39. Sample Program - D & I Specs D************************************************************************** D* Definition of all work fields used in program. * D************************************************************************** *..1....+....2....+....3....+....4....+....5....+....6....+....7....+....8 D*Name++++++++++ Ds Len+ Dc D HoldSlsp S 4 D SlspTotal S 6 2 INZ(0) D GrandTotal S 8 2 INZ(0) I************************************************************************** I* Input file of received items defined within the program. * I************************************************************************** *..1....+....2....+....3....+....4....+....5....+....6....+....7....+....8 I*ilename++Sq ISalesFile NS *..1....+....2....+....3....+....4....+....5....+....6....+....7....+....8 I* From+To+++DcField+++++++++ I 1 4 SalesPrsn I 5 7 Dept I 8 13 2SalesAmt

  40. Sample Program - C Specs C************************************************************************** C* OOOO-Mainline * C* Calculations required to produce the sales report * C************************************************************************** C EXSR Initial C* C DOW Not %EOF(SalesFile) C IF HoldSlsp <> SalesPrsn C EXSR SlspBreak C ENDIF C EXSR Detail C READ SalesFile 90 C ENDDO C* C ESXR Terminate C EVAL *INLR = *ON C RETURN

  41. Sample Program - C Specs C************************************************************************** C* 1000-Initial * C* Subroutine to read first record, set up hold salesman, and print * C* first page heading. * C************************************************************************** CSR Initial BEGSR C READ SalesFile 90 C EVAL HoldSlsp = SalesPrsn C EXCEPT Headings C ENDSR

  42. Sample Program - C Specs C************************************************************************** C* 3000-SlspBreak * C* Subroutine done when salesman changes; print subtotal, rollover * C* accumulator, zero out accumulator, and reset hold * C************************************************************************** CSR SlspBreak BEGSR C EXCEPT BreakLine C EVAL GrandTotal = GrandTotal + SlspTotal C EVAL SlspTotal = 0 C EVAL HoldSlsp = SalesPrsn C ENDSR

  43. Sample Program - C Specs C************************************************************************** C* 5000-Detail * C* Subroutine executed for each input record * C************************************************************************** CSR Detail BEGSR C IF *INOF = *ON C EXCEPT Headings C EVAL *INOF = *OFF C ENDIF C* C EXCEPT DetailLine C EVAL SlspTotal = SlspTotal + SalesAmt C ENDSR

  44. Sample Program - C Specs C************************************************************************** C* 7000-Terminate * C* Subroutine done at end of file; execute SlspBreak one last time* C* and print grand total line. * C************************************************************************** CSR Terminate BEGSR C EXSR SlspBreak C EXCEPT TotalLine C ENDSR

  45. Sample Program - O Specs *..1....+....2....+....3....+....4....+....5....+....6....+....7....+....8 O*ilename++D ExceptnameB++A++Sb+Sa+ OQPRINT E Headings 2 2 *..1....+....2....+....3....+....4....+....5....+....6....+....7....+....8 O* Field+++++++++Y End++ Constant/Editword+++++++++++ O 8 ‘R0400HOK’ O* *DATE is a four digit year. O *DATE Y 20 O 33 ’SALES REPORT' O 40 'PAGE' O PAGE Z 44 O E Headings 2 O 20 ’SLSPSN.' O 37 ’AMT.' O** Detail Line ** O E DetailLine 1 O SalesPrsn 18 O SalesAmt 1 39

  46. Sample Program - O Specs *..1....+....2....+....3....+....4....+....5....+....6....+....7....+....8 O*ilename++D ExceptnameB++A++Sb+Sa+ O E BreakLine 1 2 *..1....+....2....+....3....+....4....+....5....+....6....+....7....+....8 O* Field+++++++++Y End++ Constant/Editword+++++++++++ O 24 ‘TOTAL’ O SlspTotal 1 39 O 40 ‘*’ *..1....+....2....+....3....+....4....+....5....+....6....+....7....+....8 O*ilename++D ExceptnameB++A++Sb+Sa+ O E TotalLine *..1....+....2....+....3....+....4....+....5....+....6....+....7....+....8 O* Field+++++++++Y End++ Constant/Editword+++++++++++ O 26 'GRAND TOTAL' O GrandTotal 1 39 O 41 ‘**’

  47. Points to Remember • Structured program design means developing program logic with flow of control tightly managed, generally by using only structured operations • Top-down methodology requires that you approach designing your program hierarchically, working out its broad logic first and later attending to the detailed processing requirements

  48. Points to Remember (cont) • RPG provides structured operations IF, CASxx, and SELECT to implements decision logic • Structured operations DOW, DOU, DO and FOR to implement looping logic • Most of the structured operation of RPG require the use of one of six relational operators • The operators are: GT, LT, EQ, NE, LE, GE

More Related