The numeric data you use in your program will be one of the five types available with VS COBOL II:

  • External decimal (USAGE DISPLAY)
  • Internal decimal (USAGE PACKED-DECIMAL)
  • Binary (USAGE BINARY)
  • External floating point (USAGE DISPLAY)
  • Internal floating point (USAGE COMPUTATIONAL-1. USAGE COMPUTATIONAL-2)

The types COMPUTATIONAL and COMPUTATIONAL-4 are synonymous with BINARY. The type COMPUTATIONAL-3 is synonymous with PACKED-DECIMAL.

Sign Representation

There are six valid sign representations for external decimal (USAGE DISPLAY without the SIGN IS SEPARATE clause) and internal decimal (USAGE PACKED-DECIMAL) COBOL data. These are:

  • Positive: X'C, X'A' X*E\ and X'F'
  • Negative: X'D" and X'B'

The VS COBOL II compiler option NUMPROC affects sign processing. When you use NUMPROC(PFD), the compiler assumes that the sign in your program data is one of three 'preferred signs.' The preferred signs in COBOL are:

  • Signed positive or 0 - X'C
  • Signed negative - X'D'
  • Unsigned or alphanumeric - X'F'

Based on this assumption, the compiler uses whatever sign it is given to process data, even if the sign is incompatible with the data definition. The preferred sign is generated only where necessary (such as when signed data is moved to-an unsigned or alphanumeric data item). Using the NUMPROC(PFD) option can save a great deal of processing time, but you must be sure you use preferred signs with your data for correct processing.

When the NUMPROC(NOPFD) compiler option is in effect, the compiler accepts any valid sign configuration. When processing is done with DISPLAY or PACKED-DECIMAL data, the sign in the sending item is converted to the preferred sign before the operation is performed. The preferred sign is also generated in the receiver. NUMPROC(NOPFD) is less efficient than NUMPROC(PFD), but it should be used whenever data that does not use preferred signs may exist. In the case where an unsigned, external decimal sender is moved to an alphanumeric receiver, the sign is unchanged (even with NUMPROC(NOPFD)).

When NUMPROC(MIG) is in effect, the compiler generates code that is similar to that produced by OS/VS COBOL. This option can be especially useful as a tool when migrating; OS/VS COBOL programs to VS COBOL II. NUMPROC has no effect on binary data or floating-point data.

Incompatible Data and Numeric Class Test

The compiler assumes that the values you supply for a data item are valid for the item's PICTURE and USAGE clause and assigns the value you specify without checking for validity. When an item is given a value that is not compatible with its data description, then references to that item in the Procedure Division will be undefined and your results will be unpredictable. Frequently, values are passed into your program and assigned to items that have incompatible data descriptions for those values. For example, nonnumeric data may be moved or passed into a field in your program that is defined as a numeric item. Or, perhaps a signed number is passed into a field in your program that is defined as an unsigned number. In either case, these fields contain invalid data. It is your responsibility to ensure that the contents of a data item conform to its PICTURE and USAGE clauses before using the data item in any further processing steps. You can use the numeric class test (IF data-item IS NUMERIC.) to perform this data validation.

The numeric class test checks the contents of a data item against a set of values that are valid for the particular PICTURE and USAGE of the data item. For example, a packed decimal item would be checked for hexadecimal values X'O' through X'9' in the digit positions and for a valid sign in the sign position, as described earlier.

Execution of the numeric class test is affected by the NUMPROC compiler option and the NUMCLS installation option. Only external decimal, external floating-point, and packed decimal items are checked for sign, because binary and internal floating-point items use an 'operational' sign that is always valid.

Data Format Conversions

When the code in your program involves the interaction of numeric data items with different data formats, the compiler converts the items:

  • Temporarily, for comparisons and arithmetic operations
  • Permanently, for assignment to the receiver in a MOVE or COMPUTE statement

The conversion generally requires additional storage and processing time because data is moved to an internal work area and converted before the operation is performed. The results may have to be moved back into a work area and converted again.

A conversion is actually a move of a value from one data item to another. The compiler performs any conversions that are required during the execution of arithmetic and comparisons with the same rules that are used for MOVE and COMPUTE statements. When possible, the compiler performs the move to preserve the numeric value as opposed to a direct digit-for-digit move.

Conversions between fixed-point data formats (external decimal, packed decimal, and binary) are completed without loss of precision. The more significant conversions, where a loss of precision is possible, are those between fixed-point data formats and floating-point data formats (short floating-point, long floating-point, and external floating-point).

Numeric Data Types. Typical Uses and Conversions

Numeric Data Types. Typical Uses and Conversions

For better and efficient data conversion follow the guidelines given below:

  • Avoid Unnecessary Numeric Conversions
  • Plan the Size of Numeric Data Items
  • Align Data for Efficient Execution
  • Use De-Editing

Avoid Unnecessary Numeric Conversions

Using the USA&E clause wisely when you define the data can eliminate unnecessary data conversions. The default for a numeric item is DISPLAY. Using DISPLAY items (external decimal or external floating point) for computation is inefficient, because it requires conversion each time the data is used in a calculation. So, when defining numeric items that are used only for internal calculations, define them as BINARY or PACKED-DECIMAL; when defining floating-point items that are used only for internal calculations, define them as COMP-1 or COMP-2.

When you perform several calculations on DISPLAY (external decimal data) items or use two data items of different formats together, efficiency is increased if the data is converted once instead of several times. For example, if A is defined as a DISPLAY item and B as a PACKED-DECIMAL item, move A into a work area that has been defined as PACKED-DECIMAL whenever you will be using both items in a series of operations. When you use this technique, the conversion is performed only once, instead of each time an operation is performed.

Be careful when you are using this technique; if the value of A should change, move the new value into the work area before using it in an operation.

Plan the Size of Numeric Data Items

To avoid size errors, you need to plan the size of your numeric data items, particularly items that will hold the results of numeric calculations. The ON SIZE ERROR option is a safeguard against putting a result into an item that is too small for it. You can use it with these COBOL statements: ADD, COMPUTE, DIVIDE, MULTIPLY, and SUBTRACT. This clause does cause extra processing. When you code the ON SIZE ERROR clause, the compiler generates code to check for overflow error during execution of each arithmetic calculation with an associated ON SIZE ERROR clause. To avoid overflow errors:

  • Carefully calculate the size necessary for receiving items.
  • Just before you use them in an arithmetic calculation, test to see whether the items contain a value within the range you expected.
  • The items must be large enough to contain intermediary values that may be much larger than the answer.

Align Data for Efficient Execution

Moving numeric items is more efficient when the receiving item has the same type and number of decimal places as the sending item. Processing is most efficient when data items are alike in terms of data type, field length, position of the sign, and decimal position. Also, use of a separate sign can slow processing. Avoid it for data you're using in computations.


De-editing allows you to move a numeric-edited data item into a numeric or numeric-edited receiving data item. This is accomplished by first establishing the unedited value of the numeric-edited data item. This unedited value may be signed. The unedited numeric value is then moved to the receiving numeric data item. Suppose that a character field is being used to contain a numeric value that is displayed on the terminal, and is also being used to contain a value that the computer operator enters on the terminal. Suppose that this field has the following definition:

  • One character for a sign field, to contain a space value if the numeric field is to be positive or zero, and to contain a minus sign ('-') if the numeric field is to be negative
  • Six digit positions, in which the leading zero digits are represented by spaces
  • A decimal point ('.')
  • Two decimal digit positions

The data item used to define this field would look like:


This field could be initialized by the statement MOVE ZEROES TO NUM-EDIT and then displayed on the terminal for the user to see, and it would contain the value 'bbbbbb.OO'. Later the computer operator may use this field to enter data. Suppose that the operator entered 'bbbb123.45 into the field, and you wanted to obtain the numeric value of the field, by moving it into another data item which was defined:


The statement 'MOVE NUM-EDIT TO NUMERIC-ITEM' causes de-editing to take place, whereby the numeric value of the numeric edited field NUM-EDIT is moved into the numeric item, and the numeric item then contains the value +123.45.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

IBM Mainframe Topics