A COMP/COMP-4/COMP-5/BINARY field can contain any of the possible 256 bit patterns. X'40' in one of these fields is not a space, it is a binary value, of a particular magnitude depending on its position in the field.
A COMP-3 can easily contain X'40' and be valid, as long as it is not in the right-most byte. X'F0' is not valid anywhere in a COMP-3 field.
A PIC X field can validly contain any of the 256 bit patterns.
When using INSPECT, only use it for the particular fields you want to change. It would be unusual to use it for a group-item, and very unusual to use it for a group-item whose constituent fields were of different PICtures or USAGEs.
Note than any field, of any PICture, or any USAGE, can actually contain any bit-pattern. Nothing will stop that happening if that is how you code it. However, the results you get if you don't follow the conventions for PIC 9 USAGE DISPLAY or COMP-3, or for COMP-1 and COMP-2 for that matter, or for numeric-edited fields, won't necessarily be what you want.
Again, as you have shown, the COBOL compiler will do nothing to stop you putting "invalid" values into fields. Sometimes you'll get a result, although you may wonder exactly how you got that result. Sometimes you'll get an abend.
Becuase the compiler does nothing to prevent us trashing fields, we are careful how we use them, and also always validate numeric data arriving from external sources.
Get into the habit of knowing your data, data formats, and what happens when the format is not "normal" for a field. Keep bad data out of your system by knowing how to do so.
- These users thanked the author BillyBoyo for the post:
- Raj2006 (Mon Jul 29, 2013 10:35 am)