TIB WFWF 8207.27.0 Functions
TIB WFWF 8207.27.0 Functions
Using Functions
Release 8207
March 2021
DN4501670.0321
Using Functions 3
Contents
4
Contents
INCREASE: Calculating the Difference Between the Current and a Prior Value of a Field . . . . . . 114
PCT_INCREASE: Calculating the Percentage Difference Between the Current and a Prior Value
of a Field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
PREVIOUS: Retrieving a Prior Value of a Field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .121
RUNNING_AVE: Calculating an Average Over a Group of Rows . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
RUNNING_MAX: Calculating a Maximum Over a Group of Rows . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
RUNNING_MIN: Calculating a Minimum Over a Group of Rows . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
RUNNING_SUM: Calculating a Sum Over a Group of Rows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .132
Using Functions 5
Contents
6
Contents
Using Functions 7
Contents
8
Contents
Using Functions 9
Contents
10
Contents
Using Functions 11
Contents
12
Contents
Using Functions 13
Contents
14
Contents
Using Functions 15
Contents
16
Chapter 1 How to Use This Manual
This manual describes the functions supplied with your Information Builders product. It is
intended for application developers who call these functions from their programs to
perform calculations or manipulate data. Other users who access corporate data to
produce reports can call these functions.
This manual also explains how to create functions tailored to individual needs (called
subroutines) for use with your Information Builders product.
In this chapter:
Available Languages
Operating Systems
Available Languages
A function is available in the reporting language, the Maintain language, or both:
The reporting language includes all commands used to create a report. It is available to
users of any Information Builders product.
The Maintain language includes all commands used to maintain data sources with the
Maintain product. It is available only to those who purchased Maintain.
Look in the description of an individual function for the available language, or in the
categorized list of functions in Introducing Functions on page 19.
Operating Systems
Except in cases noted specifically, all functions run on all server-supported operating systems.
Using Functions 17
Operating Systems
18
Chapter 2 Introducing Functions
The following topics offer an introduction to functions and explain the different types of
functions available.
In this chapter:
Using Functions
Types of Functions
Using Functions
Functions operate on one or more arguments and return a single value. The returned value can
be stored in a field, assigned to a Dialogue Manager variable, used in a calculation or other
processing, or used in a selection or validation test. Functions provide a convenient way to
perform certain calculations and manipulations.
Internal functions. Built into the WebFOCUS language, requiring no extra work to access or
use. The following functions are internal functions. You cannot replace any of these internal
functions with your own functions of the same name. All other functions are external.
ABS
ASIS
DECODE
EDIT
FIND
LAST
LOG
LOOKUP
Using Functions 19
Types of Functions
SQRT
External functions. Stored in an external library that must be accessed. When invoking
these functions, an argument specifying the output field or format of the result is required.
External functions are distributed with WebFOCUS. You can replace these functions with
your own functions of the same name. However, in this case, you must set
USERFNS=LOCAL.
Subroutines. Written by the user and stored externally. For details, see Creating a
Subroutine on page 715.
For information on how to use an internal or external function, see Accessing and Calling a
Function on page 59.
Types of Functions
You can access any of the following types of functions:
Simplified analytic functions. Perform calculations using multiple rows in the internal
matrix. For details, see Simplified Analytic Functions on page 22.
Simplified character functions. Character functions with streamlined parameter lists and
no output arguments, similar to those used by SQL functions. For details, see Simplified
Character Functions on page 23.
Character functions. Manipulate alphanumeric fields or character strings. For details, see
Character Functions on page 25.
Variable length character functions. Manipulate AnV fields or character strings. For details,
see Variable Length Character Functions on page 28.
Character functions for DBCS code pages. Manipulate alphanumeric fields or character
strings on DBCS code pages. For details, see Character Functions for DBCS Code Pages on
page 29.
Data source and decoding functions. Search for or retrieve data source records or values,
and assign values. For details, see Data Source and Decoding Functions on page 31.
20
2. Introducing Functions
Simplified date and date-time functions. Date and date-time functions with streamlined
parameter lists and no output arguments, similar to those used by SQL functions. For
details, see Simplified Date and Date-Time Functions on page 33.
Date functions. Manipulate dates. For details, see Date Functions on page 33.
Date-time functions. Manipulate date-time values. For details, see Date-Time Functions on
page 36.
Maintain-specific date and time functions. Manipulate dates and times. These functions
are available only in Maintain Data. For details, see Maintain-specific Date and Time
Functions on page 38.
Simplified conversion functions. Convert fields from one format to another using
streamlined parameter lists. For details, see Simplified Conversion Functions on page 39.
Format conversion functions. Convert fields from one format to another. For details, see
Format Conversion Functions on page 40.
Simplified numeric functions. Perform calculations on numeric constants and fields using
streamlined parameter lists. For details, see Simplified Numeric Functions on page 42.
Numeric functions. Perform calculations on numeric constants and fields. For details, see
Numeric Functions on page 42.
Maintain-specific Script functions. Integrate JavaScript and VBScripts into your Maintain
Data application and perform client-side execution without returning to the WebFOCUS
Server. These functions are available only in Maintain Data. For details, see Maintain-
specific Script Functions on page 45.
Simplified statistical functions. Perform statistical calculations. For details, see Simplified
Statistical Functions on page 45.
Machine Leaning (Python-based) Functions. Run Python scripts that perform classification
and regression. For details, see Machine Learning (Python-based) Functions on page 45.
Simplified system functions. Call the operating system to obtain information about the
operating environment or to use a system service, using streamlined parameter lists. For
details, see Simplified System Functions on page 46.
Using Functions 21
Types of Functions
System functions. Call the operating system to obtain information about the operating
environment or to use a system service. For details, see System Functions on page 47.
WebFOCUS-specific Functions
Most Information Builders-supplied functions are available in both WebFOCUS and FOCUS.
However, some functions are available only in WebFOCUS. They are:
SPAWN
SYSTEM
22
2. Introducing Functions
PCT_INCREASE
Calculates the percent difference between a value in the current row and a prior row within
a partition.
PREVIOUS
Retrieves a prior value within a partition.
RUNNING_AVE
Calculate the average over a group of rows within a partition.
RUNNING_MIN
Calculate the minimum over a group of rows within a partition.
RUNNING_MAX
Calculate the maximum over a group of rows within a partition.
RUNNING_SUM
Calculate the sum over a group of rows within a partition.
Using Functions 23
Types of Functions
LAST_NONBLANK
retrieves the last field value that is neither blank nor missing. If all previous values are
either blank or missing, returns a missing value.
LOWER
Translates a string to lowercase.
24
2. Introducing Functions
TOKEN
Extracts a token (substring) based on a token number and a delimiter string.
Character Functions
The following functions manipulate alphanumeric fields or character strings. For details, see
Character Functions on page 195.
ARGLEN
Measures the length of a character string within a field, excluding trailing blanks.
Using Functions 25
Types of Functions
CHKFMT
Checks a character string for incorrect characters or character types.
26
2. Introducing Functions
LOCASE
Converts alphanumeric text to lowercase.
Using Functions 27
Types of Functions
STRIP
Removes all occurrences of a specific character from a string.
28
2. Introducing Functions
SUBSTV
Extracts a substring based on where it begins and its length in the parent string in an AnV
field.
Using Functions 29
Types of Functions
30
2. Introducing Functions
SELECTS
Decodes a value from a stack.
STRAN
Substitutes a substring for another substring in a character string.
STRCMP
Compares two alphanumeric strings using the ASCII or EBCDIC collating sequence.
STRICMP
Compares two alphanumeric strings using the ASCII or EBCDIC collating sequence, but
ignoring case differences.
STRNCMP
Compares a specified number of characters in two character strings starting at the
beginning of the strings using the EBCDIC or ASCII collating sequence.
SUBSTR
Extracts a substring based on where it begins and its length in the parent string.
TRIM
Removes trailing occurrences of a pattern within a character string.
TRIMLEN
Determines the length of a character string excluding trailing spaces.
UPCASE
Converts a character string to uppercase.
Using Functions 31
Types of Functions
DB_INFILE
Compares values in a source file to values in a target file, or if the source file is a
relational data source, to values retrieved by a subquery.
32
2. Introducing Functions
Date Functions
The following functions manipulate dates. For details see Date Functions on page 365.
Using Functions 33
Types of Functions
DATECVT
Converts date formats.
34
2. Introducing Functions
Using Functions 35
Types of Functions
Date-Time Functions
The following functions manipulate date-time values. For details see Date-Time Functions on
page 435.
HADD
Increments a date-time field by a given number of units.
36
2. Introducing Functions
Using Functions 37
Types of Functions
38
2. Introducing Functions
TODAY
Retrieves the current date from the system.
TODAY2
Retrieves the current date from the system.
Using Functions 39
Types of Functions
COMPACTFORMAT
Converts a numeric value to an alphanumeric value that represents the number in an
abbreviated format, using the characters K, M, B, and T to represent the abbreviation.
40
2. Introducing Functions
HEXBYT
Obtains the ASCII or EBCDIC character equivalent of a decimal integer value.
Using Functions 41
Types of Functions
Numeric Functions
The following functions perform calculations on numeric constants or fields. For details, see
Numeric Functions on page 547
ABS
Returns the absolute value of a number.
42
2. Introducing Functions
BAR
Produces a horizontal bar chart.
Using Functions 43
Types of Functions
44
2. Introducing Functions
Using Functions 45
Types of Functions
CLASSIFY_BLR
Finds the best linear separation between two classes in the space spanned by the
predictors, and returns either a class assignment (0 or 1) or the probability of belonging to
class 1.
CLASSIFY_KNN
Assigns a class membership to a data point by assigning the class most common among
its k nearest neighbors.
CLASSIFY_RF
Creates a random forest (ensemble of decision trees), and returns the prediction that is
the average of the individual predictions.
CLASSIFY_XGB
Creates a random forest (ensemble of decision trees), where each new tree attempts to
improve on the predictive capabilities of the prior trees.
REGRESS_KNN
Predicts a target value for a data point by assigning the average of the target values of its
k nearest neighbors.
REGRESS_POLY
Fits the target column to a polynomial expression of the predictor columns.
REGRESS_RF
Creates a random forest (ensemble of decision trees), and returns the prediction that is
the majority vote of the individual classification predictions.
REGRESS_XGB
Creates a random forest (ensemble of decision trees), where each new tree attempts to
improve on the predictive capabilities of the prior trees.
RUN_MODEL and RUN_MODEL2
RUN_MODEL runs a saved model where the field names in the data source used to run the
model are the same as the field names in the data source used to create the model.
RUN_MODEL2 runs a saved model where the field names in the data source used to run
the model are not the same as the field names in the data source used to create the
model.
46
2. Introducing Functions
ENCRYPT
Encrypts a password.
GETENV
Retrieves the value of an environment variable.
PUTENV
Assigns a value to an environment variable.
SLACK
Posts a message to a Slack channel from a WebFOCUS request.
System Functions
The following functions call the operating system to obtain information about the operating
environment or to use a system service. For details, see System Functions on page 645
CLSDDREC
Closes a file and frees the memory used to store information about open files.
Using Functions 47
Types of Functions
SYSTEM
Calls a DOS program, a DOS batch program, or a Windows application. This function is
available only for WebFOCUS.
48
2. Introducing Functions
SYSVAR
Retrieves the value of a z/OS system variable.
Using Functions 49
Character Chart for ASCII and EBCDIC
33 ! exclamation point
35 # number sign
36 $ dollar sign
37 % percent
38 & ampersand
39 ' apostrophe
40 ( left parenthesis
41 ) right parenthesis
42 * asterisk
43 + plus sign
44 , comma
45 - hyphen
46 . period
47 / slash
48 0 0
49 1 1
50 2 2
51 3 3
50
2. Introducing Functions
52 4 4
53 5 5
54 6 6
55 7 7
56 8 8
57 9 9
58 : colon
59 ; semicolon
61 = equal sign
63 ? question mark
64 @ at sign
65 A A
66 B B
67 C C
68 D D
69 E E
70 F F
71 G G
72 H H
73 I I
Using Functions 51
Character Chart for ASCII and EBCDIC
74 J J ¢ cent sign
75 K K . period
77 M M ( left parenthesis
78 N N + plus sign
79 O O | logical or
80 P P & ampersand
81 Q Q
82 R R
83 S S
84 T T
85 U U
86 V V
87 W W
88 X X
89 Y Y
90 Z Z ! exclamation point
94 ^ caret ; semicolon
52
2. Introducing Functions
97 a a / slash
98 b b
99 c c
100 d d
101 e e
102 f f
103 g g
104 h h
105 i i
106 j j
107 k k , comma
108 l l % percent
109 m m _ underscore
112 p p
113 q q
114 r r
115 s s
116 t t
117 u u
Using Functions 53
Character Chart for ASCII and EBCDIC
118 v v
119 w w
120 x x
121 y y
122 z z : colon
129 a a
130 b b
131 c c
132 d d
133 e e
134 f f
135 g g
136 h h
137 i i
145 j j
146 k k
147 l l
54
2. Introducing Functions
148 m m
149 n n
150 o o
151 p p
152 q q
153 r r
162 s s
163 t t
164 u u
165 v v
166 w w
167 x x
168 y y
169 z z
193 A A
194 B B
195 C C
196 D D
197 E E
198 F F
199 G G
Using Functions 55
Character Chart for ASCII and EBCDIC
200 H H
201 I I
209 J J
210 K K
211 L L
212 M M
213 N N
214 O O
215 P P
216 Q Q
217 R R
226 S S
227 T T
228 U U
229 V V
230 W W
231 X X
232 Y Y
233 Z Z
240 0 0
241 1 1
242 2 2
56
2. Introducing Functions
243 3 3
244 4 4
245 5 5
246 6 6
247 7 7
248 8 8
249 9 9
Using Functions 57
Character Chart for ASCII and EBCDIC
58
Chapter 3 Accessing and Calling a Function
The following topics describe the considerations for supplying arguments in a function,
and explain how to use a function in a command and access functions stored externally.
In this chapter:
Calling a Function
Calling a Function
You can call a function from a COMPUTE, DEFINE, or VALIDATE command. You can also call
functions from a Dialogue Manager command, a Financial Modeling Language (FML) command,
or a Maintain command. A function is called with the function name, arguments, and, for
external functions, an output field.
For more information on external functions, see Types of Functions on page 20.
Some Maintain-specific functions require that the MNTUWS function library be retrieved when
calling the function. For functions that require this, it is specified in the detailed information for
that function. For more information on retrieving the MNTUWS library, see How to Access the
Maintain MNTUWS Function Library on page 61.
Using Functions 59
Calling a Function
where:
function
Is the name of the function.
arg1, arg2, ...
Are the arguments.
outfield
Is the field that contains the result, or the format of the output value enclosed in single
quotation marks. This argument is required only for external functions.
In Dialogue Manager, you must specify the format. In Maintain Data, you must specify the
name of the field.
or
or
where:
DEFINE
Creates a virtual field that may be used in a request as though it is a real data source
field.
COMPUTE
Calculates one or more temporary fields in a request. The field is calculated after all
records have been selected, sorted, and summed.
field
Is the field that contains the result.
60
3. Accessing and Calling a Function
file
Is the file in which the virtual field is created.
var
Is the variable that contains the result.
fmt
Is the format of the field that contains the result.
function
Is the name of the function, up to eight characters long.
input1, input2,...
Are the input arguments, which are data values or fields used in function processing. For
more information about arguments, see Supplying an Argument in a Function on page
61.
outfield
Is the field that contains the result, or the format of the output value enclosed in single
quotation marks. This argument is required only for external functions.
In Dialogue Manager, you must specify the format. In Maintain Data, you must specify the
name of the field.
Argument Types
The following are acceptable arguments for a function:
Using Functions 61
Supplying an Argument in a Function
Alphanumeric literal, such as STEVENS or NEW YORK NY. A literal must be enclosed in
single quotation marks.
Field name, such as FIRST_NAME or HIRE_DATE. A field can be a data source field or
temporary field. The field name can be up to 66 characters long or a qualified field name,
unique truncation, or alias.
and
FN || LN
Another function.
Label or other row or column reference (such as R or E), or name of another RECAP
calculation, when the function is called in an FML RECAP command.
Argument Formats
Depending on the function, an argument can be in alphanumeric, numeric, or date format. If
you supply an argument in the wrong format, you will cause an error or the function will not
return correct data. The following are the types of argument formats:
62
3. Accessing and Calling a Function
All numeric arguments are converted to floating-point double-precision format when used
with a function, but results are returned in the format specified for the output field.
Note: With CDN ON, numeric arguments must be delimited by a comma followed by a
space.
Date argument. A date argument can be in either alphanumeric, numeric, or date format.
The list of arguments for the individual function will specify what type of format the function
accepts. A date argument can be a date in alphanumeric, numeric, or date format; a date
field or expression; or the format of a date field.
If you supply an argument with a two-digit year, the function assigns a century based on the
YRTHRESH and DEFCENT parameter settings.
Argument Length
An argument is passed to a function by reference, meaning that the memory location of the
argument is passed. No indication of the length of the argument is given.
You must supply the argument length for alphanumeric strings. Some functions require a
length for the input and output arguments (for example, SUBSTR), and others use one length
for both arguments (for example, UPCASE).
Be careful to ensure that all lengths are correct. Providing an incorrect length can cause
incorrect results:
If the specified length is shorter than the actual length, a subset of the string is used. For
example, passing the argument 'ABCDEF' and specifying a length of 3 causes the function
to process a string of 'ABC'.
If the specified length is too long, whatever is in memory up to that length is included. For
example, passing an argument of 'ABC' and specifying a length of 6 causes the function to
process a string beginning with 'ABC' plus the three characters in the next three positions
of memory. Depending on memory utilization, the extra three characters could be anything.
Some operating system routines are very sensitive to incorrectly specified lengths and read
them into incorrectly formatted memory areas.
Using Functions 63
Supplying an Argument in a Function
Arguments must be specified in the order shown in the syntax of each function. The required
order varies according to the function.
Functions typically expect parameters to be a specific type or have a length that depends on
the value of another parameter. It is possible in some situations to enforce these rules by
truncating the length of a parameter and, therefore, avoid generating an error at run time.
The level of verification and possible conversion to a valid format performed depends on the
specific function. The following two situations can usually be converted satisfactorily:
If a numeric parameter specifies a maximum size for an alphanumeric parameter, but the
alphanumeric string supplied is longer than the specified size, the string can be truncated.
If a parameter supplied as a numeric literal specifies a value larger than the maximum size
for a parameter, it can be reduced to the proper value.
where:
SYSTEM
64
3. Accessing and Calling a Function
LOCAL
Gives precedence to locally written functions. Parameter verification is not performed with
this setting in effect.
Note: When USERFNS is set to LOCAL, DT functions only display a six-digit date.
where:
setting
Can be one of the following:
ON is the default value. Verifies parameters in requests, but does not verify parameters
for functions used in Master File DEFINEs. If a parameter has an incorrect length, an
attempt is made to fix the problem. If such a problem cannot be fixed, an error
message is generated and the evaluation of the affected expression is terminated.
Because parameters are not verified for functions specified in a Master File, no errors
are reported for those functions until the DEFINE field is used in a subsequent request
when, if a problem occurs, the following message is generated:
(FOC003) THE FIELDNAME IS NOT RECOGNIZED
If a parameter that is too long would overwrite the memory area in which the
computational code is stored, the size is automatically reduced without issuing a
message.
Note:
We strongly recommend that you not use the OFF setting, as disabling parameter
checking can lead to unexpected issues.
FULL is the same as ON, but also verifies parameters for functions used in Master File
DEFINEs.
Using Functions 65
Supplying an Argument in a Function
Errors encountered during subroutine processing, unless fatal at the system level,
are communicated to the calling routine through the return of an unchanged return
parameter, which is the last parameter in the subroutine call. This is always
communicated as spaces for alphanumeric outputs.
When the request is executed with USERFCHK=ON or OFF, the incorrect length is corrected and
the request continues processing:
TITLE NEWTITLE
----- --------
SMURFS, THE S, THE
SHAGGY DOG, THE Y DOG, TH
SCOOBY-DOO-A DOG IN THE RUFF Y-DOO-A D
ALICE IN WONDERLAND IN WONDE
SESAME STREET-BEDTIME STORIES AND SONGS E STREET-
ROMPER ROOM-ASK MISS MOLLY R ROOM-AS
SLEEPING BEAUTY ING BEAUT
BAMBI
66
3. Accessing and Calling a Function
When the request is executed with USERFCHK=ON, a message is produced and the
request terminates:
ERROR AT OR NEAR LINE 5 IN PROCEDURE USERFC3 FOCEXEC
(FOC279) NUMERIC ARGUMENTS IN PLACE WHERE ALPHA ARE CALLED FOR
(FOC009) INCOMPLETE REQUEST STATEMENT
UNKNOWN FOCUS COMMAND WHERE
BYPASSING TO END OF COMMAND
Using Functions 67
Calling a Function From a Dialogue Manager Command
where:
filename
Is the data source being used.
tempfield
Is the temporary field created by the DEFINE or COMPUTE command. This is the same field
specified in outfield. If the function call supplies the format of the output value in outfield,
the format of the temporary field must match the outfield argument.
format
Is the format of the temporary field. The format is required if it is the first time the field is
created; otherwise, it is optional. The default value is D12.2.
function
Is the name of the function.
input1, input2, input3...
Are the arguments.
outfield
Is the field that contains the result, or the format of the output value enclosed in single
quotation marks. This is required only for external functions.
In Dialogue Manager, you must specify the format. In Maintain Data, you must specify the
name of the field.
From a -SET command, storing the result of a function in a variable. For more information,
see Assigning the Result of a Function to a Variable on page 69.
From an -IF command. For more information, see Calling a Function in WHERE or IF Criteria
on page 73.
From an operating system -RUN command. For more information, see Calling a Function
From an Operating System RUN Command on page 72.
Dialogue Manager converts a numeric argument to double-precision format. This occurs when
the value of the argument is numeric; this is not affected by the format expected by the
function. This means you must be careful when supplying arguments for a function in Dialogue
Manager.
68
3. Accessing and Calling a Function
If the function expects an alphanumeric string and the input is a numeric string, incorrect
results will occur because of conversion to floating-point double-precision. To resolve this
problem, append a non-numeric character to the end of the string, but do not count this extra
character in the length of the argument.
Dialogue Manager date variables such as &YYMD return alphanumeric legacy dates, not a date
format (an offset from a base date). If a function requires a date offset rather than a legacy
date, you must convert any date variable to a date offset (using the DATECVT function) before
using it as an argument. You can then convert the result back to a legacy date, again with the
DATECVT function. For example:
-SET &TODAY_OFFSET=DATECVT(&YYMD , 'I8YYMD' , 'YYMD');
-SET &BEG_CUR_YR=DATEMOV(&TODAY_OFFSET.EVAL , 'BOY');
-SET &CLOSE_DTBOY=DATECVT(&BEG_CUR_YR.EVAL , 'YYMD' , 'I8YYMD')';
A Dialogue Manager variable contains only alphanumeric data. If a function returns a numeric
value to a Dialogue Manager variable, the value is truncated to an integer and converted to
alphanumeric format before being stored in the variable.
where:
variable
Is the variable to which the result will be assigned.
function
Is the function.
arg1, arg2
Are the function's arguments.
.LENGTH
Returns the length of the variable. If a function requires the length of a character string as
an input argument, you can prompt for the character string and determine the length with
the .LENGTH suffix.
Using Functions 69
Calling a Function From a Dialogue Manager Command
format
Is the format of the result enclosed in single quotation marks. You cannot specify a
Dialogue Manager variable for the output argument unless you use the .EVAL suffix;
however, you can specify a variable for an input argument.
The format of the output date is a six-digit integer (I6). Although the format indicates that the
output is an integer, it is stored in the &OUTDATE variable as a character string. For this
reason, if you display the value of &OUTDATE, you will not see slashes separating the year,
month, and day.
If a branching command spans more than one line, continue it on the next line by placing a
dash (-) in the first column.
where:
function
Is the function.
args
Are the arguments.
relation
Is an operator that determines the relationship between the function and expression, for
example, EQ or LE.
expression
Is a value, logical expression, or function. Do not enclose a literal in single quotation
marks unless it contains a comma or embedded blank.
70
3. Accessing and Calling a Function
label1, label2
Are user-defined names up to 12 characters long. Do not use embedded blanks or the
name of any other Dialogue Manager command except -QUIT or -EXIT. Do not use a word
that can be confused with a function, or an arithmetic or logical operation.
The label text can precede or follow the -IF criteria in the procedure.
ELSE GOTO
Using Functions 71
Calling a Function From a Dialogue Manager Command
If a function requires an argument in numeric format, you must first convert it to floating-point
double-precision format using the ATODBL function because, unlike the -SET command, an
operating system RUN command does not automatically convert a numeric argument to double-
precision.
where:
-TSO|-MVS
For example, if the function returns a value that is eight bytes long, define the variable with
eight characters enclosed in single quotation marks before the function call:
-SET &output = '12345678';
72
3. Accessing and Calling a Function
where:
field
Is the field that contains the result of the function.
function
Is a function.
arguments
Are arguments for function.
function2
Is the function that is an argument for function.
arguments2
Are arguments for function2.
Using Functions 73
Calling a Function in WHERE or IF Criteria
where:
function
Is a function.
relation
Is an operator that determines the relationship between the function and expression, for
example, EQ or LE.
expression
Is a constant, field, or function. A literal must be enclosed in single quotation marks.
where:
function
Is a function.
relation
Is an operator that determines the relationship between the function and expression, for
example, EQ or LE.
value
Is a constant. In a DEFINE or COMPUTE command, the value must be enclosed in single
quotation marks.
74
3. Accessing and Calling a Function
Pre-define the format within a separate command. In the following example, the AMOUNT
field is pre-defined with the format D8.2 and the function returns a value to the output field
AMOUNT. The IF command tests the value of AMOUNT and stores the result in the
calculated value, AMOUNT_FLAG.
COMPUTE
AMOUNT/D8.2 =;
AMOUNT_FLAG/A5 = IF function(input1, input2, AMOUNT) GE 500
THEN 'LARGE' ELSE 'SMALL';
Supply the format as the last argument in the function call. In the following example, the
command tests the returned value directly. This is possible because the function defines
the format of the returned value (D8.2).
DEFINE
AMOUNT_FLAG/A5 = IF function(input1, input2, 'D8.2') GE 500
THEN 'LARGE' ELSE 'SMALL';
or
WHEN NOT(function)
where:
function
Is a function.
Using Functions 75
Calling a Function From a RECAP Command
value
Is a value or logical expression.
relation
Is an operator that determines the relationship between the value and function, for
example, LE or GT.
RECAP name[(n)|(n,m)|(n,m,i)][/format1] =
function(input1,...,['format2']);
where:
name
Is the name of the calculation.
76
3. Accessing and Calling a Function
n
Displays the value in the column number specified by n. If you omit the column number,
the value appears in all columns.
n,m
Displays the value in all columns beginning with the column number specified by n and
ending with the column number specified by m.
n,m,i
Displays the value in the columns beginning with the column number specified by n and
ending with the column number specified by m by the interval specified by i. For example, if
n is 1, m is 5, and i is 2, the value displays in columns 1, 3, and 5.
format1
Is the format of the calculation. The default value is the format of the report column.
function
Is the function.
input1,...
Are the input arguments, which can include numeric constants, alphanumeric literals, row
and column references (R notation, E notation, or labels), and names of other RECAP
calculations.
format2
Is the format of the output value enclosed in single quotation marks. If the calculation's
format is larger than the column width, the value appears in that column as asterisks.
Using Functions 77
Storing and Accessing an External Function
You can also access private user-written subroutines. If you have a private collection of
subroutines (that is, you created your own or use customized subroutines), do not store them
in the function library. Store them separately to avoid overwriting them whenever your site
installs a new release. For more information on creating a subroutine, see Creating a
Subroutine on page 715.
The search order is USERLIB, STEPLIB, JOBLIB, link pack area, and linklist.
The Server also adds the TASKLIB keyword to the search for non-APF authorized libraries. For
more information, see the Server Installation, Configuration and Operations for MVS manual.
78
3. Accessing and Calling a Function
where:
USERLIB
The load libraries are searched in the order in which they are specified in the ALLOCATE
command.
Using Functions 79
Storing and Accessing an External Function
80
Chapter 4 Simplified Analytic Functions
The analytic functions enable you do perform calculations and retrievals using multiple
rows in the internal matrix.
In this chapter:
Simple moving averages are sometimes used to analyze trends in stock prices over time. In
this scenario, the average is calculated using a specified number of periods of stock prices. A
disadvantage to this indicator is that because it drops the oldest values from the calculation
as it moves on, it loses its memory over time. Also, mean values are distorted by extreme
highs and lows, since this method gives equal weight to each point.
Using Functions 81
FORECAST_MOVAVE: Using a Simple Moving Average
Predicted values beyond the range of the data values are calculated using a moving average
that treats the calculated trend values as new data points.
The first complete moving average occurs at the nth data point because the calculation
requires n values. This is called the lag. The moving average values for the lag rows are
calculated as follows: the first value in the moving average column is equal to the first data
value, the second value in the moving average column is the average of the first two data
values, and so on until the nth row, at which point there are enough values to calculate the
moving average with the number of values specified.
where:
display
Keyword
Specifies which values to display for rows of output that represent existing data. Valid
values are:
INPUT_FIELD. This displays the original field values for rows that represent existing
data.
MODEL_DATA. This displays the calculated values for rows that represent existing
data.
Note: You can show both types of output for any field by creating two independent
COMPUTE commands in the same request, each with a different display option.
infield
Is any numeric field. It can be the same field as the result field, or a different field. It
cannot be a date-time field or a numeric field with date display options.
interval
Is the increment to add to each sort field value (after the last data point) to create the
next value. This must be a positive integer. To sort in descending order, use the BY
HIGHEST phrase. The result of adding this number to the sort field values is converted
to the same format as the sort field.
For date fields, the minimal component in the format determines how the number is
interpreted. For example, if the format is YMD, MDY, or DMY, an interval value of 2 is
interpreted as meaning two days. If the format is YM, the 2 is interpreted as meaning two
months.
82
4. Simplified Analytic Functions
npredict
Is the number of predictions for FORECAST to calculate. It must be an integer greater
than or equal to zero. Zero indicates that you do not want predictions, and is only
supported with a non-recursive FORECAST.
npoint1
Is the number of values to average for the MOVAVE method.
Using Functions 83
FORECAST_MOVAVE: Using a Simple Moving Average
In the report, the number of values to use in the average is 3 and there are no UNITS or
DOLLARS values for the generated PERIOD values.
Each average (MOVAVE value) is computed using DOLLARS values where they exist. The
calculation of the moving average begins in the following way:
The first MOVAVE value (801,123.0) is equal to the first DOLLARS value.
84
4. Simplified Analytic Functions
The second MOVAVE value (741,731.5) is the mean of DOLLARS values one and two:
(801,123 + 682,340) /2.
The third MOVAVE value (749,513.7) is the mean of DOLLARS values one through three:
(801,123 + 682,340 + 765,078) / 3.
The fourth MOVAVE value (712,897.3) is the mean of DOLLARS values two through four:
(682,340 + 765,078 + 691,274) /3.
For predicted values beyond the supplied values, the calculated MOVAVE values are used as
new data points to continue the moving average. The predicted MOVAVE values (starting with
694,975.6 for PERIOD 13) are calculated using the previous MOVAVE values as new data
points. For example, the first predicted value (694,975.6) is the average of the data points
from periods 11 and 12 (620,264 and 762,328) and the moving average for period 12
(702,334.7). The calculation is: 694,975 = (620,264 + 762,328 + 702,334.7)/3.
Using Functions 85
FORECAST_MOVAVE: Using a Simple Moving Average
86
4. Simplified Analytic Functions
The following formula determines the weight given to the newest value.
k = 2/(1+n)
where:
k
Is the newest value.
n
Is an integer greater than one. Increasing n increases the weight assigned to the earlier
observations (or data instances), as compared to the later ones.
The next calculation of the exponential moving average (EMA) value is derived by the following
formula:
This means that the newest value from the data source is multiplied by the factor k and the
current moving average is multiplied by the factor (1-k). These quantities are then summed to
generate the new EMA.
Note: When the data values are exhausted, the last data value in the sort group is used as the
next data value.
where:
display
Keyword
Specifies which values to display for rows of output that represent existing data. Valid
values are:
INPUT_FIELD. This displays the original field values for rows that represent existing
data.
MODEL_DATA. This displays the calculated values for rows that represent existing
data.
Using Functions 87
FORECAST_EXPAVE: Using Single Exponential Smoothing
Note: You can show both types of output for any field by creating two independent
COMPUTE commands in the same request, each with a different display option.
infield
Is any numeric field. It can be the same field as the result field, or a different field. It
cannot be a date-time field or a numeric field with date display options.
interval
Is the increment to add to each sort field value (after the last data point) to create the
next value. This must be a positive integer. To sort in descending order, use the BY
HIGHEST phrase. The result of adding this number to the sort field values is converted
to the same format as the sort field.
For date fields, the minimal component in the format determines how the number is
interpreted. For example, if the format is YMD, MDY, or DMY, an interval value of 2 is
interpreted as meaning two days. If the format is YM, the 2 is interpreted as meaning two
months.
npredict
Is the number of predictions for FORECAST to calculate. It must be an integer greater
than or equal to zero. Zero indicates that you do not want predictions, and is only
supported with a non-recursive FORECAST.
npoint1
For EXPAVE, this number is used to calculate the weights for each component in the
average. This value must be a positive whole number. The weight, k, is calculated by
the following formula:
k=2/(1+npoint1)
88
4. Simplified Analytic Functions
Each average (EXPAVE value) is computed using DOLLARS values where they exist. The
calculation of the moving average begins in the following way:
The first EXPAVE value (801,123.0) is the same as the first DOLLARS value.
The second EXPAVE value (741,731.5) is calculated as follows. Note that because of
rounding and the number of decimal places used, the value derived in this sample
calculation varies slightly from the one displayed in the report output:
n=3 (number used to calculate weights)
Using Functions 89
FORECAST_DOUBLEXP: Using Double Exponential Smoothing
The first equation accounts for the current time period and is a weighted average of the
current data value and the prior average, with an added component (b) that represents the
trend for the previous period. The weight constant is k:
The second equation is the calculated trend value, and is a weighted average of the
difference between the current and previous average and the trend for the previous time
period. b(t) represents the average trend. The weight constant is g:
These two equations are solved to derive the smoothed average. The first smoothed average is
set to the first data value. The first trend component is set to zero. For choosing the two
constants, the best results are usually obtained by minimizing the mean-squared error (MSE)
between the data values and the calculated averages. You may need to use nonlinear
optimization techniques to find the optimal constants.
The equation used for forecasting beyond the data points with double exponential smoothing is
where:
m
Is the number of time periods ahead for the forecast.
FORECAST_DOUBLEXP(display, infield,
interval, npredict, npoint1, npoint2)
90
4. Simplified Analytic Functions
where:
display
Keyword
Specifies which values to display for rows of output that represent existing data. Valid
values are:
INPUT_FIELD. This displays the original field values for rows that represent existing
data.
MODEL_DATA. This displays the calculated values for rows that represent existing
data.
Note: You can show both types of output for any field by creating two independent
COMPUTE commands in the same request, each with a different display option.
infield
Is any numeric field. It can be the same field as the result field, or a different field. It
cannot be a date-time field or a numeric field with date display options.
interval
Is the increment to add to each sort field value (after the last data point) to create the
next value. This must be a positive integer. To sort in descending order, use the BY
HIGHEST phrase. The result of adding this number to the sort field values is converted
to the same format as the sort field.
For date fields, the minimal component in the format determines how the number is
interpreted. For example, if the format is YMD, MDY, or DMY, an interval value of 2 is
interpreted as meaning two days. If the format is YM, the 2 is interpreted as meaning two
months.
npredict
Is the number of predictions for FORECAST to calculate. It must be an integer greater
than or equal to zero. Zero indicates that you do not want predictions, and is only
supported with a non-recursive FORECAST.
npoint1
For DOUBLEXP, this number is used to calculate the weights for each component in
the average. This value must be a positive whole number. The weight, k, is calculated
by the following formula:
k=2/(1+npoint1)
npoint2
For DOUBLEXP, this positive whole number is used to calculate the weights for each
term in the trend. The weight, g, is calculated by the following formula:
Using Functions 91
FORECAST_SEASONAL: Using Triple Exponential Smoothing
g=2/(1+npoint2)
92
4. Simplified Analytic Functions
For triple exponential smoothing you, need to know the number of data points in each time
period (designated as L in the following equations). To account for the seasonality, a seasonal
index is calculated. The data is divided by the prior season index and then used in calculating
the smoothed average.
The first equation accounts for the current time period, and is a weighted average of the
current data value divided by the seasonal factor and the prior average adjusted for the
trend for the previous period. The weight constant is k:
The second equation is the calculated trend value, and is a weighted average of the
difference between the current and previous average and the trend for the previous time
period. b(t) represents the average trend. The weight constant is g:
The third equation is the calculated seasonal index, and is a weighted average of the
current data value divided by the current average and the seasonal index for the previous
season. I(t) represents the average seasonal coefficient. The weight constant is p:
These equations are solved to derive the triple smoothed average. The first smoothed average
is set to the first data value. Initial values for the seasonality factors are calculated based on
the maximum number of full periods of data in the data source, while the initial trend is
calculated based on two periods of data. These values are calculated with the following steps:
1. The initial trend factor is calculated by the following formula:
2. The calculation of the initial seasonality factor is based on the average of the data values
within each period, A(j) (1<=j<=N):
3. Then, the initial periodicity factor is given by the following formula, where N is the number
of full periods available in the data, L is the number of points per period and n is a point
within the period (1<= n <= L):
Using Functions 93
FORECAST_SEASONAL: Using Triple Exponential Smoothing
The three constants must be chosen carefully. The best results are usually obtained by
choosing the constants to minimize the mean-squared error (MSE) between the data values
and the calculated averages. Varying the values of npoint1 and npoint2 affect the results, and
some values may produce a better approximation. To search for a better approximation, you
may want to find values that minimize the MSE.
The equation used to forecast beyond the last data point with triple exponential smoothing is:
forecast(t+m) = (SEASONAL(t) + m * b(t)) / I(t-L+MOD(m/L))
where:
m
Is the number of periods ahead for the forecast.
FORECAST_SEASONAL(display, infield,
interval, npredict, nperiod, npoint1, npoint2, npoint3)
where:
display
Keyword
Specifies which values to display for rows of output that represent existing data. Valid
values are:
INPUT_FIELD. This displays the original field values for rows that represent existing
data.
MODEL_DATA. This displays the calculated values for rows that represent existing
data.
Note: You can show both types of output for any field by creating two independent
COMPUTE commands in the same request, each with a different display option.
infield
Is any numeric field. It can be the same field as the result field, or a different field. It
cannot be a date-time field or a numeric field with date display options.
interval
Is the increment to add to each sort field value (after the last data point) to create the
next value. This must be a positive integer. To sort in descending order, use the BY
HIGHEST phrase. The result of adding this number to the sort field values is converted
to the same format as the sort field.
94
4. Simplified Analytic Functions
For date fields, the minimal component in the format determines how the number is
interpreted. For example, if the format is YMD, MDY, or DMY, an interval value of 2 is
interpreted as meaning two days. If the format is YM, the 2 is interpreted as meaning two
months.
npredict
Is the number of predictions for FORECAST to calculate. It must be an integer greater
than or equal to zero. Zero indicates that you do not want predictions, and is only
supported with a non-recursive FORECAST. For the SEASONAL method, npredict is the
number of periods to calculate. The number of points generated is:
nperiod * npredict
nperiod
For the SEASONAL method, is a positive whole number that specifies the number of
data points in a period.
npoint1
For SEASONAL, this number is used to calculate the weights for each component in
the average. This value must be a positive whole number. The weight, k, is calculated
by the following formula:
k=2/(1+npoint1)
npoint2
For SEASONAL, this positive whole number is used to calculate the weights for each
term in the trend. The weight, g, is calculated by the following formula:
g=2/(1+npoint2)
npoint3
For SEASONAL, this positive whole number is used to calculate the weights for each
term in the seasonal adjustment. The weight, p, is calculated by the following formula:
p=2/(1+npoint3)
Using Functions 95
FORECAST_SEASONAL: Using Triple Exponential Smoothing
In the output, npredict is 3. Therefore, three periods (nine points, nperiod * npredict) are
generated.
96
4. Simplified Analytic Functions
where:
y
Is the dependent variable.
x
Is the independent variable.
m
Is the slope of the line.
b
Is the y-intercept.
FORECAST_LINEAR uses a technique called Ordinary Least Squares to calculate values for m
and b that minimize the sum of the squared differences between the data and the resulting
line.
where:
n
Is the number of data points.
y
Is the data values (dependent variables).
x
Is the sort field values (independent variables).
Trend values, as well as predicted values, are calculated using the regression line equation.
Using Functions 97
FORECAST_LINEAR: Using a Linear Regression Equation
where:
display
Keyword
Specifies which values to display for rows of output that represent existing data. Valid
values are:
INPUT_FIELD. This displays the original field values for rows that represent existing
data.
MODEL_DATA. This displays the calculated values for rows that represent existing
data.
Note: You can show both types of output for any field by creating two independent
COMPUTE commands in the same request, each with a different display option.
infield
Is any numeric field. It can be the same field as the result field, or a different field. It
cannot be a date-time field or a numeric field with date display options.
interval
Is the increment to add to each sort field value (after the last data point) to create the
next value. This must be a positive integer. To sort in descending order, use the BY
HIGHEST phrase. The result of adding this number to the sort field values is converted
to the same format as the sort field.
For date fields, the minimal component in the format determines how the number is
interpreted. For example, if the format is YMD, MDY, or DMY, an interval value of 2 is
interpreted as meaning two days. If the format is YM, the 2 is interpreted as meaning two
months.
npredict
Is the number of predictions for FORECAST to calculate. It must be an integer greater
than or equal to zero. Zero indicates that you do not want predictions, and is only
supported with a non-recursive FORECAST.
98
4. Simplified Analytic Functions
Note:
Three predicted values of FORTOT are calculated. For values outside the range of the data,
new TRANSDATE values are generated by adding the interval value (1) to the prior
TRANSDATE value.
There are no QUANTITY values for the generated FORTOT values.
Each FORTOT value is computed using a regression line, calculated using all of the actual
data values for QUANTITY.
Using Functions 99
PARTITION_AGGR: Creating Rolling Calculations
TRANSDATE is the independent variable (x) and QUANTITY is the dependent variable (y).
The equation is used to calculate QUANTITY FORECAST trend and predicted values.
The following version of the request charts the data values and the regression line.
GRAPH FILE VIDEOTRK
SUM QUANTITY
COMPUTE FORTOT=FORECAST_LINEAR(MODEL_DATA,QUANTITY,1,3);
BY TRANSDATE
ON GRAPH PCHOLD FORMAT JSCHART
ON GRAPH SET LOOKGRAPH VLINE
END
100
4. Simplified Analytic Functions
By default, the field values used in the calculations are the summed values of a measure in
the request. Certain prefix operators can be used to add a column to the internal matrix and
use that column in the rolling calculations. The rolling calculation can be SUM, AVE, CNT, MIN,
MAX, FST, or LST.
PARTITION_AGGR([prefix.]measure,reset_key,lower,upper,operation)
where:
prefix.
Defines an aggregation operator to apply to the measure before using it in the rolling
calculation. Valid operators are:
SUM. which calculates the sum of the measure field values. SUM is the default
operator.
Note: The operators PCT., RPCT., TOT., MDN., and DST. are not supported. COMPUTEs
that reference those unsupported operators are also not supported.
measure
Is the measure field to be aggregated. It can be a real field in the request or a calculated
value generated with the COMPUTE command, as long as the COMPUTE does not
reference an unsupported prefix operator.
reset_key
Identifies the point at which the calculation restarts. Valid values are:
PRESET, which uses the value of the PARTITION_ON parameter, as described in How to
Specify the Partition Size for Simplified Statistical Functions on page 589.
The sort field may use BY HIGHEST to indicate a HIGH-TO-LOW sort. ACROSS COLUMNS
AND is supported. BY ROWS OVER and FOR are not supported.
lower
Identifies the starting point for the rolling calculation. Valid values are:
n, -n, which starts the calculation n rows forward or back from the current row.
B, which starts the calculation at the beginning of the current sort break (the first line
with the same sort field value as the current line).
upper
Identifies the ending point of the rolling calculation. The lower row value must precede
upper row value.
C, which ends the rolling calculation at the current row in the internal matrix.
n, -n, which ends the calculation n rows forward or back from the current row.
E, which ends the rolling calculation at the end of the sort break (the last line with the
same sort value as the current row.)
Note: The values used in the calculations depend on the sort sequence (ascending or
descending) specified in the request. Be aware that displaying a date or time dimension in
descending order may produce different results than those you may expect.
operation
Specifies the rolling calculation used on the values in the internal matrix. Supported
operations are:
MEDIAN.
102
4. Simplified Analytic Functions
STDP, which returns the population standard deviation in the partition. Requires using
the verb PRINT to avoid duplicate aggregation.
STDS, which returns the sample standard deviation in the partition. Requires using the
verb PRINT to avoid duplicate aggregation.
The calculation is performed prior to any WHERE TOTAL tests, but after any WHERE_GROUPED
tests.
The output is shown in the following image. Within each quarter, the first average is just the
value from Q1, as going back 1 would cross a boundary. The second average is calculated
using the first two rows within that quarter, and the third average is calculated using rows 2
and 3 within the quarter.
The following changes the rolling average to start from the beginning of the sort break.
COMPUTE AVE1/D12.2M = PARTITION_AGGR(COGS_US, TIME_QTR ,B, C, AVE);
104
4. Simplified Analytic Functions
The output is shown in the following image. Within each quarter, the first average is just the
value from Q1, as going back would cross a boundary. The second average is calculated using
the first two rows within that quarter, and the third average is calculated using rows 1 through
3 within the quarter.
The output is shown in the following image. The rolling average keeps adding the next row to
the average with no sort field break.
Using the WITHIN phrase for a sum is the same as computing PARTITION_AGGR on the
WITHIN sort field from B (beginning of sort break) to E (end of sort break) using SUM, as in
the following example.
106
4. Simplified Analytic Functions
With other types of calculations, the results are not the same. For example, the following
request calculates the average within quarter using the WITHIN phrase and the average
within quarter using PARTITION_AGGR.
TABLE FILE WF_RETAIL_LITE
SUM COGS_US AS Cost
CNT.COGS_US AS Count AVE.COGS_US WITHIN TIME_QTR AS 'Ave Within'
COMPUTE PART_WITHIN_QTR/D12.2M = PARTITION_AGGR(COGS_US, TIME_QTR, B, E,
AVE);
BY BUSINESS_REGION AS Region
BY TIME_QTR
ON TIME_QTR SUBTOTAL COGS_US CNT.COGS_US
BY TIME_MTH
WHERE BUSINESS_REGION EQ 'North America'
ON TABLE SET PAGE NOPAGE
ON TABLE SET STYLE *
GRID=OFF,$
ENDSTYLE
END
108
4. Simplified Analytic Functions
The output is shown in the following image. The average using the WITHIN phrase divides
the total cost for the quarter by the total count of instances for the quarter (for example,
$76,829,105.00/ 252850 = $303.85), while PARTITION_AGGR divides the total cost for
the quarter by the number of report rows in the quarter (for example, $76,829,105.00/3 =
$25,609,701.67).
If you use PARTITION_AGGR to perform operations for specific time periods using an offset,
for example, an operation on the quarters for different years, you must make sure that
every quarter is represented. If some quarters are missing for some years, the offset will
not access the correct data. In this case, generate a HOLD file that has every quarter
represented for every year (you can use BY QUARTER ROWS OVER 1 OVER 2 OVER 3 OVER
4) and use PARTITION_AGGR on the HOLD file.
Syntax: How to Retrieve Prior or Subsequent Field Values for Use in a Calculation
where:
prefix
Is optional. If used, it can be one of the following aggregation operators:
AVE. Average
MAX. Maximum
MIN. Minimum
CNT. Count
SUM. Sum
field
Is the field whose value is to be retrieved.
reset_key
Identifies the point at which the retrieval break restarts. Valid values are:
PRESET, which uses the value of the PARTITION_ON parameter, as described in How to
Specify the Partition Size for Simplified Statistical Functions on page 589.
The sort field may use BY HIGHEST to indicate a HIGH-TO-LOW sort. ACROSS COLUMNS
AND is supported. BY ROWS OVER and FOR are not supported.
Note: The values used in the retrieval depend on the sort sequence (ascending or
descending) specified in the request. Be aware that displaying a date or time dimension in
descending order may produce different results than those you may expect.
110
4. Simplified Analytic Functions
offset
Is the integer number of records to go forward (for a positive offset) or backward (for a
negative offset) to retrieve the value.
If the offset is prior to the partition boundary sort value, the return will be the default value
for the field. The calculation is performed prior to any WHERE TOTAL tests, but after
WHERE_GROUPED tests.
The output is shown in the following image. The first value within each sort break is zero
because there is no prior record to retrieve.
The following request retrieves the average cost of goods from two records prior to the current
record within the PRODUCT_CATEGORY sort field.
TABLE FILE WF_RETAIL_LITE
SUM COGS_US AVE.COGS_US AS Average
COMPUTE PartitionAve/D12.2M=PARTITION_REF(AVE.COGS_US, PRODUCT_CATEGORY,
-2);
BY PRODUCT_CATEGORY
BY PRODUCT_SUBCATEG
ON TABLE SET PAGE NOPAGE
ON TABLE SET STYLE *
GRID=OFF,$
ENDSTYLE
END
112
4. Simplified Analytic Functions
Replacing the function call with the following syntax changes the partition boundary to TABLE.
COMPUTE PartitionAve/D12.2M=PARTITION_REF(AVE.COGS_US, TABLE, -2);
INCREASE: Calculating the Difference Between the Current and a Prior Value of a Field
Given an aggregated input field and a negative offset, INCREASE calculates the difference
between the value in the current row of the report output and one or more prior rows, within a
sort break or the entire table. The reset point for the calculation is determined by the value of
the PARTITION_ON parameter described in How to Specify the Partition Size for Simplified
Statistical Functions on page 589.
114
4. Simplified Analytic Functions
Note: The values used in the calculations depend on the sort sequence (ascending or
descending) specified in the request. Be aware that displaying a date or time dimension in
descending order may produce different results than those you may expect.
Syntax: How to Calculate the Difference Between the Current and a Prior Value of a Field
INCREASE([prefix.]field, offset)
where:
prefix
Is one of the following optional aggregation operators to apply to the field before using it in
the calculation:
SUM. which calculates the sum of the field values. SUM is the default value.
Is a negative number indicating the number of rows back from the current row to use for
the calculation.
Example: Calculating the Increase Between the Current and a Prior Value of a Field
The following request uses the default value of SET PARTITION_ON (PENULTIMATE) to calculate
the increase within the PRODUCT_CATEGORY sort field between the current row and the
previous row.
SET PARTITION_ON=PENULTIMATE
TABLE FILE wf_retail_lite
SUM QUANTITY_SOLD
COMPUTE INC = INCREASE(QUANTITY_SOLD,-1);
BY PRODUCT_CATEGORY
BY PRODUCT_SUBCATEG
ON TABLE SET PAGE NOLEAD
ON TABLE SET STYLE *
GRID=OFF,$
ENDSTYLE
END
116
4. Simplified Analytic Functions
The output is shown in the following image. The first value for INC is the value in the
Accessories category for Quantity Sold, as there is no prior value. The second value for INC is
the difference between the values for Headphones and Charger, the third is the difference
between Universal Remote Controls and Headphones. Then, the calculations start over for
Camcorder, which is the reset point.
PCT_INCREASE: Calculating the Percentage Difference Between the Current and a Prior
Value of a Field
Given an aggregated input field and a negative offset, PCT_INCREASE calculates the
percentage difference between the value in the current row of the report output and one or
more prior rows, within a sort break or the entire table. The reset point for the calculation is
determined by the value of the PARTITION_ON parameter described in How to Specify the
Partition Size for Simplified Statistical Functions on page 589.
Note: The values used in the calculations depend on the sort sequence (ascending or
descending) specified in the request. Be aware that displaying a date or time dimension in
descending order may produce different results than those you may expect.
Syntax: How to Calculate the Percentage Difference Between the Current and a Prior Value of
a Field
PCT_INCREASE([prefix.]field, offset)
where:
prefix
Is one of the following optional aggregation operators to apply to the field before using it in
the calculation:
SUM. which calculates the sum of the field values. SUM is the default value.
118
4. Simplified Analytic Functions
offset
Numeric
Is a negative number indicating the number of rows back from the current row to use for
the calculation.
Example: PCT_INCREASE: Calculating the Percent Increase Between the Current and a Prior
Value of a Field
The following request uses the default value of SET PARTITION_ON (PENULTIMATE) to calculate
the percent increase within the PRODUCT_CATEGORY sort field between the current row and
the previous row.
SET PARTITION_ON=PENULTIMATE
TABLE FILE wf_retail_lite
SUM QUANTITY_SOLD
COMPUTE PCTINC/D8.2p = PCT_INCREASE(QUANTITY_SOLD,-1);
BY PRODUCT_CATEGORY
BY PRODUCT_SUBCATEG
ON TABLE SET PAGE NOLEAD
ON TABLE SET STYLE *
GRID=OFF,$
ENDSTYLE
END
The output is shown in the following image. The first value for PCTINC is zero percent, as there
is no prior value. The second value for PCTINC is the percent difference between the values for
Headphones and Charger, the third is the percent difference between Universal Remote
Controls and Headphones. Then, the calculations start over for Camcorder, which is the reset
point.
120
4. Simplified Analytic Functions
Note: The values used in the retrieval depend on the sort sequence (ascending or descending)
specified in the request. Be aware that displaying a date or time dimension in descending
order may produce different results than those you may expect.
PREVIOUS([prefix.]field, offset)
where:
prefix
Is one of the following optional aggregation operators to apply to the field before using it in
the calculation:
SUM. which calculates the sum of the field values. SUM is the default value.
Is a negative number indicating the number of rows back from the current row to use for
the retrieval.
122
4. Simplified Analytic Functions
The output is shown in the following image. The value of PREV in the first two rows is zero, as
there are no prior rows for retrieval. From then on, each value of PREV is from the
QUANTITY_SOLD value from two rows prior, with no reset points.
Syntax: How to Calculate Running Average Between the Current and a Prior Value of a Field
where:
field
Numeric
PRESET, which uses the value of the PARTITION_ON parameter, as described in How to
Specify the Partition Size for Simplified Statistical Functions on page 589.
Note: The values used in the calculations depend on the sort sequence (ascending or
descending) specified in the request. Be aware that displaying a date or time dimension in
descending order may produce different results than those you may expect.
lower
Is the starting point in the partition for the running average. Valid values are:
A negative number, which identifies the offset from the current row.
124
4. Simplified Analytic Functions
The output is shown in the following image. The first value for RAVE is the value in the
Accessories category for Quantity Sold, as there is no prior value. The second value for RAVE
is the average of the values for Headphones and Charger, the third is the average of the
values for Headphones, Charger, and Universal Remote Controls. Then, the calculations start
over for Camcorder, which is the reset point.
Syntax: How to Calculate Running Maximum Between the Current and a Prior Value of a Field
where:
field
Numeric or an alphanumeric field that contains all numeric digits.
PRESET, which uses the value of the PARTITION_ON parameter, as described in How to
Specify the Partition Size for Simplified Statistical Functions on page 589.
Note: The values used in the calculations depend on the sort sequence (ascending or
descending) specified in the request. Be aware that displaying a date or time dimension in
descending order may produce different results than those you may expect.
lower
Is the starting point in the partition for the running maximum. Valid values are:
A negative number, which identifies the offset from the current row.
126
4. Simplified Analytic Functions
The output is shown in the following image. The first value for RMAX is the value in the
Accessories category for Quantity Sold, as there is no prior value. The second value for RMAX
is the value for Headphones, as that value is larger. The third value for RMAX is still the value
for Headphones, as that value is larger than the Quantity Sold value in the third row. Since the
maximum value in the table occurs for Blu Ray, that value is repeated on all future rows, as
there is no reset point.
128
4. Simplified Analytic Functions
Syntax: How to Calculate Running Minimum Between the Current and a Prior Value of a Field
where:
field
Numeric or an alphanumeric field that contains all numeric digits.
PRESET, which uses the value of the PARTITION_ON parameter, as described in How to
Specify the Partition Size for Simplified Statistical Functions on page 589.
Note: The values used in the calculations depend on the sort sequence (ascending or
descending) specified in the request. Be aware that displaying a date or time dimension in
descending order may produce different results than those you may expect.
lower
Is the starting point in the partition for the running minimum. Valid values are:
A negative number, which identifies the offset from the current row.
SET PARTITION_ON=PENULTIMATE
TABLE FILE wf_retail_lite
SUM QUANTITY_SOLD
COMPUTE RMIN = RUNNING_MIN(QUANTITY_SOLD,PRESET,B);
BY PRODUCT_CATEGORY
BY PRODUCT_SUBCATEG
ON TABLE SET PAGE NOLEAD
ON TABLE SET STYLE *
GRID=OFF,$
ENDSTYLE
END
130
4. Simplified Analytic Functions
The output is shown in the following image. The first value for RMIN is the value in the
Accessories category for Quantity Sold, as there is no prior value. The second value for RMIN
is the value from the first row again (Charger), as that is smaller than the value in the second
row. The third is the same again, as it is still the smallest. Then, the calculations start over for
Camcorder, which is the reset point.
Syntax: How to Calculate Running Sum Between the Current and a Prior Value of a Field
where:
field
Numeric
PRESET, which uses the value of the PARTITION_ON parameter, as described in How to
Specify the Partition Size for Simplified Statistical Functions on page 589.
Note: The values used in the calculations depend on the sort sequence (ascending or
descending) specified in the request. Be aware that displaying a date or time dimension in
descending order may produce different results than those you may expect.
lower
Is the starting point in the partition for the running sum. Valid values are:
A negative number, which identifies the offset from the current row.
132
4. Simplified Analytic Functions
The output is shown in the following image. The first value for RSUM is the value in the
Accessories category for Quantity Sold, as there is no prior value. The second value for RSUM
is the sum of the values for Headphones and Charger, the third is the sum of the values for
Headphones and Universal Remote Controls. Then, the calculations start over for Camcorder,
which is the reset point.
134
Chapter 5 Simplified Character Functions
Simplified character functions have streamlined parameter lists, similar to those used by
SQL functions. In some cases, these simplified functions provide slightly different
functionality than previous versions of similar functions.
The simplified functions do not have an output argument. Each function returns a value
that has a specific data type.
When used in a request against a relational data source, these functions are optimized
(passed to the RDBMS for processing).
Note: The simplified character functions are not supported in Maintain Data.
In this chapter:
LTRIM: Removing Blanks From the Left TRIM_: Removing a Leading Character,
End of a String Trailing Character, or Both From a String
CHAR_LENGTH(string)
where:
string
Alphanumeric
136
5. Simplified Character Functions
CONCAT(string1, string2)
where:
string2
Alphanumeric
Is a string to be concatenated.
string1
Alphanumeric
Is a string to be concatenated.
138
5. Simplified Character Functions
DIFFERENCE(chrexp1, chrexp2)
where:
chrexp1, chrexp2
Alphanumeric
Zero (0) represents the least similarity. For SOUNDEX, 4 represents the most similarity,
and for METAPHONE, 16 represents the most similarity.
140
5. Simplified Character Functions
The output is shown in the following image. Note that the names JOANN and JOHN have the
highest scores for matching with JOHN, and that MARCIA, MICHAEL, and MARTHA have the
highest scores for matching with MARY.
DIGITS(number,length)
where:
number
Integer
Is the length of the returned character string. If length is longer than the number of digits
in the number being converted, the returned value is padded on the left with zeros. If
length is shorter than the number of digits in the number being converted, the returned
value is truncated on the left.
142
5. Simplified Character Functions
where:
string
Alphanumeric
Is the input string from which the token will be extracted. This can be an alphanumeric
field or constant.
delimiter_string
Alphanumeric constant
Is a string that contains the list of delimiter characters. For example, '; ,' contains three
delimiter characters, semi-colon, blank space, and comma.
occurrence
Integer constant
Is a positive integer that specifies the token to be extracted. A negative integer will be
accepted in the syntax, but will not extract a token. The value zero (0) is not supported.
144
5. Simplified Character Functions
The output is shown in the following image. The first token was extracted using the comma (,)
as the delimiter. The fourth token was extracted using the slash (/) as the delimiter.
INITCAP(input_string)
where:
input_string
Alphanumeric
LAST_NONBLANK: Retrieving the Last Field Value That is Neither Blank nor Missing
LAST_NONBLANK retrieves the last field value that is neither blank nor missing. If all previous
values are either blank or missing, LAST_NONBLANK returns a missing value.
Syntax: How to Return the Last Value That is Neither Blank nor Missing
LAST_NONBLANK(field)
146
5. Simplified Character Functions
where:
field
Is the field name whose last non-blank value is to be retrieved. If the current value is not
blank or missing, the current value is returned.
The following request displays the FIELD_1 values and computes the last non-blank value for
each FIELD_1 value.
TABLE FILE baseapp/INPUT1
PRINT FIELD_1 AS Input
COMPUTE
Last_NonBlank/A1 MISSING ON = LAST_NONBLANK(FIELD_1);
ON TABLE SET PAGE NOLEAD
ON TABLE SET STYLE *
GRID=OFF,$
ENDSTYLE
END
LEFT(chr_exp, int_exp)
where:
chr_exp
Alphanumeric or an expression that can be converted to variable-length alphanumeric.
148
5. Simplified Character Functions
150
5. Simplified Character Functions
LOWER(string)
where:
string
Alphanumeric
The returned string is the same data type and length as the source string.
LAST_NAME LOWER_NAME
--------- ----------
STEVENS stevens
SMITH smith
JONES jones
SMITH smith
BANNING banning
IRVING irving
ROMANS romans
MCCOY mccoy
BLACKWOOD blackwood
MCKNIGHT mcknight
GREENSPAN greenspan
CROSS cross
where:
string
Fixed length alphanumeric
152
5. Simplified Character Functions
If the output is specified as shorter than the original input, the original data will be
truncated, leaving only the padding characters. The output length can be specified as a
positive integer or an unquoted &variable (indicating a numeric).
LTRIM(string)
where:
string
Alphanumeric
The data type of the returned string is AnV, with the same maximum length as the source
string.
154
5. Simplified Character Functions
where:
src
Alphanumeric
Is the number of characters to replace in the source string with the entire insertion string.
PATTERNS: Returning a Pattern That Represents the Structure of the Input String
PATTERNS returns a string that represents the structure of the input argument. The returned
pattern includes the following characters:
A is returned for any position in the input string that has an uppercase letter.
a is returned for any position in the input string that has a lowercase letter.
9 is returned for any position in the input string that has a digit.
Note that special characters (for example, +-/=%) are returned exactly as they were in the input
string.
Syntax: How to Return a String That Represents the Pattern Profile of the Input Argument
PATTERNS(string)
where:
string
Alphanumeric
156
5. Simplified Character Functions
The partial output is shown in the following image. Note that the special characters (#-,) in an
address are represented in the pattern as is.
158
5. Simplified Character Functions
POSITION(pattern, string)
where:
pattern
Alphanumeric
Is the substring whose position you want to locate. The string can be as short as a single
character, including a single blank.
string
Alphanumeric
where:
search
Alphanumeric
160
5. Simplified Character Functions
Note: You can search online for information about the symbols used to create a regular
expression pattern. For example, Wikipedia has a good introduction at:
https://en.wikipedia.org/wiki/Regular_expression
[] represents any one character in the set listed within the brackets
[^] represents any one character not in the set listed within the brackets
For example, the regular expression '^Ste(v|ph)en$' matches values starting with Ste followed
by either ph or v, and ending with en.
If you are using the Unicode code page 65002, the meta-characters will be interpreted
correctly. In this environment, you need to be sure the files you are referencing, such as
FOCUS data sources, have been built using this code page.
If you are not using a Unicode code page, you can use the CHAR function to return the correct
meta-characters, based on the decimal code for the EBCDIC character. For example, to insert:
Create a Dialogue Manager variable that contains the pattern. To insert the meta-characters,
use the CHAR function, and then use that variable as the argument in the regular expression
function. For example, to generate the regular expression '[AEIOUaeiou]', which matches all
uppercase and lowercase vowels, issue a -SET command similar to the following, which
creates a variable named &VCWSTRING:
-SET &VCWSTRING=CHAR(173) || 'AEIOUaeiou' || CHAR(189);
Then use the &VCWSTRING variable as the regular expression argument in the function call.
For example:
VowelCnt/I5=REGEXP_COUNT(PRODUCT, '&VCWSTRING');
A regular expression is a sequence of special characters and literal characters that you can
combine to form a search pattern.
162
5. Simplified Character Functions
For a basic summary, see the section Summary of Regular Expressions in Chapter 2, Security,
of the Server Administration manual.
REGEX(string, regular_expression)
where:
string
Alphanumeric
Is a regular expression, enclosed in single quotation marks, constructed using literals and
meta-characters. The following meta-characters are supported
[] represents any one character in the set listed within the brackets
[^] represents any one character not in the set listed within the brackets
For example, the regular expression '^Ste(v|ph)en$' matches values starting with Ste
followed by either ph or v, and ending with en.
The following version of the request runs on z/OS. The variable ®1 contains the regular
expression string with the circumflex character (^) inserted as CHAR(95), the left bracket
character ([) inserted as CHAR(173), and the right bracket character (]) inserted as CHAR(189).
The other meta-characters are interpreted correctly.
164
5. Simplified Character Functions
REGEXP_COUNT(string, pattern)
where:
string
Alphanumeric
Is a regular expression, enclosed in single quotation marks, constructed using literals and
meta-characters. The following meta-characters are supported
[] represents any one character in the set listed within the brackets
[^] represents any one character not in the set listed within the brackets
$, which searches for a specified expression that occurs at the end of a string.
^, which searches for a specified expression that occurs at the beginning of a string.
\s*, which matches any number of whitespace characters, such as blank characters.
In the following request, REG1 is the number of occurrences of the expression 'iscotti', with
any number of following whitespace characters, that occur the end of the PRODUCT field. REG2
is the number of occurrences of the characters 'T' and 't' in the PRODUCT field.
TABLE FILE GGSALES
SUM DOLLARS AND COMPUTE
REG1/I5 = REGEXP_COUNT(PRODUCT, 'iscotti\s*$');
REG2/I5 = REGEXP_COUNT(PRODUCT, '[T,t]');
BY PRODUCT
ON TABLE SET PAGE NOLEAD
ON TABLE SET STYLE *
GRID=OFF,$
ENDSTYLE
END
166
5. Simplified Character Functions
Note:
Brackets are used to enclose a list of characters that will match the regular expression
pattern.
When the circumflex character (^) prefaces the list of characters within the brackets, the
regular expression matches any character not on the list.
The following version of the request uses REGEXP_COUNT to return the number of vowels and
number of consonants in each product name, on z/OS. The -SET commands create the regular
expressions by using the CHAR function to insert the meta-characters into the expressions.
VowelCnt is the count of vowels, and ConsonantCnt is the count of non-vowels.
-SET &VCWSTRING=CHAR(173) || 'AEIOUaeiou' || CHAR(189);
-SET &CONSTRING=CHAR(173) || CHAR(95) || 'AEIOU aeiou' || CHAR(189);
DEFINE FILE GGSALES
VowelCnt/I5=REGEXP_COUNT(PRODUCT, '&VCWSTRING');
ConsonantCnt/I5=REGEXP_COUNT(PRODUCT,'&CONSTRING');
END
TABLE FILE GGSALES
SUM MAX.VowelCnt AS 'Vowels'
MAX.ConsonantCnt AS 'Consonants'
BY PRODUCT
ON TABLE SET PAGE NOLEAD
END
168
5. Simplified Character Functions
REGEXP_INSTR(string, pattern)
where:
string
Alphanumeric
Is a regular expression, enclosed in single quotation marks, constructed using literals and
meta-characters. The following meta-characters are supported
[] represents any one character in the set listed within the brackets
[^] represents any one character not in the set listed within the brackets
$, which searches for a specified expression that occurs at the end of a string.
^, which searches for a specified expression that occurs at the beginning of a string.
\s*, which matches any number of whitespace characters, such as blank characters.
In the following request, REG1 is the position of the expression 'iscotti', with any number of
following whitespace characters, that occur the end of the PRODUCT field value. REG2 is the
position of the characters 'B' ,C, or 'S' that occur at the beginning of the PRODUCT field value.
TABLE FILE GGSALES
SUM DOLLARS AND COMPUTE
REG1/I5 = REGEXP_INSTR(PRODUCT, 'iscotti\s*$');
REG2/I5 = REGEXP_INSTR(PRODUCT, '^[B,C,S]');
BY PRODUCT
ON TABLE SET PAGE NOLEAD
ON TABLE SET STYLE *
GRID=OFF,$
ENDSTYLE
END
170
5. Simplified Character Functions
The following version of the request runs on z/OS. The first regular expression can be input
directly because the characters used are interpreted correctly. For the second regular
expression, a variable is created to contain the pattern. This variable is then used in the
function call.
where:
string
Alphanumeric
Is a regular expression, enclosed in single quotation marks, constructed using literals and
meta-characters. The following meta-characters are supported
[] represents any one character in the set listed within the brackets
[^] represents any one character not in the set listed within the brackets
172
5. Simplified Character Functions
^, which searches for a specified expression that occurs at the beginning of a string.
In the following request REG1 replaces the string 'North' at the beginning of the REGION field
value with the string 'South', and REG2 replaces the string 'Mid' at the beginning of the
REGION field value with a null string.
TABLE FILE GGSALES
SUM DOLLARS NOPRINT AND COMPUTE
REG1/A25 = REGEXP_REPLACE(REGION, '^North', 'South');
REG2/A25 = REGEXP_REPLACE(REGION, '^Mid', '');
BY REGION
ON TABLE SET PAGE NOLEAD
ON TABLE SET STYLE *
GRID=OFF,$
ENDSTYLE
END
The following version of the request runs on z/OS. The regular expression string is created in a
variable using a -SET command. The circumflex meta-character (^) is inserted as CHAR(95).
-SET ®STRING1= CHAR(95) || 'North' ;
-SET ®STRING2= CHAR(95) || 'Mid' ;
TABLE FILE GGSALES
SUM DOLLARS NOPRINT AND COMPUTE
REG1/A25 = REGEXP_REPLACE(REGION, '®STRING1', 'South');
REG2/A25 = REGEXP_REPLACE(REGION, '®STRING2', '');
BY REGION
ON TABLE SET PAGE NOLEAD
ON TABLE SET STYLE *
GRID=OFF,$
ENDSTYLE
END
REGEXP_SUBSTR(string, pattern)
where:
string
Alphanumeric
Is a regular expression, enclosed in single quotation marks, constructed using literals and
meta-characters. The following meta-characters are supported
[] represents any one character in the set listed within the brackets
[^] represents any one character not in the set listed within the brackets
174
5. Simplified Character Functions
In the following request, REG1 contains the first instance of a string within the REGION field
value that starts with an uppercase letter, followed by any number of lowercase letters,
followed by the characters 'west'. REG2 contains the first instance of a string within the
REGION field value that starts with an uppercase letter, followed by any number of lowercase
letters, followed by the characters 'east'.
TABLE FILE GGSALES
SUM DOLLARS NOPRINT AND COMPUTE
REG1/A25 = REGEXP_SUBSTR(REGION, '[A-Z][a-z]*west');
REG2/A25 = REGEXP_SUBSTR(REGION, '[A-Z][a-z]*east');
BY REGION
ON TABLE SET PAGE NOLEAD
ON TABLE SET STYLE *
GRID=OFF,$
ENDSTYLE
END
The following version of the request runs on z/OS, where the regular expression is generated
as a variable, using the CHAR function to insert the meta-characters. Note that the asterisk
meta-character (*) needs to be represented as CHAR(92).
-SET ®1=CHAR(173) || 'A-Z' || CHAR(189) || CHAR(173) || 'a-z'
- || CHAR(189) || CHAR(92) || 'west' ;
-SET ®2=CHAR(173) || 'A-Z' || CHAR(189) || CHAR(173) || 'a-z'
- || CHAR(189) || '*east';
TABLE FILE GGSALES
SUM DOLLARS NOPRINT AND COMPUTE
REG1/A25 = REGEXP_SUBSTR(REGION,'®1');
REG2/A25 = REGEXP_SUBSTR(REGION,'®2');
BY REGION
ON TABLE SET PAGE NOLEAD
ON TABLE SET STYLE *
GRID=OFF,$
ENDSTYLE
END
REPEAT(source_str, number)
where:
source_str
Alphanumeric
Is the source string to be repeated. If source_str is a field, the entire field, including
blanks, will be repeated.
number
Numeric
176
5. Simplified Character Functions
where:
input_string
Alphanumeric or text (An, AnV, TX)
Is the replacement string to be substituted for the search string. It can be a null string ('').
178
5. Simplified Character Functions
RIGHT(chr_exp, int_exp)
where:
chr_exp
Alphanumeric or an expression that can be converted to variable-length alphanumeric.
180
5. Simplified Character Functions
where:
string
Alphanumeric
182
5. Simplified Character Functions
RTRIM(string)
where:
string
Alphanumeric
The data type of the returned string is AnV, with the same maximum length as the source
string.
On the output, the slashes show that the trailing blanks in the DIRECTOR field were removed in
the TRIMDIR field:
DIRSLASH TRIMDIR
-------- -------
ABRAHAMS J. / ABRAHAMS J./
BROOKS R. / BROOKS R./
BROOKS J.L. / BROOKS J.L./
Note: To retain the spaces in HTML report output, the SHOWBLANKS parameter must be set to
ON.
SPACE(count)
where:
count
Numeric
184
5. Simplified Character Functions
SPLIT(element, string)
where:
element
Can be one of the following keywords:
NAME_FIRST. Is the first token (group of characters) in the string. Tokens are delimited
by blanks.
NAME_LAST. Is the last token (group of characters) in the string. Tokens are delimited
by blanks.
string
Alphanumeric
186
5. Simplified Character Functions
where:
string
Alphanumeric
Is the string from which to extract the substring. It can be a field, a literal in single
quotation marks (‘), or a variable.
position
Positive Integer
Is the limit for the length of the substring. The ending position of the substring is
calculated as position + length - 1. If the calculated position beyond the end of the source
string, the position of the last character of string becomes the ending position.
where:
string
Fixed length alphanumeric
188
5. Simplified Character Functions
190
5. Simplified Character Functions
Note:
Leading and trailing blanks count as characters. If the character you want to remove is
preceded (for leading) or followed (for trailing) by a blank, the character will not be removed.
Alphanumeric fields that are longer than the number of characters stored within them are
padded with trailing blanks.
The function will be optimized when run against a relational DBMS that supports trimming
the character and location specified.
Syntax: How to Remove a Leading Character, Trailing Character, or Both From a String
where:
where
Keyword
Is a single character, enclosed in single quotation marks ('), whose occurrences are to be
removed from string. For example, the character can be a single blank (‘ ‘).
string
Alphanumeric
The partial output shows that the trimmed DIRECTOR field still has the trailing periods because
the period is not the last character in the field. In the trimmed DIRECTORV field, the trailing
periods have been removed:
192
5. Simplified Character Functions
UPPER(string)
where:
string
Alphanumeric
The returned string is the same data type and length as the source string.
194
Chapter 6 Character Functions
Character functions manipulate alphanumeric fields and character strings.
In this chapter:
For many functions, the output argument can be supplied either as a field name or as a format
enclosed in single quotation marks. However, if a function is called from a Dialogue Manager
command, this argument must always be supplied as a format, and if a function is called from
a Maintain Data procedure, this argument must always be supplied as a field name. For
detailed information about calling a function and supplying arguments, see Accessing and
Calling a Function on page 59.
The ARGLEN function measures the length of a character string within a field, excluding trailing
spaces. The field format in a Master File specifies the length of a field, including trailing
spaces.
In Dialogue Manager, you can measure the length of a supplied character string using
the .LENGTH suffix.
where:
length
Integer
Is the length of the field containing the character string, or a field that contains the length.
source_string
Alphanumeric
196
6. Character Functions
output
Integer
Is the field that contains the result, or the format of the output value enclosed in single
quotation marks.
LAST_NAME NAME_LEN
--------- --------
SMITH 5
JONES 5
MCCOY 5
BLACKWOOD 9
GREENSPAN 9
CROSS 5
The ASIS function distinguishes between a space and a zero in Dialogue Manager. It
differentiates between a numeric string, a constant or variable defined as a numeric string
(number within single quotation marks), and a field defined simply as numeric. ASIS forces a
variable to be evaluated as it is entered rather than be converted to a number. It is used in
Dialogue Manager equality expressions only.
ASIS(argument)
where:
argument
Alphanumeric
Is the value to be evaluated. Supply the actual value, the name of a field that contains the
value, or an expression that returns the value. An expression can call a function.
If you specify an alphanumeric literal, enclose it in single quotation marks. If you specify
an expression, use parentheses, as needed, to ensure the correct order of evaluation.
198
6. Character Functions
If the Dialogue Manager variable '.' is used in a mathematical expression, its value will be
treated as a number. For example, in the following request, &DMVAR1 is used in an
arithmetic expression and is evaluated as zero (0).
-SET &DMVAR1='.';
-SET &DMVAR2=10 + &DMVAR1;
-TYPE DMVAR2 = &DMVAR2
DMVAR2 = 10
If the Dialogue Manager variable value '.' is used in an IF test and is compared to the
values ' ', '0', or '.', the result will be TRUE even if ASIS is used, as shown in the following
example. The following IF tests all evaluate to TRUE.
-SET &DMVAR1='.';
-SET &DMVAR2=IF &DMVAR1 EQ ' ' THEN 'TRUE' ELSE 'FALSE';
-SET &DMVAR3=IF &DMVAR1 EQ '.' THEN 'TRUE' ELSE 'FALSE';
-SET &DMVAR4=IF &DMVAR1 EQ '0' THEN 'TRUE' ELSE 'FALSE';
If the Dialogue Manager variable is used with ASIS, the result of the ASIS function will be
always be considered alphanumeric and will distinguish between the space (‘ ‘), zero (‘0’),
or period (‘.’), as in the following example. The following IF tests all evaluate to TRUE.
Comparing ASIS('0') to ' ' and ASIS(' ') to '0' always evaluates to FALSE.
The BITSON function evaluates an individual bit within a character string to determine whether
it is on or off. If the bit is on, BITSON returns a value of 1. If the bit is off, it returns a value of
0. This function is useful in interpreting multi-punch data, where each punch conveys an item
of information.
where:
bitnumber
Integer
Is the number of the bit to be evaluated, counted from the left-most bit in the character
string.
source_string
Alphanumeric
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
200
6. Character Functions
The BITVAL function evaluates a string of bits within a character string. The bit string can be
any group of bits within the character string and can cross byte and word boundaries. The
function evaluates the subset of bits in the string as an integer value.
Between 1 and 31 (the recommended range), the returned value is a zero or positive
number representing the bits specified, extended with high-order zeroes for a total of 32
bits.
Exactly 32, the returned value is the positive, zero, or the complement value of negative
two, of the specified 32 bits.
Greater than 32 (33 or more), the returned value is the positive, zero, or the complement
value of negative two, of the rightmost 32 bits specified.
where:
source_string
Alphanumeric
Is the number of the first bit in the bit string, counting from the left-most bit in the
character string. If this argument is less than or equal to 0, the function returns a value of
zero.
number
Integer
Is the number of bits in the subset of bits. If this argument is less than or equal to 0, the
function returns a value of zero.
output
Integer
Is the name of the field that contains the binary integer equivalent, or the format of the
output value enclosed in single quotation marks.
The BYTVAL function translates a character to the ASCII, EBCDIC, or Unicode decimal value
that represents it, depending on the operating system.
BYTVAL(character, output)
where:
character
Alphanumeric
Is the character to be translated. You can specify a field or variable that contains the
character, or the character itself enclosed in single quotation marks. If you supply more
than one character, the function evaluates the first.
202
6. Character Functions
output
Integer
Is the name of the field that contains the corresponding decimal value, or the format of the
output value enclosed in single quotation marks.
Assume the value entered for &CHAR is an exclamation point (!). The output is:
THE EQUIVALENT VALUE IS 33
The CHKFMT function checks a character string for incorrect characters or character types. It
compares each character string to a second string, called a mask, by comparing each
character in the first string to the corresponding character in the mask. If all characters in the
character string match the characters or character types in the mask, CHKFMT returns the
value 0. Otherwise, CHKFMT returns a value equal to the position of the first character in the
character string not matching the mask.
If the mask is shorter than the character string, the function checks only the portion of the
character string corresponding to the mask. For example, if you are using a four-character
mask to test a nine-character string, only the first four characters in the string are checked; the
rest are returned as a no match with CHKFMT giving the first non-matching position as the
result.
where:
numchar
Integer
204
6. Character Functions
string
Alphanumeric
Alphanumeric
Is the mask, which contains the comparison characters enclosed in single quotation
marks.
Some characters in the mask are generic and represent character types. If a character in
the string is compared to one of these characters and is the same type, it matches.
Generic characters are:
$ is any character.
Any other character in the mask represents only that character. For example, if the third
character in the mask is B, the third character in the string must be B to match.
output
Integer
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
where:
numchar
Integer
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
206
6. Character Functions
Product
The CTRAN function translates a character within a character string to another character based
on its decimal value. This function is especially useful for changing replacement characters to
unavailable characters, or to characters that are difficult to input or unavailable on your
keyboard. It can also be used for inputting characters that are difficult to enter when
responding to a Dialogue Manager -PROMPT command, such as a comma or apostrophe. It
eliminates the need to enclose entries in single quotation marks (').
To use CTRAN, you must know the decimal equivalent of the characters in internal machine
representation. Note that the coding chart for conversion is platform dependent, hence your
platform and configuration option determines whether ASCII, EBCDIC, or Unicode coding is
used. Printable EBCDIC or ASCII characters and their decimal equivalents are listed in .
where:
length
Integer
Is the number of characters in the source string, or a field that contains the length.
source_string
Alphanumeric
Is the character string to be translated enclosed in single quotation marks ('), or the field
or variable that contains the character string.
decimal
Integer
Is the ASCII or EBCDIC decimal value of the character to be used as a substitute for
decimal.
output
Alphanumeric
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
208
6. Character Functions
The CTRFLD function centers a character string within a field. The number of leading spaces is
equal to or one less than the number of trailing spaces.
CTRFLD is useful for centering the contents of a field and its report column, or a heading that
consists only of an embedded field. HEADING CENTER centers each field value including
trailing spaces. To center the field value without the trailing spaces, first center the value
within the field using CTRFLD.
Limit: Using CTRFLD in a styled report (StyleSheets feature) generally negates the effect of
CTRFLD unless the item is also styled as a centered element. Also, if you are using CTRFLD on
a platform for which the default font is proportional, either use a non-proportional font, or issue
SET STYLE=OFF before running the request.
where:
source_string
Alphanumeric
Is the character string enclosed in single quotation marks, or a field or variable that
contains the character string.
length
Integer
Is the number of characters in source_string and output, or a field that contains the length.
This argument must be greater than 0. A length less than 0 can cause unpredictable
results.
output
Alphanumeric
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
210
6. Character Functions
The EDIT function extracts characters from the source string and adds characters to the output
string, according to the mask. It can extract a substring from different parts of the source
string. It can also insert characters from the source string into an output string. For example, it
can extract the first two characters and the last two characters of a string to form a single
output string.
EDIT compares the characters in a mask to the characters in a source string. When it
encounters a nine (9) in the mask, EDIT copies the corresponding character from the source
field to the output string. When it encounters a dollar sign ($) in the mask, EDIT ignores the
corresponding character in the source string. When it encounters any other character in the
mask, EDIT copies that character to the corresponding position in the output string. This
process ends when the mask is exhausted.
Note:
EDIT does not require an output argument because the result is alphanumeric and its size
is determined from the mask value.
EDIT(source_string, 'mask');
where:
source_string
Alphanumeric
Is a character string from which to pick characters. Each 9 in the mask represents one
digit, so the size of source_string must be at least as large as the number of 9's in the
mask.
mask
Alphanumeric
Is a string of mask characters enclosed in single quotation marks or a field containing the
character string enclosed in single quotation marks. The length of the mask, excluding
characters other than 9 and $, determines the length of the output field.
212
6. Character Functions
The GETTOK function divides a character string into substrings, called tokens. The data must
have a specific character, called a delimiter, that occurs in the string and separates the string
into tokens. GETTOK returns the token specified by the token_number argument. GETTOK
ignores leading and trailing blanks in the source character string.
For example, suppose you want to extract the fourth word from a sentence. In this case, use
the space character for a delimiter and the number 4 for token_number. GETTOK divides the
sentence into words using this delimiter, then extracts the fourth word. If the string is not
divided by the delimiter, use the PARAG function for this purpose.
where:
source_string
Alphanumeric
Is the number of the token to extract. If this argument is positive, the tokens are counted
from left to right. If this argument is negative, the tokens are counted from right to left. For
example, -2 extracts the second token from the right. If this argument is 0, the function
returns spaces. Leading and trailing null tokens are ignored.
'delim'
Alphanumeric
Is the delimiter in the source string enclosed in single quotation marks. If you specify more
than one character, only the first character is used.
Note: In Dialogue Manager, to prevent the conversion of a delimiter space character (' ') to
a double precision zero, include a non-numeric character after the space (for example, '%').
GETTOK uses only the first character (the space) as a delimiter, while the extra character
(%) prevents conversion to double precision.
outlen
Integer
Is the size of the token extracted. If this argument is less than or equal to 0, the function
returns spaces. If the token is longer than this argument, it is truncated; if it is shorter, it
is padded with trailing spaces.
output
Alphanumeric
Is the name of the field that contains the token, or the format of the output value enclosed
in single quotation marks. The delimiter is not included in the token.
214
6. Character Functions
The LCWORD function converts the letters in a character string to mixed-case. It converts every
alphanumeric character to lowercase except the first letter of each new word and the first letter
after a single or double quotation mark, which it converts to uppercase. For example,
O'CONNOR is converted to O'Connor and JACK'S to Jack'S.
LCWORD skips numeric and special characters in the source string and continues to convert
the following alphabetic characters. The result of LCWORD is a string in which the initial
uppercase characters of all words are followed by lowercase characters.
where:
length
Integer
string
Alphanumeric
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks. The length must be greater than or equal to length.
The LCWORD2 function converts the letters in a character string to mixed-case by converting
the first letter of each word to uppercase and converting every other letter to lowercase. In
addition, a double quotation mark or a space indicates that the next letter should be converted
to uppercase.
For example, "SMITH" would be changed to "Smith" and "JACK S" would be changed to
"Jack S".
216
6. Character Functions
where:
length
Integer
Is the length, in characters, of the character string or field to be converted, or a field that
contains the length.
string
Alphanumeric
Is the character string to be converted, or a temporary field that contains the string.
output
Alphanumeric
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks. The length must be greater than or equal to length.
For example, 'SMITH' would be changed to 'Smith' and JACK'S would be changed to Jack's.
where:
length
Integer
Is the length, in characters, of the character string or field to be converted, or a field that
contains the length.
string
Alphanumeric
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks. The length must be greater than or equal to length.
On the output, the letter C after the first single quotation mark is in uppercase because it is
not followed by a blank and is not the final letter in the input string. The letter s after the
second single quotation mark (') is in lowercase because it is the last character in the input
string:
MYVAL1 LC1 MYVAL2 LC2
------ --- ------ ---
O'CONNOR'S O'Connor's o'connor's O'Connor's
LJUST left-justifies a character string within a field. All leading spaces become trailing spaces.
218
6. Character Functions
LJUST will not have any visible effect in a report that uses StyleSheets (SET STYLE=ON) unless
you center the item.
There is a version of the LJUST function that is available only in the Maintain language. For
information on this function, see LJUST: Left-Justifying a Character String (Maintain) on page
283.
where:
length
Integer
Is the number of characters in source_string and output, or a field that contains the length.
source_string
Alphanumeric
Is the character string to be justified, or a field or variable that contains the string.
output
Alphanumeric
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
where:
length
Integer
Is the number of characters in source_string and output, or a field that contains the length.
The length must be greater than 0 and the same for both arguments; otherwise, an error
occurs.
source_string
Alphanumeric
Is the character string to convert in single quotation marks, or a field or variable that
contains the string.
output
Alphanumeric
Is the name of the field in which to store the result, or the format of the output value
enclosed in single quotation marks. The field name can be the same as source_string.
220
6. Character Functions
The OVRLAY function overlays a base character string with a substring. The function enables
you to edit part of an alphanumeric field without replacing the entire field.
There is a version of the OVRLAY function that is available only in the Maintain language. For
information on this function, see OVRLAY: Overlaying a Character String (Maintain) on page
289.
where:
source_string
Alphanumeric
Is the number of characters in source_string and output, or a field that contains the length.
If this argument is less than or equal to 0, unpredictable results occur.
substring
Alphanumeric
Is the number of characters in substring, or a field that contains the length. If this
argument is less than or equal to 0, the function returns spaces.
position
Integer
Is the position in source_string at which the overlay begins. If this argument is less than or
equal to 0, the function returns spaces. If this argument is larger than stringlen, the
function returns the source string.
output
Alphanumeric
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks. If the overlaid string is longer than the output field, the string is
truncated to fit the field.
Note that if the overlaid string is longer than the output field, the string is truncated to fit
the field.
222
6. Character Functions
The PARAG function divides a character string into substrings by marking them with a delimiter.
It scans a specific number of characters from the beginning of the string and replaces the last
space in the group scanned with the delimiter, thus creating a first substring, also known as a
token. It then scans the next group of characters in the line, starting from the delimiter, and
replaces its last space with a second delimiter, creating a second token. It repeats this
process until it reaches the end of the line.
Once each token is marked off by the delimiter, you can use the function GETTOK to place the
tokens into different fields. If PARAG does not find any spaces in the group it scans, it
replaces the first character after the group with the delimiter. Therefore, make sure that any
group of characters has at least one space. The number of characters scanned is provided as
the maximum token size.
For example, if you have a field called 'subtitle' which contains a large amount of text
consisting of words separated by spaces, you can cut the field into roughly equal substrings by
specifying a maximum token size to divide the field. If the field is 350 characters long, divide it
into three substrings by specifying a maximum token size of 120 characters. This technique
enables you to print lines of text in paragraph form.
Tip: If you divide the lines evenly, you may create more sub-lines than you intend. For example,
suppose you divide 120-character text lines into two lines of 60 characters maximum, but one
line is divided so that the first sub-line is 50 characters and the second is 55. This leaves
room for a third sub-line of 15 characters. To correct this, insert a space (using weak
concatenation) at the beginning of the extra sub-line, then append this sub-line (using strong
concatenation) to the end of the one before it. Note that the sub-line will be longer than 60
characters.
where:
length
Integer
Is the number of characters in source_string and output, or a field that contains the length.
source_string
Alphanumeric
Is a string to divide into tokens enclosed in single quotation marks, or a field or variable
that contains the text.
delimiter
Alphanumeric
Is the delimiter enclosed in single quotation marks. Choose a character that does not
appear in the text.
max_token_size
Integer
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
224
6. Character Functions
Any character from the input that represents a single-byte digit becomes the character 9.
Any character that represents an uppercase letter becomes A, and any character that
represents a lowercase letter becomes a. For European NLS mode (Western Europe,
Central Europe), A and a are extended to apply to accented alphabets.
where:
length
Numeric
Is the source string enclosed in single quotation marks, or a field containing the source
string.
output
Alphanumeric
Is the name of the field to contain the result or the format of the field enclosed in single
quotation marks.
212-736-6250
212 736 4433
123-45-6789
800-969-INFO
10121-2898
10121
2 Penn Plaza
917-339-6380
917-339-4350
(212) 736-6250
(212) 736-4433
212-736-6250
212-736-6250
212-736-6250
(212) 736 5533
(212) 736 5533
(212) 736 5533
10121 Æ
800-969-INFO
FILENAME=TESTFILE, SUFFIX=FIX ,
SEGMENT=TESTFILE, SEGTYPE=S0, $
FIELDNAME=TESTFLD, USAGE=A14, ACTUAL=A14, $
The following request generates a pattern for each instance of TESTFLD and displays them by
the pattern that was generated. It shows the count of each pattern and its percentage of the
total count. The PRINT command shows which values of TESTFLD generated each pattern.
Note that the next to last line produced a pattern from an input string that contained an
unprintable character, so that character was changed to X. Otherwise, each numeric digit
generated a 9 in the output string, each uppercase letter generated the character ‘A’, and
each lowercase letter generated the character ‘a’. The output is:
226
6. Character Functions
The POSIT function finds the starting position of a substring within a source string. For
example, the starting position of the substring DUCT in the string PRODUCTION is 4. If the
substring is not in the parent string, the function returns the value 0.
There is a version of the POSIT function that is available only in the Maintain language. For
information on this function, see POSIT: Finding the Beginning of a Substring (Maintain) on page
290.
where:
source_string
Alphanumeric
Is the string to parse enclosed in single quotation marks, or a field or variable that
contains the source character string.
length
Integer
Is the number of characters in the source string, or a field that contains the length. If this
argument is less than or equal to 0, the function returns a 0.
substring
Alphanumeric
Is the substring whose position you want to find. This can be the substring enclosed in
single quotation marks, or the field that contains the string.
sublength
Integer
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
228
6. Character Functions
where:
length
Integer
Is the number of characters in source_string and output, or a field that contains the length.
source_string
Alphanumeric
Is the character string to reverse enclosed in single quotation marks, or a field that
contains the character string.
output
Alphanumeric
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
The RJUST function right-justifies a character string. All trailing blacks become leading blanks.
This is useful when you display alphanumeric fields containing numbers.
RJUST does not have any visible effect in a report that uses StyleSheets (SET STYLE=ON)
unless you center the item. Also, if you use RJUST on a platform on which StyleSheets are
turned on by default, issue SET STYLE=OFF before running the request.
There is a version of the RJUST function that is available only in the Maintain language. For
information on this function, see RJUST: Right-Justifying a Character String (Maintain) on page
291.
where:
length
Integer
Is the number of characters in source_string and output, or a field that contains the length.
Their lengths must be the same to avoid justification problems.
source_string
Alphanumeric
Is the character string to right justify, or a field or variable that contains the character
string enclosed in single quotation marks.
230
6. Character Functions
output
Alphanumeric
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
The SOUNDEX function analyzes a character string phonetically, without regard to spelling. It
converts character strings to four character codes. The first character must be the first
character in the string. The last three characters represent the next three significant sounds in
the source string.
where:
length
Alphanumeric
Is the number of characters in source_string, or a field that contains the length. It can be a
number enclosed in single quotation marks, or a field containing the number. The number
must be from 01 to 99, expressed with two digits (for example '01'); a number larger than
99 causes the function to return asterisks (*) as output.
source_string
Alphanumeric
Is the string to analyze enclosed in single quotation marks, or a field or variable that
contains the character string.
output
Alphanumeric
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
The WHERE criteria selects the last name that matches your best guess.
232
6. Character Functions
The SPELLNM function spells out an alphanumeric string or numeric value containing two
decimal places as dollars and cents. For example, the value 32.50 is THIRTY TWO DOLLARS
AND FIFTY CENTS.
where:
outlength
Integer
If you know the maximum value of number, use the following table to determine the value
of outlength:
$10 37
$100 45
$1,000 59
$10,000 74
$100,000 82
$1,000,000 96
number
Alphanumeric or Numeric (9.2)
Is the number to be spelled out. This value must contain two decimal places.
output
Alphanumeric
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
The SQUEEZ function reduces multiple contiguous spaces within a character string to a single
space. The resulting character string has the same length as the original string but is padded
on the right with spaces.
where:
length
Integer
Is the number of characters in source_string and output, or a field that contains the length.
source_string
Alphanumeric
Is the character string to squeeze enclosed in single quotation marks, or the field that
contains the character string.
234
6. Character Functions
output
Alphanumeric
Is the field that contains the result, or the format of the output value enclosed in single
quotation marks.
The STRIP function removes all occurrences of a specific character from a string. The resulting
character string has the same length as the original string but is padded on the right with
spaces.
where:
length
Integer
Is the number of characters in source_string and output, or a field that contains the
number.
source_string
Alphanumeric
Is the string from which the character will be removed, or a field containing the string.
char
Alphanumeric
Is the character to be removed from the string. This can be an alphanumeric literal
enclosed in single quotation marks, or a field that contains the character. If more than one
character is provided, the left-most character will be used as the strip character.
Note: To remove single quotation marks, use two consecutive quotation marks. You must
then enclose this character combination in single quotation marks.
output
Alphanumeric
Is the field that contains the result, or the format of the output value enclosed in single
quotation marks.
236
6. Character Functions
where:
inlength
Numeric
Is the number of characters in the replacement string. Must be zero (0) or greater.
repstring
Alphanumeric
238
6. Character Functions
The SUBSTR function extracts a substring based on where it begins and its length in the
source string. SUBSTR can vary the position of the substring depending on the values of other
fields.
There is a version of the SUBSTR function that is available only in the Maintain language. For
information on this function, see SUBSTR: Extracting a Substring (Maintain) on page 299.
where:
length
Integer
Is the string from which to extract a substring enclosed in single quotation marks, or the
field containing the parent string.
start
Integer
Is the starting position of the substring in the source string. If start is less than one or
greater than length, the function returns spaces.
end
Integer
Is the ending position of the substring. If this argument is less than start or greater than
length, the function returns spaces.
sublength
Integer
Is the number of characters in the substring (normally end - start + 1). If sublength is
longer than end - start +1, the substring is padded with trailing spaces. If it is shorter, the
substring is truncated. This value should be the declared length of output. Only sublength
characters will be processed.
output
Alphanumeric
Is the field to which the result is returned, or the format of the output value enclosed in
single quotation marks.
240
6. Character Functions
The TRIM function removes leading and/or trailing occurrences of a pattern within a character
string.
There is a version of the TRIM function that is available only in the Maintain language. For
information on this function, see TRIM: Removing Trailing Occurrences (Maintain) on page 300.
where:
trim_where
Alphanumeric
Is the string to trim enclosed in single quotation marks, or the field containing the string.
string_length
Integer
Is the field to which the result is returned, or the format of the output value enclosed in
single quotation marks.
242
6. Character Functions
The UPCASE function converts a character string to uppercase. It is useful for sorting on a field
that contains both mixed-case and uppercase values. Sorting on a mixed-case field produces
incorrect results because the sorting sequence in EBCDIC always places lowercase letters
before uppercase letters, while the ASCII sorting sequence always places uppercase letters
before lowercase. To obtain correct results, define a new field with all of the values in
uppercase, and sort on that field.
There is a version of the UPCASE function that is available only in the Maintain language. For
information on this function, see UPCASE: Converting Text to Uppercase (Maintain) on page
301.
where:
length
Integer
Is the string to convert enclosed in single quotation marks, or the field containing the
character string.
output
Alphanumeric of type AnV or An
Is the field to which the result is returned, or the format of the output value enclosed in
single quotation marks.
244
6. Character Functions
Now, when you execute the request, the names are sorted correctly.
where:
inlength
Integer
Is the length of the field containing the source character string, or a field that contains the
length.
source_string
Alphanumeric
Is the name of the field containing the source character string or the string enclosed in
single quotation marks (').
outlength
Integer
Is the length of the output character string, or a field that contains the length.
output
Integer
Is the field that contains the result, or the format of the output value enclosed in single
quotation marks.
246
6. Character Functions
XMLDECOD decodes any of the supported XML-encoded characters. Note that some viewers
automatically decode the encoded values for display, so the output is produced in a plain text
format (FORMAT WP):
FILEDEF XMLFUNCS DISK xmlfuncs.csv
DEFINE FILE XMLFUNCS
OUTSTRING/A30=XMLDECOD(30,INSTRING,30,'A30');
END
TABLE FILE XMLFUNCS
PRINT INSTRING OUTSTRING
ON TABLE PCHOLD FORMAT WP
ON TABLE SET PAGE NOPAGE
In the output string, XML-encoded characters have been decoded, and characters that were
not encoded have been left as they were in the input string:
INSTRING OUTSTRING
-------- ---------
CHARS: & < > CHARS: & < >
ENCODED: & > ENCODED: & >
ENCODED: " ' ENCODED: " '
MIXED: & < > MIXED: & < >
where:
inlength
Integer
Is the length of the field containing the source character string, or a field that contains the
length.
source_string
Alphanumeric
Is the name of the field containing the source character string or a string enclosed in
single quotation marks (').
option
Integer
Is a code that specifies whether to process a string that already contains XML-encoded
characters. Valid values are:
0, the default, which cancels processing of a string that already contains at least one
XML-encoded character.
Is the length of the output character string, or a field that contains the length.
Note: The output length, in the worst case, could be six times the length of the input.
output
Integer
Is the field that contains the result, or the format of the output value enclosed in single
quotation marks.
248
6. Character Functions
In OUTSTRING1, the supported characters have been XML-encoded, and output is produced
even if the input string contains encoded characters. OUTSTRING2 is only produced when no
XML-encoded characters exist in the input string:
INSTRING OUTSTRING1 OUTSTRING2
-------- ---------- ----------
CHARS: & < > CHARS: & < > CHARS: & < >
ENCODED: & > ENCODED: & >
ENCODED: " ' ENCODED: " '
MIXED: & < > MIXED: & < >
250
Chapter 7 Variable Length Character Functions
The character format AnV is supported in synonyms for FOCUS, XFOCUS, and relational
data sources. This format is used to represent the VARCHAR (variable length character)
data types supported by relational database management systems.
In this chapter:
Overview
Overview
For relational data sources, AnV keeps track of the actual length of a VARCHAR column. This
information is especially valuable when the value is used to populate a VARCHAR column in a
different RDBMS. It affects whether trailing blanks are retained in string concatenation and, for
Oracle, string comparisons (the other relational engines ignore trailing blanks in string
comparisons).
In a FOCUS or XFOCUS data source, AnV does not provide true variable length character
support. It is a fixed-length character field with an extra two leading bytes to contain the actual
length of the data stored in the field. This length is stored as a short integer value occupying
two bytes. Because of the two bytes of overhead and the additional processing required to
strip them, AnV format is not recommended for use with non-relational data sources.
AnV fields can be used as arguments to all Information Builders-supplied functions that expect
alphanumeric arguments. An AnV input parameter is treated as an An parameter and is padded
with blanks to its declared size (n). If the last parameter specifies an AnV format, the function
result is converted to type AnV with actual length set equal to its size.
The functions described in this topic are designed to work specifically with the AnV data type
parameters.
Many functions require both an alphanumeric string and its length as input arguments. If
the supplied string is stored in an AnV field, you still must supply a length argument to
satisfy the requirements of the function. However, the length that will be used in the
function's calculations is the actual length stored as the first two bytes of the AnV field.
In general, any input argument can be a field or a literal. In most cases, numeric input
arguments are supplied to these functions as literals, and there is no reason not to supply
an integer value. However, if the value is not an integer, it is truncated to an integer value
regardless of whether it was supplied as a field or a literal.
LENV returns the actual length of an AnV field or the size of an An field.
LENV(source_string, output)
where:
source_string
Alphanumeric of type An or AnV
Is the source string or field. If it is an An format field, the function returns its size, n. For a
character string enclosed in quotation marks or a variable, the size of the string or variable
is returned. For a field of AnV format, its length, taken from the length-in-bytes of the field,
is returned.
252
7. Variable Length Character Functions
output
Integer
Is the field to which the result is returned, or the format of the output value enclosed in
single quotation marks (').
The LOCASV function converts alphabetic characters in the source string to lowercase and is
similar to LOCASE. LOCASV returns AnV output whose actual length is the lesser of the actual
length of the AnV source string and the value of the input parameter upper_limit.
where:
upper_limit
Integer
source_string
Alphanumeric of type An or AnV
Is the name of the field in which to store the result, or the format of the output value
enclosed in single quotation marks ('). This value can be for a field that is AnV or An
format.
If the output format is AnV, the actual length returned is equal to the smaller of the source
string length and the upper limit.
The POSITV function finds the starting position of a substring within a larger string. For
example, the starting position of the substring DUCT in the string PRODUCTION is 4. If the
substring is not in the parent string, the function returns the value 0. This is similar to POSIT;
however, the lengths of its AnV parameters are based on the actual lengths of those
parameters in comparison with two other parameters that specify their sizes.
254
7. Variable Length Character Functions
where:
source_string
Alphanumeric of type An or AnV
Is the source string that contains the substring whose position you want to find. It can be
the string enclosed in single quotation marks ('), or a field or variable that contains the
source string. If it is a field of AnV format, its length is taken from the length bytes stored
in the field. If upper_limit is smaller than the actual length, the source string is truncated
to this upper limit.
upper_limit
Integer
Is the substring whose position you want to find. This can be the substring enclosed in
single quotation marks ('), or the field that contains the string. If it is a field, it can have An
or AnV format. If it is a field of type AnV, its length is taken from the length bytes stored in
the field. If sub_limit is smaller than the actual length, the source string is truncated to this
limit.
sub_limit
Integer
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks (').
The SUBSTV function extracts a substring from a string and is similar to SUBSTR. However, the
end position for the string is calculated from the starting position and the substring length.
Therefore, it has fewer parameters than SUBSTR. Also, the actual length of the output field, if
it is an AnV field, is determined based on the substring length.
256
7. Variable Length Character Functions
where:
upper_limit
Integer
Is the character string that contains the substring you want to extract. It can be the string
enclosed in single quotation marks ('), or the field containing the string. If it is a field, it
can have An or AnV format. If it is a field of type AnV, its length is taken from the length
bytes stored in the field. If upper_limit is smaller than the actual length, the source string
is truncated to the upper limit. The final length value determined by this comparison is
referred to as p_length (see the description of the output parameter for related
information).
start
Integer
Is the starting position of the substring in the source string. The starting position can
exceed the source string length, which results in spaces being returned.
sub_limit
Integer
Is the length, in characters, of the substring. Note that the ending position can exceed the
input string length depending on the provided values for start and sub_limit.
output
Alphanumeric of type An or AnV
Is the field to which the result is returned, or the format of the output value enclosed in
single quotation marks ('). This field can be in An or AnV format.
If the format of output is AnV, and assuming end is the ending position of the substring,
the actual length, outlen, is computed as follows from the values for end, start, and
p_length (see the source_string parameter for related information):
If end > p_length or end < start, then outlen = 0. Otherwise, outlen = end - start + 1.
The TRIMV function removes leading and/or trailing occurrences of a pattern within a character
string. TRIMV is similar to TRIM. However, TRIMV allows the source string and the pattern to
be removed to have AnV format.
TRIMV is useful for converting an An field to an AnV field (with the length in bytes containing
the actual length of the data up to the last non-blank character).
258
7. Variable Length Character Functions
where:
trim_where
Alphanumeric
Is the source string to be trimmed. It can be the string enclosed in single quotation marks
('), or the field containing the string. If it is a field, it can have An or AnV format. If it is a
field of type AnV, its length is taken from the length in bytes stored in the field. If
upper_limit is smaller than the actual length, the source string is truncated to this upper
limit.
upper_limit
Integer
Is the pattern to remove from the string, enclosed in single quotation marks ('). If it is a
field, it can have An or AnV format. If it is a field of type AnV, its length is taken from the
length in bytes stored in the field. If pattern_limit is smaller than the actual length, the
pattern is truncated to this limit.
plength_limit
Integer
Is the field to which the result is returned, or the format of the output value enclosed in
single quotation marks ('). The field can be in AnV or An format.
If the output format is AnV, the length is set to the number of characters left after
trimming.
where:
upper_limit
Integer
Is the limit for the length of the source string. It can be a positive constant or a field whose
integer portion represents the upper limit.
260
7. Variable Length Character Functions
source_string
Alphanumeric of type An or AnV
is the string to convert to uppercase. It can be the character string enclosed in single
quotation marks ('), or the field containing the character string. If it is a field, it can have
An or AnV format. If it is a field of type AnV, its length is taken from the length in bytes
stored in the field. If upper_limit is smaller than the actual length, the source string is
truncated to the upper limit.
output
Alphanumeric of type An or AnV
Is the field to which the result is returned, or the format of the output value enclosed in
single quotation marks ('). This can be a field with AnV or An format.
If the output format is AnV, the length returned is equal to the smaller of the source string
length and upper_limit.
262
Chapter 8 Character Functions for DBCS Code
Pages
The functions in this topic manipulate strings of DBCS and SBCS characters when your
configuration uses a DBCS code page.
In this chapter:
The DCTRAN function can translate single-byte to double-byte characters and double-byte to
single-byte characters, as well as single-byte to single-byte characters and double-byte to
double-byte characters.
where:
length
Double
Is the ASCII or EBCDIC decimal value of the character to be used as a substitute for
indecimal.
output
Alphanumeric
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks (').
DEDIT works by comparing the characters in a mask to the characters in a source field. When
it encounters a nine (9) in the mask, DEDIT copies the corresponding character from the
source field to the new field. When it encounters a dollar sign ($) in the mask, DEDIT ignores
the corresponding character in the source field. When it encounters any other character in the
mask, DEDIT copies that character to the corresponding position in the new field.
264
8. Character Functions for DBCS Code Pages
where:
inlength
Integer
Is the number of bytes in source_string. The string can have a mixture of DBCS and SBCS
characters. Therefore, the number of bytes represents the maximum number of characters
possible in the source string.
source_string
Alphanumeric
Is the string to edit enclosed in single quotation marks ('), or the field containing the
string.
mask_length
Integer
Each nine (9) in the mask causes the corresponding character from the source field to be
copied to the new field.
Each dollar sign ($) in the mask causes the corresponding character in the source field to
be ignored.
Is the field to which the result is returned, or the format of the output value enclosed in
single quotation marks (').
The following example copies alternate characters from the source string to the new field,
starting with the second character in the source string, and then adds several new characters
at the end of the extracted string:
where:
length
Double
266
8. Character Functions for DBCS Code Pages
char
Alphanumeric
Is the character to be removed from the string. If more than one character is provided, the
left-most character will be used as the strip character.
Note: To remove single quotation marks, use two consecutive quotation marks. You must
then enclose this character combination in single quotation marks.
output
Alphanumeric
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks (').
where:
inlength
Integer
Is the length of the source string in bytes, or a field that contains the length. The string can
have a mixture of DBCS and SBCS characters. Therefore, the number of bytes represents
the maximum number of characters possible in the source string.
source_string
Alphanumeric
Is the string from which the substring will be extracted enclosed in single quotation marks
('), or the field containing the parent string.
start
Integer
Is the starting position (in number of characters) of the substring in the source string. If
this argument is less than one or greater than end, the function returns spaces.
end
Integer
Is the ending position (in number of characters) of the substring. If this argument is less
than start or greater than inlength, the function returns spaces.
sublength
Integer
Is the length of the substring, in characters (normally end - start + 1). If sublength is longer
than end - start +1, the substring is padded with trailing spaces. If it is shorter, the
substring is truncated. This value should be the declared length of output. Only sublength
characters will be processed.
output
Alphanumeric
Is the field to which the result is returned, or the format of the output value enclosed in
single quotation marks (').
268
8. Character Functions for DBCS Code Pages
where:
type_of_conversion
Is one of the following options indicating the type of conversion you want to apply to
Japanese specific characters. The following table shows the single component input types:
length
Integer
Is the name of the field that contains the output, or the format enclosed in single
quotation marks (').
270
8. Character Functions for DBCS Code Pages
In the following, codepoints 0x62 0x63 0x64 are converted to 0x81 0x82 0x83, respectively:
JPTRANS('930TO939', 20, CP930_Field, 'A20')
In the following, codepoints 0x59 0x62 0x63 are converted to 0x81 0x82 0x83, respectively:
JPTRANS('939TO930', 20, CP939_Field, 'A20')
Many symbols have a one-to-one relation between Japanese Fullwidth characters and ASCII
symbols, whereas some characters have one-to-many relations. For example, the Japanese
punctuation character (U+3001) and Fullwidth comma , (U+FF0C) will be converted to the
same comma , (U+002C). The following EXTRA rule for those special cases is shown below:
HNZNSIGN:
Double Quote " (U+0022) -> Fullwidth Right Double Quote ” (U+201D)
Single Quote ' (U+0027) -> Fullwidth Right Single Quote ’ (U+2019)
Halfwidth Left Corner Bracket (U+FF62) -> Fullwidth Left Corner Bracket (U+300C)
Halfwidth Right Corner Bracket (U+FF63) -> Fullwidth Right Corner Bracket (U+300D)
Halfwidth Katakana Middle Dot ? (U+FF65) -> Fullwidth Middle Dot · (U+30FB)
ZNHNSIGN:
Fullwidth Right Double Quote ” (U+201D) -> Double Quote " (U+0022)
Fullwidth Left Double Quote “ (U+201C) -> Double Quote " (U+0022)
Fullwidth Right Single Quote ’ (U+2019) -> Single Quote ' (U+0027)
Fullwidth Left Single Quote ‘ (U+2018) -> Single Quote ' (U+0027)
Fullwidth Single Quote ' (U+FF07) -> Single Quote ' (U+0027)
Fullwidth Left Corner Bracket (U+300C) -> Halfwidth Left Corner Bracket (U+FF62)
Fullwidth Right Corner Bracket (U+300D) -> Halfwidth Right Corner Bracket (U+FF63)
Fullwidth Middle Dot · (U+30FB) -> Halfwidth Katakana Middle Dot · (U+FF65)
They convert not only letters, but also punctuation symbols on the following list:
272
8. Character Functions for DBCS Code Pages
Fullwidth Ideographic Full Stop (U+3002) <-> Halfwidth Ideographic Full Stop (U+FF61)
Fullwidth Left Corner Bracket (U+300C) <-> Halfwidth Left Corner Bracket (U+FF62)
Fullwidth Right Corner Bracket (U+300D) <-> Halfwidth Right Corner Bracket (U+FF63)
Fullwidth Middle Dot · (U+30FB) <-> Halfwidth Katakana Middle Dot · (U+FF65)
For example, text data may contain fullwidth numbers and fullwidth symbols. In some
situations, they should be cleaned up for ASCII numbers and symbols.
where:
length
Integer
Is the length of the source string in bytes, or a field that contains the length. The string can
have a mixture of DBCS and SBCS characters. Therefore, the number of bytes represents
the maximum number of characters possible in the source string.
source_string
Alphanumeric
Is the string that will be truncated enclosed in single quotation marks ('), or the field
containing the string.
output
Alphanumeric
Is the field to which the result is returned, or the format of the output value enclosed in
single quotation marks (').
The string will be truncated to the number of bytes in the output field.
274
8. Character Functions for DBCS Code Pages
where:
source_string
Alphanumeric
Is the string from which the shift code will be deleted enclosed in single quotation marks
('), or the field containing the string.
length
Integer
Is the length of the source string in bytes, or a field that contains the length. The string can
have a mixture of DBCS and SBCS characters. Therefore, the number of bytes represents
the maximum number of characters possible in the source string.
output
Alphanumeric
Is the field to which the result is returned, or the format of the output value enclosed in
single quotation marks (').
where:
source_string
Alphanumeric
Is the string into which the shift code will be inserted enclosed in single quotation marks
('), or the field containing the string.
length
Integer
Is the length of the source string in bytes, or a field that contains the length. The string can
have a mixture of DBCS and SBCS characters. Therefore, the number of bytes represents
the maximum number of characters possible in the source string.
output
Alphanumeric
Is the field to which the result is returned, or the format of the output value enclosed in
single quotation marks (').
276
8. Character Functions for DBCS Code Pages
The output displays the original COUNTRY field, the COUNTRY_DEL field with the shift code
deleted, and the COUNTRY_INS field with the shift code re-inserted.
278
Chapter 9 Maintain-specific Character Functions
Character functions manipulate alphanumeric fields or character strings. The functions in
this topic are available only in the WebFOCUS Maintain language. There are additional
character functions that are available in both the reporting and Maintain languages. For
information on these functions, see Character Functions on page 195.
In this chapter:
CHAR2INT("character")
where:
character
Is the ASCII or EBCDIC character to translate into its integer value.
INT2CHAR(value)
where:
value
Is the integer to translate into its equivalent ASCII or EBCDIC character.
280
9. Maintain-specific Character Functions
On an ASCII platform, the result would be a right bracket (]). On an EBCDIC platform, the result
would be a right parenthesis.
LCWORD. Converts every alphanumeric character to lowercase except the first letter of
each new word and the first letter after a single or double quotation mark. For example,
O'CONNOR is converted to O'Connor and JACK'S to Jack'S.
LCWORD2. Converts every alphanumeric character to lowercase except the first letter of
each new word. LCWORD2 leaves any character after a single quotation mark as upper
case, except that when there is at least one non-blank character before the quote and just
one character followed by either the end of the string or a space immediately after the
quote, the next letter is converted to lowercase. For example, 'O’CONNOR' would be
changed to 'O’Connor,' and JACK'S would be changed to Jack's.
To use these functions, you must import the function library MNTUWS. For information on
importing this library, see Accessing and Calling a Function on page 59.
There is also an LCWORD function available for both the reporting and Maintain languages. For
information on this function, see Character Functions on page 195.
{LCWORD|LCWORD2}(string)
where:
string
Alphanumeric
Is the character string to be converted, or a temporary field that contains the string.
LENGTH(string)
where:
string
Alphanumeric
Is the character string whose length is to be found, or a temporary field that contains the
string.
282
9. Maintain-specific Character Functions
LJUST will not have any visible effect in a report that uses StyleSheets (SET STYLE=ON) unless
you center the item.
To use this function, you must import the function library MNTUWS. For information on
importing this library see Accessing and Calling a Function on page 59.
There is also an LJUST function available for the reporting language. For information on this
function, see Character Functions on page 195.
LJUST(string)
where:
string
Alphanumeric
Is the character string to be justified, or a temporary field that contains the string.
To use this function, you must import the function library MNTUWS. For more information on
importing this library see Accessing and Calling a Function on page 59.
LOWER(string)
where:
string
Alphanumeric
Is the character string to be converted, or a temporary field that contains the string.
MASK works by comparing the characters in a mask to the characters in a source field. When
it encounters a 9 in the mask, MASK copies the corresponding character from the source field
to the new field. When it encounters a dollar sign in the mask, MASK ignores the
corresponding character in the source field. When it encounters any other character in the
mask, MASK copies that character to the corresponding position in the new field.
MASK replaces the masking functionality of the EDIT function that is available in the reporting
language.
MASK(fieldname, 'mask')
where:
fieldname
Is the source field.
mask
Is a character string enclosed in single quotation marks, or a temporary field that contains
the string.
MASK(FIRST_NAME, '9$$$$$$$$$')
The following are sample values for FIRST_NAME and the values for the result of the MASK
function:
FIRST_NAME MASK_FIRST_NAME
---------- ---------------
MARY M
DIANE D
JOHN J
ROSEMARIE R
MARY M
BARBARA B
284
9. Maintain-specific Character Functions
The following are sample values for EMP_ID and the values for the result of the MASK function:
EMP_ID MASK_EMP_ID
------ -----------
112847612 112-84-7612
117593129 117-59-3129
219984371 219-98-4371
326179357 326-17-9357
543729165 543-72-9165
818692173 818-69-2173
For example, you can use MNTGETTOK to extract individual values from a list separated by
semi-colons, by designating the semi-colon as the delimiter.
To use this function, you must import the function library MNTUWS.
Note:
The Maintain function called strtoken() returns only the first token from a string.
MNTGETTOK can work with variable length character strings (format A0).
Module Import(mntuws)
MNTGETTOK(infield,"delim",token_number)
where:
infield
Alphanumeric
Is the field containing the original character string or a character string enclosed in single
or double quotation marks.
delim
Alphanumeric
Is the delimiter in the parent string enclosed in single or double quotation marks. If you
specify more than one character, only the first character is used. The delimiter is not
included in the token.
token_number
Integer
Is the number of the token to extract. If this argument is positive, the tokens are counted
from left to right. If this argument is negative, the tokens are counted from right to left. For
example, -2 extracts the second token from the right. If this argument is 0, the function
returns spaces.
286
9. Maintain-specific Character Functions
ALFRED STEVENS
NEW YORK NY 10001
ZIP CODE IS: 10001
MARY SMITH
NEW YORK NY 10001
ZIP CODE IS: 10001
DIANE JONES
NEW YORK NY 10001
ZIP CODE IS: 10001
RICHARD SMITH
NEW YORK NY 10001
ZIP CODE IS: 10001
JOHN BANNING
FREEPORT NY 11520
ZIP CODE IS: 11520
JOAN IRVING
NEW YORK NY 10001
ZIP CODE IS: 10001
ANTHONY ROMANS
NEW YORK NY 10001
ZIP CODE IS: 10001
JOHN MCCOY
NEW YORK NY 10001
ZIP CODE IS: 10001
ROSEMARIE BLACKWOOD
NEW YORK NY 10001
ZIP CODE IS: 10001
ROGER MCKNIGHT
NEW YORK NY 10001
ZIP CODE IS: 10001
MARY GREENSPAN
NEW YORK NY 10001
ZIP CODE IS: 10001
BARBARA CROSS
NEW YORK NY 10001
ZIP CODE IS: 10001
288
9. Maintain-specific Character Functions
Syntax: How to Convert Characters From the Native English Code Page
NLSCHR("character")
where:
character
Is the character being converted from the native English code page.
MAINTAIN
ADOLLAR/A1=NLSCHR("$");
.
.
.
END
To use this function, you must import the function library MNTUWS. For information on
importing this library, see Accessing and Calling a Function on page 59.
There is also an OVRLAY function available for the reporting language. For information on this
function, see Character Functions on page 195.
where:
string1
Alphanumeric
position
Integer
The following are sample values for MOVIECODE and the values for the result of the OVRLAY
function:
Original Code New Code
001MCA 001MHD
081MCA 081MHD
082MCA 082MHD
161MCA 161MHD
196MCA 196MHD
530MCA 530MHD
550MCA 550MHD
883MCA 883MHD
To use this function, you must import the function library MNTUWS. For information on
importing this library see Accessing and Calling a Function on page 59.
There is also a POSIT function available for the reporting language. For information on this
function, see POSIT: Finding the Beginning of a Substring on page 227.
290
9. Maintain-specific Character Functions
POSIT(parent, substring)
where:
parent
Alphanumeric
The following are sample values for MOVIECODE and values for the result of the POSIT
function:
Title Start Position of word ROOF
FIDDLER ON THE ROOF 16
CAT ON A HOT TIN ROOF 18
RJUST does not have any visible effect in a report that uses StyleSheets (SET STYLE=ON)
unless you center the item. Also, if you use RJUST on a platform on which StyleSheets are
turned on by default, issue SET STYLE=OFF before running the request.
There is also an RJUST function available for the reporting language. For information on this
function, see RJUST: Right-Justifying a Character String on page 230.
where:
string
Is the character string, or a temporary field that contains the string.
length
Is the length, in characters, of the result. If this argument is less than the length of string,
RJUST trims string from right to left. If this argument is zero, RJUST returns a variable
length string of length zero.
char
Is the character with which to pad the character string and right-justify it. RJUST uses char
only when length is greater than the length of string.
where:
target
Is a valid expression. It can be either a field name or a variable that resolves to a single
stack cell.
code
Is the value for which SELECTS searches. Once the value is found, the input expression is
assigned the corresponding result. The comma between the code and result is optional.
result
Is the value assigned when the input expression has the corresponding code.
292
9. Maintain-specific Character Functions
default
Is the value to be assigned if the code is not found among the list of codes. If the default
is omitted, a space or zero is assigned to non-matching codes.
The following table shows sample values for CURR_JOBCODE and the corresponding values for
JOB_CATEGORY:
CURR_JOBCODE JOB_CATEGORY
------------ ------------
A01 ADMINISTRATIVE
A07 ADMINISTRATIVE
A15 ADMINISTRATIVE
A17 ADMINISTRATIVE
B02 DATA PROCESSING
B03 DATA PROCESSING
B04 DATA PROCESSING
B14 DATA PROCESSING
To use this function, import the function library MNTUWS. For more information on importing
this library see Calling a Function on page 59.
where:
string
Alphanumeric
Is the character string into which you want to substitute one substring for another, or a
temporary field that contains the string.
substr1
Alphanumeric
294
9. Maintain-specific Character Functions
The following are sample values for MODEL and values for the result of the STRAN function:
CAR MODEL STRAN
--- ----- -----
PEUGEOT 504 4 DOOR 504 4 SEATER
ALFA ROMEO 2000 4 DOOR BERLINA 2000 4 SEATER BERLINA
MASERATI DORA 2 DOOR DORA 2 SEATER
DATSUN B210 2 DOOR AUTO B210 2 SEATER AUTO
TOYOTA COROLLA 4 DOOR DIX AUTO COROLLA 4 SEATER DIX AUT
AUDI 100 LS 2 DOOR AUTO 100 LS 2 SEATER AUTO
BMW 2002 2 DOOR 2002 2 SEATER
BMW 2002 2 DOOR AUTO 2002 2 SEATER AUTO
BMW 3.0 SI 4 DOOR 3.0 SI 4 SEATER
BMW 3.0 SI 4 DOOR AUTO 3.0 SI 4 SEATER AUTO
BMW 530I 4 DOOR 530I 4 SEATER
BMW 530I 4 DOOR AUTO 530I 4 SEATER AUTO
If the first string is less than the second string, STRCMP returns a negative value.
If the first string is greater than the second string, STRCMP returns a positive value.
If the first string is equal to the second string, STRCMP returns zero.
STRCMP(string1, string2)
where:
string1, string2
Alphanumeric
Are the strings to compare, or temporary fields that contain the strings.
MAINTAIN
COMPUTE STR1/A20 = 'STRING IS LONG';
STR2/A20 = 'STRING IS LONGER';
COMPUTE DIF/I3= STRCMP(STR1, STR2);
TYPE "STR1 = <<STR1"
TYPE "STR2 = <<STR2"
If the first string is less than the second string, STRICMP returns a negative value.
If the first string is greater than the second string, STRICMP returns a positive value.
If the first string is equal to the second string, STRICMP returns zero.
296
9. Maintain-specific Character Functions
STRICMP(string1, string2)
where:
string1, string2
Alphanumeric
Are the strings to compare, or temporary fields that contain the strings.
If the first string is less than the second string, STRNCMP returns a negative value.
If the first string is greater than the second string, STRNCMP returns a positive value.
If the first string is equal to the second string, STRNCMP returns zero.
where:
string1, string2
Alphanumeric
To use this function, you must import the function library MNTUWS. For more information on
importing this library see Calling a Function on page 59.
STRTOKEN(string, delimiters)
where:
string
Alphanumeric
Is the character string, or a variable that contains the string enclosed in double quotation
marks (").
delimiters
Alphanumeric
Is a character string, or variable enclosed in double quotation marks (") that contains a list
of delimiters. Separate the delimiters with semicolons.
298
9. Maintain-specific Character Functions
There is also a SUBSTR function available for the reporting language. For information on this
function, see SUBSTR: Extracting a Substring on page 239.
where:
string
Alphanumeric
Is the parent string enclosed in single quotation marks, or a field or variable containing the
character string.
start
Integer
The following table shows sample values for FIRST_NAME and LAST_NAME, and the
corresponding values for UID:
FIRST_NAME LAST_NAME UID
JOE SMITH JSMITH
SAM JONES SJONES
TERRI WHITE TWHITE
There is also a TRIM function available for the reporting language. For information on this
function, see TRIM: Removing Leading and Trailing Occurrences on page 241.
TRIM(string)
where:
string
Alphanumeric
Is the character string enclosed in single quotation marks, or the field containing the
string.
TRIMLEN (string)
where:
string
Alphanumeric
300
9. Maintain-specific Character Functions
To use this function, you must import the function library MNTUWS. For information on
importing this library, see Calling a Function on page 59.
There is also an UPCASE function available for the reporting language. For information on this
function, see UPCASE: Converting Text to Uppercase on page 244.
UPCASE(string)
where:
string
Alphanumeric
302
Chapter 10 Data Source and Decoding Functions
Data source and decoding functions search for data source records, retrieve data source
records or values, and assign values based on the value of an input field.
The result of a data source function must be stored in a field. The result cannot be
stored in a Dialogue Manager variable.
For many functions, the output argument can be supplied either as a field name or as a
format enclosed in single quotation marks (‘). However, if a function is called from a
Dialogue Manager command, this argument must always be supplied as a format. If a
function is called from a Maintain Data procedure, this argument must always be
supplied as a field name. For detailed information about calling a function and supplying
arguments, see Accessing and Calling a Function on page 59.
In this chapter:
CHECKMD5(buffer)
where:
buffer
Is a data buffer whose hash value is to be calculated. It can be a set of data of different
types presented as a single field, or a group field in one of the following data type formats:
An, AnV, or TXn.
304
10. Data Source and Decoding Functions
The output is shown in the following image. The monospaced font shows that although the
input values have varying length, the output has a fixed length.
CHECKSUM(buffer)
where:
buffer
Is a data buffer whose hash index is to be calculated. It can be a set of data of different
types presented as a single field, in one of the following data type formats: An, AnV, or
TXn.
where:
arg1, arg2, ...
Any field, expression, or constant. The arguments should all be either numeric or
alphanumeric.
Are the input parameters that are tested for missing values.
306
10. Data Source and Decoding Functions
The output data type is the same as the input data types.
The following request uses COALESCE to return the first non-missing value:
TABLE FILE SALES
PRINT DAMAGED RETURNS RETAIL_PRICE
COMPUTE
COAL1/D12.2 MISSING ON = COALESCE(DAMAGED, RETURNS, RETAIL_PRICE);
BY STORE_CODE
ON TABLE SET PAGE NOLEAD
ON TABLE SET STYLE *
GRID=OFF,$
ENDSTYLE
END
The output is shown in the following image. The value of DAMAGED is returned, if it is not
missing. If DAMAGED is missing, the value of RETURNS is returned, if it is not missing. If they
are both missing, the value of RETAIL_PRICE is returned.
308
10. Data Source and Decoding Functions
The DB_EXPR function can be used in a DEFINE command, a DEFINE in a Master File, a
WHERE clause, a FILTER FILE command, a filter in a Master File, or in an SQL statement. It
can be used in a COMPUTE command if the request is an aggregate request (uses the SUM,
WRITE, or ADD command) and has a single display command. The expression must return a
single value.
DB_EXPR(native_SQL_expression)
where:
native_SQL_expression
Is a partial native SQL string that is valid to insert into the SQL generated by the request.
The SQL string must have double quotation marks (") around each field reference, unless
the function is used in a DEFINE with a WITH phrase.
Any request that includes one or more DB_EXPR functions must be for a synonym that has
a relational SUFFIX.
Field references in the native SQL expression must be within the current synonym context.
The native SQL expression must be coded inline. SQL read from a file is not supported.
Example: Inserting the DB2 BIGINT and CHAR Functions Into a TABLE Request
The following TABLE request against the WF_RETAIL data source uses the DB_EXPR function in
the COMPUTE command to call two DB2 functions. It calls the BIGINT function to convert the
squared revenue to a BIGINT data type, and then uses the CHAR function to convert that value
to alphanumeric.
TABLE FILE WF_RETAIL
SUM REVENUE NOPRINT
AND COMPUTE BIGREV/A31 = DB_EXPR(CHAR(BIGINT("REVENUE" * "REVENUE") ) ) ;
AS 'Alpha Square Revenue'
BY REGION
ON TABLE SET PAGE NOPAGE
END
WF_RETAIL is a sample data source you can create by right-clicking an application on the
Reporting Server Web Console and pointing to New and then clicking Tutorials from the context
menu.
The trace shows that the expression from the DB_EXPR function was inserted into the DB2
SELECT statement:
SELECT
T11."REGION",
SUM(T1."Revenue"),
((CHAR(BIGINT( SUM(T1."Revenue") * SUM(T1."Revenue")) ) ))
FROM
wrd_fact_sales T1,
wrd_dim_customer T5,
wrd_dim_geography T11
WHERE
(T5."ID_CUSTOMER" = T1."ID_CUSTOMER") AND
(T11."ID_GEOGRAPHY" = T5."ID_GEOGRAPHY")
GROUP BY
T11."REGION "
ORDER BY
T11."REGION "
FOR FETCH ONLY;
END
310
10. Data Source and Decoding Functions
The target file can be any data source that WebFOCUS can read. Depending on the data
sources accessed and the components in the request, either WebFOCUS or an RDBMS will
process the comparison of values.
If WebFOCUS processes the comparison, it reads the target data source and dynamically
creates a sequential file containing the target data values, along with a synonym describing the
data file. It then builds IF or WHERE structures in memory with all combinations of source and
target values. If the target data contains characters that WebFOCUS considers wildcard
characters, it will treat them as wildcard characters unless the command SET EQTEST = EXACT
is in effect.
The following situations exist when a relational data source is the source file:
The target values are in a relational data source from the same RDBMS and connection.
In this case, the target file referenced by DB_INFILE can be:
An SQL file containing a subquery that retrieves the target values. A synonym must exist
that describes the target SQL file. The Access File must specify the CONNECTION and
DATASET for the target file.
If the subquery results in a SELECT statement supported by the RDBMS, the relational
adapter inserts the subquery into the WHERE predicate of the generated SQL.
If the subquery does not result in a valid SELECT statement for the RDBMS, the
relational adapter retrieves the target values. It then generates a WHERE predicate, with
a list of all combinations of source and target field values.
You can create an SQL file containing a subquery and a corresponding synonym using
the HOLD FORMAT SQL_SCRIPT command. For more information, see theCreating
Reports With WebFOCUS Languagemanual.
A relational data source. A synonym must exist that describes the target data source.
If the data source contains only those fields referenced by DB_INFILE as target fields,
the relational adapter creates a subquery that retrieves the target values. If the
subquery results in a SELECT statement supported by the RDBMS, the relational
adapter inserts the subquery into the WHERE predicate of the generated SQL.
If the subquery does not result in a valid SELECT statement for the RDBMS, the
relational adapter retrieves a unique list of the target values. It then generates a
WHERE predicate with a list of all combinations of source and target field values.
The target values are in a non-relational data source or a relational data source from a
different RDBMS or connection. In this case, the target values are retrieved and passed to
WebFOCUS for processing.
Syntax: How to Compare Source and Target Field Values With DB_INFILE
where:
target_file
Is the synonym for the target file.
s1, ..., sn
Are fields from the source file.
t1, ..., tn
Are fields from the target file.
The function returns the value 1 if a set of target values matches the set of source values.
Otherwise, the function returns a zero (0).
Values are not padded or truncated when compared, except when comparing date and date-
time values.
If the source field is a date field and the target field is a date-time field, the time
component is removed before comparison.
If the source field is a date-time field and the target field is a date field, a zero time
component is added to the target value before comparison.
If WebFOCUS processes the comparison, and the target data contains characters that
WebFOCUS considers wildcard characters, it will treat them as wildcard characters unless
the command SET EQTEST = EXACT is in effect.
312
10. Data Source and Decoding Functions
Example: Comparing Source and Target Values Using an SQL Subquery File
This example uses the WF_RETAIL DB2 data source.
WF_RETAIL is a sample data source you can create by right-clicking an application on the
Reporting Server Web Console, selecting New, and then Samples from the context menu.
The SQL file named retail_subquery.sql contains the following subquery that retrieves specified
state codes in the Central and NorthEast regions:
SELECT MAX(T11.REGION), MAX(T11.STATECODE) FROM wrd_dim_geography T11
WHERE (T11.STATECODE IN('AR', 'IA', 'KS', 'KY', 'WY', 'CT', 'MA', 'NJ',
'NY', 'RI')) AND (T11.REGION IN('Central', 'NorthEast')) GROUP BY
T11.REGION, T11.STATECODE
Note: You can create an SQL subquery file, along with a corresponding synonym, using the
HOLD FORMAT SQL_SCRIPT command. For more information, see the Creating Reports With
WebFOCUS Language manual.
The following request uses the DB_INFILE function to compare region names and state codes
against the names retrieved by the subquery:
TABLE FILE WF_RETAIL
SUM REVENUE
BY REGION
BY STATECODE
WHERE DB_INFILE(RETAIL_SUBQUERY, REGION, REGION, STATECODE, STATECODE)
ON TABLE SET PAGE NOPAGE
END
The trace shows that the subquery was inserted into the WHERE predicate in the generated
SQL:
SELECT
T11."REGION",
T11."STATECODE",
SUM(T1."Revenue")
FROM
wrd_fact_sales T1,
wrd_dim_customer T5,
wrd_dim_geography T11
WHERE
(T5."ID_CUSTOMER" = T1."ID_CUSTOMER") AND
(T11."ID_GEOGRAPHY" = T5."ID_GEOGRAPHY") AND
((T11."REGION", T11."STATECODE") IN (SELECT MAX(T11.REGION),
MAX(T11.STATECODE) FROM wrd_dim_geography T11 WHERE
(T11.STATECODE IN('AR', 'IA', 'KS', 'KY', 'WY', 'CT', 'MA',
'NJ', 'NY', 'RI')) AND (T11.REGION IN('Central', 'NorthEast'))
GROUP BY T11.REGION, T11.STATECODE))
GROUP BY
T11."REGION",
T11."STATECODE "
ORDER BY
T11."REGION",
T11."STATECODE "
FOR FETCH ONLY;
END
314
10. Data Source and Decoding Functions
The empvalues.mas Master File describes the data in the empvalues.ftm file
FILENAME=EMPVALUES, SUFFIX=FIX , IOTYPE=BINARY, $
SEGMENT=EMPVALUE, SEGTYPE=S0, $
FIELDNAME=LN, ALIAS=E01, USAGE=A15, ACTUAL=A16, $
FIELDNAME=FN, ALIAS=E02, USAGE=A10, ACTUAL=A12, $
Note: You can create a sequential file, along with a corresponding synonym, using the HOLD
FORMAT SQL_SCRIPT command. For more information, see the Creating Reports With
WebFOCUS Language manual.
The following request against the FOCUS EMPLOYEE data source uses the DB_INFILE function
to compare employee names against the names stored in the empvalues.ftm file:
where:
DEFAULT
Enables DB_INFILE to create a subquery if its analysis determines that it is possible. This
is the default value.
EXPAND_ALWAYS
Prevents DB_INFILE from creating a subquery. Instead, it expands the expression into IF
and WHERE clauses in memory.
316
10. Data Source and Decoding Functions
EXPAND_NEVER
Prevents DB_INFILE from expanding the expression into IF and WHERE clauses in memory.
Instead, it attempts to create a subquery. If this is not possible, a FOC32585 message is
generated and processing halts.
You can use the DB_LOOKUP function to retrieve a value from one data source when running a
request against another data source, without joining or combining the two data sources.
DB_LOOKUP compares pairs of fields from the source and lookup data sources to locate
matching records and retrieve the value to return to the request. You can specify as many
pairs as needed to get to the lookup record that has the value you want to retrieve. If your field
list pairs do not lead to a unique lookup record, the first matching lookup record retrieved is
used.
There are no restrictions on the source file. The lookup file can be any non-FOCUS data source
that is supported as the cross referenced file in a cluster join. The lookup fields used to find
the matching record are subject to the rules regarding cross-referenced join fields for the
lookup data source. A fixed format sequential file can be the lookup file if it is sorted in the
same order as the source file.
where:
look_mf
Is the lookup Master File.
srcfld1, srcfld2 ...
Are fields from the source file used to locate a matching record in the lookup file.
lookfld1, lookfld2 ...
Are columns from the lookup file that share values with the source fields. Only columns in
the table or file can be used; columns created with DEFINE cannot be used. For multi-
segment synonyms, only columns in the top segment can be used.
returnfld
Is the name of a column in the lookup file whose value is returned from the matching
lookup record. Only columns in the table or file can be used; columns created with DEFINE
cannot be used.
If the lookup file is a fixed format sequential file, it must be sorted and retrieved in the
same order as the source file, unless the ENGINE INT SET CACHE=ON command is in
effect. Having this setting in effect may also improve performance if the values will be
looked up more than once. The key field of the sequential file must be the first lookup field
specified in the DB_LOOKUP request. If it is not, no records will match.
If the lookup field has the MISSING=ON attribute in its Master File and the DEFINE or
COMPUTE command specifies MISSING ON, the missing value is returned when the lookup
field is missing. Without MISSING ON in both places, the missing value is converted to a
default value (blank for an alphanumeric field, zero for a numeric field).
Source records display on the report output even if they lack a matching record in the
lookup file.
Only real fields in the lookup Master File are valid as lookup and return fields.
If there are multiple rows in the lookup table where the source field is equal to the lookup
field, the first value of the return field is returned.
318
10. Data Source and Decoding Functions
Example: Retrieving a Value From a Fixed Format Sequential File in a TABLE Request
The following procedure creates a fixed format sequential file named GSALE from the GGSALES
data source. The fields in this file are PRODUCT (product description), CATEGORY (product
category), and PCD (product code). The file is sorted on the PCD field:
SET ASNAMES = ON
TABLE FILE GGSALES
SUM PRODUCT CATEGORY
BY PCD
ON TABLE HOLD AS GSALE FORMAT ALPHA
END
FILENAME=GSALE, SUFFIX=FIX , $
SEGMENT=GSALE, SEGTYPE=S1, $
FIELDNAME=PCD, ALIAS=E01, USAGE=A04, ACTUAL=A04, $
FIELDNAME=PRODUCT, ALIAS=E02, USAGE=A16, ACTUAL=A16, $
FIELDNAME=CATEGORY, ALIAS=E03, USAGE=A11, ACTUAL=A11, $
The following TABLE request against the GGPRODS data source, sorts the report on the field
that matches the key field in the lookup file. It retrieves the value of the CATEGORY field from
the GSALE lookup file by matching on the product code and product description fields. Note
that the DEFINE FILE command is cleared at the end of the request:
Because the GSALE Master File does not define the CATEGORY field with the MISSING=ON
attribute, the PCAT column displays a blank in those rows that have no matching record in the
lookup file:
If you add the MISSING=ON attribute to the CATEGORY field in the GSALE Master File, the
PCAT column displays a missing data symbol in rows that do not have a matching record in the
lookup file:
Product
Code Product PCAT
------- ------- ----
B141 Hazelnut .
B142 French Roast .
B144 Kona .
F101 Scone Food
F102 Biscotti Food
F103 Croissant Food
G100 Mug Gifts
G104 Thermos Gifts
G110 Coffee Grinder Gifts
G121 Coffee Pot Gifts
The DECODE function assigns values based on the coded value of an input field. DECODE is
useful for giving a more meaningful value to a coded value in a field. For example, the field
GENDER may have the code F for female employees and M for male employees for efficient
storage (for example, one character instead of six for female). DECODE expands (decodes)
these values to ensure correct interpretation on a report.
You can use DECODE by supplying values directly in the function or by reading values from a
separate file.
The use of DECODE with Maintain is limited. For information on decoding values with
subscripted stack values, see SELECTS: Decoding a Value From a Stack on page 292.
320
10. Data Source and Decoding Functions
where:
fieldname
Alphanumeric or Numeric
Is the coded value that DECODE compares with the current value of fieldname. If the value
has embedded blanks, commas, or other special characters, it must be enclosed in single
quotation marks. When DECODE finds the specified value, it returns the corresponding
result. When the code is compared to the value of the field name, the code and field name
must be in the same format.
result
Alphanumeric or Numeric
Is the returned value that corresponds to the code. If the result has embedded blanks or
commas, or contains a negative number, it must be enclosed in single quotation marks.
Do not use double quotation marks (").
Is the value returned as a result for non-matching codes. The format must be the same as
the format of result. If you omit a default value, DECODE assigns a blank or zero to non-
matching codes.
filename
Alphanumeric
Is the name of the file in which code/result pairs are stored. Every record in the file must
contain a pair.
You can use up to 40 lines to define the code and result pairs for any given DECODE function,
or 39 lines if you also use an ELSE phrase. Use either a comma or blank to separate the code
from the result, or one pair from another.
If each record in the file consists of only one element, this element is interpreted as the
code, and the result becomes either a blank or zero, as needed.
This makes it possible to use the file to hold screening literals referenced in the screening
condition:
IF field IS (filename)
TAKE is 0 for SELECT values found in the literal file and 1 in all other cases. The VALUE
computation is carried out as if the expression had been:
322
10. Data Source and Decoding Functions
All data is interpreted in ASCII format on UNIX and Windows, or in EBCDIC format on z/OS,
and converted to the USAGE format of the DECODE pairs.
The remainder of each record is ignored and can be used for comments or other data. This
convention applies in all cases, except when the file name is HOLD. In that case, the file is
presumed to have been created by the HOLD command, which writes fields in the internal
format, and the DECODE pairs are interpreted accordingly. In this case, extraneous data in
the record is ignored.
The FIND function determines if a data value is in a data source field being searched. The
function sets a temporary field to 1 (a non-zero value for MODIFY) if the data value is found in
the data source field, and to 0 if it is not. FIND does not change the searched file's current
database position. A value greater than zero confirms the presence of the data value, not the
number of instances in the data source field.
You can also use FIND in a VALIDATE command to determine if a transaction field value exists
in another FOCUS data source. If the field value is not in that data source, the function returns
a value of 0, causing the validation test to fail and the request to reject the transaction.
You can use any number of FINDs in a COMPUTE or VALIDATE command. However, more FINDs
increase processing time and require more buffer space in memory.
Limit: FIND does not work on files with different DBA passwords.
The opposite of FIND is NOT FIND. The NOT FIND function sets a temporary field to 1 if the
incoming value is not in the data source and to 0 if the incoming value is in the data source.
where:
fieldname
Is the name of the field that contains the incoming data value.
AS dbfield
Is the name of the data source field whose values are compared to the incoming field
values.
For Maintain - the AS field is required and the name must be qualified.
file
Is the name of the FOCUS data source.
For Maintain - the IN file is unnecessary since the AS field name is required and must be
qualified.
Note:
324
10. Data Source and Decoding Functions
Example: Verifying the Existence of a Value in the Same Data Source (Maintain)
In the following example, FIND determines if a data value is found in the same data source.
MAINTAIN FILE CAR
COMPUTE RETAIL_COST=31500;
COMPUTE CHECK/I1;
COMPUTE CHECK= FIND (RETAIL_COST);
IF CHECK = 1 THEN GOTO FOUND1
ELSE GOTO NOT1;
CASE FOUND1
TYPE "THERE IS A CAR WITH A RETAIL_COST OF <<RETAIL_COST"
-* ....
ENDCASE
CASE NOT1
TYPE "THERE IS NO CAR WITH A RETAIL_COST OF <<RETAIL_COST"
-*....
ENDCASE
-*....
END
In place of eliminating data records with missing values from analysis, IMPUTE enables you to
substitute a variety of estimates for the missing values, including the mean, the median, the
mode, or a numeric constant, all calculated within the data partition specified by the reset key.
This function is designed to be used with detail level reports (PRINT or LIST commands), and
with calculated values (fields created with the COMPUTE command).
where:
field
Is the name of the numeric input field that is defined with MISSING ON.
reset_key
Defines the partition for the calculation. Valid values are:
PRESET, which uses the break defined by the SET PARTITION_ON command.
MEAN
MEDIAN
MODE
326
10. Data Source and Decoding Functions
SEGNAME=STOR_SEG, SEGTYPE=S1,
FIELDNAME=STORE_CODE, ALIAS=SNO, FORMAT=A3, $
FIELDNAME=CITY, ALIAS=CTY, FORMAT=A15, $
FIELDNAME=AREA, ALIAS=LOC, FORMAT=A1, $
The following procedure creates the SALEMISS data source and then adds the missing values
to the RETURNS and DAMAGED fields:
CREATE FILE ibisamp/SALEMISS
MODIFY FILE ibisamp/SALEMISS
FIXFORM STORE_CODE/3 CITY/15 AREA/1 DATE/4 PROD_CODE/3
FIXFORM UNIT_SOLD/5 RETAIL_PRICE/5 DELIVER_AMT/5
FIXFORM OPENING_AMT/5 RETURNS/3 DAMAGED/3
MATCH STORE_CODE
ON NOMATCH INCLUDE
ON MATCH CONTINUE
MATCH DATE
ON NOMATCH INCLUDE
ON MATCH CONTINUE
MATCH PROD_CODE
ON NOMATCH INCLUDE
ON MATCH REJECT
DATA
14BSTAMFORD S1212B10 60 .95 80 65 10 6
14BSTAMFORD S1212B12 40 1.29 20 50 3 3
14BSTAMFORD S1212B17 29 1.89 30 30 2 1
14BSTAMFORD S1212C13 25 1.99 30 40 3 0
14BSTAMFORD S1212C7 45 2.39 50 49 5 4
14BSTAMFORD S1212D12 27 2.19 40 35 0 0
14BSTAMFORD S1212E2 80 .99 100 100 9 4
14BSTAMFORD S1212E3 70 1.09 80 90 8 9
14ZNEW YORK U1017B10 30 .85 30 10 2 3
14ZNEW YORK U1017B17 20 1.89 40 25 2 1
14ZNEW YORK U1017B20 15 1.99 30 5 0 1
14ZNEW YORK U1017C17 12 2.09 10 15 0 0
14ZNEW YORK U1017D12 20 2.09 30 10 3 2
14ZNEW YORK U1017E1 30 .89 25 45 4 7
14ZNEW YORK U1017E3 35 1.09 25 45 4 2
77FUNIONDALE R1018B20 25 2.09 40 25 1 1
77FUNIONDALE R1018C7 40 2.49 40 40 0 0
K1 NEWARK U1019B12 29 1.49 30 30 1 0
K1 NEWARK U1018B10 13 .99 30 15 1 1
END
-RUN
328
10. Data Source and Decoding Functions
The following request against the SALEMISS data source generates replacement values for the
missing values in the RETURNS field, using only the values within the same store.
SET PARTITION_ON=FIRST
TABLE FILE SALEMISS
PRINT RETURNS
COMPUTE MEDIAN1 = IMPUTE(RETURNS, PRESET, MEDIAN);
COMPUTE MEAN1 = IMPUTE(RETURNS, PRESET, MEAN);
COMPUTE MODE1 = IMPUTE(RETURNS, PRESET, MODE);
BY STORE_CODE
ON TABLE SET PAGE NOPAGE
ON TABLE SET STYLE *
TYPE=REPORT, GRID=OFF,$
ENDSTYLE
END
The output is shown in the following image. The missing values occur in store 14Z, and the
replacement values are calculated using only the RETURNS values from that store because
PARTITION_ON is set to FIRST.
330
10. Data Source and Decoding Functions
Changing the PARTITION_ON setting to TABLE produces the following output, in which the
replacement values are calculated using all of the rows in the table.
In a DEFINE command, the LAST value applies to the previous record retrieved from the
data source before sorting takes place.
In a COMPUTE command, the LAST value applies to the record in the previous line of the
internal matrix.
LAST fieldname
where:
fieldname
Alphanumeric or Numeric
332
10. Data Source and Decoding Functions
The LOOKUP function retrieves a data value from a cross-referenced FOCUS data source in a
MODIFY request. You can retrieve data from a data source cross-referenced statically in a
Master File or a data source joined dynamically to another by the JOIN command. LOOKUP
retrieves a value, but does not activate the field. LOOKUP is required because a MODIFY
request, unlike a TABLE request, cannot read cross-referenced data sources freely.
LOOKUP allows a request to use the retrieved data in a computation or message, but it does
not allow you to modify a cross-referenced data source.
To modify more than one data source in one request, use the COMBINE command or the
Maintain Data facility.
LOOKUP can read a cross-referenced segment that is linked directly to a segment in the host
data source (the host segment). This means that the cross-referenced segment must have a
segment type of KU, KM, DKU, or DKM (but not KL or KLU) or must contain the cross-
referenced field specified by the JOIN command. Because LOOKUP retrieves a single cross-
referenced value, it is best used with unique cross-referenced segments.
The field containing the retrieved value. Alternatively, you can retrieve all the fields in a
segment at one time. The field, or your decision to retrieve all the fields, is specified in
LOOKUP.
For example, LOOKUP retrieves all the fields from the segment
RTN = LOOKUP(SEG.DATE_ATTEND);
The cross-referenced field. This field shares values with a field in the host segment called
the host field. These two fields link the host segment to the cross-referenced segment.
LOOKUP uses the cross-referenced field, which is indexed, to locate a specific segment
instance.
When using LOOKUP, the MODIFY request reads a transaction value for the host field. It then
searches the cross-referenced segment for an instance containing this value in the cross-
referenced field:
If there are no instances of the value, the function sets a return variable to 0. If you use
the field specified by LOOKUP in the request, the field assumes a value of blank if
alphanumeric and 0 if numeric.
If there are instances of the value, the function sets the return variable to 1 and retrieves
the value of the specified field from the first instance it finds. There can be more than one
if the cross-referenced segment type is KM or DKM, or if you specified the ALL keyword in
the JOIN command.
LOOKUP(field);
where:
field
Is the name of the field to retrieve in the cross-referenced file. If the field name also exists
in the host data source, you must qualify it here. Do not include a space between LOOKUP
and the left parenthesis.
In the MATCH command that selects the host segment instance, activate the host field
with the ACTIVATE command.
In the same MATCH command, code LOOKUP after the ACTIVATE command.
This request displays the employee ID, date of salary increase, employee name, and the
employee position after the raise was granted:
The shared field is JOBCODE. You never enter a job code; the values are stored in the data
source.
334
10. Data Source and Decoding Functions
1. The request prompts you for the employee ID and date of pay increase. Enter the employee
ID 071382660 and the date 820101 (January 1, 1982).
2. The request locates the instance containing the ID 071382660, then locates the child
instance containing the date of increase 820101.
3. This child instance contains the job code A07. The ACTIVATE command makes this value
available to LOOKUP.
4. LOOKUP locates the job code A07 in the cross-referenced segment. It returns a 1 the RTN
variable and retrieves the corresponding job description SECRETARY.
5. The TYPE command displays the values:
EMPLOYEE ID: 071382660
DATE INCREASE: 82/01/01
NAME: ALFRED STEVENS
POSITION: SECRETARY
Fields retrieved by LOOKUP do not require the D. prefix. FOCUS treats the field values as
transaction values.
You may also need to activate the host field if you are using LOOKUP within a NEXT command.
This request displays the latest position held by an employee:
The following request updates an employee's classroom hours (ED_HRS). If the employee
enrolled in classes on or after January 1, 1982, the request increases the number of
classroom hours by 10%. The enrollment dates are stored in a cross-referenced segment (field
DATE_ATTEND). The shared field is the employee ID.
If an employee record is not found in the cross-referenced segment, that employee never
enrolled in a class. The transaction is rejected as an error.
336
10. Data Source and Decoding Functions
To use this feature, create the index with the INDEX parameter set to NEW (the binary tree
scheme). To determine the type of index used by a data source, enter the FDT command.
COMPUTE
LOOKUP(field action);
where:
field
Is the name of the field in the cross-referenced data source, used in a MODIFY
computation. If the field name also exists in the host data source, you must qualify it here.
action
Specifies the action the request takes. Valid values are:
EQ causes LOOKUP to take no further action if an exact match is not found. If a match is
found, the value of rcode is set to 1; otherwise, it is set to 0. This is the default.
GE causes LOOKUP to locate the instance with the next highest value of the cross-
referenced field. The value of rcode is set to 2.
LE causes LOOKUP to locate the instance with the next lowest value of the cross-
referenced field. The value of rcode is set to -2.
The following table shows the value of rcode, depending on which instance LOOKUP locates:
Value Action
NULLIF(arg1,arg2)
where:
arg1,arg2
Any type of field, constant, or expression.
Are the input parameters that are tested for equality. They must either both be numeric or
both be alphanumeric.
The output data type is the same as the input data types.
338
10. Data Source and Decoding Functions
340
Chapter 11 Simplified Date and Date-Time Functions
Simplified date and date-time functions have streamlined parameter lists, similar to
those used by SQL functions. In some cases, these simplified functions provide slightly
different functionality than previous versions of similar functions.
The simplified functions do not have an output argument. Each function returns a value
that has a specific data type.
When used in a request against a relational data source, these functions are optimized
(passed to the RDBMS for processing).
Standard date and date-time formats refer to YYMD and HYYMD syntax (dates that are
not stored in alphanumeric or numeric fields). Dates not in these formats must be
converted before they can be used in the simplified functions. Input date and date-time
parameters must provide full component dates. Literal date-time values can be used with
the DT function.
Note: The simplified date and date-time functions are not supported in Maintain Data.
In this chapter:
Syntax: How to Return the Name of the Day From a Date Expression
DAYNAME(date_exp)
where:
date_exp
Is a date or date-time expression.
342
11. Simplified Date and Date-Time Functions
DT_CURRENT_DATE()
DT_CURRENT_DATETIME(component)
where:
component
Is one of the following time precisions.
SECOND.
MILLISECOND.
MICROSECOND.
Note: The field to which the value is returned must have a format that supports the time
precision requested.
DT_CURRENT_TIME(component)
where:
component
Is one of the following time precisions.
SECOND.
MILLISECOND.
MICROSECOND.
Note: The field to which the value is returned must have a format that supports the time
precision requested.
344
11. Simplified Date and Date-Time Functions
Converting timestamp values from different localities to a common standard time enables you
to sort events into the actual event sequence.
This function requires an IANA (Internet Assigned Numbers Authority) time zone database
names (expressed as 'Area/Location') as a parameter. You can find a table of IANA TZ
database names on Wikipedia at https://en.wikipedia.org/wiki/List_of_tz_database_time_zones,
as shown in the following image.
If you do not know what Area and Location corresponds to your time zone, but you do know
your offset from GMT, or your legacy time zone name (such as EST), scroll down in the table.
There are TZ database names that correspond to these time zone identifiers, as shown in the
following image.
346
11. Simplified Date and Date-Time Functions
Note: If you use a standard IANA time zone database name in the form 'Area/Location' (for
example, 'America/New_York'), automatic adjustments are made for Daylight Savings Time. If
you use a name that corresponds to an offset from GMT or to a legacy time zone name, it is
your responsibility to account for Daylight Savings Time.
DT_TOLOCAL(datetime, timezone)
where:
datetime
Date-time
Is a date-time expression representing UTC time, containing date and time components.
timezone
Alphanumeric
Is a character expression containing the IANA time zone name of the local time, in the
form 'Area/Location' (for example, 'America/New_York').
Converting timestamp values from different localities to a common standard time enables you
to sort events into the actual event sequence.
This function requires an IANA (Internet Assigned Numbers Authority) time zone database
names (expressed as 'Area/Location') as a parameter. You can find a table of IANA TZ
database names on Wikipedia at https://en.wikipedia.org/wiki/List_of_tz_database_time_zones,
as shown in the following image.
348
11. Simplified Date and Date-Time Functions
If you do not know what Area and Location corresponds to your time zone, but you do know
your offset from GMT, or your legacy time zone name (such as EST), scroll down in the table.
There are TZ database names that correspond to these time zone identifiers, as shown in the
following image.
Note: If you use a standard IANA time zone database name in the form 'Area/Location' (for
example, 'America/New_York'), automatic adjustments are made for Daylight Savings Time. If
you use a name that corresponds to an offset from GMT or to a legacy time zone name, it is
your responsibility to account for Daylight Savings Time.
DT_TOUTC(datetime, timezone)
where:
datetime
Date-time
Is a date-time expression representing local time, containing date and time components.
timezone
Alphanumeric
Is a character expression containing the IANA time zone name of the local time, in the
form 'Area/Location' (for example, 'America/New_York').
350
11. Simplified Date and Date-Time Functions
where:
date
Date or date-time
Is the date or date-time value to be incremented, which must provide a full component
date.
component
Keyword
YEAR (1-9999).
QUARTER (1-4).
MONTH (1-12).
HOUR (0-23).
MINUTE (0-59).
SECOND (0-59).
increment
Integer
352
11. Simplified Date and Date-Time Functions
With respect to parameter validation, DTADD will not allow anything but a standard date or
a date-time value to be used in the first parameter.
The increment is not checked, and the user should be aware that decimal numbers are not
supported and will be truncated. Any combination of values that increases the YEAR beyond
9999 returns the input date as the value, with no message. If the user receives the input
date when expecting something else, it is possible there was an error.
where:
end_date
Date or date-time
Is the ending full-component date in either standard date or date-time format. If this date
is given in standard date format, all time components are assumed to be zero.
start_date
Date or date-time
Is the starting full-component date in either standard date or date-time format. If this date
is given in standard date format, all time components are assumed to be zero.
component
Keyword
YEAR (1-9999).
QUARTER (1-4).
MONTH (1-12).
HOUR (0-23).
MINUTE (0-59).
SECOND (0-59).
354
11. Simplified Date and Date-Time Functions
DTIME(datetime, component)
where:
datetime
Date-time
Is the date-time value from which to extract the time component. It can be a field name or
a date-time literal. It must provide a full component date.
component
Keyword
TIME. The complete time portion is returned. Its smallest component depends on the
input date-time format. Nanoseconds are not supported or returned.
HOUR. The time component up to and including the hour component is extracted.
MINUTE. The time component up to and including the minute component is extracted.
SECOND. The time component up to and including the second component is extracted.
TRANSTIME contains the extracted time components from TRANSDATE down to the minute.
TRANSTIME2 extracts all of the time components from the literal date-time value
2018/01/17 05:45:22.777888.
356
11. Simplified Date and Date-Time Functions
DTPART(date, component)
where:
date
Date or date-time
Is the component to extract in integer format. Valid components (and values) are:
YEAR (1-9999).
QUARTER (1-4).
MONTH (1-12).
WEEK (of the year, 1-53). This is affected by the WEEKFIRST setting.
DAY_OF_YEAR (1-366).
WEEKDAY (day of the week, 1-7). This is affected by the WEEKFIRST setting.
HOUR (0-23).
MINUTE (0-59).
SECOND (0-59).
MILLISECOND (0-999).
MICROSECOND (0-999999).
358
11. Simplified Date and Date-Time Functions
DTRUNC(date_or_timestamp, date_period)
where:
date_or_timestamp
Date or date-time
Is the date or timestamp of interest, which must provide a full component date.
date_period
Is the period whose starting or ending date you want to find. Can be one of the following:
DAY, returns the date that represents the input date (truncates the time portion, if
there is one).
WEEK, returns the date that represents the first date of the given week.
By default, the first day of the week will be Sunday, but this can be changed using the
WEEKFIRST parameter.
360
11. Simplified Date and Date-Time Functions
Example: Returning the Date of the First and Last Days of a Week
The following request returns the dates that correspond to the first day of the week and the
last day of the week for the given date.
DEFINE FILE WF_RETAIL
WEEKSTART/YYMD = DTRUNC(START_DATE, WEEK);
WEEKEND/YYMD = DTRUNC(START_DATE, WEEK_END);
END
TABLE FILE WF_RETAIL
PRINT START_DATE WEEKSTART AS 'Start,of Week'
WEEKEND AS 'End,of Week'
BY EMPLOYEE_NUMBER
WHERE EMPLOYEE_NUMBER CONTAINS 'AH1'
ON TABLE SET PAGE NOPAGE
END
Syntax: How to Return the Name of the Month From a Date Expression
MONTHNAME(date_exp)
where:
date_exp
Is a date or date-time expression.
362
11. Simplified Date and Date-Time Functions
364
Chapter 12 Date Functions
Date functions manipulate date values. There are two types of date functions:
If a date is in an alphanumeric or numeric field that contains date display options (for
example, I6YMD), you must use the legacy date functions.
In this chapter:
Standard date functions are for use with standard date formats, or just date formats. A
date format refers to internally stored data that is capable of holding date components,
such as century, year, quarter, month, and day. It does not include time components. A
synonym does not specify an internal data type or length for a date format. Instead, it
specifies display date components, such as D (day), M (month), Q (quarter), Y (2-digit year),
or YY (4-digit year). For example, format MDYY is a date format that has three date
components; it can be used in the USAGE attribute of a synonym. A real date value, such
as March 9, 2004, described by this format is displayed as 03/09/2004, by default. Date
formats can be full component and non-full component. Full component formats include all
three letters, for example, D, M, and Y. JUL for Julian can also be included. All other date
formats are non-full component. Some date functions require full component arguments for
date fields, while others will accept full or non-full components. A date format was formerly
called a smart date.
Legacy date functions are for use with legacy dates only. A legacy date refers to formats
with date edit options, such as I6YMD, A6MDY, I8YYMD, or A8MDYY. For example, A6MDY
is a 6-byte alphanumeric string. The suffix MDY indicates the order in which the date
components are stored in the field, and the prefix I or A indicates a numeric or
alphanumeric form of representation. For example, a value '030599' can be assigned to a
field with format A6MDY, which will be displayed as 03/05/99.
Date formats have an internal representation matching either numeric or alphanumeric format.
For example, A6MDY matches alphanumeric format, YYMD and I6DMY match numeric format.
When function output is a date in specified by output, it can be used either for assignment to
another date field of this format, or it can be used for further data manipulation in the
expression with data of matching formats. Assignment to another field of a different date
format, will yield a random result.
In addition to the functions discussed in this topic, there are date and time functions that are
available only in the Maintain language. For information on these functions, see Maintain-
specific Date and Time Functions on page 479.
For many functions, the output argument can be supplied either as a field name or as a format
enclosed in single quotation marks. However, if a function is called from a Dialogue Manager
command, this argument must always be supplied as a format, and if a function is called from
a Maintain procedure, this argument must always be supplied as a field name. For detailed
information about calling a function and supplying arguments, see Accessing and Calling a
Function on page 59.
366
12. Date Functions
You can affect the behavior of date functions in the following ways:
Defining which days of the week are work days and which are not. Then, when you use a
date function involving work days, dates that are not work days are ignored. For details, see
Specifying Work Days on page 367.
Determining whether to display leading zeros when a date function in Dialogue Manager
returns a date. For details, see Enabling Leading Zeros For Date and Time Functions in
Dialogue Manager on page 373.
where:
smtwtfs
Is the seven character list of days that represents your business week. The list has a
position for each day from Sunday to Saturday:
To identify a day of the week as a business day, enter the first letter of that day in that
day's position.
If a letter is not in its correct position, or if you replace a letter with a character other than
an underscore, you receive an error message.
? SET BUSDAYS
Specifying Holidays
You can specify a list of dates that are designated as holidays in your company. These dates
are excluded when using functions that perform calculations based on working days. For
example, if Thursday in a given week is designated as a holiday, the next working day after
Wednesday is Friday.
368
12. Date Functions
Each year for which data exists must be included or the holiday file is considered invalid.
Calling a date function with a date value outside the range of the holiday file returns a zero
for business day requests.
If you are subtracting two dates in 2005, and the latest date in the holiday file is
20041231, the subtraction will not be performed. One way to avoid invalidating the holiday
file is to put a date very far in the future in any holiday file you create (for example,
29991231), and then it will always be considered valid.
You may include an optional description of the holiday, separated from the date by a space.
By default, the holiday file has a file name of the form HDAYxxxx.err and is on your path, or on
z/OS under PDS deployment, is a member named HDAYxxxx of a PDS allocated to DDNAME
ERRORS. In your procedure or request, you must issue the SET HDAY=xxxx command to
identify the file or member name. Alternatively, you can define the file to have any name and
be stored anywhere or, on z/OS under PDS deployment, allocate the holiday file as a
sequential file of any name or as member HDAYxxxx of any PDS. For information about using
non-default holiday file names, see How to FILEDEF or DYNAM the Holiday File on page 370.
where:
xxxx
Is a string of text four characters long.
where:
xxxx
Is the part of the name of the holiday file after HDAY. This string must be four characters
long.
where:
HDAYxxxx
Is the logical name (DDNAME) for the holiday file, where xxxx is any four characters. You
establish this logical name by issuing the SET HDAY=xxxx command in your procedure or
request.
370
12. Date Functions
app
Is the name of the application in which the holiday file resides.
path
Is the path to the holiday file.
filename.ext
Is the name of the holiday file.
On z/OS under PDS deployment, use the following to allocate a sequential holiday file.
DYNAM ALLOC {DD|FILE} HDAYxxxx DA qualif.filename.suffix SHR REU
On z/OS under PDS deployment, use the following to allocate a holiday file that is a member of
a PDS.
DYNAM ALLOC {DD|FILE} HDAYxxxx DA qualif.filename.suffix(HDAYxxx) SHR REU
where:
HDAYxxxx
Is the DDNAME for the holiday file. Your FOCEXEC or request must set the HDAY
parameter to xxxx, where xxxx is any four characters you choose. If your holiday file is a
member of a PDS, HDAYxxxx must also be the member name.
qualif.filename.suffix
Is the fully-qualified name of the sequential file that contains the list of holidays or the PDS
with member HDAYxxxx that contains the list of holidays.
The following request against the MOVIES data source uses the FILEDEF command to define
this file as the holiday file. The logical name in the FILEDEF command is HDAYMMMM, and the
procedure issues the SET HDAY=MMMM command. It then defines the date November 2,
2011 and calculates the next business day:
FILEDEF HDAYMMMM DISK c:\ibi\holiday.data
SET HDAY = MMMM
SET BUSDAYS = _MTWTF_
DEFINE FILE MOVIES
NEWDATE/YYMD = '20111102';
NEXTDATE/YYMD = DATEADD(NEWDATE, 'BD', 1);
END
TABLE FILE MOVIES
SUM COPIES NEWDATE NEXTDATE
ON TABLE SET PAGE NOPAGE
END
The output shows that the next business day after November 2 is November 4 because
November 3 is a holiday:
Example: Allocating the Holiday File to a Sequential File on z/OS Under PDS Deployment
The following sequential file, named USER1.HOLIDAY.DATA, defines November 3, 2011 and
December 24, 2011 as holidays:
20111103
20111224
The following request against the MOVIES data source uses the DYNAM command to allocate
this file as the holiday file. The DDNAME in the DYNAM command is HDAYMMMM, and the
procedure issues the SET HDAY=MMMM command. It then defines the date November 2,
2011 and calculates the next business day:
DYNAM ALLOC DD HDAYMMMM DA USER1.HOLIDAY.DATA SHR REU
SET HDAY = MMMM
SET BUSDAYS = _MTWTF_
DEFINE FILE MOVIES
NEWDATE/YYMD = '20111102';
NEXTDATE/YYMD = DATEADD(NEWDATE, 'BD', 1);
END
TABLE FILE MOVIES
SUM COPIES NEWDATE NEXTDATE
ON TABLE SET PAGE NOPAGE
END
372
12. Date Functions
The output shows that the next business day after November 2 is November 4 because
November 3 is a holiday:
Example: Allocating the Holiday File to a PDS Member on z/OS Under PDS Deployment
The following holiday file, member HDAYMMMM in a PDS named USER1.HOLIDAY.DATA,
defines November 3, 2011 and December 24, 2011 as holidays:
20111103
20111224
The following request against the MOVIES data source uses the DYNAM command to allocate
this file as the holiday file. The DDNAME in the DYNAM command is HDAYMMMM, the member
name is also HDAYMMMM, and the procedure issues the SET HDAY=MMMM command. It
then defines the date November 2, 2011 and calculates the next business day:
The output shows that the next business day after November 2 is November 4 because
November 3 is a holiday:
Enabling Leading Zeros For Date and Time Functions in Dialogue Manager
If you use a date and time function in Dialogue Manager that returns a numeric integer format,
Dialogue Manager truncates any leading zeros. For example, if a function returns the value
000101 (indicating January 1, 2000), Dialogue Manager truncates the leading zeros,
producing 101, an incorrect date. To avoid this problem, use the LEADZERO parameter.
LEADZERO only supports an expression that makes a direct call to a function. An expression
that has nesting or another mathematical function always truncates leading zeros. For
example,
where:
ON
This represents the date January 2000 incorrectly. Setting the LEADZERO parameter in the
request as follows:
SET LEADZERO = ON
-SET &IN = '9912';
-SET &OUT = AYM(&IN, 1, 'I4');
-TYPE &OUT
0001
374
12. Date Functions
The DATEADD function adds a unit to or subtracts a unit from a full component date format. A
unit is one of the following:
Year.
Month. If the calculation using the month unit creates an invalid date, DATEADD corrects it
to the last day of the month. For example, adding one month to October 31 yields
November 30, not November 31, since November has 30 days.
Day.
Weekday. When using the weekday unit, DATEADD does not count Saturday or Sunday. For
example, if you add one day to Friday, first DATEADD moves to the next weekday, Monday,
then it adds a day. The result is Tuesday.
Business day. When using the business day unit, DATEADD uses the BUSDAYS parameter
setting and holiday file to determine which days are working days and disregards the rest. If
Monday is not a working day, then one business day past Sunday is Tuesday.
Note that when the DATEADD function calculates the next or previous business day or work
day, it always starts from a business day or work day. So if the actual day is Saturday or
Sunday, and the request wants to calculate the next business day, the function will use
Monday as the starting day, not Saturday or Sunday, and will return Tuesday as the next
business day. Similarly, when calculating the previous business day, it will use the starting day
Friday, and will return Thursday as the previous business day. You can use the DATEMOV
function to move the date to the correct type of day before using DATEADD.
DATEADD requires a date to be in date format. Since Dialogue Manager interprets a date as
alphanumeric or numeric, and DATEADD requires a standard date stored as an offset from the
base date, do not use DATEADD with Dialogue Manager unless you first convert the variable
used as the input date to an offset from the base date.
You add or subtract non day-based dates (for example, YM or YQ) directly without using
DATEADD.
where:
date
Date
increment
Integer
Is the number of date units added to or subtracted from date. If this number is not a whole
unit, it is rounded down to the next largest integer.
Note: DATEADD does not use an output argument. It uses the format of the date argument for
the result. As long as the result is a full component date, it can be assigned only to a full
component date field or to integer field.
adds one month because the number of units is less than two.
376
12. Date Functions
in which DATE is either Saturday or Sunday yields Tuesday; Saturday and Sunday are not
weekdays, so DATEADD begins with Monday and adds one.
Note that the single quotes around the number in the first argument, ‘910623’, causes it to
be treated as a natural date literal.
MAINTAIN
compute DATE1/yymd = '20000101'
compute DATE2/yymd=dateadd(date1, 'M', 2, date2);
type "DATE1 = <<DATE1 + 2 MONTHS = DATE2 = <<DATE2"
END
The DATECVT function converts the field value of any standard date format or legacy date
format into a date format (offset from the base date), in the desired standard date format or
legacy date format. If you supply an invalid format, DATECVT returns a zero or a blank.
378
12. Date Functions
Note: You can use simple assignment instead of calling this function.
where:
date
Date
Is the date to be converted. If you supply an invalid date, DATECVT returns zero. When the
conversion is performed, a legacy date obeys any DEFCENT and YRTHRESH parameter
settings supplied for that field.
in_format
Alphanumeric
Is the format of the date enclosed in single quotation marks. It is one of the following:
Is the output format enclosed in single quotation marks or a field containing the format. It
is one of the following:
A non-date format (such as I8 or A6). This format type causes DATECVT to convert the
date into a full component date and return it as a whole number in the format provided.
or
The DATEDIF function returns the difference between two full component standard dates in
units of a specified component. A component is one of the following:
Year. Using the year unit with DATEDIF yields the inverse of DATEADD. If subtracting one
year from date X creates date Y, then the count of years between X and Y is one.
Subtracting one year from February 29 produces the date February 28.
Month. Using the month component with DATEDIF yields the inverse of DATEADD. If
subtracting one month from date X creates date Y, then the count of months between X
and Y is one. If the to-date is the end-of-month, then the month difference may be rounded
up (in absolute terms) to guarantee the inverse rule.
If one or both of the input dates is the end of the month, DATEDIF takes this into account.
This means that the difference between January 31 and April 30 is three months, not two
months.
Day.
Weekday. With the weekday unit, DATEDIF does not count Saturday or Sunday when
calculating days. This means that the difference between Friday and Monday is one day.
380
12. Date Functions
Business day. With the business day unit, DATEDIF uses the BUSDAYS parameter setting
and holiday file to determine which days are working days and disregards the rest. This
means that if Monday is not a working day, the difference between Friday and Tuesday is
one day.
DATEDIF returns a whole number. If the difference between two dates is not a whole number,
DATEDIF truncates the value to the next largest integer. For example, the number of years
between March 2, 2001, and March 1, 2002, is zero. If the end date is before the start date,
DATEDIF returns a negative number.
You can find the difference between non-day based dates (for example YM or YQ) directly
without using DATEDIF.
Since Dialogue Manager interprets a date as alphanumeric or numeric, and DATEDIF requires a
standard date stored as an offset from the base date, do not use DATEDIF with Dialogue
Manager unless you first convert the variable used as the input date to an offset from the base
date.
where:
from_date
Date
Is the start date from which to calculate the difference. Is a full component date.
to_date
Date
component
Alphanumeric
Note: DATEDIF does not use an output argument because for the result it uses the format 'I8'.
Additional examples:
DATEDIF( 'March 31 2001', 'May 30 2001', 'M') yields 1 (because May 30 is not the
end of the month).
382
12. Date Functions
Note: Using the beginning of week point (BOW) will always return Monday, and using the end of
week point (EOW) will always return Friday. Also, if the date used with the DATEMOV function
falls on Saturday or Sunday, the actual date used by the function will be the moved forward to
the next Monday. If you do not want to do the calculation by moving the date from Saturday or
Sunday to Monday, or if you want the BOW to be Sunday and the EOW to be Saturday, you can
use the DTRUNC function.
Since Dialogue Manager interprets a date as alphanumeric or numeric, and DATEMOV requires
a standard date stored as an offset from the base date, do not use DATEMOV with Dialogue
Manager unless you first convert the variable used as the input date to an offset from the base
date. For example, the following converts the integer legacy date 20050131 to a smart date,
adds one month, and converts the result to an alphanumeric legacy date:
The output shows that the DATEADD function added the actual number of days in the month of
February to get to the end of the month from the end of January:
DATEMOV(date, 'move-point')
where:
date
Date
Is the date to be moved. It must be a full component format date (for example, MDYY or
YYJUL).
move-point
Alphanumeric
Is the significant point the date is moved to enclosed in single quotation marks ('). An
invalid point results in a return code of zero. Valid values are:
384
12. Date Functions
A business day calculation is affected by the BUSDAYS and HDAY parameter settings.
Note that when the DATEADD function calculates the next or previous business day or work
day, it always starts from a business day or work day. So if the actual day is Saturday or
Sunday, and the request wants to calculate the next business day, the function will use
Monday as the starting day, not Saturday or Sunday, and will return Tuesday as the next
business day. Similarly, when calculating the previous business day, it will use the starting day
Friday, and will return Thursday as the previous business day.
To avoid skipping a business day or work day, use DATEMOV. To return the next business or
work day, use BD- or WD- to first move to the previous business or work day (if it is already a
business day or work day, it will not be moved). Then use DATEADD to move to the next
business or work day. If you want to return the previous business or work day, first use BD+ or
WD+ to move to the next business or work day (if it is already the correct type of day, it will not
be moved). Then use DATEADD to return the previous business or work day.
Note: DATEMOV does not use an output argument. It uses the format of the date argument for
the result. As long as the result is a full component date, it can be assigned only to a full
component date field or to an integer field.
The following request against the GGSALES data source uses the BD (Business Day) move
point against the DATE field. First DATE is converted to a smart date, then DATEADD is called
with the BD move-point:
DEFINE FILE GGSALES
DT1/WMDYY=DATE;
DT2/WMDYY = DATEADD(DT1 ,'BD',1);
DAY/Dt = DT1;
END
When the date is on a Saturday or Sunday on the output, the next business day is returned as
a Tuesday. This is because before doing the calculation, the original date was moved to a
business day:
DT1 DT2
--- ---
SUN, 09/01/1996 TUE, 09/03/1996
FRI, 11/01/1996 MON, 11/04/1996
SUN, 12/01/1996 TUE, 12/03/1996
SAT, 03/01/1997 TUE, 03/04/1997
TUE, 04/01/1997 WED, 04/02/1997
THU, 05/01/1997 FRI, 05/02/1997
SUN, 06/01/1997 TUE, 06/03/1997
MON, 09/01/1997 TUE, 09/02/1997
WED, 10/01/1997 THU, 10/02/1997
386
12. Date Functions
In the following version of the request, DATEMOV is called to make sure the starting day is a
business day. The move point specified in the first call is BD- which only moves the date to the
prior business day if it is not already a business day. The call to DATEADD then uses the BD
move point to return the next business day:
DEFINE FILE GGSALES
DT1/WMDYY=DATE;
DT1A/WMDYY=DATEMOV(DT1, 'BD-');
DT2/WMDYY = DATEADD(DT1A,'BD',1);
DAY/Dt = DT1;
END
On the output, the next business day after a Saturday or Sunday is now returned as Monday:
DT1 DT1A DT2
--- ---- ---
SUN, 09/01/1996 FRI, 08/30/1996 MON, 09/02/1996
FRI, 11/01/1996 FRI, 11/01/1996 MON, 11/04/1996
SUN, 12/01/1996 FRI, 11/29/1996 MON, 12/02/1996
SAT, 03/01/1997 FRI, 02/28/1997 MON, 03/03/1997
TUE, 04/01/1997 TUE, 04/01/1997 WED, 04/02/1997
THU, 05/01/1997 THU, 05/01/1997 FRI, 05/02/1997
SUN, 06/01/1997 FRI, 05/30/1997 MON, 06/02/1997
MON, 09/01/1997 MON, 09/01/1997 TUE, 09/02/1997
WED, 10/01/1997 WED, 10/01/1997 THU, 10/02/1997
Example: Using a DEFINE FUNCTION to Move a Date to the Beginning of the Week
The following DEFINE FUNCTION named BOWK takes a date and the name of the day you want
to consider the beginning of the week and returns a date that corresponds to the beginning of
the week:
DEFINE FUNCTION BOWK(THEDATE/MDYY,WEEKSTART/A10)
DAYOFWEEK/W=THEDATE;
DAYNO/I1=IF DAYOFWEEK EQ 7 THEN 0 ELSE DAYOFWEEK;
FIRSTOFWK/I1=DECODE WEEKSTART('SUNDAY' 0 'MONDAY' 1 'TUESDAY' 2
'WEDNESDAY' 3 'THURSDAY' 4 'FRIDAY' 5 'SATURDAY' 6
'SUN' 0 'MON' 1 'TUE' 2 'WED' 3 'THU' 4 'FRI' 5 'SAT' 6);
BOWK/MDYY=IF DAYNO GE FIRSTOFWK THEN THEDATE-DAYNO+FIRSTOFWK
ELSE THEDATE-7-DAYNO+FIRSTOFWK;
END
The following request uses the BOWK function to use return a date (DT2) that corresponds to
the beginning of the week for each value of the DT1 field:
DEFINE FILE GGSALES
DT1/WMDYY=DATE;
DT2/WMDYY = BOWK(DT1 ,'SUN');
END
388
12. Date Functions
where:
indate
Is the input date (in date format) to be formatted. Note that the date format cannot be an
alphanumeric or numeric format with date display options (legacy date format).
390
12. Date Functions
intype
Is one of the following character strings indicating the input date components and the
order in which you want them to display, enclosed in parentheses and single quotation
marks.
formatops
Is a string of zero or more formatting options enclosed in parentheses and single quotation
marks. The parentheses and quotation marks are required even if you do not specify
formatting options. Formatting options fall into the following categories:
Date delimiter options and options for punctuating a date with commas.
Valid options for suppressing initial zeros in month or day numbers are listed in the
following table. Note that the initial zero is replaced by a blank space:
392
12. Date Functions
The following table shows valid month and day name translation options:
394
12. Date Functions
lang
Is the two-character standard ISO code for the language into which the date should be
translated, enclosed in single quotation marks ('). Valid language codes are:
'AR' Arabic
'CS' Czech
'DA' Danish
'DE' German
396
12. Date Functions
'EN' English
'ES' Spanish
'FI' Finnish
'FR' French
'EL' Greek
'IW' Hebrew
'IT' Italian
'JA' Japanese
'KO' Korean
'LT' Lithuanian
'NL' Dutch
'NO' Norwegian
'PO' Polish
'PT' Portuguese
'RU' Russian
'SV' Swedish
'TH' Thai
'TR' Turkish
Is the length of the output field in bytes. If the length is insufficient, an all blank result is
returned. If the length is greater than required, the field is padded with blanks on the right.
output
Alphanumeric
Is the name of the field that contains the translated date, or its format enclosed in single
quotation marks.
All invalid and inconsistent inputs result in all blank output strings. Missing data also
results in blank output.
The base dates (1900-12-31 and 1900-12 or 1901-01) are treated as though the
DATEDISPLAY setting were ON (that is, not automatically shown as blanks). To suppress
the printing of base dates, which have an internal integer value of 0, test for 0 before
calling DATETRAN. For example:
RESULT/A40 = IF DATE EQ 0 THEN ' ' ELSE
DATETRAN (DATE, '(YYMD)', '(.t)', 'FR', 40, 'A40');
Valid translated date components are contained in files named DTLNGlng where lng is a
three-character code that specifies the language. These files must be accessible for each
language into which you want to translate dates.
For these NLS characters to appear correctly, the Server and Client must be configured with
the correct code pages.
398
12. Date Functions
DATEW/W=TRANS1 ;
DATEW2/W=TRANS2 ;
DATEYYMD/YYMDW=TRANS1 ;
DATEYYMD2/YYMDW=TRANS2 ;
The following request prints a blank delimited date with an abbreviated month name in English.
Initial zeros in the day number are suppressed, and a suffix is added to the end of the number:
DEFINE FILE VIDEOTRK
TRANS1/YYMD=20050104;
TRANS2/YYMD=20050302;
DATEW/W=TRANS1 ;
DATEW2/W=TRANS2 ;
DATEYYMD/YYMDW=TRANS1 ;
DATEYYMD2/YYMDW=TRANS2 ;
400
12. Date Functions
The following request prints a blank delimited date, with an abbreviated month name in
German. Initial zeros in the day number are suppressed, and a period is added to the end of
the number:
DEFINE FILE VIDEOTRK
TRANS1/YYMD=20050104;
TRANS2/YYMD=20050302;
DATEW/W=TRANS1 ;
DATEW2/W=TRANS2 ;
DATEYYMD/YYMDW=TRANS1 ;
DATEYYMD2/YYMDW=TRANS2 ;
The following request prints a blank delimited date in French, with a full day name at the
beginning and a full month name, in lowercase (the default for French):
DEFINE FILE VIDEOTRK
TRANS1/YYMD=20050104;
TRANS2/YYMD=20050302;
DATEW/W=TRANS1 ;
DATEW2/W=TRANS2 ;
DATEYYMD/YYMDW=TRANS1 ;
DATEYYMD2/YYMDW=TRANS2 ;
402
12. Date Functions
The following request prints a blank delimited date in Spanish with a full day name at the
beginning in lowercase (the default for Spanish), followed by a comma, and with the word “de”
between the day number and month and between the month and year:
DEFINE FILE VIDEOTRK
TRANS1/YYMD=20050104;
TRANS2/YYMD=20050302;
DATEW/W=TRANS1 ;
DATEW2/W=TRANS2 ;
DATEYYMD/YYMDW=TRANS1 ;
DATEYYMD2/YYMDW=TRANS2 ;
The following request prints a date in Japanese characters with a full month name at the
beginning, in the default case and with zero suppression:
DEFINE FILE VIDEOTRK
TRANS1/YYMD=20050104;
TRANS2/YYMD=20050302;
DATEW/W=TRANS1 ;
DATEW2/W=TRANS2 ;
DATEYYMD/YYMDW=TRANS1 ;
DATEYYMD2/YYMDW=TRANS2 ;
404
12. Date Functions
The following request prints a blank delimited date in Greek with a full day name at the
beginning in the default case, followed by a comma, and with a full month name in the default
case:
DEFINE FILE VIDEOTRK
TRANS1/YYMD=20050104;
TRANS2/YYMD=20050302;
DATEW/W=TRANS1 ;
DATEW2/W=TRANS2 ;
DATEYYMD/YYMDW=TRANS1 ;
DATEYYMD2/YYMDW=TRANS2 ;
Since Dialogue Manager interprets a date as alphanumeric or numeric, and DPART requires a
standard date stored as an offset from the base date, do not use DPART with Dialogue
Manager unless you first convert the variable used as the input date to an offset from the base
date.
where:
datevalue
Date
Is the name of the component to be retrieved enclosed in single quotation marks. Valid
values are:
406
12. Date Functions
Is the field that contains the result, or the integer format of the output value enclosed in
single quotation marks.
DEFINE FILE
VIDEOTRK
YEAR/I4 = DPART(TRANSDATE, 'YEAR', 'I11');
MONTH/I4 = DPART(TRANSDATE, 'MM', 'I11');
DAY/I4 = DPART(TRANSDATE, 'DAY', 'I11');
END
Since Dialogue Manager interprets a date as alphanumeric or numeric, and FIQTR requires a
standard date stored as an offset from the base date, do not use FIQTR with Dialogue
Manager unless you first convert the variable used as the input date to an offset from the base
date.
where:
inputdate
Date
Is the date for which the financial year is returned. The date must be a standard date
stored as an offset from the base date.
If the financial year does not begin on the first day of a month, the date must have Y(Y), M,
and D components, or Y(Y) and JUL components (note that JUL is equivalent to YJUL).
Otherwise, the date only needs Y(Y) and M components or Y(Y) and Q components.
lowcomponent
Alphanumeric
startmonth
Numeric
1 through 12 are used to represent the starting month of the financial year, where 1
represents January and 12 represents December. If the low component is Q, the start
month must be 1, 4, 7, or 10.
startday
Numeric
408
12. Date Functions
Is the starting day of the starting month, usually 1. If the low component is M or Q, 1 is
required.
yrnumbering
Alphanumeric
FYE to specify the Financial Year Ending convention. The financial year number is the
calendar year of the ending date of the financial year. For example, when the financial year
starts on October 1, 2008, the date 2008 November 1 is in FY 2009 Q1 because that
date is in the financial year that ends on 2009 September 30.
FYS to specify the Financial Year Starting convention. The financial year number is the
calendar year of the starting date of the financial year. For example, when the financial
year starts on April 6, 2008, the date 2008 July 6 is in FY 2008 Q2 because that date is
in the financial year that starts on 2008 April 6.
output
I or Q
The result will be in integer format, or Q. This function will return a value of 1 through 4. In
case of an error, zero is returned.
On the output, note that the date November 12, 1998 (1998/11/12) is in fiscal quarter Q1
because the starting month is October (10):
Since Dialogue Manager interprets a date as alphanumeric or numeric, and FIYR requires a
standard date stored as an offset from the base date, do not use FIYR with Dialogue Manager
unless you first convert the variable used as the input date to an offset from the base date.
where:
inputdate
Date
Is the date for which the financial year is returned. The date must be a standard date
stored as an offset from the base date.
If the financial year does not begin on the first day of a month, the date must have Y(Y), M,
and D components, or Y(Y) and JUL components (note that JUL is equivalent to YJUL).
Otherwise, the date only needs Y(Y) and M components or Y(Y) and Q components.
lowcomponent
Alphanumeric
410
12. Date Functions
startmonth
Numeric
1 through 12 are used to represent the starting month of the financial year, where 1
represents January and 12 represents December. If the low component is Q, the start
month must be 1, 4, 7, or 10.
startday
Numeric
Is the starting day of the starting month, usually 1. If the low component is M or Q, 1 is
required.
yrnumbering
Alphanumeric
FYE to specify the Financial Year Ending convention. The financial year number is the
calendar year of the ending date of the financial year. For example, when the financial year
starts on October 1, 2008, the date 2008 November 1 is in FY 2009 Q1 because that
date is in the financial year that ends on 2009 September 30.
FYS to specify the Financial Year Starting convention. The financial year number is the
calendar year of the starting date of the financial year. For example, when the financial
year starts on April 6, 2008, the date 2008 July 6 is in FY 2008 Q2 because that date is
in the financial year that starts on 2008 April 6.
output
I, Y, or YY
The result will be in integer format, or Y or YY. This function returns a year value. In case
of an error, zero is returned.
On the output, note that the period April 2002 (2002/04) is in fiscal year 2003 because the
starting month is April (4), and the FYE numbering convention is used:
Ledger
Account PERIOD FISCALYY FISCALY FISCALI
------- ------ -------- ------- -------
1000 2002/01 2002 02 2002
2002/02 2002 02 2002
2002/03 2002 02 2002
2002/04 2003 03 2003
2002/05 2003 03 2003
2002/06 2003 03 2003
2000 2002/01 2002 02 2002
2002/02 2002 02 2002
2002/03 2002 02 2002
2002/04 2003 03 2003
2002/05 2003 03 2003
2002/06 2003 03 2003
Since Dialogue Manager interprets a date as alphanumeric or numeric, and FIYYQ requires a
standard date stored as an offset from the base date, do not use FIYYQ with Dialogue
Manager unless you first convert the variable used as the input date to an offset from the base
date.
412
12. Date Functions
where:
inputdate
Date
Is the date for which the financial year is returned. The date must be a standard date
stored as an offset from the base date.
If the financial year does not begin on the first day of a month, the date must have Y(Y), M,
and D components, or Y(Y) and JUL components (note that JUL is equivalent to YJUL).
Otherwise, the date only needs Y(Y) and M components or Y(Y) and Q components.
lowcomponent
Alphanumeric
startmonth
Numeric
1 through 12 are used to represent the starting month of the financial year, where 1
represents January and 12 represents December. If the low component is Q, the start
month must be 1, 4, 7, or 10.
startday
Numeric
Is the starting day of the starting month, usually 1. If the low component is M or Q, 1 is
required.
yrnumbering
Alphanumeric
FYE to specify the Financial Year Ending convention. The financial year number is the
calendar year of the ending date of the financial year. For example, when the financial year
starts on October 1, 2008, the date 2008 November 1 is in FY 2009 Q1 because that
date is in the financial year that ends on 2009 September 30.
FYS to specify the Financial Year Starting convention. The financial year number is the
calendar year of the starting date of the financial year. For example, when the financial
year starts on April 6, 2008, the date 2008 July 6 is in FY 2008 Q2 because that date is
in the financial year that starts on 2008 April 6.
output
Y[Y]Q or QY[Y]
414
12. Date Functions
On the output, note that the date November 12, 1998 (1998/11/12) is converted to Q1 1999
because the starting month is October (10), and the FYE numbering convention is used:
The TODAY function retrieves the current date from the operating system in the format
MM/DD/YY or MM/DD/YYYY. It always returns a date that is current. Therefore, if you are
running an application late at night, use TODAY. You can remove the default embedded
slashes with the EDIT function.
You can also retrieve the date in the same format (separated by slashes) using the Dialogue
Manager system variable &DATE. You can retrieve the date without the slashes using the
system variables &YMD, &MDY, and &DMY. The system variable &DATEfmt retrieves the date
in a specified format.
TODAY(output)
where:
output
Alphanumeric, at least A8
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
DMY, MDY, YMD: Calculating the Difference Between Two Dates on page 426
DOWK and DOWKL: Finding the Day of the Week on page 427
416
12. Date Functions
All legacy date functions support dates for the year 2000 and later.
418
12. Date Functions
The AYM function adds months to or subtracts months from a date in year-month format. You
can convert a date to this format using the CHGDAT or EDIT function.
where:
indate
I4, I4YM, I6, or I6YYM
Is the legacy date in year-month format, the name of a field that contains the date, or an
expression that returns the date. If the date is not valid, the function returns the value 0
(zero).
months
Integer
Is the number of months you are adding to or subtracting from the date. To subtract
months, use a negative number.
output
I4YM or I6YYM
Is the resulting legacy date. Is the name of the field that contains the result, or the format
of the output value enclosed in single quotation marks.
Tip: If the input date is in integer year-month-day format (I6YMD or I8YYMD), divide the
date by 100 to convert to year-month format and set the result to an integer. This drops
the day portion of the date, which is now after the decimal point.
The AYMD function adds days to or subtracts days from a date in year-month-day format. You
can convert a date to this format using the CHGDAT or EDIT function.
where:
indate
I6, I6YMD, I8, I8YYMD
Is the legacy date in year-month-day format. If the date is not valid, the function returns the
value 0 (zero).
days
Integer
Is the number of days you are adding to or subtracting from indate. To subtract days, use a
negative number.
420
12. Date Functions
output
I6, I6YMD, I8, or I8YYMD
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks. If indate is a field, output must have the same format.
If the addition or subtraction of days crosses forward or backward into another century, the
century digits of the output year are adjusted.
The CHGDAT function rearranges the year, month, and day portions of an input character string
representing a date. It may also convert the input string from long to short or short to long date
representation. Long representation contains all three date components: year, month, and day;
short representation omits one or two of the date components, such as year, month, or day.
The input and output date strings are described by display options that specify both the order
of date components (year, month, day) in the date string and whether two or four digits are
used for the year (for example, 04 or 2004). CHGDAT reads an input date character string and
creates an output date character string that represents the same date in a different way.
Note: CHGDAT requires a date character string as input, not a date itself. Whether the input is
a standard or legacy date, convert it to a date character string (using the EDIT or DATECVT
functions, for example) before applying CHGDAT.
The order of date components in the date character string is described by display options
comprised of the following characters in your chosen order:
Character Description
To spell out the month rather than use a number in the resulting string, append one of the
following characters to the display options for the resulting string:
Character Description
Display options can consist of up to five display characters. Characters other than those
display options are ignored.
For example: The display options 'DMYY' specify that the date string starts with a two digit
day, then two digit month, then four digit year.
Month (for example, from Y to YM) Last month of the year (December).
422
12. Date Functions
Converting year from two-digit to four-digit The century will be determined by the 100-year
(for example, from YMD to YYMD) window defined by DEFCENT and YRTHRESH.
CHGDAT('in_display_options','out_display_options',date_string,output)
where:
'in_display_options'
A1 to A5
Is a series of up to five display options that describe the layout of date_string. These
options can be stored in an alphanumeric field or supplied as a literal enclosed in single
quotation marks.
'out_display_options'
A1 to A5
Is a series of up to five display options that describe the layout of the converted date
string. These options can be stored in an alphanumeric field or supplied as a literal
enclosed in single quotation marks.
date_string
A2 to A8
Is the input date character string with date components in the order specified by
in_display_options.
Note that if the original date is in numeric format, you must convert it to a date character
string. If date_string does not correctly represent the date (the date is invalid), the function
returns blank spaces.
output
Axx, where xx is a number of characters large enough to fit the date string specified by
out_display_options. A17 is long enough to fit the longest date string.
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
Note: Since CHGDAT uses a date string (as opposed to a date) and returns a date string with
up to 17 characters, use the EDIT or DATECVT functions or any other means to convert the
date to or from a date character string.
The DA functions convert a legacy date to the number of days between it and a base date
(December 31, 1899). By converting a date to the number of days, you can add and subtract
dates and calculate the intervals between them, or you can add to or subtract numbers from
the dates to get new dates.
There are six DA functions; each one accepts a date in a different format.
424
12. Date Functions
function(indate, output)
where:
function
Is one of the following:
indate
I6xxx or P6xxx, where xxx corresponds to the function DAxxx you are using.
Is the legacy date to be converted, or the name of a field that contains the date. The date
is truncated to an integer before conversion. If indate is a numeric literal, enter only the
last two digits of the year; the function assumes the century component. If the date is
invalid, the function returns a 0.
output
Integer
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks. The format of the date returned depends on the function.
The DMY, MDY, and YMD functions calculate the difference between two legacy dates in
integer, alphanumeric, or packed format.
function(from_date, to_date)
where:
function
Is one of the following:
from_date
I, P, or A format with date display options.
Is the beginning legacy date, or the name of a field that contains the date.
to_date
I, P, or A format with date display options.I6xxx or I8xxx where xxx corresponds to the
specified function (DMY, YMD, or MDY).
Is the end date, or the name of a field that contains the date.
426
12. Date Functions
The DOWK and DOWKL functions find the day of the week that corresponds to a date. DOWK
returns the day as a three letter abbreviation; DOWKL displays the full name of the day.
{DOWK|DOWKL}(indate, output)
where:
indate
I6YMD or I8YYMD
Is the legacy date in year-month-day format. If the date is not valid, the function returns
spaces. If the date specifies a two digit year and DEFCENT and YRTHRESH values have not
been set, the function assumes the 20th century.
output
DOWK: A4. DOWKL: A12
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
The DT functions convert an integer representing the number of days elapsed since December
31, 1899 to the corresponding date. They are useful when you are performing arithmetic on a
date converted to the number of days. The DT functions convert the result back to a date.
There are six DT functions; each one converts a number into a date of a different format.
Note: When USERFNS is set to LOCAL, DT functions only display a six-digit date.
428
12. Date Functions
function(number, output)
where:
function
Is one of the following:
number
Integer
Is the number of days since December 31, 1899. The number is truncated to an integer.
output
I8xxx, where xxx corresponds to the function DTxxx in the above list.
Is the name of the field containing the result or the format of the output value enclosed in
single quotation marks. The output format depends on the function being used.
The GREGDT function converts a date in Julian format (year-day) to Gregorian format (year-
month-day).
A date in Julian format is a five- or seven-digit number. The first two or four digits are the year;
the last three digits are the number of the day, counting from January 1. For example, January
1, 1999 in Julian format is either 99001 or 1999001; June21, 2004 in Julian format is
2004173.
430
12. Date Functions
GREGDT(indate, output)
where:
indate
I5 or I7
Is the Julian date, which is truncated to an integer before conversion. Each value must be
a five- or seven-digit number after truncation. If the date is invalid, the function returns a 0
(zero).
output
I6, I8, I6YMD, or I8YYMD
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
The JULDAT function converts a date from Gregorian format (year-month-day) to Julian format
(year-day). A date in Julian format is a five- or seven-digit number. The first two or four digits
are the year; the last three digits are the number of the day, counting from January 1. For
example, January 1, 1999 in Julian format is either 99001 or 1999001.
JULDAT(indate, output)
where:
indate
I6, I8, I6YMD, I8YYMD
Is the legacy date to convert or the name of the field that contains the date in year-month-
day format (YMD or YYMD).
output
I5 or I7
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
432
12. Date Functions
The YM function calculates the number of months between two dates. The dates must be in
year-month format. You can convert a date to this format by using the CHGDAT or EDIT
function.
where:
fromdate
I4YM or I6YYM
Is the start date in year-month format (for example, I4YM). If the date is not valid, the
function returns the value 0 (zero).
todate
I4YM or I6YYM
Is the end date in year-month format. If the date is not valid, the function returns the value
0 (zero).
output
Integer
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
434
Chapter 13 Date-Time Functions
Date-Time functions are for use with timestamps in date-time formats, also known as H
formats. A timestamp value refers to internally stored data capable of holding both date
and time components with an accuracy of up to a nanosecond.
In this chapter:
Date-Time Parameters
The DATEFORMAT parameter specifies the order of the date components for certain types of
date-time values. The WEEKFIRST parameter specifies the first day of the week. The DTSTRICT
parameter determines the extent to which date-time values are checked for validity.
where:
option
Can be one of the following: MDY, DMY, YMD, or MYD. MDY is the default value for the
U.S. English format.
DTFLDYYMD
---------
1904-04-05 00:00
436
13. Date-Time Functions
Specifying the First Day of the Week for Use in Date-Time Functions
The WEEKFIRST parameter specifies a day of the week as the start of the week. This is used in
week computations by the HADD, HDIFF, HNAME, HPART, and HYYWD functions. It is also
used by the DTADD, DTDIFF, DTRUNC, and DTPART functions. The default values are different
for these functions, as described in How to Set a Day as the Start of the Week on page 437.
The WEEKFIRST parameter does not change the day of the month that corresponds to each
day of the week, but only specifies which day is considered the start of the week.
The HPART, DTPART, HYYWD, and HNAME subroutines can extract a week number from a date-
time value. To determine a week number, they can use different definitions. For example, ISO
8601 standard week numbering defines the first week of the year as the first week in January
with four or more days. Any preceding days in January belong to week 52 or 53 of the
preceding year. The ISO standard also establishes Monday as the first day of the week.
You specify which type of week numbering to use by setting the WEEKFIRST parameter, as
described in How to Set a Day as the Start of the Week on page 437.
Since the week number returned by HNAME, DTPART, and HPART functions can be in the
current year or the year preceding or following, the week number by itself may not be useful.
The function HYYWD returns both the year and the week for a given date-time value.
where:
value
Can be:
Week numbering using these values establishes the first week in January with seven
days as week number 1. Preceding days in January belong to the last week of the
previous year. All weeks have seven days.
ISO1 through ISO7, representing Sunday through Saturday with ISO standard week
numbering.
Week numbering using these values establishes the first week in January with at least
four days as week number 1. Preceding days in January belong to the last week of the
previous year. All weeks have seven days.
STD1 through STD7, in which the digit 1 (Sunday) through 7 (Saturday) indicates the
starting day of the week.
Week numbering using these values is as follows. Week number 1 begins on January 1
and ends on the day preceding the first day of the week. For example, for STD1, the
first week ends on the first Saturday of the year. The first and last week may have
fewer than seven days.
SIMPLE, which establishes January 1 as the start of week 1, January 8 is the start of
week 2, and so on. The first day of the week is, thus, the same as the first day of the
year. The last week (week 53) is either one or two days long.
0 (zero), is the value of the WEEKFIRST setting before the user issues an explicit
WEEKFIRST setting. The date-time functions HPART, HNAME, HYYWD, HADD, and HDIFF
use Saturday as the start of the week, when the WEEKFIRST setting is 0. The simplified
functions DTADD, DTDIFF, DTRUNC, and DTPART, as well as printing of dates truncated
to weeks, and recognition of date constant strings that contain week numbers, use
Sunday as the default value, when the WEEKFIRST setting is 0. If the user explicitly
sets WEEKFIRST to another value, that value is used by all of the functions.
SET WEEKFIRST = 1
? SET WEEKFIRST
This returns the value that indicates the week numbering algorithm and the first day of the
week. For example, the integer 1 represents Sunday with non-standard week numbering.
438
13. Date-Time Functions
where:
ON
Strict processing checks date-time values when they are input by an end user, read from a
transaction file, displayed, or returned by a subroutine to ensure that they represent a
valid date and time. For example, a numeric month must be between 1 and 12, and the
day must be within the number of days for the specified month.
If DTSTRICT is ON and the result would be an invalid date-time value, the function returns
the value zero (0).
OFF
Does not invoke strict processing. Date-time components can have any value within the
constraint of the number of decimal digits allowed in the field. For example, if the field is a
two-digit month, the value can be 12 or 99, but not 115.
year yy 0001-9999
quarter qq 1-4
day-of-year dy 1-366
week wk 1-53
hour hh 0-23
minute mi 0-59
second ss 0-59
millisecond ms 0-999
microsecond mc 0-999999
nanosecond ns 0-999999999
Note:
For an argument that specifies a length of eight, ten, or 12 characters, use eight to include
milliseconds, ten to include microseconds, and 12 to include nanoseconds in the returned
value.
The last argument is always a USAGE format that indicates the data type returned by the
function. The type may be A (alphanumeric), I (integer), D (floating-point double precision),
H (date-time), or a date format (for example, YYMD).
Time components are separated by colons and may be followed by A.M., P.M., a.m., or p.m.
440
13. Date-Time Functions
The DATEFORMAT parameter specifies the order of the date components (month/day/year)
when date-time values are entered in the formatted string and translated string formats. It
makes a value’s input format independent of the format of the variable to which it is being
assigned.
String Date
99 January 1, 1999
Formatted-string Format
The formatted-string format contains a one or two-digit day, a one or two-digit month, and a two
or four-digit year, each component separated by a space, slash, hyphen, or period. All three
components must be present and follow the DATEFORMAT setting. If any of the three fields is
four digits, it is interpreted as the year, and the other two fields must follow the order given by
the DATEFORMAT setting.
1999/05/20
5 20 1999
99.05.20
1999-05-20
Translated-string Format
The translated-string format contains the full or abbreviated month name. The year must also
be present in four-digit or two-digit form. If the day is missing, day 1 of the month is assumed;
if present, it can have one or two digits. If the string contains both a two-digit year and a two-
digit day, they must be in the order given by the DATEFORMAT setting.
January 6 2000
Time Format
Time components are separated by colons and may be followed by A.M., P.M., a.m., or p.m.
Seconds can be expressed with a decimal point or be followed by a colon. If there is a colon
after seconds, the value following it represents milliseconds. There is no way to express
microseconds or nanoseconds using this notation.
A decimal point in the seconds value indicates the decimal fraction of a second. Microseconds
can be represented using six decimal digits. Nanoseconds can be represented using nine
decimal digits.
442
13. Date-Time Functions
Note that these values are stored identically internally with the STANDARDU setting. With the
STANDARD setting, everything following the Z, +, or - is ignored.
An expression that defines WHERE or IF criteria or creates a temporary field using the
DEFINE or COMPUTE command.
A date-time constant can have blanks at the beginning or end or immediately preceding an
am/pm indicator.
or
time_string [date_string]
or
DT(time_string [date_string])
In an IF expression
'date_string [time_string]'
or
'time_string [date_string]'
where:
time_string
Is a time string in acceptable format. A time string can have a blank immediately preceding
an am/pm indicator.
date_string
Is a date string in numeric string, formatted-string, or translated-string format.
In an IF criteria, if the value does not contain blanks or special characters, the single
quotation marks are not necessary.
Note: The date and time strings must be separated by at least one blank space. Blank
spaces are also permitted at the beginning and end of the date-time string.
444
13. Date-Time Functions
where:
datetime
Date-time
Is the date-time value to be incremented, the name of a date-time field that contains the
value, or an expression that returns the value.
446
13. Date-Time Functions
component
Alphanumeric
Is the number of units (positive or negative) by which to increment the component, the
name of a numeric field that contains the value, or an expression that returns the value.
length
Integer
8 indicates a date-time value that includes one to three decimal digits (milliseconds).
10 indicates a date-time value that includes four to six decimal digits (microseconds).
Is the field that contains the result, or the format of the output value enclosed in single
quotation marks. This field must be in date-time format (data type H).
The following DEFINE FUNCTION takes a number representing epoch time and converts it to a
date-time value by using the HADD function to add the number of seconds represented by the
input value in epoch time to the epoch base date:
DEFINE FUNCTION UNIX2GMT(INPUT/I9)
UNIX2GMT/HYYMDS = HADD(DT(1970 JAN 1),'SECONDS',INPUT,8,'HYYMDS');
END
The following request uses this DEFINE FUNCTION to convert the epoch time 1449068652 to
a date-time value:
DEFINE FILE GGSALES
INPUT/I9=1449068652;
OUTDATE/HMTDYYSb = UNIX2GMT(INPUT);
END
TABLE FILE GGSALES
PRINT DATE NOPRINT INPUT OUTDATE
WHERE RECORDLIMIT EQ 1
ON TABLE SET PAGE NOLEAD
END
448
13. Date-Time Functions
The HCNVRT function converts a date-time value to alphanumeric format for use with operators
such as EDIT, CONTAINS, and LIKE.
where:
datetime
Date-time
Is the date-time value to be converted, the name of a date-time field that contains the
value, or an expression that returns the value.
format
Alphanumeric
Is the format of the date-time field enclosed in parentheses and single quotation marks. It
must be a date-time format (data type H, up to H23).
length
Integer
Is the number of characters in the alphanumeric field that is returned. You can supply the
actual value, the name of a numeric field that contains the value, or an expression that
returns the value. If length is smaller than the number of characters needed to display the
alphanumeric field, the function returns a blank.
output
Alphanumeric
Is the field that contains the result, or the format of the output value enclosed in single
quotation marks. This field must be in alphanumeric format and must be long enough to
contain all of the characters returned.
The HDATE function converts the date portion of a date-time value to the date format YYMD.
You can then convert the result to other date formats.
450
13. Date-Time Functions
Syntax: How to Convert the Date Portion of a Date-Time Value to a Date Format
HDATE(datetime, output)
where:
datetime
Date-time
Is the date-time value to be converted, the name of a date-time field that contains the
value, or an expression that returns the value.
output
Date
Is the format in single quotation marks or the field that contains the result.
Example: Converting the Date Portion of a Date-Time Field to a Date Format (Reporting)
HDATE converts the date portion of the TRANSDATE field to the date format YYMD:
TABLE FILE VIDEOTR2
PRINT CUSTID TRANSDATE AS 'DATE-TIME' AND COMPUTE
TRANSDATE_DATE/YYMD = HDATE(TRANSDATE, 'YYMD');
WHERE DATE EQ 2000;
END
Example: Converting the Date Portion of a Date-Time Field to a Date Format (Maintain)
HDATE converts the date portion of DT1 to date format YYMD:
MAINTAIN FILE DATETIME
FOR 1 NEXT ID INTO STK;
COMPUTE
DT1_DATE/YYMD = HDATE(STK.DT1, DT1_DATE);
TYPE "STK(1).DT1 = <STK(1).DT1";
TYPE "DT1_DATE = <DT1_DATE";
END
The HDIFF function calculates the number of date or time component units between two date-
time values.
Performing the same calculation using HDIFF on date-time fields results in a value of 1 month
or 1 year as, in this case, the month or year is first extracted from each date-time value, and
then the subtraction occurs.
Syntax: How to Find the Number of Units Between Two Date-Time Values
where:
end_dt
Date-time
Is the date-time value to subtract from, the name of a date-time field that contains the
value, or an expression that returns the value.
start_dt
Date-time
Is the date-time value to subtract, the name of a date-time field that contains the value, or
an expression that returns the value.
component
Alphanumeric
Is the name of the component to be used in the calculation, enclosed in single quotation
marks. If the component is a week, the WEEKFIRST parameter setting is used in the
calculation.
452
13. Date-Time Functions
output
Floating-point double-precision
Is the field that contains the result, or the format of the output value enclosed in single
quotation marks. The format must be floating-point double-precision.
Example: Finding the Number of Days Between Two Date-Time Fields (Reporting)
HDIFF calculates the number of days between the TRANSDATE and ADD_MONTH fields and
stores the result in DIFF_PAYS, which has the format D12.2:
TABLE FILE VIDEOTR2
PRINT CUSTID TRANSDATE AS 'DATE-TIME' AND COMPUTE
ADD_MONTH/HYYMDS = HADD(TRANSDATE, 'MONTH', 2, 8, 'HYYMDS');
DIFF_DAYS/D12.2 = HDIFF(ADD_MONTH, TRANSDATE, 'DAY', 'D12.2');
WHERE DATE EQ 2000;
END
Example: Finding the Number of Days Between Two Date-Time Fields (Maintain)
HDIFF calculates the number of days between ADD_MONTH and DT1:
MAINTAIN FILE DATETIME
FOR 1 NEXT ID INTO STK;
COMPUTE
NEW_DATE/HYYMDS = HADD(STK.DT1, 'MONTH', 2,10, NEW_DATE);
DIFF_DAYS/D12.2 = HDIFF(NEW_DATE,STK.DT1,'DAY', DIFF_DAYS);
TYPE "STK(1).DT1 = "STK(1).DT1;
TYPE "NEW_DATE = "NEW_DATE;
TYPE "DIFF_DAYS = "DIFF_DAYS
END
The HDTTM function converts a date value to a date-time value. The time portion is set to
midnight.
where:
date
Date
Is the date to be converted, the name of a date field that contains the value, or an
expression that returns the value. It must be a full component format date. For example, it
can be MDYY or YYJUL.
length
Integer
Is the generated date-time value. It can be a field or the format of the output value
enclosed in single quotation marks. The value must have a date-time format (data type H).
454
13. Date-Time Functions
The HEXTR function extracts one or more components from a date-time value and moves them
to a target date-time field with all other components set to zero.
where:
datetime
Date-time
Is the date-time value from which to extract the specified components.
componentstring
Alphanumeric
Is a string of codes, in any order, that indicates which components are to be extracted and
moved to the output date-time field. The following table shows the valid values. The string
is considered to be terminated by any character not in this list:
Code Description
Code Description
M month
D day
H hour
I minutes
S seconds
length
Is the length of the returned date-time value. Valid values are:
456
13. Date-Time Functions
HGETC: Storing the Current Local Date and Time in a Date-Time Field
Available Languages: reporting, Maintain
The HGETC function returns the current local date and time in the desired date-time format. If
millisecond or microsecond values are not available in your operating environment, the
function retrieves the value zero for these components.
Syntax: How to Store the Current Local Date and Time in a Date-Time Field
HGETC(length, output)
where:
length
Integer
Is the returned date-time value. Can be a field that contains the result, or the format of the
output value enclosed in single quotation marks. The format must be in date-time format
(data type H).
Example: Storing the Current Date and Time in a Date-Time Field (Reporting)
HGETC stores the current date and time in DT2:
Example: Storing the Current Local Date and Time in a Date-Time Field (Maintain)
HGETC stores the current date and time in DT2:
MAINTAIN
COMPUTE DT2/HYYMDm = HGETC(10, DT2);
TYPE "DT2 = <DT2";
END
HGETZ provides the current Coordinated Universal Time (UTC/GMT time, often called Zulu
time). UTC is the primary civil time standard by which the world regulates clocks and time.
The value is returned in the desired date-time format. If millisecond or microsecond values are
not available in your operating environment, the function retrieves the value zero for these
components.
Syntax: How to Store the Current Universal Date and Time in a Date-Time Field
HGETZ(length, output)
where:
length
Integer
458
13. Date-Time Functions
output
Date-time
Is the returned date-time value. Can be a field that contains the result, or the format of the
output value enclosed in single quotation marks. The format must be in date-time format
(data type H).
Example: Storing the Current Universal Date and Time in a Date-Time Field (Reporting)
HGETZ stores the current universal date and time in DT2:
The HHMMSS function retrieves the current time from the operating system as an eight
character string, separating the hours, minutes, and seconds with periods.
A compiled MODIFY procedure must use HHMMSS to obtain the time; it cannot use the &TOD
variable, which also returns the time. The &TOD variable is made current only when you
execute a MODIFY, SCAN, or FSCAN procedure.
There is also an HHMMSS function available in the Maintain language. For information on this
function, see HHMMSS: Retrieving the Current Time (Maintain) on page 479.
HHMMSS(output)
where:
output
Alphanumeric, at least A8
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
460
13. Date-Time Functions
where:
datetime
Date-time
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
where:
source_length
Integer
Is the number of characters in the source string to be converted. You can supply the actual
value, the name of a numeric field that contains the value, or an expression that returns
the value.
source_string
Alphanumeric
462
13. Date-Time Functions
output_length
Integer
8 indicates a time value that includes one to three decimal digits (milliseconds).
10 indicates a time value that includes four to six decimal digits (microseconds).
12 indicates a time value that includes seven to nine decimal digits (nanoseconds).
output
Date-time
Is the returned date-time value. Is a field that contains the result, or the format of the
output value enclosed in single quotation marks. The format must be in date-time format
(data type H).
The HMIDNT function changes the time portion of a date-time value to midnight (all zeros by
default). This allows you to compare a date field with a date-time field.
where:
datetime
Date-time
Is the date-time value whose time is to be set to midnight, the name of a date-time field
that contains the value, or an expression that returns the value.
length
Integer
Is the date-time return value whose time is set to midnight and whose date is copied from
timestamp. Is the field that contains the result, or the format of the output value enclosed
in single quotation marks. The format must be in date-time format (data type H).
464
13. Date-Time Functions
The HMASK function extracts one or more components from a date-time value and moves
them to a target date-time field with all other components of the target field preserved.
where:
source
Is the date-time value from which the specified components are extracted.
componentstring
Is a string of codes, in any order, that indicates which components are to be extracted and
moved to the output date-time field. The following table shows the valid values. The string
is considered to be terminated by any character not in this list:
Code Description
Code Description
M month
D day
H hour
I minutes
S seconds
input
Is the date-time value that provides all the components for the output that are not
specified in the component string.
length
Is the length of the returned date-time value. Valid values are:
8 indicates a time value that includes one to three decimal digits (milliseconds).
10 indicates a time value that includes four to six decimal digits (microseconds).
12 indicates a time value that includes seven to nine decimal digits (nanoseconds).
output
Is the field that contains the result, or the format of the output value enclosed in single
quotation marks. This field must be in date-time format (data type H).
466
13. Date-Time Functions
The output is
LASTNAME FIRSTNAME ORIG_TRANSDATE TRANSDATE
-------- --------- -------------- ---------
BERTAL MARCIA 1999/07/29 12:19 1999/07/30 08:30
GARCIA JOANN 1998/05/08 12:48 1998/05/09 08:30
1999/11/30 12:12 1999/12/01 08:30
PARKER GLENDA 1999/01/06 12:22 1999/01/07 08:30
RATHER MICHAEL 1998/02/28 12:33 1998/03/01 08:30
WILSON KELLY 1999/06/26 12:34 1999/06/27 08:30
The HNAME function extracts a specified component from a date-time value and returns it in
alphanumeric format.
where:
datetime
Date-time
Is the date-time value from which a component value is to be extracted, the name of a
date-time field containing the value that contains the value, or an expression that returns
the value.
component
Alphanumeric
Is the field that contains the result, or the format of the output value enclosed in single
quotation marks. The format must be in alphanumeric format.
The function converts a month argument to an abbreviation of the month name and
converts and all other components to strings of digits only. The year is always four digits,
and the hour assumes the 24-hour system.
468
13. Date-Time Functions
The HPART function extracts a specified component from a date-time value and returns it in
numeric format.
where:
datetime
Date-time
Is the date-time value from which the component is to be extracted, the name of a date-
time field that contains the value, or an expression that returns the value.
component
Alphanumeric
Is the field that contains the result, or the integer format of the output value enclosed in
single quotation marks.
470
13. Date-Time Functions
The HSETPT function inserts the numeric value of a specified component into a date-time
value.
where:
datetime
Date-time
Is the date-time value in which to insert the component, the name of a date-time field that
contains the value, or an expression that returns the value.
component
Alphanumeric
Is the numeric value to be inserted for the requested component, the name of a numeric
field that contains the value, or an expression that returns the value.
length
Integer
8 indicates a time value that includes one to three decimal digits (milliseconds).
10 indicates a time value that includes four to six decimal digits (microseconds).
12 indicates a time value that includes seven to nine decimal digits (nanoseconds).
output
Date-time
Is the returned date-time value whose chosen component is updated. All other
components are copied from the source date-time value.
Is the field that contains the result, or the format of the output value enclosed in single
quotation marks. The format must be in date-time format (data type H).
472
13. Date-Time Functions
The HTIME function converts the time portion of a date-time value to the number of
milliseconds if the length argument is eight, microseconds if the length argument is ten, or
nanoseconds if the length argument is 12.
where:
length
Integer
8 indicates a time value that includes one to three decimal digits (milliseconds).
10 indicates a time value that includes four to six decimal digits (microseconds).
12 indicates a time value that includes seven to nine decimal digits (nanoseconds).
datetime
Date-time
Is the date-time value from which to convert the time, the name of a date-time field that
contains the value, or an expression that returns the value.
output
Floating-point double-precision
Is the field that contains the result, or the format of the output value enclosed in single
quotation marks. The format must be floating-point double-precision.
or
474
13. Date-Time Functions
where:
time
Date-Time
Is the date-time value whose time will be used. The date portion will be ignored.
length
Integer
Is the timestamp whose date is set to the current date, and whose time is copied from
time.
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
HYYWD: Returning the Year and Week Number From a Date-Time Value
The week number returned by HNAME and HPART can actually be in the year preceding or
following the input date.
The HYYWD function returns both the year and the week number from a given date-time value.
The output is edited to conform to the ISO standard format for dates with week numbers, yyyy-
Www-d.
Syntax: How to Return the Year and Week Number From a Date-Time Value
HYYWD(dtvalue, output)
where:
dtvalue
Date-time
Is the date-time value to be edited, the name of a date-time field that contains the value,
or an expression that returns the value.
476
13. Date-Time Functions
output
Alphanumeric
Is the field that contains the result, or the format of the output value enclosed in single
quotation marks.
The output format must be at least 10 characters long. The output is in the following
format:
yyyy-Www-d
where:
yyyy
Is the single-digit day of the week (1 to 7). The d value is relative to the current
WEEKFIRST setting. If WEEKFIRST is 2 or ISO2 (Monday), then Monday is represented
in the output as 1, Tuesday as 2.
Using the EDIT function, you can extract the individual subfields from this output.
Example: Returning the Year and Week Number From a Date-Time Value
The following request against the VIDEOTR2 data source calls HYYWD to convert the
TRANSDATE date-time field to the ISO standard format for dates with week numbers.
WEEKFIRST is set to ISO2, which produces ISO standard week numbering:
SET WEEKFIRST = ISO2
TABLE FILE VIDEOTR2
SUM TRANSTOT QUANTITY
COMPUTE ISODATE/A10 = HYYWD(TRANSDATE, 'A10');
BY TRANSDATE
WHERE QUANTITY GT 1
END
478
Chapter 14 Maintain-specific Date and Time
Functions
Maintain-specific date and time functions manipulate date and time values. These
functions are available only in Maintain Data.
There are additional date and time functions available in both the reporting and Maintain
languages. For more information on these functions, see Date-Time Functions on page
435.
In this chapter:
The HHMMSS function retrieves the current time from the operating system as an 8-character
string, separating the hours, minutes, and seconds with periods.
To use this function, you must import the function library MNTUWS. For information on
importing a function library, see Calling a Function on page 59.
There is also an HHMMSS function available in the reporting language. For information on this
function, see HHMMSS: Retrieving the Current Time on page 460.
HHMMSS()
The Initial_HHMMSS function returns the time when the Maintain Data application was started
as an 8-character string, with embedded periods separating the hours, minutes, and seconds.
To use this function, you must import the function library MNTUWS. For details on importing
this library, see Calling a Function on page 59.
Initial_HHMMSS()
The Initial_TODAY function returns the date in MM/DD/YY format when the Maintain Data
application was started as an 8-character string with embedded slashes.
To use this function, you must import the function library MNTUWS. For details on importing
this library, see Calling a Function on page 59.
Initial_TODAY()
The TODAY function retrieves the current date from the system in the format MM/DD/YY.
TODAY always returns a date that is current. Therefore, if you are running an application late at
night, use TODAY. You can remove the embedded slashes using the EDIT function.
480
14. Maintain-specific Date and Time Functions
To use this function, you must import the function library MNTUWS. For information on
importing this library, see Calling a Function on page 59.
There is a version of the TODAY function that is available only in the reporting language. For
information on this function, see HTMTOTS or TIMETOTS: Converting a Time to a Timestamp on
page 474.
TODAY()
Case Top
Compute date1/a8 = today();
type "Date1 = <<date1"
Endcase
END
The TODAY2 function retrieves the current date from the operating system in the format
MM/DD/YYYY. Use format A10 with the TODAY2 function to ensure proper results.
To use this function, you must import the function library MNTUWS. For information on
importing this library, see Calling a Function on page 59.
TODAY2()
Case Top
Compute date2/a10 = today2();
type "Date2 = <<date2"
Endcase
END
ADD(date,value)
or
date.ADD(value)
where:
date
Is the date to add days to, or a field containing the date.
value
Is the number of days by which to increase the date.
This function changes the value of date.
482
14. Maintain-specific Date and Time Functions
The following are sample values for DateVar and the corresponding values for
ADD(DateVar, 10):
DateVar ADD(DateVar, 10);
------- -----------------
12/31/1999 01/10/2000
01/01/2000 01/11/2000
01/02/2000 01/12/2000
The DAY function extracts the day of the month from a date and returns the result as an
integer.
DAY(date);
where:
date
Is the date (in date format) from which to extract the day of the month, or a field
containing the date.
The following are sample values for DATE and the corresponding values for DAY(DATE):
DATE DAY(DATE)
---- ---------
01/01/2000 1
01/02/2000 2
01/03/2000 3
The JULIAN function determines the number of days that have elapsed in the given year up to a
given date, and returns the result as an integer.
Syntax: How to Determine How Many Days Have Elapsed in the Year
JULIAN(date);
where:
date
Is the date (in date format) for which to determine the number of days elapsed in the
given year, or a field containing the date.
The following are sample values for DATE and the corresponding values for JULIAN(DATE):
DATE JULIAN(DATE)
---- ------------
01/01/2000 1
02/01/2000 32
03/01/2000 61
The MONTH function extracts the month from a date and returns the result as an integer.
MONTH(date);
where:
date
Is the date (in date format) from which to extract the month, or a field containing the
date.
484
14. Maintain-specific Date and Time Functions
The following are sample values for DATE and the corresponding values for MONTH(DATE):
DATE MONTH(DATE)
---- -----------
01/01/2000 1
02/01/2000 2
03/01/2000 3
The QUARTER function determines the quarter of the year in which a date resides, and returns
the result as an integer.
QUARTER(date);
where:
date
Is the date (in date format) for which to determine the quarter, or a field containing the
date.
The following are sample values for DATE and the corresponding values for QUARTER(DATE):
DATE QUARTER(DATE)
---- -------------
01/01/2000 1
04/01/2000 2
07/01/2000 3
The SETMDY function sets a value to a date based on numeric values representing a day,
month, and year. SETMDY returns a 0 if the function is successful, and a negative number if
the function fails.
or
date.SETMDY(month, day, year);
where:
date
Is the date, in date format, or a field containing the date.
month
Is an integer value representing a month.
day
Is an integer value representing the day of the month.
year
Is an integer value representing a year.
The following are sample values for month, day, and year, and the corresponding dates for
DateVar:
month day year DateVar
----- --- ---- -------
04 05 1965 Monday, April 5, 1965
02 01 1997 Saturday, February 1, 1997
01 01 2000 Saturday, January 1, 2000
486
14. Maintain-specific Date and Time Functions
SUB(date,value)
or
date.SUB(value)
where:
date
Is the date from which to subtract the value, or a field containing the date.
value
Is the value to subtract from the date.
SUB(DateVar, 10)
The following are sample values for DateVar and the corresponding values for
SUB(DateVar, 10):
DateVar SUB(DateVar, 10);
------- -----------------
12/31/1999 12/21/2000
01/01/2000 12/22/2000
01/02/2000 12/23/2000
The WEEKDAY function determines the day of the week for a date and returns the result as an
integer (1=Monday, 2=Tuesday, and so on).
WEEKDAY(date);
where:
date
Is the date (in date format) for which to determine the weekday, or a field containing
the date.
The following are sample values for DATE and the corresponding values for WEEKDAY(DATE):
DATE WEEKDAY(DATE)
---- -------------
01/01/2000 6
01/02/2000 7
01/03/2000 1
YEAR(date);
where:
date
Is the date from which to extract the year, or a field containing the date.
The following are sample values for DATE and the corresponding values for YEAR(DATE):
DATE YEAR(DATE)
---- ----------
01/01/2000 2000
02/01/2001 2001
03/01/2002 2002
488
Chapter 15 Simplified Conversion Functions
Simplified conversion functions have streamlined parameter lists, similar to those used
by SQL functions. In some cases, these simplified functions provide slightly different
functionality than previous versions of similar functions.
The simplified functions do not have an output argument. Each function returns a value
that has a specific data type.
When used in a request against a relational data source, these functions are optimized
(passed to the RDBMS for processing).
In this chapter:
For a chart of printable characters and their decimal equivalents, see Character Chart for ASCII
and EBCDIC on page 50.
CHAR(number_code)
where:
number_code
Integer
Is a field, number, or numeric expression whose whole absolute value will be used as a
number code to retrieve an output character.
Example: Using the CHAR Function to Insert Control Characters Into a String
The following request defines a field with carriage return (CHAR(13)) and line feed (CHAR(10))
characters inserted between the words HELLO and GOODBYE (in an ASCII environment). To
show that these characters were inserted, the output is generated in PDF format and the
StyleSheet attribute LINEBREAK='CRLF' is used to have these characters respected and print
the field value on two lines.
490
15. Simplified Conversion Functions
COMPACTFORMAT(input)
where:
input
Is the name of a numeric field.
CTRLCHAR(ctrl_char)
where:
ctrl_char
Is one of the following keywords.
492
15. Simplified Conversion Functions
Example: Using the CTRLCHAR Function to Insert Control Characters Into a String
The following request defines a field with carriage return (CTRLCHAR(CR)) and line feed
(CTRLCHAR(LF)) characters inserted between the words HELLO and GOODBYE. To show that
these characters were inserted, the output is generated in PDF format and the StyleSheet
attribute LINEBREAK='CRLF' is used to have these characters respected and print the field
value on two lines.
DEFINE FILE WF_RETAIL_LITE
MYFIELD/A20 WITH COUNTRY_NAME='HELLO' | CTRLCHAR(CR) | CTRLCHAR(LF) |
'GOODBYE';
END
TABLE FILE WF_RETAIL_LITE
SUM MYFIELD
ON TABLE PCHOLD FORMAT PDF
ON TABLE SET PAGE NOLEAD
ON TABLE SET STYLE *
TYPE=REPORT,LINEBREAK='CRLF',$
ENDSTYLE
END
Syntax: How to Convert a Date Value to an Alphanumeric String in a Specified Date Format
DT_FORMAT(date,'date_format')
where:
date
Numeric, date, or date-time
494
15. Simplified Conversion Functions
Is a date or date-time format that fits the input date format type, enclosed in single
quotation marks.
Note: A legacy FPRINT function also exists and is still supported. For information, see FPRINT:
Converting Fields to Alphanumeric Format on page 506. The legacy function has an additional
argument for the name or format of the returned value.
FPRINT(value, 'out_format')
where:
value
Any data type
'out_format'
Fixed length alphanumeric
Is the display format. For information about valid display formats, see the Describing Data
With WebFOCUS Language manual.
496
15. Simplified Conversion Functions
HEXTYPE(in_value)
where:
in_value
Is an alphanumeric or integer field, constant, or expression.
498
15. Simplified Conversion Functions
You can set the algorithm to use with the following command.
SET PHONETIC_ALGORITHM = {METAPHONE|SOUNDEX}
Most phonetic algorithms were developed for use with the English language. Therefore,
applying the rules to words in other languages may not give a meaningful result.
Metaphone is suitable for use with most English words, not just names. Metaphone algorithms
are the basis for many popular spell checkers.
Note: Metaphone is not optimized in generated SQL. Therefore, if you need to optimize the
request for an SQL DBMS, the SOUNDEX setting should be used.
PHONETIC(string)
where:
string
Alphanumeric
Is a string for which to create the key. A null value will be returned on failure.
The output is shown in the following image. Note that the two spellings for SMITH are assigned
the same index number.
500
15. Simplified Conversion Functions
TO_INTEGER(string)
where:
string
Is a character string enclosed in single quotation marks or a character field that
represents a number containing digits and an optional decimal point.
TO_NUMBER(string)
where:
string
Is a character string enclosed in single quotation marks or a character field that
represents a number containing digits and an optional decimal point. This string will
be converted to a double-precision floating point number.
502
Chapter 16 Format Conversion Functions
Format conversion functions convert fields from one format to another.
For information on field formats see the Describing Data With WebFOCUS Language
manual
For many functions, the output argument can be supplied either as a field name or as a
format enclosed in single quotation marks. However, if a function is called from a
Dialogue Manager command, this argument must always be supplied as a format, and if
a function is called from a Maintain Data procedure, this argument must always be
supplied as a field name.
In this chapter:
where:
source_string
Alphanumeric
Is the string consisting of digits and, optionally, one sign and one decimal point to be
converted, or a field or variable that contains the string.
length
Alphanumeric
Is the two-character length of the source string in bytes. This can be a numeric constant,
or a field or variable that contains the value. If you specify a numeric constant, enclose it
in single quotation marks, for example '12'.
output
Double precision floating-point
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
504
16. Format Conversion Functions
The EDIT function converts an alphanumeric field that contains numeric characters to numeric
format or converts a numeric field to alphanumeric format.
This function is useful for manipulating a field in an expression that performs an operation that
requires operands in a particular format.
When EDIT assigns a converted value to a new field, the format of the new field must
correspond to the format of the returned value. For example, if EDIT converts a numeric field to
alphanumeric format, you must give the new field an alphanumeric format:
DEFINE ALPHAPRICE/A6 = EDIT(PRICE);
When an alphanumeric field is converted to numeric format, a sign or decimal point in the
field is stored as part of the numeric value.
Any other non-numeric characters are invalid, and EDIT returns the value zero.
EDIT(fieldname);
where:
fieldname
Alphanumeric or Numeric
Is the field name.
where:
in_value
Any format except TX
Is the usage format of the value to be converted, including display options. The format
must be enclosed in single quotation marks.
506
16. Format Conversion Functions
output
Alphanumeric
Is the name of the output field or its format enclosed in single quotation marks.
The output format must be long enough to hold the converted number itself, with a sign
and decimal point, plus any additional characters generated by display options, such as
commas, a currency symbol, or a percent sign.
For example, D12.2 format is converted to A14 because it outputs two decimal digits, a
decimal point, a possible minus sign, up to eight integer digits, and two commas. If the
output format is not large enough, excess right-hand characters may be truncated.
The output of FPRINT for numeric values is right-justified within the area required for the
maximum number of characters corresponding to the supplied format. This ensures that all
possible values are aligned vertically along the decimal point or units digit.
By default, the column title is left justified for alphanumeric fields. To right justify the
column title, use the /R reformatting option for the field.
Maintain Data does not support the FPRINT function. However, you can do the same type of
conversion in Maintain Data using the COMPUTE command.
508
16. Format Conversion Functions
Example: Converting a Date-Time Field to Alphanumeric Format and Creating a HOLD File
The following request against the VIDEOTR2 data source converts the TRANSDATE (HYYMDI)
field to alphanumeric format. The alphanumeric representation has format A16 to account for a
four-digit year, two-digit month, two-digit day, two slashes between the date components, a
space between the date and time, a two-digit hour, a colon between the hour and minute
components, and a two-digit minute:
DEFINE FILE VIDEOTR2
DATE/I4 = HPART(TRANSDATE, 'YEAR', 'I4');
ALPHA_DATE/A16 = FPRINT(TRANSDATE,'HYYMDI', ALPHA_DATE);
END
TABLE FILE VIDEOTR2
PRINT TRANSDATE ALPHA_DATE/R
WHERE DATE EQ '1991'
ON TABLE SET PAGE NOPAGE
END
If you hold the output in a comma-delimited or other alphanumeric output file, you can see that
while the original field propagates only the numeric representation of the value, the converted
field propagates the display options as well:
DEFINE FILE VIDEOTR2
DATE/I4 = HPART(TRANSDATE, 'YEAR', 'I4');
ALPHA_DATE/A16 = FPRINT(TRANSDATE,'HYYMDI', ALPHA_DATE);
END
TABLE FILE VIDEOTR2
PRINT TRANSDATE ALPHA_DATE/R
WHERE DATE EQ '1991'
ON TABLE HOLD FORMAT COMMA
END
The HOLD file follows. The first field represents the original data, and the second field contains
the converted values with display options:
510
16. Format Conversion Functions
"19910627024500000","1991/06/27 02:45"
"19910620051500000","1991/06/20 05:15"
"19910621071100000","1991/06/21 07:11"
"19910621011000000","1991/06/21 01:10"
"19910619071800000","1991/06/19 07:18"
"19910619041100000","1991/06/19 04:11"
"19910625011900000","1991/06/25 01:19"
"19910624044300000","1991/06/24 04:43"
"19910624020800000","1991/06/24 02:08"
"19910625011700000","1991/06/25 01:17"
"19910627011700000","1991/06/27 01:17"
"19911117112800000","1991/11/17 11:28"
"19910624102700000","1991/06/24 10:27"
The FTOA function converts a number up to 16 digits long from numeric format to alphanumeric
format. It retains the decimal positions of the number and right-justifies it with leading spaces.
You can also add edit options to a number converted by FTOA.
When using FTOA to convert a number containing decimals to a character string, you must
specify an alphanumeric format large enough to accommodate both the integer and decimal
portions of the number. For example, a D12.2 format is converted to A14. If the output format
is not large enough, decimals are truncated.
where:
number
Numeric F or D (single and double precision floating-point)
Is the number to be converted, or the name of the field that contains the number.
format
Alphanumeric
Is the format of the number to be converted enclosed in parentheses. Only floating point
single-precision and double-precision formats are supported. Include any edit options that
you want to appear in the output. The D (floating-point double-precision) format
automatically supplies commas.
If you use a field name for this argument, specify the name without quotation marks or
parentheses. If you specify a format, the format must be enclosed in single quotation
marks and parentheses.
output
Alphanumeric
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks. The length of this argument must be greater than the length of
number and must account for edit options and a possible negative sign.
The HEXBYT function obtains the ASCII, EBCDIC, or Unicode character equivalent of a decimal
integer, depending on your configuration and operating environment. The decimal value you
specify must be the value associated with the character on the configured code page. HEXBYT
returns a single alphanumeric character in the ASCII, EBCDIC, or Unicode character set. You
can use this function to produce characters that are not on your keyboard, similar to the
CTRAN function.
512
16. Format Conversion Functions
The display of special characters depends on your software and hardware; not all special
characters may appear.
HEXBYT(decimal_value, output)
where:
decimal_value
Integer
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks (').
To produce the same output in a Unicode environment configured for code page 65001,
replace the COMPUTE command for the field COMMA1 with the following syntax, in which the
call to HEXBYT converts the integer value 14844058 to the comma character:
COMPUTE COMMA1/A1 = HEXBYT(14844058, COMMA1); NOPRINT
514
16. Format Conversion Functions
The ITONUM function converts a large binary integer in a non-FOCUS data source to double-
precision format.
Some programming languages and some non-FOCUS data storage systems use large binary
integer formats. However, large binary integers (more than 4 bytes in length) are not supported
in the Master File so they require conversion to double-precision format.
You must specify how many of the right-most bytes in the input field are significant. The result
is an 8-byte double-precision field.
where:
maxbytes
Numeric
Is the maximum number of bytes in the 8-byte binary input field that have significant
numeric data, including the binary sign. Valid values are:
infield
A8
Is the field that contains the binary number. Both the USAGE and ACTUAL formats of the
field must be A8.
output
Double precision floating-point (Dn)
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks. The format must be Dn.
It is defined in the EUROCAR Master File as a field named BINARYFLD. Its field formats are
USAGE=A8 and ACTUAL=A8, since its length is greater than 4 bytes.
The ITOPACK function converts a large binary integer in a non-FOCUS data source to packed-
decimal format.
Some programming languages and some non-FOCUS data storage systems use double-word
binary integer formats. These are similar to the single-word binary integers used by FOCUS, but
they allow larger numbers. However, large binary integers (more than 4 bytes in length) are not
supported in the Master File so they require conversion to packed-decimal format.
You must specify how many of the right-most bytes in the input field are significant. The result
is an 8-byte packed-decimal field of up to 15 significant numeric positions (for example, P15 or
P16.2).
Limit: For a field defined as 'PIC 9(15) COMP' or the equivalent (15 significant digits), the
maximum number that can be converted is 167,744,242,712,576.
516
16. Format Conversion Functions
where:
maxbytes
Numeric
Is the maximum number of bytes in the 8-byte binary input field that have significant
numeric data, including the binary sign.
Is the field that contains the binary number. Both the USAGE and ACTUAL formats of the
field must be A8.
output
Numeric
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks. The format must be Pn or Pn.d.
It is defined in the EUROCAR Master File as a field named BINARYFLD. Its field formats are
USAGE=A8 and ACTUAL=A8, since its length is greater than 4 bytes.
The ITOZ function converts a number in numeric format to zoned-decimal format. Although a
request cannot process zoned numbers, it can write zoned fields to an extract file for use by
an external program.
where:
length
Integer
Is the length of in_value in bytes. The maximum number of bytes is 15. The last byte
includes the sign.
in_value
Numeric
Is the number to be converted, or the field that contains the number. The number is
truncated to an integer before it is converted.
output
Alphanumeric
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
518
16. Format Conversion Functions
The PCKOUT function writes a packed-decimal number of variable length to an extract file.
When a request saves a packed number to an extract file, it typically writes it as an 8- or 16-
byte field regardless of its format specification. With PCKOUT, you can vary the field's length
between 1 to 16 bytes.
where:
in_value
Numeric
Is the input field that contains the values. It can be in packed, integer, single- or double-
precision floating point format. If it is not in integer format, it is rounded to the nearest
whole number.
length
Numeric
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks. The function returns the field as alphanumeric although it
contains packed data.
The PTOA function converts a packed-decimal number from numeric format to alphanumeric
format. It retains the decimal positions of the number and right-justifies it with leading spaces.
You can also add edit options to a number converted by PTOA.
When using PTOA to convert a number containing decimals to a character string, you must
specify an alphanumeric format large enough to accommodate both the integer and decimal
portions of the number. For example, a P12.2C format is converted to A14. If the output
format is not large enough, the right-most characters are truncated.
520
16. Format Conversion Functions
where:
number
Numeric P (packed-decimal)
Is the number to be converted, or the name of the field that contains the number.
format
Alphanumeric
Is the format of the number enclosed in both single quotation marks and parentheses.
Only packed-decimal format is supported. Include any edit options that you want to display
in the output.
The format value does not require the same length or number of decimal places as the
original field. If you change the number of decimal places, the result is rounded. If you
make the length too short to hold the integer portion of the number, asterisks appear
instead of the number.
If you use a field name for this argument, specify the name without quotation marks or
parentheses. However, parentheses must be included around the format stored in this
field. For example:
FMT/A10 = '(P12.2C)';
You can then use this field as the format argument when using the function in your
request:
COMPUTE ALPHA_GROSS/A20 = PTOA(PGROSS, FMT, ALPHA_GROSS);
output
Alphanumeric
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks. The length of this argument must be greater than the length of
number and must account for edit options and a possible negative sign.
Microsoft SQL Server and Sybase have a data type called TIMESTAMP. Rather than containing
an actual timestamp, columns with this data type contain a number that is incremented for
each record inserted or updated in the data source. This timestamp comes from a common
area, so no two tables in the database have the same timestamp column value. The value is
stored in Binary(8) or Varbinary(8) format in the table, but is returned as a double wide
alphanumeric column (A16). You can use the TSTOPACK function to convert the timestamp
value to packed decimal.
TSTOPACK(tscol, output);
522
16. Format Conversion Functions
where:
tscol
A16
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks (‘).
The Master File for the TSTEST data source follows. The field TS represents the TIMESTAMP
column:
FILENAME=TSTEST, SUFFIX=SQLMSS , $
SEGMENT=TSTEST, SEGTYPE=S0, $
FIELDNAME=I, ALIAS=I, USAGE=I11, ACTUAL=I4,
MISSING=ON, $
FIELDNAME=TS, ALIAS=TS, USAGE=A16, ACTUAL=A16, FIELDTYPE=R, $
Note: When you generate a synonym for a table with a TIMESTAMP column, the TIMESTAMP
column is created as read-only (FIELDTYPE=R).
The UFMT function converts characters in an alphanumeric source string to their hexadecimal
representation. This function is useful for examining data of unknown format. As long as you
know the length of the data, you can examine its content.
where:
source_string
Alphanumeric
Is the alphanumeric string to convert enclosed in single quotation marks ('), or the field
that contains the string.
length
Integer
524
16. Format Conversion Functions
output
Alphanumeric
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks ('). The format of output must be alphanumeric and its length
must be twice that of length.
where:
infield
Numeric
Is the length of the alphanumeric field that will hold the converted packed field. Can be
from 1 to 16.
outdec
Numeric
Is the name of the field to contain the result or the format of the field enclosed in single
quotation marks.
526
16. Format Conversion Functions
528
Chapter 17 Maintain-specific Light Update Support
Functions
Light update support functions retrieve WebFOCUS parameter or variable data implicitly
from within a Maintain Data procedure.
In this chapter:
Note: Unlike Maintain variables, WebFOCUS parameters and variables are case-sensitive.
IWC.FindAppCGIValue(parm,mnt_var);
where:
parm
Is the WebFOCUS parameter or variable whose value you are retrieving. This value is case-
sensitive, and must be alphanumeric.
mnt_var
Is the Maintain Data variable that receives the value of the WebFOCUS parameter or
variable.
The IWC.GetAppCGIValue function imports the value of a WebFOCUS parameter or variable into
a Maintain Data variable. IWC.GetAppCGIValue returns a value from the HTTP request header if
the name of the variable or parameter is passed. If the name is not found, the function returns
a null value. Therefore, you can check for errors by looking for a null value, then handle the
error as needed.
Note: Unlike Maintain variables, WebFOCUS parameters and variables are case-sensitive.
530
17. Maintain-specific Light Update Support Functions
where:
mnt_var
Is the Maintain Data variable that receives the ASCII return value of the WebFOCUS
parameter or variable. The value should be unescaped before being passed to the
Maintain variable.
type_length
Is the selected type and length of the Maintain Data variable.
parm
Is the WebFOCUS parameter or variable to import. This value is case-sensitive, and must
be alphanumeric.
532
Chapter 18 Simplified Numeric Functions
Numeric functions have been developed that make it easier to understand and enter the
required arguments. These functions have streamlined parameter lists, similar to those
used by SQL functions. In some cases, these simplified functions provide slightly
different functionality than previous versions of similar functions.
The simplified functions do not have an output argument. Each function returns a value
that has a specific data type.
When used in a request against a relational data source, these functions are optimized
(passed to the RDBMS for processing).
Note:
ASCII: Returning the ASCII Code for the Leftmost Character in a String
CEILING: Returning the Smallest Integer Value Greater Than or Equal to a Value
ASCII: Returning the ASCII Code for the Leftmost Character in a String
ASCII takes a character string and returns the ASCII code in integer format for the leftmost
character in the string.
Syntax: How to Return the ASCII Code for the Leftmost Character in a String
ASCII(charexp)
where:
charexp
Is any character string.
Example: Returning the ASCII Code for the Leftmost Character in a String
In the following request, ASCII returns the ASCII code for the leftmost character in the
CATEGORY field.
TABLE FILE GGSALES
SUM DOLLARS NOPRINT
AND COMPUTE
ASCII_CODE/I9 = ASCII(CATEGORY);
BY CATEGORY
ON TABLE SET PAGE NOLEAD
ON TABLE SET STYLE *
GRID=OFF,$
ENDSTYLE
END
CEILING: Returning the Smallest Integer Value Greater Than or Equal to a Value
CEILING returns the smallest integer value that is greater than or equal to a number.
Syntax: How to Return the Smallest Integer Greater Than or Equal to a Number
CEILING(number)
534
18. Simplified Numeric Functions
where:
number
Numeric
Is the number whose ceiling will be returned. The output data type is the same as the
input data type.
The partial output follows. Note that even though the value returned is an integer, it is returned
with the same format as the CEIL1 field (D7.2):
EXPONENT(power)
where:
power
Numeric
536
18. Simplified Numeric Functions
Syntax: How to Return the Largest Integer Less Than or Equal to a Number
FLOOR(number)
where:
number
Numeric
Is the number whose floor will be returned. The output data type is the same as the input
data type.
Partial output follows. Note that even though the value returned is an integer, it is returned
with the same format as the FLOOR1 field (D7.2):
538
18. Simplified Numeric Functions
LOG10(num_exp)
where:
num_exp
Numeric
MOD(dividend, divisor)
where:
dividend
Numeric
Note: The sign of the returned value will be the same as the sign of the dividend.
divisor
Numeric
540
18. Simplified Numeric Functions
POWER(base, power)
where:
base
Numeric
Is the value to raise to a power. The output value has the same data type as the base
value. If the base value is integer, negative power values will result in truncation.
power
Numeric
ROUND(num_exp, count)
where:
num_exp
Numeric
Is the number of decimal places to which the numeric expression is to be rounded. If the
number of decimal places is negative, ROUND rounds to the left of the decimal point.
542
18. Simplified Numeric Functions
SIGN(number)
where:
number
Is a field containing a numeric value or a number.
TRUNCATE(num_exp, count)
where:
num_exp
Numeric
Is the number of decimal places to which the numeric expression is to be truncated. If the
number of decimal places is negative, TRUNCATE truncates to the left of the decimal point.
544
18. Simplified Numeric Functions
546
Chapter 19 Numeric Functions
Numeric functions perform calculations on numeric constants and fields.
For many functions, the output argument can be supplied either as a field name or as a
format enclosed in single quotation marks. However, if a function is called from a
Dialogue Manager command, this argument must always be supplied as a format, and if
a function is called from a Maintain Data procedure, this argument must always be
supplied as a field name. For detailed information about calling a function and supplying
arguments, see Accessing and Calling a Function on page 59.
Note: With CDN ON, numeric arguments must be delimited by a comma followed by a
space.
In this chapter:
DMOD, FMOD, and IMOD: Calculating MIRR: Calculating the Modified Internal
the Remainder From a Division Return Rate
ABS(in_value)
where:
in_value
Numeric
Is the value for which the absolute value is returned, the name of a field that contains the
value, or an expression that returns the value. If you use an expression, use parentheses
as needed to ensure the correct order of evaluation.
The ASIS function distinguishes between a blank and a zero in Dialogue Manager. It
differentiates between a numeric string constant or variable defined as a numeric string, and a
field defined simply as numeric.
548
19. Numeric Functions
For details on ASIS, see ASIS: Distinguishing Between Space and Zero on page 197.
The BAR function produces a horizontal bar chart using repeating characters to form each bar.
Optionally, you can create a scale to clarify the meaning of a bar chart by replacing the title of
the column containing the bar with a scale.
where:
barlength
Numeric
Is the maximum length of the bar, in characters. If this value is less than or equal to 0, the
function does not return a bar.
infield
Numeric
Is the maximum value of a bar. This value must be greater than the maximum value stored
in infield. If infield is larger than maxvalue, the function uses maxvalue and returns a bar of
maximum length.
'char'
Alphanumeric
Is the repeating character that creates the bars enclosed in single quotation marks. If you
specify more than one character, only the first character is used.
output
Alphanumeric
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks. The output field must be large enough to contain a bar of
maximum length as defined by barlength.
To run this request on a platform for which the default font is proportional, use a non-
proportional font or issue SET STYLE=OFF.
SET STYLE=OFF
550
19. Numeric Functions
The CHKPCK function validates the data in a field described as packed format (if available on
your platform). The function prevents a data exception from occurring when a request reads a
field that is expected to contain a valid packed number but does not.
To use CHKPCK:
1. Ensure that the Master File (USAGE and ACTUAL attributes) defines the field as
alphanumeric, not packed. This does not change the field data, which remains packed, but
it enables the request to read the data without a data exception.
2. Call CHKPCK to examine the field. The function returns the output to a field defined as
packed. If the value it examines is a valid packed number, the function returns the value; if
the value is not packed, the function returns an error code.
where:
length
Numeric
Is the name of the packed field or the value to be verified as packed decimal. The value
must be described as alphanumeric, not packed.
error
Numeric
Is the error code that the function returns if a value is not packed. Choose an error code
outside the range of data. The error code is first truncated to an integer, then converted to
packed format. However, it may appear on a report with a decimal point depending on the
output format.
output
Packed-decimal
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
1. Prepare a data source that includes invalid packed data. The following example creates
TESTPACK, which contains the PACK_SAL field. PACK_SAL is defined as alphanumeric but
actually contains packed data. The invalid packed data is stored as AAA.
DEFINE FILE EMPLOYEE
PACK_SAL/A8 = IF EMP_ID CONTAINS '123'
THEN 'AAA' ELSE PCKOUT(CURR_SAL, 8, 'A8');
END
3. Create a request that uses CHKPCK to validate the values in the PACK_SAL field, and store
the result in the GOOD_PACK field. Values not in packed format return the error code -999.
Values in packed format appear accurately.
552
19. Numeric Functions
The MOD functions calculate the remainder from a division. Each function returns the
remainder in a different format.
where:
function
Is one of the following:
dividend
Numeric
Is the result whose format is determined by the function used. Can be the name of the
field that contains the result, or the format of the output value enclosed in single quotation
marks.
554
19. Numeric Functions
The EXP function raises the value "e" (approximately 2.72) to a specified power. This function
is the inverse of the LOG function, which returns the logarithm of the argument.
EXP calculates the result by adding terms of an infinite series. If a term adds less than .
000001 percent to the sum, the function ends the calculation and returns the result as a
double-precision number.
EXP(power, output)
where:
power
Numeric
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
where:
n.nn
Numeric
556
19. Numeric Functions
Note: EXPN does not use an output argument. The format of the result is floating-point double
precision.
The FMLCAP function returns the caption value for each row in an FML hierarchy request. In
order to retrieve caption values, the Master File must define an FML hierarchy and the request
must use the GET CHILDREN, ADD, or WITH CHILDREN option to retrieve hierarchy data. If the
FOR field in the request does not have a caption field defined, FMLCAP returns a blank string.
FMLCAP is supported for COMPUTE but is not recommended for use with DEFINE.
Syntax: How to Retrieve Captions in an FML Request Using the FMLCAP Function
FMLCAP(fieldname|'format')
where:
fieldname
Is the name of the caption field.
'format'
FMLFOR retrieves the tag value associated with each row in an FML request. If the FML row
was generated as a sum of data records using the OR phrase, FMLFOR returns the first value
specified in the list. If the OR phrase was generated by an FML Hierarchy ADD command,
FMLFOR returns the tag value associated with the parent specified in the ADD command.
The FMLFOR function is supported for COMPUTE but not for DEFINE. Attempts to use it in a
DEFINE result in blank values.
FMLFOR(output)
where:
output
Is name of the field that will contain the result, or the format of the output value enclosed
in single quotation marks.
558
19. Numeric Functions
The FMLINFO function returns the FOR value associated with each row in an FML report. With
FMLINFO, you can use the appropriate FOR value in a COMPUTE command to do drill-downs
and sign changes for each row in the report, even when the row is a summary row created
using an OR list or a Financial Modeling Language (FML) Hierarchy ADD command.
Note: You can use the SET parameter FORMULTIPLE=ON to enable an incoming record to be
used on more than one line in an FML report.
FMLINFO('FORVALUE', output)
where:
'FORVALUE'
Alphanumeric
Returns the FOR value associated with each row in an FML report. If the FML row was
generated as a sum of data records using the OR phrase, FMLINFO returns the first FOR
value specified in the list of values. If the OR phrase was generated by an FML Hierarchy
ADD command, FMLINFO returns the FOR value associated with the parent specified in the
ADD command.
output
Alphanumeric
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
Note: The parent value specified in the WITH CHILDREN ADD command (2000) is returned for
the first row on the report. Each subsequent row is also a consolidated subsection of the
hierarchy with a parent value that is returned by FMLINFO:
Month
Actual PRINT_AMT FORV ACTION
------ --------- ---- ------
Gross Margin -25,639,223 25,639,223 2000 CHANGED
Sales Revenue -62,362,490 62,362,490 2100 CHANGED
Retail Sales -49,355,184 49,355,184 2200 CHANGED
Mail Order Sales -6,899,416 6,899,416 2300 CHANGED
Internet Sales -6,107,890 6,107,890 2400 CHANGED
Cost Of Goods Sold 36,723,267 36,723,267 2500 UNCHANGED
Variable Material Costs 27,438,625 27,438,625 2600 UNCHANGED
Direct Labor 6,176,900 6,176,900 2700 UNCHANGED
Fixed Costs 3,107,742 3,107,742 2800 UNCHANGED
560
19. Numeric Functions
AMOUNT RETURNEDFOR
1010 8,784 1010
1020 4,494 1020
1030 7,961 1030
------ ---------
1010 21,239 1030
FMLLIST returns a string containing the complete tag list for each row in an FML request. If a
row has a single tag value, that value is returned.
The FMLLIST function is supported for COMPUTE but not for DEFINE. Attempts to use it in a
DEFINE result in blank values.
FMLLIST('A4096V')
where:
'A4096V'
INT(in_value)
where:
in_value
Numeric
Is the value for which the integer component is returned, the name of a field that contains
the value, or an expression that returns the value. If you supply an expression, use
parentheses as needed to ensure the correct order of evaluation.
562
19. Numeric Functions
LOG(in_value)
where:
in_value
Numeric
Is the value for which the natural logarithm is calculated, the name of a field that contains
the value, or an expression that returns the value. If you supply an expression, use
parentheses as needed to ensure the correct order of evaluation. If in_value is less than or
equal to 0, LOG returns 0.
The MAX and MIN functions return the maximum or minimum value, respectively, from a list of
values.
where:
MAX
Are the values for which the maximum or minimum value is returned, the name of a field
that contains the values, or an expression that returns the values. If you supply an
expression, use parentheses as needed to ensure the correct order of evaluation.
The MIRR function calculates the modified internal rate of return for a series of periodic cash
flows.
564
19. Numeric Functions
where:
field ...
Are fields that appear in the report output.
rrate
Is the field that contains the calculated return rate.
fmt
Is the format of the return rate. The data type must be D.
cashflow
Is a numeric field. Each value represents either a payment (negative value) or income
(positive value) for one period. The values must be in the correct sequence in order for the
sequence of cash flows to be calculated correctly. The dates corresponding to each cash
flow should be equally spaced and sorted in chronological order. The calculation requires
at least one negative value and one positive value in the cashflow field. If the values are all
positive or all negative, a zero result is returned.
finrate
Is a finance rate for negative cash flows. This value must be expressed as a non-negative
decimal fraction between 0 and 1. It must be constant within each sort group for which a
return rate is calculated, but it can change between sort groups.
reinvrate
Is the reinvestment rate for positive cash flows. This value must be expressed as a non-
negative decimal fraction between 0 and 1. It must be constant within each sort group but
can change between sort groups. It must be constant within each sort group for which a
return rate is calculated, but it can change between sort groups.
output
Is the name of the field that contains the return rate, or its format enclosed in single
quotation marks.
sort_field
Is a field that sorts the report output and groups it into subsets of rows on which the
function can be calculated separately. To calculate the function using every row of the
report output, use the WITHIN TABLE phrase. A WITHIN phrase is required.
The cash flow field must contain at least one negative value and one positive value.
In order to create one cash flow value per date, the values are summed. NEWDOLL is defined
in order to create negative values in each category as required by the function:
DEFINE FILE GGSALES
SDATE/YYM = DATE;
SYEAR/Y = SDATE;
NEWDOLL/D12.2 = IF DATE LT '19970401' THEN -1 * DOLLARS ELSE DOLLARS;
END
TABLE FILE GGSALES
SUM NEWDOLL
COMPUTE RRATE/D7.2% = MIRR(NEWDOLL, .1, .1, RRATE) * 100;
WITHIN CATEGORY
BY CATEGORY
BY SDATE
WHERE SYEAR EQ 97
END
566
19. Numeric Functions
A separate rate is calculated for each category because of the WITHIN CATEGORY phrase. A
portion of the output is shown:
Category SDATE NEWDOLL RRATE
-------- ----- ------- -----
Coffee 1997/01 -801,123.00 15.11%
1997/02 -682,340.00 15.11%
1997/03 -765,078.00 15.11%
1997/04 691,274.00 15.11%
1997/05 720,444.00 15.11%
1997/06 742,457.00 15.11%
1997/07 747,253.00 15.11%
1997/08 655,896.00 15.11%
1997/09 730,317.00 15.11%
1997/10 724,412.00 15.11%
1997/11 620,264.00 15.11%
1997/12 762,328.00 15.11%
Food 1997/01 -672,727.00 16.24%
1997/02 -699,073.00 16.24%
1997/03 -642,802.00 16.24%
1997/04 718,514.00 16.24%
1997/05 660,740.00 16.24%
1997/06 734,705.00 16.24%
1997/07 760,586.00 16.24%
To calculate one modified internal return rate for all of the report data, use the WITHIN TABLE
phrase. In this case, the data does not have to be sorted by CATEGORY:
DEFINE FILE GGSALES
SDATE/YYM = DATE;
SYEAR/Y = SDATE;
NEWDOLL/D12.2 = IF DATE LT '19970401' THEN -1 * DOLLARS ELSE DOLLARS;
END
The NORMSINV function is the inverse of NORMSDST. For information about NORMSINV, see
NORMSINV: Calculating Inverse Cumulative Normal Distribution on page 571.
The results of NORMSDST are returned as double-precision and are accurate to 6 significant
digits.
A standard normal distribution curve is a normal distribution that has a mean of 0 and a
standard deviation of 1. The total area under this curve is 1. A point on the X-axis of the
standard normal distribution is called a normalized value. Assuming that your data is normally
distributed, you can convert a data point to a normalized value to find the percentage of scores
that are less than or equal to the raw score.
You can convert a value (raw score) from your normally distributed data to the equivalent
normalized value (z-score) as follows:
z = (raw_score - mean)/standard_deviation
568
19. Numeric Functions
To convert from a z-score back to a raw score, use the following formula:
raw_score = z * standard_deviation + mean
The following diagram illustrates the results of the NORMSDST and NORMSINV functions.
The standard deviation describes the spread of the curve. It is the distance from the mean
to the point of inflection (where the curve changes direction).
NORMSDST(value, 'D8');
where:
value
Is a normalized value.
D8
Is the required format for the result. The value returned by the function is double-precision.
You can assign it to a field with any valid numeric format.
570
19. Numeric Functions
The results of NORMSINV are returned as double-precision and are accurate to 6 significant
digits.
Syntax: How to Calculate the Inverse Cumulative Standard Normal Distribution Function
NORMSINV(value, 'D8');
where:
value
Is a number between 0 and 1 (which represents a percentile in a standard normal
distribution).
D8
Is the required format for the result. The value returned by the function is double-precision.
You can assign it to a field with any valid numeric format.
The output shows that NORMSINV is the inverse of NORMSDST and returns the original values:
Size Z NORMSD NORMSI DSIZE
---- - ------ ------ -----
16 -.07298 .47091 -.07298 16
12 -.80273 .21106 -.80273 12
12 -.80273 .21106 -.80273 12
20 .65678 .74434 .65678 20
24 1.38654 .91721 1.38654 24
20 .65678 .74434 .65678 20
24 1.38654 .91721 1.38654 24
16 -.07298 .47091 -.07298 16
12 -.80273 .21106 -.80273 12
8 -1.53249 .06270 -1.53249 8
572
19. Numeric Functions
If PRDNOR generates a large set of numbers, they have the following properties:
The numbers lie roughly on a bell curve, as shown in the following figure. The bell curve
is highest at the 0 mark, meaning that there are more numbers closer to 0 than farther
away.
The numbers can be any size, but most are between 3 and -3.
{PRDNOR|PRDUNI}(seed, output)
where:
PRDNOR
seed
Numeric
Is the seed or the field that contains the seed, up to 9 digits. The seed is truncated to an
integer.
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
574
19. Numeric Functions
If RDNORM generates a large set of numbers (between 1 and 32768), they have the
following properties:
The numbers lie roughly on a bell curve, as shown in the following figure. The bell curve
is highest at the 0 mark, meaning that there are more numbers closer to 0 than farther
away.
The numbers can be any size, but most are between 3 and -3.
{RDNORM|RDUNIF}(output)
where:
RDNORM
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
576
19. Numeric Functions
SQRT(in_value)
where:
in_value
Numeric
Is the value for which the square root is calculated, the name of a field that contains the
value, or an expression that returns the value. If you supply an expression, use
parentheses as needed to ensure the correct order of evaluation. If you supply a negative
number, the result is zero.
The XIRR function calculates the internal rate of return for a series of cash flows that can be
periodic or non-periodic.
where:
field ...
Are fields that appear in the report output.
rrate
Is the field that contains the calculated return rate.
fmt
Is the format of the return rate. The data type must be D.
cashflow
Is a numeric field. Each value of this field represents either a payment (negative value) or
income (positive value) for one period. The values must be in the correct sequence in order
for the sequence of cash flows to be calculated correctly. The dates corresponding to each
cash flow should be equally spaced and sorted in chronological order. The calculation
requires at least one negative value and one positive value in the cashflow field. If the
values are all positive or all negative, a zero result is returned.
dates
Is a date field containing the cash flow dates. The dates must be full component dates
with year, month, and day components. Dates cannot be stored in fields with format A, I,
or P. They must be stored in date fields (for example, format YMD, not AYMD). There must
be the same number of dates as there are cash flow values. The number of dates must be
the same as the number of cash flows.
guess
Is an (optional) initial estimate of the expected return rate expressed as a decimal. The
default value is .1 (10%). To accept the default, supply the value 0 (zero) for this
argument.
578
19. Numeric Functions
maxiterations
Is an (optional) number specifying the maximum number of iterations that can be used to
resolve the rate using Newton's method. 50 is the default value. To accept the default,
supply the value 0 (zero) for this argument. The rate is considered to be resolved when
successive iterations do not differ by more than 0.0000003. If this level of accuracy is
achieved within the maximum number of iterations, calculation stops at that point. If it is
not achieved after reaching the maximum number of iterations, calculation stops and the
value calculated by the last iteration is returned.
output
D
Is the name of the field that contains the return rate, or its format enclosed in single
quotation marks.
sort_field
Is a field that sorts the report output and groups it into subsets of rows on which the
function can be calculated separately. To calculate the function using every row of the
report output, use the WITHIN TABLE phrase. A WITHIN phrase is required.
The cash flow field must contain at least one negative value and one positive value.
Dates cannot be stored in fields with format A, I, or P. They must be stored in date fields
(for example, format YMD, not AYMD).
The request is sorted by date so that the correct cash flows can be calculated. The rate
returned by the function is multiplied by 100 in order to express it as a percent rather than a
decimal value. Note that the format includes the % character. This causes a percent symbol to
display, but it does not calculate a percent:
TABLE FILE XIRR01
PRINT CASHFL
COMPUTE RATEX/D12.2%=XIRR(CASHFL, DATES, 0., 0., RATEX) * 100;
WITHIN TABLE
BY DATES
END
One rate is calculated for the entire report because of the WITHIN TABLE phrase:
DATES CASHFL RATEX
---- ------ -----
1998/01/01 -10,000.0000 37.49%
1998/03/01 2,750.0000 37.49%
1998/10/30 4,250.0000 37.49%
1999/02/15 3,250.0000 37.49%
1999/04/01 2,750.0000 37.49%
580
Chapter 20 Maintain-specific Script Functions
Script functions enable you to integrate JavaScript and VBScripts into your Maintain Data
applications and perform client-side execution without returning to the WebFOCUS
Server.
In this chapter:
where:
url
Is the URL of the webpage to display.
target
Is the window or frame to send the URL request output to.
newwindow
Determines if the URL appears in a new browser window. When this parameter is a non-
zero or true, a new browser window is created.
options
Are new window parameters. This includes, but is not limited to, the following:
screenX=distance, which is the distance the new window is placed from the left side of
the screen.
screenY=distance, which is the distance the new window is placed from the top of the
screen.
status={yes|no}, which determines whether a status bar appears at the bottom of the
window. When set to yes, a status bar is created. When set to no, a status bar is not
created.
titlebar={yes|no}, which determines whether a title bar appears at the bottom of the
window. When set to yes, a title bar is created. When set to no, a title bar is not
created.
3. IWCLink(theReport,"MyFrame",0,menubar=no,resizable=no,scrollbars=no,
status=no,toolbar=no,height=600,width=600");
582
20. Maintain-specific Script Functions
In this case, the target procedure is named rsales4, and rsales4 has a parameter named
STCD.
2. Assigns a value from an edit box (Form1.EditBox1) to the target procedure's STCD
parameter by appending the value to the URL string in theReport.
3. Invokes IWCLink to display a WebFOCUS reporting session, running the external procedure
rsales4, in the frame named MyFrame.
If you want the reporting session to appear in a new browser window, you would leave the
second argument blank and change the third argument from 0 to 1.
The remaining arguments beginning with "menubar" customize the appearance of the
browser window; for information about browser settings, see your browser documentation.
IWCSwitchToSecure();
IWCSwitchToUnsecure();
To control the Maintain Data application when a local validation test succeeds. If the
validation test fails, the function returns the end user to the form from which they executed
it.
If you use IWCTrigger in a script library, ensure the Maintain function you are calling is in
the same procedure in which you are using the script library.
IWCTrigger("functionname"[, "parm"]
where:
functionname
Is the Maintain function to call. Scripts are case-sensitive, so you must specify the name
using the same uppercase and lowercase letters that you used to name the function in the
Maintain Data procedure.
parm
Is a parameter being passed to the function.
584
20. Maintain-specific Script Functions
formname.Triggervalue
where:
formname
Is the name of the form in the Maintain Data application.
Syntax: How to Pass the Value of an ActiveX Control Property to a Maintain Function
IWCTrigger ("function",document.form.control.property);
where:
function
Is the Maintain function you are calling.
form
Is the name of the form on which the ActiveX control is located.
control
Is the name of the ActiveX control.
property
Is the name of the ActiveX control property (look for ActiveX control properties in the
ActiveX tab of the property sheet for the ActiveX control).
Note: IWC.FindAppCGIValue retrieves values, but cannot directly assign the values to a
Maintain Data variable as IWC.GetAppCGIValue does.
IWC.FindAppCGIValue(name,value);
where:
name
Is the WebFOCUS parameter or variable whose value you are finding.
value
Is the Maintain Data variable that receives the value of the WebFOCUS parameter or
variable.
586
20. Maintain-specific Script Functions
If the passed parameter or variable name is not found, the function returns a null value.
Therefore, you can check for errors by looking for a null value, then handle the error as
needed.
Note: Unlike Maintain Data variables, WebFOCUS parameters and variables are case-sensitive.
where:
mnt_var
Is the Maintain Data variable that receives the ASCII return value of the WebFOCUS
parameter or variable. The value is unescaped before being passed to the Maintain Data
variable.
type_length
Is the selected type and length format of the Maintain Data variable.
parm
Is the WebFOCUS parameter or variable to import. This value is case-sensitive.
588
Chapter 21 Simplified Statistical Functions
Simplified statistical functions can be called in a COMPUTE command to perform
statistical calculations on the internal matrix that is generated during TABLE request
processing. The STDDEV and CORRELATION functions can also be called as a verb object
in a display command. Prior to calling a statistical function, you need to establish the
size of the partition on which these functions will operate, if the request contains sort
fields.
Note: It is recommended that all numbers and fields used as parameters to these
functions be double-precision.
In this chapter:
where:
FIRST
Uses the first (also called the major) sort field in the request to partition the values.
PENULTIMATE
Uses the next to last sort field where the COMPUTE is evaluated to partition the values.
This is the default value.
TABLE
Uses the entire internal matrix to calculate the statistical function.
CORRELATION(field1, field2)
where:
field1
Numeric
Note: Arguments for CORRELATION cannot be prefixed fields. If you need to work with fields
that have a prefix operator applied, apply the prefix operators to the fields in COMPUTE
commands and save the results in a HOLD file. Then, run the correlation against the HOLD file.
590
21. Simplified Statistical Functions
Note: If there are not enough points to create the number of clusters requested, the value -10
is returned for any cluster that cannot be created.
Syntax: How to Partition Observations Into Clusters Based on the Nearest Mean Value
where:
number
Integer
Is the percent of training set size (the percent of the total data to use in the calculations).
The default value is AUTO, which uses the internal default percent.
iterations
Integer
Is the maximum number of times to recalculate using the means previously generated. The
default value is AUTO, which uses the internal default number of iterations.
tolerance
Numeric
Is a weight value between zero (0) and 1.0. The value AUTO uses the internal default
tolerance.
prefix1, prefix2
Defines an optional aggregation operator to apply to the field before using it in the
calculation. Valid operators are:
SUM. which calculates the sum of the field values. SUM is the default value.
Note: The operators PCT., RPCT., TOT., MDN., MDE., RNK., and DST. are not supported.
field1
Numeric
592
21. Simplified Statistical Functions
The equation generated is of the following form, where y is the dependent variable and x1, x2,
and x3 are the independent variables.
y = a1*x1 [+ a2*x2 [+ a3*x3] ...] + b
When there is one independent variable, the equation represents a straight line. When there
are two independent variables, the equation represents a plane, and with three independent
variables, it represents a hyperplane. You should use this technique when you have reason to
believe that the dependent variable can be approximated by a linear combination of the
independent variables.
594
21. Simplified Statistical Functions
where:
input_field1, input_field2 ...
Are any number of field names to be used as the independent variables. They should be
independent of each other. If an input field is non-numeric, it will be categorized to
transform it to numeric values that can be used in the linear regression calculation.
The output is shown in the following image. The orange line represents the regression
equation.
Given a numeric field as input, OUTLIER returns one of the following values for each value of
the field, using the 1.5 * IQR rule:
596
21. Simplified Statistical Functions
OUTLIER(input_field)
where:
input_field
Numeric
The output is shown in the following image. Values above 2 million are above the upper fence,
values below 1 million are below the lower fence, and other values are not outliers:
where:
rserve_mf
Is the synonym for the R script.
input_field1, ...input_fieldn
Are the independent variables used by the R script.
output
Is the dependent variable returned by the R script. It must be a single column (vector) of
output.
598
21. Simplified Statistical Functions
Using a configured connection (named MyRserve) for the Adapter for Rserve, and a sample
data file named wine_input_sample.csv, you create the following synonym for the R script, as
described in the Adapter Administration manual.
Master File
FILENAME=WINE_RUN_MODEL, SUFFIX=RSERVE , $
SEGMENT=INPUT_DATA, SEGTYPE=S0, $
FIELDNAME=AGST, ALIAS=AGST, USAGE=D9.4, ACTUAL=STRING,
MISSING=ON,
TITLE='AGST', $
FIELDNAME=HARVESTRAIN, ALIAS=HarvestRain, USAGE=I11, ACTUAL=STRING,
MISSING=ON,
TITLE='HarvestRain', $
FIELDNAME=WINTERRAIN, ALIAS=WinterRain, USAGE=I11, ACTUAL=STRING,
MISSING=ON,
TITLE='WinterRain', $
FIELDNAME=AGE, ALIAS=Age, USAGE=I11, ACTUAL=STRING,
MISSING=ON,
TITLE='Age', $
SEGMENT=OUTPUT_DATA, SEGTYPE=U, PARENT=INPUT_DATA, $
FIELDNAME=PRICE, ALIAS=Price, USAGE=D18.14, ACTUAL=STRING,
MISSING=ON,
TITLE='Price', $
Access File
SEGNAME=INPUT_DATA,
CONNECTION=MyRserve,
R_SCRIPT=/prediction/wine_run_model.r,
R_SCRIPT_LOCATION=WFRS,
R_INPUT_SAMPLE_DAT=prediction/wine_input_sample.csv, $
Now that the synonym has been created for the model, the model will be used to run against
the following data file named wine_forecast.csv.
Year,Price,WinterRain,AGST,HarvestRain,Age,FrancePop
1952,7.495,600,17.1167,160,31,43183.569
1953,8.0393,690,16.7333,80,30,43495.03
1955,7.6858,502,17.15,130,28,44217.857
1957,6.9845,420,16.1333,110,26,45152.252
1958,6.7772,582,16.4167,187,25,45653.805
1959,8.0757,485,17.4833,187,24,46128.638
1960,6.5188,763,16.4167,290,23,46583.995
1961,8.4937,830,17.3333,38,22,47128.005
1962,7.388,697,16.3,52,21,48088.673
1963,6.7127,608,15.7167,155,20,48798.99
1964,7.3094,402,17.2667,96,19,49356.943
1965,6.2518,602,15.3667,267,18,49801.821
1966,7.7443,819,16.5333,86,17,50254.966
1967,6.8398,714,16.2333,118,16,50650.406
1968,6.2435,610,16.2,292,15,51034.413
1969,6.3459,575,16.55,244,14,51470.276
1970,7.5883,622,16.6667,89,13,51918.389
1971,7.1934,551,16.7667,112,12,52431.647
1972,6.2049,536,14.9833,158,11,52894.183
1973,6.6367,376,17.0667,123,10,53332.805
1974,6.2941,574,16.3,184,9,53689.61
1975,7.292,572,16.95,171,8,53955.042
1976,7.1211,418,17.65,247,7,54159.049
1977,6.2587,821,15.5833,87,6,54378.362
1978,7.186,763,15.8167,51,5,54602.193
The data file can be any type of file that R can read. In this case it is another .csv file. This file
needs a synonym in order to be used in a report request. You create the synonym for this file
using the Adapter for Delimited Files.
600
21. Simplified Statistical Functions
The following request, wine_forecast_price_report.fex, uses the RSERVE bulit-in function to run
the script and return a report.
-*wine_forecast_price_report.fex
TABLE FILE PREDICTION/WINE_FORECAST
PRINT
YEAR
WINTERRAIN
AGST
HARVESTRAIN
AGE
602
21. Simplified Statistical Functions
To calculate the standard deviation for a sample, the mean is calculated using the sample
observations, and the divisor is N-1 instead of N.
STDDEV(field, sampling)
where:
field
Numeric
Indicates the origin of the data set. Can be one of the following values.
P Entire population.
S Sample of population.
Note: Arguments for STDDEV cannot be prefixed fields. If you need to work with fields that
have a prefix operator applied, apply the prefix operators to the fields in COMPUTE commands
and save the results in a HOLD file. Then, run the standard deviation against the HOLD file.
604
Chapter 22 Machine Learning (Python-based)
Functions
The Machine Learning (Python-based) functions are FOCUS functions implemented as
Python scripts. These Python scripts take advantage of Python packages such as scipy,
numpy, scikit-learn, and pandas, which extends the Python capabilities to machine
learning.
You can generate the .csv file and accompanying Master File used in the examples by
running the WebFOCUS - Machine Learning Demo tutorial in the server Web Console.
In this chapter:
where:
'options'
Is a dictionary of advanced parameters that control the model attributes, enclosed in
single quotation marks. Most of these parameters have a default value, so you can omit
them from the request, if you want to use the default values. Even with no advanced
parameters, the single quotation marks are required. The format of the advanced
parameter dictionary is:
'{"parm_name1": "parm_value1", ... ,"parm_namei": "parm_valuei"}'
606
22. Machine Learning (Python-based) Functions
"train_ratio"
Is a value between 0 and 1 that specifies the fraction of data used for training the
model. The default value is "1.0".
predictor_field1[, predictor_field2, ...]
Numeric
The following version of the request uses grade mode with the same advanced parameters and
predictors.
TABLE FILE imports85
PRINT horsepower peakRpm cityMpg highwayMpg price
COMPUTE AnomalyGradeScore/D5.2 =
ANOMALY_IF('{"trees":"123","score":"grade","contamination":"0.2"}',
horsepower, peakRpm, cityMpg,
highwayMpg, price);
ON TABLE SET PAGE NOLEAD
ON TABLE SET STYLE *
GRID=OFF,$
ENDSTYLE
END
608
22. Machine Learning (Python-based) Functions
CLASSIFY_BLR('options',
predictor_field1[, predictor_field2, ...] target_field)
where:
'options'
Is a dictionary of advanced parameters that control the model attributes, enclosed in
single quotation marks. Most of these parameters have a default value, so you can omit
them from the request, if you want to use the default values. Even with no advanced
parameters, the single quotation marks are required. The format of the advanced
parameter dictionary is:
'{"parm_name1": "parm_value1", ... ,"parm_namei": "parm_valuei"}'
610
22. Machine Learning (Python-based) Functions
612
22. Machine Learning (Python-based) Functions
CLASSIFY_KNN('options',
predictor_field1[, predictor_field2, ...] target_field)
where:
'options'
Is a dictionary of advanced parameters that control the model attributes, enclosed in
single quotation marks. Most of these parameters have a default value, so you can omit
them from the request, if you want to use the default values. Even with no advanced
parameters, the single quotation marks are required. The format of the advanced
parameter dictionary is:
'{"parm_name1": "parm_value1", ... ,"parm_namei": "parm_valuei"}'
power=1 calculates the distance as the sum of the absolute values of the
differences between the coordinates (Manhattan distance).
power=2 calculates the distance as the square root of the sum of the squares of
the differences between the coordinates (Euclidean distance). This is the default
value.
"prediction_ratio"
Is the fraction of the data that will be used for prediction. Allowed values are numbers
between 0 and 1. The default value is "0.8".
"test_ratio"
Is a value between 0 and 1 that specifies the fraction of data used for testing the
model. The default value is "0.2".
"kfold"
Is the number of folds used in the grid-search with cross-validation. A grid-search of
the nearest neighbors grid K/2, K, 2K is done. Suggested values are integers between
"2" and "10". The default value is "4".
predictor_field1[, predictor_field2, ...]
Numeric
614
22. Machine Learning (Python-based) Functions
CLASSIFY_RF('options', number_of_trees,
predictor_field1[, predictor_field2, ...] target_field)
where:
'options'
Is a dictionary of advanced parameters that control the model attributes, enclosed in
single quotation marks. Most of these parameters have a default value, so you can omit
them from the request, if you want to use the default values. Even with no advanced
parameters, the single quotation marks are required. The format of the advanced
parameter dictionary is:
'{"parm_name1": "parm_value1", ... ,"parm_namei": "parm_valuei"}'
616
22. Machine Learning (Python-based) Functions
target_field
Numeric or alphanumeric
618
22. Machine Learning (Python-based) Functions
CLASSIFY_XGB('options',
predictor_field1[, predictor_field2, ...] target_field)
where:
'options'
Is a dictionary of advanced parameters that control the model attributes, enclosed in
single quotation marks. Most of these parameters have a default value, so you can omit
them from the request, if you want to use the default values. Even with no advanced
parameters, the single quotation marks are required. The format of the advanced
parameter dictionary is:
"l2_grid"
Is a grid consisting of comma-separated positive numbers to be used as L2-
regularization strengths. The default value is "0,1,1,10". The optimal value is chosen
by cross-validation.
"kfold"
Is the number of folds used in the grid-search with cross-validation. Suggested values
are integers between "2" and "10". The default value is "4".
"max_depth_grid"
Is the maximum depth of each decision tree. A grid in the form "4,5,6" is allowed. The
default value is "5". The optimal value is chosen by cross-validation.
"scoring"
The training optimizes either for F1 Score (weighted average of Precision and
Recall) or accuracy (ratio of correctly predicted observations to total observations).
Allowed values are "f1_score" and "accuracy". The default value is "f1_score".
predictor_field1[, predictor_field2, ...]
Numeric or Alphanumeric
620
22. Machine Learning (Python-based) Functions
REGRESS_KNN('options',
predictor_field1[, predictor_field2, ...] target_field)
where:
'options'
Is a dictionary of advanced parameters that control the model attributes, enclosed in
single quotation marks. Most of these parameters have a default value, so you can omit
them from the request, if you want to use the default values. Even with no advanced
parameters, the single quotation marks are required. The format of the advanced
parameter dictionary is:
'{"parm_name1": "parm_value1", ... ,"parm_namei": "parm_valuei"}'
power=1 calculates the distance as the sum of the absolute values of the
differences between the coordinates (Manhattan distance).
power=2 calculates the distance as the square root of the sum of the squares of
the differences between the coordinates (Euclidean distance).
"prediction_ratio"
Is the fraction of the data that will be used for prediction. Allowed values are numbers
between 0 and 1. The default value is "0.8".
"test_ratio"
Is a value between 0 and 1 that specifies the fraction of data used for testing the
model. The default value is "0.2".
622
22. Machine Learning (Python-based) Functions
"kfold"
Is the number of folds used in the grid-search with cross-validation. A grid-search of
the nearest neighbors grid K/2, K, 2K is done. Suggested values are integers between
"2" and "10". The default value is "4".
predictor_field1[, predictor_field2, ...]
Numeric
624
22. Machine Learning (Python-based) Functions
REGRESS_POLY('options',
predictor_field1, predictor_field2, [...,] target_field)
where:
'options'
Is a dictionary of advanced parameters that control the model attributes, enclosed in
single quotation marks. Most of these parameters have a default value, so you can omit
them from the request, if you want to use the default values. Even with no advanced
parameters, the single quotation marks are required. The format of the advanced
parameter dictionary is:
'{"parm_name1": "parm_value1", ... ,"parm_namei": "parm_valuei"}'
"no", which generates the most general polynomial of degree degree based on the
predictor fields.
"yes", which uses only terms linear in each predictor X0, X1, . . ., and cross-terms
of the form X0*X1*X2 of at most degree predictors.
"train_ratio"
Optional. Is a value between 0 and 1 that specifies the fraction of data used for
training the model. The default value is "0.8".
"test_ratio"
Optional. Is a value between 0 and 1 that specifies the fraction of data used for
testing the model. The default value is "0.2".
"l2_grid"
Optional. Is a grid consisting of comma-separated positive numbers to be used as L2-
regularization strengths. The default value is "0,1,1,10". The optimal value is chosen
by cross-validation.
"kfold"
Optional. Is the number of folds used for cross-validation. Suggested values are
integers between "2" and "10". The default value is "4".
predictor_field1, predictor_field2, [...,]
Numeric
626
22. Machine Learning (Python-based) Functions
REGRESS_RF('options',
predictor_field1[, predictor_field2, ...] target_field)
where:
'options'
Is a dictionary of advanced parameters that control the model attributes, enclosed in
single quotation marks. Most of these parameters have a default value, so you can omit
them from the request, if you want to use the default values. Even with no advanced
parameters, the single quotation marks are required. The format of the advanced
parameter dictionary is:
'{"parm_name1": "parm_value1", ... ,"parm_namei": "parm_valuei"}'
628
22. Machine Learning (Python-based) Functions
630
22. Machine Learning (Python-based) Functions
REGRESS_XGB('options',
predictor_field1[, predictor_field2, ...] target_field)
where:
'options'
Is a dictionary of advanced parameters that control the model attributes, enclosed in
single quotation marks. Most of these parameters have a default value, so you can omit
them from the request, if you want to use the default values. Even with no advanced
parameters, the single quotation marks are required. The format of the advanced
parameter dictionary is:
"l2_grid"
Is a grid consisting of comma-separated positive numbers to be used as L2-
regularization strengths. The default value is "0,1,1,10". The optimal value is chosen
by cross-validation.
"kfold"
Is the number of folds used in the grid-search with cross-validation. Suggested values
are integers between "2" and "10". The default value is "4".
"max_depth_grid"
Is the maximum depth of each decision tree. A grid in the form "4,5,6" is allowed. The
default value is "5". The optimal value is chosen by cross-validation.
predictor_field1[, predictor_field2, ...]
Numeric or Alphanumeric
632
22. Machine Learning (Python-based) Functions
Use the RUN_MODEL function when the predictor fields in the new data source have the same
field names as the predictor fields used to generate the model. Use the RUN_MODEL2
function If the field names are different. The data types and lengths must be the same in
either case.
where:
fieldname
Is the fieldname in the COMPUTE command that returned the value from the machine
learning function.
app
Is the application folder in which to save the model.
modelname
Is the name of the saved model.
634
22. Machine Learning (Python-based) Functions
Use the RUN_MODEL2 function if the predictor field names are not the same in the model and
the data.
COMPUTE fieldname/fmt = RUN_MODEL2('app/modelname',
pfield1, ..., pfieldn);
where:
fieldname
Is the name of the field that will contain the returned predictions from the model.
app/modelname'
Is the application folder and saved model name.
pfield1, ..., pfieldn
Are the field names in the data used for running the model that match the predictor fields
used to generate the model.
636
22. Machine Learning (Python-based) Functions
638
Chapter 23 Simplified System Functions
Simplified system functions have streamlined parameter lists, similar to those used by
SQL functions. In some cases, these simplified functions provide slightly different
functionality than previous versions of similar functions.
The simplified functions do not have an output argument. Each function returns a value
that has a specific data type.
When used in a request against a relational data source, these functions are optimized
(passed to the RDBMS for processing).
In this chapter:
EDAPRINT(message_type, 'message')
where:
message_type
Keyword
I. Informational message.
W. Warning message.
E. Error message.
'message'
Is the message to insert, enclosed in single quotation marks.
ENCRYPT(password)
where:
password
Fixed length alphanumeric
640
23. Simplified System Functions
GETENV(var_name)
where:
var_name
fixed length alphanumeric
The value returned is ON if the server was started with security on or OFF if the server was
started with security off.
PUTENV(var_name, var_value)
where:
var_name
Fixed length alphanumeric
This causes UNIX to display the following prompt when the user issues the UNIX shell
command SH:
FOCUS/Shell:
The following request creates a variable named xxxx and sets it to the value this is a test. It
then retrieves the value using GETENV.
-SET &XXXX=PUTENV(xxxx,'this is a test');
-SET &YYYY=GETENV(xxxx);
-TYPE Return Code: &XXXX, Variable value: &YYYY
If the message is sent successfully, the function returns the value true.
where:
workspace
Is a Workspace name.
642
23. Simplified System Functions
channel
Is a Channel name.
message
Is an alphanumeric field containing the message.
The following request sends a Slack message to the general channel of the devibi Workspace,
when the department is MIS.
TABLE FILE ibisamp/EMPLOYEE
SUM
CURR_SAL
AND COMPUTE SLACK_MESSAGE/A200 = 'Salary for Department ' | DEPARTMENT ||
' is ' | LJUST(20, FPRINT(CURR_SAL,'D12.2M'), 'A20');
AND COMPUTE CURR_SAL_SLACK/A20=IF DEPARTMENT EQ 'MIS'
THEN SLACK('devibi', 'general', SLACK_MESSAGE) ELSE 'false';
AS 'Message Sent,to Slack highlighting,Salary'
BY DEPARTMENT
HEADING
"Slack"
"Slack Function Example"
ON TABLE SET PAGE-NUM NOLEAD
ON TABLE NOTOTAL
ON TABLE SET STYLE *
INCLUDE=IBFS:/FILE/IBI_HTML_DIR/javaassist/intl/EN/ENIADefault_combine.sty,
$
ENDSTYLE
END
644
Chapter 24 System Functions
System functions call the operating system to obtain information about the operating
environment or to use a system service.
For many functions, the output argument can be supplied either as a field name or as a
format enclosed in single quotation marks. However, if a function is called from a
Dialogue Manager command, this argument must always be supplied as a format, and if
a function is called from a Maintain Data procedure, this argument must always be
supplied as a field name. For detailed information about calling a function and supplying
arguments, see Accessing and Calling a Function on page 59.
In this chapter:
Note: You can see your list of general privileges by clicking the Console (C) button at the top
left corner of the window and selecting My Console/Show My General Privileges. A user with
Server Administrator privileges can also see the list of general privileges on the Access Control
page by right-clicking a user ID, selecting Properties from the context menu and clicking the
General Privileges tab on the Properties page.
Syntax: How to Retrieve the Privilege State for the Connected User
CHECKPRIVS(privcode, output)
where:
privcode
Is the privilege code for which to retrieve the status.
output
Alphanumeric
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
646
24. System Functions
CLSDDREC(output)
where:
output
Integer
The FEXERR function retrieves an Information Builders error message. It is especially useful in
a procedure using a command that suppresses the display of output messages.
An error message consists of up to four lines of text. The first line contains the message and
the remaining three contain a detailed explanation, if one exists. FEXERR retrieves the first line
of the error message.
FEXERR(error, 'A72')
where:
error
Numeric
'A72'
Is the format of the output value enclosed in single quotation marks. The format is A72,
the maximum length of an Information Builders error message.
The FGETENV function retrieves the value of an environment variable and returns it as an
alphanumeric string.
where:
length
Integer
Is the length of the environment variable value returned or a field in which the environment
variable value is stored.
648
24. System Functions
output
Alphanumeric
Is the format of the field in which the environment variable's value is stored.
To use this function, allocate the PDS to a ddname because the ddname is required in the
function call. You can search multiple PDSs with one function call if they are concatenated to
one ddname.
where:
ddname
A8
Is the ddname to which the PDS is allocated. This value must be an eight-character literal
enclosed in single quotation marks, or a variable that contains the ddname. If you supply a
literal less than eight characters long, pad it with trailing spaces.
member
A8
Is the member for which you are searching. This value must be eight characters long. If you
supply a literal that has less than eight characters, pad it with trailing spaces.
output
A1
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks. The result is one of the following:
E indicates an error occurred. Either the data set is not allocated to the ddname, or the
data set allocated to the ddname is not a PDS (and may be a sequential file).
The FPUTENV function assigns a character string to an environment variable. Use FPUTENV to
set values that are used elsewhere in the system.
650
24. System Functions
Limit: You cannot use FPUTENV to set or change FOCPRINT, FOCPATH, or USERPATH. Once
started, these variables are held in memory and not reread from the environment.
where:
varname_length
Integer
Is the name of the environment variable enclosed in single quotation marks. The name
must be right-justified and padded with blanks to the maximum length specified by
varname_length.
value_length
Is the maximum length of the environment variable value.
Is the value you wish to assign to the environment variable. The string must be right-
justified and contain no embedded blanks. Strings that contain embedded blanks are
truncated at the first blank.
output
Integer
Is the return code. It can be the name of the field that contains the result, or the format of
the output value enclosed in single quotation marks. If the variable is set successfully, the
return code is 0. Any other value indicates a failure occurred.
The request displays the following prompt when the user issues the UNIX shell command SH:
FOCUS/Shell:
GETCOOKI('cookie_name', length)
where:
cookie_name
Alphanumeric
Is the name of the browser cookie whose value is being retrieved. The maximum length of
the cookie name is 80 bytes. If the cookie is not set or its name exceeds 80 characters,
the function will return Invalid Cookie Name.
length
Alphanumeric (An)
Is the length of the cookie. It can be the name of the field that contains the result, or the
format of the output value enclosed in single quotation marks. If the length n specified is
greater than the actual length of the retrieved cookie, the result will be padded with
blanks. It is always recommended to use the function TRUNCATE(arg1) on return from
GETCOOKI to remove extra trailing blanks.
652
24. System Functions
GETHEADR('varname', output)
where:
varname
Alphanumeric
Is the name of the HTTP header variable whose value is being retrieved.
output
Alphanumeric
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks.
The following function call retrieves the value application/x-www-form-urlencoded from the HTTP
Header:
GETHEADR('content-type', 'A150')
The following function call retrieves the value en-us from the HTTP Header:
GETHEADR('accept-language', 'A10')
The GETPDS function determines if a specific member of a partitioned data set (PDS) exists,
and if it does, returns the PDS name. This function is used primarily in Dialogue Manager
procedures.
To use this function, allocate the PDS to a ddname because the ddname is required in the
function call. You can search multiple PDSs with one function call if they are concatenated to
one ddname.
GETPDS is almost identical to FINDMEM, except that GETPDS provides either the PDS name or
returns a different set of status codes.
where:
ddname
A8
Is the ddname to which the PDS is allocated. This value must be an eight-character literal
enclosed in single quotation marks, or a variable that contains the ddname. If you supply a
literal less than eight characters long, pad it with trailing spaces.
member
A8
Is the member for which the function searches. This value must be eight characters long. If
you supply a literal with less than eight characters, pad it with trailing spaces.
output
A44
654
24. System Functions
Is the name of the field that contains the result, or the format of the output value enclosed
in single quotation marks. The maximum length of a PDS name is 44. The result is one of
the following:
PDS name is the name of the PDS that contains the member, if it exists.
*E indicates an error occurred. For example, the data set allocated to the ddname is not a
PDS (and may be a sequential file).
GETUSER(output)
where:
output
Alphanumeric, at least A8
656
24. System Functions
Is the result field, whose length depends on the platform on which the function is issued.
Provide a length as long as required for your platform; otherwise the output will be
truncated.
GRPLIST returns a group name or a list of group names (separated by colons) for the
connected user. This function is supported for LDAP security with all types of connections.
If the group list is empty or there is an error in the function parameters, the function returns
blanks.
Syntax: How to Retrieve a List of Group Memberships for the Connected User
GRPLIST(outputLength, outformat)
where:
outputLength
Is the length of the output string.
outformat
Is the format of the output string enclosed in single quotation marks (').
Issuing the same request for user pgmuser1 shows that this user belongs to a single group:
pgmgrp1
The JOBNAME function retrieves the raw identification string of the current process from the
operating system. This is also commonly known as a process PID at the operating system
level. The function is valid in all environments, but is typically used in Dialogue Manager and
returns the value as an alphanumeric string (even though a PID is pure numeric on some
operating systems).
Note: JOBNAME strings differ between some operating systems in terms of look and length.
For example, Windows, UNIX, and z/OS job names are pure numeric (typically a maximum of 8
characters long), while an IBM i job name is a three-part string that has a 26 character
maximum length. Since an application may eventually be run in another (unexpected)
environment in the future, it is good practice to use the maximum length of 26 to avoid
accidental length truncation in the future. Applications using this function for anything more
than simple identification may also need to account for the difference in the application code.
JOBNAME(length, output)
where:
length
Integer
Is the maximum number of characters to return from the PID system call.
658
24. System Functions
output
Alphanumeric
Is the returned process identification string, whose length depends on the platform on
which the function is issued. Provide a length as long as required for your platform.
Otherwise, the output will be truncated.
The MVSDYNAM function transfers a FOCUS DYNAM command to the DYNAM command
processor. It is useful in passing allocation commands to the processor in a compiled MODIFY
procedure after the CASE AT START command.
where:
command
Alphanumeric
Is the DYNAM command enclosed in single quotation marks, or a field or variable that
contains the command. The function converts lowercase input to uppercase.
length
Numeric
outfield
I4
Is the field that contains the result, or the format of the output value enclosed in single
quotation marks.
PUTCOOKI('cookie_name', 'cookie_value')
where:
cookie_name
Alphanumeric
Is the value to submit for the cookie. It can be the name of the field that contains the
result, or the format of the output value enclosed in single quotation marks
660
24. System Functions
SET &COOKIE_VALUE=CUSTOM_EXIT();
PUTCOOKI('MYSAPSSO2', &COOKIE_VALUE )
PUTDDREC opens the file if it is not already open. Each call to PUTDDREC can use the same
file or a new one. All of the files opened by PUTDDREC remain open until the end of a request
or connection. At the end of the request or connection, all files opened by PUTDDREC are
automatically closed.
The open, close, and write operations are handled by the operating system. Therefore, the
requirements for writing to the file and the results of deviating from the instructions when
calling PUTDDREC are specific to your operating environment. Make sure you are familiar
with and follow the guidelines for your operating system when performing input/output
operations.
You can call PUTDDREC in a DEFINE FILE command or in a DEFINE in the Master File.
However, PUTDDREC does not open the file until its field name is referenced in a request.
If PUTDDREC is called in a Dialogue Manager -SET command, the files opened by PUTDDREC
are not closed automatically until the end of a request or connection. In this case, you can
close the files and free the memory used to store information about open file by calling the
CLSDDREC function.
where:
ddname
Alphanumeric
dd_len
Numeric
Is the character string to be added as the new record in the sequential file.
record_len
Numeric
Is the return code, which can have one of the following values:
0 - Record is added.
-1 - FILEDEF statement is not found.
-2 - Error while opening the file.
-3 - Error while adding the record to the file.
662
24. System Functions
The SLEEP function suspends execution for the number of seconds you specify as its input
argument.
This function is most useful in Dialogue Manager when you need to wait to start a specific
procedure. For example, you can start a FOCUS Database Server and wait until the server is
started before initiating a client application.
SLEEP(delay, output);
where:
delay
Numeric
Is the number of seconds to delay execution. The number can be specified down to the
millisecond.
output
Numeric
664
24. System Functions
Is the name of a field or a format enclosed in single quotation marks. The value returned
is the same value you specify for delay.
The SPAWN function creates a subprocess from a procedure that executes a system command
without terminating the current procedure.
Limit: On UNIX, you can invoke this function only from a COMPUTE or DEFINE command.
where:
inlength
Numeric
outcode
D
Is the return code specifying whether or not the spawn was successful, or the format of
the output value enclosed in single quotation marks. Zero indicates a successful spawn; a
non-zero value indicates an unsuccessful spawn.
The SYSTEM function calls a DOS program, a batch program, or a Windows application from a
procedure. SYSTEM passes a command string to DOS or Windows and the program is
executed as if it had been entered at the DOS command line or the command line field in the
Windows Program Manager Run dialog box. When you exit the program, control returns to
WebFOCUS.
SYSTEM suspends FOCUS execution of subsequent commands until you exit the application. It
has an advantage over the FOCUS DOS command, which also enables you to call DOS
programs and Windows applications from a procedure.
If the command name in the string passed to SYSTEM contains a .COM or .EXE extension,
the command is called directly rather than using the DOS command interpreter.
If the command name in the string does not contain a suffix or contains a .BAT extension,
SYSTEM calls the DOS command interpreter COMMAND.COM to perform the specified
command and then exit.
666
24. System Functions
SYSTEM passes the following commands to FOCUS, not to the DOS command interpreter:
CD, CLS, COPY, DEL, DIR, drive:, REN, TYPE. As a result, these commands are interpreted
directly by FOCUS, not by DOS, and you may observe a slightly different behavior. If you
want SYSTEM to pass these commands to the DOS command interpreter instead, use the
following syntax:
SYSTEM(length, 'COMMAND /C string', returncode)
where:
length
Integer
Is a valid Windows or DOS command with command line parameters enclosed in single
quotation marks.
returncode
Double precision
Is the name or length of the variable that contains the value of the DOS error level.
The SYSVAR function populates a Dialogue Manager amper variable with the contents of any
z/OS system variable. System variables are in the format [&]name[.], where the dot is
optional. They can be provided by the operating system or can be user defined. The function
can be called in a -SET command.
where:
&dmvar
Alphanumeric
Is the name of the Dialogue Manager variable to be populated with the value of the z/OS
system variable.
length
Alphanumeric
Is the length of the next parameter in the call. Do not include the escape character in the
length, if one is present in the sysvar argument.
[&|]sysvar[.]
Alphanumeric
Is the name of the system variable to be retrieved. Note that the ampersand (&) and the
dot (.) are optional. If the ampersand is included, it must be followed by the escape
character (|).
outfmt
Alphanumeric
668
24. System Functions
670
Chapter 25 Simplified Geography Functions
The simplified geography functions perform location-based calculations and retrieve
geocoded points for various types of location data. They are used by the WebFOCUS
location intelligence products that produce maps and charts. Some of the geography
functions use GIS services and require valid credentials for accessing Esri ArcGIS
proprietary data.
In this chapter:
esri-citibike.mas
FILENAME=ESRI-CITIBIKE, SUFFIX=DFIX ,
DATASET=esri/esri-citibike.csv, $
SEGMENT=CITIBIKE_TRIPDATA, SEGTYPE=S0, $
FIELDNAME=TRIPDURATION, ALIAS=tripduration, USAGE=I7, ACTUAL=A5V,
TITLE='tripduration', $
FIELDNAME=STARTTIME, ALIAS=starttime, USAGE=HMDYYS, ACTUAL=A18,
TITLE='starttime', $
FIELDNAME=STOPTIME, ALIAS=stoptime, USAGE=HMDYYS, ACTUAL=A18,
TITLE='stoptime', $
FIELDNAME=START_STATION_ID, ALIAS='start station id', USAGE=I6, ACTUAL=A4V,
TITLE='start station id', $
FIELDNAME=START_STATION_NAME, ALIAS='start station name', USAGE=A79V,
ACTUAL=A79BV, TITLE='start station name', $
FIELDNAME=START_STATION_LATITUDE, ALIAS='start station latitude', USAGE=P20.15,
ACTUAL=A18V, TITLE='start station latitude',
GEOGRAPHIC_ROLE=LATITUDE, $
FIELDNAME=START_STATION_LONGITUDE, ALIAS='start station longitude', USAGE=P20.14,
ACTUAL=A18V, TITLE='start station longitude',
GEOGRAPHIC_ROLE=LONGITUDE, $
FIELDNAME=END_STATION_ID, ALIAS='end station id', USAGE=I6,
ACTUAL=A4V, TITLE='end station id', $
672
25. Simplified Geography Functions
esri-citibike.acx
SEGNAME=CITIBIKE_TRIPDATA,
DELIMITER=',',
ENCLOSURE=",
HEADER=NO,
CDN=OFF, $
esri-citibike.csv
Note: Each complete record must be on a single line. Therefore, you must remove any line
breaks that may have been inserted due to the page width in this document.
esri-geo10036.mas
FILENAME=ESRI-GEO10036, SUFFIX=FIX ,
DATASET=esri/esri-geo10036.ftm (LRECL 80 RECFM V, IOTYPE=STREAM, $
SEGMENT=ESRIGEO, SEGTYPE=S0, $
FIELDNAME=GEOMETRY, ALIAS=GEOMETRY, USAGE=TX80L, ACTUAL=TX80,
MISSING=ON, $
674
25. Simplified Geography Functions
esri-geo10036.ftm
{"rings":[[[-73.9803889998524,40.7541490002762],[-73.9808779999197,40.7534830001
404],[-73.9814419998484,40.7537140000011],[-73.9824040001445,40.7541199998382],[
-73.982461000075,40.7541434001978],[-73.9825620002361,40.7541850001377],[-73.983
2877000673,40.7544888999428],[-73.9833499997027,40.7545150000673],[-73.983644399
969,40.7546397998869],[-73.9836849998628,40.7546570003204],[-73.9841276003085,40
.7548161002829],[-73.984399700086,40.7544544999752],[-73.9846140004357,40.754165
0001147],[-73.984871999743,40.7542749997914],[-73.9866590003126,40.7550369998577
],[-73.9874449996869,40.7553720000178],[-73.9902640001834,40.756570999552],[-73.
9914340001789,40.7570449998269],[-73.9918260002697,40.7572149995726],[-73.992429
0001982,40.7574769999636],[-73.9927679996434,40.7576240004473],[-73.993069000034
3,40.7578009996165],[-73.9931059999419,40.7577600004237],[-73.9932120003335,40.7
576230004012],[-73.9933250001486,40.7576770001934],[-73.9935390001247,40.7577669
998472],[-73.993725999755,40.7578459998931],[-73.9939599997542,40.757937999639],
[-73.9940989998689,40.7579839999617],[-73.9941529996611,40.7579959996157],[-73.9
942220001452,40.7580159996387],[-73.9943040003293,40.7580300002843],[-73.9943650
004444,40.7580330004227],[-73.99446499966,40.7580369997078],[-73.9945560002591,4
0.7580300002843],[-73.9946130001898,40.7580209998693],[-73.9945689999594,40.7580
809999383],[-73.9945449997519,40.7581149997075],[-73.9944196999092,40.7582882001
404],[-73.9943810002829,40.7583400001909],[-73.9953849998179,40.7587409997973],[
-73.9959560000693,40.7589690004191],[-73.9960649996999,40.7590149998424],[-73.99
68730000888,40.7593419996336],[-73.996975000296,40.7593809996335],[-73.997314999
7874,40.7595379996789],[-73.9977009996014,40.7597030000935],[-73.998039999946,40
.7598479995856],[-73.998334000014,40.7599709998618],[-73.9987769997587,40.760157
0003453],[-73.9990089996656,40.7602540003219],[-74.0015059997021,40.761292999672
2],[-74.0016340002089,40.7613299995799],[-74.0015350001401,40.7614539999022],[-7
4.0014580001865,40.7615479997405],[-74.0013640003483,40.7616560002242],[-74.0013
050003255,40.7617199995784],[-74.0011890003721,40.7618369995779],[-74.0010579997
269,40.7619609999003],[-74.0009659999808,40.7620389999],[-74.0008649998198,40.76
21230001764],[-74.0008390004195,40.7621430001993],[-74.0006839995669,40.76226100
0245],[-74.000531999752,40.7623750001062],[-74.0003759997525,40.7624849997829],[
-74.0002840000066,40.7625510001286],[-73.9998659996161,40.762850999574],[-73.999
8279996624,40.7628779999198],[-73.9995749996864,40.7630590001727],[-73.999312000
1487,40.7632720001028],[-73.9991639996189,40.7633989996642],[-73.998941000127,40
.7636250001936],[-73.9987589998279,40.7638580001466],[-73.9986331999622,40.76402
77004181],[-73.9986084002574,40.7640632002565],[-73.9984819996445,40.76423400039
89],[-73.9983469997142,40.7644199999831],[-73.998171999738,40.7646669996823],[-7
3.9980319995771,40.7648580003964],[-73.9979881998955,40.7649204996813],[-73.9979
368000432,40.7649942000224],[-73.9978947999051,40.7650573998791],[-73.9977017001
733,40.7653310995507],[-73.9975810003629,40.765481000348],[-73.9975069996483,40.
7654519999099],[-73.9956019999323,40.7646519998899],[-73.9955379996789,40.764625
0004434],[-73.9954779996099,40.7646030003282],[-73.9949389999348,40.764369000329
1],[-73.9936289997785,40.7638200001929],[-73.9934620001711,40.7637539998473],[-7
3.9931520002646,40.7636270002859],[-73.992701000151,40.7634409998023],[-73.99244
19000736,40.7633312995998],[-73.9898629996777,40.7622390001298],[-73.98861200044
34,40.761714000201],[-73.988021000169,40.761460000179],[-73.987028000242,40.7610
439998808],[-73.9867690998141,40.7609346998765],[-73.9848240002274,40.7601130001
149],[-73.9841635003452,40.7598425002312],[-73.9813259998949,40.7586439998208],[
-73.9805479999902,40.7583159999834],[-73.9793569999256,40.757814000216],[-73.978
1150002071,40.7572939996184],[-73.9785670003668,40.7566709996669],[-73.979014000
2958,40.7560309998308],[-73.9794719998329,40.7554120000638],[-73.9799399998311,4
0.7547649999048],[-73.9802380000836,40.7543610001601],[-73.9803889998524,40.7541
490002762]]]}
%$
GIS_DISTANCE(geo_point1,geo_point2)
where:
geo_point1,geo_point2
Fixed length alphanumeric, large enough to hold the JSON describing the point (for
example, A200).
Are the geometry points for which you want to calculate the distance.
Note: You can generate a geometry point using the GIS_POINT function.
676
25. Simplified Geography Functions
Note: This function uses GIS services and requires an Esri ArcGIS adapter connection with
named credentials.
GIS_DRIVE_ROUTE(geo_start_point,geo_end_point)
678
25. Simplified Geography Functions
where:
geo_start_point,geo_point2
Fixed length alphanumeric, large enough to hold the JSON describing the point (for
example, A200).
Is the starting point for which you want to calculate the drive route.
Note: You can generate a geometry point using the GIS_POINT function.
geo_end_point,geo_point2
Fixed length alphanumeric, large enough to hold the JSON describing the point (for
example, A200).
Is the ending point for which you want to calculate the drive route.
Note: You can generate a geometry point using the GIS_POINT function.
The format of the field to which the drive route will be returned is TX.
680
25. Simplified Geography Functions
*GRAPH_JS_FINAL
"legend": {"visible": true},
"extensions" : { "com.esri.map" :
{ "scalebar" :
{
"scalebarUnit": "dual",
"attachTo" : "bottom-left"
},
"baseMapInfo": {
"drawBasemapControl" : false,
"showArcGISBasemaps" : false,
"customBaseMaps" : [
{"ibiBaseLayer" : "dark-gray"}
]
},
"overlayLayers":
[{
"ibiDataLayer": {"map-geometry" : {"map_by_field" : "Route"}}, "title" :
"Chart"}]
},
"introAnimation": "{\"enabled\":false}"
}
*END
ENDSTYLE
HEADING
"Chart Drive Route"
END
Note: This function uses GIS services and requires an Esri ArcGIS adapter connection with
named credentials.
GIS_GEOCODE_ADDR(address[, country])
where:
address
Fixed length alphanumeric
682
25. Simplified Geography Functions
Note: This function uses GIS services and requires an Esri ArcGIS adapter connection with
named credentials.
where:
street_addr
Fixed length alphanumeric
684
25. Simplified Geography Functions
Note: This function uses GIS services and requires an Esri ArcGIS adapter connection with
named credentials.
where:
street_addr
fixed length alphanumeric
where:
geotype
Alphanumeric
686
25. Simplified Geography Functions
wkid
Alphanumeric
Is a valid spatial reference ID. WKID is an abbreviation for Well-Known ID, which identifies
a projected or geographic coordinate system.
geometry
TX
A geometry in JSON.
688
25. Simplified Geography Functions
*GRAPH_JS_FINAL
*END
ENDSTYLE
HEADING
"Chart Geometry Object"
END
GIS_IN_POLYGON(point, polygon_definition)
where:
point
Alphanumeric or text
690
25. Simplified Geography Functions
GIS_LINE(geometry1, geometry2)
where:
geometry1
Alphanumeric or text
Is the first point or line for defining the beginning of the new line.
geometry2
Alphanumeric or text
Is the second point or line for the concatenation of the new line.
692
25. Simplified Geography Functions
*GRAPH_JS_FINAL
"legend": {"visible": true},
"extensions" : { "com.esri.map" :
{ "scalebar" :
{
"scalebarUnit": "dual",
"attachTo" : "bottom-left"
},
"baseMapInfo": {
"drawBasemapControl" : false,
"showArcGISBasemaps" : false,
"customBaseMaps" : [
{"ibiBaseLayer" : "dark-gray"}
]
},
"overlayLayers":
[{
"ibiDataLayer": {"map-geometry" : {"map_by_field" : "CONNECTION_LINE"}},
"title" : "Chart"}]
},
"introAnimation": "{\"enabled\":false}"
}
*END
ENDSTYLE
HEADING
"Chart Geometry Lines"
END
694
25. Simplified Geography Functions
The field to which the point is returned should have fixed length alphanumeric format, large
enough to hold the JSON describing the point (for example, A200).
where:
wkid
Fixed length alphanumeric
Is a spatial reference code (WKID). WKID is an abbreviation for Well-Known ID, which
identifies a projected or geographic coordinate system.
longitude
D20.8
latitude
D20.8
696
25. Simplified Geography Functions
*GRAPH_JS_FINAL
"bubbleMarker": {"maxSize": "10%"},
"legend": {"visible": true},
"extensions" : { "com.esri.map" :
{ "scalebar" :
{
"scalebarUnit": "dual",
"attachTo" : "bottom-left"
},
"baseMapInfo": {
"drawBasemapControl" : false,
"showArcGISBasemaps" : false,
"customBaseMaps" : [
{"ibiBaseLayer" : "gray"}
]
},
"overlayLayers":
[{
"ibiDataLayer": {"map-geometry" : {"map_by_field" : "GPOINT"}},
"title" : "Report"}]
},
"introAnimation": "{\"enabled\":false}"
}
*END
ENDSTYLE
HEADING
"Chart Geometry Points"
END
Note: This function uses GIS services and requires an Esri ArcGIS adapter connection with
named credentials.
where:
longitude
Numeric
698
25. Simplified Geography Functions
component
Keyword
The value is returned as text and can be assigned to a field with text or alphanumeric (fixed or
variable length) format.
Note: This function uses GIS services and requires an Esri ArcGIS adapter connection with
named credentials.
where:
geo_point
Alphanumeric
Is a valid travel mode as defined in gis_serv_area.mas in the Catalog directory under the
server installation directory. The accepted travel modes are;
700
25. Simplified Geography Functions
'TravelTime'.
'TruckTravelTime'.
'WalkTime'.
'Kilometers'.
702
25. Simplified Geography Functions
*GRAPH_JS_FINAL
"legend": {"visible": true},
"extensions" : { "com.esri.map" :
{ "scalebar" :
{
"scalebarUnit": "dual",
"attachTo" : "bottom-left"
},
"baseMapInfo": {
"drawBasemapControl" : false,
"showArcGISBasemaps" : false,
"customBaseMaps" : [
{"ibiBaseLayer" : "dark-gray"}
]
},
"overlayLayers":
[{
"ibiDataLayer": {"map-geometry" : {"map_by_field" :
"STATION_SERVICE_AREA"}}, "title" : "Chart"}]
},
"introAnimation": "{\"enabled\":false}"
}
*END
ENDSTYLE
HEADING
"Chart Geometry Service Area"
END
Note: This function uses GIS services and requires an Esri ArcGIS adapter connection with
named credentials.
where:
longitude
Alphanumeric
704
25. Simplified Geography Functions
distance
Integer
Is a valid travel mode as defined in gis_serv_area.mas in the Catalog directory under the
server installation directory. The accepted travel modes are;
'TravelTime'.
'TruckTravelTime'.
'WalkTime'.
'Kilometers'.
wkid
Alphanmeric
Is the spatial reference ID for the coordinate. WKID is an abbreviation for Well-Known ID,
which identifies a projected or geographic coordinate system. The default value is '4326',
which represents decimal degrees.
706
25. Simplified Geography Functions
*GRAPH_JS_FINAL
"legend": {"visible": true},
"extensions" : { "com.esri.map" :
{ "scalebar" :
{
"scalebarUnit": "dual",
"attachTo" : "bottom-left"
},
"baseMapInfo": {
"drawBasemapControl" : false,
"showArcGISBasemaps" : false,
"customBaseMaps" : [
{"ibiBaseLayer" : "dark-gray"}
]
},
"overlayLayers":
[{
"ibiDataLayer": {"map-geometry" : {"map_by_field" :
"STATION_SERVICE_AREA"}}, "title" : "Chart"}]
},
"introAnimation": "{\"enabled\":false}"
}
*END
ENDSTYLE
HEADING
"Chart Geometry Service Area"
END
708
25. Simplified Geography Functions
710
Chapter 26 SQL Character Functions
SQL character functions manipulate alphanumeric fields and character strings.
They can be used in SQL Translator requests and, where supported by the DBMS, in
Direct SQL Passthru requests.
In this chapter:
where:
substr
Alphanumeric
712
Chapter 27 SQL Miscellaneous Functions
The SQL functions described in this chapter perform a variety of conversions, tests, and
manipulations.
They can be used in SQL Translator requests and, where supported by the DBMS, in
Direct SQL Passthru requests.
In this chapter:
CHR(number)
where:
number
Numeric
714
Appendix A Creating a Subroutine
You can create custom subroutines to use in addition to the functions provided by
Information Builders. The process of creating a subroutine consists of the following
steps:
Writing a subroutine using any language that supports subroutine calls. Some of the
most common languages are FORTRAN, COBOL, PL/I, Assembler, and C. For details,
see Writing a Subroutine on page 715.
Compiling the subroutine. For details, see Compiling and Storing a Subroutine on page
726.
Storing the subroutine in a separate file; do not include it in the main program. For
details, Compiling and Storing a Subroutine on page 726.
Testing the subroutine. For details, see Testing the Subroutine on page 727.
Writing a Subroutine
Writing a Subroutine
You can write a subroutine in any language that supports subroutines. If you intend to make
your subroutine available to other users, be sure to document what your subroutine does, what
the arguments are, what formats they have, and in what order they must appear in the
subroutine call.
When you write a subroutine you need to consider the requirements and limits that affect it.
These are:
If you write a program named INTCOMP that calculates the amount of money in an account
earning simple interest, the program reads a record, tests if the data is acceptable, and then
calls a subroutine called SIMPLE that computes the amount of money. The program and the
subroutine are stored together in the same file.
The program and the subroutine shown here are written in pseudocode (a method of
representing computer code in a general way):
Begin program INTCOMP.
Execute this loop until end-of-file.
Read next record, fields: PRINCPAL, DATE_PUT, YRRATE.
If PRINCPAL is negative or greater than 100,000,
reject record.
If DATE_PUT is before January 1, 1975, reject record.
If YRRATE is negative or greater than 20%, reject record.
Call subroutine SIMPLE (PRINCPAL, DATE_PUT, YRRATE, TOTAL).
Print PRINCPAL, YEARRATE, TOTAL.
End of loop.
End of program.
If you move the SIMPLE subroutine into a file separate from the main program and compile it,
you can call the subroutine. The following report request shows how much money employees
would accrue if they invested salaries in accounts paying 12%:
TABLE FILE EMPLOYEE
PRINT LAST_NAME DAT_INC SALARY AND COMPUTE
INVESTED/D10.2 = SIMPLE(SALARY, DAT_INC, 0.12, INVESTED);
BY EMP_ID
END
Note: The subroutine is designed to return only the amount of the investment, not the current
date because a subroutine can return only a single value each time it is called.
716
A. Creating a Subroutine
Naming a Subroutine
A subroutine name can be up to eight characters long unless the language you are using to
write the subroutine requires a shorter name. A name must start with a letter and can consist
of a combination of letters and/or numbers. Special symbols are not permitted.
Creating Arguments
When you create arguments for a subroutine, you must consider the following issues:
Maximum number of arguments. A subroutine may contain up to 200 arguments. You can
bypass this restriction by creating a subroutine that accepts multiple calls, as described in
Including More Than 200 Arguments in a Subroutine Call on page 723.
Argument types. You can use the same types of arguments in a subroutine as in a
function. For details on these argument types, see Argument Types on page 61.
Input arguments. Input arguments are passed to a subroutine using standard conventions.
Register one points to the list of arguments.
You should not assume that input parameters are stored in contiguous memory.
Output arguments. A subroutine returns only one output argument. This argument must be
the last in the subroutine. You can choose any format for the output argument except in
Dialogue Manager which requires the argument to have the format of the output field.
Dialogue Manager requirements. If you are writing a subroutine specifically for Dialogue
Manager, the subroutine may need to perform a conversion. For details on using a
subroutine with Dialogue Manager, see Calling a Function From a Dialogue Manager
Command on page 68.
The lengths of the calling arguments as defined in WebFOCUS must match the lengths of the
corresponding arguments defined in the subroutine.
Any deviation from these rules may result in problems in using the subroutine. Information
Builders recommends that you modify the subroutine to conform to the stated rules and then
link it above the line. In order to load subroutines above the line, the following are the required
link-edit options for compiling and storing the subroutine:
Language Considerations
When writing a subroutine, you must consider the following language issues:
Language and memory. If you write a subroutine in a language that brings libraries into
memory (for example, FORTRAN and COBOL), the libraries reduce the amount of memory
available to the subroutine.
The subroutine must use the GOBACK command to return to the calling program. STOPRUN
is not supported.
Numeric arguments received from a request must be declared as COMP-2 (double precision
floating point).
The format described in the DEFINE or COMPUTE command determines the format of the
output argument:
An Xn
I S9(9) COMP
P S9(n)[V9(m)]
where:
718
A. Creating a Subroutine
D COMP-2
F COMP-1
where:
Is the field length as defined by the request. Do not use the VARYING attribute.
or
BINARY FLOAT (53)
The format described in the DEFINE or COMPUTE command determines the format of the
output argument:
An CHARACTER (n)
Variables that are not arguments with the STATIC attribute must be declared. This avoids
dynamically allocating these variables every time the subroutine is executed.
The format defined in the DEFINE or COMPUTE command determines the format of the
output argument:
An char *xxx
n
720
A. Creating a Subroutine
I long
*xxx
F float
*xxx
D double
*xxx
P No equivalent in C.
Programming a Subroutine
Consider the following when planning your programming requirements:
Write the subroutine to include an argument that specifies the output field.
If the subroutine initializes a variable, it must initialize it each time it is executed (serial
reusability).
Since a single request may execute a subroutine numerous times, code the subroutine as
efficiently as possible.
If you create your subroutine in a text file or text library, the subroutine must be 31-bit
addressable.
The last argument, which is normally used for returning the result of the subroutine, can
also be used to provide input from the subroutine.
You can add flexibility to your subroutine by using a programming technique. A programming
technique can be one of the following:
Executing a subroutine at an entry point. An entry point enables you to use one algorithm to
produce different results. For details, see Executing a Subroutine at an Entry Point on page
722.
Creating a subroutine with multiple subroutine calls. Multiple calls enable the subroutine to
process more than 200 arguments. For details, see Including More Than 200 Arguments in
a Subroutine Call on page 723.
Each entry point has a name. To execute a subroutine at an entry point, specify the entry point
name in the subroutine call instead of the subroutine name. How you designate an entry point
depends on the language you are using.
where:
subroutine
Is the name of the subroutine.
entrypoint
Is the name of the entry point to execute the subroutine at.
input1, input2,...
Are the subroutine's arguments.
outfield
Is the field that contains the result, or the format of the output value enclosed in single
quotation marks.
In Dialogue Manager, you must specify the format. In Maintain Data, you must specify the
name of the field.
722
A. Creating a Subroutine
The following is a shorter way to write the subroutine. Notice that the kelv output argument
listed for the entry point is different from the centi output argument listed at the beginning of
the subroutine:
Subroutine FTOC (FAREN, CENTI).
Entry FTOK (FAREN, KELV).
Let CENTI = (5/9) * (FAREN - 32).
KELV = CENTI - 273.
Return.
End of Subroutine.
To obtain the Centigrade temperature, specify the subroutine name FTOC in the subroutine
call. The subroutine processes as:
CENTIGRADE/D6.2 = FTOC (TEMPERATURE, CENTIGRADE);
To obtain the Kelvin temperature, specify the entry name FTOK in the subroutine call. The
subroutine processes as:
KELVIN/D6.2 = FTOK (TEMPERATURE, KELVIN);
Use the following technique for writing a subroutine with multiple calls:
1. Divide the subroutine into segments. Each segment receives the arguments passed by one
corresponding subroutine call.
The argument list in the beginning of your subroutine must represent the same number of
arguments in the subroutine call, including a call number argument and an output
argument.
Each call contains the same number of arguments. This is because the argument list in
each call must correspond to the argument list in the beginning of the subroutine. You may
process some of the arguments as dummy arguments if you have an unequal number of
arguments. For example, if you divide 32 arguments among six segments, each segment
processes six arguments; the sixth segment processes two arguments and four dummy
arguments.
724
A. Creating a Subroutine
where:
field
Is the name of the field that contains the result of the segment or the format of the field
enclosed in single quotation marks. This field must have the same format as outfield.
Do not specify field for the last call statement; use outfield.
subroutine
Is the name of the subroutine up to eight characters long.
n
Is a number that identifies each subroutine call. It must be the first argument in each
subroutine call. The subroutine uses this call number to branch to segments of code.
group1, group2,...
Are lists of input arguments passed by each subroutine call. Each group contains the
same number of arguments, and no more than 26 arguments each.
In Dialogue Manager, you must specify the format. In Maintain Data, you must specify the
name of the field.
Label ONE.
Let SUM = A + B + C + D + E + F.
Return.
Label TWO
Let SUM = SUM + A + B + C + D + E + F
Return
Label THREE
Let SUM = SUM + A + B + C + D + E + F
Return
Label FOUR
Let SUM = SUM + A + B + C + D + E + F
Return
Label FIVE
Let SUM = SUM + A + B + C + D + E + F
Return
Label SIX
LET TOTAL = SUM + A + B
Return
End of subroutine
To use the ADD32 subroutine, list all six call statements, each call specifying six numbers.
The last four numbers, represented by zeros, are dummy arguments. The DEFINE command
stores the total of the 32 numbers in the SUM32 field.
DEFINE FILE EMPLOYEE
DUMMY/D10 = ADD32 (1, 5, 7, 13, 9, 4, 2, DUMMY);
DUMMY/D10 = ADD32 (2, 5, 16, 2, 9, 28, 3, DUMMY);
DUMMY/D10 = ADD32 (3, 17, 12, 8, 4, 29, 6, DUMMY);
DUMMY/D10 = ADD32 (4, 28, 3, 22, 7, 18, 1, DUMMY);
DUMMY/D10 = ADD32 (5, 8, 19, 7, 25, 15, 4, DUMMY);
SUM32/D10 = ADD32 (6, 3, 27, 0, 0, 0, 0, SUM32);
END
726
A. Creating a Subroutine
If the subroutine is written in PL/I, include the following when link-editing the subroutine
ENTRY subroutine
where:
subroutine
Is the name of the subroutine.
If an error occurs during testing, check to see if the error is in the request or in the subroutine.
Is the name of the month. Since the character string 'September' contains nine letters,
MONTH is a three element array. The subroutine passes the three elements back to your
application which concatenates them into one field.
A
Is a two dimensional, 13 by 3 array, containing the names of the months. The last three
elements contain the error message.
IMTH
728
A. Creating a Subroutine
Is a field containing the names of the months and the error message.
MLINE
Is a 13-element array that redefines the MONTH-TABLE field. Each element (called A)
contains the name of a month; the last element contains the error message.
A
MONTH
730
A. Creating a Subroutine
FULLMTH
Is a 13-element array containing the names of the months. The last element contains the
error message.
732
A. Creating a Subroutine
734
A. Creating a Subroutine
REXX subroutines are supported in the z/OS environment. A REXX subroutine contains REXX
source code. Compiled REXX code is not supported.
A REXX subroutine contains REXX source code. Compiled REXX code is not supported.
REXX subroutines are not necessarily the same in all operating environments. Therefore, some
of the examples may use REXX functions that are not available in your environment.
Because of CPU requirements, the use of REXX subroutines in large production jobs should be
monitored carefully.
or
{DEFINE|COMPUTE} fieldname/{An|In} = subname(inlen1, inparm1, ...,
outlen, outparm);
or
-SET &var = subname(inlen1, inparm1, ..., outlen, outparm);
where:
fieldname
Is the field that contains the result.
An, In
Note: If the value returned is an integer, outlen must be 4 because WebFOCUS reserves
four bytes for integer fields.
736
A. Creating a Subroutine
&var
Is the name of the Dialogue Manager variable that contains the result.
1. The EDIT function converts HIRE_DATE to alphanumeric format and stores the result in a
field with the format A6.
2. The result is stored in the DAY_OF_THE_WEEK field, and can be up to nine bytes long.
1. EDIT converts HIRE_DATE to alphanumeric format and stores the result in AHDT.
2. EDIT converts CURR_SAL to alphanumeric format and stores the result in ACSAL.
3. CURR_SAL is converted to a floating-point double-precision field that includes commas, and
the result is stored in DCSAL.
4. The second input field is six bytes long. Data is passed as a character variable &YMD in
YYMMDD format.
The third input field is a character value of 6.5, which is three bytes long to account for the
decimal point in the character string.
The fourth input field is 12 bytes long. This passes the character field ACSAL.
738
A. Creating a Subroutine
The REXX subroutine appears below. The REXX Format command is used to format the return
value.
/* Simple INTEREST program. dates are yymmdd format */
Arg start_date,now_date,percent,open_balance, .
begin = Date('B',Translate('34/56/12',start_date,'123456'),'U')
stop = Date('B',Translate('34/56/12',now_date,'123456'),'U')
valnow = open_balance * (((stop - begin) * (percent / 100)) / 365)
Return Format(valnow,9,2)
1. COMPID is the concatenation of several character fields passed as the first parameter and
stored in a field with the format A256. Each of the other parameters is a single argument.
2. EDIT converts PAY_DATE to alphanumeric format.
3. EDIT converts MO_PAY to alphanumeric format.
4. OK4RAISE executes, and the result is stored in OK4RAISE.
The REXX subroutine appears below. Commas separate FUSREXX parameters. The ARG
command specifies multiple variable names before the first comma and, therefore, separates
the first FUSREXX parameter into separate REXX variables, using blanks as delimiters between
the variables.
/* OK4RAISE routine. Parse separate tokens in the 1st parm, */
/* then more parms */
Return retvalue
REXX subroutines should use the REXX RETURN subroutine to return data. REXX EXIT is
acceptable, but is generally used to end an EXEC, not a FUNCTION.
The output length in the subroutine call must be four. Character variables cannot be more than
256 bytes. This limit also applies to REXX subroutines. FUSREXX routines return variable
length data. For this reason, you must supply the length of the input arguments and the
maximum length of the output data.
A REXX subroutine does not require any input parameters, but requires one return parameter,
which must return at least one byte of data. It is possible for a REXX subroutine not to need
input, such as a function that returns USERID.
740
A. Creating a Subroutine
A REXX subroutine does not support WebFOCUS date input arguments. When working with
dates you can do one of the following:
Pass an alphanumeric field with date display options and have the subroutine return a date
value.
Date fields contain the integer number of days since the base date 12/31/1900. REXX
has a date function that can accept and return several types of date formats, including one
called Base format ('B') that contains the number of days since the REXX base date
01/01/0001. You must account for the difference, in number of days, between the
WebFOCUS base date and the REXX base date and convert the result to integer.
Pass a date value converted to alphanumeric format. You must account for the difference
in base dates for both the input and output arguments.
1. The EDIT field converts COPIES to alphanumeric format, and stores the result in ACOPIES.
2. The result is stored in an 8-byte alphanumeric field TXTCOPIES.
1. EDIT converts HIRE_DATE to alphanumeric format and stores the result in AHDT.
2. EDIT converts DAT_INC to alphanumeric format and stores the result in ADI.
3. NUMDAYS finds the number of days between AHDT and ADI and stores the result in integer
format.
742
A. Creating a Subroutine
The subroutine appears below. The return value is converted from REXX character to HEX and
formatted to be four bytes long.
/* NUMDAYS routine. */
/* Return number of days between 2 dates in yymmdd format */
/* The value returned will be in hex format */
Arg first,second .
base1 = Date('B',Translate('34/56/12',first,'123456'),'U')
base2 = Date('B',Translate('34/56/12',second,'123456'),'U')
The number 693959 represents the difference, in number of days, between the WebFOCUS
base date and the REXX base date:
/* REXX DATEREX1 routine. Add indate (format A8YYMD) to days */
Arg indate, days .
Return D2C(Date('B',indate,'S')+ days - 693959, 4)
The following request uses the DATEREX1 macro to calculate the date that is 365 days from
the hire date of each employee. The input arguments are the hire date and the number of days
to add. Because HIRE_DATE is in I6YMD format, it must be converted to A8YYMD before being
passed to the macro:
TABLE FILE EMPLOYEE
PRINT LAST_NAME FIRST_NAME HIRE_DATE
AND COMPUTE
ADATE/YYMD = HIRE_DATE; NOPRINT
AND COMPUTE
INDATE/A8YYMD= ADATE; NOPRINT
AND COMPUTE
NEXT_DATE/YYMD = DATEREX1(8, INDATE, 3, '365', 4, NEXT_DATE);
BY LAST_NAME NOPRINT
END
The number 693959 represents the difference, in number of days, between the WebFOCUS
base date and the REXX base date:
/* REXX DATEREX2 routine. Add indate (original format YYMD) to days */
Arg indate, days .
Return D2C(Date('B',indate+693959,'B') + days - 693959, 4)
The following request uses DATEREX2 to calculate the date that is 365 days from the hire date
of each employee. The input arguments are the hire date and the number of days to add.
Because HIRE_DATE is in I6YMD format, it must be converted to an alphanumeric number of
days before being passed to the macro:
TABLE FILE EMPLOYEE
PRINT LAST_NAME FIRST_NAME HIRE_DATE
AND COMPUTE
ADATE/YYMD = HIRE_DATE; NOPRINT
AND COMPUTE
INDATE/A8 = EDIT(ADATE); NOPRINT
AND COMPUTE
NEXT_DATE/YYMD = DATEREX2(8,INDATE,3,'365',4,NEXT_DATE);
BY LAST_NAME NOPRINT
END
744
A. Creating a Subroutine
746
Appendix B ASCII and EBCDIC Codes
The table in this appendix lists ASCII and EBCDIC codes for printable and non-printable
characters.
In this appendix:
15 0F SI shift in SI shift in
748
B. ASCII and EBCDIC Codes
41 29 ) right parenthesis
48 30 0 0
49 31 1 1
51 33 3 3 IR index return
52 34 4 4 PP presentation position
53 35 5 5 TRN
56 38 8 8 SBS subscript
57 39 9 9 IT indent tab
62 3E > greater-than
64 40 @ at symbol SP space
65 41 A A
66 42 B B
67 43 C C
68 44 D D
69 45 E E
70 46 F F
750
B. ASCII and EBCDIC Codes
71 47 G G
72 48 H H
73 49 I I
74 4A J J ¢ cent
75 4B K K . period
76 4C L L < less-than
77 4D M M ( left parenthesis
78 4E N N + addition sign
79 4F O O | logical or
80 50 P P & ampersand
81 51 Q Q
82 52 R R
83 53 S S
84 54 T T
85 55 U U
86 56 V V
87 57 W W
88 58 X X
89 59 Y Y
90 5A Z Z ! exclamation mark
97 61 a a / right slash
98 62 b b
99 63 c c
100 64 d d
101 65 e e
102 66 f f
103 67 g g
104 68 h h
105 69 i i
107 6B k k , comma
109 6D m m _ underscore
112 70 p p
113 71 q q
114 72 r r
752
B. ASCII and EBCDIC Codes
115 73 s s
116 74 t t
117 75 u u
118 76 v v
119 77 w w
120 78 x x
121 79 y y ˋ grave
122 7A z z : colon
128 80
129 81 a a
130 82 b b
131 83 c c
132 84 d d
133 85 e e
134 86 f f
135 87 g g
136 88 h h
137 89 i i
138 8A
139 8B
140 8C
141 8D
142 8E
143 8F
144 90
145 91 j j
146 92 k k
147 93 l l
148 94 m m
149 95 n n
150 96 o o
151 97 p p
152 98 q q
153 99 r r
154 9A
155 9B
156 9C
157 9D
158 9E
754
B. ASCII and EBCDIC Codes
159 9F
160 A0
162 A2 s s
163 30 t t
164 A4 u u
165 A5 v v
166 A6 w w
167 A7 x x
168 A8 y y
169 A9 z z
170 AA
171 AB
172 AC
173 AD
174 AE
175 AF
176 B0
177 B1
178 B2
179 B3
180 B4
181 B5
182 B6
183 B7
184 B8
185 B9
186 BA
187 BB
188 BC
189 BD
190 BE
191 BF
193 C1 A A
194 C2 B B
195 C3 C C
196 C4 D D
197 C5 E E
198 C6 F F
199 C7 G G
200 C8 H H
201 C9 I I
202 CA
756
B. ASCII and EBCDIC Codes
203 CB
204 CC
205 CD
206 CE
207 CF
209 D1 J J
210 D2 K K
211 D3 L L
212 D4 M M
213 D5 N N
214 D6 O O
215 D7 P P
216 D8 Q Q
217 D9 R R
218 DA
219 DB
220 DC
221 DD
222 DE
223 DF
225 E1
226 E2 S S
227 E3 T T
228 E4 U U
229 E5 V V
230 E6 W W
231 E7 X X
232 E8 Y Y
233 E9 Z Z
234 EA
235 EB
236 EC
237 ED
238 EE
239 EF
240 F0 0 0
241 F1 1 1
242 F2 2 2
243 F3 3 3
244 F4 4 4
245 F5 5 5
246 F6 6 6
758
B. ASCII and EBCDIC Codes
247 F7 7 7
248 F8 8 8
249 F9 9 9
251 FB
252 FC
253 FD
254 FE
760
Legal and Third-Party Notices
SOME TIBCO SOFTWARE EMBEDS OR BUNDLES OTHER TIBCO SOFTWARE. USE OF SUCH
EMBEDDED OR BUNDLED TIBCO SOFTWARE IS SOLELY TO ENABLE THE FUNCTIONALITY (OR
PROVIDE LIMITED ADD-ON FUNCTIONALITY) OF THE LICENSED TIBCO SOFTWARE. THE
EMBEDDED OR BUNDLED SOFTWARE IS NOT LICENSED TO BE USED OR ACCESSED BY ANY
OTHER TIBCO SOFTWARE OR FOR ANY OTHER PURPOSE.
USE OF TIBCO SOFTWARE AND THIS DOCUMENT IS SUBJECT TO THE TERMS AND CONDITIONS
OF A LICENSE AGREEMENT FOUND IN EITHER A SEPARATELY EXECUTED SOFTWARE LICENSE
AGREEMENT, OR, IF THERE IS NO SUCH SEPARATE AGREEMENT, THE CLICKWRAP END USER
LICENSE AGREEMENT WHICH IS DISPLAYED DURING DOWNLOAD OR INSTALLATION OF THE
SOFTWARE (AND WHICH IS DUPLICATED IN THE LICENSE FILE) OR IF THERE IS NO SUCH
SOFTWARE LICENSE AGREEMENT OR CLICKWRAP END USER LICENSE AGREEMENT, THE
LICENSE(S) LOCATED IN THE "LICENSE" FILE(S) OF THE SOFTWARE. USE OF THIS DOCUMENT
IS SUBJECT TO THOSE TERMS AND CONDITIONS, AND YOUR USE HEREOF SHALL CONSTITUTE
ACCEPTANCE OF AND AN AGREEMENT TO BE BOUND BY THE SAME.
This document is subject to U.S. and international copyright laws and treaties. No part of this
document may be reproduced in any form without the written authorization of TIBCO Software
Inc.
TIBCO, the TIBCO logo, the TIBCO O logo, FOCUS, iWay, Omni-Gen, Omni-HealthData, and
WebFOCUS are either registered trademarks or trademarks of TIBCO Software Inc. in the
United States and/or other countries.
Java and all Java based trademarks and logos are trademarks or registered trademarks of
Oracle Corporation and/or its affiliates.
All other product and company names and marks mentioned in this document are the property
of their respective owners and are mentioned for identification purposes only.
This software may be available on multiple operating systems. However, not all operating
system platforms for a specific software version are released at the same time. See the
readme file for the availability of this software version on a specific operating system platform.
THIS DOCUMENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
761
THE CONTENTS OF THIS DOCUMENT MAY BE MODIFIED AND/OR QUALIFIED, DIRECTLY OR
INDIRECTLY, BY OTHER DOCUMENTATION WHICH ACCOMPANIES THIS SOFTWARE, INCLUDING
BUT NOT LIMITED TO ANY RELEASE NOTES AND "READ ME" FILES.
This and other products of TIBCO Software Inc. may be covered by registered patents. Please
refer to TIBCO's Virtual Patent Marking document (https://www.tibco.com/patents) for details.
762
Index
argument formats 62
-IF command 70, 71
argument length 63
-RUN command 72, 73
argument types 61
-SET command 69, 70
ASCII character chart 50, 747
BYTVAL function 202–204 character functions 23, 25, 28, 29, 196
EDIT 211, 212
C GETTOK 213, 215
764
Index
character functions 23, 25, 28, 29, 196 CHGDAT function 421, 423
XMLDECOD 245 CHKFMT function 204, 206, 207
XMLENCOD 247 CHKNUM function 206
character strings 196, 218 CHKPCK function 551
adding 284 CHR function 713
bits 199, 201 CLASSIFY_BLR function 609
centering 210, 211 CLASSIFY_KNN function 613
comparing 231, 295, 296 CLASSIFY_RF function 615
converting case 220, 244, 281, 283, 301 CLASSIFY_XGB function 619
determining length 300 CLSDDREC 661
Dialogue Manager 197 COALESCE function 306
dividing 223 commands 659
extracting 284, 297 passing 659
extracting characters 211 COMPACTFORMAT function 490
extracting substrings 213, 239, 241, 256, compiling subroutines 726
299 OS/390 727
finding substrings 227, 290 UNIX 727
format 204 Windows 727
justifying 218, 230, 291 components 440
measuring length 196, 282 COMPUTE command 67
overlaying 221, 289 assigning date-time values 445
reducing spaces 234 CONCAT function 137
removing occurrences 241, 300 controlling function parameter verification 65
right-justifying 230, 291 conversion functions, simplified 39, 489
spelling out numbers 233 CHAR 489
substrings 293, 297 CTRLCHAR 492
translating characters 202, 207, 208, 280 DT_FORMAT 494
CHECKMD5 function 304 HEXTYPE 497
CHECKPRIVS function 646 TO_INTEGER 501
CHECKSUM function 305 TO_NUMBER 502
766
Index
768
Index
770
Index
IF criteria 73
H
assigning date-time values 446
HADD function 446–448 functions and 74, 75
hash value 304, 305 IMOD function 553, 554
HCNVRT function 449, 450 IMPUTE function 326
HDATE function 450, 451 INCREASE function 114
HDIFF function 452, 453 INITCAP function 145
HDTTM function 453–455 Initial_HHMMSS function 480
header variables, retrieving 653 Initial_TODAY 480
HEXBYT function 512–514 Initial_TODAY function 480
HEXTR function 455 INT function 562
HEXTYPE function 497 INT2CHAR function 280
HGETC function 457–459 internal functions 19
HGETZ function 458 internal modified rate of return 564
HHMMSS function 460, 479, 480 internal rate of return 577
HHMS function 461 international date formats 390
HINPUT function 462, 463 invoking functions 59, 60
HMASK function 465 ISO standard date-time formats 443
HMIDNT function 464, 465 ITONUM function 515, 516
HNAME function 468, 469 ITOPACK function 516, 517
holidays 367, 368, 370 ITOZ function 518, 519
holiday files 368, 370 IWC.FindAppCGIValue function 529, 530, 585,
HPART function 469–471 586
HSETPT function 471–473 IWC.GetAppCGIValue function 530, 531, 587
HTIME function 473, 474 IWCLink function 582
HTMTOTS function 474 IWCSwitchToSecure function 583
HTTP header variables, retrieving 653 IWCSwitchToUnsecure function 583
772
Index
774
Index
P REGRESS_POLY 624
REGRESS_RF 628
packed numbers, writing to an output file 525
REGRESS_XGB 631
PARAG function 223, 224
PARTITION_AGGR 101 Q
PARTITION_REF 110
QUARTER function 485
PATTERN function 225
PATTERNS function 156
R
PCKOUT function 519, 520
PCT_INCREASE function 118 rate of return 564, 577
POSIT function 227, 228, 290, 291 RDUNIF function 575, 576
776
Index
778
Index
780