Microsoft KB Archive/47508

Problem with ZERO-FILL on AlphaNumeric Fields; COBOL 3.0

PSS ID Number: Q47508 Article last modified on 04-20-1993

3.00 3.00a | 3.00 3.00a MS-DOS | OS/2

Summary: ZERO-FILL does not work correctly as documented in the SCREEN SECTION with PIC X fields under COBOL versions 3.0 and 3.0a. ZERO-FILL also does not work at all in an ACCEPT statement within the PROCEDURE DIVISION. ZERO-FILL should cause the remaining characters of an input field to be padded with zeros. This works correctly under COBOL versions 2.x but does not work properly under versions 3.0 and 3.0a. Microsoft has confirmed this to be a problem in Microsoft COBOL versions 3.0 and 3.0a. This problem has been corrected in Microsoft COBOL Professional Development System version 4.0.

More Information: ZERO-FILL, when specified in an ACCEPT statement with a WITH clause, causes any unkeyed character positions of the data input field and the receiving field to be set to ASCII zeros when the ACCEPT is terminated. This format is the default method with PIC 9 fields. As documented in the manual, ZERO-FILL does not work properly in the SCREEN SECTION but will work correctly if the ZERO-FILL clause is specified prior to the PICture clause. This is the only workaround for obtaining ZERO-FILL in the SCREEN SECTION. The ZERO-FILL clause does not work at all in the PROCEDURE DIVISION as documented in the manual or by using the same workaround as the SCREEN SECTION. For more information on ZERO-FILL, consult the “Microsoft COBOL Compiler Version 3.0: Language Reference Manual” for versions 3.0 and 3.0a, Page 15-44.

Code Example
The code example given below can be compiled under COBOL 2.x to see the correct results. When compiled under COBOL 3.0 or 3.0a, the ZERO-FILL clause does not work properly. If the commented lines are uncommented in the SCREEN SECTION and the corresponding lines in the PROCEDURE DIVISION, they demonstrate the workaround under COBOL 3.0 and 3.0a. IDENTIFICATION DIVISION. PROGRAM-ID. ZERO-COB. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 FIELD-1 PIC X(5). 01 DELAY-VAR PIC X. SCREEN SECTION. 01 ACCEPT-INPUT. 03 LINE 1 COLUMN 1 VALUE “SCREEN-SECTION INPUT A PIC X(5) WITHOUT ZERO-FILL:”. 03 PIC X(5) USING FIELD-1 ZERO-FILL. 01 DISPLAY-INPUT. 03 LINE 3 COLUMN 1 VALUE “RESULT FOR SCREEN-SECTION PIC X(5) WITHOUT ZERO-FILL:”. 03 PIC X(5) USING FIELD-1 ZERO-FILL. 03 LINE 5 COLUMN 1 VALUE “******************************************************”. ''01 ACCEPT-INPUT2. '' 03 LINE 6 COLUMN 1 VALUE * “SCREEN-SECTION INPUT A PIC X(5) WITH ZERO-FILL:”. * 03 ZERO-FILL PIC X(5) USING FIELD-1. ''01 DISPLAY-INPUT2. '' 03 LINE 8 COLUMN 1 VALUE * “RESULT FOR SCREEN-SECTION PIC X(5) WITH ZERO-FILL:”. * 03 PIC X(5) USING FIELD-1. * 03 LINE 10 COLUMN 1 VALUE * “******************************************************”. 01 DELAY-SCREEN. 03 LINE 25 COLUMN 1 VALUE “HIT ANY KEY TO END THE PROGRAM …”. 03 PIC X AUTO SECURE USING DELAY-VAR. PROCEDURE DIVISION. MAIN-PARAGRAPH. * ACCEPT THE SCREEN-SECTION WITHOUT ZERO-FILL. DISPLAY ACCEPT-INPUT. ACCEPT ACCEPT-INPUT. DISPLAY DISPLAY-INPUT. * REINITIALIZE THE VARIABLE. MOVE SPACES TO FIELD-1. * ACCEPT THE SCREENS WITH ZERO-FILL.   #### REMOVE THE ASTERISKS() FROM THE NEXT 3 LINES AND ####  #### THE 8 LINES CORRESPONDING IN THE SCREEN-SECTION #### * #### TO ILLUSTRATE THE INCORRECT SYNTAX IN COBOL 3.0. ####   DISPLAY ACCEPT-INPUT2. * ACCEPT ACCEPT-INPUT2. * DISPLAY DISPLAY-INPUT2.   * ACCEPT IN THE PROCEDURE DIVISION. DISPLAY “PROCEDURE DIVISION. INPUT A PIC X(5) ZERO-FILL:” AT 1601. ACCEPT FIELD-1. DISPLAY “RESULT FOR PROCEDURE DIVISION PIC X(5) ZERO-FILL:” AT 1801. DISPLAY FIELD-1. * DELAY UNTIL THE USER INPUTS A CHARACTER. DISPLAY DELAY-SCREEN. ACCEPT DELAY-SCREEN. STOP RUN.

Additional reference words: 3.00 3.00a Copyright Microsoft Corporation 1993.