Sometimes I get pretty surprised about what makes programs use lots of CPU. I have a tendency to blame DB2. Because of this I am caring much about tuning DB2 SQL statements. There are other ways of using excessive amounts of CPU, though. Simple assigment statement may sometimes do the trick.
In COBOL an assigment statement is a MOVE A TO B. In PL/I and almost all other programming languages the equivalent statement is a B = A. You may argue that such a simple statement cannot use any excessive CPU. Well, it can especially when B is a large field consisting of lots of bytes. The typical limit for B is 32767 bytes and no matter how long A is most programming languages will fill out all 32767 bytes in B when B is assigned without any further directives. Believe or not, it is much cheaper to fill out 100 bytes than 32767 bytes. Therefore it is worth considering whether B may be defined shorter or only to fill out the part of B actually used.
If B is a character string of variable length then A will be transferred to B and the length of B will be set to the length of A. Therefore you should consider to declare B as a character string of variable length, if possible. Another possibility is to specify the number of bytes in B that you will assign from A. In COBOL you achieve this in the following manner:
Of course you may use a variable or a constant with the desired length instead of LENGTH. In the above case you need a variable that contains the number of valid bytes in B corresponding to the length field in a character string of varying length.
The savings by applying the proposed solution above may be quite dramatic. In a seemingly simple program I managed to save 50% of the CPU usage for the total program execution by applying the change to a single assignment statement without doing any functional changes. Instead of moving and filling out 32767 bytes each time, the statement moved on average 500 bytes after the change.