|Click here for Watson System Resources sponsor message|
Using New Date Intrinsics in COBOL II
By Shawn M.
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, Ill be taking a slight detour to cover Y2K issues before addressing anything else I have already promised. In that spirit, lets 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 CSYs 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.
Heres the lineup of intrinsics:
1. HPDATECONVERT: converts dates from one supported
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
6. A new 32-bit HPCALENDAR format (HPCALENDAR, HPFMTCALENDAR).
There are a couple of things you should be sure to do correctly when using these intrinsics. HPs 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.
Im 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). CALL INTRINSIC "HPDATEFORMAT" USING \DATE-CODE\, FROM-DATE, HOLD-FORMAT, FORMAT-DATE, FORMAT-LEN, DATE-STATUS, \DATE-CUTOFF\. IF S-INFO <> 0 DISPLAY "Error in HPDATEFORMAT". CALL INTRINSIC "HPDATEDIFF" USING \DATE-CODE\, FROM-DATE, THRU-DATE, DUMMY-VAL, DATE-STATUS, \DATE-CUTOFF\. IF S-INFO <> 0 DISPLAY "Error in HPDATEDIFF". CALL INTRINSIC "HPDATEOFFSET" USING \DATE-CODE\, FROM-DATE, \DAYS-DIFF\, THRU-DATE, DATE-STATUS, \DATE-CUTOFF\. IF S-INFO <> 0 DISPLAY "Error in HPDATEOFFSET". CALL INTRINSIC "HPDATEVALIDATE" USING \DATE-CODE\, FROM-DATE, \DATE-CUTOFF\ GIVING DATE-RESULT. IF S-INFO <> 0 DISPLAY "Error in HPDATEVALIDATE".Figure 2