Page 1 of 1

COMP-1 and confusion

PostPosted: Sat Jul 10, 2010 3:59 pm
by polarlemniscate
Does anyone know what this program produces as output?

000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. NUMBERS.
000300 AUTHOR. TEEBEE.
000400****************************************************************
000500* Simply transfer the present program to your favorite *
000600* mainframe computer, compile it, link it and submit some *
000700* appropriate JCL to run it. Its output tells the answer. *
000800****************************************************************
000900 ENVIRONMENT DIVISION.
001000 CONFIGURATION SECTION.
001100 OBJECT-COMPUTER. IBM-370.
001200 SOURCE-COMPUTER. IBM-370.
001300 DATA DIVISION.
001400 WORKING-STORAGE SECTION.
001500 01 THE-NUMBERS.
001600 10 FILLER USAGE IS COMP-1 VALUE -.24093455E+04.
001700 10 FILLER USAGE IS COMP-1 VALUE -.55439222E-47.
001800 10 FILLER USAGE IS COMP-1 VALUE -.33044246E-54.
001900 10 FILLER USAGE IS COMP-1 VALUE -.15622514E-50.
002000 10 FILLER USAGE IS COMP-1 VALUE .90854859E+00.
002100 10 FILLER USAGE IS COMP-1 VALUE -.27585575E-47.
002200 10 FILLER USAGE IS COMP-1 VALUE -.48936378E-36.
002300 10 FILLER USAGE IS COMP-1 VALUE .53763199E+00.
002400 10 FILLER USAGE IS COMP-1 VALUE .21482344E+74.
002500 10 FILLER USAGE IS COMP-1 VALUE .76006532E+00.
002600 10 FILLER USAGE IS COMP-1 VALUE -.22917763E-71.
002700 10 FILLER USAGE IS COMP-1 VALUE -.15607424E-50.
002800 01 THE-ANSWER REDEFINES THE-NUMBERS PIC X(48).
002900 PROCEDURE DIVISION.
003000 DISPLAY THE-ANSWER
003100 GOBACK.
003200 END PROGRAM NUMBERS.

My retired COBOL programmer friends tell me it produces some text (?) but as a total COBOL newbie (I can program in Delphi and Python, amongst others) I'm struggling.

Kind regards, I'm probably being dim.

Jim

Re: COMP-1 and confusion

PostPosted: Mon Jul 12, 2010 3:49 pm
by NicC
I would suggest you follow the indtructions in the comments in the ID Section. You can use a PC Cobol compiler. You should also look up the maual for REDEFINES and COMP-1

Re: COMP-1 and confusion

PostPosted: Mon Jul 12, 2010 9:52 pm
by polarlemniscate
Thanks, but assuming I am just stupid and lazy, (and can't work a cobol compiler - I HAVE TRIED!) could someone just run this through a compiler for me!

Re: COMP-1 and confusion

PostPosted: Mon Jul 12, 2010 9:56 pm
by enrico-sorichetti
... but assuming I am just stupid and lazy, ...

then doing anything on your behalf would be just a useless waste of time

Re: COMP-1 and confusion

PostPosted: Mon Jul 12, 2010 10:21 pm
by NicC
Anyway, there are 2 compile error messages - DISPLAY... and GOBACK should start in 'area b'

On the PC it displays a load of garbage but on the mainframe it displays a message in English. I think that if I cut and pasted the PC output to a file then one of my editors could be persuaded to read the file in EBCDIC rather than ASCII and I might then get the correct message.

It is all to do with how you interpret the bit patterns - you enter them as numerics and read them as text.

Re: COMP-1 and confusion

PostPosted: Tue Jul 13, 2010 5:14 pm
by polarlemniscate
okay, I'm prepared to understand this, but do you mean the english output is a readable string? If so, what string? If not, can you post the unreadable text and I'll have a go at translating it!

Re: COMP-1 and confusion

PostPosted: Tue Jul 13, 2010 6:01 pm
by Robert Sample
 Congratulations. Your answer is 'Big Blue Iron'.
is the precise output of the program.

If you use a PC compiler, you almost certainly will not get this result, which is based upon EBCDIC not ASCII. This can be done with any character string by doing something like (warning -- this is not tested code):
05  WS-TEXT PIC X(80) VALUE 'This is a test'.
05  WS-C1-VARS REDEFINES WS-TEXT.
    10  WS-C1-DATA OCCURS 20 USAGE COMP-1.
and then displaying the various WS-C1-DATA values.

Re: COMP-1 and confusion

PostPosted: Tue Jul 13, 2010 6:15 pm
by polarlemniscate
Thank you so much for this! I've been trying for ages!

Re: COMP-1 and confusion

PostPosted: Tue Jul 13, 2010 7:06 pm
by Robert Sample
Understanding this programs requires a good understanding of the internal storage formats for PIC X and USAGE COMP-1 variables. The same thing could be done on a PC COBOL compiler, but the data values would be completely different.

Re: COMP-1 and confusion

PostPosted: Mon Jul 26, 2010 1:00 am
by Don Higgins
I was able to compile, link, and execute this test COBOL program on my Windows Vista system using zCOBOL which is an open source portable mainframe COBOL compiler which generates HLASM mainframe assembler which is then assembled and executed running z390 which is open source portable mainframe assembler and emulator.

However, I first had to apply PTF 1126 to correct parsing error for floating point constants. There were 2 problems: the - exponent was being translated to _ and the unnessary + exponent was not being corrently handled. With these corrections, zcobol generted a valid HLASM assembler program which assembled and executed with the following display log:

15:00:07 numbers EZ390 START USING z390 V1.5.01ex2 ON J2SE 1.6.0_20 07/25/10
EZ390I Copyright 2008 Automated Software Tools Corporation
EZ390I z390 is licensed under GNU General Public License
EZ390I program = w:\work\z390\numbers.390
EZ390I options = SYS390(+zcobol\z390)
Congratulathons¢ Yotr answeq is 'Bif Blue Iron'¢
EZ390I instructions/sec = 2200
EZ390I total errors = 0
15:00:07 numbers EZ390 ENDED RC= 0 SEC= 0 MEM(MB)= 20 IO=185 INS=143

Notice the result is readable as zcobol and z390 do operate in EBCDIC default environment on Windows and LInux and execute all the problem state z/Architecture instructions. However there are a few characters that are off by a single bit. The differences are probably due to J2SE emulation of floating point not using enough guard digits. RPI 1124 was about the same sort of issue raised by another z390 user recently. For more on zcobol and z390 including previous presentations at SHARE visit www.z390.org.