List of Built-In Functions in rpgle


Function

Format

Function use

%ABS

%ABS (numeric expression)

%ABS returns Absolute value (Positive value) of a numeric expression

%CHAR

%CHAR(expression{:format})

%CHAR converts numeric, date, time, timestamp or graphic data type into character data type.

%CHECK

%CHECK(comparator : base string {: Start position})

%CHECK will return the first position of the base string that contains a character that is not available in the comparator.

%CHECKR

%CHECKR(comparator : base string {: Start position})

%CHECKR will return the first position of the base string that contains a character that is not available in the comparator.

%DATE

%DATE { Value { : date-format }

%DATE is used to convert a character, numeric, or timestamp data to Date type.

1st parameter is the Input value to be converted to date.

2nd parameter is the Input Date Format.

%DAYS

%Days(number of days)

%DAYS converts a number into a duration (No. of days). We can use this duration to add or subtract to a date or timestamp value.

%DEC

%DEC(date time or timestamp expression {:format}) 

%DEC function can be used to convert Date, Time OR Timestamp to Decimal.  

If the 1st parameter is a Date and 2nd parameter is *YMD, the converted decimal value will be YYMMDD. Similarly, for *MDY, the converted decimal will be MMDDYY.

%DECH

%DECH(Numeric or character expression:digits:decpos) 

%DECH is used to Round-off decimal places.

%DECH is the same as %DEC built-in function except that the half adjust is also performed if the expression is a decimal or float value. Half-adjust is a rounding process in which less significant digits are dropped off to get the rounded result.

%DIFF

%DIFF(date or time expression 1: date or time expression 2: unit)

Here unit will be MSECONDS|*SECONDS|*MINUTES|*HOURS|*DAYS|*MONTHS|*YEARS

%DIFF function is used to find difference between Two Date, Time, or Timestamp Values.

%DIFF produces the difference (duration) between two date or time values. The first and second parameters must have the same or compatible types.

The following combinations are valid for getting the difference:

§       Difference b/w two Dates

§       Difference b/w two Times

§       Difference b/w two Timestamps

§       Difference b/w Date and timestamp (only the date portion of the timestamp is taken to have the difference)

§       Difference b/w Time and timestamp (only the time portion of the timestamp is taken to have the difference)

%EDITC

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

·   1st parameter is Input numeric value which we want to edit.

·   2nd parameter is the editcode option used to generate the required edited string.

·   3rd parameter is other format option used to generate the required edited string.

·   3rd parameter is optional parameter.

%EDITC is used to format numeric values with special characters like Asterisk(*),Period(.),Comma(,),Cent sign(¢), Pound sign(£),Dollar sign($), minus sign(-), Credit sign(CR) etc. It can also be used to suppress zeros or format number with slash(/) to result in date format.

%EDITW

%EDITC(numeric : editword)

·   1st parameter is Input numeric value which we want to edit.

·   2nd parameter is the editword option used to generate the required edited string.

%EDITW is used to format numeric values with special characters like Asterisk(*),Period(.),Comma(,),Cent sign(¢), Dollar sign($), minus sign(-), Credit sign(CR), Percentage(%) etc. It can also be used to format number with slash(/) to result in date format.

%ELEM

It can be used in below formats:

%ELEM(table_name)

%ELEM(array_name)

%ELEM(multiple_occurrence_data_structure_name)

%ELEM is used to get total number of elements in an array, table, or multiple-occurrence data structure. In other words, we can get the dimension using this function.

%EOF

%EOF(file name)

%EOF is used to detect end-of file, beginning of file, or subfile full conditions while performing a file operation similar to resulting indicator.

%EQUAL

%EQUAL(file name)

%EQUAL is used along with two operation codes SETLL and LOOKUP. 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. Hence we can use SETLL along with %EQUAL to check the existence of the record.

%ERROR

%ERROR( )

%ERROR is used to trace error while performing some operations like while reading a file, calling a program or procedure. We can use 'E' operation code extender or %ERROR to trace the error. If there is an error then the function will return ‘1’ else will return ‘0’.

%FIELDS

%FIELDS(field1: field2: ....) 

In the parameter of %FIELDS, We enter the fields name we want to update in file. Only the mentioned fields are updated.

%FIELDS function is used to partially update a file. In other words, we may need to update only 1 or 2 fields of a file. For that we use this function.

%FOUND

%FOUND{(file_name)}

We use %found in file operations (CHAIN, SETGT,SETLL) and String operations(CHECK , CHECKR, SCAN) and Array Search operations(LOOKUP).   

%found returns '1' if the recent operation finds a relevant/matching record; yet it is not necessary that there will be exact match.

If the match is not found, then it returns '0'.

%HOURS

 %HOURS (Number)

%HOURS converts a number into a duration(No. of hours). We can use this duration to add or subtract to a time or timestamp value. Hence by using %HOURS, we can get any previous time or future time.

%INTH

 %INTH (float)

%INTH function is used to Convert to Integer Format with Half Adjust.

 %INTH is very much like %INT except that if the expression is a decimal, float or character value, half adjust is applied to the value of the expression while converting it to integer type.

%MINUTES

%MINUTES(Number)

%MINUTES converts a number into a duration(No. of minutes). We can use this duration to add or subtract to a time or timestamp value. 

%MONTHS

 %MONTHS (Number of Months)

%MONTHS converts a number into a duration(No. of months). We can use this duration to add or subtract to a Date or timestamp value.

%MSECONDS

 %MSECONDS (Number of Microseconds)

%MSECONDS converts a number into a duration that can be added to a time or timestamp value to affect its no. of microseconds.

%OPEN

%OPEN (file name)

%OPEN function is used to check to see if a file has already been opened.

 It returns *ON if the file is opened, otherwise it returns *OFF.

 In case we are using USROPN keyword in F-Spec, then during the program initialization the file will be closed and we need to open it explicitly.

 If we are not using the keyword USROPN then by default the file will be open during program initialization.

%PARMS

%PARMS

%PARMS returns the number of parameters that were passed to the procedure in which %PARMS is used. For the main procedure, %PARMS is the same as *PARMS.

%REPLACE

%REPLACE (Replacing string, actual string, starting position, offset)

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

%SCAN

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

·     1st parameter of the function is search element are looking up in the source string.

·     2nd parameter is the source string in which we are doing the search.

·     3rd parameter denotes the position from where we want the start the search in source string.

·     The second parameter must be the same type as the first parameter. These parameters can be character, graphic, or UCS-2.

·     Search arguments or source String can contain blanks in form of string or string padded with blank. While doing search those blank spaces are also taken into consideration.

%SCAN function is used to find the first position of the search argument in the source string. If a match is found, then position of that matched position is returned else 0 is returned.

%SECONDS

%SECONDS (Number)

%SECONDS converts a number into a duration that can be added to a time or timestamp value to affect its no. of Seconds.

%SIZE

%SIZE(variable)

%SIZE(array{:*ALL})

%SIZE(table{:*ALL})

%SIZE(multiple occurrence data structure{:*ALL})

%SIZE function returns the number of bytes occupied by the element.

The argument may be a literal, a named constant, a data structure, a field, an array etc.

For a null value field %SIZE returns full length.

If *ALL is specified as the second parameter for %SIZE, then the elements or occurrences size is also considered for array or multiple occurrence data structure

%STATUS

%STATUS{file name}

%STATUS provides a five-digit status code that identifies the error.

Program status codes are in the range 00100 to 00999 and File status codes are in the range 01000 to 01999.

Status codes in the range 00000 to 00050 are normal (i.e., they are not set by an exception/error condition).

%SUBST

%SUBST(Source string:start:length to extract)

·   1st parameter is the source string from which we want to extract some part of string.

·   2nd parameter is the starting position from where we will start the extraction of string.

·   3rd parameter is the length to extract.

%SUBST function partially extracts the string from any position.

%TIMESTAMP

%TIMESTAMP (value : *ISO | *ISO0 )

·   Here, 1st parameter is the Input value which we want to convert to timestamp.

·   We can mention 2nd parameter as well, which tells us about timestamp format of input string.

%TIMESTAMP function is used to convert string into timestamp data type.

%TRIM

%TRIM (Source String : characters to trim)

%TRIM function is used to trim blank spaces from both sides of a string.

 It can also be used to trim characters other than blanks. We can mention those characters to be trimmed in parameter 2.

%TRIML

%TRIML(Source String : characters to trim)

%TRIML function is used to trim leading spaces of a string.

 It can also be used to trim characters other than blanks. We can mention those characters to be trimmed in parameter 2.

%TRIMR

%TRIMR(Source String : characters to trim)

%TRIMR function is used to trim trailing spaces of a string.

 It can also be used to trim characters other than blanks. We can mention those characters to be trimmed in parameter 2.

%YEARS

%YEARS(Number of Years)

%YEARS converts a number into a duration(No. of Years). We can use this duration to add or subtract to a Date or timestamp value. Hence by using %YEARS, we can get any previous Date or future Date.












User Comments:



Subscribe

  Email:



Copyright © www.go4as400.com, 2013-2018. Copyright notice