|
On Wed, 2005-08-03 at 07:46 -0500, Joe Pluta wrote:
> > From: Rich Duzenbury
> >
> Nitpick: This won't work because the first three return statements will
> be flagged for not returning anything.
Right, as I said "not drawn to scale" -- I didn't compile any of this,
just off the top of my head.
> But it does bring up an
> interesting class of problems, the "single-error validation routine"
> (SEVR). In the single-error validation routine, the first error
> encountered causes a failure and the program ends. As it happens, RPG
> has an absolutely outstanding way to handle that situation:
>
> /free
> select;
> when parm1 <> 'foo';
> rc = '*BADPARM1';
>
> when parm2 <> 'bar';
> rc = '*BADPARM2';
>
> when parm3 <> 'baz';
> rc = '*BADPARM3';
>
> other;
> rc = '*OKAY';
> // do the magic here
> endsl;
>
> // now return the result
> return result;
> /end-free
>
> Not a lot of people think of using select this way, especially Java
> programmers, because in most languages the "switch" statement is the
> closest analogue, and switch supports only comparing a single value.
> Because you can have complex comparisons on every when, the select
> statement is much more powerful and lends itself quite nicely.
Hmm, it does work, but seems a bit 'tricky' to me. Some maintenance
programmers I know would look at that select and say to themselves -
"hey, these select clauses don't do anything. I can delete them."
>
> BTW, the MEVR (multiple-error validation routine) is better handled
> using if statements. Typically an MEVR returns a Boolean (good/bad); it
> calls a routine to log each error in some way.
>
> /free
> valid = *on;
>
> if parm1 <> 'foo';
> sendError('Parm 1 Error');
> valid = *off;
> endif;
>
> if parm2 <> 'bar';
> sendError('Parm 2 Error');
> valid = *off;
> endif;
>
> if parm3 <> 'baz';
> sendError('Parm 3 Error');
> valid = *off;
> endif;
>
> if valid;
> // do the magic here
> endif;
>
> // now return the result
> return valid;
> /end-free
>
> Joe
>
This looks excellent. Easy to read and easy to understand.
Regards,
Rich
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.