Midware Ltd.
|
Sign-up for e-mail notifications
|
Built-in-functions (BIF's) are probably the most exciting new feature in RPG IV - not just because of the functionality they provide, but because of the potential they promise. Built in functions are actually procedures written by IBM that may be used in expressions (IF, EVAL, etc.) as if they are variables. Procedures are an ILE concept that we will cover in later sections. For now just think of a procedure as a kind of hybrid subroutine. In later sections, we'll show you how you can write your own functions. This is a little more advanced, and requires some knowledge of ILE concepts. There is nothing special you need to do to use built in functions however. If you are using RPG IV, you have full access to all BIF's. All built in functions begin with a percent sign (%). Most built in functions accept parameters which can be coded in parenthesis. Multiple parameters should be separated by a colon (:). The syntax of built-in-functions is:
BIF's may be used in any freeform expressions and may be embedded in in other built in functions. For example:
The built in function %ABS returns the absolute value of a numeric parameter. %INT returns the integer portion a numeric parameter. The above example will execute from the innermost parenthesis first. Each BIF will execute a procedure call and return the result in place of the expressions. For example, lets assume that @Value is set to -3.14 at the time the EVAL statement is executed. The sequence the statement will be evaluated is as follows:
A wide range of built in functions are available. New functions are added with each release of the operation system. At one point, IBM said that most of the near-term enhancements to RPG will be in the form of new BIF's. Check with IBM's online documentation for the BIF's available in your release or click here for a complete list of BIF's in V4R5. Following is a rundown of some of the more useful built-in-functions. %ABS(numeric expression) %EDITC(numeric : editcode {: *ASTFILL | *CURSYM | currency-symbol})
%EOF{(file_name)} %EOF, %EQUAL and %FOUND may be used to replace the status indicators on I/O operations. %EOF is used with read operations (READ, READE, etc.), %EQUAL may be used with the SETLL operation, and %FOUND may be used with the CHAIN, DELETE, SETLL and SETGT operations.
If the file parameter is omitted from the function, the status of the last file operation will be returned. For example:
The %EQUAL and %FOUND functions may be used also for some non-I/O operations as well. The LOOKUP operation code will set both %EQUAL and %FOUND. %FOUND may also be used with the CHECK, CHECKR, and SCAN operation codes in place of an indicator. %INT(numeric expression)
Note the use of the %CHAR built in function to convert the numeric data to character format. Remember, you can not mix data types in a free-format expression (%CHAR can only be used to convert numeric data as of V4R4). %LEN(expression) %SCAN(search argument : source string {: start}) %TRIM(string)
|
Send mail to midware@midwareservices.com
with questions or comments about this web site. Last Modified: August 18, 2000 |