OPTIONS(*NOPASS *OMIT *VARSIZE *STRING *TRIM *RIGHTADJ *NULLIND)
- Whether a parameter must be passed
- Whether the special value *OMIT can be passed for the parameter passed by reference.
- Whether a parameter that is passed by reference can be shorter in length than is specified in the prototype.
- Whether the called program or procedure is expecting a pointer to a null-terminated string, allowing you to specify a character expression as the passed parameter.
- Whether the parameter should be trimmed of blanks before being passed.
- Whether the parameter value should be right-adjusted in the passed parameter.
- Whether the null-byte-map should be passed with the parameter.
When OPTIONS(*NOPASS) is specified on a definition specification, the parameter does not have to be passed on the call. Any parameters following that specification must also have *NOPASS specified. When the parameter is not passed to a program or procedure, the called program or procedure will simply function as if the parameter list did not include that parameter. If the unpassed parameter is accessed in the called program or procedure, unpredictable results will occur.
When OPTIONS(*OMIT) is specified, then the value *OMIT is allowed for that parameter. *OMIT is only allowed for CONST parameters and parameters which are passed by reference. For more information on omitted parameters, see the chapter on calling programs and procedures in Rational Development Studio for i: ILE RPG Programmer's Guide.
OPTIONS(*VARSIZE) is valid only for parameters passed by reference that have a character, graphic, or UCS-2 data type, or that represent an array of any type.
For parameters passed by reference, the address of the passed parameter is passed on the call except when a temporary is used for a read-only reference parameter; in that case, the address of the temporary is passed on the call. For more information about the use of a temporary with a read-only reference parameter, see CONST{(constant)}.
When OPTIONS(*VARSIZE) is specified, the passed parameter may be shorter or longer in length than is defined in the prototype. It is then up to the called program or subprocedure to ensure that it accesses only as much data as was passed. To communicate the amount of data passed, you can either pass an extra parameter containing the length, or use operational descriptors for the subprocedure. For variable-length fields, you can use the %LEN built-in function to determine the current length of the passed parameter.
When OPTIONS(*VARSIZE) is omitted for fixed-length fields, you must pass at least as much data as is required by the prototype; for variable-length fields, the parameter must have the same declared maximum length as indicated on the definition.
When OPTIONS(*STRING) is specified for a basing pointer parameter passed by value or by constant-reference, you may either pass a pointer or a character expression. If you pass a character expression, a temporary value will be created containing the value of the character expression followed by a null-terminator (x'00'). The address of this temporary value will be passed to the called program or procedure.
When OPTIONS(*RIGHTADJ) is specified for a CONST or VALUE parameter in a prototype, the character, graphic, or UCS-2 parameter value is right adjusted. This keyword is not allowed for a varying length parameter within a procedure prototype. Varying length values may be passed as parameters on a procedure call where the corresponding parameter is defined with OPTIONS(*RIGHTADJ).
When OPTIONS(*TRIM) is specified for a CONST or VALUE parameter of type character, UCS-2 or graphic, the passed parameter is copied without leading and trailing blanks to a temporary. If the parameter is not a varying length parameter, the trimmed value is padded with blanks (on the left if OPTIONS(*RIGHTADJ) is specified, otherwise on the right). Then the temporary is passed instead of the original parameter. Specifying OPTIONS(*TRIM) causes the parameter to be passed exactly as though %TRIM were coded on every call to the procedure.
When OPTIONS(*STRING : *TRIM) is specified for a CONST or VALUE parameter of type pointer, the character parameter or %STR of the pointer parameter is copied without leading or trailing blanks to a temporary, a null-terminator is added to the temporary and the address of the temporary is passed.
- ALWNULL(*USRCTL) must be in effect.
- OPTIONS(*NULLIND) is not valid for parameters passed by value.
- The only other options that can be specified with OPTIONS(*NULLIND) are *NOPASS and *OMIT.
- Only variables may be passed as the parameter when OPTIONS(*NULLIND) is specified, and the variable must be an exact match even when CONST is specified.
- If the parameter is a data structure, the passed parameter must be defined with the same parent LIKEDS or LIKEREC as the prototyped parameter. Furthermore, the null-capability of the prototyped parameter and passed parameter must match exactly.
- A prototyped data structure parameter can have OPTIONS(*NULLIND) specified whether or not there are any null-capable subfields.
- If a non-data-structure prototyped parameter is defined with OPTIONS(*NULLIND), the parameter in the procedure interface is defined as null-capable.
- See Rational Development Studio for i: ILE RPG Programmer's Guide for information about using OPTIONS(*NULLIND) when the calling procedure or called procedure is not written using ILE RPG.
You can specify more than one option. For example, to specify that an optional parameter can be shorter than the prototype indicates, you would code OPTIONS(*VARSIZE : *NOPASS).
The following example shows how to code a prototype and procedure that use OPTIONS(*NOPASS) to indicate that a parameter is optional.
The following example shows how to code a prototype and procedure using OPTIONS(*OMIT) to indicate that the special value *OMIT may be passed as a parameter.
The following example shows how to code a prototype and procedure allowing variable-length parameters, using OPTIONS(*VARSIZE).
*------------------------------------------------------------
* Search:
* Searches for SearchFor in the array SearchIn. Returns
* the element where the value is found, or 0 if not found.
* The character parameters can be of any length or
* dimension since OPTIONS(*VARSIZE) is specified for both.
*------------------------------------------------------------
P Search B
D Search PI 5U 0
D SearchIn 50A OPTIONS(*VARSIZE)
D DIM(100) CONST
D ArrayLen 5U 0 VALUE
D ArrayDim 5U 0 VALUE
D SearchFor 50A OPTIONS(*VARSIZE) CONST
D FieldLen 5U 0 VALUE
D I S 5U 0
* Check each element of the array to see if it the same
* as the SearchFor. Use the dimension that was passed as
* a parameter rather than the declared dimension. Use
* %SUBST with the length parameter since the parameters may
* not have the declared length.
C 1 DO ArrayDim I 5 0
* If this element matches SearchFor, return the index.
C IF %SUBST(SearchIn(I) : 1 : ArrayLen)
C = %SUBST(SearchFor : 1 : FieldLen)
C RETURN I
C ENDIF
C ENDDO
* No matching element was found.
C RETURN 0
P Search E
Compile-time data section:
**CTDATA ARR1
A2$@*jM
**CTDATA ARR2
Red
Blue
Yellow
The following example shows how to use OPTIONS(*STRING) to code a prototype and procedure that use a null-terminated string parameter.
D trimStringProc PR
D trimString * value options(*string : *trim)
D string * value options(*string)
D ptr s *
/free
// trimProc is called with the same value passed
// for every parameter
//
// The called procedure receives the following parameters
// trimLeftAdj 'abc '
// leftAdj ' abc '
// trimRightAdj ' abc'
// rightAdj ' abc '
// trimVar 'abc'
// var ' abc '
callp trimProc (' abc ' : ' abc ' : ' abc ' :
' abc ' : ' abc ' : ' abc ' );
// trimStringProc is called with the same value passed
// for both parameters
//
// The called procedure receives the following parameters,
// where ¬ represents x'00'
// trimstring pointer to 'abc¬'
// string pointer to ' abc ¬'
callp trimStringProc (' abc ' : ' abc ');
// trimStringProc is called with the same pointer passed
// to both parameters
//
// The called procedure receives the following parameters,
// where ¬ represents x'00'
// trimstring pointer to 'xyz¬'
// string
pointer to ' xyz ¬'
ptr = %alloc (6);
%str(ptr : 6) = ' xyz ';
callp trimStringProc (ptr : ptr);
*-----------------------------------
* Called procedure PROC
*-----------------------------------
P B
D proc PI
D parm LIKEDS(ds)
D OPTIONS(*NULLIND)
D parm2 10A OPTIONS(*NULLIND)
D parm3 10A OPTIONS(*NULLIND) CONST
/free
if %NULLIND(parm.null1);
// This code will be executed because the
// caller set on the null indicator for
// subfield NULL1 of the parameter DS
endif;
if %NULLIND(parm3);
// PARM3 is defined as null-capable since it was
// defined with OPTIONS(*NULLIND).
// This code will not be executed, because the
// caller set off the null-indicator for the parameter
endif;
// Change some data values and null-indicator values
// The calling procedure will see the updated values.
parm2 = 'newvalue';
%NULLIND(parm2) = *OFF;
%NULLIND(parm.null1) = *OFF;
parm.null1 = 'newval';
return;
/end-free
P E