Examples

DECIMAL FIXED to BINARY FIXED with fractions

  dcl I fixed bin(31,5) init(1);
      I = I+.1;

The value of I is now 1.0625. This is because .1 is converted to FIXED BINARY (5,4), so that the nearest binary approximation is 0.0001B (no rounding occurs). The decimal equivalent of this is .0625. The result achieved by specifying .1000 in place of .1 would be different.

Arithmetic to bit string

  dcl A bit(1),
      D bit(5);
  A=1;         /* A has value '0'B     */
  D=1;         /* D has value '00010'B */
  D='1'B;      /* D has value '10000'B */
  if A=1 then go to Y;
         else go to X;

The branch is to X, because the assignment to A resulted in the following sequence of actions:

  1. The decimal constant, 1, has the attributes FIXED DECIMAL (1,0) and is assigned to temporary storage with the attributes FIXED BINARY(4,0) and the value 0001B.
  2. This value now converts to a bit string of length (4), so that it becomes '0001'B.
  3. The bit string is assigned to A. Since A has a declared length of 1, and the value to be assigned has acquired a length of 4, truncation occurs at the right, and A has a final value of '0'B.

For the comparison operation in the IF statement, '0'B and 1 convert to FIXED BINARY and compare arithmetically. They are unequal, giving a result of false for the relationship A=1.

In the first assignment to D, a sequence of actions similar to that described for A takes place, except that the value is extended at the right with a zero, because D has a declared length that is 1 greater than that of the assigned value.

Arithmetic to character

In the following example, the three blanks are necessary to allow for the possibility of a minus sign, a decimal or binary point, and provision for a single leading zero before the point:
  dcl A char(4),
      B char(7);
  A='0'; /*A has value '0bbb'*/
  A=0;   /*A has value 'bbb0'*/
  B=1234567; /*B has value 'bbb1234'*/

A conversion error

dcl Ctlno char(8) init('0');
do I=1 to 100;
Ctlno=Ctlno+1;
⋮
end;

For this example, FIXED DECIMAL precision 15 was used for the implementation maximum. The example raises the CONVERSION condition because of the following sequence of actions:

  1. The initial value of CTLNO, that is, '0bbbbbbb' converts to FIXED DECIMAL(15,0).
  2. The decimal constant, 1, with attributes FIXED DECIMAL(1,0), is added; in accordance with the rules for addition, the precision of the result is (16,0).
  3. This value now converts to a character string of length 18 in preparation for the assignment back to CTLNO.
  4. Because CTLNO has a length of 8, the assignment causes truncation at the right; thus, CTLNO has a final value that consists entirely of blanks. This value cannot be successfully converted to arithmetic type for the second iteration of the loop.