Ask the Expert

Making a file with an automatic key in iSeries with DDS keyword

I need a file with an automatic key in it on the iSeries. I know you can create one using SQL but is there a keyword in DDS that can be used for this? Would I have to use the following code in an RPGLESQL program to do this?

CREATE TABLE invoice_data
(invoice# INTEGER NOT NULL
GENERATED ALWAYS AS IDENTITY
(START WITH 1
,INCREMENT BY 1
,NO MAXVALUE
,NO CYCLE
,ORDER)
,sale_date DATE NOT NULL
,customer_id CHAR(20) NOT NULL
,product_id INTEGER NOT NULL
,quantity INTEGER NOT NULL
,price DECIMAL(18,2) NOT NULL
,PRIMARY KEY (invoice#));

The Identity column attribute is only available to SQL-created tables. However, the good news is that although there's no DDS support, any native writes performed against an SQL table created with an identity table will result in DB2 generating identity values. Any SQL table created with an identity column will generate identity values for both SQL and non-SQL I/O interfaces.

This was first published in May 2008