This module covers detailed explanation and the usage of the built-in functions of the RPGLE programming language.
RPGLE offers a wide range of Built-in functions to perform various tasks. Built-in functions have a pre-defined logic, which accept some input parameters and executes the logic and returns the result. They start with % symbol like %CHECK, %SUBST, etc. Built-in functions can be used in an expression.
The built-in functions make the programmers work easy as the logic is available ready-made.
The basic syntax:
function-name{(argument{:argument…})}
There are some mandatory and optional arguments to the function. The arguments can be variables, constants, expressions, the procedures or other built-in functions.
There are variety of built-in functions broadly categorized as follows:
String Functions:
%CHAR, %CHECK, %CHECKR, %SCAN, %SUBST
Numeric Functions:
%ABS, %DEC, %INT, %DECPOS, %DIV, %FLOAT
Date-Time Related Functions:
%DATE, %TIME, %TIMESTAMP, %DIFF, %MONTHS, %DAYS, %YEARS
File Related Functions:
%EOF, %FOUND, %EQUAL
Error-Handling Functions:
%ERROR, %STATUS
Array & Data structure Related Functions:
%ELEM, %LOOKUP, %LOOKUPXX, %FIELDS, %KDS, %OCCUR
Example 1: (To validate the Mobile number)
**FREE
Dcl-c Digits ‘0123456789’;
Dcl-s mob_num char(10);
Dsply ‘Enter the mobile’ ‘ ‘ mob_num;
If %check(digits:mob_num) > 0;
Dsply ‘Mobile number should contain only digits’;
Endif;
*inlr = *on;
Example 2: (To display the age)
**FREE
Dcl-s Today Date inz(*sys);
Dcl-s DOB Date inz(D’1998-06-09′);
Dsply (‘You are ‘ + %char(%diff(Today:DOB:*y)) + ‘ Years Old’);
*Inlr = *on;
These are just few examples of how built-in functions can be used. Built-in functions make the code more readable and maintainable. Register for the course, if you want to explore the functions in detail. If you have any questions or specific scenarios, feel free to ask for more details