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) 

File and Record Description Fields (columns 7-41) (Cont) 

Record Identification Codes (Columns 21-41).   

When a file contains more than one record type and the program processes
each type differently, you must assign a unique code to each type using
this field.  The code that you assign must exist in one or more data
records in the file.  (When a file contains just one type of record or
when each type is processed the same way, leave this field blank.)

-----------------------------------------------------------------------------------------------
|                       |                   |                                                 |
|        Column         |       Value       |                   Description                   |
|                       |                   |                                                 |
-----------------------------------------------------------------------------------------------
|                       |                   |                                                 |
| Position:             |      1-9999       | The position (relative to the first position of |
| (columns 21-24, 28-31,| (right-justified, | the record) where this identification code      |
| 35-38)                | leading zeros are | character appears in the input record.          |
|                       |   not required)   |                                                 |
|                       |                   |                                                 |
|                       |       blank       | A record identification code does not apply.    |
|                       |                   |                                                 |
| Not:                  |         N         | The character, zone, or digit must not be       |
| (columns 25, 32, 39)  |                   | present in the location specified by the        |
|                       |                   | Position subfield.                              |
|                       |                   |                                                 |
|                       |       blank       | A character, zone, or digit must be present.    |
|                       |                   |                                                 |
| Portion:              |         C         | Use the entire character (zone and digit        |
| (columns 26, 33, 40)  |                   | portions) for the record identification code.   |
|                       |                   |                                                 |
|                       |         D         | Use only the digit portion of the character for |
|                       |                   | the record identification code.                 |
|                       |                   |                                                 |
|                       |         Z         | Use only the zone portion of the character for  |
|                       |                   | the record identification code.                 |
|                       |                   |                                                 |
|                       |       blank       | No character applies.                           |
|                       |                   |                                                 |
| Character:            |    Any letter,    | Test for this character (on input) in the       |
| (columns 27, 34, 41)  | digit, or special | location specified by the Position subfield.    |
|                       |     character     |                                                 |
|                       |                   |                                                 |
|                       |       blank       | No character applies in this position.          |
|                       |                   |                                                 |
-----------------------------------------------------------------------------------------------

You can use one or more Input Specifications to assign record
identification codes.  To assign from one to three characters, use one
Input Specification.  Enter the first character in column 27 and describe
it in columns 21-26.  Enter the second character in column 34 and
describe it in columns 28-33.  Enter the third character in column 41 and
describe it in columns 35-40.  Enter AND (columns 14-16) lines when the
record identification codes are longer than three characters.  Use OR
(columns 14-16) lines to assign more than one record identification code
to the same record type.

When a record identification code is recognized at run time, the
record-identifying indicators associated with the record type (see the
Record Indicator/Look-Ahead/Trailer/Data Structure Field, columns 19-20)
are turned ON. If a record meets the requirements of more than one record
type, it is processed according to the first record type listed in the
program.

Portion (Columns 26, 33, 40) 

This field lets you specify which portion of the record identification
code character to use in identifying the record type.  You can use the
entire character, the zone portion, or the digit portion.

Normally, RPG compares record identification codes in ASCII. If you want
to compare using the EBCDIC character set, enter an E in the EBCDIC
Zone/Digit Tests Field (column 39) of the Header Specification.
(Appendix D lists the ASCII and EBCDIC collating sequences.)

C (Character) 

The character in the data record is compared to the entire character
(each of the eight bit positions) that you enter in column 27, 34, or 41.
The corresponding record-identifying indicator is turned ON only when all
bit positions match.

D (Digit) 

The low-order four bits (digit portion) of the character in the data
record are compared to the low-order four bits of the character that you
enter in column 27, 34, or 41.  If these bits match, regardless of
whether the zone portion matches, the corresponding record-identifying
indicator is turned ON. For example, if you enter A in column 27, the
data characters Q and 1 will result in a match and cause the associated
record-identifying indicator to turn ON.

Z (Zone) 

The high-order four bits (zone portion) of the character in the data
record is compared to the high-order four bits of the character that you
enter in column 27, 34, or 41.  If each zone bit matches, the
corresponding record-identifying indicator is turned ON. For example, if
you enter A in column 27, the letters B through O will result in a match
and cause the associated record-identifying indicator to turn ON.

Example 

Three examples of record identification codes appear in the Input
Specification in Figure 7-11 .  The first record type (line 1) has the
letter A in position 1.  The second record type (line 2) includes all
records with an F in position 3 and any character except D in position 2.
The third record type (line 3) contains a character in position 4 whose
zone portion matches the letter T.
___________________________________________________________________________________
|                                                                                 |
|                1         2         3         4         5         6         7    |
|            678901234567890123456789012345678901234567890123456789012345678901234|
|              _______________________________________________________            |
|                                                                                 |
|     1     IANYFILE AA  01   1 CA                                                |
|            I        .                                                           |
|     2     I        BB  02   2NCD   3 CF                                         |
|            I        .                                                           |
|     2     I        CC  03   4 ZT                                                |
|                                                                                 |
|                                                                                 |
___________________________________________________________________________________

          Figure 7-11.  Record Identification Codes 

Field Description Fields (Columns 43-70) 

These fields describe the data fields within the records defined by the
File and Record Description Fields (columns 7-41).  Data fields include
arrays and array elements.

Enter fields on separate lines, starting with the line immediately
following the line that contains the File and Record Description Fields
for the record.  Leave columns 7-42 blank.  You only need to define those
fields actually used in the program.  See Figure 7-2  for an example
of how to enter Field Description Fields.

Data Format (Column 43).   

This field describes the format of numeric fields as they exist in the
input file.  Do not enter a value into this field for alphanumeric or
unpacked (external) decimal fields.

--------------------------------------------------------------------------------------------
|                       |                                                                  |
|       Column 43       |                           Description                            |
|                       |                                                                  |
--------------------------------------------------------------------------------------------
|                       |                                                                  |
|           B           | Binary format (1 or 2 word integer).                             |
|                       |                                                                  |
|           L           | Unpacked decimal format with leading plus or minus sign.         |
|                       |                                                                  |
|           P           | Packed decimal format.                                           |
|                       |                                                                  |
|           R           | Unpacked decimal format with trailing plus or minus sign.        |
|                       |                                                                  |
|          1-9          | The number of digits required by a binary field for internal     |
|                       | computation.                                                     |
|                       |                                                                  |
|         blank         | Alphanumeric or unpacked decimal (with no leading or trailing    |
|                       | signs) format.  For unpacked decimal format, enter a digit (0-9) |
|                       | in the Decimal Positions Field (column 52).  For alphanumeric    |
|                       | format, leave column 52 blank.                                   |
|                       |                                                                  |
--------------------------------------------------------------------------------------------

If a numeric field is not defined as a packed decimal (P) field, it is
converted to that format once it is read from the input file.  Internal
operations use packed decimal format because it is more efficient.
Additionally, when an alphanumeric field is moved to a numeric field or
used in computations, it is converted to packed decimal format with the
low-order position determining the sign:

If the low-order position is:         The sign is: 

0-9                                   Unsigned - hexadecimal F (1111)

{ or A-I                              Positive - hexadecimal C (1100)

} or J-R                              Negative - hexadecimal D (1101)

For example, the number -256 looks like this when represented in
alphanumeric (ASCII) format:

     bits:   0 0 1 1   0 0 1 0    0 0 1 1   0 1 0 1    0 1 0 0   1 1 1 1
             --------|--------    --------|--------    --------|--------
             <----  byte  ---->   <----  byte  ---->   <----  byte  ---->

                      2                   5                    0  

Since the ASCII representation of the low-order character is O, the field
is assumed to be negative and looks like this when converted to packed
decimal:

     bits:   0 0 1 0   0 1 0 1    0 1 1 0   1 1 0 1
             --------|--------    --------|--------
             <----  byte  ---->   <----  byte  ---->

                 2        5           6        D  

Similarly, if the number 256 has a positive sign in low-order digit
(25F), it is assumed to be positive when converted to packed decimal and
looks like this:

     bits:   0 0 1 0   0 1 0 1    0 1 1 0   1 1 0 0
             --------|--------    --------|--------
             <----  byte  ---->   <----  byte  ---->

                 2        5           6        C  

B (Binary Format) 

Numbers are represented in two's complement form.  A field is either two
or four bytes long.

The two-byte format, also known as fixed-point format, lets you store
positive and negative integers in the range -32,768 to +32,767.  Bit 0 of
the high-order byte is the sign bit.  It is 0 for positive numbers and 1
for negative numbers.  The remaining bits (1-15) are used for the
integer.  The following example shows how the number 256 is stored.

     bits:   0 0 0 0   0 0 0 1    0 0 0 0   0 0 0 0
             --------|--------    --------|--------
             <----  byte  ---->   <----  byte  ---->

                               256  

The four-byte format, also a fixed-point format, is the same as the
two-byte format except that the four bytes allow 32 bits for the integer.
Bit 0 of the high-order byte is the sign bit.  You can store positive and
negative integers in the range -2 billion to +2 billion.

L (Unpacked Decimal Format With Leading Sign) 

This format requires one byte (8 bits) to store each digit of the
integer.  It is the same as unpacked decimal format (see the description
for the "blank" entry) except that the first byte is reserved for the
sign.  For negative numbers, it is the ASCII negative sign (see the
beginning of this section).  For positive numbers, it can be any
character.  For example, a field which is located in positions 11-15 of a
record has the sign in position 11 and the integer value in positions
12-15.

P (Packed Decimal Format) 

Each byte of the field is divided into two parts - each holding one
digit.  This format saves memory because only four bits are required for
each digit.  The low-order four bits of the low-order byte contains the
sign.  If the number is negative, the sign bits are 1101 (the character D
in hexadecimal).  If the number is positive, the sign bits are 1100 (the
character C in hexadecimal), though any bit configuration except 1101 is
considered positive.  For example, the number 256 is stored as follows:

     bits:   0 0 1 0   0 1 0 1    0 1 1 0   1 1 0 1
             --------|--------    --------|--------
             <----  byte  ---->   <----  byte  ---->

                 2        5           6        D  

R (Unpacked Decimal Format With Trailing Sign) 

This format requires one byte (8 bits) to store each digit of the
integer.  It is the same as unpacked decimal format (see the description
for the "blank" entry) except that the last byte is reserved for the
sign.  For negative numbers, it is the ASCII negative sign (see the
beginning of this section).  For positive numbers, it can be any
character.  For example, a field which is located in positions 11-15 of a
record has the sign in position 15 and the integer value in positions
11-14.

1-9 (Internal Binary Digits) 

When a binary field is converted to packed decimal format for internal
use, RPG assumes that it contains either 5 or 10 digits.  If you want to
reduce or expand the number of digits during internal calculations, enter
the appropriate number in this column.  For example, if the field is used
in calculations that can result in a larger number, enter the number of
digits for that number in this field.

Blank (Unpacked Decimal and Alphanumeric Formats) 

The field contains unpacked decimal or alphanumeric data.  Unpacked
decimal fields can contain any number and alphanumeric fields can contain
any alphabetic, numeric or special character.  Both types of data have
ASCII representation and each character in the fields occupy an eight-bit
byte.

In unpacked decimal format, the unsigned number 256 appears as follows:

     bits:   0 0 1 1   0 0 1 0   0 0 1 1   0 1 0 1   0 0 1 1   0 1 1 0
             --------|--------   --------|--------   --------|--------
             <----  byte  ---->  <----  byte  ---->  <----  byte  ---->

                     2                   5                   6  

From Field Position (Columns 44-47).   

This field defines where the data field starts in the input record.  This
field is required.

--------------------------------------------------------------------------------------------
|                                    |                                                     |
|           Columns 44-47            |                     Description                     |
|                                    |                                                     |
--------------------------------------------------------------------------------------------
|                                    |                                                     |
|               1-9999               | The beginning position of the field in the input    |
|         (right-justified,          | record.                                             |
|         leading zeros are          |                                                     |
|           not required)            |                                                     |
|                                    |                                                     |
--------------------------------------------------------------------------------------------

To Field Position (Columns 48-51).   

This field defines the last position of the data field.  This field is
required.

--------------------------------------------------------------------------------------------
|                                    |                                                     |
|           Columns 48-51            |                     Description                     |
|                                    |                                                     |
--------------------------------------------------------------------------------------------
|                                    |                                                     |
|               1-9999               | The ending position of the field in the input       |
|         (right-justified,          | record.  The maximum length for alphanumeric fields |
|         leading zeros are          | is 256 characters; for numeric fields, 15 digits.   |
|           not required)            |                                                     |
|                                    |                                                     |
--------------------------------------------------------------------------------------------

Enter a position relative to the first position of the record.  It must
be greater than or equal to the number in the From Field (columns 44-47)
and it must fall within the record length defined in the File Description
Specification.  (A one position field contains the same number in both
this field and the From Field.)

If you want to process part of an input array only, enter only those
positions in the From Field and this field that you want to use.

Decimal Positions (Column 52).   

This field specifies the number of decimal positions that a numeric field
contains.  Do not enter a value into this field for alphanumeric fields.
This field is required for numeric fields.

--------------------------------------------------------------------------------------------
|                                    |                                                     |
|             Column 52              |                     Description                     |
|                                    |                                                     |
--------------------------------------------------------------------------------------------
|                                    |                                                     |
|                0-9                 | The number of decimal positions in the field (not   |
|                                    | to exceed the number of digits in the field).       |
|                                    |                                                     |
|               blank                | The field contains alphanumeric data.               |
|                                    |                                                     |
--------------------------------------------------------------------------------------------

This field indicates where the decimal point belongs in the field,
although no actual decimal point appears there.  If this is an array, you
can leave this field blank but you must enter the number of decimals for
it in the Decimal Positions Field (column 44) of the File Extension
Specification.

Field Name (Columns 53-58) 

This field names the field, array or array element defined by the
specification.  Every field must have a name; you use this name in the
program to reference the field.

---------------------------------------------------------------------------------------------
|                                                          |                                |
|                      Columns 53-58                       |          Description           |
|                                                          |                                |
---------------------------------------------------------------------------------------------
|                                                          |                                |
| Field name.  (This can be a name of up to six            | The name of the input field.   |
| characters, beginning with a letter or @, $, or #; the   |                                |
| remaining characters can be letters, digits, or @, $, or |                                |
| #.  Embedded blanks are not allowed.)                    |                                |
|                                                          |                                |
| Array name.  (This can be a name of up to six            | The name of the input array.   |
| characters, beginning with a letter or @, $, or #; the   | (The name must have previously |
| remaining characters can be letters, digits, or @, $, or | been defined as an array on    |
| #.  Embedded blanks are not allowed.)                    | the File Extension             |
|                                                          | Specification.)                |
|                                                          |                                |
| Array name, comma, and index.  The array name is the     | The name of the input array    |
| same as described above.  The index is either a number   | item.  The name must be        |
| or the name of a field (see the field name entry above)  | defined as an array in the     |
| that contains a number.  The array name/comma/index      | File Extension Specification.  |
| combination is limited to six characters.                |                                |
|                                                          |                                |
| PAGE, or PAGE1 through PAGE7                             | The name of a field that       |
|                                                          | provides the page number for   |
|                                                          | output files.                  |
|                                                          |                                |
| *ERROR                                                   | The name of one-character      |
|                                                          | field used for run-time error  |
|                                                          | codes.                         |
|                                                          |                                |
---------------------------------------------------------------------------------------------

Field Name 

Enter a name for the field.

Normally, you assign unique names to fields that have the same record
type.  If you use duplicate names, only the last field can be accessed
using the name.

If you use the same field name in more than one record type, be sure the
fields have the same field length, data format and number of decimal
positions.  The fields can have different beginning locations.  If the
fields are in the same locations in the records, you can save time by
using OR lines to define them (see the following example).

Example 

Figure 7-12  shows how to assign the names FIELD1, FIELD2 and FIELD3
to three fields in the file FILEX (the names start in line 1).

The example also shows how to use the same field names for fields in two
different record types in the file FILEX. The field names are FIELDA,
FIELDB, and FIELDC and their definitions begin with line 3.  The OR line
is used to avoid defining the fields twice.  The fields have the same
length on both record types and are located in the same positions.
___________________________________________________________________________________
|                                                                                 |
|                1         2         3         4         5         6         7    |
|            678901234567890123456789012345678901234567890123456789012345678901234|
|              _______________________________________________________            |
|                                                                                 |
|            IFILEX   AA  01   1 CA                                               |
|     1     I                                       11  20 FIELD1                 |
|            I                                       21  30 FIELD2                |
|            I                                       31  40 FIELD3                |
|            I        BB  02   1 CB                                               |
|     2     I       OR   03   1 CC                                                |
|     3     I                                       11  20 FIELDA                 |
|            I                                       21  30 FIELDB                |
|            I                                       31  40 FIELDC                |
|            I                                        .                           |
|            I                                        .                           |
|                                                                                 |
|                                                                                 |
___________________________________________________________________________________

          Figure 7-12.  Entering Field Names 

Array Name 

When you want to read an entire array, enter the array name in this
field.  To read a portion of the array, enter the array name with an
index (see the next paragraph).

Array Name, Comma, Index 

To read one element in an array, enter the array name and an index.  The
index specifies the element to read.  To read more than one element, but
not the entire array, enter an index that specifies the starting location
of the first element, then in the From Field Position Field (columns
44-47) and the To Field Position Field (columns 48-51) enter the total
number of characters to read.

The index can be a number or a field that contains a number.  If you
enter a field for the index, it must be a numeric field containing no
more than 9 digits.  The field must not have decimal positions.  If the
index is an input field, you must have defined it on a previous Input
Specification (its value should be read before you use it as an index;
otherwise, the value from the previous record is used).  If you're
calculating the value for the index field in a Calculation Specification
operation, make sure you perform the operation before using the field as
an index.

PAGE, PAGE1-PAGE7 

Using the field PAGE in an Input Specification lets you change the length
and initial value of the field PAGE. PAGE is a predefined four-digit
field which is set to zeros.  It is used for printing page numbers in
report files.

Normally, you use the field PAGE only in Output Specifications for
printing the page number (see the Field Name Field (columns 32-37).  Page
numbering starts with one and continues to 9999.  Defining PAGE in an
Input Specification lets you override these defaults.  You can specify
any length for the field, but it must be a numeric field without decimal
positions.  Pagination starts with the number you enter in PAGE, plus
one.  For example, if you set PAGE to 9, the first page number is 10.

You can define PAGE as a field in a regular data file, as part of a data
structure, or in a file by itself.  If it is part of a data record, its
value changes each time a record is read from the file and pagination
restarts with the new value.  Place the value for PAGE in the input
record right-justified.  Leading zeros are not required.

If you have more than one report file, and you want to override the
pagination defaults for them (as described for PAGE), use any of the
names PAGE1 through PAGE7.

Example 

Figure 7-13  shows how to define PAGE so that its value is read from
the input file PAGENO. PAGE is five characters long in the record.
___________________________________________________________________________________
|                                                                                 |
|                1         2         3         4         5         6         7    |
|            678901234567890123456789012345678901234567890123456789012345678901234|
|              _______________________________________________________            |
|                                                                                 |
|            IPAGENO  CC  04   1 CP                                               |
|     1     I                                        2   60PAGE                   |
|                                                                                 |
|                                                                                 |
___________________________________________________________________________________

          Figure 7-13.  Entering the PAGE Field Name 

*ERROR 

*ERROR is a predefined, one-character alphanumeric field.  When a
run-time error occurs that does not cause the program to terminate, RPG
places a unique character in *ERROR that identifies the error.  If you
enter this field in an Input Specification, you can interrogate it to
determine the cause of the error.  (See Appendix B for the values that
are placed in *ERROR for various run-time errors.)

If, for some reason, you want to overwrite *ERROR, define it with a
length of one using the From Field Position Field (columns 44-47) and the
To Field Position Field (columns 48-51).

Control Level (Columns 59-60).   

This field assigns a control-level indicator to the field.  You can
assign control-level indicators to fields in primary and secondary files.
Do not assign them to look-ahead or trailer fields or to fields in
chained or demand files.

--------------------------------------------------------------------------------------------
|                           |                                                              |
|       Column 59-60        |                         Description                          |
|                           |                                                              |
--------------------------------------------------------------------------------------------
|                           |                                                              |
|           L1-L9           | Assign this control-level indicator to the field.            |
|                           |                                                              |
|           blank           | The field is not a control field.                            |
|                           |                                                              |
--------------------------------------------------------------------------------------------

A control-level indicator identifies a control field in the file.  When
the value in the control field changes on input, a new control group 
begins and a control break occurs.  When a control break occurs, the
control-level indicator is turned ON along with all indicators of lower
rank (see the next paragraph) and all calculation and output operations
associated with the indicator(s) are performed.  Use control-level
indicators to condition:

   *   Operations for the first record of a new control group.

   *   Operations to be performed after all records in a control group
       are read.

   *   Total and subtotal output operations.

You can assign control-level indicators in any sequence.  For example,
you can assign L5, L1 and L7 in that order and omit the others.  However,
within an indicator range such as L1-L9, the indicator's number indicates
its rank.  For example, L9 is ranked higher than L8, L8 higher than L7,
and so forth.  When a control break associated with L9 occurs, all
lower-ranked indicators (L8 to L1) are also turned ON. When you assign
control-level indicators, associate them with the field that corresponds
to their rank in the control field group.  For example, in a
city/county/state control field group, where state is the highest control
field, L3 can be assigned to the state field, L2 to the county field and
L1 to city field.

The control-level indicator L0 is always turned ON. You cannot assign it
to a control field, but you can use it to condition Calculation
Specification operations.  The LR indicator is turned ON when the last
record is read.  When it is turned ON, L1-L9 are also turned ON.

A control break often occurs for the first record in a file because the
control field is compared to a field of blanks or zeros.  When this
happens, total-time calculations and output operations are suppressed.

Arithmetic signs and decimal positions are ignored when numeric control
fields are compared.  For example, if one control field contains +5 and
another contains -5, the fields are considered equal.  Similarly, 2.11 is
equal to 211.

You can combine several fields to form one control field.  You do this by
defining them in the Input Specifications and assigning the same
control-level indicator to them.  (The fields are called split control 
fields.)  If you're using split control fields (that have the same
control-level indicator) in more than one file, the total length of the
split control fields in each file must be the same.  If the split control
fields are in the same record type, they may be separated by other
fields, but they cannot be intermixed with other control-level fields.
The maximum length for a split control field is 256 characters.

You can assign the same control-level indicator to fields in different
files.  Control breaks occur the same as if the fields were in the same
file.  For example, if L3 is assigned to a field in one file and L3 is
assigned to a field in another file, a change in either of these fields
turns ON L3 and causes a control break.

Example 

Figure 7-14  shows how to enter the Input Specifications for a program
that prints a voter count by county, city and precinct.  The file VOTERS
contains voter registration data for a particular state.  The fields on
each input record specify the voter's name, street address, city, county,
and precinct.  After each record in VOTERS is read, the program
increments the voter count in the precinct by 1.  When the last record in
a precinct is read, a control break occurs because the contents of the
PRECNT field (line 3), associated with the L1 indicator, changes.  The
operations conditioned by the L1 indicator are then performed.  The
program prints the total number of voters in the precinct, adds this
value to a value counter for total voters in the city, and clears the
precinct counter.

When the contents of the control field CITY (line 1) changes, a higher
level control break occurs because L2 and L1 are turned ON. The program
now performs the operations conditioned by both indicators.  It prints
the number of voters in the precinct, adds this value to the city
counter, prints the number of voters in the city, adds the contents of
the city counter to the county counter, and then clears both the precinct
and city counters.

When the contents of the COUNTY field (line 2) change, L3, L2 and L1 are
turned ON. Totals for the county, in addition to those for the city and
precinct, are calculated and printed.

Finally, when end-of-file is encountered for VOTERS, the program turns ON
the last-record (LR) indicator.  It then performs all operations
conditioned by this indicator (and indicators L1-L9), such as calculating
and printing the total number of voters in the state as well as those for
precinct, city, and county.  The program then ends.
___________________________________________________________________________________
|                                                                                 |
|                1         2         3         4         5         6         7    |
|            678901234567890123456789012345678901234567890123456789012345678901234|
|              _______________________________________________________            |
|                                                                                 |
|            IVOTERS  AA  01   1 CA                                               |
|            I                                        5  25 NAME                  |
|            I                                       26  30 ADDR                  |
|     1     I                                       31  35 CITY  L2               |
|     2     I                                       36  40 COUNTYL3               |
|     3     I                                       41  45 PRECNTL1               |
|                                                                                 |
|                                                                                 |
___________________________________________________________________________________

          Figure 7-14.  Using Control-Level Indicators in a Voter Count Program 



MPE/iX 5.0 Documentation