CL Programming

Changing the Value of Variables

You can change the value of variables by using the EVAL command with the assignment operator (=).

The scope of the variables used in the EVAL command is defined by using the QUAL command. However, you do not need to specifically define the scope of the variables contained in a CL module because they are all of global scope.

You can use the EVAL debug command to assign numeric, character, and hexadecimal data to variables provided they match the definition of the variable.

To change the value of the variable, type:

EVAL variable-name = value

on the debug command line. Variable-name is the name of the variable that you want to change and value is an identifier or literal value that you want to assign to variable-name. For example,

EVAL &COUNTER = 3.0

changes the value of &COUNTER; to 3.0 and shows

&COUNTER = 3.0 = 3.0

on the message line of the Display Module Source display. The result is preceded by the variable-name and value you are changing.

When you assign values to a character variable, the following rules apply:

Note:
DBCS variables can be assigned any of the following:

Change logical variable examples

CL declarations:   DCL    VAR(&LGL1) TYPE(*LGL) VALUE('1')
                   DCL    VAR(&LGL2) TYPE(*LGL)
 
 
Debug command:     EVAL &LGL1
 
Result:            &LGL1 = '1'
 
 
Debug command:     EVAL &LGL1 = X'F0'
 
Result:            &LGL1 = X'F0' = '0'
 
 
Debug command:     EVAL &LGL2 = &LGL1
 
Result:            &LGL2 = &LGL1 = '0'
 

Change character variable examples

CL declarations:   DCL    VAR(&CHAR1) TYPE(*CHAR) LEN(1) VALUE('A')
                   DCL    VAR(&CHAR2) TYPE(*CHAR) LEN(10)
 
 
Debug command:     EVAL &CHAR1 = 'B'
 
Result:            &CHAR1 = 'B' = 'B'
 
 
Debug command:     EVAL &CHAR1 = X'F0F1F2F3'
 
Result:            &CHAR1 = 'F0F1F2F3' = '0'
 
 
Debug command:     EVAL &CHAR2 = 'ABC'
 
Result:            &CHAR2 = 'ABC' = 'ABC       '
 
 
Debug command:     EVAL %SUBSTR(CHAR2 1 2) = %SUBSTR(&CHAR2 3 1)
 
Result:            %SUBSTR(CHAR2 1 2) = %SUBSTR(&CHAR2 3 1) = 'C '
 
Comment:           Variable &CHAR contains 'C C       '

The %SUBSTR built-in function allows you to substring a character string variable. The first argument must be a string identifier, the second argument is the starting position, and the third argument is the number of single byte or double byte characters. Arguments are delimited by one or more spaces.

Change decimal variable examples

CL declarations:    DCL    VAR(&DEC1) TYPE(*DEC) LEN(3 1) VALUE(73.1)
                    DCL    VAR(&DEC2) TYPE(*DEC) LEN(2 1) VALUE(3.1)
 
 
Debug command:     EVAL &DEC1 = 12.3
 
Result:            &DEC1 = 12.3 = 12.3
 
 
Debug command:     EVAL &DEC1 = &DEC2
 
Result:            &DEC1 = &DEC2 = 03.1
 


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]