rpg iv
Download
Skip this Video
Download Presentation
RPG IV

Loading in 2 Seconds...

play fullscreen
1 / 48

RPG IV - PowerPoint PPT Presentation


  • 206 Views
  • Uploaded on

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.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'RPG IV' - lexiss


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
rpg iv

RPG IV

Top-Down, Structured Program Design - Chapter 5

objectives
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
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
relational codes
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

collating sequence
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
selection operations
Selection Operations
  • IF Conditional expression - ENDIF
  • IF Conditional expression - ELSE - ENDIF
  • AND - OR
  • Nested Ifs (Case logic)
  • SELECT - ENDSL
  • CASxx - ENDCS
if endif
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
if else endif
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
and or
AND - OR
  • AND, both relationships must be true
  • OR, one or the other or both relationships must be true
nested ifs
Nested IFs
  • Build IFs within Ifs
if and page overflow
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
select
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
select cont
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
casxx
CASxx
  • Nearly identical to SELEC
  • CASxx operation sends control to subroutines
  • Use ENDCS to signal end of CASxx
iteration operations
Iteration Operations
  • DOW Conditional expression - ENDDO
  • DOU Conditional expression - ENDDO
  • DO - ENDDO
  • FOR - ENDFOR
slide20
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
slide22
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
slide23
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
do cont
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
slide25
FOR
  • FOR is a free-form replacement for the DO operation
  • Like DO, FOR is a count-controlled loop instruction
early exits from loops
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
subroutines
Subroutines
  • BEGSR/ENDSR
  • EXSR
begsr endsr
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
begsr endsr cont
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
slide30
EXSR
  • Execute subroutine
  • Enter the name of the subroutine to be performed in factor 2
control break hierarchy
Control Break Hierarchy

0000-Mainline

1000-Initial

3000-SlspBreak

5000-Detail

7000-Terminate

3000-SlspBreak

control break logic 0000 mainline
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

control break logic 1000 initial
Control Break Logic: 1000-Initial

Read first record

Set up hold area

Print Headings

END routine

control break logic 3000 slspbreak
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

control break logic 5000 detail
Control Break Logic:5000-Detail

IF page overflow

Print headings

ENDIF

Print detail line

Accumulate sales in salesperson’s total

END routine

control break logic 7000 terminate
Control Break Logic: 7000-Terminate

Do Slspbreak Routine

Print grand total

END Routine

sample program f specs
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)

sample program d i specs
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

sample program c specs
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

sample program c specs41
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

sample program c specs42
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

sample program c specs43
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

sample program c specs44
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

sample program o specs
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

sample program o specs46
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 ‘**’

points to remember
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
points to remember cont
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
ad