Wirt writes:
>> Joe writes:
>>
> > In COBOL II, an IMAGE J2 field is defined as a binary integer with a
> > minimum length of 5 and a maximum length of 9 digits.
>
>Although the manuals may suggest an interpretation something like the comment
>above, your statement is a mild misinterpretation of what is actually being
>said. The way that the manual's comments should be read is: if you need a
>COBOL binary integer between 5 and 9 digits, then a J2 datatype will fill
>your bill. A J1 datatype won't be big enough, and a J4 would be overkill.
>
>What's not being said, even though it could be read that way, is that a J2
>datatype can only legitimately contain numbers with a minimum of 5 digits and
>a maximum of 9 digits. A COBOL-legitimate datavalue for a J2 field can range
>from 0 (1 digit) to plus or minus 999999999 (nine digits) -- and that's only
>if the application program enforces those rules. IMAGE itself, as I mentioned
>earlier, doesn't impose any restrictions on the bit patterns that can be put
>into the 32-bits of a J2 dataitem.
>
>Wirt Atmar
Allow me to clarify:
In my original comment, I indicated how the data item is to be defined. I
did not mention the range of numbers in a J2 data item that are constituted
as valid by COBOL and QUERY.
As we all know, the legitimate value of a J2 data item can range from zero
to + or - 999999999.
However, the COBOL variable referencing the J2 data item must be defined as
having 5 to 9 digits in order to map the 32 bit word correctly. For
example, a J2 variable defined as S9(5) BINARY will be treated as a signed
5 digit number by the COBOL program. If you set this variable to zero, the
program will generate "+00000", not just a single digit.
A binary integer that is defined with less than 5 digits is a J1 data item
(halfword). These items may legitimately contain numbers of 1 to 4 digits
in length. They would be defined as S9 BINARY through S9(4) BINARY and
range from zero to + or - 9999.
The following program demonstrates how J1 and J2 items are defined and how
their values are represented by their data descriptions. A J1 item is
initialized to zero and the item is viewed through 1 digit and 4 digit
descriptors. Then a J2 item is set to "1" and this item is displayed
through 5 digit and 9 digit descriptors.
00014 001000$CONTROL OPTIMIZE=1
00015 001100 IDENTIFICATION DIVISION.
00016 001200 PROGRAM-ID. TESTPROG.
00017 001300 AUTHOR. Joe Berliner/Humboldt Group.
00018 001400 DATE-COMPILED. MON, OCT 23, 2000, 2:16 AM
00019 001500
00020 001600 ENVIRONMENT DIVISION.
00021 001700
00022 001800 CONFIGURATION SECTION.
00023 001900 SOURCE-COMPUTER. HP-3000.
00024 002000 OBJECT-COMPUTER. HP-3000.
00025 002100
00026 002200 DATA DIVISION.
00027 002300
00028 002400 WORKING-STORAGE SECTION.
00029 002500
00030 002600 01 J1-ITEM-1 PIC S9 BINARY.
00031 002700 01 J1-ITEM-4 REDEFINES J1-ITEM-1
00032 002800 PIC S9(4) BINARY.
00033 002900
00034 003000 01 J2-ITEM-5 PIC S9(5) BINARY.
00035 003100 01 J2-ITEM-9 REDEFINES J2-ITEM-5
00036 003200 PIC S9(9) BINARY.
00037 003300
00038 003400 PROCEDURE DIVISION.
00039 003500
00040 003600 A00-MAINLINE.
00041 003700
00042 003800 MOVE ZERO TO J1-ITEM-1.
00043 003900 MOVE 1 TO J2-ITEM-5.
00044 004000
00045 004100 DISPLAY "J1-ITEM (1 DIGIT) = ", J1-ITEM-1.
00046 004200 DISPLAY "J1-ITEM (4 DIGITS) = ", J1-ITEM-4.
00047 004300 DISPLAY SPACE.
00048 004400 DISPLAY "J2-ITEM (5 DIGITS) = ", J2-ITEM-5.
00049 004500 DISPLAY "J2-ITEM (9 DIGITS) = ", J2-ITEM-9.
00050 004600
00051 004700 STOP RUN.
0 ERROR(s), 0 QUESTIONABLE, 0 WARNING(s)
DATA AREA IS 48 BYTES.
CPU TIME = 0:00:00. WALL TIME = 0:00:00.
END OF PROGRAM
END OF COMPILE
HP Link Editor/iX (HP30315A.06.14) Copyright Hewlett-Packard Co 1986
LinkEd> link
END OF LINK
J1-ITEM (1 DIGIT) = +0
J1-ITEM (4 DIGITS) = +0000
J2-ITEM (5 DIGITS) = +00001
J2-ITEM (9 DIGITS) = +000000001
END OF PROGRAM
COBOL enforces the range restrictions by allowing the programmer to check
for overflow conditions during arithmetic operations via the SIZE ERROR
phrase. If the coder fails to trap the error, COBOL's numeric alignment
rules will come into play to insure that a legitimate value is placed in
the field. For example, an 8 digit result cannot be placed in a S9(7)
BINARY variable; the 7 low-order digits would be placed in the data item
and the high-order digit would be truncated.
- Joe -
|