/**Begin D:\nextcloud\dev2main2bizline\PDM_UPGRADE\pdm1\BASE_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_INV_PER_BAL') 
 CREATE TABLE T_IM_INV_PER_BAL (
FID BIGINT DEFAULT 0 NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL,
FWAREHOUSEID BIGINT DEFAULT 0 NOT NULL,
FLOCATIONID BIGINT DEFAULT 0 NOT NULL,
FOWNERTYPE VARCHAR(20) DEFAULT ' ' NOT NULL,
FOWNERID BIGINT DEFAULT 0 NOT NULL,
FKEEPERTYPE VARCHAR(20) DEFAULT ' ' NOT NULL,
FKEEPERID BIGINT DEFAULT 0 NOT NULL,
FINVSTATUSID BIGINT DEFAULT 0 NOT NULL,
FFINVTYPEID BIGINT DEFAULT 0 NOT NULL,
FMATERIALID BIGINT DEFAULT 0 NOT NULL,
FAUXPTYID BIGINT DEFAULT 0 NOT NULL,
FLOTNUMBER VARCHAR(50) DEFAULT ' ' NOT NULL,
FPROJECTID BIGINT DEFAULT 0 NOT NULL,
FPRODUCEDATE DATETIME,
FEXPIRYDATE DATETIME,
FUNITID BIGINT DEFAULT 0 NOT NULL,
FBASEUNIT BIGINT DEFAULT 0 NOT NULL,
FUNIT2NDID BIGINT DEFAULT 0 NOT NULL,
FPERIOD INT DEFAULT 0 NOT NULL,
FENDPERIOD INT DEFAULT 0 NOT NULL,
FQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY2ND DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY_IN DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBASEQTY_IN DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY2ND_IN DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY_OUT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBASEQTY_OUT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY2ND_OUT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY_BAL DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBASEQTY_BAL DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY2ND_BAL DECIMAL(23,10) DEFAULT 0 NOT NULL,
FKEYCOL VARCHAR(50) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_INV_PER_BAL_SP') 
 CREATE TABLE T_IM_INV_PER_BAL_SP (
FID BIGINT DEFAULT 0 NOT NULL,
FPERIOD INT DEFAULT 0 NOT NULL,
FQTY_SP DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBASEQTY_SP DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY2ND_SP DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY_IN_SP DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBASEQTY_IN_SP DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY2ND_IN_SP DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY_OUT_SP DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBASEQTY_OUT_SP DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY2ND_OUT_SP DECIMAL(23,10) DEFAULT 0 NOT NULL,
FKEYCOL VARCHAR(50) DEFAULT ' ' NOT NULL,
FBILLNAME VARCHAR(50) DEFAULT ' ' NOT NULL,
FBILLID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FUPDATETIME BIGINT DEFAULT 0 NOT NULL,
FISNEW CHAR(1) DEFAULT ' ' NOT NULL,
FSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FUPDATETYPE INT DEFAULT 0 NOT NULL,
FBILLNO VARCHAR(50) DEFAULT ' ' NOT NULL,
FENTRYSEQ INT DEFAULT 0 NOT NULL,
FUPDATERULEID VARCHAR(36) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_CAL_PER_BAL') 
 CREATE TABLE T_IM_CAL_PER_BAL (
FID BIGINT DEFAULT 0 NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL,
FWAREHOUSEID BIGINT DEFAULT 0 NOT NULL,
FLOCATIONID BIGINT DEFAULT 0 NOT NULL,
FOWNERTYPE VARCHAR(20) DEFAULT ' ' NOT NULL,
FOWNERID BIGINT DEFAULT 0 NOT NULL,
FKEEPERTYPE VARCHAR(20) DEFAULT ' ' NOT NULL,
FKEEPERID BIGINT DEFAULT 0 NOT NULL,
FINVSTATUSID BIGINT DEFAULT 0 NOT NULL,
FFINVTYPEID BIGINT DEFAULT 0 NOT NULL,
FMATERIALID BIGINT DEFAULT 0 NOT NULL,
FAUXPTYID BIGINT DEFAULT 0 NOT NULL,
FLOTNUMBER VARCHAR(50) DEFAULT ' ' NOT NULL,
FPROJECTID BIGINT DEFAULT 0 NOT NULL,
FPRODUCEDATE DATETIME,
FEXPIRYDATE DATETIME,
FUNITID BIGINT DEFAULT 0 NOT NULL,
FBASEUNIT BIGINT DEFAULT 0 NOT NULL,
FUNIT2NDID BIGINT DEFAULT 0 NOT NULL,
FPERIOD INT DEFAULT 0 NOT NULL,
FENDPERIOD INT DEFAULT 0 NOT NULL,
FQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY2ND DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY_IN DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBASEQTY_IN DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY2ND_IN DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY_OUT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBASEQTY_OUT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY2ND_OUT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY_BAL DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBASEQTY_BAL DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY2ND_BAL DECIMAL(23,10) DEFAULT 0 NOT NULL,
FKEYCOL VARCHAR(50) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_CAL_PER_BAL_SP') 
 CREATE TABLE T_IM_CAL_PER_BAL_SP (
FID BIGINT DEFAULT 0 NOT NULL,
FPERIOD INT DEFAULT 0 NOT NULL,
FQTY_SP DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBASEQTY_SP DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY2ND_SP DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY_IN_SP DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBASEQTY_IN_SP DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY2ND_IN_SP DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY_OUT_SP DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBASEQTY_OUT_SP DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY2ND_OUT_SP DECIMAL(23,10) DEFAULT 0 NOT NULL,
FKEYCOL VARCHAR(50) DEFAULT ' ' NOT NULL,
FBILLNAME VARCHAR(50) DEFAULT ' ' NOT NULL,
FBILLID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FUPDATETIME BIGINT DEFAULT 0 NOT NULL,
FISNEW CHAR(1) DEFAULT ' ' NOT NULL,
FSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FUPDATETYPE INT DEFAULT 0 NOT NULL,
FBILLNO VARCHAR(50) DEFAULT ' ' NOT NULL,
FENTRYSEQ INT DEFAULT 0 NOT NULL,
FUPDATERULEID VARCHAR(36) DEFAULT ' ' NOT NULL
);

 EXEC p_AlterColumn 'T_IM_BAL_RECAL_LOG', 'FERRORMSG', 'NVARCHAR(200)', 'NOT NULL', '0100', ''' ''';

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_BAL_RECAL_LOG' AND KSQL_COL_NAME IN ('FBAL')) 
 ALTER TABLE T_IM_BAL_RECAL_LOG ADD (FBAL VARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_BAL_RECAL_LOG' AND KSQL_COL_NAME IN ('FORG')) 
 ALTER TABLE T_IM_BAL_RECAL_LOG ADD (FORG BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_BAL_RECAL_LOG' AND KSQL_COL_NAME IN ('FERRORMSG_TAG')) 
 ALTER TABLE T_IM_BAL_RECAL_LOG ADD (FERRORMSG_TAG NCLOB );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_BAL_RECAL_POINT' AND KSQL_COL_NAME IN ('FORG')) 
 ALTER TABLE T_IM_BAL_RECAL_POINT ADD (FORG BIGINT DEFAULT 0 NOT NULL );


/**End D:\nextcloud\dev2main2bizline\PDM_UPGRADE\pdm1\BASE_table.sql **/
