IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MDS_FCDATATS_KZ') 
create table T_MDS_FCDATATS_KZ
(
  fid           BIGINT default 0 not null,
  frule 		BIGINT default 0 not null,
  fbillno       NVARCHAR(30) default ' ' not null,
  fbillstatus   NVARCHAR(50) default ' ' not null,
  fcreatorid    BIGINT default 0 not null,
  fmodifierid   BIGINT default 0 not null,
  fenablestatus NVARCHAR(50) default ' ' not null,
  fcreatetime   DATETIME,
  fmodifytime   DATETIME,
  fauditorid    BIGINT default 0 not null,
  fauditdate    DATETIME,
  forgid        BIGINT default 0 not null,
  ffcvrnnum     BIGINT default 0 not null,
  finvaldate    DATETIME,
  fid2          BIGINT default 0 not null
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MDS_FCDATATSENTRY_KZ') 
create table T_MDS_FCDATATSENTRY_KZ
(
  fid             BIGINT default 0 not null,
  fentryid        BIGINT default 0 not null,
  fseq            BIGINT default 0 not null,
  fmaterialid     BIGINT default 0 not null,
  fbaseunitid     BIGINT default 0 not null,
  fprodorg        BIGINT default 0 not null,
  fplangp         BIGINT default 0 not null,
  fremark         NVARCHAR(300) default ' ' not null,
  fqty1           DECIMAL(23,10) default 0 not null,
  fqty2           DECIMAL(23,10) default 0 not null,
  fqty3           DECIMAL(23,10) default 0 not null,
  fqty4           DECIMAL(23,10) default 0 not null,
  fqty5           DECIMAL(23,10) default 0 not null,
  fqty6           DECIMAL(23,10) default 0 not null,
  fqty7           DECIMAL(23,10) default 0 not null,
  fqty8           DECIMAL(23,10) default 0 not null,
  fqty9           DECIMAL(23,10) default 0 not null,
  fqty10          DECIMAL(23,10) default 0 not null,
  fqty11          DECIMAL(23,10) default 0 not null,
  fqty12          DECIMAL(23,10) default 0 not null,
  fqty13          DECIMAL(23,10) default 0 not null,
  fqty14          DECIMAL(23,10) default 0 not null,
  fqty15          DECIMAL(23,10) default 0 not null,
  fqty16          DECIMAL(23,10) default 0 not null,
  fqty17          DECIMAL(23,10) default 0 not null,
  fqty18          DECIMAL(23,10) default 0 not null,
  fqty19          DECIMAL(23,10) default 0 not null,
  fqty20          DECIMAL(23,10) default 0 not null,
  fqty21          DECIMAL(23,10) default 0 not null,
  fqty22          DECIMAL(23,10) default 0 not null,
  fqty23          DECIMAL(23,10) default 0 not null,
  fqty24          DECIMAL(23,10) default 0 not null,
  fqty25          DECIMAL(23,10) default 0 not null,
  fqty26          DECIMAL(23,10) default 0 not null,
  fqty27          DECIMAL(23,10) default 0 not null,
  fqty28          DECIMAL(23,10) default 0 not null,
  fqty29          DECIMAL(23,10) default 0 not null,
  fqty30          DECIMAL(23,10) default 0 not null,
  fqty31          DECIMAL(23,10) default 0 not null,
  fqty32          DECIMAL(23,10) default 0 not null,
  fqty33          DECIMAL(23,10) default 0 not null,
  fqty34          DECIMAL(23,10) default 0 not null,
  fqty35          DECIMAL(23,10) default 0 not null,
  fqty36          DECIMAL(23,10) default 0 not null,
  fqty37          DECIMAL(23,10) default 0 not null,
  fqty38          DECIMAL(23,10) default 0 not null,
  fqty39          DECIMAL(23,10) default 0 not null,
  fqty40          DECIMAL(23,10) default 0 not null,
  fqty41          DECIMAL(23,10) default 0 not null,
  fqty42          DECIMAL(23,10) default 0 not null,
  fqty43          DECIMAL(23,10) default 0 not null,
  fqty44          DECIMAL(23,10) default 0 not null,
  fqty45          DECIMAL(23,10) default 0 not null,
  fqty46          DECIMAL(23,10) default 0 not null,
  fqty47          DECIMAL(23,10) default 0 not null,
  fqty48          DECIMAL(23,10) default 0 not null,
  fqty49          DECIMAL(23,10) default 0 not null,
  fqty50          DECIMAL(23,10) default 0 not null,
  fqty51          DECIMAL(23,10) default 0 not null,
  fqty52          DECIMAL(23,10) default 0 not null,
  fqty53          DECIMAL(23,10) default 0 not null,
  fqty54          DECIMAL(23,10) default 0 not null,
  fqty55          DECIMAL(23,10) default 0 not null,
  fqty56          DECIMAL(23,10) default 0 not null,
  fqty57          DECIMAL(23,10) default 0 not null,
  fqty58          DECIMAL(23,10) default 0 not null,
  fqty59          DECIMAL(23,10) default 0 not null,
  fqty60          DECIMAL(23,10) default 0 not null,
  fqty61          DECIMAL(23,10) default 0 not null,
  fqty62          DECIMAL(23,10) default 0 not null,
  fqty63          DECIMAL(23,10) default 0 not null,
  fqty64          DECIMAL(23,10) default 0 not null,
  fqty65          DECIMAL(23,10) default 0 not null,
  fqty66          DECIMAL(23,10) default 0 not null,
  fqty67          DECIMAL(23,10) default 0 not null,
  fqty68          DECIMAL(23,10) default 0 not null,
  fqty69          DECIMAL(23,10) default 0 not null,
  fqty70          DECIMAL(23,10) default 0 not null,
  fqty71          DECIMAL(23,10) default 0 not null,
  fqty72          DECIMAL(23,10) default 0 not null,
  fqty73          DECIMAL(23,10) default 0 not null,
  fqty74          DECIMAL(23,10) default 0 not null,
  fqty75          DECIMAL(23,10) default 0 not null,
  fqty76          DECIMAL(23,10) default 0 not null,
  fqty77          DECIMAL(23,10) default 0 not null,
  fqty78          DECIMAL(23,10) default 0 not null,
  fqty79          DECIMAL(23,10) default 0 not null,
  fqty80          DECIMAL(23,10) default 0 not null,
  fqty81          DECIMAL(23,10) default 0 not null,
  fqty82          DECIMAL(23,10) default 0 not null,
  fqty83          DECIMAL(23,10) default 0 not null,
  fqty84          DECIMAL(23,10) default 0 not null,
  fqty85          DECIMAL(23,10) default 0 not null,
  fqty86          DECIMAL(23,10) default 0 not null,
  fqty87          DECIMAL(23,10) default 0 not null,
  fqty88          DECIMAL(23,10) default 0 not null,
  fqty89          DECIMAL(23,10) default 0 not null,
  fqty90          DECIMAL(23,10) default 0 not null,
  fqty91          DECIMAL(23,10) default 0 not null,
  fqty92          DECIMAL(23,10) default 0 not null,
  fqty93          DECIMAL(23,10) default 0 not null,
  fqty94          DECIMAL(23,10) default 0 not null,
  fqty95          DECIMAL(23,10) default 0 not null,
  fqty96          DECIMAL(23,10) default 0 not null,
  fqty97          DECIMAL(23,10) default 0 not null,
  fqty98          DECIMAL(23,10) default 0 not null,
  fqty99          DECIMAL(23,10) default 0 not null,
  fqty100         DECIMAL(23,10) default 0 not null,
  fqty101         DECIMAL(23,10) default 0 not null,
  fqty102         DECIMAL(23,10) default 0 not null,
  fqty103         DECIMAL(23,10) default 0 not null,
  fqty104         DECIMAL(23,10) default 0 not null,
  fqty105         DECIMAL(23,10) default 0 not null,
  fqty106         DECIMAL(23,10) default 0 not null,
  fqty107         DECIMAL(23,10) default 0 not null,
  fqty108         DECIMAL(23,10) default 0 not null,
  fqty109         DECIMAL(23,10) default 0 not null,
  fqty110         DECIMAL(23,10) default 0 not null,
  fqty111         DECIMAL(23,10) default 0 not null,
  fqty112         DECIMAL(23,10) default 0 not null,
  fqty113         DECIMAL(23,10) default 0 not null,
  fqty114         DECIMAL(23,10) default 0 not null,
  fqty115         DECIMAL(23,10) default 0 not null,
  fqty116         DECIMAL(23,10) default 0 not null,
  fqty117         DECIMAL(23,10) default 0 not null,
  fqty118         DECIMAL(23,10) default 0 not null,
  fqty119         DECIMAL(23,10) default 0 not null,
  fqty120         DECIMAL(23,10) default 0 not null,
  fqty121         DECIMAL(23,10) default 0 not null,
  fqty122         DECIMAL(23,10) default 0 not null,
  fqty123         DECIMAL(23,10) default 0 not null,
  fqty124         DECIMAL(23,10) default 0 not null,
  fqty125         DECIMAL(23,10) default 0 not null,
  fqty126         DECIMAL(23,10) default 0 not null,
  fqty127         DECIMAL(23,10) default 0 not null,
  fqty128         DECIMAL(23,10) default 0 not null,
  fqty129         DECIMAL(23,10) default 0 not null,
  fqty130         DECIMAL(23,10) default 0 not null,
  fqty131         DECIMAL(23,10) default 0 not null,
  fqty132         DECIMAL(23,10) default 0 not null,
  fqty133         DECIMAL(23,10) default 0 not null,
  fqty134         DECIMAL(23,10) default 0 not null,
  fqty135         DECIMAL(23,10) default 0 not null,
  fqty136         DECIMAL(23,10) default 0 not null,
  fqty137         DECIMAL(23,10) default 0 not null,
  fqty138         DECIMAL(23,10) default 0 not null,
  fqty139         DECIMAL(23,10) default 0 not null,
  fqty140         DECIMAL(23,10) default 0 not null,
  fqty141         DECIMAL(23,10) default 0 not null,
  fqty142         DECIMAL(23,10) default 0 not null,
  fqty143         DECIMAL(23,10) default 0 not null,
  fqty144         DECIMAL(23,10) default 0 not null,
  fqty145         DECIMAL(23,10) default 0 not null,
  fqty146         DECIMAL(23,10) default 0 not null,
  fqty147         DECIMAL(23,10) default 0 not null,
  fqty148         DECIMAL(23,10) default 0 not null,
  fqty149         DECIMAL(23,10) default 0 not null,
  fqty150         DECIMAL(23,10) default 0 not null,
  freceive1       DECIMAL(23,10) default 0 not null,
  freceive2       DECIMAL(23,10) default 0 not null,
  freceive3       DECIMAL(23,10) default 0 not null,
  freceive4       DECIMAL(23,10) default 0 not null,
  freceive5       DECIMAL(23,10) default 0 not null,
  freceive6       DECIMAL(23,10) default 0 not null,
  freceive7       DECIMAL(23,10) default 0 not null,
  freceive8       DECIMAL(23,10) default 0 not null,
  freceive9       DECIMAL(23,10) default 0 not null,
  freceive10      DECIMAL(23,10) default 0 not null,
  fofferingedit   NVARCHAR(200) default ' ' not null,
  flevel1edit     NVARCHAR(200) default ' ' not null,
  fmdsuser        BIGINT,
  fspdt           NVARCHAR(50) default ' ' not null,
  fedituser       BIGINT,
  feditdate       DATETIME,
  feditcreatedate DATETIME,
  fentrymodifier  BIGINT,
  fid2            BIGINT default 0 not null,
  fseq2           BIGINT default 0 not null
);
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MDS_DATEENTRY_KZ') 
create table T_MDS_DATEENTRY_KZ
(
  fid             BIGINT default 0 not null,
  fentryid        BIGINT default 0 not null,
  fseq            BIGINT default 0 not null,
  ffieldkey       NVARCHAR(50) default ' ' not null,
  fdeliverycolumn CHAR(1) default '1' not null,
  ftargetdate     DATETIME,
  fid2            BIGINT default 0 not null
);
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MDS_FPLOG') 
create table T_MDS_FPLOG
(
  fid         BIGINT not null,
  fnumber     NVARCHAR(30) default ' ' not null,
  fstatus     NVARCHAR(50) default ' ' not null,
  fcreatorid  BIGINT,
  fmodifierid BIGINT,
  fenable     NVARCHAR(50) default ' ' not null,
  fcreatetime DATETIME,
  fmodifytime DATETIME,
  fmasterid   BIGINT,
  fsyncresult NVARCHAR(50) default ' ' not null,
  ferrorinfo  NVARCHAR(1000) default ' ' not null,
  ffpinfo     NVARCHAR(50) default ' ' not null,
  fstartdate  DATETIME,
  fenddate    DATETIME,
  fsummin     DECIMAL(23,2)
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MDS_FPLOG_L') 
 CREATE TABLE T_MDS_FPLOG_L
(
  fpkid     NVARCHAR(36) not null,
  fid       BIGINT not null,
  flocaleid VARCHAR(10) not null,
  fname     NVARCHAR(50) default ' ' not null
);


