Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ISCobol Data Type Definitions

Status
Not open for further replies.

klophockey

Programmer
May 25, 2016
41
US
Could you point to or provide documentation that would show the appropriate way to code for COMP-1 and COMP-2 fields in Working Storage.

I read some documentation that the Picture clause is not allowed and that USAGE IS must be used. However, that does not compile cleanly in the ISCobol environment.

What I would hope to see is a list of data types and the definition for them. One would be non signed and the other would be signed.

Example of what I am looking to code correctly is shown below as the starter so you can see what I am trying to code.
For example, I would like to insert the value of 12.89 into C1-2 and 23.45 in C1-2S.
Of course, they do not have the decimal shown but if I code such as 99v999999999 it says out of range and the USAGE clause does not work

03 C1-1 PIC 9 COMP-1.
03 C1-1S PIC S9 COMP-1.
03 C1-2 PIC 9(18) COMP-1.
03 C1-2S PIC S9(18) COMP-1.

03 C2-1 PIC 99v99 COMP-2.
03 C2-1S PIC S99v99 COMP-2.
 
I am a bit rusty on Cobol, but COMP-1 and COMP-2 are both floating point (short and long respectively) so the picture clause is irrelevant.

Have you tried:

03 C2-1 USAGE IS COMP-2.

I would be wary of using either of them as they are both approximations and may not always return the exact value you set them to. ( I am sire there are discussions of this on the internet of you want to see why.)

The purpose of them is to be able to hold very small (as in 0.000000000001) and very large (1000000000000000.0) numbers.
 
Thank you for sharing your knowledge.

I understand what you are saying about the precision. So, I will think about the concept of not even testing COMP-1 fields because a hard coded value to check against what the value the machine stores may not be exact and would, therefore, fail the compare.

HOWEVER.......in the meantime.....
I tried the USAGE IS COMP-1 on the C1-2 and C1-2S fields.
03 C1-2 USAGE IS COMP-1.
03 C1-2S USAGE IS COMP-1.


The compiler came back with this message:
Compiling programs for pgmtest.bat ...--S: #28 Missing picture clause C1-2; file = src\mypgm.cbl, line = 27, col 8
--S: #51 Missing FD for file: FCOMP; file = src\mypgm.cbl, line = 4, col 11
--S: #31 Expected/found token mismatch: PROCEDURE/03; file = src\mypgm.cbl, line = 28, col 4
Compiling result
Severe error(s) - 3
X --> src\mypgm.cbl: compilation failed


PLEASE NOTE THAT THERE IS NO COMPILE ERROR IF I COMPILE AS SHOWN IN THE ORIGINAL CODE IN MY ORIGINAL POST.
So, the missing FD error is a result of changing to C1-2 USAGE IS COMP-1 and C1-2S USAGE IS COMP-1 are what caused that error.

The COMP-2 fields seem to work as they are coded.
I think the issues is that ISCobol compiling does not recognize the USAGE IS COMP-1 phrase for a given field but I doubt it is a compiler setting as much as ISCobol just does not recognize USAGE.
 
Further searches have not helped a great deal, although I did find this:

"COMP-1 refers to short floating-point format and COMP-2 refers to long floating-point format, which occupy 4 and 8 bytes of storage, respectively. The leftmost bit contains the sign and the next 7 bits contain the exponent; the remaining 3 or 7 bytes contain the mantissa."

The above is hardware specific.

Most sites I visited pretty much dodged the issue, although I did find one site with an example using "PIC(03) USAGE COMP-1", but this doesn't really make sense to me.

Good luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top