Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

COBOL - Differing answer from mainframe to PC for same COMPUTE

I have this very simple dummy COBOL program which does a dummy COMPUTE and displays the result.

   ID DIVISION.
   PROGRAM-ID. DUMMYPGM.
   DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 NUM-A PIC 9(3) VALUE 399.
   01 NUM-B PIC 9(3) VALUE 211.
   01 NUM-C PIC 9(3).
  *
   PROCEDURE DIVISION.
   MAIN.
       COMPUTE NUM-C = ((NUM-A / 100) - (NUM-B / 100)) * 100
       DISPLAY 'NUM-C IS ' NUM-C
       STOP RUN.

When I compile this code on a mainframe (with compiler MVS Enterprise COBOL V4.2) and execute it, I get "NUM-C IS 100", probably because (399 / 100) is treated as a 3 instead of a 3.99 in the calculation (and same goes for 211 / 100).

But when I compile the same exact code on a PC (with the GnuCobol compiler) and execute it, I get "NUM-C IS 188". The PC's answer is correct , but I would like to make it behave like the mainframe (and thus, losing precision in that compute statement to give 100 instead of 188)... How would I do that ?

The reason for the above is a general expression of this code:

 COMPUTE PDISCR = (((((X(1) + DX - XBRAK) * (ABRAK(1) / 1000)) / 100)
                  + PHT(1) + DPH - PHBRAK) * 2) + ((V(1) + DV 
                  + VBRAKMPM) * (V(1) + DV - VBRAKMPM) / 100000)) 

This is part of a 50-year-old Train simulation program, which I need to migrate to GnuCOBOL. All the fields used in the COMPUTE are integers. I need to be able to get the same answer from GnuCOBOL.

Confirmed for OpenCOBOL/GnuCOBOL up to 2.0.

like image 440
Gael L Avatar asked Oct 04 '16 14:10

Gael L


1 Answers

https://lwn.net/Articles/733129/

This link mentions a new std option for gnuCobol 2.2: ibm-strict. I wonder if that would force the compute statement to do what you want.

like image 182
George Avatar answered Oct 18 '22 20:10

George