Rational Developer for System z
Enterprise PL/I for z/OS, Version 3.8, Migration Guide

Even precision PICTURE loop control variables

Consider the following program to initialize an array:

   winter: proc;
      dcl n pic'99';
      dcl a(0:99) fixed bin ext;
      do n = 0 to 99;
         a(n) = n;
      end;
   end;

This code is not valid PL/I since if the SIZE condition were enabled, it would be raised after n became equal to 99 (since the next value, 100, it would assume is too large for a PIC'99' variable).

For best performance, using a PICTURE variable for a loop control variable is usually not a good idea. However, for the code above it is a very bad idea since the new compiler will generate code that will make this loop run endlessly.

By the definition of the DO statement, this loop is equivalent to the following code which will loop infinitely under both the old and new compiler.

      n = 0;
      if n > 99 then go to loop_exit;
      loop_body:;
         a(n) = n;
      n = n + 1;
      if n <= 99 then go to loop_body;
      loop_exit:;

However, for the original code using the DO-loop, the old compiler cheats and generates code that is, strictly speaking, incorrect.

The new compiler will try to alert you to this situation by issuing the following messages:

  IBM1089I W    Control variable in DO loop cannot
                exceed TO value, and loop may be infinite.
  IBM1220I W    Result of comparison is always constant.
  IBM1220I W    Result of comparison is always constant.

You should closely examine (and probably change) any code that causes the compiler to issue message IBM1089. You could also use the EXIT option to raise the severity of this message.

To correct your code, you could change the attributes for the DO-loop control variable from PICTURE to FIXED BIN(31).

Finally, note that this problem will occur in any loop where the DO-loop control variable is PICTURE'(n)9' when n is an even number and the loop limit is equal to 10**n-1.

This problem could also occur in forms which would not be flagged by the compiler. For example, consider the following program to initialize an array:

   sommer: proc;
      dcl n pic'999';
      dcl a(0:999) fixed bin ext;
      do n = 0 to 998 by 2;
         a(n) = n;
      end;
   end;

In this case, since the TO value of 998 is less than the maximum value that n could assume, the compiler will not issue message IBM1089. However, after n assumes the value 998, the next time through the loop n will be assigned the value 0 and the loop will repeat.

This problem could also occur when the BY value was negative:

   eiki: proc;
      dcl n pic'999';
      dcl a(0:99) fixed bin ext;
      do n = 79 to 1 by -2;
         a(n) = n;
      end;
   end;

However, after n assumes the value 1, the next time through the loop n will be decremented by 2 and assigned the value 1 and the loop will repeat.


Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)