NUMCHECK

The NUMCHECK compiler option tells the compiler whether to generate extra code to validate data items when they are used as sending data items. For zoned decimal (numeric USAGE DISPLAY) and packed decimal (COMP-3) data items, the compiler generates implicit numeric class tests for each sending field. Start of changeFor alphanumeric senders whose contents are being moved to a numeric receiver, the compiler treats the sender as a numeric integer so NUMCHECK generates an implicit numeric class test for each alphanumeric sender. End of changeFor binary data items, the compiler generates SIZE ERROR checking to see whether the data item has more digits than its PICTURE clause allows.

The NUMCHECK option is updated to remove redundant checks for invalid data, thus improving runtime performance. There may be fewer runtime messages than before.

The analysis done to remove redundant checks is more involved at OPT(1|2) than at OPT(0). OPT(0) does a simpler form of the analysis to keep compilation time as low as possible. There may be fewer messages at higher OPT levels.

When the compiler is able to determine at compile time that a check will always find invalid data, a compile-time message is produced and the runtime check is removed. (See MSG|ABD below.)

NUMCHECK option syntax

Read syntax diagramSkip visual syntax diagramNONUMCHECKNUMCHECK(,ZON(,ALPHNUMNOALPHNUMLAXSTRICT)NOZONPACNOPACBIN(TRUNCBINNOTRUNCBIN)NOBINMSGABD)

Default is: NONUMCHECK

Suboption defaults are:
  • Start of changeIf no suboption is specified, defaults are ZON(ALPHNUM,STRICT), PAC, Start of changeBIN(TRUNCBIN)End of change, and MSG. For example, NUMCHECK has the same effect as Start of changeNUMCHECK(ZON(ALPHNUM,STRICT),PAC,BIN(TRUNCBIN),MSG)End of change.End of change
  • Start of changeIf no datatype suboption is specified, default datatype suboptions are ZON(ALPHNUM,STRICT), PAC, and Start of changeBIN(TRUNCBIN)End of change. For example, NUMCHECK(ABD) has the same effect as Start of changeNUMCHECK(ZON(ALPHNUM,STRICT),PAC,BIN(TRUNCBIN),ABD)End of change.End of change
  • If only one datatype suboption is specified, defaults are NOZON, NOPAC, NOBIN, and MSG. For example, NUMCHECK(BIN) has the same effect as Start of changeNUMCHECK(NOZON,NOPAC,BIN(TRUNCBIN),MSG)End of change.
  • If all datatype suboptions are specified with NO, then the listing will show NONUMCHECK. For example, NUMCHECK(NOZON,NOPAC,NOBIN) has the same effect as NONUMCHECK.

Abbreviations are: NONC | NC

Start of changeZON(ALPHNUM|NOALPHNUM,LAX|STRICT) | NOZONEnd of change

Start of changeThe default is ZON(ALPHNUM,STRICT) when ZON is specified with no suboptions.End of change

Specifying ZON(ALPHNUM) causes the compiler to generate code for an implicit numeric class test for zoned decimal (numeric USAGE DISPLAY) data items that are used as sending data items in COBOL statements.

Specifying ZON(NOALPHNUM) causes the compiler to generate code for an implicit numeric class test for zoned decimal (numeric USAGE DISPLAY) data items that are used as sending data items in COBOL statements, except when they are used in a comparison with an alphanumeric data item, alphanumeric literal, or alphanumeric figurative constant.

Receivers are not checked, unless they are both a sender and a receiver, such as data item B in the following sample statements:

ADD A TO B
DIVIDE A INTO B
COMPUTE B = A + B
INITIALIZE B REPLACING ALPHANUMERIC BY B
This checking is done before the data is used in each statement:
  • If the data is NOT NUMERIC, either a warning message for NUMCHECK(ZON,MSG) or a terminating message for NUMCHECK(ZON,ABD) is issued.
  • If the data is NUMERIC, the external behavior of the statement is the same as NUMCHECK(NOZON), other than being slower.
Start of changeSpecifying ZON(LAX) causes the compiler to be more tolerant of invalid data in a zoned decimal data item. Start of changeThree casesEnd of change are considered by the compiler as follows:
  • An unsigned zoned decimal data item redefines a signed trailing overpunch zoned decimal data item such that the last byte of the unsigned item overlaps the last byte of the signed item. In this case, the unsigned redefining item is treated as a signed zoned decimal item for the purposes of the NUMCHECK checking.
    Notes:
    • The signed zoned decimal item that is redefined must be a level-01 or level-77 item. The unsigned zoned decimal item can be a level-01 or level-77 item or can be a subordinate item in a group.
    • The unsigned zoned decimal item does not need to overlap the entire signed zoned decimal item. It is only necessary for the last byte of each item to overlap. For example:
      01 NUM1 PIC S9(8).
      01 NUM2 REDEFINES NUM1.
         03 NUM2-PART1 PIC 9(4).
         03 NUM2-PART2 PIC 9(2).
         03 NUM2-PART3 PIC 9(2).
      In this case, data item NUM2-PART3 will be treated by NUMCHECK as a signed zoned decimal data item because its last byte overlaps the last byte of NUM1, which is a signed trailing overpunch zoned decimal item. Thus, the following values of NUM2-PART3 are all considered valid:
      • x'F1F2F3F4F5F6F7F8'
      • x'F1F2F3F4F5F6F7C8'
      • x'F1F2F3F4F5F6F7D8'
      .
  • A zoned decimal data item redefines a numeric-edited data item that may contain leading spaces, as indicated by the Z symbol in the numeric-edited item’s PICTURE string, and the leading bytes of the zoned decimal data item overlap some or all of the leading bytes of the numeric-edited item. In this case, NUMCHECK will tolerate spaces in the leading bytes of the zoned decimal data item that overlap those bytes of the numeric-edited item that permit spaces.
    Notes:
    • The numeric-edited item that is redefined must be a level-01 or level-77 item. The zoned decimal item can be a level-01 or level-77 item or can be a subordinate item in a group.
    • If the zoned decimal item is signed, it must be signed trailing overpunch.
    • The first byte of the zoned decimal item must overlap the first byte of the numeric-edited item to be considered eligible for this treatment, but the zoned decimal item does not need to overlap the entire numeric-edited item. For example:
      01 NUMED PIC ZZ99.99.
      01 NUM REDEFINES NUMED.
         03 INTVAL PIC 9(4).
         03 FILLER PIC X.
         03 DECVAL PIC 9(2).
      In this case, NUMCHECK tolerates spaces in the first two bytes of INTVAL because it overlaps the first two bytes of NUMED which are defined with the Z symbol in its PICTURE string. Thus, the following values of INTVAL are all considered valid:
      • x'F1F2F3F4'
      • x'40F1F2F3'
      • x'4040F1F2'
      Note that for performance reasons, mixes of spaces and non-spaces are tolerated in the leading bytes, thus x’F140F1F2’ is also considered valid.
  • Start of changeA zoned decimal data item is moved to a zoned Start of changeor alphanumericEnd of change data item. In this case, NUMCHECK will not check the sender of the move. However, if the sender is subsequently used in a numeric context, it will be checked.End of change
End of change
Start of changeIf ZON(STRICT) is specified, NUMCHECK does not consider any data items that a zoned decimal data item might redefine, and strict checking of the zoned decimal data is performed as usual.
Note: Start of changeThe ZON(LAXREDEF|STRICTREDEF) option is deprecated but is tolerated for compatibility, and it is replaced by the ZON(LAX|STRICT) option.End of change
End of change
PAC | NOPAC

Specifying PAC causes the compiler to generate code for an implicit numeric class test for packed decimal (COMP-3) data items that are used as sending data items in COBOL statements. For packed decimal data items that have an even number of digits, the unused bits are checked for ones.

Restriction: For CALL statements, NUMCHECK(ZON) and NUMCHECK(PAC) check BY CONTENT data items that are zoned decimal or packed decimal, but they do not check BY REFERENCE parameters. (Neither zoned decimal nor packed decimal data items can be specified in a BY VALUE phrase.)
Start of changeBIN(TRUNCBIN|NOTRUNCBIN) | NOBINEnd of change
Specifying BIN causes the compiler to generate code similar to ON SIZE ERROR to test if binary data items contents are bigger than the PICTURE clause. This extra code will be generated only for binary data items that are used as sending data items, and COMP-5 data items will not get this ON SIZE ERROR code generated.
Start of changeWhen BIN(TRUNCBIN) is in effect, the checking code is generated for binary data items, even when the TRUNC(BIN) compiler option is in effect. Note that BIN(TRUNCBIN) is the default when no suboption for BIN is specified.End of change
Start of changeWhen BIN(NOTRUNCBIN) is in effect, the checking code is not generated for binary items when the TRUNC(BIN) compiler option is in effect.End of change
Start of change
Note: BIN(NOTRUNCBIN) is useful for users who want to make NUMCHECK(..., BIN, ...) a fixed option in their default options, but do not want the checking to be done for modules that are compiled with the TRUNC(BIN) option in effect.
End of change
MSG | ABD
Determines whether the message issued for invalid data is a warning level message to continue processing or a terminating level message to cause an abend:
  • If MSG is in effect, a runtime warning message with the line number, data item name, data item content, and program name is issued. Start of changeAlso, the affected statements will still be executed. End of change
  • If ABD is in effect, a terminating message is issued that causes an abend.

When the compiler is able to determine at compile time that a check will always find invalid data, a compile-time error-level message is produced and the check is removed regardless of whether MSG or ABD is in effect.

Performance considerations: NUMCHECK is much slower than NONUMCHECK, depending on how many zoned decimal (numeric USAGE DISPLAY) data items, packed decimal (COMP-3) data items, and binary data items are used in a COBOL program.
Since COBOL 6.2 with service applied, performance of NUMCHECK has been improved. However, performance is still best when specifying NONUMCHECK, and will be better at a higher OPT level.

Note: ZONECHECK is deprecated but is tolerated for compatibility, and it is replaced by NUMCHECK(ZON(ALPHNUM)).

Related references  
NUMPROC  
TRUNC  
ZONECHECK  
INVDATA