Microsoft KB Archive/35729

Using MS(2) Directive, IF with Computed Expressions May Fail

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

3.00 | 3.00 MS-DOS | OS/2

Summary: The MS(2) dialect option sets SIGN(EBCDIC) as its default. This setting alters normal evaluation of comparisons with expression values. This means that any IF … THEN construct using a computed expression may take an unexpected path. The code examples below show the problem. To work around the problem, you can reset the compiler switch to SIGN(ASCII) or compute the actual value of the expression before making the comparison. This problem does not occur in versions of COBOL earlier than 3.0 and was corrected in Microsoft COBOL Professional Development System version 4.0 for MS-DOS and MS OS/2.

More Information: The following is a code example: * All of the comparisons can be made to work correctly by putting a * $SET SIGN(ASCII) at the beginning, where $ goes in column 7 or in * the COBOL.DIR file or on the command line. DATA DIVISION. WORKING-STORAGE SECTION. 01 LITERAL-AREA. 02 LITERAL1 PIC S9(3) COMP-3 VALUE +1. 02 LITERAL11 PIC S99V99 COMP-3 VALUE +11. 02 LITERAL12 PIC 999 VALUE 12. 02 COMPVAL PIC S99V99. 02 CONSTANT30 PIC 99 VALUE 30. PROCEDURE DIVISION. MAIN. * This works with SIGN(EBCDIC) or SIGN(ASCII): COMPUTE COMPVAL = LITERAL11 / LITERAL12 IF (COMPVAL > 30) THEN DISPLAY “compval > 30”.   These work correctly only with SIGN(ASCII): IF (LITERAL11 / LITERAL12) > 30 THEN DISPLAY “LITERAL11 / LITERAL12 > 30”. IF (LITERAL11 / LITERAL12) > CONSTANT30 THEN DISPLAY “LITERAL11 / LITERAL12 > CONSTANT30”. IF (11 / 12 ) > 30 THEN DISPLAY “even with real integers it fails”. STOP RUN.

Additional reference words: 3.00 Copyright Microsoft Corporation 1993.