CL Programming

Retrieving System Values

A system value contains control information for the operation of certain parts of the system. IBM supplies several types of system values. For example, QDATE and QTIME are date and time system values, which you set when OS/400 is started.

You can bring system values into your procedure and manipulate them as variables using the Retrieve System Value (RTVSYSVAL) command:

RTVSYSVAL  SYSVAL(system-value-name)  RTNVAR(CL-variable-name)

The RTNVAR parameter specifies the name of the variable in your CL procedure that is to receive the value of the system value.

The type of the variable must match the type of the system value. For character and logical system values, the length of the CL variable must equal the length of the value. For decimal values, the length of the variable must be greater than or equal to the length of the system value. System value attributes are defined in the iSeries Information Center under the Systems Management category of information.

System Value QTIME

In the following example, QTIME is received and moved to a variable, which is then compared with another variable.

      PGM
      DCL  VAR(&PWRDNTME)  TYPE(*CHAR)  LEN(6)  VALUE('162500')
      DCL  VAR(&TIME)  TYPE(*CHAR)  LEN(6)
      RTVSYSVAL  SYSVAL(QTIME)  RTNVAR(&TIME)
      IF  (&TIME *GT &PWRDNTME)  THEN(DO)
      SNDBRKMSG('Powering down in 5 minutes.  Please sign off.')
      PWRDWNSYS  OPTION(*CNTRLD)  DELAY(300)  RESTART(*NO)  +
               IPLSRC(*PANEL)
 
      ENDDO
      ENDPGM

See the Systems Management category of information in the iSeries Information Center for a list of system values and how you can change and display them.

System Value QDATE

In many applications, you may want to use the current date in your procedure by retrieving the system value QDATE and placing it in a variable. You may also want to change the format of that date for use in your procedure. To convert the format of a date in a CL procedure, use the Convert Date (CVTDAT) command.

The format for the system date is the system value QDATFMT, which is initially MDY (monthdayyear). For example, 062488 is the MDY format for June 24 1988. You can change this format to the YMD, DMY, or the JUL (Julian) format. For Julian, the QDAY value is a 3-character value from 001 to 366. It is used to determine the number of days between two dates. You can also delete the date separators or change the character used as a date separator with the CVTDAT command.

Note:
The shipped value of QDATFMT varies according to country.

The format for the CVTDAT command is:

CVTDAT    DATE(date-to-be-converted) TOVAR(CL-variable) +
          FROMFMT(old-format) TOFMT(new-format) +
          TOSEP(new-separators)

The DATE parameter can specify a constant or a variable to be converted. Once the date has been converted, it is placed in the variable named on the TOVAR parameter. In the following example, the date in variable &DATE, which is formatted as MDY, is changed to the DMY format and placed in the variable &CVTDAT.

CVTDAT    DATE(&DATE) TOVAR(&CVTDAT) FROMFMT(*MDY) TOFMT(*DMY)
          TOSEP(*SYSVAL)

The date separator remains as specified in the system value QDATSEP.

The CVTDAT command can be useful when creating objects or adding a member that uses a date as part of its name. For example, assume that a member must be added to a file using the current system date. Also, assume that the current date is in the MDY format and is to be converted to the Julian format.

PGM
DCL &DATE6 *CHAR  LEN(6)
DCL &DATE5  *CHAR  LEN(5)
RTVSYSVAL  QDATE  RTNVAR(&DATE6)
CVTDAT  DATE(&DATE6)  TOVAR(&DATE5)  TOFMT(*JUL)  TOSEP(*NONE)
ADDPFM  LIB1/FILEX  MBR('MBR'  *CAT  &DATE5)
.
.
.
ENDPGM

If the current date is 5 January 1988, the added member would be named MBR88005.

Remember the following when converting dates:

The following is an alternative program that uses the ILE bindable API, Get Current Local Time (CEELOCT), to convert a date to Julian format. To create this program, you must use the CRTBNDCL command alone or the CRTCLMOD command and the CRTPGM command together.

PGM
DCL  &LILDATE  *CHAR  LEN(4)
DCL  &PICTSTR  *CHAR  LEN(5)  VALUE(YYDDD)
DCL  &JULDATE  *CHAR  LEN(5)
DCL  &SECONDS  *CHAR  8       /*  Seconds from CEELOCT  */
DCL  &GREG     *CHAR  23      /*  Gregorian date from CEELOCT  */
                              /*                               */
CALLPRC  PRC(CEELOCT)         /*  Get current date and time    */ +
         PARMS (&LILDATE)     /*  Date in Lilian format        */ +
                &SECONDS      /*  Seconds field will not be used  */
                &GREG         /*  Gregorian field will not be used */
                *OMIT         /*  Omit feedback parameter so exceptions +
                                  are signalled     */
 
CALLPRC  PRC(CEEDATE) +
         PARMS (&LILDATE)     /*  Today's date                 */ +
                &PICTSTR      /*  How to format                */ +
                &JULDATE      /*  Julian date                  */ +
                *OMIT
 
ADDPGM   LIB1/FILEX  MBR('MBR'  *CAT   &JULDATE')
 
ENDPGM

See the Programming category of information in the iSeries Information Center for more information on ILE API's.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]