Microsoft KB Archive/37165

From BetaArchive Wiki

ADDing Numbers with Unequal Decimal Lengths Gives Wrong Value

PSS ID Number: Q37165 Article last modified on 04-20-1993

3.00 3.00a | 3.00 3.00a MS-DOS | OS/2

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

Summary: Addition and subtraction do not work correctly in COBOL versions 3.0 and 3.0a under the following conditions: 1. The numbers involved do not have the same number of decimal places. 2. The numbers are of the USAGE COMP-3. 3. The TARGET“286” compiler directive is explicitly specified. (However, the case of adding a PIC 99V99 COMP-3 to a PIC 99V9 COMP-3 gives a problem even without the TARGET“286” directive.) The code example below incorrectly outputs as follows: 1 + 0111 = +0211 and 1 - 1111 = -0011 If the TARGET“286” compiler directive is NOT specified, the output should correctly display as follows: 1 + 1111 = +1211 and 1 - 1111 = -1011

More Information: Microsoft has confirmed this to be a problem with versions 3.0 and 3.0a of Microsoft COBOL Compiler. This problem was corrected in Microsoft COBOL Professional Development System version 4.0 for MS-DOS and MS OS/2. The example below works correctly in previous versions of the Microsoft COBOL Compiler. When compiled in the following manner, the following code example produces incorrect results: COBOL progname /TARGET(286); LINK progname+adis+adisinit+adiskey; DATA DIVISION. WORKING-STORAGE SECTION. 01 LITERAL-AREA. 02 LITERAL1 PIC S9(3) COMP-3 VALUE +001. 02 LITERAL11 PIC S99V99 COMP-3 VALUE +11.11. 02 TempVar PIC S99V99 COMP-3. PROCEDURE DIVISION. MAIN. ADD LITERAL1 TO LITERAL11 GIVING TempVar. DISPLAY LITERAL1 " + " LITERAL11 " = " TempVar. COMPUTE TempVar = LITERAL1 + LITERAL11. DISPLAY “COMPUTED” LITERAL1 " + " LITERAL11 " = " TempVar. SUBTRACT LITERAL11 FROM LITERAL1 GIVING TempVar. DISPLAY LITERAL1 " - " LITERAL11 " = " TempVar. COMPUTE TempVar = LITERAL1 - LITERAL11. DISPLAY “COMPUTED” LITERAL1 " - " LITERAL11 " = " TempVar. STOP RUN.

Additional reference words: 3.00 3.00a Copyright Microsoft Corporation 1993.