...same player shoots again ;-)
Here's the situation:
77 WS-LENGTH PIC S9(004) COMP.
01 WS-ALPHABET-UPPER-LOWER.
06 WS-UPPER-1ST-HALF PIC X(013) VALUE 'ABCDEFGHIJKLM'.
06 WS-UPPER-2ND-HALF PIC X(013) VALUE 'NOPQRSTUVWXYZ'.
06 WS-LOWER-1ST-HALF PIC X(013) VALUE 'abcdefghijklm'.
06 WS-LOWER-2ND-HALF PIC X(013) VALUE 'nopqrstuvwxyz'.
06 WS-ALPHABET-AND-MORE PIC X(010) VALUE '!@#$%/&*()'.
01 WS-RECEIVER-GROUP.
06 WS-RECEIVE PIC X(007).
06 WS-RECEIVE-OVERFLOW PIC X(055).
MOVE some-value TO WS-LENGTH
MOVE ALL '1234567890' TO WS-RECEIVE-GROUP.
MOVE WS-UPPER-1ST-HALF TO WS-RECEIVE(1:WS-LENGTH)
The value of WS-ALPHABET-UPPER-LOWER is:
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@%/&*()"
The value of WS-RECEIVER-GROUP (before the MOVE) is:
"12345678901234567890123456789012345678901234567890123456789012"
When using a value for WS-LENGTH > 13, i.e. larger than the sending(!) data item, I get different results:
COBOL-
LENGTH VERSION WS-RECEIVER-GROUP
0 ?! 4.2 "12345678901234567890123456789012345678901234567890123456789012"
5.1 "12345678901234567890123456789012345678901234567890123456789012" = equal (no modification)
13 ?! 4.2 "ABCDEFGHIJKLM4567890123456789012345678901234567890123456789012"
5.1 "ABCDEFGHIJKLM4567890123456789012345678901234567890123456789012" = equal
20 ?! 4.2 "ABCDEFGHIJKLM 123456789012345678901234567890123456789012" <-- 7 SPACEs
5.1 "ABCDEFGHIJKLMNOPQRST123456789012345678901234567890123456789012"
60 ?! 4.2 "ABCDEFGHIJKLM 12" <-- 47 SPACEs
5.1 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%/&*12"
I know it's all "illegal" code; the manual states that length must be a positive nonzero integer and <= #characters in that data item.
When those illegal values are hard-coded into the source, the compiler gives error messages.
This situation is taken from a program that ABENDs (0C7) in COBOL 5.1 and didn't do so in COBOL 4.2.
The "overflowed" area has a NUMERIC data-item and the overflowing SPACEs in COBOL 4.2 are handled "better" than the overflowing "rubbish" that COBOL 5.1 puts in.
The programmer never noticed the "overflow" situation and got away with it in COBOL 4.2. (un)Fortunately the program even took all the right paths and the outcome was "correct".
Not so in COBOL 5.1 (in this case).
The ZONECHECK option helps to determine invalid data at run-time.
Is there an option to have the program to perform a check for an invalid length in the reference moficication at run-time?
RenéBeurskens