HP3000-L Archives

October 2004, 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:
Walter Murray <[log in to unmask]>
Reply To:
Walter Murray <[log in to unmask]>
Date:
Mon, 18 Oct 2004 14:48:06 -0500
Content-Type:
text/plain
Parts/Attachments:
text/plain (87 lines)
 "Peter Smithson" <[log in to unmask]> wrote:

> I must be doing something really stupid.

You can be forgiven.  HP COBOL doesn't support a full 16-bit unsigned binary
data type, which explains why you got 1996 instead of 53540 for today's date
(2004-10-18).

> The documentation for item 6 (file creation date) is that it uses the
> CALENDAR intrinsic format which says -
>
> Bits   Value/Meaning
> 7:9   Day of year
> 0:7   Year since 1900
>
> I get a bit confused with this notation.  Is that saying that the low 9
> bits are the year and the high 7 is the year?

That is correct.  (You meant to say the low 9 bits are the day of the year.)

> So today is year 104, day 292.  So the value I'd expect is
> 292 + 104 * (2^9) which is 53540.

Correct again, interpreting the return value as a 16-bit unsigned binary
integer.

> When I run a test program on MPE I get 1996 which is day 460 year 03.

You probably described the item as PIC 9(4) COMP or PIC S9(4) COMP.  That
makes COBOL allocate the correct amount of space, but says that the value
will never exceed 9999.  That causes COBOL to mess up ("mess up" is a highly
technical compiler term :-) and not do what you expected when you displayed
the item containing the value 53540.

Here is how you can see why you got the result you did, if you want to work
through the binary representation.  Take the 16-bit binary representation
for 53540, i.e., the value you got back from CALENDAR.  In hex, this is
$D124.  If you think of it as signed, then the high-order bit is 1, which
implies a negative number, so take the absolute value by doing a
two's-complement operation.  This gives $2EDC.  Convert to decimal.  You get
11996.  Truncate to four digits.  Voila!  1996, the answer you saw.

Or, letting the Command Interpreter do the work:

     :CALC ABS (53540 LSL 16 ASR 16) MOD 10000

which gives 1996.

You'll probably get a lot of good suggestions on how to do what you want.
I'll just suggest that you check out the ALMANAC intrinsic, if you're not
familiar with it.

If you really want to see the numeric value of the item returned from
CALENDAR, in this case 53540, here's a COBOL kludge that will work:

-----cut here-----
 IDENTIFICATION DIVISION.
 PROGRAM-ID. CALENDAR-TEST.
 DATA DIVISION.
 WORKING-STORAGE SECTION.
 01  CALENDAR-X.
     02  FILLER    PIC 9(4)    COMP    VALUE 0.
     02  CAL16     PIC 9(4)    COMP.
 01  CALENDAR-N    REDEFINES CALENDAR-X    PIC 9(9)    COMP.
 PROCEDURE DIVISION.
 BEGIN.
     CALL INTRINSIC "CALENDAR" GIVING CAL16
     DISPLAY CALENDAR-N
     STOP RUN.
 END PROGRAM CALENDAR-TEST.
-----cut here-----

Hope this helps.

Walter





----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---

* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *

ATOM RSS1 RSS2