ANSWERS: 2
  • Yes, you use inspect to count past leading zeros or spaces, then use string to use the result. Example: WORKING STORAGE: 77 WS-NUMBER PIC S9(9) COMP. 77 WS-START-POS PIC S9(4) COMP. 77 WS-ZERO-SUPPRESS PIC ZZZZZZZZZ9. COBOL PROCEDURE: MOVE WS-NUMBER TO WS-ZERO-SUPPRESS MOVE ZERO TO WS-START-POS INSPECT WS-ZERO-SUPPRESS TALLYING WS-START-POS FOR LEADING SPACE IF WS-NUMBER < ZERO THEN STRING 'THE NEGATIVE NUMBER ' '-' WS-ZERO-SUPPRESS(WS-START-POS:) ' HAS NO LEADING ZEROS.' DELIMITED BY SIZE INTO DISPLAY-FIELD END-STRING ELSE STRING 'THE NUMBER ' WS-LEFT-JUSTIFY(WS-START-POS:) ' HAS NO LEADING ZEROS.' INTO DISPLAY-FIELD END-STRING END-IF CONTINUE.
  • If your compiler supports ASCII Control Characters with double double quotes there is a more simple solution. If not you need a binary field of 1 byte containing the NUL character (000). Working-Storage Section. 01 NUM-FLD pic S9(6)V99. 01 EDT-FLD pic Zzz,zz9.99-. Procedure Division. Spc-to-nul section. s20. Move NUM-FLD to EDT-FLD. Inspect EDT-FLD replacing leading spaces by ""1"".

Copyright 2020, Wired Ivy, LLC

Answerbag | Terms of Service | Privacy Policy