Click here for Watson System Resources sponsor message

Using New Date Intrinsics in COBOL II

By Shawn M. Gordon

Since Year 2000 is rapidly approaching, I am going to be covering anything that comes up in that arena concerning COBOL. Since its timing is more critical, I’ll be taking a slight detour to cover Y2K issues before addressing anything else I have already promised. In that spirit, let’s review the new date intrinsics that HP gave us in MPE/iX 5.5 PowerPatch 4.

I have been doing a lot of Y2K consulting lately, and it seems that everyone has written their own date routines. Most that I have seen will break shortly. My goal in my consulting was to implement the HP-supplied solution, making it easier to support YYMMDD as well as YYYYMMDD date functions during the conversion process.

The official documentation for these new intrinsics can be found at CSY’s Jazz Web site. The only negative comment I have about these intrinsics is that I wish they had been created 10 years ago, with the introduction of the Spectrum series of HP 3000s (MPE/XL systems). I could have used them then, too.

There are six new intrinsics available, and the documentation from Jazz only shows one short example. What you will notice is that all the parameters to all the intrinsics are now 32-bit. I believe this means they will work for as long as anyone reading this will ever care.

Here’s the lineup of intrinsics:

1. HPDATECONVERT: converts dates from one supported format to another
2. HPDATEFORMAT: converts a date into a display type (I usually use this instead of HPDATECONVERT)
3. HPDATEDIFF: returns the number of days between to given dates
4. HPDATEOFFSET: returns a date that is plus or minus the number of days from the source date
5. HPDATEVALIDATE: verifies that the date conforms to a supported date format

There are a couple of things you should be sure to do correctly when using these intrinsics. HP’s documentation shows that some parameters on some intrinsics need to be passed by value (see my examples in Figure 1 with DATE-CODE, DAYS-DIFF and DATE-CUTOFF). You do this by putting the \ backward slashes around the variable name.

The other thing that can be confusing is the DATE-CUTOFF. This defines a “split” year. If anything is below this value, it will be translated to the next century. In other words, if the value of DATE-CUTOFF is 50, and you are using a 2 digit year of 00..49, then it will be resolved as 2000..2049, and those in the range of 50..99 will be 1950..1999.

If you use a value of -1, then the intrinsic will pick up the value of the predefined system variable HPSPLITYEAR. This method lets you control the value outside of your program, so I use a DATE-CUTOFF of -1 to stay modular.

The other thing to note is DATE-CODE, which indicates the style of the date that you are working with. I am using 15 because it works with both YYMMDD and YYYYMMDD format.

I’m including some code examples in Figure 1 of the variable declarations, as well as results (Figure 2) of running a program MYDATE which uses the functions.

Figure 1

       01 DATE-CODE            PIC S9(9)  COMP VALUE 15.
       01 DATE-RESULT          PIC S9(9)  COMP VALUE 0.
       01 DATE-STATUS.
          03 S-INFO            PIC S9(4)  COMP VALUE 0.
          03 S-SUBSYS          PIC S9(4)  COMP VALUE 0.
       01 DATE-CUTOFF          PIC S9(9)  COMP VALUE -1.
       01 FORMAT-LEN           PIC S9(9)  COMP VALUE 20.
       01 FROM-DATE            PIC 9(8)   COMP.
       01 THRU-DATE            PIC 9(8)   COMP.
       01 DAYS-DIFF            PIC S9(9)  COMP.
       01 FORMAT-DATE          PIC X(20).
       01 FORMAT-TYPE          PIC X(20).

           IF S-INFO <> 0
              DISPLAY "Error in HPDATEFORMAT".

           IF S-INFO <> 0
              DISPLAY "Error in HPDATEDIFF".

           IF S-INFO <> 0
              DISPLAY "Error in HPDATEOFFSET".

                                          GIVING DATE-RESULT.
           IF S-INFO <> 0
              DISPLAY "Error in HPDATEVALIDATE".
Figure 2


Enter date in YYMMDD or YYYYMMDD format: 19980317
Enter date format string: MM/DD/YY
Formatted date is 03/17/98
Julian date is 01998076

Enter From date: 19980101
Enter Thru date: 19980501
Number of days = +000000120

Enter start date: 19980801
Enter day offset: -31
New date is 19980701
I feel it’s important to standardize on these new HP-supplied intrinsics. They will make it a lot safer than trying to maintain some piece of code that was probably written 20 years ago. With code that old, it’s likely that nobody remembers how it works.

Don’t forget, if your tips make it into The Wire, you get a free 3000 Always Online hat. Send them to me at, or fax them to the NewsWire at 512.331.3807.

Shawn M. Gordon, whose S.M. Gordon & Associates firm supplies HP 3000 utilities, has worked with 3000s since 1983.

Copyright 1998, The 3000 NewsWire. All rights reserved.