How can we help you?

We have hundreds of highly-qualified, experienced experts working in 70+ technologies.

IBM i e-Book

A Developer’s Guide to Mastering IBM i Concepts

Report Program Generator (RPG)

Built-in Functions

%ABS:

The absolute value of the numeric expression specified as the parameter is returned by %ABS. The value is returned unchanged if the numeric expression’s value is non-negative.

To find the Absolute value (Positive value) of a numerical expression, use the %ABS function. When we want the expression results to be positive, we can use the %ABS () function.

Syntax: %ABS (numeric expression)

Example:

Result

%DIFF:

To find the difference between two date, time, or timestamp values, use the %DIFF function. The difference (duration) between two date or time data is generated by %DIFF.
The types of the first and second parameters must be the same or compatible.

The combinations mentioned below can be used to obtain the difference:

  • Differences between the two dates
  • Difference between the two times
  • Difference between two timestamps
  • Difference between Date and timestamp (only the time portion of the timestamp)
  • Difference between Time and timestamp (only the time portion of the timestamp)

The unit of evaluating for the difference is indicated by the third parameter. The units mentioned below are Valid:

  • Difference between two dates or between a timestamp and a date: *DAYS, *MONTHS, *YEARS.
  • *SECONDS, *MINUTES, *HOURS, for two times, or a time and a timestamp.
  • The *MSECONDS, *SECONDS, *MINUTES, *HOURS, *DAYS, *MONTHS, and *YEARS timestamps differ from each other.

Syntax:%DIFF(op1 : op2 : unit {: frac })

Example:

Result

%DIV:

The integer part of the quotient obtained by dividing operands n by m is returned by the function %DIV.

It is required that the two operands have decimal values with zero decimal places.

The result is packed numeric if the operand is either a zoned, packed, or binary numeric value. The result is an integer if either operand has an integer numeric value. If not, the outcome is an unsigned number.

Numerical operands that float are prohibited.
If the operands are constants that can fit in 8-byte integers or unsigned fields, constant folding is applied to the built-in function.

In this scenario, the definition specifications can be used to code the built-in %DIV function.

Syntax:%DIV(n:m)

Example:

Result

%EDITC:

Numerical values can be formatted with special characters such as asterisk (*), period (. ), comma (, ), cent sign (¢), pound sign (£), dollar sign ($), minus sign (-), credit sign (CR), etc.

using the %EDITC function. To produce a date format, it can also be used to suppress zeros or format numbers with a slash (/).

Real-world scenarios frequently need us to provide reports with amount fields that look like $12,345.67-, $12,345.67CR, or ‘***12345.67-‘ rather than showing the amount as -12,345.67.

We can use the %EDITC Function in such report production programs to generate the results we desire.

Syntax:%EDITC(numeric : editcode {: *ASTFILL | *CURSYM | currency-symbol})

Here, the input numeric value that we wish to change is the first parameter.
2nd parameter is the edit code option used to generate the required edited string.

Another format choice, the third parameter, is used to create the necessary manipulated string.

3rd parameter is an optional parameter.

Example:

Result

%EDITFLT:

The numeric expression’s value is converted to the float’s character external display representation by using %EDITFLT. Either 14 or 23 characters are the result.
The final result is 14 characters if the parameter is a 4-byte float field. If not, there are 23 characters.

When a definition specification keyword takes in a parameter, it must be either a built-in function or a numeric literal, float literal, or name of a numeric valued constant.

Constant folding is applied when stated in an expression, provided that the numeric expression has a constant value.

Syntax:%EDITFLT(numeric expression)

Example:

Result

%EDITW:

Numerical values with special characters such as asterisk(*), period(. ),comma(. ), cent sign(«), dollar sign($), minus sign(-), credit sign(CR), percentage(%), etc. can be formatted using the %EDITW function.

Additionally, it can be used to format a number in date format by using a slash(/).

Real-world scenarios frequently need us to provide reports with amount fields that look like $12,345.67-, $12,345.67CR, or ‘***12345.67-‘ rather than showing the amount as -12,345.67.

We can use the %EDITW Function in such report production programs to generate the output we desire.

Syntax:%EDITW(numeric : editword)

The input numeric value that we wish to modify is the first argument.
2nd parameter is the edit word option used to generate the required edited string.

Example:

Result

%ELEM:

The %ELEM function can be used to get the total number of elements present in a table, array, or multiple-occurrence data structure.

Stated alternatively, this function allows us to get the dimension.

Syntax: %ELEM(table_name)
%ELEM(array_name)
%ELEM(multiple_occurrence_data_structure_name)

Example:

Result

%EOF (Return End or Beginning of File Condition)

When carrying out a file action equal to the resultant indicator, this built-in function is utilized to identify end-of-file, beginning-of-file, or subfile full situations.

Therefore, we only use %EOF to determine whether the file’s end has been reached rather than looking for any resulting indications.

%EOF returns ‘1’ if the whole condition of the end-of-file, beginning-of-file, or subfile is detected; if not, it returns ‘0’.

If the file ends, READ, READC, and READE return %EOF=*ON.

If the beginning of the file is reached, READP and READPE return %EOF=*ON.

If a subfile detail record is provided with a subfile-full condition, the WRITE operation returns %EOF=*ON.

CHAIN operation on successful search sets %EOF=*OFF if %EOF=*ON and we execute the CHAIN operation.

In the event where %EOF=*ON occurs and a CHAIN operation is carried out, the successful search sets %EOF=*OFF.

On successful operations, SETGT, SETLL, OPEN, and %EOF=*OFF are set.

Syntax: %EOF(file_name)

Example:

%EQUAL:

In addition to the two operation codes SETLL and LOOKUP, %EQUAL is used.

It is used by the SETLL operation to indicate that it detected a record in the file with a key equal to that of the value specified in Factor 1.

Therefore, to verify that the record is present, we can use SETLL along with %EQUAL.

For the SETLL operation, this function returns ‘1’ if a record is present whose key or relative record number is mentioned in factor-1.

If an element is found that exactly matches the element in factor-1, this method returns ‘1’ for the LOOKUP operation.

Syntax: %EQUAL(file_name);

Example:

%LOWER :

Yields the string operand after it has been partially or fully converted to lowercase.

The string that needs to be changed from uppercase to lowercase is the first operand.

It may be UCS-2 or alphanumeric in type.

The conversion’s starting point is represented by the second operand.

Its value must be between one and the string’s length, and it must be a numeric expression with zero decimal places. It’s Optional.

The conversion begins at the first position in the string if it is not specified.

The length to be converted is the third operand. It must be less than or equal to the length of the string beginning at the start point, and it must be a numeric expression with zero decimal places. It might be zero. It’s not required.

Syntax: %LOWER(string {: start { : length } })

Example:

Result

%UPPER:

%UPPER returns the string operand, with all or part of the operand converted to upper case.
The conversion’s starting point is represented by the second operand.

Its value must be between one and the string’s length, and it must be a numeric expression with zero decimal places. It’s Optional. The conversion begins at the first position in the string if it is not specified.

The length to be converted is the third operand.

It must be less than or equal to the length of the string beginning at the start point, and it must be a numeric expression with zero decimal places. It might be zero. It’s not required.

Syntax: %UPPER(string {: start { : length } })

Example:

Result

%MAX:

The maximum value of its operands is returned by %MAX.

The operands must all have data types that are compatible for comparison with each other.

In the case that one item in the list is alphanumeric, the others in the list may be graphic, UCS-2, or alphanumeric. The others can be packed as integers, unsigned integers, binary decimal, float, zoned numeric, or packed numeric if one is packed numeric.

Operands cannot include items of type object or procedure-pointer.

There must be at least two operands. There is no practical upper limit for the number of operands.

Syntax: %MAX(item1 : item2 {: item3 { item4 … } })

Example:

Result

%MIN:

The minimum value of its operands is returned by %MIN.

The operands must all have data types that are compatible for comparison with each other

In the case that one item in the list is alphanumeric, the others in the list may be graphic, UCS-2, or alphanumeric.

The others can be packed as integers, unsigned integers, binary decimal, float, zoned numeric, or packed numeric if one is packed numeric.

Operands cannot include items of type object or procedure-pointer.

There must be at least two operands. There is no practical upper limit for the number of operands.

Syntax: %MIN(item1 : item2 {: item3 { item4 … } })

Example:

Result

%SCAN:

To determine the search argument’s first position in the source string, use the %SCAN function.

Position of the matching position is returned if a match is found; else, 0 is returned.
The search element that is being looked up in the source string is the function’s first parameter.

The source string that we are searching in is the second parameter.

The third parameter indicates the starting point for the search within the given string.

The type of the second argument should to match with the first. These parameters may be UCS-2, graphic, or character-based.

Seek arguments or source String can contain blanks in form of string or string padded with blank. Those blanks are also taken into consideration when performing the search.

Syntax: %SCAN(search argument : source string {: start position {: length}})

Example:

Result

%SCANR :

%SCANR returns the last position of the search argument in the source string, or 0 if it was not found.

The start position and length specify the substring of the source string to be searched.

The length and start positions are set to the default values of 1 and the remainder of the source string, respectively. The result is always the position in the source string even if the starting position is specified.

The search element that is being looked up in the source string is the function’s first parameter.

The source string that we are searching in is the second parameter.

The third parameter indicates the starting point for the search within the given string.

The type of the second argument should to match with the first. These parameters may be UCS-2, graphic, or character-based.
Seek arguments or source String can contain blanks in form of string or string padded with blank. Those blanks are also taken into consideration when performing the search.

Syntax: %SCANR(search argument : source string {: start position {: length}})

Example:

Result

%SCANRPL:

All instances of the scan string in the source string are replaced with the replacement string, and the resultant string is returned by the %SCANRPL function

Starting at the scan start position and continuing for the scan length is the search for the scan string.

The parts of the source string that are outside the range specified by the scan start position and the scan length are included in the result.

The first, second and third parameters must be of type character, graphic, or UCS-2. They may come in formats with variable lengths or set lengths.

Each of these factors needs to be CCSID and of the same type.

The starting position, expressed in characters, where the search for the scan string must begin is represented by the fourth argument. The start position is set to one by default if it is not given. The value could be anything from one to the source string’s current length.

The fifth parameter represents the number of characters in the source string to be scanned. If the parameter is not specified, the length defaults to remainder of the source string starting from the start position.

Syntax: %SCANRPL(scan string : replacement : source { : scan start { : scan length } } )

Example:

Result

%TRIM:

To remove blank space from a string on both sides, use the %TRIM function.

Other than blanks, it can also be used to trim characters. In argument 2, we can specify which characters should be removed.

Syntax: %TRIM(string {: characters to trim})

Example:

Result

%TRIML:

The %TRIML method is used to remove a string’s leading blank spaces.

Other than blanks, it can also be used to trim characters. In argument 2, we can specify which characters should be cut.

Syntax: %TRIML(string {: characters to trim})

Example:

Result

%TRIMR:

The %TRIMR function is used to remove a string’s trailing blank spaces.

Other than blanks, it can also be used to trim characters. In argument 2, we can specify which characters should be cut.

Syntax: %TRIMR(string {: characters to trim})

Example:

Result

%XLATE:

The string is translated by %XLATE based on the values of startpos, from, and to.

A list of characters that need to be replaced is contained in the first parameter, and the replacements are given in the second. The third character in to is replaced for every occurrence of the character in from, for instance, if the string contains the third character in from.

The string that needs to be translated is the third parameter. The translation’s starting point is the fourth parameter. Translation starts at position 1 by default.

The additional characters in the first parameter are ignored if it is longer than the second parameter.

The first three of parameters can belong to either character, graphic, or UCS-2 types. All three must have the same type.

Syntax: %XLATE(from:to:string{:startpos})

Example:

Result

%SUBST:

The string is partially extracted from any point using the %SUBST method.
The source string, from which we wish to extract a portion of the string, is the first parameter in this case.

The beginning point from which we will begin the string extraction process is the second argument.
The length to extract is the third argument.

Syntax: %SUBST(string:start{:length})

Example:

Result

%HOURS:

A number is converted to a duration (number of hours) using %HOURS.

This duration can be used to increase or decrease the value of a time or timestamp.

Therefore, we may obtain any past or future time by using %HOURS.

Syntax: %HOURS(number)

Example:

Result

%MINUTES:

A number is converted to a duration (number of minutes) using %MINUTES. This duration can be used to increase or decrease the value of a time or timestamp. Thus, we may obtain any past or future time by using %MINUTES.

Syntax: %MINUTES(number)

Example:

Result

%SECONDS:

To modify the duration of seconds in a time or timestamp, add a duration to the number using %SECONDS.

Syntax: %SECONDS(number)

Example:

Result

%SUBDT:

A subset of the data in a date, time, or timestamp value is extracted using %SUBDT.

It returns an unsigned numeric value.

The date, time, or timestamp value is the first parameter.

The part you wish to extract is the second parameter.

Syntax: %SUBDT(value : unit { : digits { : decpos } })

Example:

Result

%RANGE:

The IN operator is used with %RANGE. %RANGE can only be specified by following the IN operator; it does not return a value.

The IN operator determines to see if the first operand is within the range given by %RANGE when it is used with %RANGE.

The expression using the IN operator with %RANGE is true if the first operand of the IN operator is greater than or equal to the first operand of %RANGE and less than or equal to the second operand of %RANGE.

An array cannot be the IN operator’s initial operand.

The operands of %RANGE must be able to be compared to each other and to the first operand of the IN operator.

Syntax:

Example:

Result

%SQRT:

The square root of the given numeric expression is returned by the %SQRT function. If the operand is of type float, the result is of type float; otherwise, the result is packed decimal numeric. The parameter raises exception 00101 if its value is less than zero.

Syntax: %SQRT (numeric expression)

Example:

Result

%REPLACE

The segment of a string with the replacement string is used with the %REPLACE function.

Syntax: %REPLACE(replacement string: source string{:start position {:source length to replace}})

Example:

Result

%XFOOT:

The total of each element in the given numeric array expression is produced by using %XFOOT.

The precision of the result is the minimum that can hold the result of adding together all array elements, up to a maximum of 63 digits. The result’s decimal places are always the same as the array expression’s decimal places.

Syntax: %XFOOT (array-expression)

Example:

Result

%MSECONDS :

A number can be converted into a duration using %MSECONDS, which is able to be added to a time or timestamp value.

Only the plus or minus sign in an addition or subtraction expression can be followed by %MSECONDS. A time or timestamp must be the value that comes before the plus or minus sign. The result is a time or timestamp value with the appropriate number of microseconds added or subtracted. The resultant value is initially displayed in *ISO format.

Syntax: %MSECONDS(number)

Example:

Result

%ADDR :

A value of type basing pointer is returned by %ADDR. The address of the specified variable is the value. It may only be compared with and assigned to items of type basing pointer.

When *DATA is given as the second argument of %ADDR, the address of the data component of a variable-length field is returned by %ADDR.

The array index needs to be known at compile time if %ADDR with an array index parameter is used as a parameter for defining specification keywords INZ or CONST. Either a numerical literal or a numerical constant must be used as the index.

Syntax: %ADDR(variable)
%ADDR(varying-length variable : *DATA)

Example:

Result

%ALLOC:

A pointer to freshly allocated heap storage of the given length is returned by %ALLOC. The newly allocated storage is uninitialized.

The parameter must be a non-float numeric value with zero decimal places. The length must fall between 1 and the maximum dimension that is allowed.

The maximum size allowed depends on the type of heap storage used for RPG memory management operations due to the ALLOC keyword on the Control specification.

Syntax: %ALLOC(num)

Example:

Result

%BITAND :

The bit-wise ANDing of each argument’s bits is returned by %BITAND. That is, the result bit is ON when all of the corresponding bits in the arguments are ON, and OFF otherwise.

This built-in function accepts either character or numeric parameters. Numerical arguments are first converted to integer if they are not integer or unsigned. If the value does not fit in an 8-byte integer, a numeric overflow exception is issued.

There can be two or more arguments for %BITAND. Each parameter must be of the same type—a number or character. The types of the arguments and the result are the same.

Syntax: %BITAND(expr:expr{:expr…})

Example:


Result

%BITNOT:

%BITNOT returns the bit-wise inverse of the bits of the argument. In other words, the result bit is ON when the argument’s corresponding bit is OFF and OFF otherwise.

This built-in function accepts either a character or a number argument. Numerical arguments are first converted to integer if they are not integer or unsigned. If the value does not fit in an 8-byte integer, a numeric overflow exception is issued.

%BITNOT only accepts a single parameter. The types of the arguments and the result are the same. If all of the parameters are unsigned, the result for numerical arguments is unsigned; if not, it is an integer.

Syntax: %BITNOT(expr)

Example:


Result

%BITOR:

%BITOR returns the bit-wise ORing of the bits of all the arguments. In other words, the result bit is OFF otherwise and ON when any corresponding bit in the arguments is ON

This built-in function accepts either character or numeric parameters. Numerical arguments are first converted to integer if they are not integer or unsigned. If the value does not fit in an 8-byte integer, a numeric overflow exception is issued.

There may be two or more arguments for %BITOR. Each parameter must be of the same type—a number or character.

Syntax: %BITOR(expr:expr{:expr…})

Example:


Result

%SPLIT :

%SPLIT splits a string into an array of substrings. It returns a temporary array of the substrings.

%SPLIT can be used in calculation statements wherever an array can be used except:

  • SORTA
  • %ELEM
  • %LOOKUP
  • %SUBARR

The first operand is the string to be split. It can be alphanumeric, graphic, or UCS-2.

The second operand is the list of characters that indicate the end of each substring. It is optional. It must have the same type and CCSID as the first operand. If it is not specified, %SPLIT defaults to splitting at blanks.

If the length of the second operand is greater than 1, any of the characters in the second operand indicate the end of each substring.
For example, %SPLIT(‘abc.def-ghi’ : ‘.-‘) has two separator characters, ‘.’, and ‘-‘, so it returns an array with three elements: (‘abc’,’def’,’ghi’).

Syntax: %SPLIT(string {: separators })

Example:

Result

%BITXOR :

The bit-wise exclusive ORing of the two parameters’ bits is returned by %BITXOR. That is, the result bit is ON when just one of the corresponding bits in the arguments are ON, and OFF otherwise.

This built-in function accepts either a character or a number argument. Numerical arguments are first converted to integer if they are not integer or unsigned. If the value does not fit in an 8-byte integer, a numeric overflow exception is issued.

%BITXOR requires a pair of arguments. The types of the arguments and the result are the same. If all of the parameters are unsigned, the result for numerical arguments is unsigned; if not, it is an integer.

Syntax: %BITXOR(expr:expr)

Example:


Result

%Error :

If an error condition was encountered during the most recent operation using the requested extender ‘E,’ then %ERROR returns ‘1.

This is equivalent to having the operation’s error indicator turned on. Before an operation with extender ‘E’ specified begins, %ERROR is set to return ‘0’ and remains unchanged following the operation if no error occurs.

The built-in function %ERROR can be set by any action that allows the use of an error indicator. The CALLP operation can also set %ERROR.

Example:


Result

%SIZE :

The number of bytes that the element occupies is returned by the %SIZE function.

A named constant, data structure, array, field, literal, etc. can all be used as arguments.

%SIZE returns full length for a field with a null value.

For an array or multiple occurrence data structure, the elements or occurrences size is additionally considered if *ALL is given as the second option for %SIZE.

Syntax: %SIZE(variable)
%SIZE(array{:*ALL})
%SIZE(table{:*ALL})
%SIZE(multiple occurrence data structure{:*ALL})

Example:


Result

%TIMESTAMP :

To convert a string into a timestamp data type, use the %TIMESTAMP method.

Syntax: %TIMESTAMP (value : *ISO | *ISO0 )

The input value that we wish to convert to a timestamp is the first parameter in this case.

The second option, which informs us of the input string’s timestamp format, can also be mentioned.

Example:

Result

%FOUND:

If the most recent operation finds out a relevant or matching record, %FOUND returns ‘1’; however, an exact match is not assured.

In the event that no match is found, ‘0’ is returned.

Syntax: %FOUND{(file_name)}

Example:

%MAXARR:

%MAXARR returns the index of the maximum value in the array, or the subsection of the array identified by the start-element operand and the number-of-elements operand.

Syntax: %MAXARR(array {: start-index {:number-of-elements}})

Example:

Result

%MINARR:

%MINARR returns the index of the minimum value in the array, or the subsection of the array identified by the start-element operand and the number-of-elements operand.

Syntax: %MINARR(array {: start-index {:number-of-elements}})

Example:

Result

%STATUS:

The program or file status’s most recent value is returned by the %STATUS function. %)STATUS is set anytime there is a change in the status of any file or program, usually as a result of an error.

The most recent program or file status update is returned if %STATUS is used without the optional file_name parameter. If a file is specified, the value contained in the INFDS *STATUS field for the specified file is returned. It is not necessary to specify the INFDS for the file.

%STATUS starts with a return value of 00000 and is reset to 00000 before any operation with a ‘E’ extender specified begins.

Syntax: %STATUS{(file_name)}

Example:


%LEN:

You can set the current length of a variable-length field, find the maximum length of a varying-length expression, or retrieve the length of a variable expression using %LEN

A figurative constant cannot be the parameter.

Syntax: %LEN(expression) or %LEN(varying-length expression : *MAX)

Example:


Result

%REM :

When operands n and m are divided, the remainder is returned by %REM. Numerical values with zero places in decimals must be the two operands. If either operand is a packed, zoned, or binary numeric value, the result is packed numeric. An integer is the result if either operand has an integer numeric value.
If not, unsigned numeric is the outcome. Numerical operands that float are not permitted. The sign of the outcome and the dividend are the same.

Syntax: %REM(n:m)

Example:

Result

%INT:

The built-in %INT function converts the numeric expression’s value to an integer.

Syntax: %INT(NumericExpression)

Example:

Result

%MSG:

The second operand in the SND-MSG operation is %MSG. Other than for the SND-MSG operation, %MSG cannot be provided and does not return a value.

Sending the message is specified by %MSG.

The message ID is the first operand. It must be a character expression in the job CCSID. The message ID consists of seven characters. The operand’s remaining characters must be blank if its length exceeds 7. The message ID needs to be present in the message file at run-time.

The message file is the second operand. In the CCSID task, it needs to be a character expression. One of the following formats is possible for it:

  • MYMSGF
  • MYLIB/MYMSGF
  • *LIBL/MYMSGF

There is an optional third operand. It specifies the replacement text for the message. It could be a data structure or a character value in the job CCSID

Syntax:

Example:

I can use the %MSG BiF to send that message to the job log. Before I can show that I am going to need to have a message file, and a message within it I can use.



%STR:

Null-terminated character strings, which are frequently used in C and C++ applications, can be created or utilized with the %STR symbol.

A value for a starting point must be the first parameter. (Any expression that starts with “%ADDR(DATA)” or “P+1” is acceptable as a basing pointer.) The second parameter, if specified, must be a numeric value with zero decimal positions.
If not specified, it takes the longest character variable definition provided by default.

The first parameter must point to storage that is at least as long as the length given by the second parameter.

Syntax: %STR(basing pointer{: max-length})(right-hand-side)
%STR(basing pointer : max-length)(left-hand-side)

Example:

I can use the %MSG BiF to send that message to the job log. Before I can show that I am going to need to have a message file, and a message within it I can use.

%OPEN:

When a file is given and opened, %OPEN returns ‘1’. When a file is opened by the RPG module at initialization or through an OPEN operation and hasn’t been closed since, it’s referred to be “open”.

The file is considered to be closed and %OPEN returns ‘0’ if it is dependent on an external indicator and that indicator was turned off during module initialization.

Syntax: %OPEN(file_name)

Example:

%UNS :

The expression’s value is converted to unsigned format using %UNS. Any decimal digits are truncated. An array index can be created by truncating the decimal places of a float or decimal value using %UNS.

If a character expression is used as the parameter

See Rules for converting character values to numeric values using built-in functions for the rules for character expressions for %DEC.

Floating point data cannot be used, such as ‘1.2E6’.

Floating point data is not allowed. In other words, when the numerical value is followed by an exponent (as in ‘1.2E6’) and E.

If invalid numeric data is found, an exception occurs with status code 105

Syntax: %UNS(numeric or character expression)

Example:

Result

%UNSH:

%UNSH and %UNS are equivalent, with the exception that when converting an expression to an integer type, half an adjustment is applied to the expression’s value if it is a decimal, float, or character value. No message is issued if half adjust cannot be performed.

Syntax: %UNS(numeric or character expression)

Example:

Result

%TLOOKUPxx

The current table element for the search table is set to the element that satisfies the condition if a value meets the specified condition; if not, the function returns the value *ON and sets the current table element for the alternate table to the same element.

*OFF is returned if no value fulfills the required criteria.

Any type is acceptable for the first two arguments, but they must be of the same type. They do not need to have the same length or number of decimal positions.

Unless arg or search-table is defined with ALTSEQ(*NONE), the ALTSEQ table is used.

Built-in functions %FOUND and %EQUAL are not set following a %LOOKUP operation.

%TLOOKUP

An exact match.

%TLOOKUPLT
The value that is closest to arg but less than arg.

%TLOOKUPLE

An exact match, or the value that is closest to arg but less than arg.

%TLOOKUPGT

The value that is closest to arg but greater than arg.

%TLOOKUPGE

An exact match, or the value that is closest to arg but greater than arg.

Syntax:

%TLOOKUP(arg : search-table {: alt-table})

%TLOOKUPLT(arg : search-table {: alt-table})

%TLOOKUPGE(arg : search-table {: alt-table})

%TLOOKUPGT(arg : search-table {: alt-table})

%TLOOKUPLE(arg : search-table {: alt-table})

Example:


Result

%TARGET:

The third operand in the SND-MSG operation is %TARGET. Other than for the SND-MSG operation, %TARGET cannot be provided and does not return a value.

%TARGET specifies the target program or procedure for the message.

*SELF may be used as the first operand. This is the default for an informational message. The current procedure receives the message.
*CALLER. This is the default for an escape message. The message is sent to the caller of the current procedure.
The name of a program or procedure on the program stack. It has to be a CCSID character value.
The second operand is the offset on the program stack. It is optional. If it is not specified, it defaults to zero. It must be a numeric value with zero decimal positions.
The value cannot be negative.

Example:

%SUBARR:

Built-in function %SUBARR returns a section of the specified array starting at start-index. The optional number-of-elements parameter specifies how many elements will be returned. The number-of-elements defaults to the remaining value in the array if it is not supplied.

%SUBARR requires an array as its first parameter. That is, an array-defined standalone field, data structure, or subfield. The first parameter must not be a table name or procedure call.

There must be a numeric value with zero decimal places for the start-index argument. A float numeric value is not allowed. The value must be less than or equal to the array’s element count and higher than or equal to 1.

A integer value with zero decimal places must be entered for the optional number-of-elements argument.

Syntax: %SUBARR(array:start-index{:number-of-elements})

Example:

Result

%SHTDN :

%SHTDN returns ‘1’ if the system operator has requested shutdown; otherwise, it returns ‘0’.

Syntax: %SHTDN

Example:

Result

%FIELDS:

A file can be partially updated by using the %FIELDS function. To put it another way, we might just need to edit one or two fields in a file. For that we use this funtion.

We specify the name of the field we want to edit in the file in the %FIELDS argument. Only the mentioned fields are updated.

Syntax: %FIELDS(name{:name…})

Example:

Result

Before:

After:

%PARMS:

The number of parameters given to the procedure where %PARMS is used is returned by %PARMS. *PARMS and %PARMS are the same for the main procedure.

Example:

Result

%GRAPH:

%GRAPH returns a graphic value after converting the expression’s value from character, graphic, or UCS-2. If the parameter varies in length, the outcome will also vary in length.

The CCSID of the resulting expression is indicated by the second parameter, ccsid, which is optional. Control keyword CCSID(*GRAPH) specifies the default graphic CCSID of the module, which is the default CCSID by default.
The built-in %GRAPH is prohibited if CCSID(*GRAPH: *IGNORE) is mentioned in the control specification or presumed for the module.

Syntax: %GRAPH(char-expr | graph-expr | UCS-2-expr { : ccsid })

Example:

%INTH:

%INTH and %INT are equivalent, with except that when converting an expression to an integer type, half of the expression’s value is adjusted if it is a decimal, float, or character value. No message is issued if half adjust cannot be performed.

Syntax: %INTH(numeric or character expression)

Example:

Result

How can we help you?

We have hundreds of highly-qualified, experienced experts working in 70+ technologies.

X

Awards and Certifications

company-logo
company-logo
company-logo
company-logo
company-logo
company-logo
company-logo
company-logo
company-logo
company-logo