F run-time switch

Checks all numeric items for valid numeric data.
Restriction: These switches are supported for native COBOL only.

Properties:

Default: On
Type: General

Comments:

If the data is not valid, run-time system error 163 ("Illegal character in numeric field") is produced. Setting this switch to off suppresses this checking.

This checking is only done on generated code created with the CHECKNUM Compiler directive, and on intermediate code.

The run-time system and generated code try to optimize many types of numeric operations. These operations can cause invalid results if the numeric operands do not contain valid numeric data. By default, the run-time system gives the run-time system error 163 when a numeric operation is tried with invalid numeric data.

Invalid data is handled differently by intermediate and native code. We recommend that you enable numeric field checking while you are developing your program.

If you receive run-time error 163, we recommend that you adjust your code so that no invalid data is used. You can locate the invalid numeric data in your code by setting the +F switch on and then animating your program until run-time system error 163 is detected.

If you are not able to correct your code, you might want to use one or more of the following Compiler directives to resolve invalid data in numeric fields:

  • HOSTNUMCOMPARE - controls the operation of comparisons between integer numeric data items of USAGE DISPLAY and alphanumeric literals or figurative constants.
  • HOSTNUMMOVE - causes the Compiler to switch off checking for illegal characters in numeric fields during the execution of certain MOVE statements. (Use with care.)
  • SIGN-FIXUP - provides limited emulation of mainframe compiler options NUMPROC(NOPFD) and NUMPROC(PFD) for MOVE and COMPARE statements if you also set HOSTNUMCOMPARE or HOSTNUMMOVE.
  • SPZERO - causes space characters in numeric data items of USAGE DISPLAY to be treated as zeros.
Note: It is recommended to use both HOSTNUMMOVE or HOSTNUMCOMPARE with CHARSET(EBCDIC) to give maximum compatibility with IBM mainframe behavior. If CHARSET(ASCII) is used, then some compatibility may be lost due to character encoding differences.

Example:

working-storage section. 
    01 item-a       pic 9.
procedure division.
    If item-a =  0.
        Display "zero"
    else
        display "nonzero"
    end-if.

The variable item-a is not initialized by a VALUE clause, and so contains a space character x"20". Running this program with the F switch set on causes the run-time system to check whether the numeric field contains a non-numeric value resulting in run-time error 163.