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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert COBOL Comp or Comp-3 to a regular number

Status
Not open for further replies.

rmittal

Programmer
Aug 8, 2000
8
US
Hi,<br>&nbsp;&nbsp;I am a programmer doing CGI scripting in REXX. Te input to the REXX programs are through the CICS program on mainframes. I need to get the Pic 9(4) COMP or COMP-3 data in REXX as a regular number. I cannot change the field size since then the entire record structure will have to be modified. How do I do this?
 
I know it can be done, just don't have the doc at home. I've emailed your message to myself at work. Let me know if you still need a reply (I just joined today).

I believe comp is binary and comp-3 is packed decimal. Been awhile since I've used COBOL. [sig]<p>PhiloVance<br>Other hobbies, interests: Travel, Model RR (HO Gauge), Genealogy.[/sig]
 
Here's a little rexx exec I worked up on an IBM mainframe. Assume REXX is pretty similar whatever environment.
Hope it helps. Also included doc from IBM about packed decimal digits. They are quite different.

**********************************************************
/*rexx*/
/* example of displaying COMP numbers from a COBOL program */
/* trace ?r */
comp:
digits=1234
comp.digits=c2x(digits)
display.digits=x2c(comp.digits)
say display.digits

/* example of displaying COMP-3 numbers from a COBOL program */
/*
COMP-3 is packed decimal usually an uneven number, lets use 3
as an example. COBOL would show double that -1, i.e.
77 PACKED-DECIMAL VALUE +0 PIC S9(5) COMP-3.
A packed decimal number will have a sign as the last nibble of
the last byte, i.e., +2345 will, in a hex dump look like
02345C, that's 3 bytes, but can contain up to 5 numbers. If the
number were negative it would be 02345B. B and D are negative, all
other signs are positive.
*/
compthree:
digit=b2x(100011010001011011) /* binary for 02345- */
len=length(digit)
display.digits=left(digit,len-1)
sign=substr(digit,len,1)
sign=translate(sign) /* make it upper case */
if sign='B' or sign='D' then display.digits=display.digits*-1
say display.digits

***************************************************************
Following is from IBM website
Taken from:
Title: ESA/390 Principles of Operation
Document Number: SA22-7201-04

--------------------------------------------------------------------------------

A.1.2 Decimal Integers


Decimal integers consist of one or more decimal digits and a sign. Each
digit and the sign are represented by a 4-bit code. The decimal digits
are in binary-coded decimal (BCD) form, with the values 0-9 encoded as
0000-1001. The sign is usually represented as 1100 (C hex) for plus and
1101 (D hex) for minus. These are the preferred sign codes, which are
generated by the machine for the results of decimal-arithmetic operations.
There are also several alternate sign codes (1010, 1110, and 1111 for
plus; 1011 for minus). The alternate sign codes are accepted by the
machine as valid in source operands but are not generated for results.


Decimal integers may have different lengths, from one to 16 bytes. There are two decimal formats: packed and zoned. In the packed format, each byte contains two decimal digits, except for the rightmost byte, which contains the sign code in the right half. For decimal arithmetic, the number of decimal digits in the packed format can vary from one to 31. Because decimal integers must consist of whole bytes and there must be a sign code on the right, the number of decimal digits is always odd. If an even number of significant digits is desired, a leading zero must be inserted on the left.


In the zoned format, each byte consists of a decimal digit on the right and the zone code 1111 (F hex) on the left, except for the rightmost byte where the sign code replaces the zone code. Thus, a decimal integer in the zoned format can have from one to 16 digits. The zoned format may be used directly for input and output in the extended binary-coded-decimal interchange code (EBCDIC), except that the sign must be separated from the rightmost digit and handled as a separate character. For positive (unsigned) numbers, however, the sign can simply be represented by the zone code of the rightmost digit because the zone code is one of the acceptable alternate codes for plus.

Taken from:
Title: ESA/390 Principles of Operation
Document Number: SA22-7201-04
Build Date: 06/13/97 13:18:22 Build Version: 1.3.0



In either format, negative decimal integers are represented in true notation with a separate sign. As for binary integers, the radix point (decimal point) of decimal integers is considered to be fixed at the right, and any scaling is done by the programmer.


The following are some examples of decimal integers shown in hexadecimal notation:


Decimal
Value Packed Format Zoned Format

+123 12 3C F1 F2 C3
or or
12 3F F1 F2 F3

-4321 04 32 1D F4 F3 F2 D1

+000050 00 00 05 0C F0 F0 F0 F0 F5 C0
or or
00 00 05 0F F0 F0 F0 F0 F5 F0

-7 7D D7

00000 00 00 0C F0 F0 F0 F0 C0
or or
00 00 0F F0 F0 F0 F0 F0

Under some circumstances, a zero with a minus sign (negative zero) is
produced. For example, the multiplicand:

00 12 3D (-123)

times the multiplier:

0C (+0)

generates the product:

00 00 0D (-0)

because the product sign follows the algebraic rule of signs even when the
value is zero. A negative zero, however, is equivalent to a positive zero
in that they compare equal in a decimal comparison.




--------------------------------------------------------------------------------

© Copyright IBM Corp. 1990, 1991, 1993, 1994, 1996, 1997
--------------------------------------------------------------------------------


IBM BookManager® BookServer Copyright 1989, 1999 IBM Corporation. All rights reserved. [sig]<p>PhiloVance<br>Other hobbies, interests: Travel, Model RR (HO Gauge), Genealogy.[/sig]
 
Hi Mittal /Philovance !

i have the similiar type of problem.

I have a seqential file that has a few fields that contain data in binary format(they were defined in the program as PIC S9(9) COMP).Which means i cannot see them and read them meaningfully when i browse the data.My client wants this file to be converted so that she can read the binary data also meaning fully.So my task now is to convert the binary data into numric format so that she can read it while browsing and could undestand.

Do we have any cobol functions
(a)that convert binary data into ordinary numeric data
(b)that convert packed data into ordinary numeric data

or do we need to resort to REXX or CLIST ?

The solution as Philovence suggested using REXX is a good one.
I am new to REXX.I have a basic doubts.

Can i embed this REXX program in a VSCOBOL II source?
What else do i need to do to make this program compile?


[sig][/sig]
 
Can a rountine in VB be written to read in an EBCDIC file with packed, signed data and convert it to ASCII?

Seeking Help
rfasanel@rcn.com
 
I too am facing a problem with the data types in Rexx and I want to know the Data type of a variable before converting it to some other format. . . Otherwise I won't know which function I have to use.

I am writing a program that reads a flat file that has DB2 data, converts the data to some other form(char and integers and floats) which may be easily deciphered and writing the converted data to another flat file.

Thanks a lot.
Manish
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top