IBM Support

COBOL INSPECT of signed-numeric field may give an unexpected sign result

Technote (FAQ)


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:

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.

Cross reference information
Segment Product Component Platform Version Edition
Software Development COBOL for VSE/ESA Compile

Historical Number

RTA000130655 PRO (DATE/19940902)

Document information

More support for: Enterprise COBOL for z/OS

Software version: 3.4, 4.1, 4.2

Operating system(s): z/OS

Reference #: 1002559

Modified date: 12 December 2012

Translate this page: