MainframeSupports
tip week 38/2011:

In PL/I you assign values to variables by using an assignment statement. In COBOL on the contrary there is a variety of statements that assigns values to variables, for example MOVE, ADD, COMPUTE and SUBTRACT. One of the most commonly used statements in all programming languages is adding one to a variable. In COBOL you use a ADD 1 TO VARIABLE. In PL/I you use VARIABLE = VARIABLE + 1. But since version 3 of PL/I was introduced you can write VARIABLE += 1 to acheive exactly the same.

Version 3 of PL/I is commonly known as Enterprise PL/I and was released in 1998. The implementation of a new version of PL/I is typically a slow moving project. It may take several years before you as a programmer hear about it and even longer before you actually can use it. It is only two years ago I detected that the assignment statement has been extended with a compound assignment statement, which gives you the ability to add, subtract, multiply and divide using an abbreviated syntax:

DCL X FIXED BIN(31);
X = 1;
X += 1;
X -=1;
X *= 2;
X /= 2;
PUT SKIP LIST('X='!!X);
DCL A CHAR(10) VAR;
A = 'ABC';
A !!= 'DEF';
A !!= 'GHIJ';
PUT SKIP LIST('A='!!A);

The two PUT statements will output X=1 and A=ABCDEFGHIJ. All in all the compound statement can save you some keystrokes. At the same time it makes it easier to understand PL/I for C-programmers, who are familiar with this syntax. If you think it also makes PL/I programs faster to execute you will be slightly disappointed. For the last 25 years or more the PL/I compiler has been able to translate X=X+1 into ADD 1 TO X and create the corresponding more efficient machine code.

Previous tip in english        Forrige danske tip        Tip list