CRITICAL
Rule Definition
The CORRESPONDING option allows moving fields from a data structure to another by using their respective names with only one statement. This option works silently because the moved fields are not explicitly specified and this can lead different problems:
- A field is defined into only one data structure
- Two fields defined in the both data structures have the same name but not the same type.
In the first case, the field will not be moved and the data will be lost. In the second case, data fields with different (incompatible?) types will be moved the one into the other and the data will be corrupted because of truncated size or bad conversion.
Remediation
Try as much as possible to replace the MOVE CORRESPONDING statements by explicit MOVE statements or add explanations about fields to be moved in the code.
Violation Code Sample
01 A.
05 FIELD-1 PIC XX.
05 FIELD-2 PIC XXX.
05 FIELD-3 PIC 9.
01 B.
05 FIELD-1 PIC XX.
05 FIELD-4 PIC 999.
05 FIELD-2 PIC X(3).
PROCEDURE DIVISION.
MOVE CORRESPONDING A TO B.
Fixed Code Sample
MOVE FIELD-1 OF A TO FIELD-1 OF B.
MOVE FIELD-2 OF A TO FIELD-2 OF B.
Related Technologies
Cobol
Technical Criterion
CWE-197 - Numeric Truncation Error
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.