Can anyone explain this. We have a text field, (A08), which users enter a Date in the format CCYYMMDD, eg 20090812), and validate it using MASK(20YYMMDD). If a user mistypes and enters the date as 02090812, the validation passes. Why is this?
An simple program showing this is below:
DEFINE DATA LOCAL
01 #A(A08) INIT <‘02090812’>
END-DEFINE
PRINT ‘=’ #A
IF #A = MASK(20YYMMDD)
PRINT ‘Valid’
END-IF
END
The above program displays the ‘Valid’ Statement when run.
The Natural version that is being used is Natural 6.1.1 Pl9.
As stated, your mask is testing for 0 - 2 in the first position and 0 - 0 in the second position. Try ('20’YYMMDD) to see the difference.
I don’t think that either of these edit masks will get you what you want, so search these forums for previous “date mask” posts to see how to get the results that you’re looking for.
Your MASK(20YYMMDD) checks for any value in the range 00-20 in the first two positions. If you just want to check for 20 in the first two positions you can either use Ralph’s suggestion of ‘20’ (which is an alpha MASK) or 20-20 (which is a numeric MASK). My preference would be for the alpha MASK.
However, if you want a range of centuries you might want to code something like 19-21 followed by YYMMDD.
WARNING; this leads to problems for century years. Here is an excerpt from Natural’s documentation:
"When dates are checked for a 2-digit year (YY), the current century will be assumed if no Sliding or Fixed Window is set. For more details about Sliding or Fixed Windows, refer to profile parameter YSLW in the Parameter Reference. "
So, if you code 19-21YYMMDD and have a date 19000229 you will be told this is valid since Natural is testing if 0229 is valid for the year 2000 (it is) rather than the year 1900 (not valid).