Change the value of a variable

You can change the value of a CL variable using the Change Variable (CHGVAR) command.

The value can be changed:

The CHGVAR command can be used to retrieve and to change the local data area also. For example, the following commands blank out 10 bytes of the local data area and retrieve part of the local data area:

CHGVAR %SST(*LDA 1 10) ' '
 
CHGVAR &A %SST(*LDA 1 10)

The following table shows valid assignments to variables from values (literals or variables).

Table 1. Valid assignments to variables from values
  Logical Value Character Value Decimal Value Signed Integer Value Unsigned Integer Value
Logical Variable X        
Character Variable X X X X X
Decimal Variable   X X X X
Signed Integer Variable   X X X X
Unsigned Integer Variable   X X X X
Note:
  1. When specifying a numeric value for a character variable, remember the following:

    • The value of the character variable is right-justified and, if necessary, padded with leading zeros.
    • The character variable must be long enough to contain a decimal point and a minus (-) sign, when necessary.
    • When used, a minus (-) sign is placed in the leftmost position of the value.

    For example, &A is a character variable to be changed to the value of the decimal variable &B. The length of &A is 6. The length and decimal positions of &B are 5 and 2, respectively. The current value of &B is 123. The resulting value of &A is 123.00.

  2. When specifying a character value for a numeric variable, remember the following:

    • The decimal point is determined by the placement of a decimal point in the character value. If the character value does not contain a decimal point, the decimal point is placed in the rightmost position of the value.
    • The character value can contain a minus (-) sign or plus (+) sign immediately to the left of the value; no intervening blanks are allowed. If the character value has no sign, the value is assumed to be positive.
    • If the character value contains more digits to the right of the decimal point than can be contained in the numeric variable, the digits are truncated if it's a decimal variable, or rounded if it's an integer variable. If the excess digits are to the left of the decimal point, they are not truncated and an error occurs.

      For example, &C is a decimal variable to be changed to the value of the character variable &D The length of &C is 5 with 2 decimal positions. The length of &D is 10 and its current value is +123.1bbbb (where b=blank). The resulting value of &C is 123.10.

Related reference
%ADDRESS built-in function
%OFFSET built-in function
%SUBSTRING built-in function
%SWITCH built-in function
%BINARY built-in function
Related information
Change Variable (CHGVAR) command