1748122 Members
3341 Online
108758 Solutions
New Discussion юеВ

SUbtracting in OpenVMS

 
SOLVED
Go to solution

SUbtracting in OpenVMS

Hi,

I am writing a COM to rename a group of files which satisfy the below condition. The File name has the current date and time
Example: 20100919103344
If the difference between the current date (20100920) and the file date (20100919) is greater than 1, then i need to do certain steps.
I tried this but it is not working as expected.

$file_name = "V2B_20100919103344.TXT"
$file_name = "V2B_20100919103344.TXT_TEMP"
$
$SH SYM file_name
FILE_NAME = "V2B_20100919103344.TXT_TEMP"
$file_date = f$extract(4,8,''file_name)
$SH SYM file_date
FILE_DATE = "20100919"
$CUR_DAT = F$CVTIME(,,"DATE") - "-" - "-"
$SH SYM CUR_DAT
CUR_DAT = "20100920"
$
$FINAL = (CUR_DAT - FILE_DATE)
$SH SYM FINAL
FINAL = "20100920"

Please advice.
34 REPLIES 34
Kris Clippeleyr
Honored Contributor
Solution

Re: SUbtracting in OpenVMS

You could use F$INTEGER on the strings CUR_DAT and FILE_DATE, and then do the subtraction.

Regards,
Kris (aka Qkcl)
I'm gonna hit the highway like a battering ram on a silver-black phantom bike...
abrsvc
Respected Contributor

Re: SUbtracting in OpenVMS

As stated above, use the f$integer lexical as shown in a modified version of your procedure listed bwloe.

Dan

============================================

$file_name = "V2B_20100919103344.TXT"
$file_name = "V2B_20100919103344.TXT_TEMP"
$!
$SH SYM file_name
$file_date = f$extract(4,8,''file_name)
$SH SYM file_date
$CUR_DAT = F$CVTIME(,,"DATE") - "-" - "-"
$SH SYM CUR_DAT
$!
$ c=f$integer("''cur_dat'")
$ f=f$integer("''file_date'")
$FINAL = (c - f)
$SH SYM FINAL
abrsvc
Respected Contributor

Re: SUbtracting in OpenVMS

Please note that the double and single quotes in the F$integer parameter are not required. I am a creature of habitand tend to include them, but they are not required in this context.

Dan
Hein van den Heuvel
Honored Contributor

Re: SUbtracting in OpenVMS



Why subtract? Your requirement
"If the difference between the current date"

_any_ difference will be 1 day or more.

So instead of :

- $FINAL = (CUR_DAT - FILE_DATE)

Use a string compare like:

- $IF CUR_DAT .GTS. FILE_DATE .......


Enjoy,
Hein
John Gillings
Honored Contributor

Re: SUbtracting in OpenVMS

Just to explain the behaviour... this is DCL doing clever things with the minus operator and polymorphic operands.

When DCL sees what appears to be an arithmetic expression containing only "+" and "-" it tries to work out if this is an INTEGER operation or a STRING operation, depending on the apparent types of the operands. In this case CUR_DATE is determined to be STRING, so the operation is STRING. Since the subtrahend is not a substring of the minuend, the result is the minuend.

You need to be very careful with these operators, to make sure DCL understands your intent. Sometimes you need to use F$INTEGER to force an operand to be interpreted as INTEGER or F$STRING to force it to be STRING.
In this case I'd go with Hein and use a comparison. Note that there you also need to be explicit about data type "GTS" for string and "GT" for integer.
A crucible of informative mistakes
John McL
Trusted Contributor

Re: SUbtracting in OpenVMS

Why not get yesterday's date in the same format as used in the filenames, then you can simply compare them.

$ yest_date = F$CVTIME("","COMPARISON","DATE") - "-" - "-"

(The above gives 20100921 when I run it because here it's already 21 Sep here.)

Just compare yest_date to the first 8 characters of your filename string.

It's not clear if you want to rename the files but this would be the simplest because you wouldn't need to check if the files were created earlier than yesterday.

Re: SUbtracting in OpenVMS

Hi All,

Thanks a lot for your replies.
I will be trying today with all of your valuable inputs..

Really thanks a lot..

Re: SUbtracting in OpenVMS

Hi All,

I have a problem now.
Consider this Example:
The current date is 20101001(October 1st 2010). The File date is 20100930.
I went with subtracting them as an integer. But i need the value to be 1. If i subtract, it gives the putput as 71.

Please Help..
The Brit
Honored Contributor

Re: SUbtracting in OpenVMS

Can I ask why you are messing with this subtraction stuff at all.

Is there no way you can do this using the f$delta_time lexical.

F$DELTA_TIME

Returns the time difference between a given start and end time.
The end time must be the same as or later than the start time.

Format

F$DELTA_TIME(start-time,end-time)

Times are supplied as "Absolute", so use f$cvtime to convert FILE_DATE back to absolute, Set CUR_DATE to f$cvtime(,"ABSOLUTE","DATE").

f$delta will return the difference as a Delta time. From which you extract the "day" component to test.

It certainly avoids having to worry about days-in-month.

Dave.