The Report Writer has a number of built-in functions as shown in the table below:
Subsection Function Name
File ERROR (f)
EOF (f)
END_OF_FILE (f)
FILEFULL (f)
Date DATE (m, d, y)
DAY (dt)
MONTH (dt)
YEAR (dt)
Time TIME (h, m, s)
HOUR (tm)
MINUTE (tm
SECOND (time)
Rounding ROUND (expr)
String Manipulation STRLEN (str)
STRLEFT (str,n)
STRRIGHT (str, n)
STRMID (str, b, n)
Pattern Matching MATCH (str, pat)
RESULT (n)
Data Formatting FORMAT (value, fmt)
The groupings shown in the table are for documentation purposes only (further information on these functions can be found in the corresponding subsections that follow).
File Functions
The file group of functions provide information about error conditions resulting from I/O operations. The file functions provided are:
ERROR ( fname ) return error number, or
zero if no errors.
EOF ( fname ) return true if end of file
END_OF_FILE (fname) reached on read, else
return false.
FILEFULL ( fname ) return true if the file
was full before an
insert, else return false.
In all functions, fname is an internal file name declared in the FILE declarations. The value returned by the functions can be tested as in
IF ERROR (mag) THEN
PRINT "Can't delete record.", NL;
or
READ mag;
WHILE NOT EOF (mag) REPEAT BEGIN
DO details;
READ mag;
END
Date Functions
The date conversion functions split a date into its components (month, day, and year) and compute a date from the components. The functions provided are:
DATE ( month , day , year ) return date value of month, day and year.
DAY ( date ) return day of date value.
MONTH ( date ) return month of date value.
YEAR ( date ) return year of date value.
The following examples show how these functions can be used:
mon = MONTH ($todays_date) ;
year = YEAR ($todays_date) ;
begin_date = DATE (mon, 1, year) ;
IF mon EQ 12 THEN
end_date = DATE (12, 31, year) ;
ELSE
end_date = DATE (mon+1, 1, year) -1;
These examples set begin_date to the first day of the current month and end_date to the last day of the current month. Notice the special care taken for December (mon EQ 12), all values used in the DATE function must be legal date values.
Time Functions
The time conversion functions split a time into its components (hours, minutes, and seconds) and compute a time from the components. The functions provided are:
TIME (hour , minute , second) return time value of hour, minute and second.
HOUR (time) return hour of time value.
MINUTE (time) return minute of time value.
SECOND (time) return second of time value.
These functions can be used in much the same manner as the various date functions.
Rounding Function
The rounding function allows fractional values to be rounded to the nearest whole value. Its syntax is:
ROUND (expression)
This function rounds the numeric value represented by expression to a whole number. Money values are rounded to the nearest basic unit of currency (penny for the U.S.). Therefore, in the statement:
X := ROUND (y) ;
if y is a money value of 1.495, x would equal 1.50. However, if y is a real value of 1.495, x would equal 1.
String Manipulation Functions
The string manipulation functions allow STRING and CHAR type strings to be split into substrings. The string manipulation functions provided are:
STRLEN (string) return number of significant characters in string.
STRLEFT (string , number) return first number significant characters of string.
STRRIGHT (string , number) return last number significant characters of string.
STRMID (string , start , number) return first number significant characters of sub-string of string starting at position start.
For the STRLEFT and STRRIGHT functions, if string contains fewer than number characters, string is returned. If the substring starting at position start contains fewer than number characters, STRMID returns the entire substring. The following examples show how these functions can be used:
PRINT STRLEN (str), NL;
PRINT STRLEFT (str, 10), NL;
PRINT STRRIGHT (str, 10), NL;
PRINT STRMID (str, 5, 6), NL;
If str has the value of Hello, world!, the following output would be produced from these examples:
13
Hello, wor
lo, world!
, worl
Pattern Matching Functions
The pattern matching functions provide a method of testing and parsing strings based on regular expressions.
MATCH (string, pattern) matches the string value string with the regular expression string pattern. Returns $TRUE if the regular expression matches the string; otherwise the MATCH function returns $FALSE.
RESULT (number) return a string matched by the last MATCH function.
If the MATCH function returns $TRUE, you can use the RESULT function to return the substring of string that matched the regular expression.
Regular Expressions
Pattern Description
c Matches itself (c can be any character except the special characters \ * . [ $).
\c Matches single special character c (c can be one of the special characters \ * . [ $).
. Matches any single character.
[class] Matches any single character in class. Class is one or more single characters, a range of characters a-b, or a combination.
[^class] Matches any single character not in class. Class is one or more single characters, a range of characters a-b, or a combination.
re* Matches 0 or more occurrences of the single character regular expression re.
re\{m\} Matches exactly m occurrences of the single character regular expression re.
re\{m,\} Matches at least m occurrences of the single character regular expression re.
re\{m,n\} Matches from m through n occurrences of the single character regular expression re.
\(re\ Matches the regular expression re and saves the string matched by re.
\n Matches the saved string from the n'th \(...\).
^ At the beginning of a regular expression, ^matches the beginning of string.
$ At the end of a regular expression, $ matches the end of string.
re re Matches first regular expression followed by the second regular expression.
The following examples illustrate some common regular expressions:
MATCH (x,"abc") Matches the string abc anywhere in x.
MATCH (x,"^abc") Matches the string abc at the beginning of x.
MATCH (x,"abc$") Matches the string abc at the end of x.
MATCH (x,"a\\c") Matches the string a\c anywhere in x.
MATCH (phone,"([0-9]\{3\})[0-9]\{3\}-[0-9]\{4\}")
Matches a phone number in phone.
RESULT (expression)
Description
The RESULT function returns a string matched by the last match statement. If the value of the expression is 0, RESULT returns the string matched by the entire regular expression. Otherwise, RESULT returns the string matched by the n'th \(...\) in the regular expression, where n is the value of expression.
If there was no previous MATCH function, or the last MATCH was not successful, RESULT returns an empty string.
The MATCH and RESULT functions are useful in extracting substrings from a string.
Example
The following example extracts an area code from a phone number
IF MATCH (phone,"(\([0-9]\{3\}\))[0-9]\{3\}-[0-9]\{4\}") THEN
area = RESULT(1);
Data Formatting
Ordinarily, the Report Writer uses the standard formatting routines to change values from their binary representation into a string representation. For example, with this code
year = 89;
key = "Dec" @ year @ "." @ seq;
if seq has a value of 2039, the value of key would be Dec89.2,039. If seq takes on very large numbers, 234452482391, the value of the key is probably not what is desired.
To overcome this, an explicit conversion function, FORMAT, is provided that allows any value to be formatted into a string representation using a user specified format. The syntax of this function is as follows:
FORMAT (value.format)
where value is the data value to be converted, and format is the RMS formatting string to control the conversion. See Chapter 13, Formatting Data Values for more information on legal "output" formatting strings. FORMAT returns the string representation of the value.
Function Summary
As mentioned at the beginning of this section on data values, function calls may be used as data values in expressions. Any time you see expression as part of the syntax statement, you may use function calls, or function calls combined with expression operators.