Displaying a COMP field is no longer zero suppressed

We're migrating from an old big-endian Solaris compiler (compiler version 5.1.4.0) to VC 9.0.0.59 (patch update 2) on little-endian Linux.

We're seeing an extra leading zero on fields defined as COMP. 

This field:

03 ct-read pic 9(07) comp value 0.

will display as an 8 digit number (not 7 as defined) on Linux:

07754589

On Solaris, it would display as:

7754589

The field is displayed directly using a DISPLAY statement.

Compiler options for both platforms are:

NOBOUND NOALTER COMP NOCHECK NOCHECKDIV NOTRUNC OPT=3 FASTLINK NOANIM NOCOBIDY OPTSPEED

Changing NOTRUNC to TRUNC on Linux results in a completely different number being displayed (using the same static input files):

4531805

Removing both compiler directives COMP and NOTRUNC also removes the leading zero from the display on Linux:

7754589

As part of the migration, we would of course like the output of all of our programs to be the same on both platforms.

So some questions:

* Why is there now a leading zero in the display on Linux?  Why does it disappear when COMP and NOTRUNC are not supplied? 

* Are there performance or accuracy implications in removing those directives?

* Why does changing from NOTRUNC to TRUNC result in such a completely different number?  The value would seem to very comfortably fit within the range of values supported by the picture.

Thanks in advance!

Tags:

  • 0  

    Hi Mark,

    I'm not able to reproduce the results you've described, so I think we might not have a complete picture of what's happening. Here's a simple COBOL program:

           01 my-group.
            03 ct-read pic 9(07) comp value 0.
           procedure division.
               move 7754589 to ct-read
               display ct-read
               goback.
    

    Using the same compiler directive list that you've mentioned, this program displays the same value with Server Express 5.1 Wrap Pack 8 on a Big Endian (Solaris 10 on SPARC):

     > cobrun blaircutdown
    07754589

     

    As it does in Visual COBOL 9.0 Patch Update 2 on Red Hat Linux 7 (Little Endian):

    $ cobrun blaircutdown
    07754589

    Also, I want to mention that generally, using the DISPLAY statement with COMP fields is not recommended - instead, it's better to move the COMP value to a usage DISPLAY value before displaying it.

    In your case, is the value in the ct-read field the result of a calculation? 

    What kind of built file is the COBOL compiled to? Is it built to .int or .gnt, or .so, or native executable? Please feel free to modify the program provided above to reproduce the behavior you described.

    Blair

  • 0 in reply to   

    Thanks very much for your reply, Blair.

    Noted that COMP fields should not be displayed directly - we're migrating many hundreds of legacy programs, and seeking to do it with minimal code changes, however I'll let the team know about this.

    We're building to shared objects on Linux (Ubuntu Server, but it should be the same as Red Hat).

    You have in fact reproduced the issue that I posted about.  Your cut down program, using the compiler directives that I supplied, does prefix the value of ct-read with a zero.

    You are correct in that ct-read is a counter field, used to accumulate the number of records read from a file.

    If I compile your cut down program with a very simple command line (I saved the program as comp.cbl):

    cob64 -z comp.cbl

    ...and run that with cobrun comp.so, I get:

    7754589

    On further investigation, I have found that the compile script on the older Solaris server does not attempt to optimise for production, so does a very basic compile using mostly defaults, similar to the command line above.

    However, on the Linux server that we're migrating to, I do want to optimise for production runs.  I found this link, which provides suggested directives for production optimisation:

    https://www.microfocus.com/documentation/visual-cobol/vc90/DevHub/HHPFCHPERF0N.html

    You'll notice that neither COMP no NOTRUNC are present in the list.  When using the directives from that link, the leading zero issue is not present, either.

    I'm happy to discard the COMP and NOTRUNC directives for production code, and use their defaults, but would hope that they will not affect program output in any way.

  • 0   in reply to 

    Hi Mark,

    Thanks for your update. It sound like the reason for the original difference in behavior you described was that you used different compile directives on the Solaris machine than you were using on Linux.

    Thanks also for sharing that with the compile directives from the "Compiler Directives for Optimizing Code" page in the Visual COBOL documentation, you now get the (desired) display behavior with Visual COBOL that you got with Server Express. However, we can't say whether you will encounter any (other) changes in behavior. Our recommendation is that you test the application and confirm to your satisfaction that it works as expected in the new environment. This is recommended for these reasons:

    • You are upgrading from a very old release of Server Express to Visual COBOL
    • You are changing platforms, and endianness
    • You are planning to change compile directives and rebuild the application

    Hope this helps,
    Blair