Data Types for DB2 under z/OS

Overview

Every column in a table has a name and a data type. The data type tells DB2 how much physical storage to set aside for the column and the form in which the data is stored. This section includes information about DB2 data types, NULL and default values, and data conversions.

For more information about DB2 data types, see your DB2 SQL reference documentation.

SAS/ACCESS does not support some types of distinct DB2 data types.

Supported Data Types for DB2 under z/OS

Here are the data types that DB2 under z/OS supports:

For more information about DB2 data types, see your DB2 documentation.

DB2 Null and Default Values

DB2 has a special value that is called NULL. A DB2 NULL value means an absence of information and is analogous to a SAS missing value. When SAS/ACCESS reads a DB2 NULL value, it interprets it as a SAS missing value.

DB2 columns can be specified so that they do not allow NULL data. For example, NOT NULL would indicate that DB2 does not allow a row to be added to the TestID.Customers table unless there is a value for CUSTOMER. When creating a DB2 table with SAS/ACCESS, you can use the DBNULL= data set option to indicate whether NULL is a valid value for specified columns.

You can also define DB2 columns as NOT NULL WITH DEFAULT. The following table lists default values that DB2 assigns to columns that you define as NOT NULL WITH DEFAULT. An example of such a column is STATE in Testid.Customers. If a column is omitted from a view descriptor, default values are assigned to the column. However, if a column is specified in a view descriptor and it has no values, no default values are assigned.

Default Values That DB2 Assigns for Columns Specified as NOT NULL WITH DEFAULT

DB2 Column Type

DB2 Default1

CHAR(n) | GRAPHIC(n)

blanks, unless the NULLCHARVAL= option is specified

VARCHAR | LONG VARCHAR | VARGRAPHIC | LONG VARGRAPHIC

empty string

BLOB | CLOB | DBCLOB

empty string

SMALLINT | INT | FLOAT | DECIMAL | REAL

0

DATE

current date, derived from the system clock

TIME

current time, derived from the system clock

TIMESTAMP

current timestamp, derived from the system clock

1 The default values that are listed in this table pertain to values that DB2 assigns.

Knowing whether a DB2 column allows NULL values or whether DB2 supplies a default value can assist you in writing selection criteria and in entering values to update a table. Unless a column is specified as NOT NULL or NOT NULL WITH DEFAULT, the column allows NULL values.

For more information about how SAS handles NULL values, see Potential Result Set Differences When Processing Null Data.

To control how the DBMS handles SAS missing character values, use the NULLCHAR= and NULLCHARVAL= data set options.

LIBNAME Statement Data Conversions

This table shows the default formats that SAS/ACCESS Interface to DB2 assigns to SAS variables when using the LIBNAME statement to read from a DB2 table. These default formats are based on DB2 column attributes.

LIBNAME Statement: Default SAS Formats for DB2 Data Types

DB2 Column Type

Default SAS Format

CHAR(n)1

VARCHAR(n)1

LONG VARCHAR

$w.

BLOB

CLOB

DBCLOB

$HEX32767.

$32767.

$w.

GRAPHIC(n)1

VARGRAPHIC(n)1

LONG VARGRAPHIC

$w.( w<=127)

$127. (w>127)

INTEGER

11.

SMALLINT

6.

DECIMAL(m,n)2

w+2.d

FLOAT

none

DOUBLE PRECISION

none

REAL

none

NUMERIC(m,n)2

w+2.d

DATE

DATE9.

TIME

TIME8.

TIMESTAMP

DATETIME30.6

ROWID

none

1 n in DB2 character and graphic data types is equivalent to w in SAS formats.
2 m and n in DB2 numeric data types are equivalent to w and d in SAS formats.

This table shows the default DB2 data types that SAS/ACCESS assigns to SAS variable formats during output operations.

LIBNAME Statement: Default DB2 Data Types for SAS Variable Formats

SAS Variable Format

DB2 Data Type

$w.

$CHARw.

$VARYINGw.

$HEXw.

CHARACTER(n) for 1–2551

VARCHAR(n) for >2551

any date format

DATE

any time format

TIME

any datetime format

TIMESTAMP

all other numeric formats

FLOAT

1 n in DB2 character and graphic data types is equivalent to w in SAS formats.

ACCESS Procedure Data Conversions

This table shows the default SAS variable formats that SAS/ACCESS assigns to DB2 data types when you use the ACCESS procedure.

ACCESS Procedure: Default SAS Formats for DB2 Data Types

DB2 Column Type

Default SAS Format

CHAR(n)

$w. (w<=199)1

VARCHAR(n)

$w.

$200. (w>200)1

LONG VARCHAR

$w.

BLOB

CLOB

DBCLOB

none

none

none

GRAPHIC(n)

VARGRAPHIC(n)

LONG VARGRAPHIC

$w. ( w<=127)1

$127. (w>127)1

INTEGER

11.

SMALLINT

6.

DECIMAL(m,n)

w+2.d

For example, DEC(6,4) becomes SAS format 8.4

REAL

E12.

DOUBLE PRECISION

E12.

FLOAT(n)

E12.

FLOAT

E12.

NUMERIC(m,n)

w+2.d2

For example, NUMERIC(6,2) becomes SAS format 8.2

DATE

DATE7.

TIME

TIME8.

TIMESTAMP

DATETIME30.6

1 n in DB2 character and graphic data types is equivalent to w in SAS formats.
2 m and n in DB2 numeric data types are equivalent to w and d in SAS formats.

You can use the YEARCUTOFF= option to make your DATE7. dates comply with Year 2000 standards. For more information about this SAS system option, see SAS System Options: Reference.

DBLOAD Procedure Data Conversions

This table shows the default DB2 data types that SAS/ACCESS assigns to SAS variable formats when you use the DBLOAD procedure.

DBLOAD Procedure: Default DB2 Data Types for SAS Variable Formats

SAS Variable Format

DB2 Data Type

$w.

$CHARw.

$VARYINGw.

$HEXw.

CHARACTER(n)

any date format

DATE

any time format

TIME

any datetime format

TIMESTAMP

w.d

IB, IBR, PIB, PIBR

all other numeric formats

DECIMAL(m,n)1

INTEGER

FLOAT

1 m and n in DB2 numeric data types are equivalent to w and d in SAS formats.
Last updated: February 3, 2026