CoSORT:
Using System Variables in Reporting Scripts
CoSORT’s sort control language (SortCL)
reporting program affords many opportunities to replace literal
values with multiple variables, either internal
to CoSORT or in the shell. CoSORT also
supports the use of conversion specifiers,
to allow you to convert (and display) known values into their equivalents
in another data type, and to assist in condition evaluation.
Internal Variables
SortCL maintains internal values which you can use
for record-formatting DATA statements, and within headers and footers.
The internal variables supported by CoSORT include a wide array
of timestamp and date formats, User Name, system date/time, and
page number. When using internal variables in place of literal strings,
the syntax required is %char, where char is a letter that represents
any of CoSORT’s own format-control characters.
For example, if you want a footer that cites the
user name and page number, you might specify:
/FOOTREC=”Generated by %s [%d]\n”,USER,
PAGE_NUMBER
When executed, the footer record from page 27 of
this report might read:
Generated by bob_smith [27]
In this example, %s is used to represent a string
(user name), and %d is used for a decimal integer (page number).
As you can see, sortcl requires you to specify the name of the internal
variables (e.g., USER, PAGE_NUMBER) to the right of the double quotes,
and in the same order in which their corresponding variables were
specified inside the quotes.

Environment Variables
SortCL accepts the use of environment variables
(preceded by $) at all levels of scripting. This allows you to maintain
only one script for a variety of jobs that use some of the same
parameters. Typically, environment variables are used in place of
literal /INFILE and /OUTFILE names, and
their values are often given earlier in a batch script context in
which one or more SortCL jobs is
executed. You can also set the value of an environment variable
on an ad-hoc basis from the command line. For example consider this
script:
/INFILE=$Thurs_unsorted
/SPEC=Thursday.ddf #
contains input field layouts
/SORT
/KEY=$Primary
/OUTFILE=$Thurs_sorted
where the names of the input and output files, and
the sort key are all environment variables. From the command line,
or within a batch script, you might set the value of these environment
variables as follows:
Thurs_unsorted=/weekly/input/Thurs_unload.dat;
export Thurs_unsorted
Thurs_sorted=/weekly/output/Thurs_reload.dat;
export Thurs_unsorted
Primary=Customer; export Primary
Depending on your shell or your operating system,
this method may vary.

Conversion Specifiers
SortCL's conversion specifiers, such as %E, allow
you to convert (and display) known values into their equivalents
in another data type. Conversion specifiers are supported for ASCII,
EBCDIC,
hexadecimal, and packed data values. You can also use conversion
specifiers for condition evaluation.
For an example of using a known value to display
an unknown value, you can return the EBCDIC
equivalent of the ASCII value 65 in an output file by specifying:
/DATA=%EBCDIC"65"
The following example shows how you can use a conversion
specifier to perform condition evaluation when an input field is
in EBCDIC format:
/Condition=(Senior,TEST=(Age >
%E"65"))
If you /INCLUDE this condition, only those records
where the EBCDIC equivalent of 66 and higher for the field Age are
included in the output.

|