TEST (Test Date/Time/Timestamp)

Free-Form Syntax TEST{(EDTZ)} {dtz-format} field-name
Code Factor 1


Factor 2 Result Field


TEST (E) Date/Time or Timestamp Field _ ER _
TEST (D E) Date Format Character or Numeric field _ ER _
TEST (E T) Time Format Character or Numeric field _ ER _
TEST (E Z) Timestamp Format Character or Numeric field _ ER _

The TEST operation code allows users to test the validity of date, time, or timestamp fields prior to using them.

For information on the formats that can be used see Date Data Type, Time Data Type, and Timestamp Data Type.

Numeric fields and character fields without separators are tested for valid digit portions of a Date, Time, or Timestamp value. Character fields are tested for both valid digits and separators.

If the character or numeric field specified as the field-name operand is longer than required by the format being tested, extra data is ignored. For character data, only the leftmost data is used; for numeric data, only the rightmost data is used. For example, if the dtz-format operand is *MDY for a test of a numeric date, only the rightmost 6 digits of the field-name operand are examined.

For the test operation, either the operation code extender 'E' or an error indicator ER must be specified, but not both. If the content of the field-name operand is not valid, program status code 112 is signaled. Then, the error indicator is set on or the %ERROR built-in function is set to return '1' depending on the error handling method specified. For more information on error handling, see Program Exception/Errors.

For more information, see Date Operations or Test Operations.

Figure 388. TEST (E D/T/Z) Example
D Datefield       S               D   DATFMT(*JIS)
D Num_Date        S              6P 0 INZ(910921)
D Char_Time       S              8    INZ('13:05 PM')
D Char_Date       S              6    INZ('041596')
D Char_Tstmp      S             20    INZ('19960723140856834000')

D Char_Date2      S              9A   INZ('402/10/66')
D Char_Date3      S              8A   INZ('2120/115')
 *  Indicator 18 will not be set on, since the character field is a
 *  valid *ISO timestamp field, without separators.
C     *ISO0         TEST (Z)                Char_Tstmp             18
 *  Indicator 19 will not be set on, since the character field is a
 *  valid *MDY date, without separators.
C     *MDY0         TEST (D)                Char_Date              19
 *  %ERROR will return '1', since Num_Date is not *DMY.
C     *DMY          TEST (DE)               Num_Date
 *  No Factor 1 since result is a D data type field
 *  %ERROR will return '0', since the field
 *  contains a valid date
C                   TEST (E)                Datefield
 * In the following test, %ERROR will return '1' since the
 * Timefield does not contain a valid USA time.
C     *USA          TEST (ET)               Char_Time
 *  In the following test, indicator 20 will be set on since the
 *  character field is a valid *CMDY, but there are separators.
C     *CMDY0        TEST (D)                char_date2             20
 *  In the following test, %ERROR will return '0' since
 *  the character field is a valid *LONGJUL date.
C     *LONGJUL      TEST (DE)               char_date3

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