Beruflich Dokumente
Kultur Dokumente
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
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
Symbol > < = <> <= >= Code GT LT EQ NE LE GE Meaning Greater than Less than Equal to Not equal to Less than or equal to Greater than or equal to
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
IF Conditional expression - ENDIF IF Conditional expression - ELSE ENDIF AND - OR Nested Ifs (Case logic) SELECT - ENDSL CASxx - ENDCS
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 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, both relationships must be true OR, one or the other or both relationships must be true
Nested IFs
Build IFs within Ifs
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
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
Nearly identical to SELEC CASxx operation sends control to subroutines Use ENDCS to signal end of CASxx
Iteration Operations
DOW Conditional expression - ENDDO DOU Conditional expression - ENDDO DO - ENDDO FOR - ENDFOR
Do While Loop
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
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
DO
Designed specifically for countcontrolled loops Specify four things:
starting value of counter limit value of counter counter increment value to be added to counter
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
FOR
FOR is a free-form replacement for the DO operation Like DO, FOR is a count-controlled loop instruction
LEAVE
Terminates the looping process and sends the control to the statements following the ENDDO
Subroutines
BEGSR/ENDSR EXSR
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
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
EXSR
Execute subroutine Enter the name of the subroutine to be performed in factor 2
1000-Initial
3000-SlspBreak
5000-Detail
7000-Terminate
3000-SlspBreak
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