Why does the result of INSPECT ... CONVERTING give a different signed result than the previous TRANSFORM verb in Enterprise COBOL for z/OS and COBOL for VSE/ESA?
Use of the INSPECT verb with the CONVERTING clause in a COBOL program can get unexpected results that differ from TRANSFORM when the inspected item is defined as a signed-numeric field.
With the signed-numeric field, COBOL will preserve the original sign of the field and restore it after the INSPECT instruction is done. No additional sign fix-up is done, and unexpected results can follow if checking is done later for valid numeric contents in the field.
The program in question has a field defined as S9(7) and code:
INSPECT field CONVERTING SPACES TO ZEROES.
When the field is converted, the result is 6 zeroes and 1 space (i.e hex F0F0F0F0F0F040), the field then fails an IF NUMERIC test.
The Language Reference states that if a sign is separate, it will not be inspected or converted, but this is not the case here.
The INSPECT process will preserve the original sign. You will see an MVZ instruction to restore the sign after the TR instruction is done, when you read the LIST output for the INSPECT verb.
To get the results you want, eliminate the sign (that is, use PIC 9(7) without the "S") or redefine the field as X(7).
When the TRANSFORM verb (from COBOL '74 or earlier) is converted to INSPECT, do not use it with signed numeric data items because the two verbs behave differently in that respect. Redefine the data as alphanumeric (or unsigned numeric, even) and use that newly redefined name in the INSPECT verb, and not the original name that was in the TRANSFORM. When used in this manner, the INSPECT verb will be a good replacement for the OS/VS COBOL TRANSFORM verb.
|Software Development||COBOL for VSE/ESA||Compile|
RTA000130655 PRO (DATE/19940902)
Rate this page:
Copyright and trademark information
IBM, the IBM logo and ibm.com are trademarks of International Business Machines Corp., registered in many jurisdictions worldwide. Other product and service names might be trademarks of IBM or other companies. A current list of IBM trademarks is available on the Web at "Copyright and trademark information" at www.ibm.com/legal/copytrade.shtml.