• Keine Ergebnisse gefunden

Positive sign l

Im Dokument RPG II (Seite 155-160)

Packed Decimal Format:

Zoned Decimal Format: 2

I I

a 8

I

0000 I 1000

I I I

1 .

I

1

2 bytes

9

I

0001 I 1001

I

I

0001 I

I

Positive sign l

- - - 3 bytes

---~

+ 8 + 4

I I

:

Positive

Zone Zone Zone Zone 1

t l 8 l J 9 sign

I

+ 2

I

---5

bytes---~

I

+

I

ITo obtain the numeric value of a positive binary number, add the values of the bits that are on (1); the sign bit is not included. To obtain the numeric value of a negative binary number, add the values of the bits that are off (0) plus one; the sign bit is not included.

21f 8.191 is read into storage as a zoned decimal field, it occupies 4 bytes. However, if it is converted to packed decimal format, it occupies 3 bytes; then when it is converted back to zoned decimal format, it occupies 5 bytes.

Figure 7-16. Binary, Packed Decimal, and Zoned Decimal Representation of 8,191

7 -28 I nput Specifications

Because data must be represented in zoned decimal format once it is inside the computer, you must give the RPG II program an indication when input fields are in another format. Entering a P in column 43 indicates that the input field is in the packed decimal format and that the system must convert this field to the required zoned decimal format.

When a packed decimal field is converted to a zoned decimal field, the zoned decimal field always contains an odd number of bytes. If a zoned decimal field with an even number of bytes is converted to a packed decimal field and then converted back to a zoned decimal field, the resulting zoned decimal field also contains an odd number of bytes.

Packed fields can be up to

8

bytes long. The following chart shows the packed equivalents for zoned decimal fields up to 15 bytes long:

Zoned Decimal Packed Length Length in Bytes in Bytes 15

14

8

13

12

7

11

10 6

9

8

5

7

6 4

5

4 3

3

2 2

1

Binary Format (B)

Binary format means that 2 bytes of disk storage can contain a four-digit number, and that 4 bytes of disk storage can contain a nine-digit number. The binary format allows you to save even more disk storage space than you can save using the packed decimal format. In the binary format, each field on disk must be either 2 or 4 bytes long.

Each 2-byte binary field consists of a 1-bit sign followed by a 15-bit numeric value. In binary format, a decimal number as high as 9,999 requires only 2 bytes of disk storage. For each 2-byte binary field stored on disk, the RPG II compiler automatically sets aside 4 bytes of storage to accommodate the field when it is unpacked. A 2-byte field in binary format looks like this:

o

15

Number

- - - 2

bytes

-Column 43 (Packed or Binary Field) 7-29

Each 4-byte binary field consists of a 1-bit sign followed by a 31-bit numeric value. In binary format, a decimal number as high as 999,999,999 requires only 4 bytes of disk storage. For each 4-byte binary field stored on disk, the RPG II compiler automatically sets aside 9 bytes of storage to accommodate the field when it is converted. A 4-byte field in binary format looks like this:

o

Number

31

~---4bytes---~

In each case, the sign portion of the high-order byte indicates whether the numeric value is positive (sign bit off) or negative (sign bit on). Positive numbers are represented in true binary notation with a 0 bit in the sign position. Negative numbers are represented in twos-complement notation with a 1 bit in the sign position. The bits between the sign position and the leftmost significant bit of the integer are always the same as the sign bit. When the number is positive, all bits to the left of the most significant bit, including the sign bit, are Os. When the number !s negative, all bits to the left of the most significant bit, including the sign bit, are 1 s. Notice that, in the binary format, the zone position of the decimal number is not given. Compare how the decimal number 8,191 is represented in binary format with packed and zoned decimal representation (see Figure 7-16).

Because data must be represented in zoned decimal format once it is inside the computer, you must give the RPG II program an indication when input fields are in another format. Entering a B in column 43 indicates that the input field is in the binary format and that the system must convert this field to the required zoned decimal format.

Note: Although packed and binary fields require less disk storage space, the conversion routines needed to handle such data increase the object program size.

7-30 Input Specifications

COLUMNS 44-51 (FIELD LOCATION) Entry

1-9999

Explanation

Beginning of a field (from) or end of a field "(to). See Chapter 12 for CONSOLE file considerations. For a WORKSTN file, the from and to positions refer to the location of the fields in the input record and not to their location in the displayed format.

Use columns 44 through 51 to describe the location on the record of the field named in columns 53 through 58.

Enter the number of the record position in which the field begins in columns 44 through 47. Enter the number of the record position in which the field ends in columns 48 through 51. The entries must end in columns 47 and 51. Leading zeros can be omitted.

Define a single-position field by entering the same number in both the from (columns 44 through 47) and to (columns 48 through 51) positions. If a field of more than one position is defined, the number entered in columns 44 through 47 must be smaller than the number entered in columns 48 through 51.

The maximum field length for a zoned decimal numeric field is 15 positions (8 if the field is packed and 4 if it is binary). The maximum field length for an alphameric field is 256 characters, and the maximum length for a data structure is 9,999 characters.

COLUMN 52 (DECIMAL POSITIONS) Entry

Blank 0-9

Explanation Alphameric field

Number of decimal positions in numeric field

Use column 52 to indicate the number of positions to the right of the decimal in any numeric field named in columns 53 through 58. Column 52 must contain an entry when the field named in columns 53 through 58 is numeric. To define a field as numeric with no decimal position, enter a O. If a field is to be used in arithmetic operations or is to be edited, it must be numeric. If the number of decimal positions specified for a field exceeds the length of that field, the number of decimal positions is assumed equal to the length of the field.

COLUMNS 53-58 (FIELD NAME)

Entry Explanation

1-6 alpha- Field name, array name, meric or array element characters

PAGE, Special words

PAGE1-PAGE7

Use columns 53 through 58 to name a field, array, or array element found on your input records. When referencing an array, additional entries may be needed in these columns (see Array Name and Index in Chapter 14, Tables and Arrays). Use this name throughout the program whenever you refer to this field. Indicate the names of the fields for all types of records using a separate line for each field. However, name only the fields that you use. For example, if you use only the first 10 positions of a record that is 96 positions long, define positions 1 through 10 on the input

specifications.

For CONSOLE files, whole array names must be entered in one of the following ways:

• Define the whole array as a subfield within a field.

• Define each element of the array with an index and place this entry in columns 53 through 58 of the input specifications. The index must be an integer value.

Field Names

A field name can be from 1 to 6 characters long and must begin in column 53. The first character must be an alphabetic character. The remaining characters can be any combination of alphabetic and numeric

characters (special characters are not allowed). Blanks cannot appear between characters in the name.

All fields in one type of record should have different names. If two or more fields on the same record type have the same name, only the field described last is used. However, fields from different record types can have the same name if the fields are the same length and contain the same type of data. This applies even if the fields are in different locations in each record type.

Numeric fields can have a maximum length of 15 digits.

Alphameric fields can have a maximum length of 256 characters (66 for CONSOLE files). A data structure can have a maximum length of 9,999 characters. Subfields can have a maximum length of 256 characters for alphameric subfields and 15 digits for numeric subfields.

If a data structure is specified, only field record relation indicators (columns 63 and 64) can be specified. Entries for control level indicators (columns 59 and 60)' match field values (columns 61 and 62), and field indicators (columns 65 through 70) are not allowed. A data structure name cannot be specified as a subfield in a data structure.

Fields that are used in arithmetic operations (see Chapter 10, Operation Codes) or fields that are edited or zero suppressed (see Column 38 and Columns 45-70 in Chapter 9, Output Specifications) must be defined as numeric. Therefore, column 52 must have a decimal position entry (0 through 9).

Columns 53-58 (Field Name) 7-31

Field Names in OR Relationship

If two or more record types contain identical fields, you must describe each field. To eliminate duplicate coding of identical fields from different record types, use the OR relationship (see Figure 7 -17). A maximum of 20 OR lines can be used for each record sequence group if no AND lines are specified.

An OR relationship means that the fields named can be found in either of the record types. You can use OR lines when:

• Two or more record types have the same fields in the same positions (Figure 7-17).

• Two or more record types have some fields that are identical and some fields that differ in location, length, or type of data. See Columns 63-64 in this chapter for sample coding of such record types.

Nrite OR in columns 14 and 15 to indicate an OR line.

f there are several AND or OR lines, field description nes start after the last record identification line.

7-32 Input Specifications

Special Words (PAGE, PAGE1-PAGE7)

If a printed report has several pages that are to be numbered, use the special word PAG E to indicate that page numbering is to be done. When you use a PAGE entry on the output specifications, page numbering automatically starts with 1 (see Columns 32-37 in Chapter 9, Output Specifications).

To start at a page number other than 1, enter that page number in a field of an input record and name that field PAGE in columns 53 through 58. The number entered in the PAGE field should be one less than the starting page number. If numbering starts with 24, enter a 23 in the PAGE field. The PAGE field can be 1 to 15 digits long, but must have zero decimal positions (see Figure

~ -18). If a PAGE field is used but it is not defined, the PAGE field is assumed to be 4 digits long with zero decimal positions. Any entry in the PAGE field should be right-justified, such as 0023.

Page numbering can be restarted during a program run when a number is specified in a PAGE field of any input record. The PAGE field can be defined as a numeric field, 1 to 15 digits in length, with zero decimal positions, and used in calculations like any other field.

The eight possible PAGE entries (PAGE, PAGE1, PAGE2, PAGE3, PAGE4, PAGE5, PAGE6, and PAGE7) are provided for numbering different page types in the output file or for numbering the pages for different printer files.

(

Input Specifications

I

0 Record Identification Codes Field

~ Field Location

f - - - 1 2 3 Indicators

-i

~~ 0

Line Filename ~ Field Name :E-o

~ 0 .~ ~

& ~ -.; "-,,- Zero

"0. Position

~ e ~ Position ~ e ~ Position go

lji

From To .~ ~ Plus Minus or

j.

"5 :~ Blank

'O~;- z 0 ~2 Uu ~f.36 ~ § ;;:u ~2

~rr;ro

3 4 5 6 7 8 9 10 11 12 13 1415 16 17 18 19 20 21222324 2526 27 28 29 3031 3233 34 35 36 37 38 3940 4142 434445464 7 48 49 50 51 52 53 54 55 56 57 58 59 60 6162 6364 65 66 6768 69 70 71 72 73 74

Im Dokument RPG II (Seite 155-160)