Rpg iv l.jpg
This presentation is the property of its rightful owner.
Sponsored Links
1 / 48

RPG IV PowerPoint PPT Presentation


  • 162 Views
  • Uploaded on
  • Presentation posted in: General

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.

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.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 l.jpg

RPG IV

Top-Down, Structured Program Design - Chapter 5


Objectives l.jpg

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 l.jpg

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


Sequence control structure l.jpg

Sequence Control Structure


Selection control structure l.jpg

Selection Control Structure


Iteration control structure l.jpg

Iteration Control Structure


Relational codes l.jpg

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 l.jpg

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 l.jpg

Selection Operations

  • IF Conditional expression - ENDIF

  • IF Conditional expression - ELSE - ENDIF

  • AND - OR

  • Nested Ifs (Case logic)

  • SELECT - ENDSL

  • CASxx - ENDCS


If endif l.jpg

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 l.jpg

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 l.jpg

AND - OR

  • AND, both relationships must be true

  • OR, one or the other or both relationships must be true


Nested ifs l.jpg

Nested IFs

  • Build IFs within Ifs


If and page overflow l.jpg

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 l.jpg

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 l.jpg

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 l.jpg

CASxx

  • Nearly identical to SELEC

  • CASxx operation sends control to subroutines

  • Use ENDCS to signal end of CASxx


Iteration operations l.jpg

Iteration Operations

  • DOW Conditional expression - ENDDO

  • DOU Conditional expression - ENDDO

  • DO - ENDDO

  • FOR - ENDFOR


Do while loop l.jpg

Do While Loop


Slide20 l.jpg

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


Do until loop l.jpg

Do Until Loop


Slide22 l.jpg

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 l.jpg

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 l.jpg

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 l.jpg

FOR

  • FOR is a free-form replacement for the DO operation

  • Like DO, FOR is a count-controlled loop instruction


Early exits from loops l.jpg

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 l.jpg

Subroutines

  • BEGSR/ENDSR

  • EXSR


Begsr endsr l.jpg

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 l.jpg

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 l.jpg

EXSR

  • Execute subroutine

  • Enter the name of the subroutine to be performed in factor 2


Control break ipo l.jpg

Control Break IPO


Control break hierarchy l.jpg

Control Break Hierarchy

0000-Mainline

1000-Initial

3000-SlspBreak

5000-Detail

7000-Terminate

3000-SlspBreak


Control break logic 0000 mainline l.jpg

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 l.jpg

Control Break Logic: 1000-Initial

Read first record

Set up hold area

Print Headings

END routine


Control break logic 3000 slspbreak l.jpg

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 l.jpg

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 l.jpg

Control Break Logic: 7000-Terminate

Do Slspbreak Routine

Print grand total

END Routine


Sample program f specs l.jpg

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 l.jpg

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 l.jpg

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 l.jpg

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 l.jpg

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 l.jpg

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 l.jpg

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 l.jpg

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 l.jpg

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 l.jpg

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 l.jpg

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


  • Login