
Built in functions in CL
CL provides the following built-in functions
%SUBST(character-variable-name starting-position length)
%SWITCH(8-character-mask)
%BINARY(character-variable-name starting-position length
%SUBSTRING
-
Produce a character string that is a subset of a character string
-
In CHGVAR command %SST can be specified
-
Used only in CL program
%SUBSTRING(CHARACTER_VARIABLE_NAME
STARTING_POSITION LENGTH)
-
Can use *LDA in the place of character variable name and use %SST can be performed on the contents of the *LDA
-
Neither the starting position nor the length can be 0 or negative
-
Both Position and length can also be variables
Example:
DCL &A *CHAR VALUE(‘DEF’)
DCL &B *CHAR VALUE(‘ABC’)
IF (%SUBSTRING(&A 1 2 ) *EQ %SST(&B 1 2))
CALL PGMA
%SWITCH
-
Compares one or more of eight switches with the eight switches setting established for the job
-
Returns value of ‘0’ or ‘1’
-
Initial values of the switches for the job are determined first by the CRTJOBD command with default value as 00000000.
-
Switches can be tested in CL procedures to control the flow of the procedure
-
Using CHGJOB command the value of the switches can be changed in a CL procedure
-
Position 1 corresponds to job switch; position 2 correspond to job switch 2 ......
-
Each position in the mask can be specified as 0, 1 or X
-
0 OFF
1 On
X Not to be tested
Syntax:
%SWITCH(8-character-mask)
% SWITCH(0X111XX0)
JOB SWITCHES
1 & 8 are tested for ‘0’s:
2, 6 & 7 are not to be tested
3, 4 & 5 are tested for ‘1’ s;
-
If Switch contains the value in the mask, the result of %switch will be ‘1’ (true)
IF (%SWITCH(011XXXXX)) CALL PGMA
IF (%SWITCH(1XXXXXXX)) CALLPRC Procedure1
ELSE CALLPRC Procedure2
CHGVAR VAR(&A) VALUE(%SWITCH(10000001))
% BINARY
-
Used to manipulate binary numbers
-
The %Binary function is used to extract a binary integer from a character (*CHAR) variable.
-
The syntax of the %Binary takes the following form:
CHGVAR VAR(&decnbr) VALUE(%BINARY(&decnbr 1 2)