0

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
  • Output is :

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 ??

  • Tip: You can use the [`set verify`](http://h41379.www4.hpe.com/doc/83final/9996/9996pro_224.html) command to debug DCL procedures. That should at least pin down the problem line pretty quickly. – HABO Sep 12 '17 at 16:44

1 Answers1

0

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'
Hein
  • 1,453
  • 8
  • 8
  • Never mind... I did not see the $ Y:== y $ N:== n on the top. That's sooo confusing. Why? And why rely on the auto-upcase, just too confusing. Anyway, using the symbols (fooled me!) you do NOT need the "Y" in the test, but you still must not use the single-quoted 'OPTION' as this become a naked word, not a string. Just use the symbol, don't use the substitution quotes. – Hein Sep 12 '17 at 16:15