HP3000-L Archives

October 1997, Week 3

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Michael Berkowitz <[log in to unmask]>
Reply To:
Michael Berkowitz <[log in to unmask]>
Date:
Wed, 15 Oct 1997 10:53:45 -0800
Content-Type:
text/plain
Parts/Attachments:
text/plain (67 lines)
Rick Brooks writes:

>>> Rick Brooks <[log in to unmask]> 10/15/97 08:13am >>>
Tony Furnivall  wrote:
>>Cynthia Redick ([log in to unmask]) wrote:
>>: We are looking for a "C" language routine that would format a c
data ty=
>>: pe in
>>: such a way that it could be used to update a cobol comp-3 field,
or an =
>>: image
>>: P(x) field.  Thanks in advance!
>>
>
And Bary kindly supplied a lot of C code (snipped)
 and I repeat my ealier (private) reply to Cynthia:
Why not a COBOL routine?

LINKAGE SECTION

 01  C-PARM         PIC S9(9) COMP.       ;Putatively an integer
 01  COBOL-PARM     PIC S9(9) COMP-3.     ;A packed variable

PROCEDURE DIVISION


<stuff>

 MOVE  C-PARM TO COBOL-PARM.

I believe that event though an S9(9) COMP and a C int are both 32 bit
(or sign+31 bit) integers, COBOL still relies on the number of digits
listed in the
PICTURE.  Therefore, the full range of a signed C int extends to 10
digits
and can't be fully represented in COBOL-which will truncate the item
unless care is taken with ON SIZE ERROR phrases.
------------------------------------------------------------------------------------
No, Tony is right.  Even though a COBOL PIC S9(9) COMP should only
hold to a maximum of 999,999,999, the compiler only uses your picture
clause as a blueprint for move and display statements.  Internally it will
treat the number as a 32 bit signed integer that can have a maximum
value of (2 ** 31) - 1 or 2,147,483,647, unless you use an on size error
clause.

Try the sample program:
 IDENTIFICATION DIVISION.
 PROGRAM-ID.  TST.
 DATA DIVISION.
 WORKING-STORAGE SECTION.
 77  A PIC S9(9) COMP.
 77  B PIC S9(18) COMP.
 PROCEDURE DIVISION.
 BEG-IT.
     COMPUTE A = (2 ** 31) - 1.
     MOVE A TO B.
     DISPLAY "A = " A.
     DISPLAY "B = " B.
     STOP RUN.

When you run it you will get:
A = +147483647
B = +000000002147483647

Mike Berkowitz
Guess? Inc.

ATOM RSS1 RSS2