classAnova - Knowledge Shared


Posted by: Bob Cozzi
IT Researcher
Cozzi Productions, Inc.
North Aurora, IL
Bob Cozzi's RPG IV Cheat Sheets
has no ratings.
Published: 08 Feb 2011
Revised: 04 Aug 2011 - 1213 days ago
Last viewed on: 29 Nov 2014 (8157 views) 
RPG IV Built-In Function Summary Published by: Bob Cozzi on 08 Feb 2011 view comments

RPG IV - Built-in Functions through IBM i v6.11

The original release of RPG IV included a set of built-in functions. These built-in functions were:

%ADDR, %PADDR, %SIZE, %ELEM, %SUBST, %TRIM, %TRIML, %TRIMR

In addition, under OS/400 V3R2 and V3R7 the %PARMS built-in function was introduced. Since then, several built-in functions have been added to RPG IV. The following table provides the OS/400 Version and Release that the specific built-in functions were introduced and/or enhanced.

   
Version Release Built-in Function Parameters Return Value Description
V3R7 %ABS numeric expression Absolute value of expression
  %ADDR variable name { :  *DATA } Address of variable (for VARYING fields, *DATA may be used to get ptr to the data portion)
V5R1 %ALLOC memory size Pointer to the allocated storage.
  %BITAND value1 : value2 { : value 3 { : value-n... } } Performs bit-wise ANDing of the parameters and returns that result.
  %BITNOT value Performs a bit-wise NOT of the value and returns that result.
  %BITOR value1 : value2 { : value 3 { : value-n... } } Performs bit-wise ORing of the parameters and returns that result.
  %BITXOR value1 : value2 Performs bit-wise Exclusive ORing of the two parameters and returns that result.
V4R2 V4R4 %CHAR graphic, date, time, timestamp, or numeric expression { : date/time-format } Value in character format. For
V5R1 %CHECK compare-value : data-to-search { : start } First position in the searched-data that contains a character not in the list of the characters in the compare value.
V5R1 %CHECKR compare-value : data-to-search { : start } Last position in the searched-data that contains a character not in the list of the characters in the compare value. (Search begins with the right-most character and proceeds to the left.
V5R1 %DATE { value { : date-format-code }  A date data-type value after converting the "value" to the specified date format. If no value is specified, the current system date is returned.
V5R1 %DAYS days Converts the input value to a duration value that can be used in an expression to add or subtract a number of days to a date value.
V3R7 %DEC numeric expression {:digits : decpos} Value in packed numeric format. If digits and decpos are specified the result value is formatted to fit in a variable of the number of digits specified.
  %DEC date/time value { : format } Converts a date, time or timestamp value to numeric. The Format parameter indicates the resulting value's format regardless of the input date/time value's format.
V3R7 %DECH numeric expression : digits : decpos Half-adjusted value in packed numeric format. The length and decimal positions
V3R7 %DECPOS numeric expression Number of decimal digits.
V5R1 %DIFF start-date : end-date : duration-code Calculates the difference between two date fields. The type of difference returned is specified by the duration-code and may be *MSECONDS *SECONDS *MINUTES *HOURS *DAYS *MONTHS *YEARS.
V4R4 %DIV Numerator : Denominator Performs integer division and returns the quotient (result) of that division operation.
V3R7 %EDITC non-float numeric expression : edit code {:*CURSYM | *ASTFILL | currency symbol} String representing edited value.
V3R7 %EDITFLT numeric expression Character external display representation of float.
V3R7 %EDITW non-float numeric expression : edit word String representing edited value
  %ELEM array, table, or multiple occurrence data structure name Number of elements or occurrences. Note: Data Structure Arrays and Multiple Occurrence Data Structures are supported along with regular tables and arrays.
V4R2 %EOF {file name} '1' if the most recent file input operation or write to a subfile (for a particular file, if specified) | ended in an end-of-file or | beginning-of-file condition '0' otherwise.
V4R2 %EQUAL {file name} '1' if the most recent SETLL (for a particular file, if specified) or LOOKUP operation found an exact match '0' otherwise.
V4R2 %ERROR   '1' if the most recent operation code with extender 'E' specified resulted in an error '0' otherwise.
  %FIELDS update-field-list A list of fields to be updated by an RPG IV UPDATE operation code. Only the fields specified are updated by the UPDATE operation. If %FIELDS is not specified, the entire record is updated. This is not strictly a built-in function but rather an opcode parameter.
V3R7 %FLOAT numeric expression Value in float format.
V4R2 %FOUND {file name} '1' if the most recent relevant operation (for a particular file, if specified) found a record (CHAIN, DELETE, SETGT, SETLL), an element (LOOKUP), or a match (CHECK, CHECKR, SCAN) '0' otherwise.
V4R4 %GRAPHIC character value { : ccsid } Converts any character, graphic, or UCS-2 data to double-byte character set value to Graphic (double-byte) data.
  %HANDLER subprocedure : data-structure Used by the XML-INTO or XML-SAX operation codes to identify a callback subprocedure. This not strictly a built-in function but rather an opcode parameter.
V5R1 %HOURS hours A duration value that can be used in an expression to add or subtract a number of hours to a time value.
V3R7 %INT numeric or character expression Returns an integer (no decimal position) value.
V3R7 %INTH numeric or character expression Returns an integer (no decimal position) value that is rounded off.
  %KDS data-struct or field list { : field count } Used by any random access RPG database operation to identify the key list (list of key fields). If a data structure is specified, its subfields are used and the optional 2nd parameter indicates the number of those subfields to be used as  key list key fields. This is not strictly a built-in function but rather an opcode parameter.
V3R7 %LEN any expression
  1. Returns the length of a variable or literal value, or the current length of a varying length field.
  2. When used on the left side of the equal sign, sets the length of a varying length field.
V5R1 %LOOKUPxx search-data : array { : start-index { : elements to search }} An array index of the element in the array where the search-data is located.
V5R1 %TLOOKUPxx search-data : searched-table { : alternate-table } *ON if the search is successful, otherwise *OFF. (NOTE: The indexes of the searched-table and alternate-table are set to the index of the search-data if *ON is returned.)
V5R1 %MINUTES minutes A duration value that can be used in an expression to add or subtract a number of minutes to a time value.
V5R1 %MONTHS months A duration value that can be used in an expression to add or subtract a number of months to a date value.
V5R1 %MSECONDS milliseconds A duration value that can be used in an expression to add or subtract a number of milliseconds to a time value.
V3R7 %NULLIND null-capable field name Value in indicator format representing the null indicator setting for the null-capable field.
V5R1 %OCCUR data-structure The current occurrence of the data structure, or sets the current occurrence of the data structure
V4R2 %OPEN file name '1' if the specified file is open '0' if the specified file is closed. Consider this built-in to be an 'Is this file open?" operation.
  %PADDR procedure name Address of procedure
V3R2
V3R6
%PARMS   Number of parameters passed to procedure
V5R1 %REALLOC pointer : new-size Pointer to the allocated storage.
V4R4 %REM Numerator : Denominator Performs integer division and returns the remainder from the division operation.
V4R2 %REPLACE 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.
V3R7 %SCAN search argument : string to be searched {:start position} First position of search argument in string or zero, if not found.
V5R1 %SECONDS seconds A duration value that can be used in an expression to add or subtract a number of seconds to a time value.
V5R1 %SHTDN   *ON if the job is being shut down (e.g., when the PWRDWNSYS command is issued) otherwise *OFF is returned.
  %SIZE variable, data structure, array, or literal {: *ALL} Number of bytes used by variable or literal. *ALL returns the number of bytes used by all the elements of the array, or all the occurrences of the data structure.
V5R1 %SQRT expression or value The square root of the expression or value.
V4R2 %STATUS {file name} 0 if no program or file error occurred since the most recent operation code with extender 'E' specified most recent value set for any program or file status, if an error occurred if a file is specified, the value returned is the most recent status for that file.
V3R7 %STR pointer{:maximum length} Characters addressed by pointer argument up to but not including the first x'00'.
V5R4 %SUBARR array : first elem {: elem-count } Returns a subset of an array based on the parameters of this built-in function.
V5R1 %SUBDT date : duration-code The extracted component of the date value. (The functional equivalent of the EXTRCT operation code.)
V3R1 %SUBST string:start{:length} Substring value. If length is not specified, the substring begins with start and continues through the end of the string.
V5R1 %THIS   Used for Java integration. Returns an Object reference.
V5R1 %TIME { value { : time-format-code }  A time data-type value after converting the "value" to the specified time format. If no value is specified, the current system time is returned.
V5R1 %TIMESTAMP {value { : *ISO | *ISO0 }  A timestamp data-type value with or without separators.
  %TRIM string { : trim characters } String with left and right trim-characters trimmed (removed). If no trim-characters are specified, blanks are trimmed.
  %TRIML string { : trim characters } String with left trim-characters trimmed (removed). If no trim-characters are specified, blanks are trimmed.
  %TRIMR string { : trim characters } String with right trim-characters trimmed (removed). If no trim-characters are specified, blanks are trimmed.
V4R4 %UCS2 Any character value { : ccsid } Returns a UCS-2 value from the input string. The 2nd parameter is the resulting CCSID which defaults to 13488.
V4R2 %UNS numeric/character expression Value in unsigned integer format.
V4R2 %UNSH numeric/character expression Half-adjusted value in unsigned integer format.
V4R4 %XFOOT array Returns the total (cross-foot) of the elements in the numeric input array.
V5R1 %XLATE from-table : to-table : string-to-convert { : starting-position }  The converted string is returned.
  %XML xml data or document { : options } Used by the XML-INTO and XML-SAX operation codes to identify the XML being processed.
V5R1 %YEARS years A duration value that can be sued in an expression to add or subtract a number of years to a date value.

Return to classanova.com home page.
Sort Ascend | Descend

COMMENTS