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!

How to convert COMP-3 to Regular Number?

Status
Not open for further replies.

MickeD

Programmer
Feb 20, 2000
54
Hi All!<br>I am Visual Basic Programmer without any knowlage in Cobol :)<br>I need to convert <font color=red><b>COMP-3</b></font> value to &quot;regular&quot; format <br>Is there any algorythm for this convertion?<br>Where can I find information about this?
 
The&nbsp;&nbsp;comp-3 format means:<br><br>x'12345c' for +12345<br>x'12345d' for -12345<br>x'12345f' for&nbsp;&nbsp;12345<br><br>so you can compare the valid hexadecimal values to find out what you have and then convert them into readable digits.
 
You can move the comp-3 value to a display format value:<br><br>example working storage:<br>02 AVALUE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PIC S9(9) COMP-3.<br>02 BVALUE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PIC S9(9).<br><br>example procedure division:<br>MOVE AVALUE TO BVALUE.<br>or<br>COMPUTE BVALUE = 1 * AVALUE.<br><br>The BVALUE will not be in packed decimal (comp-3) format.
 
Michael Mattias wrote some stuff on COBOL data types.&nbsp;&nbsp;It is available at:<br><br><A HREF=" TARGET="_new"> to COBOL Numeric Data Types<br>Michael Mattias has created a text and graphics based introduction to COBOL numeric data types. It was designed for intermediate to advanced programmers not familiar with the COBOL language or COBOL numeric data storage. A Windows Write or compatible word processor is recommended, but an ASCII text file format is also included). The PKZIP format file includes an executable program file as well as PB 3.2 source code. This file is Copyrighted but free for personal use. A compiler is NOT required to use this product.<br><br>COBDATA.ZIP (56,423; March 10, 1999)<br>
 
I know this reply is late, but for completeness, I thought <br>I'd send it.<br><br>If I'm not mistaken, the example CORLEWD provided would <br>convert x'12345F' to 1234E (x'F1F2F3F4C5') not 12345<br>(x'F1F2F3F4F5'). If you want 12345 use BVALUE PIC&nbsp;&nbsp;9(5)<br>(i.e no sign) or REDEFINE it to this.<br><br>Also, you can &quot;move&quot; a numeric value by using:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;COMPUTE VALUEB = VALUEA<br><br>Hope this helps, Jack
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top