After completing this chapter, you will be able to describe how to apply built-in functions.
There are over 50 functions built into the language processor. The built-in functions fall into the following categories:
Arithmetic functions:
These functions evaluate numbers from the argument and return a particular value.
Comparison functions:
These functions compare numbers and/or strings and return a value.
Conversion functions:
These functions convert one type of data representation to another type of data representation.
Formatting functions:
These functions manipulate the characters and spacing in strings supplied in the Argument.
String manipulating functions:
These functions analyze a string supplied in the argument (or a variable representing a string) and return a particular value.
Miscellaneous functions:
These functions do not clearly fit into any of the other categories.
The following tables briefly describe the functions in each category.
Function | Description |
---|---|
ABS | Returns the absolute value of the input number. |
MAX | Returns the largest number from the list specified formatted according to the current NUMERIC settings |
MIN | Returns the smallest number from the list specified formatted according to the current NUMERIC settings. |
RANDOM | Returns a quasi-random, non-negative whole number in the range specified. |
SIGN | Returns a number that indicates the sign of the input number |
TRUNC | Returns the integer part of the input number, and optionally a specified number of decimal places. |
Function | Description |
---|---|
COMPARE | Returns 0 if the two input strings are identical. Otherwise, returns the position of the first character that does not match. |
DATATYPE | Returns a string indicating the input string is a particular data type, such as a number or character. |
Function | Description |
---|---|
B2X | Returns a string, in character format, that represents the input binary string converted to hexadecimal. (Binary to hexadecimal) |
C2D | Returns the decimal value of the binary representation of the input string. (Character to Decimal) |
C2X | Returns a string, in character format, that represents the input string converted to hexadecimal. (Character to Hexadecimal) |
D2C | Returns a string, in character format, that represents the input decimal number converted to binary. (Decimal to Character) |
D2X | Returns a string, in character format, that represents the input decimal number converted to hexadecimal. (Decimal to Hexadecimal) |
X2B | Returns a string, in character format, that represents the input hexadecimal string converted to binary. (Hexadecimal to binary). |
X2C | Returns a string, in character format, that represents the input hexadecimal string converted to character. (Hexadecimal to Character) |
X2D | Returns the decimal representation of the input hexadecimal string. (Hexadecimal to Decimal) |
Function | Description |
---|---|
CENTER / CENTRE | Returns a string of a specified length with the input string centered in it, with pad characters added as necessary to make up the length. |
COPIES | Returns the specified number of concatenated copies of the input string. |
FORMAT | Returns the input number, rounded and formatted. |
LEFT | Returns a string of the specified length, truncated or padded on the right as needed. |
RIGHT | Returns a string of the specified length, truncated or padded on the left as needed. |
SPACE | Returns the words in the input string with a specified number of pad characters between each word. |
Function | Description |
---|---|
ABBREV | Returns a string indicating if one string is equal to the specified number of leading characters of another string. |
DELSTR | Returns a string after deleting a specified number of characters, starting at a specified point in the input string. |
DELWORD | Returns a string after deleting a specified number of words, starting at a specified word in the input string. |
FIND | Returns the word number of the first word of a specified phrase found within the input string. |
INDEX | Returns the character position of the first character of a specified string found in the input string. |
LASTPOS | Returns the starting character position of the last occurrence of one string in another. |
LENGTH | Returns the length of the input string. |
POS | Returns the character position of one string in another. |
REVERSE | Returns a character string, the characters of which are in reverse order (swapped end for end). |
STRIP | Returns a character string after removing leading or trailing characters or both from the input string. |
SUBSTR | Returns a portion of the input string beginning at a specified character position. |
SUBWORD | Returns a portion of the input string starting at a specified word number. |
WORD | Returns a word from an input string as indicated by a specified number. |
WORDINDEX | Returns the character position in an input string of the first character in the specified word. |
WORDLENGTH | Returns the length of a specified word in the input string. |
WORDPOS | Returns the word number of the first word of a specified phrase in the input string. |
WORDS | Returns the number of words in the input string |
Function | Description |
---|---|
ADDRESS | Returns the name of the environment to which commands are currently being sent. |
ARG | Returns an argument or information about the argument strings passed to a program or internal routine. |
BITAND | Returns a string composed of the two input strings logically ANDed together, bit by bit. |
BITOR | Returns a string composed of the two input strings logically ORed together, bit by bit. |
BITXOR | Returns a string composed of the two input strings eXclusive ORed together, bit by bit. |
CONDITION | Returns the condition information, such as name and status, associated with the current trapped condition. |
DATE | Returns the date in the default format (dd mon yyyy) or in one of various optional formats. |
QUEUED | Returns the number of lines remaining in the external data queue at the time when the function is invoked. |
TIME | Returns the local time in the default 24-hour clock format (hh:mm:ss) or in one of various optional formats. |
TRACE | Returns the trace actions currently in effect. |
USERID | Returns the TSO/E user ID, if the REXX exec is running in the TSO/E address space. |
Write an exec that checks a data set member name for a length of 8 characters. If a member name is longer than 8 characters, the exec truncates it to 8 and sends the user a message indicating the shortened name. Use LENGTH and SUBSTR built-in functions.
/**************************REXX****************************************/ /* This Exec tests the length of a name for a dataset member. If the */ /* name exceeds 8 characters, the exec truncates the extra characters */ /* and sends the user a message indicating the shortened member name */ /**********************************************************************/ SAY 'PLEASE ENTER A MEMBER NAME' PULL MEMBERNAME IF LENGTH(MEMBERNAME) > 8 THEN /* Name is Longer than 8 Characters */ DO MEMBERNAME = SUBSTR(MEMBERNAME,1,8) /* Shorten the name to first 8 characters */ SAY 'THE MEMBER NAME YOU ENTERED WAS TOO LONG' SAY MEMBERNAME 'WILL BE USED' END ELSE NOP EXIT 0 |
Program receives member name as input.
The LENGTH(membername) In Built function gets the length of the input.
If length is greater than 8, use SUBSTR function to retrieve the first 8 characters of the member name.
Proper comments must be used for better understanding.
Indentation must be appropriate for better readability.
There are different types of Build-in functions available in Rexx.
If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!