/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\MAL_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MAL_APILOG') 
 CREATE TABLE T_MAL_APILOG (
FID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FEXTSYSAPI BIGINT DEFAULT 0 NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FSYSTYPE CHAR(1) DEFAULT ' ' NOT NULL,
FSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FEND_TIME DATETIME,
FPARAMS NCLOB,
FPARAMS_TAG NCLOB,
FRESULT NCLOB,
FRESULT_TAG NCLOB
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MAL_APILOGBACK') 
 CREATE TABLE T_MAL_APILOGBACK (
FID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FEXTSYSAPI BIGINT DEFAULT 0 NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FSYSTYPE CHAR(1) DEFAULT ' ' NOT NULL,
FSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FEND_TIME DATETIME,
FPARAMS NCLOB,
FPARAMS_TAG NCLOB,
FRESULT NCLOB,
FRESULT_TAG NCLOB
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MAL_APILOGSETTING') 
 CREATE TABLE T_MAL_APILOGSETTING (
FID BIGINT DEFAULT 0 NOT NULL,
FAUTOARCHIVEAMT BIGINT DEFAULT 0 NOT NULL,
FAUTOCLEARTIME BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MAL_EXT_APISETENTRY') 
 CREATE TABLE T_MAL_EXT_APISETENTRY (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FEXTSYSAPI BIGINT DEFAULT 0 NOT NULL,
FHANDLECLASS VARCHAR(100) DEFAULT ' ' NOT NULL,
FVALID CHAR(1) DEFAULT ' ' NOT NULL,
FSYSTYPE CHAR(1) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MAL_EXTAPISET') 
 CREATE TABLE T_MAL_EXTAPISET (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FENABLE CHAR(1) DEFAULT ' ' NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FISPRESET CHAR(1) DEFAULT ' ' NOT NULL,
FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MAL_EXTAPISET_L') 
 CREATE TABLE T_MAL_EXTAPISET_L (
FPKID VARCHAR(36) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MAL_EXTSYS') 
 CREATE TABLE T_MAL_EXTSYS (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FENABLE CHAR(1) DEFAULT ' ' NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FSYSSOURCEID BIGINT DEFAULT 0 NOT NULL,
FSYSTYPE CHAR(1) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MAL_EXTSYS_API') 
 CREATE TABLE T_MAL_EXTSYS_API (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FENABLE CHAR(1) DEFAULT ' ' NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FGROUPID BIGINT DEFAULT 0 NOT NULL,
FRECORD_LOG CHAR(1) DEFAULT ' ' NOT NULL,
FISPRESET CHAR(1) DEFAULT ' ' NOT NULL,
FCONTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FCONCONFIG BIGINT DEFAULT 0 NOT NULL,
FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MAL_EXTSYS_API_L') 
 CREATE TABLE T_MAL_EXTSYS_API_L (
FPKID VARCHAR(36) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MAL_EXTSYS_L') 
 CREATE TABLE T_MAL_EXTSYS_L (
FPKID VARCHAR(36) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MAL_EXTSYSAPI_INPUTS') 
 CREATE TABLE T_MAL_EXTSYSAPI_INPUTS (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FINPUT_FIELD VARCHAR(100) DEFAULT ' ' NOT NULL,
FINPUT_IS_ARRAY CHAR(1) DEFAULT ' ' NOT NULL,
FREQUIRED CHAR(1) DEFAULT ' ' NOT NULL,
FINPUT_DESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL,
FINPUT_DATA_TYPE VARCHAR(30) DEFAULT ' ' NOT NULL,
FDEFAULT_VALUE NVARCHAR(500) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MAL_EXTSYSAPI_OUTPUTS') 
 CREATE TABLE T_MAL_EXTSYSAPI_OUTPUTS (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FINPUT_FIELD VARCHAR(100) DEFAULT ' ' NOT NULL,
FINPUT_IS_ARRAY CHAR(1) DEFAULT ' ' NOT NULL,
FINPUT_DESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL,
FINPUT_DATA_TYPE VARCHAR(30) DEFAULT ' ' NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MAL_EXTSYS_API' AND KSQL_COL_NAME IN ('FFULL_NAME')) 
 ALTER TABLE T_MAL_EXTSYS_API ADD (FFULL_NAME NVARCHAR(255) DEFAULT ' ' NOT NULL );

 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MAL_INVOICETYPE' AND KSQL_COL_NAME ='FBDINVOICETYPE') 
 ALTER TABLE T_MAL_INVOICETYPE ADD (FBDINVOICETYPE BIGINT DEFAULT 0 NOT NULL );

/**End E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\MAL_table.sql **/
