WHEN-COMPILED Function [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation
HP COBOL II/XL Reference Manual
WHEN-COMPILED Function
The WHEN-COMPILED function returns the date and time the system compiled
your program and the difference between the local time when your program
was compiled and Universal Coordinated Time (UTC) or Greenwich Mean Time.
To get the correct time differential, you need to set the environment
variable TZ to your local time zone before compiling programs that
contain this function. See below for more information. The function
type is alphanumeric.
This function is different from the WHEN-COMPILED special register word
(described in Chapter 3 ). One difference is that the WHEN-COMPILED
function provides a four-digit year.
Syntax
FUNCTION WHEN-COMPILED
Return Value
This function returns a 19-character alphanumeric string with each
character position defined as follows:
Character Contents
Positions
1-4 Four numeric digits of the year in the Gregorian calendar.
5-6 Two numeric digits of the month of the year, in the range
01 through 12.
7-8 Two numeric digits of the day of the month, in the range 01
through 31.
9-10 Two numeric digits of the hours past midnight, in the range
00 through 23.
11-12 Two numeric digits of the minutes past the hour, in the
range 00 through 59.
13-14 Two numeric digits of the seconds past the minute, in the
range 00 through 59.
15-16 Two numeric digits of the hundredths of a second past the
second, in the range 00 through 99. The value 00 is
returned because your system cannot provide the fractional
part of a second.
17 One of the following:
Value When Returned
- Returned if the local time of compilation in the
previous character positions is behind Greenwich
Mean Time.
+ Returned if the local time indicated is the same
as or ahead of Greenwich Mean Time.
0 Returned on non-MPE XL systems that do not have
the facility to provide the local time
differential factor.
Table 10-7. (cont.)
Character Contents
Positions
18-19 Depending on the value of character position 17, one of the
following:
Position 17 Contents
- Two numeric digits in the range 00 through 12
indicating the number of hours that the
reported time is behind Greenwich Mean Time.
+ Two numeric digits in the range 00 through 13
indicating the number of hours that the
reported time is ahead of Greenwich Mean Time.
0 The value 00 is returned.
20-21 Depending on the value of character position 17, one of the
following:
Position 17 Contents
- Two numeric digits in the range 00 through 59
indicating the number of additional minutes
that the reported time is behind of Greenwich
Mean Time.
+ Two numeric digits in the range 00 through 59
indicating the number of additional minutes
that the reported time is ahead of Greenwich
Mean Time.
0 The value 00 is returned.
The returned value is the date and time of compilation of the source
program that contains this function. If the program is a contained
program, the returned value is the compilation date and time of the
separately compiled program in which it is contained.
Setting the TZ Environment Variable
To get the correct difference between local time and Greenwich Mean Time,
you must set the environment variable TZ to your local time zone. To set
TZ, use the MPE XL SETVAR command. For example, the following command
sets the time zone to Central Standard Time and Central Daylight Time,
which would be correct for Chicago, Illinois:
:SETVAR TZ 'CST6CDT'
See the function CURRENT-DATE earlier in this chapter for a table of time
zones. Check your local time zone to be sure you use the correct one.
Example
01 FULL-COMPILED-DATE.
05 C-DATE.
10 C-YEAR PIC 9(4).
10 C-MONTH PIC 99.
10 C-DAY PIC 99.
05 C-TIME.
10 C-HOUR PIC 99.
10 C-MINUTES PIC 99.
10 C-SECONDS PIC 99.
10 C-SEC-HUND PIC 99.
05 C-TIME-DIFF.
10 C-GMT-DIR PIC X.
10 C-HOUR PIC 99.
10 C-MINUTES PIC 99.
:
MOVE FUNCTION WHEN-COMPILED TO FULL-COMPILED-DATE.
DISPLAY "Full date is: ", FULL-COMPILED-DATE.
DISPLAY "Year is: ", C-YEAR.
DISPLAY "Month is: ", C-MONTH.
DISPLAY "Day is: ", C-DAY.
DISPLAY "Hour is: ", C-HOUR OF C-TIME.
DISPLAY "Minute is: ", C-MINUTES OF C-TIME.
DISPLAY "Second is: ", C-SECONDS.
DISPLAY "Hundredths of seconds is: ", C-SEC-HUND.
DISPLAY "Difference from GMT is: ", C-GMT-DIR.
DISPLAY "Hours from GMT is: ", C-HOUR OF C-TIME-DIFF.
DISPLAY "Minutes from GMT is: ", C-MINUTES OF C-TIME-DIFF.
The above example displays the following:
Full date is: 1991022016512900-0800
Year is: 1991
Month is: 02
Day is: 20
Hour is: 16
Minute is: 51
Second is: 29
Hundredths of seconds is: 00
Difference from GMT is: -
Hours from GMT is: 08
Minutes from GMT is: 00
MPE/iX 5.0 Documentation