Purpose

The Assignment (=) statement assigns the value of a constant to a variable, the value of one variable to another variable, or the value of an expression to a variable.
 

Syntax

variable = operand
 

Operation

variable is any valid alphanumeric, wide, or numeric variable.

operand
 is any valid alphanumeric, wide, or numeric constant, variable, or expression.

 

Remarks

The operand must be of the same data type as the variable (i.e. either both alphanumeric, both wide, or both numeric.)
 

Example

Assume that   #A = 10,   $B = ‘A01’,   $C = "‘PROIV TECHNOLOGY", and
CUSTNAME is an alphanumeric file variable with a maximum length of 8.

#I = #A sets #I to 10

#I = 35.98765 sets #I to 35.98765

$I = $B sets $I to ‘A01’

$I = ‘XYZ’ sets $I to ‘XYZ’

#A = $B is invalid because the variables are not of the same data type

CUSTNAME=’SMITH’ sets CUSTNAME to ‘SMITH’

CUSTNAME=$C sets CUSTNAME to ‘PROIV TE’

"INVALID" = $B is invalid because the left side of the equation is a constant not a variable.
 

Intermediate Assignment

There are four special formats of the Assignment (=) statement that automatically increment, decrement, multiply, or divide the current value of the numeric variable on the left-hand-side of the equation.  The value is defined by the value of the numeric constant, variable, or expression on the right-hand side of the equation, and places the new value in the variable on the left-hand-side.
 

Syntax

operand1 operator = operand2
 

Operation

operand1 is any valid numeric variable.

op
erator
 is one of the following intermediate assignment operators:

+
(automatic increment)
-  
(automatic decrement)
*
(automatic multiply)
/
(automatic divide)

operand2
 is any valid numeric constant, expression, or variable.
 

Example

Assume that COUNTER, TOTAL, NEW-SALE, and RETURNS are numeric variables.

A += 2 is equivalent to A = A + 2

B -= 4 is equivalent to B = B – 4

C *= 5 is equivalent to C = C * 5

D /= 6 is equivalent to D = D / 6

COUNTER += 1 is equivalent to COUNTER = COUNTER + 1

COUNTER -= 1 is equivalent to COUNTER = COUNTER – 1

TOTAL += NEW-SALE  is equivalent to TOTAL = TOTAL + NEW-SALE

TOTAL -= RETURNS  is equivalent to TOTAL = TOTAL – RETURNS
 

Comment on this topic

Topic ID: 520022