× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



> From: Rich Duzenbury
> 
> D compute             b
> D compute             pi            10a
> D  parm1                            10a
> D  parm2                            10a
> D  parm3                            10a
> 
> D  result             s             10a
>  /free
>     if parm1 <> 'foo';
>         return;
>     endif;
> 
>     if parm2 <> 'bar';
>         return;
>     endif;
> 
>     if parm3 <> 'baz';
>         return;
>     endif;
> 
> 
>     // do the magic here
> 
>     // now return the result
>     return result;
>  /end-free

Nitpick: This won't work because the first three return statements will
be flagged for not returning anything.  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.

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


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 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.