shellopenvmsdcl

Need to give option Y or N in DCL scripting


My requirement is -- I need to give two options(yes or no) to users. So whenever user enters other than Y or N then system should throw an error. I created the below piece of code, but it is not giving the expected output.

$ Y:== y
$ N:== n
$ ALPHA:
$ INQUIRE OPTION "Y or N"
$ DEFINE/NOLOG Report_file 'OPTION'
$       if f$type (OPTION) .eqs. "INTEGER"
$       then
$                   esc[0,7] = 27
$                   text = "Numeric values not accepted !!"
$                   write sys$output   "''esc'[5m''text'''esc'[m"
$               wait 0:0:0.15
$               set term/width=132
$               goto ALPHA
$       endif
$ if 'OPTION' .NES. Y 
$ then
$                 esc[0,7] = 27
$                 text = "Enter "Y" or "N""
$                 write sys$output   "''esc'[5m''text'''esc'[m"
$ endif
$ if 'OPTION' .NES. N
$ then
$                  esc[0,7] = 27
$                  text = "Enter "Y" or "N""
$                  write sys$output   "''esc'[5m''text'''esc'[m"
$ endif

Whenever I try to give interger values then it is running as I designed.. But when I am trying to enter A,B,C etc other than Y or N, then it is giving the below warning.

Aksh - $-> @test.com
Y or N: k
%DCL-W-UNDSYM, undefined symbol - check validity and spelling
\K\
%DCL-W-UNDSYM, undefined symbol - check validity and spelling
\K\
%DCL-W-UNDSYM, undefined symbol - check validity and spelling
\K\

Any suggestions on this ??


Solution

  • Hmmm, seems to me you simply need to un-quote your string compare variable and and quote the fixed string values:

    bad: if 'OPTION' .NES. Y good: if OPTION .NES. "Y"

    Some folks like goof: if "''OPTION'" .NES. "Y" ! This will show the value for OPTION when run with SET VERIFY

    Free advice...

    1) Never assign values before verifying: - DEFINE/NOLOG Report_file 'OPTION' ---> move to bottom of script after validation ---> use "''OPTION'" if you ever want to accept spaces in the OPTION answer (not the case)

    2) Be a little nicer to the users - consider using F$EXTRACT to just get the first character of OPTION to also allows "Yes" (and "Yeah!") - use F$EDIT to UPPERCASE before comparing. - consider using F$LOC to find OPTION in a list of acceptable values like "YyNn"

    Try this:

    $ Y:== y
    $ N:== n
    $ esc[0,7] = 27
    $ALPHA:
    $ INQUIRE OPTION "Y or N"
    $ if OPTION .NES. Y .and. OPTION .NES. N
    $ then
    $     text =  "Enter ""Y"" or ""N"""
    $     write sys$output   esc + "[5m" + text + esc + "[m"
    $     goto ALPHA
    $ endif
    $ DEFINE/NOLOG Report_file 'OPTION'