MOVE substring in COBOL
For many years it has been possible in COBOL to make MOVE as:
MOVE <field> (<position>: <length>) TO ...
MOVE ... TO <field> (<position>: <length>)
which is very clever, as it is very easy to work with dynamic text strings.
In the above examples, it is possible to omit <length>, which indicates that data must be moved to the end of <field>, where in the receiving situation, padding with spaces should be made.
However, it is haphazardly dangerous to omit <length> as very serious storage violations can occur if <position> erroneously points behind the end of <field> when MOVE is made, as COBOL then erroneously calculates a negative length that the machine perceives positively, thereby making a MOVE with a padding length of about 16 M bytes, which can inevitably cause a CICS to shut down.
However, it has been found that there is another serious consequence by omitting <length> if <field> is a large area.
This is documented by the following two examples:
01 <long-text> PIC X(256000).
01 <data> PIC X(80).
MOVE 1 TO IX
MOVE LENGTH OF <data> TO LEN
COMPUTE MAX = LENGTH OR <long-text> - LEN
PERFORM <retrieve-data>
* Example-1
PERFORM UNTIL <no-more-data> OR IX > MAX
MOVE <data> TO <long-text> (IX:)
ADD LEN TO IX
PERFORM <retrieve-data>
END-PERFORM
MOVE 1 TO IX
MOVE LENGTH OF <data> TO LEN
COMPUTE MAX = LENGTH OR <long-text> - LEN
PERFORM <retrieve-data>
* Example-2
PERFORM UNTIL <no-more-data> OR IX> MAX
MOVE <data> TO <long-text> (IX:LEN)
ADD LEN TO IX
PERFORM <retrieve-data>
END-PERFORM
Where data is moved to a large area of 256,000 bytes with 80 bytes at a time in a loop. In Example-1 there is no <length> while in Example-2 <length> is specified. <retrieve-data> is in the current sample an empty section and <no-more-data> is false.
In Example-1 padding is made with spaces to the end of <long-text> every time around in the loop, while no padding is made in Example-2.
In Example-1, a total of 256,000 / 80/2 * (80 + 256,000) = 409,728,000 bytes are received.
In Example-2, a total of 256,000 bytes are received.
The CPU consumption in Example-1 is measured at 0.064268 CPU-second.
The CPU consumption in Example-2 is measured at 0, 000155 CPU second.
By comparison, an average transaction in our Netbank/Mobilebank performing about 100 DB2-SQL-calls is consuming 0.002047 CPU seconds.
All is running on IBM z13 model 2964-710 / N63.
In Example-1, 415 times more CPU is consumed than in Example-2, while the result is, in principle the same, and the consumption in Example-1 is more than 31 times higher than the average Netbank / Mobilebank transaction, which is completely thought-provoking.
There are therefore several good reasons to ALWAYS specify <length> in MOVE substring! ! !
Det er mange år siden jeg "stod i lære" hos Ole og det er også længe siden jeg har skrevet en linie Cobol - det er der sikkert mange, der er glade for ;-) Men som en smed der elsker sin armbolt, en tømmer der holder af sin sav - nyder jeg forsat at læse "doktriner".