CL Elements

179 Views


Control language (CL) contains elements such as character sets and values, expressions, built-in functions, and naming within commands.

Character sets: Control language (CL) uses the extended binary-coded decimal interchange code (EBCDIC) character set.

Symbolic operators:

A variety of characters can be used as symbolic operators in CL commands. The following characters are used as symbolic operators in CL commands.

Expressions in CL commands

The following types of expressions are supported in CL programs: 

Arithmetic (&VAR + 15) 

Character string (SIX || TEEN)

Relational (&VAR > 15)

Logical (&VAR & &TEST)

There are three operators that can be used in character string expressions.

They are:

*CAT (concatenation, symbol ||) operator

The *CAT operator concatenates two character strings. 

For example: ABC *CAT DEF becomes ABCDEF
Blanks are included in the concatenation. 
For example: ’ABC ’ *CAT ’DEF ’ becomes ’ABC DEF ’

*BCAT (concatenation with blank insertion, symbol |>) operator

The *BCAT operator truncates all trailing blanks in the first character string; one blank is inserted, then the two character strings are concatenated. Leading blanks on the second operand are not truncated.

For example:
ABC *BCAT DEF becomes ABC DEF
’ABC ’ *BCAT DEF becomes ’ABC DEF’

*TCAT (concatenation with trailing blank truncation, symbol |<) operator

The *TCAT operator truncates all trailing blanks in the first character string, then the two character strings are concatenated. All leading blanks on the second operand are not truncated.

For example:

ABC *TCAT DEF becomes ABCDEF
’ABC ’ *TCAT DEF becomes ’ABCDEF’
ABC *TCAT ’ DEF’ becomes ’ABC DEF’
’ABC ’ *TCAT ’ DEF’ becomes ’ABC DEF’

All blanks that surround the concatenation operator are ignored, but at least one blank must be on each side of the reserved value operator (*CAT, *BCAT, or *TCAT).

This example shows the variables and their corresponding character string expressions.

This example shows how several character variables and character strings can be concatenated to produce a message for a workstation operator.

DCL VAR(&MSG)TYPE(*CHAR) LEN(100)
*
*
CHGVAR &MSG (’Customer’ *BCAT &CUSNAMD +
*BCAT’Account Number’ *BCAT +
&CUSNUM *BCAT ’is overdue by’ +
*BCAT &DAYS *BCAT ’days.’)

After the appropriate variables have been substituted, the resulting message might be:

Customer ABC COMPANY Account Number 12345
is overdue by 4 days.

Relational expressions:

The operands in a relational expression can be arithmetic or character string expressions. They can also be logical constants and logical variables.

Only two operands can be used with each relational operator.

The data type (arithmetic, character string, or logical) must be the same for the pair of operands.

The result of a relational expression is a logical value '0' or '1'.

Symbols: (=, >, =, , <) or their reserved values (*EQ, *GT, *LT, *GE, *LE, *NE, *NG, *NL).

The following are examples of relational expressions: (&X *GT 25) (&X > 25) (&X>25) (&NAME *EQ GSD) (&NAME *EQ &GSD) (&NAME *EQ ’GSD’) (&BLANK

Logical expressions:

The operands in a logical expression consist of relational expressions, logical variables, or constants that are separated by logical operators.

The result of a logical expression is a '0' or '1'.

The logical operators used to specify the relationship between the operands are *AND and *OR (as reserved values), and & and | (as symbols).

The AND operator indicates that both operands (on either side of the operator) have to be a certain value to produce a particular result.

The OR operator indicates that one or the other of its operands can determine the result.

The logical operator *NOT is used to negate logical variables.

The following are examples of logical expressions:

((&C *LT 1) *AND (&TIME *GT 1430))
(&C *LT 1 *AND &TIME *GT 1430)
((&C < 1) & (&TIME *GT 1430))
((&C<1)&(&TIME>1430))
(&A *OR *NOT &B)
(&TOWN *EQ CHICAGO *AND &ZIP *EQ 60605)

Two examples of logical expressions used in the IF command are:
IF &A CALL PROG1
IF (&A *OR &B) CALL PROG1

Operators in expressions:

Operators are used in expressions to indicate an action to be performed on the operands in the expression or the relationship between the operands. There are four kinds of operators, one for each of the four types of expressions: v

  • Arithmetic operators (+, -, *, /)
  • Character operator (||, |>, |, =, , ¬<)
  • Logical operators (&, |, ¬) 
  • Relational operators (=, >, =, , ¬<)

Each operator must be between the operands of the expression in which it is used; for example, (&A + 4).

Operators can be specified as a predefined value (for example, *EQ) or as a symbol (for example, =).

The following character combinations are the predefined values and symbols that represent the four kinds of operators

Priority of operators when evaluating expressions:

When multiple operators occur in an expression, the expression is evaluated in a specific order depending upon the operators in the expression. Parentheses can be used to change the order of expression evaluation.

The following table shows the priority of all the operators used in expressions, including signed decimal values.

Built-in functions for CL

Control language (CL) provides several built-in functions.

Built-in functions are used in arithmetic, character string, relational, or logical expressions.

CL provides the following built-in functions: %ADDRESS %BINARY  %CHECK  %CHECKR  %OFFSET  %SCAN  %SUBSTRING  %SWITCH  %TRIM  %TRIML  %TRIMR

%ADDRESS built-in function
The address built-in function (%ADDRESS or %ADDR) can be used to change or test the memory
address stored in a CL pointer variable and can only be used within a CL program or procedure.
%BINARY built-in function
The binary built-in function (%BINARY or %BIN) interprets the contents of a specified CL character
variable as a signed binary integer.

%CHECK built-in function
The check built-in function (%CHECK) returns the first position of a base string that contains a character
that does not appear in the comparator string. If all of the characters in the base string also appear in the
comparator string, the function returns 0. This function can only be used within a CL program or
procedure.
%CHECKR built-in function
The reverse check built-in function (%CHECKR) returns the last position of a base string that contains a
character that does not appear in the comparator string. If all of the characters in the base string also
appear in the comparator string, the function returns 0. This function can only be used within a CL
program or procedure.
%OFFSET built-in function
The offset built-in function (%OFFSET or %OFS) can be used to store or change the offset portion of a CL
pointer variable and can only be used within a CL program or procedure.
%SCAN built-in function
The scan built-in function (%SCAN) returns the first position of a search argument in the source string, or 0
if it was not found. This function can only be used within a CL program or procedure
%SUBSTRING built-in function
The substring built-in function (%SUBSTRING or %SST) produces a character string that is a subset of an
existing character string. This function can only be used within a CL program or procedure.
%SWITCH built-in function
The switch built-in function (%SWITCH) compares one or more of eight switches with the eight switch
settings already established for the job and returns a logical value of '0' or '1'.
%TRIM built-in function
The trim built-in function (%TRIM) with one parameter produces a character string with any leading and
trailing blanks removed. The trim built-in function (%TRIM) with two parameters produces a character
string with any leading and trailing characters that are in the characters to trim parameter removed. This
function can only be used within a CL program or procedure.
%TRIML built-in function
The trim left built-in function (%TRIML) with one parameter produces a character string with any
leading blanks removed. The trim left built-in function (%TRIML) with two parameters produces a
character string with any leading characters that are in the characters to trim parameter removed. This
function can only be used within a CL program or procedure.
%TRIMR built-in function
The trim right built-in function (%TRIMR) with one parameter produces a character string with any
trailing blanks removed. The trim right built-in function (%TRIMR) with two parameters produces a
character string with any trailing characters that are in the characters to trim parameter removed. This
function can only be used within a CL program or procedure

 

Post Comments