cancel
Showing results for 
Search instead for 
Did you mean: 

Vms DCL Code

 
SOLVED
Go to solution
Steve ward_3
Advisor

Vms DCL Code

I have a com file that prompts user to put in # of day to generate a speicific report. The problem is when a user puts in 500 days the code loops.

Ex. Enter # of Days >

How can I limit the number of days requested to a maximum value of 31 or 365 or whatever.

What would the DCL code be for this?
15 REPLIES 15
Steven Schweda
Honored Contributor
Solution

Re: Vms DCL Code

> The problem is when a user puts in 500
> days the code loops.

What code? I see no code. Perhaps someone
with psychic powers greater than mine could
tell you why "the code loops".

HELP IF
Hein van den Heuvel
Honored Contributor

Re: Vms DCL Code

It would help if you had showed us how the input is being aquired in teh first place.
Command line argument? From terminal?

Here is an example of a value checking read loop:

$MIN_DAYS = 31
$MAX_DAYS = 365
$read_days_loop:
$READ/END=done/PROMPT="Enter # of Days > " SYS$COMMAND days
$IF F$TYPE(days).NES."INTEGER" -
.OR. days.LT.MIN_DAYS -
.OR. days.GT.MAX_DAYS
$THEN
$ WRITE SYS$OUTPUT "Please enter a NUMBER from ''MIN_DAYS' to ''MAX_DAYS'"
$ GOTO read_days_loop
$ENDIF
$
$ WRITE SYS$OUTPUT "Processing ''days' days."
$ GOTO read_days_loop
$
$done:
$ WRITE SYS$OUTPUT "Bye now."

hth,
Hein.


Andy Bustamante
Honored Contributor

Re: Vms DCL Code


You might consider the book, "Writing Real Programs in DCL." http://www.alibris.com/search/books/qwork/8739673/used/Writing%20Real%20Programs%20in%20DCL

Although out of print, it can still be found.

Andy
If you don't have time to do it right, when will you have time to do it over? Reach me at first_name + "." + last_name at sysmanager net
Robert Gezelter
Honored Contributor

Re: Vms DCL Code

Steve,

There are two questions here.

First, the syntax of an IF statement in DCL. This is covered in the "DCL Dictionary", in the standard documentation library, available on the HP OpenVMS www site at http://www.hp.com/go/openvms , and is documented in the online HELP text.

The short answer to that question is something along the lines of:

$ IF (days .ge. 500) then $ xxx

There are several variants that may be appropriate, depending on what is written in the command file already.

There is a second question, namely, WHY is the command file failing? Also, "At what point does the command file fail?". This, IMHO, is a more serious problem. Generally, I recommend careful investigation of this type of question, as it often uncovers far more serious problems.

I hope that the above is helpful.

- Bob Gezelter, http://www.rlgsc.com
Steve ward_3
Advisor

Re: Vms DCL Code

Here is the code
Barry Alford
Frequent Advisor

Re: Vms DCL Code

(Simple solution)
After the line:

$ if f$type(date) .nes. "INTEGER" then goto detail

insert a line:
$ if date .gt. then goto detail

...where is the desired maximum days
jf Marchal
Occasional Visitor

Re: Vms DCL Code

Having replaced the search instructions by a search in a dummy file, I have tested your procedure with no loop occuring.

Maybe you could "set verify" your code and attach the output of the run ?

Jean-Francois
Wim Van den Wyngaert
Honored Contributor

Re: Vms DCL Code

It's when you enter a number bigger than 9999 that it will go wrong.

f$cvtime("-''date'-00",...
will display errors for values bigger than 9999 and this will look like it's looping on an error.

fwiw

Wim
Wim
Steve ward_3
Advisor

Re: Vms DCL Code

(Simple solution)
After the line:

$ if f$type(date) .nes. "INTEGER" then goto detail

insert a line:
$ if date .gt. then goto detail

...where is the desired maximum days

Yes, When I put in 31 days for the max and type in 32 it just hangs there? Shouldn't it just exit or prompt me to put in the right # of days again?
Wim Van den Wyngaert
Honored Contributor

Re: Vms DCL Code

I would also test the miniumum. f$cvt("--1-00") is also a valid syntax.

Wim
Wim
Wim Van den Wyngaert
Honored Contributor

Re: Vms DCL Code

And as I read your code, it should prompt you again (Enter # of Days>").

Wim
Wim
Hein van den Heuvel
Honored Contributor

Re: Vms DCL Code

>> Shouldn't it just exit or prompt me to put in the right # of days again?

Yes, if you made the edit correctly, then it should.
See my early example how to use a single IF with OR clause if desired.

>> it just hangs there

Are you sure? Dcl scripts do not 'just sit there'.
Check at least with control-T or SET VERIFY
(control-Y, $set verify, $continue).



Please note MANY inefficiencies and oddities in the script.

imho that "f$cvtime("-''date'-00"
is better written withotu the "00". That just confuses.

Instead of worrying about spaces in the dates before the 10'th you may want to search using ... /MATCH=AND "Start: ", " ''thedate'"

IF you are going to unconditionally append the search out to a file, then why not have search put it there directly?
Instead of

$create 'outf'
$loop:
$sea/out=x.tmp
$appen x.tmp 'outf'
:
$if .not.done then goto loop

use:

$create 'outf'
$open/append outf 'outf'
$loop:
$sea/out=outf
:
$if .not.done then goto loop
$close outf

But most importantly... don't loop through the file over and over!
You might want to open it with DCL, or an other language, check each record. If it has "Start:", then check the date.

Personally I would use perl.
I'll stick in an example, because the date handling might be tricky for a first time.

Usage:

$perl date-filter.pl stats_dir:autostat.dat 123 > 'outf'

#---- date-filter.pl ----
use strict;
use Time::Local;

my $file = shift or die "Please provide file to search";
my $days = shift or die "Please provide a number of daqys to look for";
my ($sec,$min,$hour,$mday,$mon,$year) = localtime();
my $cutoff = timelocal(0,0,0,$mday,$mon,$year) - $days*86400;

open FILE, "<$file" or die "Could not open search file $file\n$!";
while () {
if (/(\d+)-(\w+)-(\d+)/) {
my $n = index(" JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC", $2)/3;
print if $cutoff < timelocal(0,0,0,$1,$n-1,$3-1900);
}
}
#-------------------------------

Enjoy,
Hein.
John Travell
Valued Contributor

Re: Vms DCL Code

Without checking what else your code does, I cannot fully answer why it hangs for you. On my V8.3 machine the following trivial mod of your code works as expected.
$ maxdays = 365
$detail:
$ read/prompt="ENTER # OF DAYS (up to ''maxdays') > " sys$command date
$ if f$type(date) .nes. "INTEGER" then goto detail
$ if date .gt. maxdays then goto detail

You need to replicate this at 'Summary:', but other than that I cannot see why you have any problem with the code.
John Travell
Valued Contributor

Re: Vms DCL Code

Darn, Hein's response was not there when I started to reply... Pass on mine, Hein did a much better job...
JT:
Hoff
Honored Contributor

Re: Vms DCL Code

[[[Yes, When I put in 31 days for the max and type in 32 it just hangs there? Shouldn't it just exit or prompt me to put in the right # of days again?]]]

Well, only if you coded the DCL to do that, actually.

DCL does what you tell it to do, within its various limits. DCL is certainly arcane, but it's also among the company of most other languages in lacking any sort of magical DWIM (do what I mean) powers. You gotta code it, or it just won't happen.

Now to see what is happening here with your hang, use the verification mechanism; straight SET VERIFY and invoke, or use something akin to:

$ oldvfy = f$verify(f$trnnm("BACKUP_DEBUG"))
[stuff]
$common_exit:
$ vfy = f$verify(oldvfy)
$ exit

to allow you to selectively enable debug with a logical name. Then see what's wedging.

Based on a quick look, that DCL code is laced with design errors and with some subtle restrictions. It's easy for filenames to collide, for instance.

As has been stated, the processing of the input string is best updated. I'd probably swap from:

$detail:
$ read/prompt="ENTER # OF DAYS > " sys$command date
$ if f$type(date) .nes. "INTEGER" then goto detail

over to -- and note I changed "date" to "days" here, which will require changes downstream -- the following:

$detail:
$ read/prompt="ENTER # OF DAYS > " sys$command days
$ days = f$integer(days)
$ if (days .le. 0) .or. (days .gt. 365) then goto detail

This:

$ search prod_admin:backup.log,backup.sav;*

looks broken. Searching the binary saveset? Really?

This:

/output=addm0700_backup_save.tmp

can collide.

This:

$ if f$search("''addm0700*.tmp;'") .nes. "" then purge/nolog 'addm0700*.tmp;';*
$ if f$search("''addm0700*.tmp;'") .nes. "" then delete/nolog 'addm0700*.tmp;';*

looks broken

I'd probably put the days prompt code in a subroutine, since it looks common.)

This:

$ Set proc/priv=all

implies this is some sort of a menu. And f$setprv() is more common. And enabling all privileges at the top of the DCL is just asking for something (else) to get corrupted or deleted. (The good news for those so included: unless that login thing is marked CAPTIVE, full privileges are easily available.)

And I'd add an /ERROR and/or /END_OF_FILE on the READ, to allow a graceful path out if something on the input messes up. Or if the user uses ^Z to try to punt the operation.

I'm not at all certain if my DCL book is in or out of print. It seems to wink in and out of publication status; AFAIK, it's still available as a demand-print book.

Stephen Hoffman
HoffmanLabs LLC