dcl &Date *char 6
dcl &FName *char 10
rtvsysval QDATE rtnvar( &Date )
chgvar &FName ( ‘INVC’ *cat %sst( &Date 1 4 ) )
crtpf MyLib/&FName …</pre>
Retrieve the QDATE system value into a *CHAR(6) variable. Generate your file name into a *CHAR(10) variable. The code above takes the letters ‘INVC’ and concatenates them with four characters from the beginning of the date.
If the system date format is MDY and it is 5 March 2010, then &Date will contain ‘030510’. The first four characters are ‘0305’. When those are concatenated to ‘INVC’, the value in &FName becomes ‘INVC0305 ‘.
If the system date format is DMY, then &Date would be ‘050310’. You might need to retrieve the QDATFMT system value to see what the format is. You would take the substring of the month and day portions as appropriate for the date format. Alternatively, you could simply retrieve the QMONTH and QDAY system values. (But then you’d need to be careful of Julian as a system date format. Various possibilities arise when trying to use some troublesome value like a “date” as part of a name.)
Since names of physical files are limited to ten characters, you need to use six letters or less when you use four characters from the date.
Personally, I’d never use part of a “date” as a name. Dates are already made available as part of the object header. Why try to duplicate that in a name? After all, this is “programming”. Use a different method and code your program accordingly.