Microsoft KB Archive/40711

From BetaArchive Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Dividing Negative Number by Constant Gives Garbage in COBOL

PSS ID Number: Q40711 Article last modified on 11-18-1990

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

Summary: When Microsoft COBOL versions 3.00 and 3.00a divide a negative number by a constant or a Level 78 data item, the results produced may be incorrect. If the constant or Level 78 data item is replaced by a standard data item in the WORKING-STORAGE SECTION, the division works correctly. The program below demonstrates the problem. Microsoft has confirmed this to be a problem in versions 3.00 and 3.00a. This problem was corrected in Microsoft COBOL Professional Development System version 4.00 for MS-DOS and MS OS/2.

Code Example

This program should be compiled and LINKed without a COBOL.DIR file: WORKING-STORAGE SECTION. 78 REAL-CONST VALUE 2. 77 CONSTANT-1 PIC 99 VALUE 2. 77 NUMERATOR PIC S9(6)V99 VALUE 0. 77 RESULT-1 PIC S9(6)V99 VALUE 0. 77 RESULT-2 PIC S9(6)V99 VALUE 0. PROCEDURE DIVISION. MOVE -100 TO NUMERATOR. Prints correct result COMPUTE RESULT-1 = NUMERATOR / CONSTANT-1. DISPLAY RESULT-1. Prints incorrect result COMPUTE RESULT-2 = NUMERATOR / 2. DISPLAY RESULT-2. *Also prints incorrect result COMPUTE RESULT-2 = NUMERATOR / REAL-CONST. DISPLAY RESULT-2. STOP RUN.

Copyright Microsoft Corporation 1990.