Rational Developer for System z
Enterprise PL/I for z/OS, Version 4.2, Language Reference

Example of assigning a structure using BY NAME

The following example illustrates structure assignment using the BY NAME option:

  declare      declare       declare
  1 One,       1 Two,        1 Three,
   2 Part1,     2 Part1,      2 Part1,
    3 Red,       3 Blue,       3 Red,
    3 Orange,    3 Green,      3 Blue,
   2 Part2,      3 Red,        3 Brown,
    3 Yellow,   2 Part2,      2 Part2,
    3 Blue,      3 Brown,      3 Yellow,
    3 Green;     3 Yellow;     3 Green;
 1 
 2 
  One = Two, by name;
  One.Part1 = Three.Part1, by name;
 1 
The first assignment statement is the same as the following:
  One.Part1.Red    = Two.Part1.Red;
  One.Part2.Yellow = Two.Part2.Yellow;
 2 
The second assignment statement is the same as the following:
  One.Part1.Red = Three.Part1.Red;

Example of assigning a structure using BY DIMACROSS

The following example illustrates structure assignment using the BY DIMACROSS option.

Example 1
This code sums up all the row elements:
   dcl
     1 x,
        2 a fixed bin(31),
        2 b fixed bin(31),
        2 c fixed bin(31),
        2 d fixed bin(31);

   dcl 1 xa(17) dimacross like x;

   dcl jx fixed bin;

   x = 0;

   do jx = lboundacross( xa ) to hboundacross( xa );

      x = x + xa, by dimacross( jx );

   end;                             
The assignment inside the loop is equivalent to the following statements:
      x.a = x.a + xa.a(jx);
      x.b = x.b + xa.b(jx);
      x.c = x.c + xa.c(jx);
      x.d = x.d + xa.d(jx);
Example 2
This code exchanges the entries in the first and seventeenth columns of xa:
   dcl
     1 x,
        2 a fixed bin(31),
        2 b fixed bin(31),
        2 c fixed bin(31),
        2 d fixed bin(31);

   dcl 1 xa(17) dimacross like x;

   dcl y like x;

   x = xa, by dimacross( 1  );
   y = xa, by dimacross( 17 );
   xa = y, by dimacross( 1  );
   xa = x, by dimacross( 17 );

Terms of use | Feedback

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