CDO$HELP.HLB  —  fld-properties  COMPUTED_BY
    Format

                   { value-expr                                       }
                   { IF cond-expr THEN value-expr [ ELSE value-expr ] }
      COMPUTED BY  { NULLIF ( value-expr, value-expr )                }
                   {                                                  }
                   { COALESCE ( value-expr [ , value-expr ]  ... )    }

1  –  Parameters

1.1  –  value-expr

    Specifies an expression a product can use to calculate a field's
    value. See Expressions for more information on value expressions.

1.2  –  cond-expr

    Specifies an expression that represents the relationship between
    two value expressions. See Expressions for more information on
    conditional expressions.

2  –  Description

    The COMPUTED BY field property evaluates an expression, allowing
    a product that uses CDO to determine the value of a field at
    runtime.

    The expression must be a valid CDO expression. CDO checks the
    expression for correct syntax and field references.

    The product must be able to interpret the CDO expression.

    When you specify a conditional expression in the COMPUTED BY
    field property, you can define a field that is equivalent to a
    COBOL level 88 condition. The computed by expression must be in
    one of the following forms:

    o  if [name EQ literal1] THEN 1 ELSE 0

    o  if [(name GE literal1 AND name LE literal2) OR (name GE
       literal3 AND name LE literal4)]... THEN 1 ELSE 0

    Use NULL IF to substitute NULL when two value expressions are
    equal.

    Use COALESCE to return the first non-NULL value from a series of
    value expressions.

    There is a limited subset of valid COMPUTED BY fields that are
    acceptable in COBOL syntax for inclusion through the COPY FROM
    DICTIONARY clause. They have the following format:

    COMPUTED BY IF expression THEN 1 ELSE 0

    Where expression is:

    {                                                   }
    {            { number }                             }
    { fld-name = {        }                             }
    {            { string }                             }
    {                                                   } OR ...
    {             { number }                 { number } }
    { fld-name GE {        } AND fld-name LE {        } }
    {             { string }                 { string } }
    {                                                   }

    For example, the following COMPUTED BY fields are defined:

    DEFINE FIELD Y_TRUE
         COMPUTED BY IF (Y = "TRUE") THEN 1 ELSE 0.
    DEFINE FIELD Z_NULL
        COMPUTED BY IF (Z = 0) THEN 1 ELSE 0.
    DEFINE FIELD W_ALPHABETIC COMPUTED BY
        IF ((W GE "A") AND (W LE "Z")) OR ((W GE "a") AND (W LE "z"))
        THEN 1 ELSE 0.
    DEFINE FIELD X_3_DIGITS
        COMPUTED BY IF (X GE 100) AND (X LE 999) THEN 1 ELSE 0.

    They are translated as the following COBOL level 88 conditions:

    02 Y ...
       88 Y_TRUE VALUE IS "TRUE".
    02 Z ...
       88 Z_NULL VALUE IS 0.
    02 W ...
       88 W_ALPHABETIC VALUES ARE "A" THRU "Z", "a" THRU "z".
    02 X ...
     88 X_3_DIGITS VALUES ARE 100 THRU 999.

                               RESTRICTION

       The COMPUTED BY field property can reference only one field.
       The fld-name parameter must be the same field name in all
       instances. When included in COBOL, the COMPUTED BY field
       will be translated as a level 88 condition associated with
       the field that was referenced.

3  –  Examples

    1.CDO>  DEFINE FIELD SUBTOTAL_PRICE
      cont>   COMPUTED BY UNIT_PRICE * QUANTITY.

      In this example, the DEFINE FIELD command includes the COMPUTED
      BY property to calculate a value for the SUBTOTAL_PRICE field
      element. The value is computed by multiplying UNIT_PRICE by
      QUANTITY.

    2.CDO>  DEFINE FIELD TOTAL_PRICE
      cont>   COMPUTED BY UNIT_PRICE (3) * 10.

      In this example, the DEFINE FIELD command includes a COMPUTED
      BY property to calculate a value for the TOTAL_PRICE field
      element. The value is calculated by multiplying the value in
      the third instance of the UNIT_PRICE field element by 10.

    3.CDO>  CHANGE FIELD TOTAL_PRICE
      cont>   NOCOMPUTED BY.

      In this example, the CHANGE FIELD command includes the
      NOCOMPUTED BY keywords to remove the COMPUTED BY property from
      the TOTAL_PRICE field element.

    4.CDO>  DEFINE FIELD C
      cont>   DATATYPE SIGNED WORD.
      CDO>  DEFINE FIELD C_ONE
      cont>   COMPUTED BY IF C EQ 1 THEN 1 ELSE 0.
      CDO>  DEFINE FIELD C_FIVE_TEN
      cont>   NAME FOR COBOL IS C_5_10
      cont>   COMPUTED BY IF C GE 5 AND C LE 10 THEN 1 ELSE 0.
      CDO>  DEFINE FIELD C_OTHER
      cont>   COMPUTED BY
      cont>   IF (C GE 2 AND C LE 4)
      cont>   OR (C GE 11 AND C LE 20)
      cont>   THEN 1 ELSE 0.
      CDO> DEFINE RECORD COB88.
      cont> C.
      cont> C_ONE.
      cont> C_FIVE_TEN.
      cont> C_OTHER.
      cont> END RECORD.

      In this example, the DEFINE FIELD commands include COMPUTED BY
      properties that contain conditional and value expressions.
      These expressions are related to the value of the C field
      element, as follows:

      o  The C_ONE field element takes the value of one (if C
         evaluates to one) or zero.

      o  The C_FIVE_TEN field element takes the value of one (if C
         evaluates to a value between five and ten) or zero.

      o  The C_OTHER field element takes the value of one (if C
         evaluates to a value between two and four or if C evaluates
         to a value between eleven and twenty) or zero.

    5.01  COB88.
          03  C                 USAGE IS COMP PIC 9(4).
             88  C_ONE          VALUE 1.
             88  C_FIVE_TEN     VALUES ARE 5 THRU 10.
             88  C_OTHER        VALUES ARE 2 THRU 4
                                11 THRU 20.

      This example shows COBOL syntax for the record containing level
      88 definitions.
Close Help