Numeric character data

A numeric character data item is the value of a variable that has been declared with the PICTURE attribute with a numeric picture specification. The data item is the character representation of a decimal fixed-point or floating-point value.

Numeric picture specification describes a character string that can be assigned only data that can be converted to an arithmetic value.

Consider the following example:

  declare Price picture '999V99';

This declare specifies that any value assigned to Price is maintained as a character string of five decimal digits, with an assumed decimal point preceding the rightmost two digits. Data assigned to Price is aligned on the assumed point in the same way that point alignment is maintained for fixed-point decimal data.

Numeric character data has arithmetic attributes, but it is not stored in coded arithmetic form. Numeric character data is stored as a character string. Before it can be used in arithmetic computations, it must be converted either to decimal fixed-point or to decimal floating-point format. Such conversions are done automatically, but they require extra processing time.

Although numeric character data is in character form, like character strings, and although it is aligned on the decimal point like coded arithmetic data, it is processed differently from the way either coded arithmetic items or character strings are processed. Editing characters can be specified for insertion into a numeric character data item, and such characters are actually stored within the data item. Consequently, when the item is printed or treated as a character string, the editing characters are included in the assignment operation. However, if a numeric character item is assigned to another numeric character or arithmetic variable, the editing characters are not included in the assignment operation—only the actual digits, signs, and the location of the assumed decimal point are assigned. Consider the following example:

  declare Price picture '$99V.99',
          Cost character (6),
          Amount fixed decimal (6,2);
  Price = 12.28;
  Cost = '$12.28';

In the picture specification for PRICE, the currency symbol ($) and the decimal point (.) are editing characters. They are stored as characters in the data item. However, they are not a part of its arithmetic value. After both assignment statements are executed, the actual internal character representation of Price and Cost can be considered identical. If they were printed, they would print exactly the same; but they do not always function in the same way. Consider the following example:

  Amount = Price;
  Cost   = Price;
  Amount = Cost;
  Price  = Cost;

After the first two assignment statements are executed, the value of Amount is 0012.28 and the value of Cost is '$12.28'. In the assignment of Price to Amount, the currency symbol and the decimal point are editing characters, and they are not part of the assignment. The numeric value of Price is converted to internal coded arithmetic form. In the assignment of Price to Cost, however, the assignment is to a character string, and the editing characters of a numeric picture specification always participate in such an assignment. No conversion is necessary because Price is stored in character form.

The third and fourth assignment statements would raise the CONVERSION condition. The value of Cost cannot be assigned to Amount because the currency symbol in the string makes it invalid as an arithmetic constant. The value of Cost cannot be assigned to Price for the same reason. Only values that are of arithmetic type, or that can be converted to arithmetic type, can be assigned to a variable declared with a numeric picture specification.

Although the decimal point can be an editing character or an actual character in a character string, it does not raise the CONVERSION condition in converting to arithmetic form, because its appearance is valid in an arithmetic constant. The same is true for a valid plus or minus sign, because converting to arithmetic form provides for a sign preceding an arithmetic constant.

Other editing characters, including zero suppression characters, drifting characters, and insertion characters, can be used in numeric picture specifications.