IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_AUTOOPENED')
CREATE TABLE T_ER_AUTOOPENED (
                                 FID BIGINT DEFAULT 0 NOT NULL,
                                 FGRANTSERVERS VARCHAR(50) DEFAULT ' ' NOT NULL,
                                 FCOMPANYNUM VARCHAR(255) DEFAULT ' ' NOT NULL,
                                 FCOMPANYNAME VARCHAR(255) DEFAULT ' ' NOT NULL,
                                 FAPPROVALTYPE VARCHAR(1) DEFAULT ' ' NOT NULL,
                                 FTRIPADMINUSER BIGINT DEFAULT 0 NOT NULL,
                                 FORDERSTATUSADDR VARCHAR(2000) DEFAULT ' ' NOT NULL,
                                 FCHANNELID VARCHAR(255) DEFAULT ' ' NOT NULL,
                                 FCHANNELKEYS VARCHAR(255) DEFAULT ' ' NOT NULL,
                                 FOPENEDSTATUS VARCHAR(1) DEFAULT ' ' NOT NULL,
                                 FSYNCADMINSTATUS VARCHAR(1) DEFAULT ' ' NOT NULL,
                                 FENABLESERVERS VARCHAR(1) DEFAULT ' ' NOT NULL,
                                 FBILLSTATUS VARCHAR(50) DEFAULT ' ' NOT NULL,
                                 FSYNCUSERTRACEID VARCHAR(255) DEFAULT ' ' NOT NULL,
                                 FSYNCTRACEID VARCHAR(255) DEFAULT ' ' NOT NULL
);
EXEC P_ALTERPK 'PK_T_ER_AUTOOPENED', 'T_ER_AUTOOPENED', 'FID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_AUTOOPENED_FSERVERS') CREATE INDEX IDX_AUTOOPENED_FSERVERS ON T_ER_AUTOOPENED ( FGRANTSERVERS );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_AUTOOPENED_COMPANY') CREATE INDEX IDX_AUTOOPENED_COMPANY ON T_ER_AUTOOPENED ( FCOMPANYNUM ,FCOMPANYNAME );