Visual RPG built-in functions are similar to RPG operation codes in that they provide an action that returns a result. However, built-in functions can be used in expressions). (eg, x = %XFOOT( MyArray )). Built-in functions always start with a percent sign (%).
function-name{(argument{:argument...})}
- or -
function-name{(argument{,argument...})}
As defined by IBM, built-in functions use a colon (:) to delimit arguments being passed to a function. For example, the formal IBM syntax for using the %EDITC function is:
x = %EDITC( NumVal : '3' )
where the colon delimits the functions arguments.
Visual RPG offers an optional, more intuitive syntax, that uses the comma (,) to separate function arguments. For example,
x = %EDITC( NumVal, '3' )
is also valid with Visual RPG code.
You can use whichever syntax you prefer.
Arguments for the function may be variables, constants, expressions, a prototyped procedure, or other built-in functions. An expression argument can include a built-in function.
See the individual built-in function descriptions for details on what arguments are allowed.
Note – In syntax samples and elsewhere, optional arguments are surrounded by curly braces ({}). These braces are not used in actual code, they only serve as a visual indicator that an argument is optional.
| Built-In Function | Argument(s) | Value Returned |
|---|---|---|
|
numeric expression |
Absolute value of the numeric expression. |
|
|
boolean expression |
True of False value. |
|
|
numeric, date, time or timestamp expression |
Value in character format. |
|
|
comparator, base {,start} |
The first position of base (start, then left to right) that contains a character that does NOT appear in comparator: otherwise 0. start default is 1. |
|
|
comparator, base {,start} |
The last position of base (start, then right to left) that contains a character that does NOT appear in comparator: otherwise 0. start default is the length of the string. |
|
|
(character, numeric, or timestamp expression {,*ISO *JUL | *USA | *EUR | *JIS | *MDY | *DMY | *YMD}) |
Value of expression converted to type date or the current system date in *ISO date format. |
|
|
number |
The result is a date or timestamp value with the appropriate number of days added or subtracted. |
|
|
numeric expression { ,digits ,decpos } |
Value in packed numeric format. |
|
|
numeric expression,digits, decpos |
Half-adjusted value in packed numeric format. |
|
|
numeric expression |
Number of decimal digits. |
|
|
op1, op2, {*MSECONDS | *SECONDS | *MINUTES | *HOURS | *DAYS | *MONTHS | *YEARS} |
The difference (duration) between two date, time, or timestamp values. |
|
|
Numeric,start{,length} |
Value in integer format. |
|
|
dividend , divisor |
The quotient from the division of two arguments; packed numeric if either operand is a packed, zoned, or binary numeric value, or integer if either operand is an integer numeric value. |
|
|
non-float numeric expression , edit code {, *ASTFill | *CURSYM | currency-symbol}) |
Value in string format representing the edited value. |
|
|
numeric expression |
Character external display representation of float. |
|
|
non-float numeric expression , edit word |
Value in string format representing the edited value. |
|
|
array, table, or multiple occurrence data structure name |
Number of elements or occurrences. |
|
|
{file name} |
'1' if the most recent read operation or write to a subfile ended in an end of file or beginning of file condition; otherwise, it returns '0'. |
|
|
{file name} |
'1' if the most recent relevant operation found an exact match; otherwise, it returns '0'. |
|
|
'1' if the most recent operation with extender 'E' specified resulted in an error condition. '0' and remains unchanged following the operation if no error occurs. |
||
|
numeric expression |
Value in float format. |
|
|
{file name} |
'1' if the most recent relevant file operation found a record (CHAIN, DELETE, SETGT, SETLL), an element (LOOKUP), or a match (CHECK, CHECKR, SCAN). Otherwise, this function returns '0'. |
|
|
number |
The result is a time or timestamp value with the appropriate number of hours added or subtracted. |
|
|
numeric expression |
Value in integer format. |
|
|
numeric expression |
Half-adjusted value in integer format. |
|
|
dsn name {,number-keys} |
The data structure reference as indicated by setting the Key parameter in the CHAIN, DELETE, READE, READPE, SETGT, or SETLL using this function. |
|
|
expression |
The length of a program defined variable or database variable defined as variable length, or also the current length of such fields. |
|
|
argument, array {,start-index {,num-elements}} |
Returns the array index of the item in array that matches the argument; otherwise, zero if no match is found. |
|
|
number |
The result is a time or timestamp value with the appropriate number of minutes added or subtracted. |
|
|
number |
The result is a date or timestamp value with the appropriate number of months added or subtracted. |
|
|
number |
The result is a time or timestamp value with the appropriate number of microseconds added or subtracted. |
|
|
fieldname |
The name of the field to query or set the null indicator for null-capable fields. |
|
|
dsn name |
Returns an unsigned numeric value of the current occurrence number of the dsn name (data structure). Also can be used to set the occurrence number. |
|
|
%OMITTED is only valid inside of BegProc routines for ILE procedures, and is only valid on Parameters that have the *OMIT option; i.e. DCLSRPARM CustName Options (*OMIT) if not %OMITTED(CustName) // we have a name EndIf |
||
|
file name |
'1' if the specified file is open. |
|
| number |
%Parms is only valid inside of BegProc routines for ILE procedures. DCLSRPARM CustName Options(*OMIT) If (%Parms = 3) // if we are here, it means that CustPone was passed, but it may be omitted If not %OMITTED(CustPhone) // we have a valid phone number EndIf EndIf |
|
|
, dividend, divisor |
The remainder from the division of the two arguments. |
|
|
Replacement string , source string {,start position{,source length to Replace}} |
String produced by inserting Replacement string into source string, starting at start position and replacing the specified number of characters. |
|
|
Search argument, string to be searched {,start position] |
First position of search argument in string, or zero if not found. |
|
|
number |
The result is a time or timestamp value with the appropriate number of seconds added or subtracted. |
|
|
numeric expression |
The square root of the numeric expression. |
|
|
array ,start-index {,num-elements} |
Returns a section of the specified Array starting at Start-index. The number of elements returned is specified by num-elements. or the remainder of the array if num-elements is not specified. |
|
|
date, time, or timestamp value, {*MSECONDS | *SECONDS | *MINUTES | *HOURS | *DAYS | *MONTHS | *YEARS} |
An unsigned numeric value with the extracted portion of a date, time, or timestamp value. |
|
|
String,start{,length} |
Substring. |
|
|
(character, numeric, or timestamp expression {, *ISO | *HMS | *USA | *EUR | *JIS}) |
Value of expression converted to type time or the current system time in *ISO format. |
|
|
(character, numeric, or timestamp expression {, *ISO | *ISO0}) |
Value of expression converted to type timestamp or the current system timestamp in *ISO format. |
|
|
argument, search-table {, alternate_table} |
Sets the current table element to the element that satisfies the condition and returns the value *ON, otherwise, *OFF if no match is found. |
|
|
string |
String with left and right blanks trimmed. |
|
|
string |
String with left blanks trimmed. |
|
|
string |
String with right blanks trimmed. |
|
|
array expression |
Sum of the elements. |
|
|
from, to, string {,start position} |
Value translated from String, with any From character values replaced with the corresponding To character values. |
|
|
number |
The result is a date or timestamp value with the appropriate number of years added or subtracted. |
Visual RPG Language Reference
Provides a reference of the Visual RPG language.