Microsoft KB Archive/35656

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 19:21, 12 August 2020 by X010 (talk | contribs) (X010 moved page Microsoft KB Archive/Q35656 to Microsoft KB Archive/35656 without leaving a redirect: Text replacement - "Microsoft KB Archive/Q" to "Microsoft KB Archive/")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Incorrect Sign Adding Unsigned and Signed Fields; COBOL 3.0

PSS ID Number: Q35656 Article last modified on 04-21-1993

3.00 | 3.00 MS-DOS | OS/2

The information in this article applies to:
- Microsoft COBOL for MS-DOS and OS/2, version 3.0

Summary: Adding two positive numbers (one signed and one unsigned) may result in a negative number when the two numbers being added together have the following characteristics: 1. A has the picture clause PIC 9(5)V9(2) COMP-3. 2. B has the picture clause PIC S9(5)V(9) COMP-3. 3. C REDEFINES B with the picture clause PIC 9(5)V9(2) COMP-3. Microsoft has confirmed this to be a problem in Version 3.0. This problem was corrected in Microsoft COBOL Version 3.0a.

More Information: C is initialized with 0. This should also cause B to be initialized with 0 because C and B are sharing the same place in memory. A is initialized to 100. Before the addition takes place, everything appears to have the proper values. A is then added to B with the result stored in B. B should have a value of +100 after the addition. Instead, B has the value of -100. The following program demonstrates the problem: IDENTIFICATION DIVISION. PROGRAM-ID. NEG. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 77 A PIC 9(05)V9(02) COMP-3. 77 B PIC S9(05)V9(02) COMP-3 VALUE 0. 77 C REDEFINES B PIC 9(05)V9(02) COMP-3. PROCEDURE DIVISION. P00-MAIN-ROUTINE. MOVE 0 TO C MOVE 100 TO A. DISPLAY B. * will display +0 ADD A TO B. DISPLAY B. * should display +100 but actually displays -100.

Additional reference words: 3.00 Copyright Microsoft Corporation 1993.