Midware Ltd.

Omitting Parameters

Home
Services
News
AS/400
Employment

Sign-up for e-mail notifications

Take our weekly poll

Dow Jones Intraday

Nasdaq Intraday

 

 

The OPTIONS(*NOPASS) parameter gives us a quick and easy way of making certain parameters optional.  There is one major drawback though.

Let's say for example that we also want our IsWorkday procedure to return an optional indicator to the calling procedure to indicate if the date is a weekday or weekend.  The procedure now has two optional parameters.  Let's say we set up our procedure interface like this:

D++++++++++++++++++++++++++++++++++++++++++++++++++++++
D IsWorkday       PI              N
D  @Date                         8  0  const
D  @WeekDay                       N    options(*nopass)
D  @RtnCode                      3  0  options(*nopass)

Because of the limitations of OPTIONS(*NOPASS), if the user wants the procedure to return the error code, the @Weekday parameter MUST also be passed.  This forces the user to setup a dummy field for the undesired return value.

A better way to handle this situation is to use the OPTIONS(*OMIT) keyword.  This allows users of the procedure to pass the literal value "*OMIT" instead of an actual field.  *OMIT may be used on any of the parameters.  Parameters following a *OMIT do not also have to be coded with *OMIT.

The *OMIT parameter may be used in conjunction with *NOPASS to indicate that the parameter can be omitted either with the *OMIT literal or by leaving the position empty.

Using the *OMIT and *NOPASS keywords, our procedure interface now looks like this:

D+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
D IsWorkday       PI              N
D  @Date                         8  0  const
D  @WeekDay                       N    options(*nopass: *omit)
D  @RtnCode                      3  0  options(*nopass)

The procedure may be called with any of these methods:

if        IsWorkday(991231)

if        IsWorkday(991231: *in88: @Error)

if        IsWorkday(991231: *omit: @Error)

if        IsWorkday(991231: *in88)

Now, with one statement, a user can return three different pieces of information about one date - is it a valid date, is it a weekday, and is it a workday.

Although you can, it doesn't really make sense to code *OMIT on the last parameter.


Determining if a parameter has been *OMIT-ted

If *OMIT has been passed as a parameter, it will be included in the %PARMS built in function.  For example:

if        IsWorkday(991231: *in88: @Error)

will set the %PARMS built in function to 3.

The only way to check if *OMIT was passed is to check the memory address of the parameter in question.  If the address is set to *NULL, then *OMIT was passed.  If both *OMIT and *NOPASS are allowed for a parameter, you should use both %PARMS and %ADDR to check for a valid value.  For example:

if        %parms > 1
    something was passed
if        %addr(@WeekDay) = *null
    *OMIT was passed
else
    a valid field was passed
endif
else
    the parameter was not passed
endif

  Back to Advanced Parameter Passing

Next to Variable Size Strings

 
Home Feedback Contents Search

Send mail to midware@midwareservices.com with questions or comments about this web site.
Copyright 2000 Midware, Ltd.

Last Modified:  September 07, 2000