HP 3000 Manuals

More About the RPG Logic Cycle [ HP RPG/XL Programmer's Guide ] MPE/iX 5.0 Documentation


HP RPG/XL Programmer's Guide

More About the RPG Logic Cycle 

The following sections in this chapter give details about how the RPG
logic cycle works and how indicators are used.  Use this section when you
have specific questions about how a particular RPG feature is
implemented.

The Primary Steps in the RPG Logic Cycle 

When an RPG program is first executed, certain initialization and
housekeeping operations (described under Step 1 below) are performed.
Then the main RPG cycle begins (Steps 2-8).  Steps 2 through 8 are
repeated for each set of input records.  Figure 1-3 diagrams these steps:

Step        Description 

1        Pre-Cycle Initialization and Housekeeping 

         RPG performs certain preliminary functions once before the main
         logic cycle begins.  During these operations, all data areas are
         initialized and the 1P and L0 indicators are turned on.  All
         files are prepared for processing and all preexecution-time
         tables and arrays are read into memory.  First-page alignment is
         performed for printer files and all output controlled by the 1P
         indicator is written.  A record is read from each primary and
         secondary input file.  The program is now ready to begin the
         main logic cycle.

2        Heading and Detail-Time Output 

         This begins the main logic cycle.  The RPG program writes all
         heading and detail records whose conditions are satisfied.
         (Heading records are identified by an H in the Type Field of the
         Output Specification; detail records are indicated by a D in the
         Type Field.)  The program tests the status of all halt
         indicators (and halts if any are turned on), and turns off all
         record-identifying and control-level indicators that are on.
         All overflow indicators that were turned on before the last
         detail calculations (done in Step 8) are turned off.  RPG also
         tests the LR indicator for end-of-program status and transfers
         to Step 6 if this indicator is on.

         _______________________________________________________________ 

         NOTE  The term "detail-time" used throughout this manual
               collectively refers to detail-time calculations (occurring
               in Step 8) followed by detail output (occurring in this
               step).

         _______________________________________________________________ 

3        Record Input 

         If there are no primary or secondary files, control goes to Step
         6; otherwise, a record is read from the current file.  If it is
         end-of-file, control skips to Step 4.  If the record has an
         invalid record type or is in the wrong sequence and columns
         56-71 of the Header Specification contains a pre-response to the
         error, the pre-response is performed.  If there is an error and
         no pre-response is entered, the response comes from the operator
         (session mode) or the job file (job mode).

4        Record Selection 

         If the program has just one input file, the next record from
         that file is selected for processing.  If the program has more
         than one input file, the record is selected as follows:

           a.  If a file is FORCEd (uses the FORCE Calculation
           Specification operation), the next record from that file is
           selected.

           b.  If any input records without matching fields have been
           read, the highest-priority record among them is chosen.
           Primary file records have greatest priority, followed by
           secondary file records in the order that they are entered in
           the File Description Specifications.

           c.  If all input records have matching fields and the input
           sequence is ascending, the lowest-sequenced record is chosen.
           If all input records have matching fields and the input
           sequence is descending, the highest-sequenced record is
           chosen.  If the matching fields are the same, the record with
           the highest priority (see Step 4b.)  is selected.

5        Control Break Check 

         If a control break occurs, the appropriate control-level
         indicator and all lower-level indicators are turned on.

6        Total-Time Operations 

         If this is the first record with control level fields, the
         program skips total-time operations.  But, if this is not the
         first record with control level fields, the program performs
         total-time calculations and output (including total-time
         overflow output).  Total-time operations are all those
         calculations with L0-L9 or LR indicator entries in the Control
         Level Field (columns 7-8) and output operations of record type
         T. These operations are done after each control break occurs or
         after the last input record is read, but before the information
         on the input record selected in Step 4 is actually made
         available for processing.  The program also sets all resulting
         indicators as specified.  If there are no more records to
         process in any of the files, the LR indicator is turned on,
         output tables and arrays are written, all files are closed and
         the program ends.

7        Data Movement 

         The program moves the data from the record selected into the
         input fields for processing.  If this is a matching record, it
         sets the matching-record (MR) indicator.  If this is a
         look-ahead record, the program reads the look-ahead fields and
         moves them into the input fields.  If input chaining is used,
         the chained file(s) are read, their records identified and their
         fields moved to the data area.

8        Detail-Time Calculations 

         The program performs detail-time calculations for the record
         specified, and returns to Step 2.  Detail-time calculations are
         those calculations not conditioned by control-level indicators
         in the Control Level Field (columns 7-8.)  Notice that these
         calculations and the detail-time output, described in Step 2,
         are both done after the information (from the record selected in
         Step 4) becomes available.  They are usually based on
         information from this record.  At this point, the program also
         turns on resulting indicators used with these calculations.

[]
Figure 1-3. The Primary Steps in the RPG Logic Cycle Substeps in the RPG Logic Cycle This section describes in detail each step of the RPG logic cycle including when indicators are turned on and off. The substeps listed below expand upon the primary logic steps discussed in the previous section and they correspond to the steps shown on the HP RPG Logic Cycle diagram (Figure 1-4) at the end of this chapter. Substep Description 1 Pre-Cycle Processing The operations in this step are performed once. They are not part of the main cycle. 1A All data areas are initialized. This includes compile-time tables and arrays and the user date (UDATE) fields obtained from the system. User indicators (U1-U8) are fetched from the specified source. The Local Data Area (LDA) is initialized with the contents of LDAFILE, if specified. The 1P and L0 indicators are turned on. All files, including TurboIMAGE databases and data sets, are opened unless the program has been suspended by the JCW RPGSUSP (see "End-of-Job Processing", Step E-2B). Preexecution-time tables and arrays are loaded into the data area. 1B If forms alignment is requested, the first output line for each print file conditioned by 1P is printed. The first-page heading records are then written to the specified files. 1C A record is read from each input (primary and secondary) file. The matching and control fields and the record indicator for each file are identified. 2 Heading and Detail-Time Output This is the beginning of the main logic cycle. 2A RPG writes all heading (except those conditioned by the 1P indicator) and detail lines whose conditions are satisfied. It turns on the appropriate overflow indicator (if used), if the overflow line is reached, and it turns off any overflow indicators that were already processed. It performs overflow processing if Fetch Overflow is specified and the overflow indicator is assigned and turned on. 2B If overflow processing was performed by the previous pass through the cycle or by Fetch Overflow, turn off the overflow indicator. If the overflow indicator was turned on because Fetch Overflow was specified and the overflow line was reached during detail calculations in the previous cycle (or during detail output time in the current cycle), leave the overflow indicator on (you can use the overflow indicator to condition Calculation Specifications during the current cycle). 2C If a halt indicator (H0-H9) is on, control goes to "Run-Time Error Processing", Step E-1. 2D The first-page indicator (1P) and the control-level indicators (L1-L9) are turned off. The L0 indicator is turned on. 2E If this is the first time through the logic cycle, control skips to Step 4A. 2F All record-identifying indicators are turned off. 2G If the last-record (LR) indicator is on, control skips to Step 6B. 3 Record Input 3A If there are no primary or secondary files defined in the program, control skips to Step 6A. (If there are no primary or secondary files, the program loops indefinitely unless the program contains Calculation Specifications that turn LR on.) 3B If the file is not an update or combined file and it contains look-ahead fields, control skips to Step 3G. (A record from the file was read before detail Calculation Specifications were performed in the previous cycle.) 3C If there are spread records defined for an input file and there are more fields to be processed before reading the next record, control skips to Step 4A. 3D A record is read from the last file processed. If this file is retrieved using a Record Address File, the data in the RAF defines the record to be selected. 3E If the file just read is at end-of-file, control skips to Step 4A. 3F If the record just read contains an unidentified record type, or an incorrect record sequence (as specified in the Group Sequence Field of the Input Specification), control skips to "Run-Time Error Processing", Step E-1. 3G If the record just read is a blank spread record, control goes back to Step 3D. 4 Record Selection 4A The next record is selected for processing. If a FORCE Calculation Specification operation was executed during the detail-time calculations in the previous pass through the cycle, the record is selected from the FORCEd file. If no matching-record processing is used, the next record is selected according to the primary/secondary processing order. If matching-record processing is used, the next record is selected according to the matching-record processing order. 4B The program determines if all end-of-file conditions are met (all records in files having an E in the End-of-File Field of the File Description Specification are processed and all matching secondary records are processed). If so, control skips to Step 6B. 4C The record-identifying indicator (associated with the record selected for processing) is turned on. 5 Control Break Check If a control break occurred for the selected input record, turn on the appropriate control-level indicator and all lower-level indicators. (A control break occurs when the value in the control-level fields of the record differs from the control fields of the previous record.) 6 Total-Time Operations 6A If this is the first time through the logic cycle or this is the first record with control fields, control skips to Step 6E; otherwise, control proceeds to Step 6C. 6B If there are no more records to process in any of the files, all control-level indicators (L1-L9 and LR) are turned on. 6C Total-time calculations are performed. If CHAIN or READ operations are used, the appropriate records are retrieved. The appropriate indicators resulting from total calculations are turned on; overflow conditions resulting from EXCPT output operations are set and Fetch Overflow processing is performed if required by EXCPT output operations. 6D Total-time lines are written. Overflow processing is performed if it was not done in Step 6C. 6E If the LR indicator is on, control skips to "End-of-Job Processing", Step E-2A. 7 Data Movement 7A Overflow lines are written for total-time then detail-time records that are conditioned by overflow indicators but that have not yet been processed by Fetch Overflow. 7B If matching fields are specified and the records match, the MR indicator is turned on; otherwise, it is turned off. When it is turned on, it remains on until the matching record is processed. 7C The data fields from the record selected in Step 4A are extracted and moved into the input data area. Field indicators, if specified, are turned on or off according to the data in the field. 7D If chaining field codes (C1-C9) are entered in the Chaining Field of one or more Input Specifications, a record is retrieved from each specified file; the appropriate record-identifying indicators are turned on; the data fields are moved to the input data area and field indicators are set. 7E If look-ahead fields are specified, the look-ahead fields are extracted and moved to the look-ahead data area. For combined and update files, the look-ahead fields are extracted from the current record; for all other files, the look-ahead fields are extracted from the next record in the file currently being processed. 8 Detail-Time Calculations Detail-time calculations are performed. If CHAIN or READ operations are used, the appropriate records are retrieved. The appropriate indicators resulting from detail calculations are turned on; overflow conditions resulting from EXCPT output operations are set and Fetch Overflow processing is performed if required by EXCPT output operations. E-1 Run-Time Error Processing E-1A If there is a pre-selected response for this error in the Header Specification, control skips to Step E-1C. E-1B The response is obtained from the computer operator or from the job file. E-1C If the response is 0 (CONTINUE), control proceeds to Step E-1D. If the response is 1 (BYPASS), control skips to Step 2B. If the response is 2 (REGULAR TERMINATION), control skips to Step 6B. If the response is 3 (IMMEDIATE TERMINATION), control skips to Step E-2F. If the response is 4 (REGULAR TERMINATE WITH DUMP), control skips to Step E-1G. If the response is 5 (IMMEDIATE TERMINATE WITH DUMP), control skips to Step E-1F. E-1D Each halt indicator (H0-H9) is tested. If an indicator is on, it is reset and control skips back to Step E-1A. E-1E Processing is resumed at the point in the logic cycle where the error occurred. E-1F An Error Dump is printed and the program skips to step E-2F. E-1G An Error Dump is printed and control skips to Step 6B. E-2 End-of-Job Processing E-2A Output tables and arrays are written. All files are closed (except when the program is in suspend mode). The settings of the user indicators (U1-U8) update the Job Control Word and the Local Data Area is written back to the LDAFILE, if specified. E-2B If the JCW RPGSUSP does not equal 1 (the program is not suspended), the program ends. E-2C Processing is suspended. Files are left open for later access. E-2D Control is transferred back to the father process. E-2E If the father process reactivates the suspended program, control begins at Step 1. E-2F Close files.


MPE/iX 5.0 Documentation