Previous Topic Next topic Print topic


Data Types and Conversion

Each variable must be declared to have a data type. Except for cases under control of the DEFAULT statement, failure to specify a data type causes the Compiler to issue a warning and to give the variable a data type of Fixed Binary(15) if its name begins with any of the letters I through N; otherwise, the variable is given a data type of Float Decimal(6).

A complete discussion of data types is contained in the chapter Data Types. The following examples show several data types available in Open PL/I.

Examples:

DECLARE A FLOAT DECIMAL(7); 
DECLARE N FIXED BINARY(15); 
DECLARE C CHARACTER(30); 
DECLARE B BIT(1);

In these examples, variable A is capable of holding any floating-point decimal value with mantissa of up to 7 digits and exponent of up to 3 digits; variable N is capable of holding any binary integer value between -32768 and +32767 inclusive; variable C is capable of holding any string of 30 characters; and variable B is capable of holding either '1'B or '0'B.

Although each variable is capable of holding values of only a specific data type, the Open PL/I language provides a complete set of operations that convert values from one data type to another. Whenever a value is assigned to a variable, it is first converted to the data type of the variable, as illustrated in the following examples (which refer to the declarations in the previous examples).

Examples:

A = 1; /* converts 1 to FLOAT DECIMAL(7) */
N = 2.5; /* converts 2.5 to the FIXED BIN(15) integer 2 */
C = -4.5; /* converts -4.5 to a character string */
B = 0; /* converts integer 0 to '0'B */

For a complete discussion of data type conversions, see the chapter Data Type Conversions.

Previous Topic Next topic Print topic