SYSTEM definitions are used to describe words
like ZERO that have a special meaning in COBOL, and Functions like $Len and
$Today that are built into the Jazz language. Because there are special rules
for SYSTEM definitions, they are described
separately here.
Here is
part of the definition of “COBOL” that is inserted into the program. You can
see the full version by clicking the workbench’s [Show All] button.
*# Last Updated by robertb at 5/05/2013 5:03:56 p.m.
DEFINE COBOL SYSTEM DATA(
ZERO SMALLINT FIGURATIVE,
ZEROS SMALLINT FIGURATIVE,
[Snip]
$Today DATETIME FUNCTION(),
$Now DATETIME FUNCTION(),
$Len SMALLINT FUNCTION());
In summary,
the main differences with SYSTEM definitions
are: -
1.
There
is no record or file defined into the COBOL program. Thus you won’t find “01 COBOL.” anywhere
in the program’s data division, nor will you find definitions for ZERO or
$Today.
2. Within a SYSTEM definition item names can start with “$”. “$Today” would be invalid in most other types.
3. Items can be defined with properties like SMALLINT and DATETIME, as normal, but their definition can also include the property FIGURATIVE, INTRINSIC, or FUNCTION.
4. Items can be defined with properties NUMBER and UNSPECIFIED. These are used for FUNCTION definitions, where the actual format returned depends on the function’s parameters. It becomes the user’s responsibility to ensure that such function values are assigned to the correct type of target variables.
5. Items in SYSTEM definitions can be used in expressions, but may not be the target of an assignment. Thus you can write
R1.Myfield = Zero;
but you can’t write
Zero = R1.Myfield;
It’s as if every item in a SYSTEM definition has the property CONSTANT.
Special-Name-Definition ::= Name property {FIGURATIVE | Intrinsic-Definition | Function-Definition}
Name ::= follows the normal rules for field names, plus:
Figurative or Intrinsic: must be a name known to COBOL as a Figurative Constant or Intrinsic function
Function-Definition: must be the name of an implemented Jazz built-in function. Must start with $.
Property ::= a data type like SMALLINT, CHAR, etc.
Intrinsic-Definition::= INTRINSIC ([Parameter-list]). The parameter list is as described for Functions.
Function-Definition::- FUNCTION([parameter-list]) [EXPRESSION]. See below for more information.
This is used to define the names used by COBOL as Figurative Constants. Jazz supports all of COBOL’s figurative constants except ALL. Here is a list of the figurative constants: -
ZERO SMALLINT FIGURATIVE,
ZEROS SMALLINT FIGURATIVE,
ZEROES SMALLINT FIGURATIVE,
SPACE CHAR(0) FIGURATIVE,
SPACES CHAR(0) FIGURATIVE,
HIGH-VALUE CHAR(0) FIGURATIVE,
HIGH-VALUES CHAR(0) FIGURATIVE,
LOW-VALUE CHAR(0) FIGURATIVE,
LOW-VALUES CHAR(0) FIGURATIVE,
QUOTE CHAR(0) FIGURATIVE,
QUOTES CHAR(0) FIGURATIVE,
[ALL literal Not supported]
NULL CHAR(0) FIGURATIVE,
NULLS CHAR(0) FIGURATIVE,
If you use one of these names, then it will be left as you wrote it, it will not become a qualified name in your program. Thus if you have defined field MyField within definition R1, when you write
Myfield = Zero;
Myfield is changed to R1.MyField, but Zero just becomes ZERO, making the assignment
R1.MyField = ZERO;
ZERO and ZEROS are defined as SMALLINT, but in fact this is interpreted as “Any Number”. Similarly, the functions like SPACES that are defined as “CHAR(0)” are interpreted as “Character, of undefined length”.
Some COBOL Intrinsic Functions are defined using property INTRINSIC. However many of COBOL’s Intrinsic functions are unnecessary as built-in functions are available that perform the same function. For example, $Trim is used instead of directly referencing the COBOL intrinsic Trim. Built-in functions are more general (for example, $Trim will handle VARCHAR fields, but COBOL does not support VARCHAR directly), and Jazz error-checking is better with $Trim.
INTRINSIC functions may be defined with a list of argument types: these are interpreted as described below for Functions.
Numeric intrinsic functions, for example MOD, must appear in a “numeric context”. Thus in COBOL you can write
COMPUTE IX2 OF JZ = FUNCTION MOD ( IX2
OF JZ , 2 )
but
MOVE FUNCTION MOD ( IX2 OF JZ ,
2 ) TO IX2 OF JZ
won’t compile, producing this message: -
IGYPA3245-S Numeric function "INTEGER FUNCTION
MOD" was not allowed in this context.
Jazz will produce a MOVE statement from a simple assignment statement, but will produce a COMPUTE statement if the assignment source is an arithmetic expression. Thus
JZ.IX2 = Mod(JZ.IX1, 2);
produces
a MOVE statement and message IGYPA3245-S, while
JZ.IX2 = Mod(JZ.IX2, 2) + 0;
produces a COMPUTE statement and functions correctly.
Function-definition ::= FUNCTION([Parameter-list]) EXPRESSION
Parameter-list ::= Parameter [,parameter]…
Parameter ::= [OPTIONAL] REFERENCE | STRING | NUMBER | DECIMAL | KEYWORD | CHAR | VARCHAR | SMALLINT
Items like
$Len SMALLINT FUNCTION()
define a Jazz built-in function.
Functions cannot be part of a more complex expression. This means that you cannot combine them with operators and other operands in statements like
R1.B = $Len(Input.Field1) + $Len(Input.Field2);
or
R1.C = $Concat($Trim(Input.CField1), $Trim(Input.CField2));
In some cases this restriction will be permanent due to COBOL limitations, but where possible this restriction will be temporary.
1. All Jazz built-in functions are named starting with “$”. Without this rule there is a risk that a future version of Jazz might introduce a new built-in function with a name that you’d used for one of your own program variables or functions, and this might invalidate your program. However, as long as you avoid “$” there should be no problems.
Also, this rule makes it very
easy to recognize built-in functions within your Jazz programs.
2. Next comes a property like SMALLINT, DATETIME, etc. With built-in functions this is the default data type: sometimes the arguments to the function will change the type. For example, although $Today is defined
$Today DATETIME FUNCTION(),
if you write $Today(Year) then a number is returned. For example: -
DEFINE R1 DATA(
A DATETIME,
B SMALLINT);
R1.A = $Today;
R1.B = $Today;
#131 S Assignment Source and Target(s) are not compatible
R1.A = $Today(Year);
#131 S Assignment Source and Target(s) are not compatible
R1.B = $Today(Year);
3. After the word FUNCTION there will be a pair of brackets, as in
FUNCTION()
Between the brackets there may be one or more argument types, like this: -
$Len SMALLINT FUNCTION(REFERENCE)
$CONCAT VARCHAR FUNCTION(STRING, STRING)
If the function is defined with (), then the reference is not checked: you could write a reference to the function with no arguments: -
R1.A = $Today;
with a correct argument: -
R1.A = $Today(Datetime)
or with any number of arguments: -
R1.A = $Today(Argument1, Argument2, Argument3)
Excess arguments will be ignored without comment, incorrect arguments may be ignored, may cause Jazz to fail, or may cause your generated COBOL program to fail.
If an argument list is given, then the function reference must be written with the correct number of arguments, and each argument must be the right type. Thus references to $Len must have exactly one argument: an error message will be produced by Jazz if you write
$Len;
or
$Len(argument1, argument2)
4.
Specifying Argument types. Each argument type
is: -
a. A data type, like SMALLINT, VARCHAR, CHAR, etc. Do not specify the
number of digits or characters.
b. REFERENCE, STRING, NUMBER, DECIMAL, KEYWORD.
REFERENCE means a reference to a record or field that you’ve defined in your program. Thus you can write
R1.B = $Len(R1.A);
R1.B = $Len(R1.*);
but you can’t refer to a literal string or number, nor a word that is not defined as a record name or field name within your program. These are invalid if $Len is defined with (Reference): -
R1.B = $Len(‘abcde’);
R1.B = $Len(Unknown-word);
STRING. This means a string variable (types CHAR, VARCHAR, and PIC), or a string constant, e.g. ‘abcde’.
NUMBER.
This means a numeric variable – any of the types SMALLINT, INTEGER, BIGINT, DECIMAL, MONEY, SHORT, and FLOAT –
or a number like 1234. It does not mean
a Decimal number, and if a variable with type DECIMAL, MONEY, SHORT, or FLOAT is used then any
fractional part will be ignored.
DECIMAL.
This means a variable with type DECIMAL or MONEY, or a decimal number like 123.45.
KEYWORD(list) is used when the argument must be a word from a list for that function. Thus arguments to $Today and $Now are DATETIME, DATE, TIME, YEAR, MONTH, DAY, HOUR, MINUTE, SECONDS, GMTDIFFERENCE. Function $TODAY is defined:-
$TODAY DATETIME FUNCTION(KEYWORD(DATETIME, DATE, TIME, YEAR, MONTH, DAY,
HOUR, MINUTE, SECONDS, GMTDIFFERENCE))
so reference to $Today must give one
argument. Errors are noted if no
argument is given, or more than one argument.
The single argument must be one of these words.
5.
Optional arguments. Some functions may have
varying numbers of arguments. We can
indicate this by writing OPTIONAL in the argument list. After one
optional argument all following arguments must also be optional.