HP 3000 Manuals

The Input Specification Fields (Cont.) [ HP RPG/iX Reference Manual ] MPE/iX 5.0 Documentation


HP RPG/iX Reference Manual

The Input Specification Fields (Cont.) 

Field Name (Columns 53-58) (Cont.) 

Matching/Chaining Fields (Columns 61-62).   

This field contains either a matching or a chaining code for the field.
If you're not using matching or chaining fields, leave this field blank.

--------------------------------------------------------------------------------------------
|                           |                                                              |
|       Columns 61-62       |                         Description                          |
|                           |                                                              |
--------------------------------------------------------------------------------------------
|                           |                                                              |
|           C1-C9           | This is a chaining field identified by this code.            |
|                           |                                                              |
|           M1-M9           | This is a matching field identified by this code.            |
|                           |                                                              |
|           blank           | The field is neither a matching nor a chaining field.        |
|                           |                                                              |
--------------------------------------------------------------------------------------------

C1-C9 (Chaining fields) 

Chaining field codes let you identify the fields to be used in retrieving
records from a direct-access chained MPE file.  (A chained file can also
be a TurboIMAGE or KSAM file.)  A chaining field code marks a field as a
chaining field.  A chaining field contains addresses of records that you
want to access in a chained file.  Chaining takes place before
detail-time processing.

There are two ways to access a chained file:

   *   You can use the CHAIN Calculation Specification operation.  This
       method may be more flexible than the next method because you can
       use indicators to condition the operation.

   *   You can assign one or more chaining field codes as described in
       this section (this is called "input chaining").  This method reads
       the chained file automatically each time a record is selected for
       processing that has a chaining field.  You must enter a File
       Extension Specification to associate the chaining file to the
       chained file.

Figure 7-15  shows how chaining takes place.  A program reads a record
from a transaction (chaining) file on disk that contains a customer
number and the customer charge amount.  This file does not contain the
mailing address of the customer.  The program obtains this address by
using the chaining field (customer name) to access the customer's record
in the chained file.  At detail time in the HP RPG logic cycle, the
mailing address is retrieved and the program can print the customer
bill with mailing label.  Figure 7-16  shows how to enter the
specifications for this example using chaining field codes.

[]
Figure 7-15. Chaining to a Direct-Access File You can have up to nine chaining fields per record type. (This lets you access more than one chained file for each record.) The chaining field codes do not have a rank based on their number. You determine the order of the chaining fields by the sequence in which you enter the Input Specifications. For example, if you assign C3 to the first field in a record and C2 to the next field and C5 to the third, the chained files are read in this order: C3, C2, C5. Chaining fields can contain: * Numeric relative record addresses of records to be accessed in the chained file. * Alphanumeric or numeric keys for records to be accessed in the chained file. (The chained file must be a KSAM or TurboIMAGE file processed by key.) You can assign the same chaining field code to more than one field, creating a split chaining field. Split chaining fields are combined to form one chaining field. They can be adjoining or non-adjoining fields. The first chaining field for the specification defines the leftmost position of the combined chaining field. The last field defines the rightmost position of the combined chaining field. When assigning chaining field codes, follow these rules: 1. Do not use look-ahead fields or arrays as chaining fields. 2. Do not enter L or R (for leading or trailing arithmetic signs) in the Data Format Field (column 43). If you do, chaining field codes specified for the record type are ignored. 3. Do not intermix lines containing split chaining fields with those containing regular chaining fields. 4. If the chaining field contains relative disk addresses, the field must be defined as numeric. 5. If you want to use the same chaining field to read more than one chained file, define a separate chaining field for each file but use the same starting and ending positions for each of them. Also use different names and chaining codes. Example Figure 7-16 shows the specifications that perform the chaining illustrated in Figure 7-15 . The customer names and charge amounts are stored in the chaining file TRANSAC. The customer mailing addresses and other information are contained in the KSAM file MASTER. The first field in TRANSAC, CUST, contains the customer name and it is identified as the chaining field by the code C3. When MASTER is read, the record whose CUST field matches the name in CUST (TRANSAC) is selected. ___________________________________________________________________________________ | | | 1 2 3 4 5 6 7 | | 678901234567890123456789012345678901234567890123456789012345678901234| | _______________________________________________________ | | | | 1 FTRANSAC IP F 80 CARD | | 2 FMASTER IC F 256RI5AI 1 DISK | | | | 3 EAAC3TRANSAC MASTER | | | | ITRANSAC AA 01 80 CT | | 4 I 01 15 CUST C3 | | I 16 200RECNO | | I 21 25 AMOUNT | | IMASTER BB 02 80 CM | | I 01 15 CUST | | I 16 25 STREET | | I 25 35 CITY | | I 35 40 STATE | | I 41 45 ZIP | | | | | ___________________________________________________________________________________ Figure 7-16. Specifying Chaining Fields Using the Input Specification M1-M9 (Matching fields) You can use matching fields with sequential primary and secondary files having any file organization (when you do, these files are called matching files). Matching field codes perform two functions in a program, depending on the number of files to which you assign them. These functions are summarized below and are explained in detail in the paragraphs which follow: * When used with one file, they identify the fields to be sequence-checked if the Input Sequence Field (column 18) of the File Description Specification requests sequence-checking. * When used with two or more files, they identify the fields to be matched on input. If you use matching field codes for only one file in a program, they identify the fields to be sequence-checked. (You can sequence-check input, combined and update files only.) You can use one or all of the matching field codes. If you use more than one, the fields are treated as a single control field. The fields associated with the higher matching field codes come first, followed by the lower-ranking ones. For example, the field associated with M9 comes first followed by the field associated with M8 and so on. Be sure that the Input Sequence Field (column 18) of the File Description Specification specifies the sequence you want to use. If a sequence error occurs, an error message is printed and the error response specified by the Error Response Field (columns 56-71) of the Header Specification, if any, is performed. Example Figure 7-17 shows how to assign matching field codes to three fields (DEPT, DIV and BRANCH) in the file INFILE. M3 is assigned to the major control field, BRANCH. If INFILE contained the following three records and if ascending sequence is specified for the file in column 18 of the File Description Specification, the DIV code in the third record will cause a sequence error. DEPT: DIV: BRANCH: 003 005 01 002 006 01 001 004 01 ___________________________________________________________________________________ | | | 1 2 3 4 5 6 7 | | 678901234567890123456789012345678901234567890123456789012345678901234| | _______________________________________________________ | | | | IINFILE | | I 1 10 IDNO | | I 21 30 DEPT M1 | | I 31 40 DIV M2 | | I 41 45 BRANCH M3 | | | | | ___________________________________________________________________________________ Figure 7-17. Using Matching Field Codes to Sequence-Check a File When you assign matching field codes to fields in more than one file, the fields are used as control fields for matching-record processing. Normally (when you do not specify matching-record processing), records are not matched; all records in the primary file are processed first, then records from each secondary file are processed in the order in which you enter them in the File Description Specifications (this is called the "primary/secondary processing order"). When using matching-record processing (when you enter matching code fields for two or more files), records are selected for processing in the order of the matching fields (this is called the "matching-record processing order"). When the matching fields are equal, the matching-record indicator (MR) is turned ON and operations conditioned by the MR indicator are performed. All matching records in the primary file are processed first followed by matching records in the secondary file, in the order in which the File Specifications are entered. Figure 7-18 illustrates how matching-record processing works and the narrative below describes it in detail. 1. The first record in each input, update or combined primary and secondary file is read. A record is selected and processed through the logic cycle. 2. At the start of the next cycle, the next record from the file just processed is read. 3. If one of the files is forced (see the FORCE Calculation Specification operation), its record is selected. 4. If a file does not use matching fields and it is a primary file, its record is selected. If not, the record from the first secondary file is selected. 5. If all of the files use matching fields, the fields are compared. If you specified an alternating collating sequence, fields are compared using that sequence. If a sequence error occurs, the response that you entered in the Error Response Field (column 56-71) of the Header Specification, if any, is performed. If the fields do not match and the records are in ascending order, the record with the lowest matching field is selected. If the records are in descending order, the record with the highest matching field is selected. If the fields are equal, the record from the primary file is selected, followed by any other records from the primary file having the same matching field value. Secondary records are processed next in the order in which their File Description Specifications are entered. The matching-record (MR) indicator is turned ON before detail-time Calculation Specification processing. It remains ON (unless you turn it OFF with a Calculation Specification operation) until this point in the next cycle.
[]
Figure 7-18. Matching-Record Processing When you use matching field codes, follow these rules: 1. For each matching file, enter the same sequence in the Input Sequence Field (column 18) of the File Description Specification. 2. Assign matching field codes to at least one record type in two or more files. If you do not, matching-record processing does not take place. When you use more than one matching field code, all fields in the control group must match before the MR indicator is turned ON. If you assign M5, M4, M3 and M2, all four fields from the primary file must match all four fields from the secondary file. You do not have to assign matching field codes to each record type in a file. When any matching field (that has the same matching field code) is numeric, all of them are treated as numeric. For example, if one matching field contains 03 and another contains _3, they are considered equal. Also, arithmetic signs and decimal points are ignored in matching fields. For example, a field containing 7 is considered equal to a field containing -0.07. 3. Use the same matching field codes for each matching file. The field names to which you assign them, however, do not have to be the same (field names are not used in matching). 4. Be sure that all fields with the same code are the same length and contain the same format (alphanumeric or numeric). Matching fields in binary format are not allowed. 5. Make sure that the combined length of all matching fields does not exceed 256. 6. When you use more than one code, assign them to fields in the order you want these fields combined to form the control field. The fields are combined in the order M9 to M1. For example, if M3 is assigned to field XXX, M7 is assigned to ZZZ and M1 is assigned to YYY, the fields are combined as follows: ZZZXXXYYY 7. Do not assign the same matching field code to more than one field within a record type. Matching fields cannot be split in this manner. Example Figure 7-19 shows how to assign matching field codes to fields in the files ALPHA and BETA. M1 is assigned to field DATA1 in file ALPHA and to field DATA4 in file BETA. M2 is assigned to field DATA2 in file ALPHA and to field DATA3 in file BETA. When the contents of these matching fields are equal, the MR indicator is turned ON. ___________________________________________________________________________________ | | | 1 2 3 4 5 6 7 | | 678901234567890123456789012345678901234567890123456789012345678901234| | _______________________________________________________ | | | | IALPHA AA 01 80 CA | | I 1 5 DATA1 M1 | | I 6 10 DATA2 M2 | | IBETA BB 021 80 CB | | I 21 25 DATA3 M2 | | I 31 35 DATA4 M1 | | | | | ___________________________________________________________________________________ Figure 7-19. Assigning Matching Field Codes Field Record Relation (Columns 63-64). When you use OR lines to define record types, and some of the fields are not contained in all types, you can enter an indicator in this field to associate those input fields with the appropriate record type. -------------------------------------------------------------------------------------------- | | | | Columns 63-64 | Description | | | | -------------------------------------------------------------------------------------------- | | | | 01-99 | General indicator that relates this field to a specific record | | | type. | | | | | F0-F9 | Function key indicator that relates this field to a specific | | | record type. | | | | | H1-H9 | Halt indicator that relates the field to a specific record type. | | | | | KA-KN, | Command key indicator that regulates the acceptance of data from | | KP-KY | the file. | | | | | L1-L9 | Control-level indicator that regulates acceptance and use of | | | data from t if a control break occurs. Data is accepted only | | | when the indicator is turned ON. | | | | | LR | Last-record indicator that relates the field to a specific | | | record type. | | | | | MR | Matching-record indicator that regulates use and acceptance of | | | data from matching field. Data is accepted only when the | | | indicator is turned ON. | | | | | OA-OG, OV | Overflow indicator that relates the field to a specific record | | | type. | | | | | U1-U8 | User indicator that conditions the use of the field. | | | | | 1P | First-page indicator, used as a general indicator, that relates | | | the file to a specific record type. | | | | | blank | The field appears in all record types for this OR relationship. | | | | -------------------------------------------------------------------------------------------- When using OR lines, you define a field once even though it appears in different record types. This eliminates duplicate coding for those fields that are identical. To distinguish a field that is unique, associate an indicator with it using this field. Use the same indicator that you associated with the record type in the Record Indicator/Look-Ahead/Trailer/Data Structure Field (columns 19-20). When the indicator is ON, it conditionally identifies the field as belonging to the associated record type. (See the RPG logic cycle section in the HP RPG Programmer's Guide for details on how the indicators are used.) For example, you can use the general indicator 10 in this field. This associates the field with the record type having indicator 10 in columns 19-20. When two control fields (or matching fields) have the same control-level indicator (or matching field code), you can enter an indicator in one of these fields or both of them. Only the field associated with the indicator that is ON is used. The field that does not have an indicator associated with it is used (if defined first) when the indicator is turned OFF. When you enter an indicator with control-level, matching or chaining fields, follow these rules: 1. Enter specifications that do not use this field before those that do. 2. Enter an indicator for matching and control-level fields that matches the record-identifying indicators for the record type. 3. Group all fields together that relate to one record type. Within the groups, you can enter the fields in any order. 4. Assign the same indicator to all fields that belong to a split control field. Define them together as a group. Example Figure 7-20 defines the file INPUT that contains two different types of records. The general indicator 01 specifies that the field ALPHA belongs to record type A. GAMMA and DELTA also belong to record type A because they do not have an indicator associated with them. The general indicator 02 specifies that the field BETA belongs to record type B. Since GAMMA and DELTA do not have an indicator associated with them, they also belong to record type B. ___________________________________________________________________________________ | | | 1 2 3 4 5 6 7 | | 678901234567890123456789012345678901234567890123456789012345678901234| | _______________________________________________________ | | | | IINPUT AA 01 1 CA | | I OR 02 1 CB | | 1 I 2 5 ALPHA 01 | | 2 I 6 10 BETA 02 | | I 11 15 GAMMA | | I 16 20 DELTA | | | | | ___________________________________________________________________________________ Figure 7-20. Using Indicators to Associate Fields with Record Types Field Indicators (Columns 65-70). This field lets you test for positive values, negative values, zeros or blanks in the field. ----------------------------------------------------------------------------------------------- | | | | | Column | Value | Description | | | | | ----------------------------------------------------------------------------------------------- | | | | | Plus (65-66): | 01-99, F0-F9, H1-H9, | The indicator used for | | | KA-KN, KP-KY, | testing numeric fields for | | | L1-L9, LR, MR, | positive data. | | | OA-OG, OV, | | | | U1-U8, 1P | | | | | | | | blank | Do not test data in this | | | | field. | | | | | | Minus (67-68): | 01-99, F0-F9, H1-H9, | The indicator used for | | | KA-KN, KP-KY, | testing numeric fields for | | | L1-L9, LR, MR, | negative data. | | | OA-OG, OV, | | | | U1-U8, 1P | | | | | | | | blank | Do not test data in this | | | | field. | | | | | | Zero or Blank (69-70): | 01-99, F0-F9, H1-H9, | The indicator used for | | | KA-KN, KP-KY, | testing numeric fields for | | | L1-L9, LR, MR, | zeros or blanks or | | | OA-OG, OV, | alphanumeric fields for | | | U1-U8, 1P | blanks. | | | | | | | blank | Do not test data in this | | | | field. | | | | | ----------------------------------------------------------------------------------------------- When you enter an indicator in this field, it is turned ON when the condition that you're testing for is true. It is OFF when the condition is not true. For instance, you can use a halt indicator to check a field for a negative quantity. When a negative quantity is encountered, the indicator turns ON and causes a halt at the end of the current cycle (unless you entered a pre-response in the Error Response Field (columns 56-71) of the Header Specification. When using indicators in this field, remember that: 1. An indicator used for positive or negative testing is OFF when the program begins. It is turned ON when a record is read containing a positive or negative value in the field. 2. An indicator used for zero or blank testing is OFF when the program begins, unless you turn it ON by using the Indicator Setting Field (column 42) of the Header Specification. It is turned ON when a record is read that contains zeros or blanks in the field. 3. When you assign two or three field indicators to one input field, only the indicator which tests for the true condition is turned ON; the others are turned OFF. 4. When you assign the same indicator to fields in different record types, its ON/OFF status reflects the current record being processed. The indicator remains ON until the field no longer meets the testing criteria of the indicator. 5. You can turn indicators ON and OFF with the SETON and SETOFF Calculation Specification operations. Example Figure 7-21 shows how to use field indicators to test input data. The field POSDAT is tested for positive values. NEGDAT is tested for negative numbers and the field NODAT is tested for zeros or blanks. When any of the conditions are true, calculations and output conditioned by the indicators are performed. ___________________________________________________________________________________ | | | 1 2 3 4 5 6 7 | | 678901234567890123456789012345678901234567890123456789012345678901234| | _______________________________________________________ | | | | IINPUT AA 01 1 CY | | I OR 02 1 CZ | | 1 I 1 102POSDAT 0110 | | 2 I 11 152NEGDAT 02 11 | | 3 I 16 202NODAT 12 | | | | | ___________________________________________________________________________________ Figure 7-21. Using Field Indicators to Test Input Data Program Name (Columns 75-80) This field contains the program name. The format for this field is discussed in Chapter 2.


MPE/iX 5.0 Documentation