RPG IV - PowerPoint PPT Presentation

fordon
rpg iv n.
Skip this Video
Loading SlideShow in 5 Seconds..
RPG IV PowerPoint Presentation
play fullscreen
1 / 22
Download Presentation
RPG IV
154 Views
Download Presentation

RPG IV

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. RPG IV Maintaining the Past - Chapter 13

  2. Objectives • Discuss the migration of older RPG programs to RPG IV • Introduce the features now obsolete in RPG IV • Introduce the fixed logic cycle • Introduce the conditioning, resulting, and level indicators

  3. Compatibility and Conversion • RPG II programs could be compiled under RPG III with only slight changes • RPG IV source code lines increased to 100 characters • A CL command CVTRPGSRC (Convert RPG Source) will convert pre-RPG IV source code to RPG IV syntax

  4. Defining Work Fields • In RPG III, D Specs did not exist • Work fields were defined within the C Specs in which the field appeared as a result

  5. Performing Arithmetic and Numeric Assignment • The EVAL operation was also not avaibable before RPG IV • Specific arithmetic operations were used (ADD, SUB, MULT, DIV) • In its basic form, operation ADD adds the value of Factor 1 and Factor 2, storing the answer in the Result field • Only one arithmetic opeation is coded per line

  6. Performing Arithmetic and Numeric Assignmet (cont) • Z-ADD and Z-SUB were used to assign value to numeric variables • The function of the Z-ADD was to zero out the Result field and add Factor 2 to it • The function of the Z-SUB was to zero out the Result field and subtract Factor 2 from it

  7. Looping and Selecting • Pre-RPG IV looping and selecting operations are not free-form expressions • DOWxx, DOUxx, Ifxx, WHENxx are the operations (the small xx represents relational code) • Two unstuctured operations were also available: CABxx and GOTO

  8. Manipulating Strings • SUBST has been superseded by the built-in function %SUBST • CAT has been made obsolete by the concatenation (+) operator used within an EVAL operation

  9. Delimiting Arrays and Tables • Compile time Tables and Arrays use ** rather than **CTDATA and the array/table name • Progams with multiple compile time tables/arrays must define the tables/arrays in the same order as the data appears at the programs end • E Specs used to define tables/arrays are obsolete

  10. Moving Data • Before EVAL, MOVE and MOVEL were used for all character assignment operations • Before the introduction of string operations, arrays and the MOVEA operation were used to inspect and manipulate characters within string fields

  11. RPG II: An Initial Look • RPG II programs rely on RPG’s fixed logic cycle • All versions of RPG (including RPG IV) have a built-in read-process-write cycle that could be used to automate part of the processing requirements • To start the cycle, the main file must be designated as P (for Primary) instead of F (for Full procedural)

  12. RPG II: An Initial Look (cont) • A record-identifying indicator in positions 21-22 on the I Specs is added • The indicator will be turned on each time RPG successfully reads a record • The indicator will be turned off just befor the next automatic attemp to read the file • At EOF the LR indicator is automatically turned on

  13. RPG II: An Initial Look (cont) • Each record format type on the O Specs is changed from E to the type appropriate for a given line: • H for heading lines • D for detail • T for total • Remove the line names

  14. RPG II: An Initial Look (cont) • Indicator 1p (First Page) is used for first time headings • Indicator OF is used for page overflow • Indicator 01 is used to print the detail lines

  15. RPG’s Fixed Logic Cycle Turn on 1P indicator WHILE LR is off Print detail output (H and D lines) Turn off 1P, record-identifying, and level indicators Read record from primary file IF end-of-file Turn on LR and all level indicators ELSE Turn on record-identifying indicator IF change in control field Turn on level indicator(s) ENDIF Perform total calculations Perform total output (T lines) IF LR is not on IF overflow indicator is on Print lines conditioned by overflow ENDIF Move data into input fields Perform detail calculations ENDIF ENDWHILE

  16. The Fixed-Logic Cycle and Control Breaks • Control-break reports require detecting a change in a control-field value • When such a change is detected: • Print a subtotal • Roll over accumulators • Zero out accumulators • Reset the hold field

  17. The Fixed-Logic Cycle and Control Breaks (cont) • Special level indicators, L1-L9, that can be associated with control fields • Level indicators eliminate the need for special hold fields • Level indicators can condition any calculations and printing out subtotals • B in position 45 on O Spec will automatically set the field to zero

  18. Decisions in RPG II • RPG II relies on COMP (Compare) operation for decision logic • Operation COMP compares the values of Factor 1 and Factor 2 and turns on an indicator in the Hi, Lo or Eq columns • The indicators are then used in calcualtions following the COMP to condition whether the operation was to be performed

  19. Resulting Indicators and Arithmetic • Arithmetic operations used resulting indicators • If the result was positive the Hi indicator was turned on • If the result was negative the Lo indicator was turned on • If the result was 0 the Eq indicator was turned on

  20. Iteration and RPG II • In RPG II, loop logic was implemented using the COMP operand and indicators • The indicators conditioned a GOTO that sent control back to prior calculations to repeat procesing steps

  21. Improving on the Past • RPG IV free-form exprssions is preferable to using the older specific arithmetic operations, assignment operations and fixed-format decision and iteration operations • Data definitions should always take place in the D Specs, rather than within the C Specs

  22. Points to Remember • RPG has evolved since its introduction in the early 60s • Use of the fixed-logic cycle has diminished through time • Today’s programmers should avoid outdated techniques in their own code, they still must understand how such methods and operations work