On Sun, 20 Jun 2021, at 17:25, Paul Gilmartin wrote:
> On Sun, 20 Jun 2021 16:09:54 +0100, Jeremy Nicoll wrote:
> >
> >> So what would you do? Suppose it'd not just [been] three things
> >> that need to be exclu[d]ed first but, say, twenty?
> >
> >select
> > when words(f!ce_bfe) \== 1 then f!ce_err = "bfe '"f!ce_bfe"' not a
> > single word"
> > when \datatype(f!ce_ssn,"W") then f!ce_err = "ssn '"f!ce_ssn"' not a
> > whole number"
> > when \datatype(f!ce_ssx,"W") then f!ce_err = "ssx '"f!ce_ssx"' not a
> > whole number"
> > when \datatype(f!ce_wcn,"W") then f!ce_err = "wcn '"f!ce_wcn"' not a
> > whole number"
> > when \datatype(f!ce_wcx,"W") then f!ce_err = "wcx '"f!ce_wcx"' not a
> > whole number"
> > when \datatype(f!ce_wln,"W") then f!ce_err = "wln '"f!ce_wln"' not a
> > whole number"
> > when \datatype(f!ce_wlx,"W") then f!ce_err = "wlx '"f!ce_wlx"' not a
> > whole number"
> > when \datatype(f!ce_wld,"W") then f!ce_err = "wld '"f!ce_wld"' not a
> > whole number"
> > otherwise f!ce_err = ""
> >end
> >
> I see. I'd be inclined to code the repetitive part of that as a loop.
There'd be no gain in converting the 8 separate named-for-what-they do variables
into stem variables if that's what you mean, unless one also defined _bfe, _ssn
etc
as separate subscripts. The vars are in fact the parameters to the function,
originally
set via
parse arg
f!ce_tst,f!ce_bfe,f!ce_ssn,f!ce_ssx,f!ce_stm,f!ce_wcn,f!ce_wcx,f!ce_wln,f!ce_wlx,f!ce_wld
Referring to each of those as a stem variable in the code that follows would
just
make the following code more cumbersome.
Also note that the tests are not all the same, though most here are. There's
other examples in my programs where the tests performed in each "when" are
wildly different, and there's far more than just 8 of them.
(These are the parameters passed to the function, which is called from lots of
other routines to do parameter validation. The _bfe, _ssn, _ssx vars etc
mostly
represent either a flag dictating whether or not a certain form of validation
should be performed, or also a value required for it. For example _ssn and
_ssx are the miNimum and maXimum values of a ("ss") string's size (ie length).
A typical call is ALWAYS accompanied by a parameter comment, eg
*
bfe,ssn,ssx,stm,wcn,wcx,wln,wlx,wld
f!mn_chk = "func_jn_chk_encp"(f!mn_optns,"L", 2, -1, "", 1, -1, 2, -1,
2)
(which will look sensible in a fixed-space font). That's a call from a menu-
handling function, when it is validating the value of the: f!mn_optns
parameter, which should look something like "L=(xxxx xx ... xxxx)". It's
checking that the "L=(" and trailing ")" are present and that what's inside
the brackets meets certain conditions. )
> >if f!ce_err \== "" then do
> > f!ce_rettxt = f!ce_errpfx f!ce_err
> > signal func_jn_chk_encp_z
> >end
> >
> SIGNAL? I suppose it's OK here.
Thank-you, that's big of you. It's a branch to the end of the function, so
that there's only one place where control returns to the caller.
What would you suggest instead? I don't want to have to indent the
whole of the following code in a monster
if f!ce_err == "" then do
...
end
structure, nor (if I didn't do that) add "& f!ce_err == "") to every other
condition that follows this lot.
I only use signal in error handling / immediate exit/return situations.
--
Jeremy Nicoll - my opinions are my own.
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN