CONVERT Phrase

WITH {CONVERSION}
     {CONVERT   }
  1. Specifying the CONVERT phrase allows non-USAGE DISPLAY items to be accepted or displayed. It also allows for automatic conversion of entered data into the internal format of the destination field.
  2. In a DISPLAY statement, the CONVERT phrase affects only numeric and numeric edited data items. For numeric data items, leading zeros are converted into spaces, a decimal point is inserted (if needed), and a leading minus sign is inserted (if the value is negative). The result is then left-justified if RM/COBOL compatibility mode is being used. Numeric edited items are not converted, but they are justified in the same manner as numeric items. This form of the CONVERT phrase is called output conversion.

    Floating-point data items are converted from internal format to E-notation. The format of E-notation is as follows:

    • FLOAT items have eight digits, one of which is before the decimal point.
    • DOUBLE items have 17 digits, one of which is before the decimal point.
    • A leading sign is shown for negative values, otherwise there is a leading space.
    • The exponent is shown as an "E", followed by a sign if negative, followed by one or more digits.
    • The decimal point is shown using the program's current decimal point character.
  3. In an ACCEPT statement, the action of the CONVERT phrase depends on the data type of the receiving field:
    1. A nonnumeric field receives the entered data as if it were the destination of a MOVE statement with an alphanumeric source. This causes justification and editing to have their normal effect.
    2. A numeric or numeric edited field causes the ACCEPT statement to first check the data for correctness. Legal characters for numeric items include any characters that can appear in a numeric edited data item (digits, plus and minus sign, period, comma, currency symbol, CR, DB, "/", and "*"). Characters that are legal but have no meaning in an arithmetic literal are simply ignored (space, "*", "/", currency symbol, currency comma). Any other non-space character is an error. Legal values are then assigned to the receiving field such that the algebraic value remains the same.
    3. The input format for floating-point numbers consists of the following components in the order given:
      • An optionally signed string of digits (possibly containing a decimal point)
      • An optional exponent field consisting of:
        1. "E" or "e"
        2. an optional + or -
        3. an integer

        See Numeric Literals for more information.

  4. If the CONVERT phrase is not specified, the accepted data is placed in the receiving field from left to right with no editing or justification. In RM/COBOL compatibility mode, however, a numeric receiving field causes the data to be assigned from right to left instead.
  5. For entries in the Screen Section, conversion is automatically used during input and not used during output. For this reason, Screen Section entries for non-integer numeric fields should specify a numeric edited PICTURE so that the decimal point is visible. Likewise, signed numeric fields should either specify SIGN SEPARATE or be represented by numeric edited items. Note that conversion occurs automatically for all controls that reference numeric, numeric edited, right justified, or wide character data.
  6. If a conversion error occurs, the runtime system prints an error message and forces the user to correct the field. This behavior can be modified. See The KEYBOARD Variable for more information.
  7. Several compile-time and run-time options are available to change various aspects of the CONVERT phrase, including the behavior of conversion errors and justification of the output of numeric items. See Video Options and The SCREEN Option in the ACUCOBOL-GT User's Guide for more information.