by BillyBoyo » Fri Apr 21, 2017 10:31 pm
ACCEPT and DISPLAY in Enterprise COBOL and prior IBM Mainframe COBOLs are very limited (and Standard) in their operation. They are not intended for general-purpose use in producing/consuming formatted data.
If you define a numeric-edited field and MOVE the binary value to that, and then DISPLAY the numeric-edited field, you'll get a much more "friendly" output.
01 to-show-a-signed-binary PIC -99999. (five digits in case you have TRUNC(BIN), else four).
If you were to DISPLAY a binary defined with decimal places, you wouldn't get any in your output. Again, define a numeric edited field to show those if you ever have them.
Without using numeric-edited fields, you are getting output which distinguishes between + and -, but without showing you are sign (which sign would you want, leading, trailing, CR/DB)?
If you try it, you'll find a similar thing with zoned-decimal and packed-decimal. Instead of relying on the default values for the representation of DISPLAY, use numeric-edited if you want to see the value which would be represented on a report or screen, and REDEFINES the field as a PIC (or have the fields subordinate to a group-item) and DISPLAY that field (and use HEX when looking at the output) if you want to see the internal representation - the value prior to what was produced by the editing (useful if you feel there may be bad data in your field).