__IF_EXISTS__
SELECT 1
  FROM CI_UT_INSTL_DTL
 WHERE SCRIPT_FILE_NAME = 'FW400_POSTDATA1.SQL'
   AND END_DTTM IS NOT NULL
/
__THEN__

__EXIT__

__ENDIF__

__IF_EXISTS__
SELECT 1
  FROM CI_INSTALL_PROD
 WHERE INSTALL_OPT_ID = '11111'
   AND OWNER_FLG = 'F1'
/
__ELSE__

__EXIT__

__ENDIF__



INSERT INTO F1_SCHEMA  (SELECT DISTINCT A.SCR_CD, 'F1BP',1,'<schema><include'||decode(UPPER(A.SCHEMA_TYPE_FLG),'F1BO','BO','F1MP','Map','F1BS','BS','F1SC','SS','F1DA','DA')||' name="'||
                        RTRIM(A.SCHEMA_NAME)||'"/></schema>',B.OWNER_FLG 
                                FROM CI_SCR_DA A,
                                     CI_SCR B
                               WHERE RTRIM(A.SCR_CD)         = RTRIM(B.SCR_CD)
                                 AND UPPER(RTRIM(A.SCR_CD)) NOT LIKE 'ZZ%'
                                 AND UPPER(RTRIM(B.SCR_CD)) NOT LIKE 'ZZ%'
                                 AND UPPER(RTRIM(B.SCR_TYPE_FLG))     = 'BPSC'
                                 AND UPPER(A.SCHEMA_TYPE_FLG)       IN ('F1BO','F1MP','F1BS','F1SC','F1DA')
                                 AND UPPER(RTRIM(A.DA_NAME)) = 'PARM'
                                 AND NOT EXISTS ( SELECT 1
                                                    FROM F1_SCHEMA C
                                                   WHERE RTRIM(C.SCHEMA_NAME) = RTRIM(A.SCR_CD)
                                                     AND UPPER(RTRIM(C.SCHEMA_TYPE_FLG))     = 'F1BP'
                                                )
                           )
/


INSERT INTO F1_SCHEMA  (SELECT DISTINCT A.SCR_CD, 'F1BP',1,'<schema/>',B.OWNER_FLG 
                                FROM (SELECT DISTINCT SCR_CD FROM CI_SCR_DA WHERE SCR_CD NOT IN ( SELECT SCR_CD FROM CI_SCR_DA WHERE DA_NAME = 'PARM'))  A,
                                     CI_SCR B
                               WHERE RTRIM(A.SCR_CD)         = RTRIM(B.SCR_CD)
                                 AND UPPER(RTRIM(A.SCR_CD)) NOT LIKE 'ZZ%'
                                 AND UPPER(RTRIM(B.SCR_CD)) NOT LIKE 'ZZ%'
                                 AND UPPER(RTRIM(B.SCR_TYPE_FLG))     = 'BPSC'
                                 AND NOT EXISTS ( SELECT 1
                                                    FROM F1_SCHEMA C
                                                   WHERE RTRIM(C.SCHEMA_NAME) = RTRIM(A.SCR_CD)
                                                     AND UPPER(RTRIM(C.SCHEMA_TYPE_FLG))     = 'F1BP'
                                                )
                           )
/


                  
INSERT INTO F1_SCHEMA (SELECT A.SCR_CD, 'F1BP',1,'<schema/>',A.OWNER_FLG
                                FROM CI_SCR A
                               WHERE UPPER(RTRIM(A.SCR_TYPE_FLG))          = 'BPSC'
                                 AND UPPER(RTRIM(A.SCR_CD)) NOT LIKE 'ZZ%'
                                 AND NOT EXISTS ( SELECT 1
                                                    FROM F1_SCHEMA B
                                                   WHERE RTRIM(B.SCHEMA_NAME) = RTRIM(A.SCR_CD)
                                                     AND UPPER(RTRIM(B.SCHEMA_TYPE_FLG))     = 'F1BP'
                                                )
                                 AND NOT EXISTS ( SELECT 1
                                                    FROM CI_SCR_DA C
                                                   WHERE RTRIM(C.SCR_CD) = RTRIM(A.SCR_CD)
                                                 )
                       )
/



UPDATE CI_SCR_DA
   SET DA_TYPE_FLG     = 'BPSM',
       SCHEMA_NAME     =  SCR_CD,
       SCHEMA_TYPE_FLG = 'F1BP'
 WHERE (RTRIM(SCR_CD),RTRIM(DA_NAME)) IN (SELECT RTRIM(A.SCR_CD),RTRIM(A.DA_NAME)
                                                        FROM CI_SCR_DA A, CI_SCR B
                                                       WHERE RTRIM(A.SCR_CD) = RTRIM(B.SCR_CD)
                                                         AND UPPER(RTRIM(B.SCR_TYPE_FLG)) = 'BPSC'
                                                         AND UPPER(RTRIM(A.SCR_CD)) NOT LIKE 'ZZ%'
                                                         AND UPPER(RTRIM(B.SCR_CD)) NOT LIKE 'ZZ%'
                                                         AND UPPER(RTRIM(A.DA_NAME)) = 'PARM'
                                                         AND UPPER(RTRIM(A.SCHEMA_TYPE_FLG)) IN 
                                                            ('F1BO','F1MP','F1BS','F1SC','F1DA')
                                         )
/








