[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP BASIC for OpenVMS
User Manual


Previous Contents Index

21.7 CDD/Repository Variants

A variant comprises two or more fields of a record that provide alternative descriptions for the same portion of a record.

The following is an example of a CDDL data definition containing variant fields and the corresponding HP BASIC RECORD statement:

CDDL Definition


define record CDD$top.basic.variant_example
    description is

        /* test simple variant */.
    variant_example structure.
        my_string datatype text size 9.
        variants.
            variant.
                my_s_real       datatype        f_floating.
                my_d_real       datatype        d_floating.
            end variant.
            variant.
                my_g_real       datatype        g_floating.
                my_h_real       datatype        h_floating.
            end variant.
        end variants.
                my_byte         datatype        signed byte.
   end variant_example structure.
end variant_example.

Translated RECORD Statement


     1          %INCLUDE %FROM %CDD "CDD$TOP.BASIC.VARIANT_EXAMPLE"
        C1              !   test simple variant
        C1              RECORD  VARIANT_EXAMPLE            ! UNSPECIFIED
        C1                STRING  MY_STRING  = 9           ! TEXT
        C1                VARIANT
        C1                CASE
        C1                  SINGLE  MY_S_REAL              ! F_FLOATING
        C1                  DOUBLE  MY_D_REAL              ! D_FLOATING
        C1                CASE
        C1                  GFLOAT  MY_G_REAL              ! G_FLOATING
        C1                  HFLOAT  MY_H_REAL              ! H_FLOATING
        C1                END VARIANT
        C1                BYTE    MY_BYTE                  ! SIGNED BYTE
        C1              END RECORD

CDD/Repository data definitions sometimes contain VARIANTS OF field description statements as well as simple variants. A CDDL or CDO VARIANTS OF statement names a tag variable whose value at run time determines which of the variant fields is the current variant. HP BASIC does not support the VARIANTS OF statement. If a CDD/Repository data definition containing a VARIANTS OF statement is extracted, HP BASIC signals the informational message, "<number> tag value from CDD/Repository ignored" and treats the VARIANTS OF as an ordinary variant and ignores the tag value.

21.8 NAME FOR BASIC Clause

HP BASIC supports the CDDL and CDO field attribute clause NAME FOR BASIC.

The field attribute clause NAME FOR BASIC declares a facility-specific name for a field. For example:


name for basic is "subject_name$"

When you assign a name using the NAME FOR BASIC clause in a CDDL or CDO data definition, HP BASIC recognizes only this name when you refer to the field. Note that when you use the NAME FOR BASIC clause, you can place dollar sign ($) and percent sign (%) suffixes in your RECORD statement field names.

The following example is a CDDL data definition containing the NAME FOR BASIC clause and the corresponding HP BASIC RECORD statement.

CDDL Definition


define record city_study
    description is

       /* This example formats data resulting from a
       study on the relationship between place of birth
       and earning potential */.
    info structure.
        subject_name                    datatype text size 10
                                        name for basic is "subject_name$".
        birth_city                      datatype text size 10
                                        name for basic is "city_of_birth$".
        salary                          datatype signed byte
                                        name for basic is "salary%".
    end info structure.
end city_study.

Translated RECORD Statement


1          %INCLUDE %FROM %CDD "CDD$TOP.BASIC.CITY_STUDY"
   C1              !   This example formats data resulting from a
   C1              !   study on the relationship between place of birth
   C1              !   and earning potential
   C1              RECORD  INFO                       ! UNSPECIFIED
   C1                STRING  SUBJECT_NAME$  = 10      ! TEXT
   C1                STRING  CITY_OF_BIRTH$  = 10     ! TEXT
   C1                BYTE    SALARY%                  ! SIGNED BYTE
   C1              END RECORD

Caution

The NAME FOR BASIC clause enables you to assign completely different names to the same field.

For more information about the CDDL NAME FOR BASIC field attribute clause, see the CDD/Repository documentation.

21.9 CDD/Repository Data Types

HP BASIC supports a subset of CDD/Repository data types, as shown in Table 21-1.

Table 21-1 Supported CDD/Repository Data Types
Data Type HP BASIC Translation
TEXT STRING
SIGNED BYTE BYTE
SIGNED WORD WORD
SIGNED LONGWORD LONG
F_FLOATING SINGLE
D_FLOATING DOUBLE
G_FLOATING GFLOAT
PACKED DECIMAL DECIMAL

If a CDD/Repository data definition containing an unsupported data type is extracted, HP BASIC signals the informational message "Datatype in CDD/Repository not supported, substituted group for: <field-name>" and translates the data type by creating a group to contain the data type field. The group name is the name of the unsupported data type followed by the text "_VALUE". This allows you to access the field name within the group.

An example of how HP BASIC translates unsupported CDD/Repository data types is shown in the following CDDL data definition and corresponding HP BASIC RECORD statement:

CDDL Definition


define record CDD$top.basic.stock
        description is
           /* this is an example data definition that contains
           data types not supported by HP BASIC */.

        stock structure.
                product_no      datatype is text
                                size is 8 characters.
                date_ordered    datatype is date.
                status_code     datatype is unsigned byte.
                quantity        datatype is unsigned longword
                                aligned on longword.
                location        array 1:4
                                datatype is text
                                size is 30 characters.
                unit_price      datatype is longword.
       end stock structure.
end stock.

Translated RECORD Statement


     1          %INCLUDE %FROM %CDD "CDD$TOP.BASIC.STOCK"
        C1              !  This is an example data definition that contains
        C1              !  data types not supported by HP BASIC
        C1              RECORD  STOCK                      ! UNSPECIFIED
        C1                STRING  PRODUCT_NO  = 8          ! TEXT
        C1                GROUP   DATE_ORDERED             ! DATE
        C1                  STRING  STRING_VALUE  = 8
        C1                END GROUP
        C1                GROUP   STATUS_CODE              ! UNSIGNED BYTE
        C1                  BYTE    BYTE_VALUE
        C1                END GROUP
        C1                STRING  FILL = 3
        C1                GROUP   QUANTITY                 ! UNSIGNED LONGWORD
        C1                  LONG    LONG_VALUE
        C1                END GROUP
        C1                STRING  LOCATION(1 TO 4) = 30    ! TEXT
        C1                GROUP   UNIT_PRICE               ! UNSIGNED LONGWORD
        C1                  LONG    LONG_VALUE
        C1                END GROUP
        C1              END RECORD
%BASIC-I-CDDSUBGRO,           data type in CDD/Repository not supported,
                substituted group for: STOCK::DATE_ORDERED.
%BASIC-I-CDDSUBGRO,           data type in CDD/Repository not supported,
                substituted group for: STOCK::STATUS_CODE.
%BASIC-I-CDDSUBGRO,           data type in CDD/Repository not supported,
                substituted group for: STOCK::QUANTITY.
%BASIC-I-CDDSUBGRO,           data type in CDD/Repository not supported,
                substituted group for: STOCK::UNIT_PRICE.

Table 21-2 describes CDD/Repository data types not supported by HP BASIC and their translation.

Table 21-2 Unsupported CDD/Repository Data Types
Data Type HP BASIC Translation
UNSIGNED BYTE GROUP CDD/Repository-field-name
BYTE BYTE_VALUE
END GROUP
UNSIGNED WORD GROUP CDD/Repository-field-name
WORD WORD_VALUE
END GROUP
UNSIGNED LONGWORD GROUP CDD/Repository-field-name
LONG LONG_VALUE
END GROUP
SIGNED QUADWORD GROUP CDD/Repository-field-name
STRING STRING_VALUE = 8
END GROUP
UNSIGNED QUADWORD GROUPCDD/Repository-field-name
STRING STRING_VALUE = 8
END GROUP
SIGNED OCTAWORD GROUP CDD/Repository-field-name
STRING STRING_VALUE = 16
END GROUP
UNSIGNED OCTAWORD GROUP CDD/Repository-field-name
STRING STRING_VALUE = 16
END GROUP
H_FLOATING GROUP CDD/Repository-field-name
STRING STRING_VALUE = 16
END GROUP
F_FLOATING COMPLEX GROUP CDD/Repository-field-name
SINGLE SINGLE_R_VALUE
SINGLE SINGLE_I_VALUE
END GROUP
D_FLOATING COMPLEX GROUP CDD/Repository-field-name
DOUBLE DOUBLE_R_VALUE
DOUBLE DOUBLE_I_VALUE
END GROUP
G_FLOATING COMPLEX GROUP CDD/Repository-field-name
GFLOAT GFLOAT_R_VALUE
GFLOAT GFLOAT_I_VALUE
END GROUP
H_FLOATING COMPLEX GROUP CDD/Repository-field-name
HFLOAT HFLOAT_R_VALUE
HFLOAT HFLOAT_I_VALUE
END GROUP
ZONED NUMERIC GROUP CDD/Repository-field-name
STRING STRING_VALUE = length
END GROUP
UNSIGNED NUMERIC GROUP CDD/Repository-field-name
STRING STRING_VALUE = length
END GROUP
LEFT SEPARATE NUMERIC GROUP CDD/Repository-field-name
STRING STRING_VALUE = length + 1
END GROUP
LEFT OVERPUNCHED
NUMERIC
GROUP CDD/Repository-field-name
STRING STRING_VALUE = length
END GROUP
RIGHT SEPARATE NUMERIC GROUP CDD/Repository-field-name
STRING STRING_VALUE = length + 1
END GROUP
RIGHT OVERPUNCHED
NUMERIC
GROUP CDD/Repository-field-name
STRING STRING_VALUE = length
END GROUP
VARYING STRING GROUP CDD/Repository-field-name
WORD WORD_VALUE
STRING STRING_VALUE = length
END GROUP
BIT 1 GROUP CDD/Repository-field-name
STRING STRING_VALUE = length /8
END GROUP
DATE GROUP CDD/Repository-field-name
STRING STRING_VALUE = 8
END GROUP
POINTER GROUP CDD/Repository-field-name
LONG LONG_VALUE
END GROUP
UNSPECIFIED GROUP CDD/Repository-field-name
STRING STRING_VALUE = length
END GROUP
VIRTUAL FIELD Ignored

1CDD/Repository specifies bit field length in bits; HP BASIC specifies string length in bytes. If the length in bits does not divide evenly into bytes, HP BASIC signals the error "Field <fieldname> from CDD/Repository has bit offset or length."

The following sections describe how HP BASIC translates CDD/Repository data types.

21.9.1 Character String Data Types

There are two CDD/Repository character string data types, TEXT and VARYING STRING. The TEXT data type translates directly into the HP BASIC STRING data type. VARYING STRING is not a supported HP BASIC data type; therefore, HP BASIC creates a group to contain the field.

The following example is a CDD/Repository definition that contains both the TEXT and VARYING STRING data types and the translated HP BASIC RECORD statement:

Example 21-1 CDDL

define record CDD$top.basic.strings
    description is

        /* test */.

    basicstrings structure.
        abc         datatype is text size is 10.
        xyz         datatype is varying string size is 16.
    end basicstrings structure.
end strings.

Example 21-2 Translated RECORD Statement

     1          %INCLUDE %FROM %CDD "CDD$TOP.BASIC.STRINGS"
        C1              !   test
        C1              RECORD  BASICSTRINGS               ! UNSPECIFIED
        C1                STRING  ABC  = 10                ! TEXT
        C1                GROUP   XYZ                      ! VARYING STRING
        C1                  WORD    WORD_VALUE
        C1                  STRING  STRING_VALUE  = 16
        C1                END GROUP
        C1              END RECORD
................1
%BASIC-I-CDD/SUBGRO, 1:        data type in CDD/Repository not supported,
                substituted group for: BASICSTRINGS::XYZ.

In the VARYING STRING data type, the actual character string is preceded by a 16-bit count field. Therefore, HP BASIC creates a WORD variable to hold the specified string length.

Note

The count field preceding the VARYING STRING is actually an UNSIGNED WORD. Therefore, the count field of a VARYING STRING whose length is greater than 32,767 is interpreted by HP BASIC as a negative number.

In the previous example, the group name (XYZ) is the same name as a CDD/Repository field. Therefore, HP BASIC supplies an additional name for the RECORD components. The supplied names are WORD_VALUE and STRING_VALUE. For example, the following program statement creates an instance of the record BASICSTRINGS, called MY_REC:


100      MAP (TEST) BASICSTRINGS MY_REC

The names you use to reference these components in HP BASIC are MY_REC::XYZ::WORD_VALUE and MY_REC::XYZ::STRING_VALUE.

21.9.2 Integer Data Types

CDD/Repository refers to integer data types as fixed-point data types. CDD/Repository supports BYTE, WORD, LONGWORD, QUADWORD, and OCTAWORD integer data types. Each of these data types can have the following additional attributes:

SIGNED
UNSIGNED
SIZE
DIGITS
FRACTION


BASE
SCALE

In CDDL, if integer data types are not specified as being signed or unsigned, the default is unsigned. HP BASIC supports only signed BYTE, signed WORD, signed LONGWORD, and signed QUADWORD integers. If a CDD/Repository data definition containing an unsigned BYTE, WORD, LONGWORD, or QUADWORD integer is extracted, HP BASIC signals the informational message "Datatype in CDD/Repository not supported, substituted group for: <field-name>," and creates a group to contain the field. Because the group name is the same as the CDD/Repository field name, HP BASIC assigns a new name to the field. This is shown in the following CDDL data definition and corresponding HP BASIC RECORD statement:

CDDL Definition


define record CDD$top.basic.integers
    description is

       /*Test of selected integer data types*/.
    basicint structure.
        my_byte         datatype is signed byte.
        my_ubyte        datatype is byte.
        my_word         datatype is signed word.
        my_uword        datatype is unsigned word.
        my_long         datatype is signed longword.
        my_ulong        datatype is unsigned longword.
    end basicint structure.
end integers.

Translated RECORD Statement


     1          %INCLUDE %FROM %CDD "CDD$TOP.BASIC.INTEGERS"
        C1              !  Test of selected integer data types
        C1              RECORD  BASICINT                   ! UNSPECIFIED
        C1                BYTE    MY_BYTE                  ! SIGNED BYTE
        C1                GROUP   MY_UBYTE                 ! UNSIGNED BYTE
        C1                  BYTE    BYTE_VALUE
        C1                END GROUP
        C1                WORD    MY_WORD                  ! SIGNED WORD
        C1                GROUP   MY_UWORD                 ! UNSIGNED WORD
        C1                  WORD    WORD_VALUE
        C1                END GROUP
        C1                LONG    MY_LONG                  ! SIGNED LONGWORD
        C1                GROUP   MY_ULONG                 ! UNSIGNED LONGWORD
        C1                  LONG    LONG_VALUE
        C1                END GROUP
        C1              END RECORD
................1
%BASIC-I-CDDSUBGRO, 1:        data type in CDD/Repository not supported,
                substituted group for: BASICINT::MY_UBYTE.
%BASIC-I-CDDSUBGRO, 1:        data type in CDD/Repository not supported,
                substituted group for: BASICINT::MY_UWORD.
%BASIC-I-CDDSUBGRO, 1:        data type in CDD/Repository not supported,
                substituted group for: BASICINT::MY_ULONG.

When the previous data definition is extracted from CDD/Repository, HP BASIC signals an informational message for each of the unsigned data types, and names the CDD/Repository unsigned byte field BYTE_VALUE, the CDD/Repository unsigned word field WORD_VALUE, and the CDD/Repository unsigned longword field LONG_VALUE.

HP BASIC does not support OCTAWORD integers. If a CDD/Repository definition contains an OCTAWORD integer, HP BASIC signals the informational message "Datatype in CDD/Repository not supported, substituted group for: <field-name>" and creates a group to contain the field and a string component within the group. The string component is 16 bytes for OCTAWORD integers. For example:

CDDL Definition


define record CDD$top.basic.bigintegers
    description is

        /*Test of quadword and octaword integer data types*/.

    basicint structure.
        my_quad         datatype is signed quadword.
        my_octa         datatype is signed octaword.
    end basicint structure.
end bigintegers.

Translated RECORD Statement


     1          %INCLUDE %FROM %CDD "CDD$TOP.BASIC.BIGINTEGERS"
        C1              !  Test of quadword and octaword integer data types
        C1              RECORD  BASICINT                   ! UNSPECIFIED
        C1                QUAD   MY_QUAD                   ! SIGNED QUADWORD
        C1                GROUP   MY_OCTA                  ! SIGNED OCTAWORD
        C1                  STRING  STRING_VALUE  = 16
        C1                END GROUP
        C1              END RECORD
%BASIC-I-CDDSUBGRO,           data type in CDD/Repository not supported,
                substituted group for: BASICINT::MY_OCTA.

CDD/Repository supports the SCALE keyword to specify an implied exponent in integer data types, and the BASE keyword (supported in CDDL only) to specify that the scale for a fixed-point field is to be interpreted in a numeric base other than 10. HP BASIC does not support these integer attributes. Therefore, HP BASIC signals the informational message "CDD/Repository specifies SCALE for <name>. Not supported" for fixed-point fields containing a SCALE specification, and the error message "CDD/Repository attributes for <name> are other than base 10" for fixed-point fields specifying a base other than 10. For example:

CDDL Definition


define record CDD$top.basic.funnyintegers
    description is

        /* Test of quadword and octaword integer data types */.

    basicint structure.
        my_byte         datatype is signed byte scale 2.
        my_long         datatype is signed longword base 8.
    end basicint structure.
end funnyintegers.

Translated RECORD Statement


     1          %INCLUDE %FROM %CDD "CDD$TOP.BASIC.FUNNYINTEGERS"
        C1              !   Test of quadword and octaword integer data types
        C1              RECORD  BASICINT                   ! UNSPECIFIED
        C1                GROUP   MY_BYTE                  ! SIGNED BYTE
        C1                  BYTE    BYTE_VALUE
        C1                END GROUP
        C1                LONG    MY_LONG                  ! SIGNED LONGWORD
        C1              END RECORD
%BASIC-I-CDDATTSCA,     CDD specifies SCALE for BASICINT::MY_BYTE. Not supported
%BASIC-E-CDDATTBAS,     CDD attributes for BASICINT::MY_LONG are other than base 10

At compilation time, HP BASIC also signals these warning errors for each reference to fields that are not base 10 or that have a SCALE.


Previous Next Contents Index