    insert into i$SDD_LVI
    values (
       SDD_LVI_rec9.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_LVI_rec9.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_LVI_rec9.TYPES
     , SDD_LVI_rec9.ELEMENT_TYPE_NAME
     , SDD_LVI_rec9.DATE_CREATED
     , SDD_LVI_rec9.CREATED_BY
     , SDD_LVI_rec9.DATE_CHANGED
     , SDD_LVI_rec9.CHANGED_BY
     , SDD_LVI_rec9.NOTM
     , SDD_LVI_rec9.GENERAL_MODULE_REF
     , SDD_LVI_rec9.LIST_OF_VALUES_REF
     , SDD_LVI_rec9.USAGE_SEQUENCE
     , SDD_LVI_rec9.ITEM_REF
     , SDD_LVI_rec9.RETURN_LIST
     , SDD_LVI_rec9.LONG_LIST_FLAG
     , SDD_LVI_rec9.USED_FOR
     , SDD_LVI_rec9.RESTRICTION_CLAUSE
     , SDD_LVI_rec9.REQ_VIEW_POSX
     , SDD_LVI_rec9.REQ_VIEW_POSY
     , SDD_LVI_rec9.DISPLAY_TITLE_OVERRIDE
     , SDD_LVI_rec9.USRX0
     , SDD_LVI_rec9.USRX1
     , SDD_LVI_rec9.USRX2
     , SDD_LVI_rec9.USRX3
     , SDD_LVI_rec9.USRX4
     , SDD_LVI_rec9.USRX5
     , SDD_LVI_rec9.USRX6
     , SDD_LVI_rec9.USRX7
     , SDD_LVI_rec9.USRX8
     , SDD_LVI_rec9.USRX9
     , SDD_LVI_rec9.USRX10
     , SDD_LVI_rec9.USRX11
     , SDD_LVI_rec9.USRX12
     , SDD_LVI_rec9.USRX13
     , SDD_LVI_rec9.USRX14
     , SDD_LVI_rec9.USRX15
     , SDD_LVI_rec9.USRX16
     , SDD_LVI_rec9.USRX17
     , SDD_LVI_rec9.USRX18
     , SDD_LVI_rec9.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_LVI_rec9.irid, SDD_LVI_rec9.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_MCH_rec10 in SDD_MCH_cur10 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_MCH
    values (
       SDD_MCH_rec10.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_MCH_rec10.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_MCH_rec10.TYPES
     , SDD_MCH_rec10.ELEMENT_TYPE_NAME
     , SDD_MCH_rec10.DATE_CREATED
     , SDD_MCH_rec10.CREATED_BY
     , SDD_MCH_rec10.DATE_CHANGED
     , SDD_MCH_rec10.CHANGED_BY
     , SDD_MCH_rec10.NOTM
     , SDD_MCH_rec10.MODULE_REF
     , SDD_MCH_rec10.CHANGE_REF
     , SDD_MCH_rec10.DEVELOPER
     , SDD_MCH_rec10.DEVELOPMENT_DIR
     , SDD_MCH_rec10.PRODUCT_VERSION
     , SDD_MCH_rec10.DATE_OUT
     , SDD_MCH_rec10.DATE_COMPLETE
     , SDD_MCH_rec10.DESCRIPTION
     , SDD_MCH_rec10.DATE_TRANSFERRED
     , SDD_MCH_rec10.TRANSFERRED_BY
     , SDD_MCH_rec10.USRX0
     , SDD_MCH_rec10.USRX1
     , SDD_MCH_rec10.USRX2
     , SDD_MCH_rec10.USRX3
     , SDD_MCH_rec10.USRX4
     , SDD_MCH_rec10.USRX5
     , SDD_MCH_rec10.USRX6
     , SDD_MCH_rec10.USRX7
     , SDD_MCH_rec10.USRX8
     , SDD_MCH_rec10.USRX9
     , SDD_MCH_rec10.USRX10
     , SDD_MCH_rec10.USRX11
     , SDD_MCH_rec10.USRX12
     , SDD_MCH_rec10.USRX13
     , SDD_MCH_rec10.USRX14
     , SDD_MCH_rec10.USRX15
     , SDD_MCH_rec10.USRX16
     , SDD_MCH_rec10.USRX17
     , SDD_MCH_rec10.USRX18
     , SDD_MCH_rec10.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_MCH_rec10.irid, SDD_MCH_rec10.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_MCL_rec11 in SDD_MCL_cur11 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_MCL
    values (
       SDD_MCL_rec11.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_MCL_rec11.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_MCL_rec11.TYPES
     , SDD_MCL_rec11.ELEMENT_TYPE_NAME
     , SDD_MCL_rec11.DATE_CREATED
     , SDD_MCL_rec11.CREATED_BY
     , SDD_MCL_rec11.DATE_CHANGED
     , SDD_MCL_rec11.CHANGED_BY
     , SDD_MCL_rec11.NOTM
     , SDD_MCL_rec11.MCN_REF_FROM
     , SDD_MCL_rec11.TABLE_USAGE_REF_FROM
     , SDD_MCL_rec11.MCN_REF_TO
     , SDD_MCL_rec11.TABLE_USAGE_REF_TO
     , SDD_MCL_rec11.JOIN_CONSTRAINT_REF
     , SDD_MCL_rec11.PRIMARY_KEY_REF
     , SDD_MCL_rec11.FK_ON_FROM_COMPONENT_FLAG
     , SDD_MCL_rec11.SQL_QUERY_CLAUSE
     , SDD_MCL_rec11.MODULE_COMPONENT_LINK_TYPE
     , SDD_MCL_rec11.MODULE_REF_FROM
     , SDD_MCL_rec11.MODULE_REF_TO
     , SDD_MCL_rec11.KEY_BASED_LINK_VIA
     , SDD_MCL_rec11.USRX0
     , SDD_MCL_rec11.USRX1
     , SDD_MCL_rec11.USRX2
     , SDD_MCL_rec11.USRX3
     , SDD_MCL_rec11.USRX4
     , SDD_MCL_rec11.USRX5
     , SDD_MCL_rec11.USRX6
     , SDD_MCL_rec11.USRX7
     , SDD_MCL_rec11.USRX8
     , SDD_MCL_rec11.USRX9
     , SDD_MCL_rec11.USRX10
     , SDD_MCL_rec11.USRX11
     , SDD_MCL_rec11.USRX12
     , SDD_MCL_rec11.USRX13
     , SDD_MCL_rec11.USRX14
     , SDD_MCL_rec11.USRX15
     , SDD_MCL_rec11.USRX16
     , SDD_MCL_rec11.USRX17
     , SDD_MCL_rec11.USRX18
     , SDD_MCL_rec11.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_MCL_rec11.irid, SDD_MCL_rec11.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_MCN_rec12 in SDD_MCN_cur12 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_MCN
    values (
       SDD_MCN_rec12.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_MCN_rec12.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_MCN_rec12.TYPES
     , SDD_MCN_rec12.ELEMENT_TYPE_NAME
     , SDD_MCN_rec12.DATE_CREATED
     , SDD_MCN_rec12.CREATED_BY
     , SDD_MCN_rec12.DATE_CHANGED
     , SDD_MCN_rec12.CHANGED_BY
     , SDD_MCN_rec12.NOTM
     , SDD_MCN_rec12.GENERAL_MODULE_REF
     , SDD_MCN_rec12.MODULE_COMPONENT_REF
     , SDD_MCN_rec12.SUBCOMPONENT_REF
     , SDD_MCN_rec12.USAGE_SEQUENCE
     , SDD_MCN_rec12.WINDOW_REF
     , SDD_MCN_rec12.RIGHT_OF_MCN_REF
     , SDD_MCN_rec12.REQ_PLACEMENT
     , SDD_MCN_rec12.PLACEMENT_ITEM
     , SDD_MCN_rec12.REQ_VIEW_POSX
     , SDD_MCN_rec12.REQ_VIEW_POSY
     , SDD_MCN_rec12.TAB_SCOPE
     , SDD_MCN_rec12.PARENT_MCN_REF
     , SDD_MCN_rec12.USRX0
     , SDD_MCN_rec12.USRX1
     , SDD_MCN_rec12.USRX2
     , SDD_MCN_rec12.USRX3
     , SDD_MCN_rec12.USRX4
     , SDD_MCN_rec12.USRX5
     , SDD_MCN_rec12.USRX6
     , SDD_MCN_rec12.USRX7
     , SDD_MCN_rec12.USRX8
     , SDD_MCN_rec12.USRX9
     , SDD_MCN_rec12.USRX10
     , SDD_MCN_rec12.USRX11
     , SDD_MCN_rec12.USRX12
     , SDD_MCN_rec12.USRX13
     , SDD_MCN_rec12.USRX14
     , SDD_MCN_rec12.USRX15
     , SDD_MCN_rec12.USRX16
     , SDD_MCN_rec12.USRX17
     , SDD_MCN_rec12.USRX18
     , SDD_MCN_rec12.USRX19
     , SDD_MCN_rec12.MCN_FOR
    );
  jr_reg_ver.vercopy_dependencies(SDD_MCN_rec12.irid, SDD_MCN_rec12.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_ACI_rec13 in SDD_ACI_cur13 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_ACI
    values (
       SDD_ACI_rec13.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_ACI_rec13.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_ACI_rec13.TYPES
     , SDD_ACI_rec13.ELEMENT_TYPE_NAME
     , SDD_ACI_rec13.DATE_CREATED
     , SDD_ACI_rec13.CREATED_BY
     , SDD_ACI_rec13.DATE_CHANGED
     , SDD_ACI_rec13.CHANGED_BY
     , SDD_ACI_rec13.NOTM
     , SDD_ACI_rec13.MCN_REF
     , SDD_ACI_rec13.WINDOW_REF
     , SDD_ACI_rec13.NAME
     , SDD_ACI_rec13.GENERATOR_ITEM_TYPE
     , SDD_ACI_rec13.USAGE_SEQUENCE
     , SDD_ACI_rec13.DEFAULT_FLAG
     , SDD_ACI_rec13.MCN_REF_TO
     , SDD_ACI_rec13.ENABLE_ON_DB_RECORD_FLAG
     , SDD_ACI_rec13.IMPLEMENTATION_ITEM
     , SDD_ACI_rec13.MODULE_NETWORK_REF
     , SDD_ACI_rec13.PROMPT
     , SDD_ACI_rec13.ICON_NAME
     , SDD_ACI_rec13.CREATE_BUTTON_FLAG
     , SDD_ACI_rec13.BUTTON_HEIGHT
     , SDD_ACI_rec13.BUTTON_WIDTH
     , SDD_ACI_rec13.CREATE_MENU_ITEM_FLAG
     , SDD_ACI_rec13.HINT_TEXT
     , SDD_ACI_rec13.ACTION_ITEM_TYPE
     , SDD_ACI_rec13.ACTION_ITEM_FOR
     , SDD_ACI_rec13.NAVIGATION_TO
     , SDD_ACI_rec13.USRX0
     , SDD_ACI_rec13.USRX1
     , SDD_ACI_rec13.USRX2
     , SDD_ACI_rec13.USRX3
     , SDD_ACI_rec13.USRX4
     , SDD_ACI_rec13.USRX5
     , SDD_ACI_rec13.USRX6
     , SDD_ACI_rec13.USRX7
     , SDD_ACI_rec13.USRX8
     , SDD_ACI_rec13.USRX9
     , SDD_ACI_rec13.USRX10
     , SDD_ACI_rec13.USRX11
     , SDD_ACI_rec13.USRX12
     , SDD_ACI_rec13.USRX13
     , SDD_ACI_rec13.USRX14
     , SDD_ACI_rec13.USRX15
     , SDD_ACI_rec13.USRX16
     , SDD_ACI_rec13.USRX17
     , SDD_ACI_rec13.USRX18
     , SDD_ACI_rec13.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_ACI_rec13.irid, SDD_ACI_rec13.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_MODBUN_rec14 in SDD_MODBUN_cur14 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_MODBUN
    values (
       SDD_MODBUN_rec14.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_MODBUN_rec14.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_MODBUN_rec14.TYPES
     , SDD_MODBUN_rec14.ELEMENT_TYPE_NAME
     , SDD_MODBUN_rec14.DATE_CREATED
     , SDD_MODBUN_rec14.CREATED_BY
     , SDD_MODBUN_rec14.DATE_CHANGED
     , SDD_MODBUN_rec14.CHANGED_BY
     , SDD_MODBUN_rec14.NOTM
     , SDD_MODBUN_rec14.MODULE_REF
     , SDD_MODBUN_rec14.BUSINESS_UNIT_REF
     , SDD_MODBUN_rec14.REMARK
     , SDD_MODBUN_rec14.USRX0
     , SDD_MODBUN_rec14.USRX1
     , SDD_MODBUN_rec14.USRX2
     , SDD_MODBUN_rec14.USRX3
     , SDD_MODBUN_rec14.USRX4
     , SDD_MODBUN_rec14.USRX5
     , SDD_MODBUN_rec14.USRX6
     , SDD_MODBUN_rec14.USRX7
     , SDD_MODBUN_rec14.USRX8
     , SDD_MODBUN_rec14.USRX9
     , SDD_MODBUN_rec14.USRX10
     , SDD_MODBUN_rec14.USRX11
     , SDD_MODBUN_rec14.USRX12
     , SDD_MODBUN_rec14.USRX13
     , SDD_MODBUN_rec14.USRX14
     , SDD_MODBUN_rec14.USRX15
     , SDD_MODBUN_rec14.USRX16
     , SDD_MODBUN_rec14.USRX17
     , SDD_MODBUN_rec14.USRX18
     , SDD_MODBUN_rec14.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_MODBUN_rec14.irid, SDD_MODBUN_rec14.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_MODFUN_rec15 in SDD_MODFUN_cur15 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_MODFUN
    values (
       SDD_MODFUN_rec15.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_MODFUN_rec15.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_MODFUN_rec15.TYPES
     , SDD_MODFUN_rec15.ELEMENT_TYPE_NAME
     , SDD_MODFUN_rec15.DATE_CREATED
     , SDD_MODFUN_rec15.CREATED_BY
     , SDD_MODFUN_rec15.DATE_CHANGED
     , SDD_MODFUN_rec15.CHANGED_BY
     , SDD_MODFUN_rec15.NOTM
     , SDD_MODFUN_rec15.MODULE_REF
     , SDD_MODFUN_rec15.FUNCTION_REF
     , SDD_MODFUN_rec15.REMARK
     , SDD_MODFUN_rec15.USRX0
     , SDD_MODFUN_rec15.USRX1
     , SDD_MODFUN_rec15.USRX2
     , SDD_MODFUN_rec15.USRX3
     , SDD_MODFUN_rec15.USRX4
     , SDD_MODFUN_rec15.USRX5
     , SDD_MODFUN_rec15.USRX6
     , SDD_MODFUN_rec15.USRX7
     , SDD_MODFUN_rec15.USRX8
     , SDD_MODFUN_rec15.USRX9
     , SDD_MODFUN_rec15.USRX10
     , SDD_MODFUN_rec15.USRX11
     , SDD_MODFUN_rec15.USRX12
     , SDD_MODFUN_rec15.USRX13
     , SDD_MODFUN_rec15.USRX14
     , SDD_MODFUN_rec15.USRX15
     , SDD_MODFUN_rec15.USRX16
     , SDD_MODFUN_rec15.USRX17
     , SDD_MODFUN_rec15.USRX18
     , SDD_MODFUN_rec15.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_MODFUN_rec15.irid, SDD_MODFUN_rec15.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_MODMOD_rec16 in SDD_MODMOD_cur16 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_MODMOD
    values (
       SDD_MODMOD_rec16.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_MODMOD_rec16.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_MODMOD_rec16.TYPES
     , SDD_MODMOD_rec16.ELEMENT_TYPE_NAME
     , SDD_MODMOD_rec16.DATE_CREATED
     , SDD_MODMOD_rec16.CREATED_BY
     , SDD_MODMOD_rec16.DATE_CHANGED
     , SDD_MODMOD_rec16.CHANGED_BY
     , SDD_MODMOD_rec16.NOTM
     , SDD_MODMOD_rec16.PARENT_MODULE_REF
     , SDD_MODMOD_rec16.CHILD_MODULE_REF
     , SDD_MODMOD_rec16.CALLED_SEQUENCE
     , SDD_MODMOD_rec16.METHOD
     , SDD_MODMOD_rec16.USRX0
     , SDD_MODMOD_rec16.USRX1
     , SDD_MODMOD_rec16.USRX2
     , SDD_MODMOD_rec16.USRX3
     , SDD_MODMOD_rec16.USRX4
     , SDD_MODMOD_rec16.USRX5
     , SDD_MODMOD_rec16.USRX6
     , SDD_MODMOD_rec16.USRX7
     , SDD_MODMOD_rec16.USRX8
     , SDD_MODMOD_rec16.USRX9
     , SDD_MODMOD_rec16.USRX10
     , SDD_MODMOD_rec16.USRX11
     , SDD_MODMOD_rec16.USRX12
     , SDD_MODMOD_rec16.USRX13
     , SDD_MODMOD_rec16.USRX14
     , SDD_MODMOD_rec16.USRX15
     , SDD_MODMOD_rec16.USRX16
     , SDD_MODMOD_rec16.USRX17
     , SDD_MODMOD_rec16.USRX18
     , SDD_MODMOD_rec16.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_MODMOD_rec16.irid, SDD_MODMOD_rec16.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_PVL_rec17 in SDD_PVL_cur17 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_PVL
    values (
       SDD_PVL_rec17.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_PVL_rec17.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_PVL_rec17.TYPES
     , SDD_PVL_rec17.ELEMENT_TYPE_NAME
     , SDD_PVL_rec17.DATE_CREATED
     , SDD_PVL_rec17.NAME
     , SDD_PVL_rec17.CREATED_BY
     , SDD_PVL_rec17.DATE_CHANGED
     , SDD_PVL_rec17.CHANGED_BY
     , SDD_PVL_rec17.NOTM
     , SDD_PVL_rec17.MODULE_NETWORK_REF
     , SDD_PVL_rec17.CALLED_ARGUMENT_REF
     , SDD_PVL_rec17.MODULE_ARGUMENT_REF
     , SDD_PVL_rec17.ITEM_REF
     , SDD_PVL_rec17.VALUE
     , SDD_PVL_rec17.CALLED_ARGUMENT_VALUE_FROM
     , SDD_PVL_rec17.PASSED_VALUE_TYPE
     , SDD_PVL_rec17.USRX0
     , SDD_PVL_rec17.USRX1
     , SDD_PVL_rec17.USRX2
     , SDD_PVL_rec17.USRX3
     , SDD_PVL_rec17.USRX4
     , SDD_PVL_rec17.USRX5
     , SDD_PVL_rec17.USRX6
     , SDD_PVL_rec17.USRX7
     , SDD_PVL_rec17.USRX8
     , SDD_PVL_rec17.USRX9
     , SDD_PVL_rec17.USRX10
     , SDD_PVL_rec17.USRX11
     , SDD_PVL_rec17.USRX12
     , SDD_PVL_rec17.USRX13
     , SDD_PVL_rec17.USRX14
     , SDD_PVL_rec17.USRX15
     , SDD_PVL_rec17.USRX16
     , SDD_PVL_rec17.USRX17
     , SDD_PVL_rec17.USRX18
     , SDD_PVL_rec17.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_PVL_rec17.irid, SDD_PVL_rec17.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_MODPGD_rec18 in SDD_MODPGD_cur18 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_MODPGD
    values (
       SDD_MODPGD_rec18.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_MODPGD_rec18.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_MODPGD_rec18.TYPES
     , SDD_MODPGD_rec18.ELEMENT_TYPE_NAME
     , SDD_MODPGD_rec18.DATE_CREATED
     , SDD_MODPGD_rec18.CREATED_BY
     , SDD_MODPGD_rec18.DATE_CHANGED
     , SDD_MODPGD_rec18.CHANGED_BY
     , SDD_MODPGD_rec18.NOTM
     , SDD_MODPGD_rec18.GENERAL_MODULE_REF
     , SDD_MODPGD_rec18.PLSQL_MODULE_REF
     , SDD_MODPGD_rec18.PROGRAM_DATUM_REF
     , SDD_MODPGD_rec18.SEQUENCE
     , SDD_MODPGD_rec18.READ
     , SDD_MODPGD_rec18.WRITEABLE
     , SDD_MODPGD_rec18.METHOD_OF_USE
     , SDD_MODPGD_rec18.MODULE_TYPE_FOR
     , SDD_MODPGD_rec18.USRX0
     , SDD_MODPGD_rec18.USRX1
     , SDD_MODPGD_rec18.USRX2
     , SDD_MODPGD_rec18.USRX3
     , SDD_MODPGD_rec18.USRX4
     , SDD_MODPGD_rec18.USRX5
     , SDD_MODPGD_rec18.USRX6
     , SDD_MODPGD_rec18.USRX7
     , SDD_MODPGD_rec18.USRX8
     , SDD_MODPGD_rec18.USRX9
     , SDD_MODPGD_rec18.USRX10
     , SDD_MODPGD_rec18.USRX11
     , SDD_MODPGD_rec18.USRX12
     , SDD_MODPGD_rec18.USRX13
     , SDD_MODPGD_rec18.USRX14
     , SDD_MODPGD_rec18.USRX15
     , SDD_MODPGD_rec18.USRX16
     , SDD_MODPGD_rec18.USRX17
     , SDD_MODPGD_rec18.USRX18
     , SDD_MODPGD_rec18.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_MODPGD_rec18.irid, SDD_MODPGD_rec18.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_MUN_rec19 in SDD_MUN_cur19 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_MUN
    values (
       SDD_MUN_rec19.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_MUN_rec19.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_MUN_rec19.TYPES
     , SDD_MUN_rec19.ELEMENT_TYPE_NAME
     , SDD_MUN_rec19.DATE_CREATED
     , SDD_MUN_rec19.CREATED_BY
     , SDD_MUN_rec19.DATE_CHANGED
     , SDD_MUN_rec19.CHANGED_BY
     , SDD_MUN_rec19.NOTM
     , SDD_MUN_rec19.GENERAL_MODULE_REF
     , SDD_MUN_rec19.MODULE_COMPONENT_REF
     , SDD_MUN_rec19.NAME
     , SDD_MUN_rec19.SHORT_DESCRIPTION
     , SDD_MUN_rec19.IMPLEMENTATION_ITEM
     , SDD_MUN_rec19.LANGUAGE_REF
     , SDD_MUN_rec19.MODULE_LEVEL_FLAG
     , SDD_MUN_rec19.DATASOURCE_TYPE
     , SDD_MUN_rec19.DATATARGET_TYPE
     , SDD_MUN_rec19.INSERT_FLAG
     , SDD_MUN_rec19.DELETE_FLAG
     , SDD_MUN_rec19.UPDATE_FLAG
     , SDD_MUN_rec19.SELECT_FLAG
     , SDD_MUN_rec19.AUTOQUERY_FLAG
     , SDD_MUN_rec19.DISPLAY_TITLE
     , SDD_MUN_rec19.LAYOUT_STYLE
     , SDD_MUN_rec19.ROWS_DISPLAYED
     , SDD_MUN_rec19.REQ_OVERFLOW
     , SDD_MUN_rec19.REQ_PAGE_WIDTH
     , SDD_MUN_rec19.REQ_PAGE_HEIGHT
     , SDD_MUN_rec19.REQ_VIEW_WIDTH
     , SDD_MUN_rec19.REQ_VIEW_HEIGHT
     , SDD_MUN_rec19.MODULE_UNIT_SUBTYPE
     , SDD_MUN_rec19.HELP_CONTEXT_ID_PREFIX
     , SDD_MUN_rec19.RUNTIME_PATHNAME
     , SDD_MUN_rec19.HELP_CONTEXT_ID_SUFFIX
     , SDD_MUN_rec19.USRX0
     , SDD_MUN_rec19.USRX1
     , SDD_MUN_rec19.USRX2
     , SDD_MUN_rec19.USRX3
     , SDD_MUN_rec19.USRX4
     , SDD_MUN_rec19.USRX5
     , SDD_MUN_rec19.USRX6
     , SDD_MUN_rec19.USRX7
     , SDD_MUN_rec19.USRX8
     , SDD_MUN_rec19.USRX9
     , SDD_MUN_rec19.USRX10
     , SDD_MUN_rec19.USRX11
     , SDD_MUN_rec19.USRX12
     , SDD_MUN_rec19.USRX13
     , SDD_MUN_rec19.USRX14
     , SDD_MUN_rec19.USRX15
     , SDD_MUN_rec19.USRX16
     , SDD_MUN_rec19.USRX17
     , SDD_MUN_rec19.USRX18
     , SDD_MUN_rec19.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_MUN_rec19.irid, SDD_MUN_rec19.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_IGR_rec20 in SDD_IGR_cur20 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_IGR
    values (
       SDD_IGR_rec20.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_IGR_rec20.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_IGR_rec20.TYPES
     , SDD_IGR_rec20.ELEMENT_TYPE_NAME
     , SDD_IGR_rec20.DATE_CREATED
     , SDD_IGR_rec20.CREATED_BY
     , SDD_IGR_rec20.DATE_CHANGED
     , SDD_IGR_rec20.CHANGED_BY
     , SDD_IGR_rec20.NOTM
     , SDD_IGR_rec20.MODULE_COMPONENT_REF
     , SDD_IGR_rec20.SUBCOMPONENT_REF
     , SDD_IGR_rec20.NAME
     , SDD_IGR_rec20.ITEM_GROUP_REF
     , SDD_IGR_rec20.PROMPT
     , SDD_IGR_rec20.IMPLEMENTATION_ITEM
     , SDD_IGR_rec20.STYLE
     , SDD_IGR_rec20.ORIENTATION
     , SDD_IGR_rec20.STACKED_FLAG
     , SDD_IGR_rec20.TAB_SCOPE
     , SDD_IGR_rec20.START_TAB
     , SDD_IGR_rec20.END_TAB
     , SDD_IGR_rec20.BREAK_GROUP_FLAG
     , SDD_IGR_rec20.BREAK_GROUP_STYLE
     , SDD_IGR_rec20.USRX0
     , SDD_IGR_rec20.USRX1
     , SDD_IGR_rec20.USRX2
     , SDD_IGR_rec20.USRX3
     , SDD_IGR_rec20.USRX4
     , SDD_IGR_rec20.USRX5
     , SDD_IGR_rec20.USRX6
     , SDD_IGR_rec20.USRX7
     , SDD_IGR_rec20.USRX8
     , SDD_IGR_rec20.USRX9
     , SDD_IGR_rec20.USRX10
     , SDD_IGR_rec20.USRX11
     , SDD_IGR_rec20.USRX12
     , SDD_IGR_rec20.USRX13
     , SDD_IGR_rec20.USRX14
     , SDD_IGR_rec20.USRX15
     , SDD_IGR_rec20.USRX16
     , SDD_IGR_rec20.USRX17
     , SDD_IGR_rec20.USRX18
     , SDD_IGR_rec20.USRX19
     , SDD_IGR_rec20.ITEM_GROUP_FOR
    );
  jr_reg_ver.vercopy_dependencies(SDD_IGR_rec20.irid, SDD_IGR_rec20.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_ITE_rec21 in SDD_ITE_cur21 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_ITE
    values (
       SDD_ITE_rec21.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_ITE_rec21.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_ITE_rec21.TYPES
     , SDD_ITE_rec21.ELEMENT_TYPE_NAME
     , SDD_ITE_rec21.DATE_CREATED
     , SDD_ITE_rec21.CREATED_BY
     , SDD_ITE_rec21.DATE_CHANGED
     , SDD_ITE_rec21.CHANGED_BY
     , SDD_ITE_rec21.NOTM
     , SDD_ITE_rec21.MODULE_UNIT_REF
     , SDD_ITE_rec21.SQL_QUERY_SET_REF
     , SDD_ITE_rec21.DETAIL_TABLE_USAGE_REF
     , SDD_ITE_rec21.COLUMN_REF
     , SDD_ITE_rec21.NAME
     , SDD_ITE_rec21.UNBOUND_TYPE
     , SDD_ITE_rec21.USAGE_SEQUENCE
     , SDD_ITE_rec21.INSERT_FLAG
     , SDD_ITE_rec21.UPDATE_FLAG
     , SDD_ITE_rec21.SELECT_FLAG
     , SDD_ITE_rec21.RANGE_SEARCH_FLAG
     , SDD_ITE_rec21.CONTEXT_OPTION_QUERY_FLAG
     , SDD_ITE_rec21.DISPLAY_FLAG
     , SDD_ITE_rec21.IMPLEMENTATION_ITEM
     , SDD_ITE_rec21.PROMPT
     , SDD_ITE_rec21.DISPLAY_TYPE
     , SDD_ITE_rec21.SHOW_MEANING
     , SDD_ITE_rec21.DISPLAY_WIDTH
     , SDD_ITE_rec21.DISPLAY_HEIGHT
     , SDD_ITE_rec21.JUSTIFICATION
     , SDD_ITE_rec21.DISPLAY_FORMAT
     , SDD_ITE_rec21.HIGHLIGHTING
     , SDD_ITE_rec21.TRUNCATE_FLAG
     , SDD_ITE_rec21.ITEM_GROUP_REF
     , SDD_ITE_rec21.CONTEXT_FLAG
     , SDD_ITE_rec21.START_TAB
     , SDD_ITE_rec21.END_TAB
     , SDD_ITE_rec21.ALIGN_PROMPT_FLAG
     , SDD_ITE_rec21.DOMAIN_REF
     , SDD_ITE_rec21.DATATYPE
     , SDD_ITE_rec21.DEFAULT_VALUE
     , SDD_ITE_rec21.NULLIFY_FLAG
     , SDD_ITE_rec21.ORDER_SEQUENCE
     , SDD_ITE_rec21.SORTING_ORDER
     , SDD_ITE_rec21.RESET_LEVEL
     , SDD_ITE_rec21.RESET_GROUP
     , SDD_ITE_rec21.SOFT_LOV
     , SDD_ITE_rec21.HINT_TEXT
     , SDD_ITE_rec21.HELP_CONTEXT_ID_SUFFIX
     , SDD_ITE_rec21.ITEM_TYPE
     , SDD_ITE_rec21.REMARK
     , SDD_ITE_rec21.ITEM_FOR
     , SDD_ITE_rec21.DEFAULT_VALUE_TYPE
     , SDD_ITE_rec21.MAXIMUM_LENGTH
     , SDD_ITE_rec21.USRX0
     , SDD_ITE_rec21.USRX1
     , SDD_ITE_rec21.USRX2
     , SDD_ITE_rec21.USRX3
     , SDD_ITE_rec21.USRX4
     , SDD_ITE_rec21.USRX5
     , SDD_ITE_rec21.USRX6
     , SDD_ITE_rec21.USRX7
     , SDD_ITE_rec21.USRX8
     , SDD_ITE_rec21.USRX9
     , SDD_ITE_rec21.USRX10
     , SDD_ITE_rec21.USRX11
     , SDD_ITE_rec21.USRX12
     , SDD_ITE_rec21.USRX13
     , SDD_ITE_rec21.USRX14
     , SDD_ITE_rec21.USRX15
     , SDD_ITE_rec21.USRX16
     , SDD_ITE_rec21.USRX17
     , SDD_ITE_rec21.USRX18
     , SDD_ITE_rec21.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_ITE_rec21.irid, SDD_ITE_rec21.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_MTI_rec22 in SDD_MTI_cur22 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_MTI
    values (
       SDD_MTI_rec22.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_MTI_rec22.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_MTI_rec22.TYPES
     , SDD_MTI_rec22.ELEMENT_TYPE_NAME
     , SDD_MTI_rec22.DATE_CREATED
     , SDD_MTI_rec22.CREATED_BY
     , SDD_MTI_rec22.DATE_CHANGED
     , SDD_MTI_rec22.CHANGED_BY
     , SDD_MTI_rec22.NOTM
     , SDD_MTI_rec22.MODULE_UNIT_REF
     , SDD_MTI_rec22.SQL_QUERY_SET_REF
     , SDD_MTI_rec22.TABLE_REF
     , SDD_MTI_rec22.ALIAS
     , SDD_MTI_rec22.NAME_IN_DATABASE
     , SDD_MTI_rec22.PARTITION_NAME
     , SDD_MTI_rec22.USAGE_TYPE
     , SDD_MTI_rec22.SELECT_DISTINCT_FLAG
     , SDD_MTI_rec22.MTI_REF
     , SDD_MTI_rec22.CONSTRAINT_REF
     , SDD_MTI_rec22.OUTER_JOIN_FLAG
     , SDD_MTI_rec22.NOT_EXISTS_FLAG
     , SDD_MTI_rec22.TREEWALK_JOIN_CONSTRAINT
     , SDD_MTI_rec22.CONSTRAINT_REF2
     , SDD_MTI_rec22.TREEWALK_DIRECTION
     , SDD_MTI_rec22.REMARK
     , SDD_MTI_rec22.REPORT_USAGE_TYPE
     , SDD_MTI_rec22.MTI_FOR
     , SDD_MTI_rec22.USRX0
     , SDD_MTI_rec22.USRX1
     , SDD_MTI_rec22.USRX2
     , SDD_MTI_rec22.USRX3
     , SDD_MTI_rec22.USRX4
     , SDD_MTI_rec22.USRX5
     , SDD_MTI_rec22.USRX6
     , SDD_MTI_rec22.USRX7
     , SDD_MTI_rec22.USRX8
     , SDD_MTI_rec22.USRX9
     , SDD_MTI_rec22.USRX10
     , SDD_MTI_rec22.USRX11
     , SDD_MTI_rec22.USRX12
     , SDD_MTI_rec22.USRX13
     , SDD_MTI_rec22.USRX14
     , SDD_MTI_rec22.USRX15
     , SDD_MTI_rec22.USRX16
     , SDD_MTI_rec22.USRX17
     , SDD_MTI_rec22.USRX18
     , SDD_MTI_rec22.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_MTI_rec22.irid, SDD_MTI_rec22.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_CNU_rec23 in SDD_CNU_cur23 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_CNU
    values (
       SDD_CNU_rec23.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_CNU_rec23.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_CNU_rec23.TYPES
     , SDD_CNU_rec23.ELEMENT_TYPE_NAME
     , SDD_CNU_rec23.DATE_CREATED
     , SDD_CNU_rec23.CREATED_BY
     , SDD_CNU_rec23.DATE_CHANGED
     , SDD_CNU_rec23.CHANGED_BY
     , SDD_CNU_rec23.NOTM
     , SDD_CNU_rec23.CONSTRAINT_REF
     , SDD_CNU_rec23.TABLE_USAGE_REF
    );
  jr_reg_ver.vercopy_dependencies(SDD_CNU_rec23.irid, SDD_CNU_rec23.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_SQS_rec24 in SDD_SQS_cur24 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_SQS
    values (
       SDD_SQS_rec24.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_SQS_rec24.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_SQS_rec24.TYPES
     , SDD_SQS_rec24.ELEMENT_TYPE_NAME
     , SDD_SQS_rec24.DATE_CREATED
     , SDD_SQS_rec24.CREATED_BY
     , SDD_SQS_rec24.DATE_CHANGED
     , SDD_SQS_rec24.CHANGED_BY
     , SDD_SQS_rec24.NOTM
     , SDD_SQS_rec24.MODULE_COMPONENT_REF
     , SDD_SQS_rec24.LIST_OF_VALUES_REF
     , SDD_SQS_rec24.NAME
     , SDD_SQS_rec24.SEQUENCE_NUMBER
     , SDD_SQS_rec24.USRX0
     , SDD_SQS_rec24.USRX1
     , SDD_SQS_rec24.USRX2
     , SDD_SQS_rec24.USRX3
     , SDD_SQS_rec24.USRX4
     , SDD_SQS_rec24.USRX5
     , SDD_SQS_rec24.USRX6
     , SDD_SQS_rec24.USRX7
     , SDD_SQS_rec24.USRX8
     , SDD_SQS_rec24.USRX9
     , SDD_SQS_rec24.USRX10
     , SDD_SQS_rec24.USRX11
     , SDD_SQS_rec24.USRX12
     , SDD_SQS_rec24.USRX13
     , SDD_SQS_rec24.USRX14
     , SDD_SQS_rec24.USRX15
     , SDD_SQS_rec24.USRX16
     , SDD_SQS_rec24.USRX17
     , SDD_SQS_rec24.USRX18
     , SDD_SQS_rec24.USRX19
     , SDD_SQS_rec24.SQL_QUERY_SET_FOR
    );
  jr_reg_ver.vercopy_dependencies(SDD_SQS_rec24.irid, SDD_SQS_rec24.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_PGD_rec25 in SDD_PGD_cur25 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_PGD
    values (
       SDD_PGD_rec25.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_PGD_rec25.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_PGD_rec25.TYPES
     , SDD_PGD_rec25.ELEMENT_TYPE_NAME
     , SDD_PGD_rec25.DATE_CREATED
     , SDD_PGD_rec25.CREATED_BY
     , SDD_PGD_rec25.DATE_CHANGED
     , SDD_PGD_rec25.CHANGED_BY
     , SDD_PGD_rec25.NOTM
     , SDD_PGD_rec25.PLSQL_MODULE_REF
     , SDD_PGD_rec25.GENERAL_MODULE_REF
     , SDD_PGD_rec25.NAME
     , SDD_PGD_rec25.DATA_CONSTRUCT_TYPE
     , SDD_PGD_rec25.SCOPE
     , SDD_PGD_rec25.SEQUENCE
     , SDD_PGD_rec25.DOMAIN_REF
     , SDD_PGD_rec25.DATASTRUCTURE_REF
     , SDD_PGD_rec25.COLUMN_REF
     , SDD_PGD_rec25.TABLE_DEFINITION_REF
     , SDD_PGD_rec25.ORACLE_TYPE_REF
     , SDD_PGD_rec25.VALUE_DATATYPE
     , SDD_PGD_rec25.VALUE_LENGTH
     , SDD_PGD_rec25.VALUE_SCALE
     , SDD_PGD_rec25.VALUE_DEFAULT
     , SDD_PGD_rec25.VALUE_DEFAULT_TYPE
     , SDD_PGD_rec25.OPTIONAL_FLAG
     , SDD_PGD_rec25.DELIMITER
     , SDD_PGD_rec25.ORACLE_ERROR_CODE_NUMBER
     , SDD_PGD_rec25.REMARK
     , SDD_PGD_rec25.DESCRIPTION
     , SDD_PGD_rec25.PROGRAM_DATUM_FOR
     , SDD_PGD_rec25.MODULE_TYPE_FOR
     , SDD_PGD_rec25.USRX0
     , SDD_PGD_rec25.USRX1
     , SDD_PGD_rec25.USRX2
     , SDD_PGD_rec25.USRX3
     , SDD_PGD_rec25.USRX4
     , SDD_PGD_rec25.USRX5
     , SDD_PGD_rec25.USRX6
     , SDD_PGD_rec25.USRX7
     , SDD_PGD_rec25.USRX8
     , SDD_PGD_rec25.USRX9
     , SDD_PGD_rec25.USRX10
     , SDD_PGD_rec25.USRX11
     , SDD_PGD_rec25.USRX12
     , SDD_PGD_rec25.USRX13
     , SDD_PGD_rec25.USRX14
     , SDD_PGD_rec25.USRX15
     , SDD_PGD_rec25.USRX16
     , SDD_PGD_rec25.USRX17
     , SDD_PGD_rec25.USRX18
     , SDD_PGD_rec25.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_PGD_rec25.irid, SDD_PGD_rec25.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_WIN_rec26 in SDD_WIN_cur26 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_WIN
    values (
       SDD_WIN_rec26.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_WIN_rec26.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_WIN_rec26.TYPES
     , SDD_WIN_rec26.ELEMENT_TYPE_NAME
     , SDD_WIN_rec26.DATE_CREATED
     , SDD_WIN_rec26.CREATED_BY
     , SDD_WIN_rec26.DATE_CHANGED
     , SDD_WIN_rec26.CHANGED_BY
     , SDD_WIN_rec26.NOTM
     , SDD_WIN_rec26.GENERAL_MODULE_REF
     , SDD_WIN_rec26.NAME
     , SDD_WIN_rec26.TITLE
     , SDD_WIN_rec26.IMPLEMENTATION_ITEM
     , SDD_WIN_rec26.SCROLLABLE_FLAG
     , SDD_WIN_rec26.REQ_WIDTH
     , SDD_WIN_rec26.REQ_HEIGHT
     , SDD_WIN_rec26.REQ_POSX
     , SDD_WIN_rec26.REQ_POSY
     , SDD_WIN_rec26.USRX0
     , SDD_WIN_rec26.USRX1
     , SDD_WIN_rec26.USRX2
     , SDD_WIN_rec26.USRX3
     , SDD_WIN_rec26.USRX4
     , SDD_WIN_rec26.USRX5
     , SDD_WIN_rec26.USRX6
     , SDD_WIN_rec26.USRX7
     , SDD_WIN_rec26.USRX8
     , SDD_WIN_rec26.USRX9
     , SDD_WIN_rec26.USRX10
     , SDD_WIN_rec26.USRX11
     , SDD_WIN_rec26.USRX12
     , SDD_WIN_rec26.USRX13
     , SDD_WIN_rec26.USRX14
     , SDD_WIN_rec26.USRX15
     , SDD_WIN_rec26.USRX16
     , SDD_WIN_rec26.USRX17
     , SDD_WIN_rec26.USRX18
     , SDD_WIN_rec26.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_WIN_rec26.irid, SDD_WIN_rec26.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  jr_reg_ver.vercopy_dependent_objects(SDD_ORT_ver.ivid, new_ivid);
  return new_ivid;
end SDD_ORT_ver;
/
create or replace function PK_SDD_ORT (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_ORT the_tab_new, SDD_ORT the_tab_old
  where  the_tab_new.ivid = PK_SDD_ORT.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_ORT.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_ORT;
/
create or replace function FK_ORT_TO_OOT (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ORACLE_OBJECT_TYPE_REF ref_value
  from   i$SDD_ORT the_tab
  where  the_tab.ivid = FK_ORT_TO_OOT.object_ivid
  and    the_tab.ORACLE_OBJECT_TYPE_REF is not null
  and    not exists (
             select null
             from   SDD_ORT foreign_tab
             where  the_tab.ORACLE_OBJECT_TYPE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4858, action);
  end loop;
  return is_ok;
end FK_ORT_TO_OOT;
/
create or replace function FK_DOI_TO_OSP_d (
el_ivid number
 ,IRID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, child_tab.types
  from   SDD_DOI child_tab
  where  child_tab.STORAGE_DEFINITION_REF=FK_DOI_TO_OSP_d.IRID
  ;
 is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
    insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid)
    select o.irid, o.ivid, o.table_irid
    from   SDD_DOI child_tab, i$sdd_object_versions o
    where  child_tab.STORAGE_DEFINITION_REF=FK_DOI_TO_OSP_d.IRID
    and    child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(el_ivid,el_type,ref.irid,ref.types,action);
  end loop;
  return is_ok;
end FK_DOI_TO_OSP_d;
/
create or replace function FK_DOI_TO_OSP2_d (
el_ivid number
 ,IRID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, child_tab.types
  from   SDD_DOI child_tab
  where  child_tab.SNAP_LOG_STORAGE_REF=FK_DOI_TO_OSP2_d.IRID
  ;
 is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
    insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid)
    select o.irid, o.ivid, o.table_irid
    from   SDD_DOI child_tab, i$sdd_object_versions o
    where  child_tab.SNAP_LOG_STORAGE_REF=FK_DOI_TO_OSP2_d.IRID
    and    child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(el_ivid,el_type,ref.irid,ref.types,action);
  end loop;
  return is_ok;
end FK_DOI_TO_OSP2_d;
/
create or replace function FK_INS_TO_OSP_d (
el_ivid number
 ,IRID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, child_tab.types
  from   SDD_INS child_tab
  where  child_tab.STORAGE_DEFINITION_REF=FK_INS_TO_OSP_d.IRID
  ;
 is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
    insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid)
    select o.irid, o.ivid, o.table_irid
    from   SDD_INS child_tab, i$sdd_object_versions o
    where  child_tab.STORAGE_DEFINITION_REF=FK_INS_TO_OSP_d.IRID
    and    child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(el_ivid,el_type,ref.irid,ref.types,action);
  end loop;
  return is_ok;
end FK_INS_TO_OSP_d;
/
create or replace function FK_ORS_TO_OSP_d (
el_ivid number
 ,IRID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, child_tab.types
  from   SDD_ORS child_tab
  where  child_tab.STORAGE_DEFINITION_REF=FK_ORS_TO_OSP_d.IRID
  ;
 is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
    insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid)
    select o.irid, o.ivid, o.table_irid
    from   SDD_ORS child_tab, i$sdd_object_versions o
    where  child_tab.STORAGE_DEFINITION_REF=FK_ORS_TO_OSP_d.IRID
    and    child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(el_ivid,el_type,ref.irid,ref.types,action);
  end loop;
  return is_ok;
end FK_ORS_TO_OSP_d;
/
create or replace function FK_OTB_TO_OSP_d (
el_ivid number
 ,IRID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, child_tab.types
  from   SDD_OTB child_tab
  where  child_tab.STORAGE_DEFINITION_REF=FK_OTB_TO_OSP_d.IRID
  ;
 is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
    insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid)
    select o.irid, o.ivid, o.table_irid
    from   SDD_OTB child_tab, i$sdd_object_versions o
    where  child_tab.STORAGE_DEFINITION_REF=FK_OTB_TO_OSP_d.IRID
    and    child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(el_ivid,el_type,ref.irid,ref.types,action);
  end loop;
  return is_ok;
end FK_OTB_TO_OSP_d;
/
create or replace function SDD_OSP_ver (irid number, ivid number, copy_dependencies boolean default true) return number as
  new_ivid           number; -- new ivid of primary object
  new_secondary_ivid number; -- new ivid of secondary objects
  cursor SDD_OSP_cur is
    select *
    from   i$SDD_OSP the_tab
    where  the_tab.irid=SDD_OSP_ver.irid
    and    the_tab.ivid=SDD_OSP_ver.ivid;
  SDD_OSP_rec SDD_OSP_cur%ROWTYPE;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_OSP_cur;
  fetch SDD_OSP_cur into SDD_OSP_rec;
  close SDD_OSP_cur;
  insert into i$SDD_OSP
  values (
    SDD_OSP_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_OSP_rec.TYPES
   ,SDD_OSP_rec.ELEMENT_TYPE_NAME
   ,SDD_OSP_rec.DATE_CREATED
   ,SDD_OSP_rec.CREATED_BY
   ,SDD_OSP_rec.DATE_CHANGED
   ,SDD_OSP_rec.CHANGED_BY
   ,SDD_OSP_rec.NOTM
   ,SDD_OSP_rec.NAME
   ,SDD_OSP_rec.INITIAL_EXTENT
   ,SDD_OSP_rec.INITIAL_EXTENT_UNIT
   ,SDD_OSP_rec.NEXT_EXTENT
   ,SDD_OSP_rec.NEXT_EXTENT_UNIT
   ,SDD_OSP_rec.MINIMUM_EXTENTS
   ,SDD_OSP_rec.MAXIMUM_EXTENTS
   ,SDD_OSP_rec.UNLIMITED_FLAG
   ,SDD_OSP_rec.PCT_INCREASE
   ,SDD_OSP_rec.FREELIST_GROUPS
   ,SDD_OSP_rec.FREELISTS
   ,SDD_OSP_rec.REMARK
   ,SDD_OSP_rec.USRX0
   ,SDD_OSP_rec.USRX1
   ,SDD_OSP_rec.USRX2
   ,SDD_OSP_rec.USRX3
   ,SDD_OSP_rec.USRX4
   ,SDD_OSP_rec.USRX5
   ,SDD_OSP_rec.USRX6
   ,SDD_OSP_rec.USRX7
   ,SDD_OSP_rec.USRX8
   ,SDD_OSP_rec.USRX9
   ,SDD_OSP_rec.USRX10
   ,SDD_OSP_rec.USRX11
   ,SDD_OSP_rec.USRX12
   ,SDD_OSP_rec.USRX13
   ,SDD_OSP_rec.USRX14
   ,SDD_OSP_rec.USRX15
   ,SDD_OSP_rec.USRX16
   ,SDD_OSP_rec.USRX17
   ,SDD_OSP_rec.USRX18
   ,SDD_OSP_rec.USRX19
  );
  jr_reg_ver.vercopy_dependencies(SDD_OSP_ver.irid, SDD_OSP_ver.ivid, new_ivid, null, copy_dependencies);
  jr_reg_ver.vercopy_dependent_objects(SDD_OSP_ver.ivid, new_ivid);
  return new_ivid;
end SDD_OSP_ver;
/
create or replace function PK_SDD_OSP (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_OSP the_tab_new, SDD_OSP the_tab_old
  where  the_tab_new.ivid = PK_SDD_OSP.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_OSP.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_OSP;
/
create or replace function FK_COL_TO_OSQ_d (
el_ivid number
 ,IRID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, child_tab.types
  from   SDD_COL child_tab
  where  child_tab.SEQUENCE_REF=FK_COL_TO_OSQ_d.IRID
  ;
 is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
    insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid)
    select o.irid, o.ivid, o.table_irid
    from   SDD_COL child_tab, i$sdd_object_versions o
    where  child_tab.SEQUENCE_REF=FK_COL_TO_OSQ_d.IRID
    and    child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(el_ivid,el_type,ref.irid,ref.types,action);
  end loop;
  return is_ok;
end FK_COL_TO_OSQ_d;
/
create or replace function SDD_OSQ_ver (irid number, ivid number, copy_dependencies boolean default true) return number as
  new_ivid           number; -- new ivid of primary object
  new_secondary_ivid number; -- new ivid of secondary objects
  cursor SDD_OSQ_cur is
    select *
    from   i$SDD_OSQ the_tab
    where  the_tab.irid=SDD_OSQ_ver.irid
    and    the_tab.ivid=SDD_OSQ_ver.ivid;
  SDD_OSQ_rec SDD_OSQ_cur%ROWTYPE;
  cursor SDD_DSY_cur1 is
    select *
    from i$SDD_DSY the_tab
    where the_tab.parent_ivid=SDD_OSQ_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_OSQ_cur;
  fetch SDD_OSQ_cur into SDD_OSQ_rec;
  close SDD_OSQ_cur;
  insert into i$SDD_OSQ
  values (
    SDD_OSQ_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_OSQ_rec.TYPES
   ,SDD_OSQ_rec.ELEMENT_TYPE_NAME
   ,SDD_OSQ_rec.DATE_CREATED
   ,SDD_OSQ_rec.CREATED_BY
   ,SDD_OSQ_rec.DATE_CHANGED
   ,SDD_OSQ_rec.CHANGED_BY
   ,SDD_OSQ_rec.NOTM
   ,SDD_OSQ_rec.NAME
   ,SDD_OSQ_rec.SEQUENCE_TYPE
   ,SDD_OSQ_rec.PURPOSE
   ,SDD_OSQ_rec.REMARK
   ,SDD_OSQ_rec.USRX0
   ,SDD_OSQ_rec.USRX1
   ,SDD_OSQ_rec.USRX2
   ,SDD_OSQ_rec.USRX3
   ,SDD_OSQ_rec.USRX4
   ,SDD_OSQ_rec.USRX5
   ,SDD_OSQ_rec.USRX6
   ,SDD_OSQ_rec.USRX7
   ,SDD_OSQ_rec.USRX8
   ,SDD_OSQ_rec.USRX9
   ,SDD_OSQ_rec.USRX10
   ,SDD_OSQ_rec.USRX11
   ,SDD_OSQ_rec.USRX12
   ,SDD_OSQ_rec.USRX13
   ,SDD_OSQ_rec.USRX14
   ,SDD_OSQ_rec.USRX15
   ,SDD_OSQ_rec.USRX16
   ,SDD_OSQ_rec.USRX17
   ,SDD_OSQ_rec.USRX18
   ,SDD_OSQ_rec.USRX19
  );
  jr_reg_ver.vercopy_dependencies(SDD_OSQ_ver.irid, SDD_OSQ_ver.ivid, new_ivid, null, copy_dependencies);
  for SDD_DSY_rec1 in SDD_DSY_cur1 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_DSY
    values (
       SDD_DSY_rec1.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_DSY_rec1.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_DSY_rec1.TYPES
     , SDD_DSY_rec1.ELEMENT_TYPE_NAME
     , SDD_DSY_rec1.DATE_CREATED
     , SDD_DSY_rec1.CREATED_BY
     , SDD_DSY_rec1.DATE_CHANGED
     , SDD_DSY_rec1.CHANGED_BY
     , SDD_DSY_rec1.NOTM
     , SDD_DSY_rec1.TABLE_DEFINITION_REF
     , SDD_DSY_rec1.VIEW_DEFINITION_REF
     , SDD_DSY_rec1.SNAPSHOT_DEFINITION_REF
     , SDD_DSY_rec1.SEQUENCE_REF
     , SDD_DSY_rec1.PLSQL_MODULE_REF
     , SDD_DSY_rec1.JAVA_MODULE_REF
     , SDD_DSY_rec1.NAME
     , SDD_DSY_rec1.SCOPE
     , SDD_DSY_rec1.COMPLETE_FLAG
     , SDD_DSY_rec1.SYNONYM_FOR
     , SDD_DSY_rec1.USRX0
     , SDD_DSY_rec1.USRX1
     , SDD_DSY_rec1.USRX2
     , SDD_DSY_rec1.USRX3
     , SDD_DSY_rec1.USRX4
     , SDD_DSY_rec1.USRX5
     , SDD_DSY_rec1.USRX6
     , SDD_DSY_rec1.USRX7
     , SDD_DSY_rec1.USRX8
     , SDD_DSY_rec1.USRX9
     , SDD_DSY_rec1.USRX10
     , SDD_DSY_rec1.USRX11
     , SDD_DSY_rec1.USRX12
     , SDD_DSY_rec1.USRX13
     , SDD_DSY_rec1.USRX14
     , SDD_DSY_rec1.USRX15
     , SDD_DSY_rec1.USRX16
     , SDD_DSY_rec1.USRX17
     , SDD_DSY_rec1.USRX18
     , SDD_DSY_rec1.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_DSY_rec1.irid, SDD_DSY_rec1.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  jr_reg_ver.vercopy_dependent_objects(SDD_OSQ_ver.ivid, new_ivid);
  return new_ivid;
end SDD_OSQ_ver;
/
create or replace function PK_SDD_OSQ (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_OSQ the_tab_new, SDD_OSQ the_tab_old
  where  the_tab_new.ivid = PK_SDD_OSQ.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_OSQ.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_OSQ;
/
create or replace function PK_SDD_OST (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_OST the_tab_new, SDD_OST the_tab_old
  where  the_tab_new.ivid = PK_SDD_OST.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_OST.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_OST;
/
create or replace function FK_OST_TO_FILES (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ICON_FILE_REF ref_value
  from   i$SDD_OST the_tab
  where  the_tab.ivid = FK_OST_TO_FILES.object_ivid
  and    the_tab.ICON_FILE_REF is not null
  and    not exists (
             select null
             from   SDD_FILES foreign_tab
             where  the_tab.ICON_FILE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4819, action);
  end loop;
  return is_ok;
end FK_OST_TO_FILES;
/
create or replace function PK_SDD_OSTOST (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_OSTOST the_tab_new, SDD_OSTOST the_tab_old
  where  the_tab_new.ivid = PK_SDD_OSTOST.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_OSTOST.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_OSTOST;
/
create or replace function FK_OSTOST_TO_OST2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.OBJECT_STATE_OF_REF ref_value
  from   i$SDD_OSTOST the_tab
  where  the_tab.ivid = FK_OSTOST_TO_OST2.object_ivid
  and    the_tab.OBJECT_STATE_OF_REF is not null
  and    not exists (
             select null
             from   SDD_OST foreign_tab
             where  the_tab.OBJECT_STATE_OF_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4831, action);
  end loop;
  return is_ok;
end FK_OSTOST_TO_OST2;
/
create or replace function FK_DBU_TO_OTB_cmd (irid number, ivid number) return boolean as
cursor bad_cur is
  select child_tab.irid child_irid, child_tab.types child_type
        ,parent_tab.ivid par_ivid, parent_tab.types par_type
  from   SDD_DBU child_tab, i$SDD_OTB parent_tab
  where  parent_tab.parent_ivid=FK_DBU_TO_OTB_cmd.ivid
  and    child_tab.DEFAULT_TABLESPACE_REF=parent_tab.IRID
  ;
  is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
   insert into I$SDD_INVALID_OBJECTS(object_irid,object_ivid,table_irid)
    select o.irid,o.ivid,o.table_irid
      from SDD_DBU child_tab
          ,i$SDD_OTB parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_DBU_TO_OTB_cmd.ivid
       and child_tab.DEFAULT_TABLESPACE_REF=parent_tab.IRID
       and child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(ref.par_ivid,ref.par_type,ref.child_irid,ref.child_type,'DEL');
  end loop;
  return is_ok;
end FK_DBU_TO_OTB_cmd;
/
create or replace function FK_DBU_TO_OTB_d (
el_ivid number
 ,IRID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, child_tab.types
  from   SDD_DBU child_tab
  where  child_tab.DEFAULT_TABLESPACE_REF=FK_DBU_TO_OTB_d.IRID
  ;
 is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
    insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid)
    select o.irid, o.ivid, o.table_irid
    from   SDD_DBU child_tab, i$sdd_object_versions o
    where  child_tab.DEFAULT_TABLESPACE_REF=FK_DBU_TO_OTB_d.IRID
    and    child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(el_ivid,el_type,ref.irid,ref.types,action);
  end loop;
  return is_ok;
end FK_DBU_TO_OTB_d;
/
create or replace function FK_DBU_TO_OTB2_cmd (irid number, ivid number) return boolean as
cursor bad_cur is
  select child_tab.irid child_irid, child_tab.types child_type
        ,parent_tab.ivid par_ivid, parent_tab.types par_type
  from   SDD_DBU child_tab, i$SDD_OTB parent_tab
  where  parent_tab.parent_ivid=FK_DBU_TO_OTB2_cmd.ivid
  and    child_tab.TEMP_TABLESPACE_REF=parent_tab.IRID
  ;
  is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
   insert into I$SDD_INVALID_OBJECTS(object_irid,object_ivid,table_irid)
    select o.irid,o.ivid,o.table_irid
      from SDD_DBU child_tab
          ,i$SDD_OTB parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_DBU_TO_OTB2_cmd.ivid
       and child_tab.TEMP_TABLESPACE_REF=parent_tab.IRID
       and child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(ref.par_ivid,ref.par_type,ref.child_irid,ref.child_type,'DEL');
  end loop;
  return is_ok;
end FK_DBU_TO_OTB2_cmd;
/
create or replace function FK_DBU_TO_OTB2_d (
el_ivid number
 ,IRID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, child_tab.types
  from   SDD_DBU child_tab
  where  child_tab.TEMP_TABLESPACE_REF=FK_DBU_TO_OTB2_d.IRID
  ;
 is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
    insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid)
    select o.irid, o.ivid, o.table_irid
    from   SDD_DBU child_tab, i$sdd_object_versions o
    where  child_tab.TEMP_TABLESPACE_REF=FK_DBU_TO_OTB2_d.IRID
    and    child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(el_ivid,el_type,ref.irid,ref.types,action);
  end loop;
  return is_ok;
end FK_DBU_TO_OTB2_d;
/
create or replace function FK_DOI_TO_OTB_cmd (irid number, ivid number) return boolean as
cursor bad_cur is
  select child_tab.irid child_irid, child_tab.types child_type
        ,parent_tab.ivid par_ivid, parent_tab.types par_type
  from   SDD_DOI child_tab, i$SDD_OTB parent_tab
  where  parent_tab.parent_ivid=FK_DOI_TO_OTB_cmd.ivid
  and    child_tab.TABLESPACE_REF=parent_tab.IRID
  ;
  is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
   insert into I$SDD_INVALID_OBJECTS(object_irid,object_ivid,table_irid)
    select o.irid,o.ivid,o.table_irid
      from SDD_DOI child_tab
          ,i$SDD_OTB parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_DOI_TO_OTB_cmd.ivid
       and child_tab.TABLESPACE_REF=parent_tab.IRID
       and child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(ref.par_ivid,ref.par_type,ref.child_irid,ref.child_type,'DEL');
  end loop;
  return is_ok;
end FK_DOI_TO_OTB_cmd;
/
create or replace function FK_DOI_TO_OTB_d (
el_ivid number
 ,IRID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, child_tab.types
  from   SDD_DOI child_tab
  where  child_tab.TABLESPACE_REF=FK_DOI_TO_OTB_d.IRID
  ;
 is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
    insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid)
    select o.irid, o.ivid, o.table_irid
    from   SDD_DOI child_tab, i$sdd_object_versions o
    where  child_tab.TABLESPACE_REF=FK_DOI_TO_OTB_d.IRID
    and    child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(el_ivid,el_type,ref.irid,ref.types,action);
  end loop;
  return is_ok;
end FK_DOI_TO_OTB_d;
/
create or replace function FK_DOI_TO_OTB2_cmd (irid number, ivid number) return boolean as
cursor bad_cur is
  select child_tab.irid child_irid, child_tab.types child_type
        ,parent_tab.ivid par_ivid, parent_tab.types par_type
  from   SDD_DOI child_tab, i$SDD_OTB parent_tab
  where  parent_tab.parent_ivid=FK_DOI_TO_OTB2_cmd.ivid
  and    child_tab.OVERFLOW_TABLESPACE_REF=parent_tab.IRID
  ;
  is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
   insert into I$SDD_INVALID_OBJECTS(object_irid,object_ivid,table_irid)
    select o.irid,o.ivid,o.table_irid
      from SDD_DOI child_tab
          ,i$SDD_OTB parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_DOI_TO_OTB2_cmd.ivid
       and child_tab.OVERFLOW_TABLESPACE_REF=parent_tab.IRID
       and child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(ref.par_ivid,ref.par_type,ref.child_irid,ref.child_type,'DEL');
  end loop;
  return is_ok;
end FK_DOI_TO_OTB2_cmd;
/
create or replace function FK_DOI_TO_OTB2_d (
el_ivid number
 ,IRID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, child_tab.types
  from   SDD_DOI child_tab
  where  child_tab.OVERFLOW_TABLESPACE_REF=FK_DOI_TO_OTB2_d.IRID
  ;
 is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
    insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid)
    select o.irid, o.ivid, o.table_irid
    from   SDD_DOI child_tab, i$sdd_object_versions o
    where  child_tab.OVERFLOW_TABLESPACE_REF=FK_DOI_TO_OTB2_d.IRID
    and    child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(el_ivid,el_type,ref.irid,ref.types,action);
  end loop;
  return is_ok;
end FK_DOI_TO_OTB2_d;
/
create or replace function FK_DOI_TO_OTB3_cmd (irid number, ivid number) return boolean as
cursor bad_cur is
  select child_tab.irid child_irid, child_tab.types child_type
        ,parent_tab.ivid par_ivid, parent_tab.types par_type
  from   SDD_DOI child_tab, i$SDD_OTB parent_tab
  where  parent_tab.parent_ivid=FK_DOI_TO_OTB3_cmd.ivid
  and    child_tab.SNAP_LOG_TABLESPACE_REF=parent_tab.IRID
  ;
  is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
   insert into I$SDD_INVALID_OBJECTS(object_irid,object_ivid,table_irid)
    select o.irid,o.ivid,o.table_irid
      from SDD_DOI child_tab
          ,i$SDD_OTB parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_DOI_TO_OTB3_cmd.ivid
       and child_tab.SNAP_LOG_TABLESPACE_REF=parent_tab.IRID
       and child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(ref.par_ivid,ref.par_type,ref.child_irid,ref.child_type,'DEL');
  end loop;
  return is_ok;
end FK_DOI_TO_OTB3_cmd;
/
create or replace function FK_DOI_TO_OTB3_d (
el_ivid number
 ,IRID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, child_tab.types
  from   SDD_DOI child_tab
  where  child_tab.SNAP_LOG_TABLESPACE_REF=FK_DOI_TO_OTB3_d.IRID
  ;
 is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
    insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid)
    select o.irid, o.ivid, o.table_irid
    from   SDD_DOI child_tab, i$sdd_object_versions o
    where  child_tab.SNAP_LOG_TABLESPACE_REF=FK_DOI_TO_OTB3_d.IRID
    and    child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(el_ivid,el_type,ref.irid,ref.types,action);
  end loop;
  return is_ok;
end FK_DOI_TO_OTB3_d;
/
create or replace function FK_INS_TO_OTB_cmd (irid number, ivid number) return boolean as
cursor bad_cur is
  select child_tab.irid child_irid, child_tab.types child_type
        ,parent_tab.ivid par_ivid, parent_tab.types par_type
  from   SDD_INS child_tab, i$SDD_OTB parent_tab
  where  parent_tab.parent_ivid=FK_INS_TO_OTB_cmd.ivid
  and    child_tab.TABLESPACE_REF=parent_tab.IRID
  ;
  is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
   insert into I$SDD_INVALID_OBJECTS(object_irid,object_ivid,table_irid)
    select o.irid,o.ivid,o.table_irid
      from SDD_INS child_tab
          ,i$SDD_OTB parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_INS_TO_OTB_cmd.ivid
       and child_tab.TABLESPACE_REF=parent_tab.IRID
       and child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(ref.par_ivid,ref.par_type,ref.child_irid,ref.child_type,'DEL');
  end loop;
  return is_ok;
end FK_INS_TO_OTB_cmd;
/
create or replace function FK_INS_TO_OTB_d (
el_ivid number
 ,IRID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, child_tab.types
  from   SDD_INS child_tab
  where  child_tab.TABLESPACE_REF=FK_INS_TO_OTB_d.IRID
  ;
 is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
    insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid)
    select o.irid, o.ivid, o.table_irid
    from   SDD_INS child_tab, i$sdd_object_versions o
    where  child_tab.TABLESPACE_REF=FK_INS_TO_OTB_d.IRID
    and    child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(el_ivid,el_type,ref.irid,ref.types,action);
  end loop;
  return is_ok;
end FK_INS_TO_OTB_d;
/
create or replace function FK_ORS_TO_OTB_cmd (irid number, ivid number) return boolean as
cursor bad_cur is
  select child_tab.irid child_irid, child_tab.types child_type
        ,parent_tab.ivid par_ivid, parent_tab.types par_type
  from   SDD_ORS child_tab, i$SDD_OTB parent_tab
  where  parent_tab.parent_ivid=FK_ORS_TO_OTB_cmd.ivid
  and    child_tab.TABLESPACE_REF=parent_tab.IRID
  ;
  is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
   insert into I$SDD_INVALID_OBJECTS(object_irid,object_ivid,table_irid)
    select o.irid,o.ivid,o.table_irid
      from SDD_ORS child_tab
          ,i$SDD_OTB parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_ORS_TO_OTB_cmd.ivid
       and child_tab.TABLESPACE_REF=parent_tab.IRID
       and child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(ref.par_ivid,ref.par_type,ref.child_irid,ref.child_type,'DEL');
  end loop;
  return is_ok;
end FK_ORS_TO_OTB_cmd;
/
create or replace function FK_ORS_TO_OTB_d (
el_ivid number
 ,IRID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, child_tab.types
  from   SDD_ORS child_tab
  where  child_tab.TABLESPACE_REF=FK_ORS_TO_OTB_d.IRID
  ;
 is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
    insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid)
    select o.irid, o.ivid, o.table_irid
    from   SDD_ORS child_tab, i$sdd_object_versions o
    where  child_tab.TABLESPACE_REF=FK_ORS_TO_OTB_d.IRID
    and    child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(el_ivid,el_type,ref.irid,ref.types,action);
  end loop;
  return is_ok;
end FK_ORS_TO_OTB_d;
/
create or replace function FK_TBP_TO_OTB_cmd (irid number, ivid number) return boolean as
cursor bad_cur is
  select child_tab.irid child_irid, child_tab.types child_type
        ,parent_tab.ivid par_ivid, parent_tab.types par_type
  from   SDD_TBP child_tab, i$SDD_OTB parent_tab
  where  parent_tab.parent_ivid=FK_TBP_TO_OTB_cmd.ivid
  and    child_tab.TABLESPACE_REF=parent_tab.IRID
  ;
  is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
   insert into I$SDD_INVALID_OBJECTS(object_irid,object_ivid,table_irid)
    select o.irid,o.ivid,o.table_irid
      from SDD_TBP child_tab
          ,i$SDD_OTB parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_TBP_TO_OTB_cmd.ivid
       and child_tab.TABLESPACE_REF=parent_tab.IRID
       and child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(ref.par_ivid,ref.par_type,ref.child_irid,ref.child_type,'DEL');
  end loop;
  return is_ok;
end FK_TBP_TO_OTB_cmd;
/
create or replace function FK_TBP_TO_OTB_d (
el_ivid number
 ,IRID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, child_tab.types
  from   SDD_TBP child_tab
  where  child_tab.TABLESPACE_REF=FK_TBP_TO_OTB_d.IRID
  ;
 is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
    insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid)
    select o.irid, o.ivid, o.table_irid
    from   SDD_TBP child_tab, i$sdd_object_versions o
    where  child_tab.TABLESPACE_REF=FK_TBP_TO_OTB_d.IRID
    and    child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(el_ivid,el_type,ref.irid,ref.types,action);
  end loop;
  return is_ok;
end FK_TBP_TO_OTB_d;
/
create or replace function FK_TSQ_TO_OTB_cmd (irid number, ivid number) return boolean as
cursor bad_cur is
  select child_tab.irid child_irid, child_tab.types child_type
        ,parent_tab.ivid par_ivid, parent_tab.types par_type
  from   SDD_TSQ child_tab, i$SDD_OTB parent_tab
  where  parent_tab.parent_ivid=FK_TSQ_TO_OTB_cmd.ivid
  and    child_tab.TABLESPACE_REF=parent_tab.IRID
  ;
  is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
   insert into I$SDD_INVALID_OBJECTS(object_irid,object_ivid,table_irid)
    select o.irid,o.ivid,o.table_irid
      from SDD_TSQ child_tab
          ,i$SDD_OTB parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_TSQ_TO_OTB_cmd.ivid
       and child_tab.TABLESPACE_REF=parent_tab.IRID
       and child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(ref.par_ivid,ref.par_type,ref.child_irid,ref.child_type,'DEL');
  end loop;
  return is_ok;
end FK_TSQ_TO_OTB_cmd;
/
create or replace function FK_TSQ_TO_OTB_d (
el_ivid number
 ,IRID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, child_tab.types
  from   SDD_TSQ child_tab
  where  child_tab.TABLESPACE_REF=FK_TSQ_TO_OTB_d.IRID
  ;
 is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
    insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid)
    select o.irid, o.ivid, o.table_irid
    from   SDD_TSQ child_tab, i$sdd_object_versions o
    where  child_tab.TABLESPACE_REF=FK_TSQ_TO_OTB_d.IRID
    and    child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(el_ivid,el_type,ref.irid,ref.types,action);
  end loop;
  return is_ok;
end FK_TSQ_TO_OTB_d;
/
create or replace function PK_SDD_OTB (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_OTB the_tab_new, SDD_OTB the_tab_old
  where  the_tab_new.ivid = PK_SDD_OTB.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_OTB.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_OTB;
/
create or replace function FK_OTB_TO_OSP (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.STORAGE_DEFINITION_REF ref_value
  from   i$SDD_OTB the_tab
  where  the_tab.ivid = FK_OTB_TO_OSP.object_ivid
  and    the_tab.STORAGE_DEFINITION_REF is not null
  and    not exists (
             select null
             from   SDD_OSP foreign_tab
             where  the_tab.STORAGE_DEFINITION_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5000, action);
  end loop;
  return is_ok;
end FK_OTB_TO_OSP;
/
create or replace function SDD_PER_ver (irid number, ivid number, copy_dependencies boolean default true) return number as
  new_ivid           number; -- new ivid of primary object
  new_secondary_ivid number; -- new ivid of secondary objects
  cursor SDD_PER_cur is
    select *
    from   i$SDD_PER the_tab
    where  the_tab.irid=SDD_PER_ver.irid
    and    the_tab.ivid=SDD_PER_ver.ivid;
  SDD_PER_rec SDD_PER_cur%ROWTYPE;
  cursor SDD_PERACR_cur1 is
    select *
    from i$SDD_PERACR the_tab
    where the_tab.parent_ivid=SDD_PER_ver.ivid;
  cursor SDD_PERPER_cur2 is
    select *
    from i$SDD_PERPER the_tab
    where the_tab.parent_ivid=SDD_PER_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_PER_cur;
  fetch SDD_PER_cur into SDD_PER_rec;
  close SDD_PER_cur;
  insert into i$SDD_PER
  values (
    SDD_PER_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_PER_rec.TYPES
   ,SDD_PER_rec.ELEMENT_TYPE_NAME
   ,SDD_PER_rec.DATE_CREATED
   ,SDD_PER_rec.CREATED_BY
   ,SDD_PER_rec.DATE_CHANGED
   ,SDD_PER_rec.CHANGED_BY
   ,SDD_PER_rec.NOTM
   ,SDD_PER_rec.NAME
   ,SDD_PER_rec.EMAIL_ADDRESS
   ,SDD_PER_rec.NLS_LANGUAGE
   ,SDD_PER_rec.NLS_TERRITORY
   ,SDD_PER_rec.STATUS
  );
  jr_reg_ver.vercopy_dependencies(SDD_PER_ver.irid, SDD_PER_ver.ivid, new_ivid, null, copy_dependencies);
  for SDD_PERACR_rec1 in SDD_PERACR_cur1 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_PERACR
    values (
       SDD_PERACR_rec1.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_PERACR_rec1.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_PERACR_rec1.TYPES
     , SDD_PERACR_rec1.ELEMENT_TYPE_NAME
     , SDD_PERACR_rec1.DATE_CREATED
     , SDD_PERACR_rec1.CREATED_BY
     , SDD_PERACR_rec1.DATE_CHANGED
     , SDD_PERACR_rec1.CHANGED_BY
     , SDD_PERACR_rec1.NOTM
     , SDD_PERACR_rec1.ACTOR_REF
     , SDD_PERACR_rec1.PERSON_REF
    );
  jr_reg_ver.vercopy_dependencies(SDD_PERACR_rec1.irid, SDD_PERACR_rec1.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_PERPER_rec2 in SDD_PERPER_cur2 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_PERPER
    values (
       SDD_PERPER_rec2.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_PERPER_rec2.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_PERPER_rec2.TYPES
     , SDD_PERPER_rec2.ELEMENT_TYPE_NAME
     , SDD_PERPER_rec2.DATE_CREATED
     , SDD_PERPER_rec2.CREATED_BY
     , SDD_PERPER_rec2.DATE_CHANGED
     , SDD_PERPER_rec2.CHANGED_BY
     , SDD_PERPER_rec2.NOTM
     , SDD_PERPER_rec2.MANAGER_REF
     , SDD_PERPER_rec2.MANAGED_PERSON_REF
     , SDD_PERPER_rec2.REPORTS_TO_FLAG
    );
  jr_reg_ver.vercopy_dependencies(SDD_PERPER_rec2.irid, SDD_PERPER_rec2.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  jr_reg_ver.vercopy_dependent_objects(SDD_PER_ver.ivid, new_ivid);
  return new_ivid;
end SDD_PER_ver;
/
create or replace function PK_SDD_PER (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_PER the_tab_new, SDD_PER the_tab_old
  where  the_tab_new.ivid = PK_SDD_PER.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_PER.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_PER;
/
create or replace function PK_SDD_PERACR (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_PERACR the_tab_new, SDD_PERACR the_tab_old
  where  the_tab_new.ivid = PK_SDD_PERACR.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_PERACR.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_PERACR;
/
create or replace function FK_PERACR_TO_ACR (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ACTOR_REF ref_value
  from   i$SDD_PERACR the_tab
  where  the_tab.ivid = FK_PERACR_TO_ACR.object_ivid
  and    the_tab.ACTOR_REF is not null
  and    not exists (
             select null
             from   SDD_ACR foreign_tab
             where  the_tab.ACTOR_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4840, action);
  end loop;
  return is_ok;
end FK_PERACR_TO_ACR;
/
create or replace function PK_SDD_PERPER (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_PERPER the_tab_new, SDD_PERPER the_tab_old
  where  the_tab_new.ivid = PK_SDD_PERPER.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_PERPER.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_PERPER;
/
create or replace function FK_PERPER_TO_PER2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.MANAGED_PERSON_REF ref_value
  from   i$SDD_PERPER the_tab
  where  the_tab.ivid = FK_PERPER_TO_PER2.object_ivid
  and    the_tab.MANAGED_PERSON_REF is not null
  and    not exists (
             select null
             from   SDD_PER foreign_tab
             where  the_tab.MANAGED_PERSON_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4835, action);
  end loop;
  return is_ok;
end FK_PERPER_TO_PER2;
/
create or replace function FK_ITM_TO_PGD_cmd (irid number, ivid number) return boolean as
cursor bad_cur is
  select child_tab.irid child_irid, child_tab.types child_type
        ,parent_tab.ivid par_ivid, parent_tab.types par_type
  from   SDD_ITM child_tab, i$SDD_PGD parent_tab
  where  parent_tab.parent_ivid=FK_ITM_TO_PGD_cmd.ivid
  and    child_tab.PROGRAM_DATUM_REF=parent_tab.IRID
  ;
  is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
   insert into I$SDD_INVALID_OBJECTS(object_irid,object_ivid,table_irid)
    select o.irid,o.ivid,o.table_irid
      from SDD_ITM child_tab
          ,i$SDD_PGD parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_ITM_TO_PGD_cmd.ivid
       and child_tab.PROGRAM_DATUM_REF=parent_tab.IRID
       and child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(ref.par_ivid,ref.par_type,ref.child_irid,ref.child_type,'DEL');
  end loop;
  return is_ok;
end FK_ITM_TO_PGD_cmd;
/
create or replace function FK_ITM_TO_PGD_d (
el_ivid number
 ,IRID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, child_tab.types
  from   SDD_ITM child_tab
  where  child_tab.PROGRAM_DATUM_REF=FK_ITM_TO_PGD_d.IRID
  ;
 is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
    insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid)
    select o.irid, o.ivid, o.table_irid
    from   SDD_ITM child_tab, i$sdd_object_versions o
    where  child_tab.PROGRAM_DATUM_REF=FK_ITM_TO_PGD_d.IRID
    and    child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(el_ivid,el_type,ref.irid,ref.types,action);
  end loop;
  return is_ok;
end FK_ITM_TO_PGD_d;
/
create or replace function PK_SDD_PGD (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_PGD the_tab_new, SDD_PGD the_tab_old
  where  the_tab_new.ivid = PK_SDD_PGD.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_PGD.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_PGD;
/
create or replace function FK_PGD_TO_COL (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.COLUMN_REF ref_value
  from   i$SDD_PGD the_tab
  where  the_tab.ivid = FK_PGD_TO_COL.object_ivid
  and    the_tab.COLUMN_REF is not null
  and    not exists (
             select null
             from   SDD_COL foreign_tab
             where  the_tab.COLUMN_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5014, action);
  end loop;
  return is_ok;
end FK_PGD_TO_COL;
/
create or replace function FK_PGD_TO_DAT (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.DATASTRUCTURE_REF ref_value
  from   i$SDD_PGD the_tab
  where  the_tab.ivid = FK_PGD_TO_DAT.object_ivid
  and    the_tab.DATASTRUCTURE_REF is not null
  and    not exists (
             select null
             from   SDD_DAT foreign_tab
             where  the_tab.DATASTRUCTURE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5045, action);
  end loop;
  return is_ok;
end FK_PGD_TO_DAT;
/
create or replace function FK_PGD_TO_DOM (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.DOMAIN_REF ref_value
  from   i$SDD_PGD the_tab
  where  the_tab.ivid = FK_PGD_TO_DOM.object_ivid
  and    the_tab.DOMAIN_REF is not null
  and    not exists (
             select null
             from   SDD_DOM foreign_tab
             where  the_tab.DOMAIN_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5020, action);
  end loop;
  return is_ok;
end FK_PGD_TO_DOM;
/
create or replace function FK_PGD_TO_GEM (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.GENERAL_MODULE_REF ref_value
  from   i$SDD_PGD the_tab
  where  the_tab.ivid = FK_PGD_TO_GEM.object_ivid
  and    the_tab.GENERAL_MODULE_REF is not null
  and    not exists (
             select null
             from   SDD_MOD foreign_tab
             where  the_tab.GENERAL_MODULE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5022, action);
  end loop;
  return is_ok;
end FK_PGD_TO_GEM;
/
create or replace function FK_PGD_TO_ORT (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ORACLE_TYPE_REF ref_value
  from   i$SDD_PGD the_tab
  where  the_tab.ivid = FK_PGD_TO_ORT.object_ivid
  and    the_tab.ORACLE_TYPE_REF is not null
  and    not exists (
             select null
             from   SDD_ORT foreign_tab
             where  the_tab.ORACLE_TYPE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4858, action);
  end loop;
  return is_ok;
end FK_PGD_TO_ORT;
/
create or replace function FK_PGD_TO_PLM (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.PLSQL_MODULE_REF ref_value
  from   i$SDD_PGD the_tab
  where  the_tab.ivid = FK_PGD_TO_PLM.object_ivid
  and    the_tab.PLSQL_MODULE_REF is not null
  and    not exists (
             select null
             from   SDD_MOD foreign_tab
             where  the_tab.PLSQL_MODULE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5022, action);
  end loop;
  return is_ok;
end FK_PGD_TO_PLM;
/
create or replace function FK_PGD_TO_TBL (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.TABLE_DEFINITION_REF ref_value
  from   i$SDD_PGD the_tab
  where  the_tab.ivid = FK_PGD_TO_TBL.object_ivid
  and    the_tab.TABLE_DEFINITION_REF is not null
  and    not exists (
             select null
             from   SDD_TAB foreign_tab
             where  the_tab.TABLE_DEFINITION_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4982, action);
  end loop;
  return is_ok;
end FK_PGD_TO_TBL;
/
create or replace function SDD_PRS_ver (irid number, ivid number, copy_dependencies boolean default true) return number as
  new_ivid           number; -- new ivid of primary object
  new_secondary_ivid number; -- new ivid of secondary objects
  cursor SDD_PRS_cur is
    select *
    from   i$SDD_PRS the_tab
    where  the_tab.irid=SDD_PRS_ver.irid
    and    the_tab.ivid=SDD_PRS_ver.ivid;
  SDD_PRS_rec SDD_PRS_cur%ROWTYPE;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_PRS_cur;
  fetch SDD_PRS_cur into SDD_PRS_rec;
  close SDD_PRS_cur;
  insert into i$SDD_PRS
  values (
    SDD_PRS_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_PRS_rec.TYPES
   ,SDD_PRS_rec.ELEMENT_TYPE_NAME
   ,SDD_PRS_rec.DATE_CREATED
   ,SDD_PRS_rec.CREATED_BY
   ,SDD_PRS_rec.DATE_CHANGED
   ,SDD_PRS_rec.CHANGED_BY
   ,SDD_PRS_rec.NOTM
   ,SDD_PRS_rec.NAME
   ,SDD_PRS_rec.PRODUCT_FLAVOR
   ,SDD_PRS_rec.FROZEN_FLAG
   ,SDD_PRS_rec.USRX0
   ,SDD_PRS_rec.USRX1
   ,SDD_PRS_rec.USRX2
   ,SDD_PRS_rec.USRX3
   ,SDD_PRS_rec.USRX4
   ,SDD_PRS_rec.USRX5
   ,SDD_PRS_rec.USRX6
   ,SDD_PRS_rec.USRX7
   ,SDD_PRS_rec.USRX8
   ,SDD_PRS_rec.USRX9
   ,SDD_PRS_rec.USRX10
   ,SDD_PRS_rec.USRX11
   ,SDD_PRS_rec.USRX12
   ,SDD_PRS_rec.USRX13
   ,SDD_PRS_rec.USRX14
   ,SDD_PRS_rec.USRX15
   ,SDD_PRS_rec.USRX16
   ,SDD_PRS_rec.USRX17
   ,SDD_PRS_rec.USRX18
   ,SDD_PRS_rec.USRX19
  );
  jr_reg_ver.vercopy_dependencies(SDD_PRS_ver.irid, SDD_PRS_ver.ivid, new_ivid, null, copy_dependencies);
  jr_reg_ver.vercopy_dependent_objects(SDD_PRS_ver.ivid, new_ivid);
  return new_ivid;
end SDD_PRS_ver;
/
create or replace function PK_SDD_PRS (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_PRS the_tab_new, SDD_PRS the_tab_old
  where  the_tab_new.ivid = PK_SDD_PRS.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_PRS.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_PRS;
/
create or replace function PK_SDD_PRU (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_PRU the_tab_new, SDD_PRU the_tab_old
  where  the_tab_new.ivid = PK_SDD_PRU.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_PRU.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_PRU;
/
create or replace function UK_PRU (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_PRU the_tab_new, SDD_PRU the_tab_old
  where  the_tab_new.ivid = UK_PRU.ivid
  and    the_tab_new.PREFERENCE_SET_REF = the_tab_old.PREFERENCE_SET_REF
  and    the_tab_new.CIELEMENT_REF = the_tab_old.CIELEMENT_REF
  and    the_tab_old.ivid != UK_PRU.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end UK_PRU;
/
create or replace function FK_PRU_TO_PRS (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.PREFERENCE_SET_REF ref_value
  from   i$SDD_PRU the_tab
  where  the_tab.ivid = FK_PRU_TO_PRS.object_ivid
  and    the_tab.PREFERENCE_SET_REF is not null
  and    not exists (
             select null
             from   SDD_PRS foreign_tab
             where  the_tab.PREFERENCE_SET_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4935, action);
  end loop;
  return is_ok;
end FK_PRU_TO_PRS;
/
create or replace function SDD_PSE_ver (irid number, ivid number, copy_dependencies boolean default true) return number as
  new_ivid           number; -- new ivid of primary object
  new_secondary_ivid number; -- new ivid of secondary objects
  cursor SDD_PSE_cur is
    select *
    from   i$SDD_PSE the_tab
    where  the_tab.irid=SDD_PSE_ver.irid
    and    the_tab.ivid=SDD_PSE_ver.ivid;
  SDD_PSE_rec SDD_PSE_cur%ROWTYPE;
  cursor SDD_TRA_cur1 is
    select *
    from i$SDD_TRA the_tab
    where the_tab.parent_ivid=SDD_PSE_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_PSE_cur;
  fetch SDD_PSE_cur into SDD_PSE_rec;
  close SDD_PSE_cur;
  insert into i$SDD_PSE
  values (
    SDD_PSE_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_PSE_rec.TYPES
   ,SDD_PSE_rec.ELEMENT_TYPE_NAME
   ,SDD_PSE_rec.DATE_CREATED
   ,SDD_PSE_rec.CREATED_BY
   ,SDD_PSE_rec.DATE_CHANGED
   ,SDD_PSE_rec.CHANGED_BY
   ,SDD_PSE_rec.NOTM
   ,SDD_PSE_rec.TYPE
   ,SDD_PSE_rec.SEQUENCE_NUMBER
   ,SDD_PSE_rec.TITLE
   ,SDD_PSE_rec.NAMED_RULE_REF
  );
  jr_reg_ver.vercopy_dependencies(SDD_PSE_ver.irid, SDD_PSE_ver.ivid, new_ivid, null, copy_dependencies);
  for SDD_TRA_rec1 in SDD_TRA_cur1 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_TRA
    values (
       SDD_TRA_rec1.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_TRA_rec1.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_TRA_rec1.TYPES
     , SDD_TRA_rec1.ELEMENT_TYPE_NAME
     , SDD_TRA_rec1.DATE_CREATED
     , SDD_TRA_rec1.CREATED_BY
     , SDD_TRA_rec1.DATE_CHANGED
     , SDD_TRA_rec1.CHANGED_BY
     , SDD_TRA_rec1.NOTM
     , SDD_TRA_rec1.SOURCE_ACTIVITY_REF
     , SDD_TRA_rec1.SOURCE_ACT_USAGE_REF
     , SDD_TRA_rec1.SOURCE_EVENT_REF
     , SDD_TRA_rec1.SOURCE_OBJECT_STATE_REF
     , SDD_TRA_rec1.SOURCE_PSEUDOSTATE_REF
     , SDD_TRA_rec1.TARGET_ACTIVITY_REF
     , SDD_TRA_rec1.TARGET_ACT_USAGE_REF
     , SDD_TRA_rec1.TARGET_EVENT_REF
     , SDD_TRA_rec1.TARGET_OBJECT_STATE_REF
     , SDD_TRA_rec1.TARGET_PSEUDOSTATE_REF
     , SDD_TRA_rec1.SEQUENCE_NUMBER
     , SDD_TRA_rec1.NAMED_RULE_REF
     , SDD_TRA_rec1.PRIMARY_FLAG
     , SDD_TRA_rec1.TRANSITION_REF
     , SDD_TRA_rec1.EVENT_PUBLICATION_REF
     , SDD_TRA_rec1.EVENT_SUBSCRIPTION_REF
     , SDD_TRA_rec1.CREATABLE_FLAG
     , SDD_TRA_rec1.MESSAGING_AUDIT
     , SDD_TRA_rec1.CHANNEL_NAME
     , SDD_TRA_rec1.RETRIEVABLE_FLAG
     , SDD_TRA_rec1.CHANNEL_TYPE
     , SDD_TRA_rec1.UPDATABLE_FLAG
     , SDD_TRA_rec1.AUTOMATIC_INVOCATION_FLAG
     , SDD_TRA_rec1.DELETABLE_FLAG
     , SDD_TRA_rec1.TRIGGERING_FLAG
     , SDD_TRA_rec1.ACTIVITY_SIGNATURE_FLAG
     , SDD_TRA_rec1.TRIGGER_EVENT_REF
     , SDD_TRA_rec1.SOURCE_TYPE
     , SDD_TRA_rec1.TARGET_TYPE
    );
  jr_reg_ver.vercopy_dependencies(SDD_TRA_rec1.irid, SDD_TRA_rec1.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  jr_reg_ver.vercopy_dependent_objects(SDD_PSE_ver.ivid, new_ivid);
  return new_ivid;
end SDD_PSE_ver;
/
create or replace function PK_SDD_PSE (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_PSE the_tab_new, SDD_PSE the_tab_old
  where  the_tab_new.ivid = PK_SDD_PSE.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_PSE.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_PSE;
/
create or replace function FK_PSE_TO_RUL (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.NAMED_RULE_REF ref_value
  from   i$SDD_PSE the_tab
  where  the_tab.ivid = FK_PSE_TO_RUL.object_ivid
  and    the_tab.NAMED_RULE_REF is not null
  and    not exists (
             select null
             from   SDD_RUL foreign_tab
             where  the_tab.NAMED_RULE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4833, action);
  end loop;
  return is_ok;
end FK_PSE_TO_RUL;
/
create or replace function SDD_PST_ver (irid number, ivid number, copy_dependencies boolean default true) return number as
  new_ivid           number; -- new ivid of primary object
  new_secondary_ivid number; -- new ivid of secondary objects
  cursor SDD_PST_cur is
    select *
    from   i$SDD_PST the_tab
    where  the_tab.irid=SDD_PST_ver.irid
    and    the_tab.ivid=SDD_PST_ver.ivid;
  SDD_PST_rec SDD_PST_cur%ROWTYPE;
  cursor SDD_PSTADC_cur1 is
    select *
    from i$SDD_PSTADC the_tab
    where the_tab.parent_ivid=SDD_PST_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_PST_cur;
  fetch SDD_PST_cur into SDD_PST_rec;
  close SDD_PST_cur;
  insert into i$SDD_PST
  values (
    SDD_PST_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_PST_rec.TYPES
   ,SDD_PST_rec.ELEMENT_TYPE_NAME
   ,SDD_PST_rec.DATE_CREATED
   ,SDD_PST_rec.CREATED_BY
   ,SDD_PST_rec.DATE_CHANGED
   ,SDD_PST_rec.CHANGED_BY
   ,SDD_PST_rec.NOTM
   ,SDD_PST_rec.NAME
   ,SDD_PST_rec.IMPLEMENTATION_TARGET
   ,SDD_PST_rec.ASSOCIATION_NAME_PREFIX
   ,SDD_PST_rec.TABLE_PREFIX
   ,SDD_PST_rec.ASSOCIATION_NAME_SUFFIX
   ,SDD_PST_rec.CREATE_RTL_PK_COLS_FLAG
   ,SDD_PST_rec.COLUMN_PREFIX
   ,SDD_PST_rec.GENERATE_COMMENTS_FLAG
   ,SDD_PST_rec.CLASS_NAME_PREFIX
   ,SDD_PST_rec.MM_ASSOC_IMPLEMENTATION
   ,SDD_PST_rec.CLASS_NAME_SUFFIX
   ,SDD_PST_rec.FK_CONSTRAINT_SUFFIX
   ,SDD_PST_rec.DATA_MEMBER_NAME_PREFIX
   ,SDD_PST_rec.DISCRIMINATOR_COLUMN_SUFFIX
   ,SDD_PST_rec.DATA_MEMBER_NAME_SUFFIX
   ,SDD_PST_rec.PK_CONSTRAINT_SUFFIX
   ,SDD_PST_rec.GENERATE_ACCESSORS_FLAG
   ,SDD_PST_rec.SURROGATE_PK_COLUMN_SUFFIX
   ,SDD_PST_rec.GENERATE_JAVA_IMP_STMTS_FLAG
   ,SDD_PST_rec.SEQUENCE_SUFFIX
   ,SDD_PST_rec.GENERATE_TS_COLL_CLASS_FLAG
   ,SDD_PST_rec.UPDATE_SERVER_MODEL_FLAG
   ,SDD_PST_rec.GENERATE_CREATE_METHOD_FLAG
   ,SDD_PST_rec.UK_CONSTRAINT_SUFFIX
   ,SDD_PST_rec.GENERATE_REMOVE_METHOD_FLAG
   ,SDD_PST_rec.GENERATE_DML_METHODS_FLAG
   ,SDD_PST_rec.ORACLE_ATT_PREFIX_FOR_ASS_ENDS
   ,SDD_PST_rec.ORACLE_COLLECTION_TYPE_PREFIX
   ,SDD_PST_rec.ORACLE_TYPE_SUFFIX
   ,SDD_PST_rec.PROJECT_STANDARD_SUBTYPE
  );
  jr_reg_ver.vercopy_dependencies(SDD_PST_ver.irid, SDD_PST_ver.ivid, new_ivid, null, copy_dependencies);
  for SDD_PSTADC_rec1 in SDD_PSTADC_cur1 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_PSTADC
    values (
       SDD_PSTADC_rec1.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_PSTADC_rec1.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_PSTADC_rec1.TYPES
     , SDD_PSTADC_rec1.ELEMENT_TYPE_NAME
     , SDD_PSTADC_rec1.DATE_CREATED
     , SDD_PSTADC_rec1.CREATED_BY
     , SDD_PSTADC_rec1.DATE_CHANGED
     , SDD_PSTADC_rec1.CHANGED_BY
     , SDD_PSTADC_rec1.NOTM
     , SDD_PSTADC_rec1.PROJECT_STANDARD_REF
     , SDD_PSTADC_rec1.ATTRIBUTE_DOMAIN_REF
     , SDD_PSTADC_rec1.MAPPING
    );
  jr_reg_ver.vercopy_dependencies(SDD_PSTADC_rec1.irid, SDD_PSTADC_rec1.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  jr_reg_ver.vercopy_dependent_objects(SDD_PST_ver.ivid, new_ivid);
  return new_ivid;
end SDD_PST_ver;
/
create or replace function PK_SDD_PST (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_PST the_tab_new, SDD_PST the_tab_old
  where  the_tab_new.ivid = PK_SDD_PST.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_PST.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_PST;
/
create or replace function PK_SDD_PSTADC (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_PSTADC the_tab_new, SDD_PSTADC the_tab_old
  where  the_tab_new.ivid = PK_SDD_PSTADC.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_PSTADC.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_PSTADC;
/
create or replace function FK_PSTADC_TO_ADC (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ATTRIBUTE_DOMAIN_REF ref_value
  from   i$SDD_PSTADC the_tab
  where  the_tab.ivid = FK_PSTADC_TO_ADC.object_ivid
  and    the_tab.ATTRIBUTE_DOMAIN_REF is not null
  and    not exists (
             select null
             from   SDD_CLA foreign_tab
             where  the_tab.ATTRIBUTE_DOMAIN_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4841, action);
  end loop;
  return is_ok;
end FK_PSTADC_TO_ADC;
/
create or replace function PK_SDD_PVL (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_PVL the_tab_new, SDD_PVL the_tab_old
  where  the_tab_new.ivid = PK_SDD_PVL.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_PVL.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_PVL;
/
create or replace function FK_PVL_TO_ARG (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.MODULE_ARGUMENT_REF ref_value
  from   i$SDD_PVL the_tab
  where  the_tab.ivid = FK_PVL_TO_ARG.object_ivid
  and    the_tab.MODULE_ARGUMENT_REF is not null
  and    not exists (
             select null
             from   SDD_ARG foreign_tab
             where  the_tab.MODULE_ARGUMENT_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4991, action);
  end loop;
  return is_ok;
end FK_PVL_TO_ARG;
/
create or replace function FK_PVL_TO_ARG2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.CALLED_ARGUMENT_REF ref_value
  from   i$SDD_PVL the_tab
  where  the_tab.ivid = FK_PVL_TO_ARG2.object_ivid
  and    the_tab.CALLED_ARGUMENT_REF is not null
  and    not exists (
             select null
             from   SDD_ARG foreign_tab
             where  the_tab.CALLED_ARGUMENT_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4991, action);
  end loop;
  return is_ok;
end FK_PVL_TO_ARG2;
/
create or replace function FK_PVL_TO_ITE (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ITEM_REF ref_value
  from   i$SDD_PVL the_tab
  where  the_tab.ivid = FK_PVL_TO_ITE.object_ivid
  and    the_tab.ITEM_REF is not null
  and    not exists (
             select null
             from   SDD_ITE foreign_tab
             where  the_tab.ITEM_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4997, action);
  end loop;
  return is_ok;
end FK_PVL_TO_ITE;
/
create or replace function PK_SDD_QSU (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_QSU the_tab_new, SDD_QSU the_tab_old
  where  the_tab_new.ivid = PK_SDD_QSU.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_QSU.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_QSU;
/
create or replace function FK_QUE_TO_QTD_d (
el_ivid number
 ,IRID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, child_tab.types
  from   SDD_QUE child_tab
  where  child_tab.QUEUE_TABLE_DEF_REF=FK_QUE_TO_QTD_d.IRID
  ;
 is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
    insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid)
    select o.irid, o.ivid, o.table_irid
    from   SDD_QUE child_tab, i$sdd_object_versions o
    where  child_tab.QUEUE_TABLE_DEF_REF=FK_QUE_TO_QTD_d.IRID
    and    child_tab.ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(el_ivid,el_type,ref.irid,ref.types,action);
  end loop;
  return is_ok;
end FK_QUE_TO_QTD_d;
/
create or replace function SDD_QTD_ver (irid number, ivid number, copy_dependencies boolean default true) return number as
  new_ivid           number; -- new ivid of primary object
  new_secondary_ivid number; -- new ivid of secondary objects
  cursor SDD_QTD_cur is
    select *
    from   i$SDD_QTD the_tab
    where  the_tab.irid=SDD_QTD_ver.irid
    and    the_tab.ivid=SDD_QTD_ver.ivid;
  SDD_QTD_rec SDD_QTD_cur%ROWTYPE;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_QTD_cur;
  fetch SDD_QTD_cur into SDD_QTD_rec;
  close SDD_QTD_cur;
  insert into i$SDD_QTD
  values (
    SDD_QTD_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_QTD_rec.TYPES
   ,SDD_QTD_rec.ELEMENT_TYPE_NAME
   ,SDD_QTD_rec.DATE_CREATED
   ,SDD_QTD_rec.CREATED_BY
   ,SDD_QTD_rec.DATE_CHANGED
   ,SDD_QTD_rec.CHANGED_BY
   ,SDD_QTD_rec.NOTM
   ,SDD_QTD_rec.NAME
   ,SDD_QTD_rec.ORACLE_TYPE_REF
   ,SDD_QTD_rec.DATATYPE
   ,SDD_QTD_rec.SORT_LIST
   ,SDD_QTD_rec.MULTIPLE_CONSUMERS_FLAG
   ,SDD_QTD_rec.MESSAGE_GROUPING
   ,SDD_QTD_rec.AUTO_COMMIT_FLAG
   ,SDD_QTD_rec.PRIMARY_INSTANCE
   ,SDD_QTD_rec.SECONDARY_INSTANCE
   ,SDD_QTD_rec.COMPATIBLE_DB_VERSION
   ,SDD_QTD_rec.REMARK
   ,SDD_QTD_rec.DATATYPE_DEFINED_BY
   ,SDD_QTD_rec.USRX0
   ,SDD_QTD_rec.USRX1
   ,SDD_QTD_rec.USRX2
   ,SDD_QTD_rec.USRX3
   ,SDD_QTD_rec.USRX4
   ,SDD_QTD_rec.USRX5
   ,SDD_QTD_rec.USRX6
   ,SDD_QTD_rec.USRX7
   ,SDD_QTD_rec.USRX8
   ,SDD_QTD_rec.USRX9
   ,SDD_QTD_rec.USRX10
   ,SDD_QTD_rec.USRX11
   ,SDD_QTD_rec.USRX12
   ,SDD_QTD_rec.USRX13
   ,SDD_QTD_rec.USRX14
   ,SDD_QTD_rec.USRX15
   ,SDD_QTD_rec.USRX16
   ,SDD_QTD_rec.USRX17
   ,SDD_QTD_rec.USRX18
   ,SDD_QTD_rec.USRX19
  );
  jr_reg_ver.vercopy_dependencies(SDD_QTD_ver.irid, SDD_QTD_ver.ivid, new_ivid, null, copy_dependencies);
  jr_reg_ver.vercopy_dependent_objects(SDD_QTD_ver.ivid, new_ivid);
  return new_ivid;
end SDD_QTD_ver;
/
create or replace function PK_SDD_QTD (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_QTD the_tab_new, SDD_QTD the_tab_old
  where  the_tab_new.ivid = PK_SDD_QTD.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_QTD.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_QTD;
/
create or replace function FK_QTD_TO_ORT (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ORACLE_TYPE_REF ref_value
  from   i$SDD_QTD the_tab
  where  the_tab.ivid = FK_QTD_TO_ORT.object_ivid
  and    the_tab.ORACLE_TYPE_REF is not null
  and    not exists (
             select null
             from   SDD_ORT foreign_tab
             where  the_tab.ORACLE_TYPE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4858, action);
  end loop;
  return is_ok;
end FK_QTD_TO_ORT;
/
create or replace function FK_QUI_TO_NPQ_d (
el_ivid number
 ,IRID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, child_tab.types
  from   SDD_QUI child_tab
  where  child_tab.NON_PERSISTENT_QUEUE_REF=FK_QUI_TO_NPQ_d.IRID
  ;
 is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
    insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid)
    select o.irid, o.ivid, o.table_irid
    from   SDD_QUI child_tab, i$sdd_object_versions o
    where  child_tab.NON_PERSISTENT_QUEUE_REF=FK_QUI_TO_NPQ_d.IRID
    and    child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(el_ivid,el_type,ref.irid,ref.types,action);
  end loop;
  return is_ok;
end FK_QUI_TO_NPQ_d;
/
create or replace function SDD_QUE_ver (irid number, ivid number, copy_dependencies boolean default true) return number as
  new_ivid           number; -- new ivid of primary object
  new_secondary_ivid number; -- new ivid of secondary objects
  cursor SDD_QUE_cur is
    select *
    from   i$SDD_QUE the_tab
    where  the_tab.irid=SDD_QUE_ver.irid
    and    the_tab.ivid=SDD_QUE_ver.ivid;
  SDD_QUE_rec SDD_QUE_cur%ROWTYPE;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_QUE_cur;
  fetch SDD_QUE_cur into SDD_QUE_rec;
  close SDD_QUE_cur;
  insert into i$SDD_QUE
  values (
    SDD_QUE_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_QUE_rec.TYPES
   ,SDD_QUE_rec.ELEMENT_TYPE_NAME
   ,SDD_QUE_rec.DATE_CREATED
   ,SDD_QUE_rec.CREATED_BY
   ,SDD_QUE_rec.DATE_CHANGED
   ,SDD_QUE_rec.CHANGED_BY
   ,SDD_QUE_rec.NOTM
   ,SDD_QUE_rec.NAME
   ,SDD_QUE_rec.QUEUE_TABLE_DEF_REF
   ,SDD_QUE_rec.MULTIPLE_CONSUMERS_FLAG
   ,SDD_QUE_rec.QUEUE_TYPE
   ,SDD_QUE_rec.AUTO_COMMIT_FLAG
   ,SDD_QUE_rec.MAX_RETRIES
   ,SDD_QUE_rec.RETRY_DELAY
   ,SDD_QUE_rec.RETENTION_TIME
   ,SDD_QUE_rec.INFINITE_FLAG
   ,SDD_QUE_rec.REMARK
   ,SDD_QUE_rec.QUEUE_SUBTYPE
   ,SDD_QUE_rec.USRX0
   ,SDD_QUE_rec.USRX1
   ,SDD_QUE_rec.USRX2
   ,SDD_QUE_rec.USRX3
   ,SDD_QUE_rec.USRX4
   ,SDD_QUE_rec.USRX5
   ,SDD_QUE_rec.USRX6
   ,SDD_QUE_rec.USRX7
   ,SDD_QUE_rec.USRX8
   ,SDD_QUE_rec.USRX9
   ,SDD_QUE_rec.USRX10
   ,SDD_QUE_rec.USRX11
   ,SDD_QUE_rec.USRX12
   ,SDD_QUE_rec.USRX13
   ,SDD_QUE_rec.USRX14
   ,SDD_QUE_rec.USRX15
   ,SDD_QUE_rec.USRX16
   ,SDD_QUE_rec.USRX17
   ,SDD_QUE_rec.USRX18
   ,SDD_QUE_rec.USRX19
  );
  jr_reg_ver.vercopy_dependencies(SDD_QUE_ver.irid, SDD_QUE_ver.ivid, new_ivid, null, copy_dependencies);
  jr_reg_ver.vercopy_dependent_objects(SDD_QUE_ver.ivid, new_ivid);
  return new_ivid;
end SDD_QUE_ver;
/
create or replace function PK_SDD_QUE (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_QUE the_tab_new, SDD_QUE the_tab_old
  where  the_tab_new.ivid = PK_SDD_QUE.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_QUE.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_QUE;
/
create or replace function FK_QUE_TO_QTD (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.QUEUE_TABLE_DEF_REF ref_value
  from   i$SDD_QUE the_tab
  where  the_tab.ivid = FK_QUE_TO_QTD.object_ivid
  and    the_tab.QUEUE_TABLE_DEF_REF is not null
  and    not exists (
             select null
             from   SDD_QTD foreign_tab
             where  the_tab.QUEUE_TABLE_DEF_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5137, action);
  end loop;
  return is_ok;
end FK_QUE_TO_QTD;
/
create or replace function PK_SDD_QUI (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_QUI the_tab_new, SDD_QUI the_tab_old
  where  the_tab_new.ivid = PK_SDD_QUI.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_QUI.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_QUI;
/
create or replace function FK_QUI_TO_DBU (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.QUEUE_TABLE_DBU_REF ref_value
  from   i$SDD_QUI the_tab
  where  the_tab.ivid = FK_QUI_TO_DBU.object_ivid
  and    the_tab.QUEUE_TABLE_DBU_REF is not null
  and    not exists (
             select null
             from   SDD_DBU foreign_tab
             where  the_tab.QUEUE_TABLE_DBU_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5034, action);
  end loop;
  return is_ok;
end FK_QUI_TO_DBU;
/
create or replace function FK_QUI_TO_NPQ (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.NON_PERSISTENT_QUEUE_REF ref_value
  from   i$SDD_QUI the_tab
  where  the_tab.ivid = FK_QUI_TO_NPQ.object_ivid
  and    the_tab.NON_PERSISTENT_QUEUE_REF is not null
  and    not exists (
             select null
             from   SDD_QUE foreign_tab
             where  the_tab.NON_PERSISTENT_QUEUE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5139, action);
  end loop;
  return is_ok;
end FK_QUI_TO_NPQ;
/
create or replace function FK_QUI_TO_PQU (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.PERSISTENT_QUEUE_REF ref_value
  from   i$SDD_QUI the_tab
  where  the_tab.ivid = FK_QUI_TO_PQU.object_ivid
  and    the_tab.PERSISTENT_QUEUE_REF is not null
  and    not exists (
             select null
             from   SDD_QUE foreign_tab
             where  the_tab.PERSISTENT_QUEUE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5139, action);
  end loop;
  return is_ok;
end FK_QUI_TO_PQU;
/
create or replace function FK_ENTUIE_TO_RELEND_cmd (irid number, ivid number) return boolean as
cursor bad_cur is
  select child_tab.irid child_irid, child_tab.types child_type
        ,parent_tab.ivid par_ivid, parent_tab.types par_type
  from   SDD_ENTUIE child_tab, i$SDD_RELEND parent_tab
  where  parent_tab.parent_ivid=FK_ENTUIE_TO_RELEND_cmd.ivid
  and    child_tab.RELATIONSHIP_END_REF=parent_tab.IRID
  ;
  is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
   insert into I$SDD_INVALID_OBJECTS(object_irid,object_ivid,table_irid)
    select o.irid,o.ivid,o.table_irid
      from SDD_ENTUIE child_tab
          ,i$SDD_RELEND parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_ENTUIE_TO_RELEND_cmd.ivid
       and child_tab.RELATIONSHIP_END_REF=parent_tab.IRID
       and child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(ref.par_ivid,ref.par_type,ref.child_irid,ref.child_type,'DEL');
  end loop;
  return is_ok;
end FK_ENTUIE_TO_RELEND_cmd;
/
create or replace function FK_ENTUIE_TO_RELEND_d (
el_ivid number
 ,IRID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, child_tab.types
  from   SDD_ENTUIE child_tab
  where  child_tab.RELATIONSHIP_END_REF=FK_ENTUIE_TO_RELEND_d.IRID
  ;
 is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
    insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid)
    select o.irid, o.ivid, o.table_irid
    from   SDD_ENTUIE child_tab, i$sdd_object_versions o
    where  child_tab.RELATIONSHIP_END_REF=FK_ENTUIE_TO_RELEND_d.IRID
    and    child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(el_ivid,el_type,ref.irid,ref.types,action);
  end loop;
  return is_ok;
end FK_ENTUIE_TO_RELEND_d;
/
create or replace function PK_SDD_RELEND (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_RELEND the_tab_new, SDD_RELEND the_tab_old
  where  the_tab_new.ivid = PK_SDD_RELEND.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_RELEND.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_RELEND;
/
create or replace function FK_RELEND_TO_ENT2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.TO_ENTITY_REF ref_value
  from   i$SDD_RELEND the_tab
  where  the_tab.ivid = FK_RELEND_TO_ENT2.object_ivid
  and    the_tab.TO_ENTITY_REF is not null
  and    not exists (
             select null
             from   SDD_ENT foreign_tab
             where  the_tab.TO_ENTITY_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5002, action);
  end loop;
  return is_ok;
end FK_RELEND_TO_ENT2;
/
create or replace function PK_SDD_RGP (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_RGP the_tab_new, SDD_RGP the_tab_old
  where  the_tab_new.ivid = PK_SDD_RGP.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_RGP.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_RGP;
/
create or replace function FK_RGP_TO_ORC (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ORACLE_DATABASE_REF ref_value
  from   i$SDD_RGP the_tab
  where  the_tab.ivid = FK_RGP_TO_ORC.object_ivid
  and    the_tab.ORACLE_DATABASE_REF is not null
  and    not exists (
             select null
             from   SDD_ODB foreign_tab
             where  the_tab.ORACLE_DATABASE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4927, action);
  end loop;
  return is_ok;
end FK_RGP_TO_ORC;
/
create or replace function PK_SDD_RPG (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_RPG the_tab_new, SDD_RPG the_tab_old
  where  the_tab_new.ivid = PK_SDD_RPG.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_RPG.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_RPG;
/
create or replace function SDD_RUL_ver (irid number, ivid number, copy_dependencies boolean default true) return number as
  new_ivid           number; -- new ivid of primary object
  new_secondary_ivid number; -- new ivid of secondary objects
  cursor SDD_RUL_cur is
    select *
    from   i$SDD_RUL the_tab
    where  the_tab.irid=SDD_RUL_ver.irid
    and    the_tab.ivid=SDD_RUL_ver.ivid;
  SDD_RUL_rec SDD_RUL_cur%ROWTYPE;
  cursor SDD_MEMCOM_cur1 is
    select *
    from i$SDD_MEMCOM the_tab
    where the_tab.parent_ivid=SDD_RUL_ver.ivid;
  cursor SDD_RULRUL_cur2 is
    select *
    from i$SDD_RULRUL the_tab
    where the_tab.parent_ivid=SDD_RUL_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_RUL_cur;
  fetch SDD_RUL_cur into SDD_RUL_rec;
  close SDD_RUL_cur;
  insert into i$SDD_RUL
  values (
    SDD_RUL_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_RUL_rec.TYPES
   ,SDD_RUL_rec.ELEMENT_TYPE_NAME
   ,SDD_RUL_rec.DATE_CREATED
   ,SDD_RUL_rec.CREATED_BY
   ,SDD_RUL_rec.DATE_CHANGED
   ,SDD_RUL_rec.CHANGED_BY
   ,SDD_RUL_rec.NOTM
   ,SDD_RUL_rec.NAME
   ,SDD_RUL_rec.SHORT_DESCRIPTION
   ,SDD_RUL_rec.LANGUAGE_REF
   ,SDD_RUL_rec.EVENT_CLASSIFIER_REF
   ,SDD_RUL_rec.EXECUTION_STRING
   ,SDD_RUL_rec.METHOD_REF
  );
  jr_reg_ver.vercopy_dependencies(SDD_RUL_ver.irid, SDD_RUL_ver.ivid, new_ivid, null, copy_dependencies);
  for SDD_MEMCOM_rec1 in SDD_MEMCOM_cur1 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_MEMCOM
    values (
       SDD_MEMCOM_rec1.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_MEMCOM_rec1.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_MEMCOM_rec1.TYPES
     , SDD_MEMCOM_rec1.ELEMENT_TYPE_NAME
     , SDD_MEMCOM_rec1.DATE_CREATED
     , SDD_MEMCOM_rec1.CREATED_BY
     , SDD_MEMCOM_rec1.DATE_CHANGED
     , SDD_MEMCOM_rec1.CHANGED_BY
     , SDD_MEMCOM_rec1.NOTM
     , SDD_MEMCOM_rec1.NAMED_RULE_REF
     , SDD_MEMCOM_rec1.INTEGRITY_RULE_REF
     , SDD_MEMCOM_rec1.CROSS_OBJECT_RULE_REF
     , SDD_MEMCOM_rec1.STATE_RULE_REF
     , SDD_MEMCOM_rec1.ATTRIBUTE_DERIV_RULE_REF
     , SDD_MEMCOM_rec1.CLASSIFIER_ATTRIBUTE_REF
     , SDD_MEMCOM_rec1.ASSOCIATION_END_REF
     , SDD_MEMCOM_rec1.METHOD_REF
     , SDD_MEMCOM_rec1.MEMBER_COMPONENT_OF
     , SDD_MEMCOM_rec1.MEMBER_COMPONENT_IN
    );
  jr_reg_ver.vercopy_dependencies(SDD_MEMCOM_rec1.irid, SDD_MEMCOM_rec1.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_RULRUL_rec2 in SDD_RULRUL_cur2 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_RULRUL
    values (
       SDD_RULRUL_rec2.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_RULRUL_rec2.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_RULRUL_rec2.TYPES
     , SDD_RULRUL_rec2.ELEMENT_TYPE_NAME
     , SDD_RULRUL_rec2.DATE_CREATED
     , SDD_RULRUL_rec2.CREATED_BY
     , SDD_RULRUL_rec2.DATE_CHANGED
     , SDD_RULRUL_rec2.CHANGED_BY
     , SDD_RULRUL_rec2.NOTM
     , SDD_RULRUL_rec2.USED_IN_RULE_REF
     , SDD_RULRUL_rec2.USE_OF_RULE_REF
     , SDD_RULRUL_rec2.SEQUENCE_IN_PARENT
    );
  jr_reg_ver.vercopy_dependencies(SDD_RULRUL_rec2.irid, SDD_RULRUL_rec2.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  jr_reg_ver.vercopy_dependent_objects(SDD_RUL_ver.ivid, new_ivid);
  return new_ivid;
end SDD_RUL_ver;
/
create or replace function PK_SDD_RUL (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_RUL the_tab_new, SDD_RUL the_tab_old
  where  the_tab_new.ivid = PK_SDD_RUL.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_RUL.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_RUL;
/
create or replace function FK_RUL_TO_EVC (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.EVENT_CLASSIFIER_REF ref_value
  from   i$SDD_RUL the_tab
  where  the_tab.ivid = FK_RUL_TO_EVC.object_ivid
  and    the_tab.EVENT_CLASSIFIER_REF is not null
  and    not exists (
             select null
             from   SDD_CLA foreign_tab
             where  the_tab.EVENT_CLASSIFIER_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4841, action);
  end loop;
  return is_ok;
end FK_RUL_TO_EVC;
/
create or replace function FK_RUL_TO_LAN (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.LANGUAGE_REF ref_value
  from   i$SDD_RUL the_tab
  where  the_tab.ivid = FK_RUL_TO_LAN.object_ivid
  and    the_tab.LANGUAGE_REF is not null
  and    not exists (
             select null
             from   SDD_LAN foreign_tab
             where  the_tab.LANGUAGE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4996, action);
  end loop;
  return is_ok;
end FK_RUL_TO_LAN;
/
create or replace function FK_RUL_TO_MET (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.METHOD_REF ref_value
  from   i$SDD_RUL the_tab
  where  the_tab.ivid = FK_RUL_TO_MET.object_ivid
  and    the_tab.METHOD_REF is not null
  and    not exists (
             select null
             from   SDD_MET foreign_tab
             where  the_tab.METHOD_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4834, action);
  end loop;
  return is_ok;
end FK_RUL_TO_MET;
/
create or replace function PK_SDD_RULRUL (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_RULRUL the_tab_new, SDD_RULRUL the_tab_old
  where  the_tab_new.ivid = PK_SDD_RULRUL.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_RULRUL.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_RULRUL;
/
create or replace function FK_RULRUL_TO_RUL2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.USE_OF_RULE_REF ref_value
  from   i$SDD_RULRUL the_tab
  where  the_tab.ivid = FK_RULRUL_TO_RUL2.object_ivid
  and    the_tab.USE_OF_RULE_REF is not null
  and    not exists (
             select null
             from   SDD_RUL foreign_tab
             where  the_tab.USE_OF_RULE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4833, action);
  end loop;
  return is_ok;
end FK_RULRUL_TO_RUL2;
/
create or replace function PK_SDD_SBA (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_SBA the_tab_new, SDD_SBA the_tab_old
  where  the_tab_new.ivid = PK_SDD_SBA.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_SBA.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_SBA;
/
create or replace function FK_SBA_TO_EVS (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.EVENT_SUBSCRIPTION_REF ref_value
  from   i$SDD_SBA the_tab
  where  the_tab.ivid = FK_SBA_TO_EVS.object_ivid
  and    the_tab.EVENT_SUBSCRIPTION_REF is not null
  and    not exists (
             select null
             from   SDD_EVS foreign_tab
             where  the_tab.EVENT_SUBSCRIPTION_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5083, action);
  end loop;
  return is_ok;
end FK_SBA_TO_EVS;
/
create or replace function FK_SBA_TO_SUD (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.SUBSCRIPTION_DETAIL_REF ref_value
  from   i$SDD_SBA the_tab
  where  the_tab.ivid = FK_SBA_TO_SUD.object_ivid
  and    the_tab.SUBSCRIPTION_DETAIL_REF is not null
  and    not exists (
             select null
             from   SDD_SUD foreign_tab
             where  the_tab.SUBSCRIPTION_DETAIL_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5084, action);
  end loop;
  return is_ok;
end FK_SBA_TO_SUD;
/
create or replace function PK_SDD_SMI (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_SMI the_tab_new, SDD_SMI the_tab_old
  where  the_tab_new.ivid = PK_SDD_SMI.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_SMI.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_SMI;
/
create or replace function PK_SDD_SOU (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_SOU the_tab_new, SDD_SOU the_tab_old
  where  the_tab_new.ivid = PK_SDD_SOU.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_SOU.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_SOU;
/
create or replace function PK_SDD_SPV (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_SPV the_tab_new, SDD_SPV the_tab_old
  where  the_tab_new.ivid = PK_SDD_SPV.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_SPV.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_SPV;
/
create or replace function PK_SDD_SQS (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_SQS the_tab_new, SDD_SQS the_tab_old
  where  the_tab_new.ivid = PK_SDD_SQS.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_SQS.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_SQS;
/
create or replace function FK_SQS_TO_LOV (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.LIST_OF_VALUES_REF ref_value
  from   i$SDD_SQS the_tab
  where  the_tab.ivid = FK_SQS_TO_LOV.object_ivid
  and    the_tab.LIST_OF_VALUES_REF is not null
  and    not exists (
             select null
             from   SDD_MUN foreign_tab
             where  the_tab.LIST_OF_VALUES_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5051, action);
  end loop;
  return is_ok;
end FK_SQS_TO_LOV;
/
create or replace function FK_SQS_TO_MCO (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.MODULE_COMPONENT_REF ref_value
  from   i$SDD_SQS the_tab
  where  the_tab.ivid = FK_SQS_TO_MCO.object_ivid
  and    the_tab.MODULE_COMPONENT_REF is not null
  and    not exists (
             select null
             from   SDD_MUN foreign_tab
             where  the_tab.MODULE_COMPONENT_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5051, action);
  end loop;
  return is_ok;
end FK_SQS_TO_MCO;
/
create or replace function PK_SDD_SRG (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_SRG the_tab_new, SDD_SRG the_tab_old
  where  the_tab_new.ivid = PK_SDD_SRG.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_SRG.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_SRG;
/
create or replace function FK_SRG_TO_ORS (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ROLLBACK_SEGMENT_REF ref_value
  from   i$SDD_SRG the_tab
  where  the_tab.ivid = FK_SRG_TO_ORS.object_ivid
  and    the_tab.ROLLBACK_SEGMENT_REF is not null
  and    not exists (
             select null
             from   SDD_ORS foreign_tab
             where  the_tab.ROLLBACK_SEGMENT_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5006, action);
  end loop;
  return is_ok;
end FK_SRG_TO_ORS;
/
create or replace function PK_SDD_SRU (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_SRU the_tab_new, SDD_SRU the_tab_old
  where  the_tab_new.ivid = PK_SDD_SRU.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_SRU.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_SRU;
/
create or replace function FK_SRU_TO_LAN (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.LANGUAGE_REF ref_value
  from   i$SDD_SRU the_tab
  where  the_tab.ivid = FK_SRU_TO_LAN.object_ivid
  and    the_tab.LANGUAGE_REF is not null
  and    not exists (
             select null
             from   SDD_LAN foreign_tab
             where  the_tab.LANGUAGE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4996, action);
  end loop;
  return is_ok;
end FK_SRU_TO_LAN;
/
create or replace function FK_SRU_TO_MET (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.METHOD_REF ref_value
  from   i$SDD_SRU the_tab
  where  the_tab.ivid = FK_SRU_TO_MET.object_ivid
  and    the_tab.METHOD_REF is not null
  and    not exists (
             select null
             from   SDD_MET foreign_tab
             where  the_tab.METHOD_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4834, action);
  end loop;
  return is_ok;
end FK_SRU_TO_MET;
/
create or replace function FK_STESTE_TO_STE2_d (
el_ivid number
 ,IRID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, child_tab.types
  from   SDD_STESTE child_tab
  where  child_tab.SUPERTYPE_REF=FK_STESTE_TO_STE2_d.IRID
  ;
 is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
    insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid)
    select o.irid, o.ivid, o.table_irid
    from   SDD_STESTE child_tab, i$sdd_object_versions o
    where  child_tab.SUPERTYPE_REF=FK_STESTE_TO_STE2_d.IRID
    and    child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(el_ivid,el_type,ref.irid,ref.types,action);
  end loop;
  return is_ok;
end FK_STESTE_TO_STE2_d;
/
create or replace function SDD_STE_ver (irid number, ivid number, copy_dependencies boolean default true) return number as
  new_ivid           number; -- new ivid of primary object
  new_secondary_ivid number; -- new ivid of secondary objects
  cursor SDD_STE_cur is
    select *
    from   i$SDD_STE the_tab
    where  the_tab.irid=SDD_STE_ver.irid
    and    the_tab.ivid=SDD_STE_ver.ivid;
  SDD_STE_rec SDD_STE_cur%ROWTYPE;
  cursor SDD_STESTE_cur1 is
    select *
    from i$SDD_STESTE the_tab
    where the_tab.parent_ivid=SDD_STE_ver.ivid;
  cursor SDD_TAG_cur2 is
    select *
    from i$SDD_TAG the_tab
    where the_tab.parent_ivid=SDD_STE_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_STE_cur;
  fetch SDD_STE_cur into SDD_STE_rec;
  close SDD_STE_cur;
  insert into i$SDD_STE
  values (
    SDD_STE_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_STE_rec.TYPES
   ,SDD_STE_rec.ELEMENT_TYPE_NAME
   ,SDD_STE_rec.DATE_CREATED
   ,SDD_STE_rec.CREATED_BY
   ,SDD_STE_rec.DATE_CHANGED
   ,SDD_STE_rec.CHANGED_BY
   ,SDD_STE_rec.NOTM
   ,SDD_STE_rec.BASE_CLASS
   ,SDD_STE_rec.NAME
   ,SDD_STE_rec.ABSTRACT_FLAG
   ,SDD_STE_rec.LEAF_FLAG
   ,SDD_STE_rec.ROOT_FLAG
   ,SDD_STE_rec.ICON_FILE_REF
  );
  jr_reg_ver.vercopy_dependencies(SDD_STE_ver.irid, SDD_STE_ver.ivid, new_ivid, null, copy_dependencies);
  for SDD_STESTE_rec1 in SDD_STESTE_cur1 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_STESTE
    values (
       SDD_STESTE_rec1.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_STESTE_rec1.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_STESTE_rec1.TYPES
     , SDD_STESTE_rec1.ELEMENT_TYPE_NAME
     , SDD_STESTE_rec1.DATE_CREATED
     , SDD_STESTE_rec1.CREATED_BY
     , SDD_STESTE_rec1.DATE_CHANGED
     , SDD_STESTE_rec1.CHANGED_BY
     , SDD_STESTE_rec1.NOTM
     , SDD_STESTE_rec1.SUBTYPE_REF
     , SDD_STESTE_rec1.SUPERTYPE_REF
    );
  jr_reg_ver.vercopy_dependencies(SDD_STESTE_rec1.irid, SDD_STESTE_rec1.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_TAG_rec2 in SDD_TAG_cur2 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_TAG
    values (
       SDD_TAG_rec2.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_TAG_rec2.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_TAG_rec2.TYPES
     , SDD_TAG_rec2.ELEMENT_TYPE_NAME
     , SDD_TAG_rec2.DATE_CREATED
     , SDD_TAG_rec2.CREATED_BY
     , SDD_TAG_rec2.DATE_CHANGED
     , SDD_TAG_rec2.CHANGED_BY
     , SDD_TAG_rec2.NOTM
     , SDD_TAG_rec2.STEREOTYPE_REF
     , SDD_TAG_rec2.NAME
    );
  jr_reg_ver.vercopy_dependencies(SDD_TAG_rec2.irid, SDD_TAG_rec2.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  jr_reg_ver.vercopy_dependent_objects(SDD_STE_ver.ivid, new_ivid);
  return new_ivid;
end SDD_STE_ver;
/
create or replace function PK_SDD_STE (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_STE the_tab_new, SDD_STE the_tab_old
  where  the_tab_new.ivid = PK_SDD_STE.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_STE.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_STE;
/
create or replace function FK_STE_TO_FILES (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ICON_FILE_REF ref_value
  from   i$SDD_STE the_tab
  where  the_tab.ivid = FK_STE_TO_FILES.object_ivid
  and    the_tab.ICON_FILE_REF is not null
  and    not exists (
             select null
             from   SDD_FILES foreign_tab
             where  the_tab.ICON_FILE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4819, action);
  end loop;
  return is_ok;
end FK_STE_TO_FILES;
/
create or replace function PK_SDD_STESTE (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_STESTE the_tab_new, SDD_STESTE the_tab_old
  where  the_tab_new.ivid = PK_SDD_STESTE.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_STESTE.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_STESTE;
/
create or replace function FK_STESTE_TO_STE2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.SUPERTYPE_REF ref_value
  from   i$SDD_STESTE the_tab
  where  the_tab.ivid = FK_STESTE_TO_STE2.object_ivid
  and    the_tab.SUPERTYPE_REF is not null
  and    not exists (
             select null
             from   SDD_STE foreign_tab
             where  the_tab.SUPERTYPE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5146, action);
  end loop;
  return is_ok;
end FK_STESTE_TO_STE2;
/
create or replace function FK_EVH_TO_SUD_cmd (irid number, ivid number) return boolean as
cursor bad_cur is
  select child_tab.irid child_irid, child_tab.types child_type
        ,parent_tab.ivid par_ivid, parent_tab.types par_type
  from   SDD_EVH child_tab, i$SDD_SUD parent_tab
  where  parent_tab.parent_ivid=FK_EVH_TO_SUD_cmd.ivid
  and    child_tab.SUBSCRIPTION_DETAIL_REF=parent_tab.IRID
  ;
  is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
   insert into I$SDD_INVALID_OBJECTS(object_irid,object_ivid,table_irid)
    select o.irid,o.ivid,o.table_irid
      from SDD_EVH child_tab
          ,i$SDD_SUD parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_EVH_TO_SUD_cmd.ivid
       and child_tab.SUBSCRIPTION_DETAIL_REF=parent_tab.IRID
       and child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(ref.par_ivid,ref.par_type,ref.child_irid,ref.child_type,'DEL');
  end loop;
  return is_ok;
end FK_EVH_TO_SUD_cmd;
/
create or replace function FK_EVH_TO_SUD_d (
el_ivid number
 ,IRID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, child_tab.types
  from   SDD_EVH child_tab
  where  child_tab.SUBSCRIPTION_DETAIL_REF=FK_EVH_TO_SUD_d.IRID
  ;
 is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
    insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid)
    select o.irid, o.ivid, o.table_irid
    from   SDD_EVH child_tab, i$sdd_object_versions o
    where  child_tab.SUBSCRIPTION_DETAIL_REF=FK_EVH_TO_SUD_d.IRID
    and    child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(el_ivid,el_type,ref.irid,ref.types,action);
  end loop;
  return is_ok;
end FK_EVH_TO_SUD_d;
/
create or replace function PK_SDD_SUD (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_SUD the_tab_new, SDD_SUD the_tab_old
  where  the_tab_new.ivid = PK_SDD_SUD.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_SUD.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_SUD;
/
create or replace function FK_SUD_TO_AEN (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ASSOCIATION_END_REF ref_value
  from   i$SDD_SUD the_tab
  where  the_tab.ivid = FK_SUD_TO_AEN.object_ivid
  and    the_tab.ASSOCIATION_END_REF is not null
  and    not exists (
             select null
             from   SDD_AEN foreign_tab
             where  the_tab.ASSOCIATION_END_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5065, action);
  end loop;
  return is_ok;
end FK_SUD_TO_AEN;
/
create or replace function FK_SUD_TO_CLAEVC (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.EVENT_PUBLICATION_REF ref_value
  from   i$SDD_SUD the_tab
  where  the_tab.ivid = FK_SUD_TO_CLAEVC.object_ivid
  and    the_tab.EVENT_PUBLICATION_REF is not null
  and    not exists (
             select null
             from   SDD_CLAEVC foreign_tab
             where  the_tab.EVENT_PUBLICATION_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5081, action);
  end loop;
  return is_ok;
end FK_SUD_TO_CLAEVC;
/
create or replace function SDD_SYN_ver (irid number, ivid number, copy_dependencies boolean default true) return number as
  new_ivid           number; -- new ivid of primary object
  new_secondary_ivid number; -- new ivid of secondary objects
  cursor SDD_SYN_cur is
    select *
    from   i$SDD_SYN the_tab
    where  the_tab.irid=SDD_SYN_ver.irid
    and    the_tab.ivid=SDD_SYN_ver.ivid;
  SDD_SYN_rec SDD_SYN_cur%ROWTYPE;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_SYN_cur;
  fetch SDD_SYN_cur into SDD_SYN_rec;
  close SDD_SYN_cur;
  insert into i$SDD_SYN
  values (
    SDD_SYN_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_SYN_rec.TYPES
   ,SDD_SYN_rec.ELEMENT_TYPE_NAME
   ,SDD_SYN_rec.DATE_CREATED
   ,SDD_SYN_rec.CREATED_BY
   ,SDD_SYN_rec.DATE_CHANGED
   ,SDD_SYN_rec.CHANGED_BY
   ,SDD_SYN_rec.NOTM
   ,SDD_SYN_rec.ENTITY_REF
   ,SDD_SYN_rec.TERM_REF
   ,SDD_SYN_rec.NAME
   ,SDD_SYN_rec.SYNONYM_FOR
   ,SDD_SYN_rec.USRX0
   ,SDD_SYN_rec.USRX1
   ,SDD_SYN_rec.USRX2
   ,SDD_SYN_rec.USRX3
   ,SDD_SYN_rec.USRX4
   ,SDD_SYN_rec.USRX5
   ,SDD_SYN_rec.USRX6
   ,SDD_SYN_rec.USRX7
   ,SDD_SYN_rec.USRX8
   ,SDD_SYN_rec.USRX9
   ,SDD_SYN_rec.USRX10
   ,SDD_SYN_rec.USRX11
   ,SDD_SYN_rec.USRX12
   ,SDD_SYN_rec.USRX13
   ,SDD_SYN_rec.USRX14
   ,SDD_SYN_rec.USRX15
   ,SDD_SYN_rec.USRX16
   ,SDD_SYN_rec.USRX17
   ,SDD_SYN_rec.USRX18
   ,SDD_SYN_rec.USRX19
  );
  jr_reg_ver.vercopy_dependencies(SDD_SYN_ver.irid, SDD_SYN_ver.ivid, new_ivid, null, copy_dependencies);
  jr_reg_ver.vercopy_dependent_objects(SDD_SYN_ver.ivid, new_ivid);
  return new_ivid;
end SDD_SYN_ver;
/
create or replace function PK_SDD_SYN (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_SYN the_tab_new, SDD_SYN the_tab_old
  where  the_tab_new.ivid = PK_SDD_SYN.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_SYN.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_SYN;
/
create or replace function FK_SYN_TO_ENT (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ENTITY_REF ref_value
  from   i$SDD_SYN the_tab
  where  the_tab.ivid = FK_SYN_TO_ENT.object_ivid
  and    the_tab.ENTITY_REF is not null
  and    not exists (
             select null
             from   SDD_ENT foreign_tab
             where  the_tab.ENTITY_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5002, action);
  end loop;
  return is_ok;
end FK_SYN_TO_ENT;
/
create or replace function FK_SYN_TO_TER (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.TERM_REF ref_value
  from   i$SDD_SYN the_tab
  where  the_tab.ivid = FK_SYN_TO_TER.object_ivid
  and    the_tab.TERM_REF is not null
  and    not exists (
             select null
             from   SDD_TER foreign_tab
             where  the_tab.TERM_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4994, action);
  end loop;
  return is_ok;
end FK_SYN_TO_TER;
/
create or replace function FK_ITM_TO_TBL_d (
el_ivid number
 ,IRID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, child_tab.types
  from   SDD_ITM child_tab
  where  child_tab.TABLE_DEFINITION_REF=FK_ITM_TO_TBL_d.IRID
  ;
 is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
    insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid)
    select o.irid, o.ivid, o.table_irid
    from   SDD_ITM child_tab, i$sdd_object_versions o
    where  child_tab.TABLE_DEFINITION_REF=FK_ITM_TO_TBL_d.IRID
    and    child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(el_ivid,el_type,ref.irid,ref.types,action);
  end loop;
  return is_ok;
end FK_ITM_TO_TBL_d;
/
create or replace function FK_MTI_TO_TAB_d (
el_ivid number
 ,IRID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, child_tab.types
  from   SDD_MTI child_tab
  where  child_tab.TABLE_REF=FK_MTI_TO_TAB_d.IRID
  ;
 is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
    insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid)
    select o.irid, o.ivid, o.table_irid
    from   SDD_MTI child_tab, i$sdd_object_versions o
    where  child_tab.TABLE_REF=FK_MTI_TO_TAB_d.IRID
    and    child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(el_ivid,el_type,ref.irid,ref.types,action);
  end loop;
  return is_ok;
end FK_MTI_TO_TAB_d;
/
create or replace function FK_VWTAB_TO_TAB2_d (
el_ivid number
 ,IRID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, child_tab.types
  from   SDD_VWTAB child_tab
  where  child_tab.TABLE_REF=FK_VWTAB_TO_TAB2_d.IRID
  ;
 is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
    insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid)
    select o.irid, o.ivid, o.table_irid
    from   SDD_VWTAB child_tab, i$sdd_object_versions o
    where  child_tab.TABLE_REF=FK_VWTAB_TO_TAB2_d.IRID
    and    child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(el_ivid,el_type,ref.irid,ref.types,action);
  end loop;
  return is_ok;
end FK_VWTAB_TO_TAB2_d;
/
create or replace function SDD_TAB_ver (irid number, ivid number, copy_dependencies boolean default true) return number as
  new_ivid           number; -- new ivid of primary object
  new_secondary_ivid number; -- new ivid of secondary objects
  cursor SDD_TAB_cur is
    select *
    from   i$SDD_TAB the_tab
    where  the_tab.irid=SDD_TAB_ver.irid
    and    the_tab.ivid=SDD_TAB_ver.ivid;
  SDD_TAB_rec SDD_TAB_cur%ROWTYPE;
  cursor SDD_COL_cur1 is
    select *
    from i$SDD_COL the_tab
    where the_tab.parent_ivid=SDD_TAB_ver.ivid;
  cursor SDD_ATV_cur2 is
    select *
    from i$SDD_ATV the_tab
    where the_tab.parent_ivid=SDD_TAB_ver.ivid;
  cursor SDD_CQA_cur3 is
    select *
    from i$SDD_CQA the_tab
    where the_tab.parent_ivid=SDD_TAB_ver.ivid;
  cursor SDD_CQACOL_cur4 is
    select *
    from i$SDD_CQACOL the_tab
    where the_tab.parent_ivid=SDD_TAB_ver.ivid;
  cursor SDD_DSY_cur5 is
    select *
    from i$SDD_DSY the_tab
    where the_tab.parent_ivid=SDD_TAB_ver.ivid;
  cursor SDD_IND_cur6 is
    select *
    from i$SDD_IND the_tab
    where the_tab.parent_ivid=SDD_TAB_ver.ivid;
  cursor SDD_INDCOL_cur7 is
    select *
    from i$SDD_INDCOL the_tab
    where the_tab.parent_ivid=SDD_TAB_ver.ivid;
  cursor SDD_OCO_cur8 is
    select *
    from i$SDD_OCO the_tab
    where the_tab.parent_ivid=SDD_TAB_ver.ivid;
  cursor SDD_OKY_cur9 is
    select *
    from i$SDD_OKY the_tab
    where the_tab.parent_ivid=SDD_TAB_ver.ivid;
  cursor SDD_TABENT_cur10 is
    select *
    from i$SDD_TABENT the_tab
    where the_tab.parent_ivid=SDD_TAB_ver.ivid;
  cursor SDD_TRG_cur11 is
    select *
    from i$SDD_TRG the_tab
    where the_tab.parent_ivid=SDD_TAB_ver.ivid;
  cursor SDD_TRGCOL_cur12 is
    select *
    from i$SDD_TRGCOL the_tab
    where the_tab.parent_ivid=SDD_TAB_ver.ivid;
  cursor SDD_VWTAB_cur13 is
    select *
    from i$SDD_VWTAB the_tab
    where the_tab.parent_ivid=SDD_TAB_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_TAB_cur;
  fetch SDD_TAB_cur into SDD_TAB_rec;
  close SDD_TAB_cur;
  insert into i$SDD_TAB
  values (
    SDD_TAB_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_TAB_rec.TYPES
   ,SDD_TAB_rec.ELEMENT_TYPE_NAME
   ,SDD_TAB_rec.DATE_CREATED
   ,SDD_TAB_rec.CREATED_BY
   ,SDD_TAB_rec.DATE_CHANGED
   ,SDD_TAB_rec.CHANGED_BY
   ,SDD_TAB_rec.NOTM
   ,SDD_TAB_rec.RECORD_FILE_REF
   ,SDD_TAB_rec.NAME
   ,SDD_TAB_rec.TABLE_TYPE
   ,SDD_TAB_rec.ALIAS
   ,SDD_TAB_rec.COLUMN_PREFIX
   ,SDD_TAB_rec.DISPLAY_TITLE
   ,SDD_TAB_rec.ORACLE_OBJECT_TYPE_REF
   ,SDD_TAB_rec.UPDATABLE_FLAG
   ,SDD_TAB_rec.JOURNAL_LOCATION
   ,SDD_TAB_rec.OID_ATTRIBUTE_LIST
   ,SDD_TAB_rec.INITIAL_NUMBER_OF_ROWS
   ,SDD_TAB_rec.MAXIMUM_NUMBER_OF_ROWS
   ,SDD_TAB_rec.CLUSTER_REF
   ,SDD_TAB_rec.RECORD_FORMAT
   ,SDD_TAB_rec.INDEX_ONLY_FLAG
   ,SDD_TAB_rec.RECORD_SIZE
   ,SDD_TAB_rec.DATAWAREHOUSE_TYPE
   ,SDD_TAB_rec.OVERRIDE_SELECT_TEXT_FLAG
   ,SDD_TAB_rec.SAMPLE_TYPE
   ,SDD_TAB_rec.SAMPLE_PERCENT
   ,SDD_TAB_rec.REMARK
   ,SDD_TAB_rec.USRX0
   ,SDD_TAB_rec.USRX1
   ,SDD_TAB_rec.USRX2
   ,SDD_TAB_rec.USRX3
   ,SDD_TAB_rec.USRX4
   ,SDD_TAB_rec.USRX5
   ,SDD_TAB_rec.USRX6
   ,SDD_TAB_rec.USRX7
   ,SDD_TAB_rec.USRX8
   ,SDD_TAB_rec.USRX9
   ,SDD_TAB_rec.USRX10
   ,SDD_TAB_rec.USRX11
   ,SDD_TAB_rec.USRX12
   ,SDD_TAB_rec.USRX13
   ,SDD_TAB_rec.USRX14
   ,SDD_TAB_rec.USRX15
   ,SDD_TAB_rec.USRX16
   ,SDD_TAB_rec.USRX17
   ,SDD_TAB_rec.USRX18
   ,SDD_TAB_rec.USRX19
   ,SDD_TAB_rec.DATA_PERSISTENCE
  );
  jr_reg_ver.vercopy_dependencies(SDD_TAB_ver.irid, SDD_TAB_ver.ivid, new_ivid, null, copy_dependencies);
  for SDD_COL_rec1 in SDD_COL_cur1 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_COL
    values (
       SDD_COL_rec1.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_COL_rec1.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_COL_rec1.TYPES
     , SDD_COL_rec1.ELEMENT_TYPE_NAME
     , SDD_COL_rec1.DATE_CREATED
     , SDD_COL_rec1.CREATED_BY
     , SDD_COL_rec1.DATE_CHANGED
     , SDD_COL_rec1.CHANGED_BY
     , SDD_COL_rec1.NOTM
     , SDD_COL_rec1.TABLE_REF
     , SDD_COL_rec1.ORACLE_OBJECT_TYPE_REF
     , SDD_COL_rec1.NAME
     , SDD_COL_rec1.SEQUENCE_NUMBER
     , SDD_COL_rec1.COMPLETE_FLAG
     , SDD_COL_rec1.DOMAIN_REF
     , SDD_COL_rec1.DATATYPE
     , SDD_COL_rec1.AVERAGE_LENGTH
     , SDD_COL_rec1.MAXIMUM_LENGTH
     , SDD_COL_rec1.DECIMAL_PLACES
     , SDD_COL_rec1.ORACLE_TYPE_REF
     , SDD_COL_rec1.OBJECT_TYPE_INCLUSION
     , SDD_COL_rec1.SCOPE_TABLE_REF
     , SDD_COL_rec1.STORE_REF_WITH_ROWID_FLAG
     , SDD_COL_rec1.NULL_INDICATOR
     , SDD_COL_rec1.UPPERCASE
     , SDD_COL_rec1.DEFAULT_VALUE
     , SDD_COL_rec1.DEFAULT_VALUE_TYPE
     , SDD_COL_rec1.SEQUENCE_REF
     , SDD_COL_rec1.CLUSTER_COLUMN_REF
     , SDD_COL_rec1.INITIAL_VOLUME
     , SDD_COL_rec1.FINAL_VOLUME
     , SDD_COL_rec1.DISPLAY_FLAG
     , SDD_COL_rec1.DEFAULT_IMPLEMENTATION_ITEM
     , SDD_COL_rec1.DEFAULT_DISPLAY_TYPE
     , SDD_COL_rec1.JUSTIFICATION
     , SDD_COL_rec1.DISPLAY_LENGTH
     , SDD_COL_rec1.DISPLAY_HEIGHT
     , SDD_COL_rec1.DISPLAY_SEQUENCE
     , SDD_COL_rec1.DESCRIPTOR_COLUMN
     , SDD_COL_rec1.FORMAT_MODIFIER
     , SDD_COL_rec1.HIGHLIGHTING
     , SDD_COL_rec1.SOURCE_RELATIONSHIP_END
     , SDD_COL_rec1.PROMPT
     , SDD_COL_rec1.SOURCE_ENTITY_DERIVED_FROM
     , SDD_COL_rec1.SOURCE_REL_ENTITY_ATTRIBUTE
     , SDD_COL_rec1.SOURCE_REL_ENTITY
     , SDD_COL_rec1.ORDER_SEQUENCE
     , SDD_COL_rec1.SORTING_ORDER
     , SDD_COL_rec1.BASE_COLUMN_REF
     , SDD_COL_rec1.RELATION_SELECTION_REF
     , SDD_COL_rec1.EXPRESSION_TEXT
     , SDD_COL_rec1.RELATION_TYPE
     , SDD_COL_rec1.COLUMN_FOR
     , SDD_COL_rec1.COLUMN_DENORMALISED_FROM
     , SDD_COL_rec1.CONSTRAINT_DENORMALISED_VIA
     , SDD_COL_rec1.DENORMALIZED_SUMMARY_FUNCTION
     , SDD_COL_rec1.AUTO_GENERATED
     , SDD_COL_rec1.SERVER_DEFAULTED_FLAG
     , SDD_COL_rec1.SERVER_DERIVED_FLAG
     , SDD_COL_rec1.DERIVATION_EXPRESSION_TYPE
     , SDD_COL_rec1.SOURCE_ATTRIBUTE_REF
     , SDD_COL_rec1.SUGGESTION_LIST_FLAG
     , SDD_COL_rec1.SOFT_LOV
     , SDD_COL_rec1.WHERE_VALIDATION_TYPE
     , SDD_COL_rec1.VALIDATION_FAILURE_MESSAGE
     , SDD_COL_rec1.HELP_TEXT
     , SDD_COL_rec1.REMARK
     , SDD_COL_rec1.FIELD_LEVEL
     , SDD_COL_rec1.SIGNED
     , SDD_COL_rec1.FIELD_INITIAL_VALUE
     , SDD_COL_rec1.FIELD_NULL_VALUE
     , SDD_COL_rec1.STORAGE_FORMAT
     , SDD_COL_rec1.REDEFINES
     , SDD_COL_rec1.OCCURS
     , SDD_COL_rec1.USRX0
     , SDD_COL_rec1.USRX1
     , SDD_COL_rec1.USRX2
     , SDD_COL_rec1.USRX3
     , SDD_COL_rec1.USRX4
     , SDD_COL_rec1.USRX5
     , SDD_COL_rec1.USRX6
     , SDD_COL_rec1.USRX7
     , SDD_COL_rec1.USRX8
     , SDD_COL_rec1.USRX9
     , SDD_COL_rec1.USRX10
     , SDD_COL_rec1.USRX11
     , SDD_COL_rec1.USRX12
     , SDD_COL_rec1.USRX13
     , SDD_COL_rec1.USRX14
     , SDD_COL_rec1.USRX15
     , SDD_COL_rec1.USRX16
     , SDD_COL_rec1.USRX17
     , SDD_COL_rec1.USRX18
     , SDD_COL_rec1.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_COL_rec1.irid, SDD_COL_rec1.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_ATV_rec2 in SDD_ATV_cur2 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_ATV
    values (
       SDD_ATV_rec2.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_ATV_rec2.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_ATV_rec2.TYPES
     , SDD_ATV_rec2.ELEMENT_TYPE_NAME
     , SDD_ATV_rec2.DATE_CREATED
     , SDD_ATV_rec2.CREATED_BY
     , SDD_ATV_rec2.DATE_CHANGED
     , SDD_ATV_rec2.CHANGED_BY
     , SDD_ATV_rec2.NOTM
     , SDD_ATV_rec2.ATTRIBUTE_REF
     , SDD_ATV_rec2.DOMAIN_REF
     , SDD_ATV_rec2.COLUMN_REF
     , SDD_ATV_rec2.MODULE_ARGUMENT_REF
     , SDD_ATV_rec2.UNBOUND_ITEM_REF
     , SDD_ATV_rec2.LOW_VALUE
     , SDD_ATV_rec2.HIGH_VALUE
     , SDD_ATV_rec2.ABBREVIATION
     , SDD_ATV_rec2.LOW_VALUE_TYPE
     , SDD_ATV_rec2.MEANING
     , SDD_ATV_rec2.HIGH_VALUE_TYPE
     , SDD_ATV_rec2.RADIO_SEQUENCE
     , SDD_ATV_rec2.ATTRIBUTE_VALUE_FOR
     , SDD_ATV_rec2.USRX0
     , SDD_ATV_rec2.USRX1
     , SDD_ATV_rec2.USRX2
     , SDD_ATV_rec2.USRX3
     , SDD_ATV_rec2.USRX4
     , SDD_ATV_rec2.USRX5
     , SDD_ATV_rec2.USRX6
     , SDD_ATV_rec2.USRX7
     , SDD_ATV_rec2.USRX8
     , SDD_ATV_rec2.USRX9
     , SDD_ATV_rec2.USRX10
     , SDD_ATV_rec2.USRX11
     , SDD_ATV_rec2.USRX12
     , SDD_ATV_rec2.USRX13
     , SDD_ATV_rec2.USRX14
     , SDD_ATV_rec2.USRX15
     , SDD_ATV_rec2.USRX16
     , SDD_ATV_rec2.USRX17
     , SDD_ATV_rec2.USRX18
     , SDD_ATV_rec2.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_ATV_rec2.irid, SDD_ATV_rec2.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_CQA_rec3 in SDD_CQA_cur3 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_CQA
    values (
       SDD_CQA_rec3.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_CQA_rec3.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_CQA_rec3.TYPES
     , SDD_CQA_rec3.ELEMENT_TYPE_NAME
     , SDD_CQA_rec3.DATE_CREATED
     , SDD_CQA_rec3.CREATED_BY
     , SDD_CQA_rec3.DATE_CHANGED
     , SDD_CQA_rec3.CHANGED_BY
     , SDD_CQA_rec3.NOTM
     , SDD_CQA_rec3.TABLE_DEFINITION_REF
     , SDD_CQA_rec3.QUALIFIED_NAME
     , SDD_CQA_rec3.OVERRIDE_DEFAULT_FLAG
     , SDD_CQA_rec3.DEFAULT_VALUE
     , SDD_CQA_rec3.NULL_INDICATOR
     , SDD_CQA_rec3.SCOPE_TABLE_REF
     , SDD_CQA_rec3.STORE_REF_WITH_ROWID_FLAG
     , SDD_CQA_rec3.CLUSTER_COLUMN_REF
     , SDD_CQA_rec3.USRX0
     , SDD_CQA_rec3.USRX1
     , SDD_CQA_rec3.USRX2
     , SDD_CQA_rec3.USRX3
     , SDD_CQA_rec3.USRX4
     , SDD_CQA_rec3.USRX5
     , SDD_CQA_rec3.USRX6
     , SDD_CQA_rec3.USRX7
     , SDD_CQA_rec3.USRX8
     , SDD_CQA_rec3.USRX9
     , SDD_CQA_rec3.USRX10
     , SDD_CQA_rec3.USRX11
     , SDD_CQA_rec3.USRX12
     , SDD_CQA_rec3.USRX13
     , SDD_CQA_rec3.USRX14
     , SDD_CQA_rec3.USRX15
     , SDD_CQA_rec3.USRX16
     , SDD_CQA_rec3.USRX17
     , SDD_CQA_rec3.USRX18
     , SDD_CQA_rec3.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_CQA_rec3.irid, SDD_CQA_rec3.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_CQACOL_rec4 in SDD_CQACOL_cur4 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_CQACOL
    values (
       SDD_CQACOL_rec4.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_CQACOL_rec4.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_CQACOL_rec4.TYPES
     , SDD_CQACOL_rec4.ELEMENT_TYPE_NAME
     , SDD_CQACOL_rec4.DATE_CREATED
     , SDD_CQACOL_rec4.CREATED_BY
     , SDD_CQACOL_rec4.DATE_CHANGED
     , SDD_CQACOL_rec4.CHANGED_BY
     , SDD_CQACOL_rec4.NOTM
     , SDD_CQACOL_rec4.CQA_REF
     , SDD_CQACOL_rec4.COLUMN_REF
     , SDD_CQACOL_rec4.SEQUENCE
    );
  jr_reg_ver.vercopy_dependencies(SDD_CQACOL_rec4.irid, SDD_CQACOL_rec4.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_DSY_rec5 in SDD_DSY_cur5 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_DSY
    values (
       SDD_DSY_rec5.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_DSY_rec5.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_DSY_rec5.TYPES
     , SDD_DSY_rec5.ELEMENT_TYPE_NAME
     , SDD_DSY_rec5.DATE_CREATED
     , SDD_DSY_rec5.CREATED_BY
     , SDD_DSY_rec5.DATE_CHANGED
     , SDD_DSY_rec5.CHANGED_BY
     , SDD_DSY_rec5.NOTM
     , SDD_DSY_rec5.TABLE_DEFINITION_REF
     , SDD_DSY_rec5.VIEW_DEFINITION_REF
     , SDD_DSY_rec5.SNAPSHOT_DEFINITION_REF
     , SDD_DSY_rec5.SEQUENCE_REF
     , SDD_DSY_rec5.PLSQL_MODULE_REF
     , SDD_DSY_rec5.JAVA_MODULE_REF
     , SDD_DSY_rec5.NAME
     , SDD_DSY_rec5.SCOPE
     , SDD_DSY_rec5.COMPLETE_FLAG
     , SDD_DSY_rec5.SYNONYM_FOR
     , SDD_DSY_rec5.USRX0
     , SDD_DSY_rec5.USRX1
     , SDD_DSY_rec5.USRX2
     , SDD_DSY_rec5.USRX3
     , SDD_DSY_rec5.USRX4
     , SDD_DSY_rec5.USRX5
     , SDD_DSY_rec5.USRX6
     , SDD_DSY_rec5.USRX7
     , SDD_DSY_rec5.USRX8
     , SDD_DSY_rec5.USRX9
     , SDD_DSY_rec5.USRX10
     , SDD_DSY_rec5.USRX11
     , SDD_DSY_rec5.USRX12
     , SDD_DSY_rec5.USRX13
     , SDD_DSY_rec5.USRX14
     , SDD_DSY_rec5.USRX15
     , SDD_DSY_rec5.USRX16
     , SDD_DSY_rec5.USRX17
     , SDD_DSY_rec5.USRX18
     , SDD_DSY_rec5.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_DSY_rec5.irid, SDD_DSY_rec5.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_IND_rec6 in SDD_IND_cur6 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_IND
    values (
       SDD_IND_rec6.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_IND_rec6.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_IND_rec6.TYPES
     , SDD_IND_rec6.ELEMENT_TYPE_NAME
     , SDD_IND_rec6.DATE_CREATED
     , SDD_IND_rec6.CREATED_BY
     , SDD_IND_rec6.DATE_CHANGED
     , SDD_IND_rec6.CHANGED_BY
     , SDD_IND_rec6.NOTM
     , SDD_IND_rec6.TABLE_DEFINITION_REF
     , SDD_IND_rec6.SNAPSHOT_DEFINITION_REF
     , SDD_IND_rec6.CLUSTER_REF
     , SDD_IND_rec6.NAME
     , SDD_IND_rec6.RELATION_INDEX_TYPE
     , SDD_IND_rec6.COMPLETE_FLAG
     , SDD_IND_rec6.COMPUTE_STATISTICS_FLAG
     , SDD_IND_rec6.FOREIGN_KEY_REF
     , SDD_IND_rec6.REMARK
     , SDD_IND_rec6.INDEX_TYPE
     , SDD_IND_rec6.RELATION_INDEX_FOR
     , SDD_IND_rec6.USRX0
     , SDD_IND_rec6.USRX1
     , SDD_IND_rec6.USRX2
     , SDD_IND_rec6.USRX3
     , SDD_IND_rec6.USRX4
     , SDD_IND_rec6.USRX5
     , SDD_IND_rec6.USRX6
     , SDD_IND_rec6.USRX7
     , SDD_IND_rec6.USRX8
     , SDD_IND_rec6.USRX9
     , SDD_IND_rec6.USRX10
     , SDD_IND_rec6.USRX11
     , SDD_IND_rec6.USRX12
     , SDD_IND_rec6.USRX13
     , SDD_IND_rec6.USRX14
     , SDD_IND_rec6.USRX15
     , SDD_IND_rec6.USRX16
     , SDD_IND_rec6.USRX17
     , SDD_IND_rec6.USRX18
     , SDD_IND_rec6.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_IND_rec6.irid, SDD_IND_rec6.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_INDCOL_rec7 in SDD_INDCOL_cur7 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_INDCOL
    values (
       SDD_INDCOL_rec7.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_INDCOL_rec7.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_INDCOL_rec7.TYPES
     , SDD_INDCOL_rec7.ELEMENT_TYPE_NAME
     , SDD_INDCOL_rec7.DATE_CREATED
     , SDD_INDCOL_rec7.CREATED_BY
     , SDD_INDCOL_rec7.DATE_CHANGED
     , SDD_INDCOL_rec7.CHANGED_BY
     , SDD_INDCOL_rec7.NOTM
     , SDD_INDCOL_rec7.RELATION_INDEX_REF
     , SDD_INDCOL_rec7.COLUMN_REF
     , SDD_INDCOL_rec7.SEQUENCE_NUMBER
     , SDD_INDCOL_rec7.INDEX_FUNCTION
     , SDD_INDCOL_rec7.INDEX_ENTRY_TYPE
     , SDD_INDCOL_rec7.NAME
     , SDD_INDCOL_rec7.CQA_REF
     , SDD_INDCOL_rec7.INDEX_ENTRY_FOR
     , SDD_INDCOL_rec7.USRX0
     , SDD_INDCOL_rec7.USRX1
     , SDD_INDCOL_rec7.USRX2
     , SDD_INDCOL_rec7.USRX3
     , SDD_INDCOL_rec7.USRX4
     , SDD_INDCOL_rec7.USRX5
     , SDD_INDCOL_rec7.USRX6
     , SDD_INDCOL_rec7.USRX7
     , SDD_INDCOL_rec7.USRX8
     , SDD_INDCOL_rec7.USRX9
     , SDD_INDCOL_rec7.USRX10
     , SDD_INDCOL_rec7.USRX11
     , SDD_INDCOL_rec7.USRX12
     , SDD_INDCOL_rec7.USRX13
     , SDD_INDCOL_rec7.USRX14
     , SDD_INDCOL_rec7.USRX15
     , SDD_INDCOL_rec7.USRX16
     , SDD_INDCOL_rec7.USRX17
     , SDD_INDCOL_rec7.USRX18
     , SDD_INDCOL_rec7.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_INDCOL_rec7.irid, SDD_INDCOL_rec7.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_OCO_rec8 in SDD_OCO_cur8 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_OCO
    values (
       SDD_OCO_rec8.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_OCO_rec8.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_OCO_rec8.TYPES
     , SDD_OCO_rec8.ELEMENT_TYPE_NAME
     , SDD_OCO_rec8.DATE_CREATED
     , SDD_OCO_rec8.CREATED_BY
     , SDD_OCO_rec8.DATE_CHANGED
     , SDD_OCO_rec8.CHANGED_BY
     , SDD_OCO_rec8.NOTM
     , SDD_OCO_rec8.TABLE_REF
     , SDD_OCO_rec8.FOREIGN_TABLE_REF
     , SDD_OCO_rec8.NAME
     , SDD_OCO_rec8.COMPLETE_FLAG
     , SDD_OCO_rec8.ENABLED_FLAG
     , SDD_OCO_rec8.MANDATORY_FLAG
     , SDD_OCO_rec8.FK_TRANSFERABLE
     , SDD_OCO_rec8.KEY_UPDATEABLE
     , SDD_OCO_rec8.NULL_IS_DISCRETE_VALUE_FLAG
     , SDD_OCO_rec8.IMPLEMENTATION_LEVEL
     , SDD_OCO_rec8.DEFER_STATUS
     , SDD_OCO_rec8.ERROR_MESSAGE
     , SDD_OCO_rec8.EXCEPTION_TABLE
     , SDD_OCO_rec8.CLIENT_ENFORCE_WHEN_NULL_FLAG
     , SDD_OCO_rec8.CHECK_CONSTRAINT_TYPE
     , SDD_OCO_rec8.FK_CASCADE_DELETE
     , SDD_OCO_rec8.REMARK
     , SDD_OCO_rec8.FK_CASCADE_UPDATE
     , SDD_OCO_rec8.ARC_NUMBER
     , SDD_OCO_rec8.ARC_MANDATORY
     , SDD_OCO_rec8.PRIMARY_KEY_REF
     , SDD_OCO_rec8.UNIQUE_KEY_REF
     , SDD_OCO_rec8.RELATIONSHIP_END_REF
     , SDD_OCO_rec8.UNIQUE_IDENTIFIER_REF
     , SDD_OCO_rec8.CONSTRAINT_TYPE
     , SDD_OCO_rec8.FOR_JOINING_TO
     , SDD_OCO_rec8.USRX0
     , SDD_OCO_rec8.USRX1
     , SDD_OCO_rec8.USRX2
     , SDD_OCO_rec8.USRX3
     , SDD_OCO_rec8.USRX4
     , SDD_OCO_rec8.USRX5
     , SDD_OCO_rec8.USRX6
     , SDD_OCO_rec8.USRX7
     , SDD_OCO_rec8.USRX8
     , SDD_OCO_rec8.USRX9
     , SDD_OCO_rec8.USRX10
     , SDD_OCO_rec8.USRX11
     , SDD_OCO_rec8.USRX12
     , SDD_OCO_rec8.USRX13
     , SDD_OCO_rec8.USRX14
     , SDD_OCO_rec8.USRX15
     , SDD_OCO_rec8.USRX16
     , SDD_OCO_rec8.USRX17
     , SDD_OCO_rec8.USRX18
     , SDD_OCO_rec8.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_OCO_rec8.irid, SDD_OCO_rec8.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_OKY_rec9 in SDD_OKY_cur9 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_OKY
    values (
       SDD_OKY_rec9.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_OKY_rec9.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_OKY_rec9.TYPES
     , SDD_OKY_rec9.ELEMENT_TYPE_NAME
     , SDD_OKY_rec9.DATE_CREATED
     , SDD_OKY_rec9.CREATED_BY
     , SDD_OKY_rec9.DATE_CHANGED
     , SDD_OKY_rec9.CHANGED_BY
     , SDD_OKY_rec9.NOTM
     , SDD_OKY_rec9.CONSTRAINT_REF
     , SDD_OKY_rec9.CONSTRAINT_TYPE
     , SDD_OKY_rec9.COLUMN_REF
     , SDD_OKY_rec9.SEQUENCE_NUMBER
     , SDD_OKY_rec9.FOREIGN_COLUMN_REF
     , SDD_OKY_rec9.FOREIGN_COLUMN_REF2
     , SDD_OKY_rec9.CONVERSION_FORMAT_MODIFIER
     , SDD_OKY_rec9.REMARK
     , SDD_OKY_rec9.FOREIGN_CQA_REF
     , SDD_OKY_rec9.FOREIGN_CQA_REF2
     , SDD_OKY_rec9.CQA_REF
     , SDD_OKY_rec9.OKY_ARC1_FOR
     , SDD_OKY_rec9.OKY_ARC2_FOR
     , SDD_OKY_rec9.OKY_ARC3_FOR
     , SDD_OKY_rec9.USRX0
     , SDD_OKY_rec9.USRX1
     , SDD_OKY_rec9.USRX2
     , SDD_OKY_rec9.USRX3
     , SDD_OKY_rec9.USRX4
     , SDD_OKY_rec9.USRX5
     , SDD_OKY_rec9.USRX6
     , SDD_OKY_rec9.USRX7
     , SDD_OKY_rec9.USRX8
     , SDD_OKY_rec9.USRX9
     , SDD_OKY_rec9.USRX10
     , SDD_OKY_rec9.USRX11
     , SDD_OKY_rec9.USRX12
     , SDD_OKY_rec9.USRX13
     , SDD_OKY_rec9.USRX14
     , SDD_OKY_rec9.USRX15
     , SDD_OKY_rec9.USRX16
     , SDD_OKY_rec9.USRX17
     , SDD_OKY_rec9.USRX18
     , SDD_OKY_rec9.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_OKY_rec9.irid, SDD_OKY_rec9.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_TABENT_rec10 in SDD_TABENT_cur10 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_TABENT
    values (
       SDD_TABENT_rec10.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_TABENT_rec10.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_TABENT_rec10.TYPES
     , SDD_TABENT_rec10.ELEMENT_TYPE_NAME
     , SDD_TABENT_rec10.DATE_CREATED
     , SDD_TABENT_rec10.CREATED_BY
     , SDD_TABENT_rec10.DATE_CHANGED
     , SDD_TABENT_rec10.CHANGED_BY
     , SDD_TABENT_rec10.NOTM
     , SDD_TABENT_rec10.TABLE_REF
     , SDD_TABENT_rec10.ENTITY_REF
     , SDD_TABENT_rec10.MAPPING_TYPE
     , SDD_TABENT_rec10.COLUMN_REF
     , SDD_TABENT_rec10.DISCRIMINATOR_VALUE
     , SDD_TABENT_rec10.REMARK
     , SDD_TABENT_rec10.MAPPING_MODE
     , SDD_TABENT_rec10.USRX0
     , SDD_TABENT_rec10.USRX1
     , SDD_TABENT_rec10.USRX2
     , SDD_TABENT_rec10.USRX3
     , SDD_TABENT_rec10.USRX4
     , SDD_TABENT_rec10.USRX5
     , SDD_TABENT_rec10.USRX6
     , SDD_TABENT_rec10.USRX7
     , SDD_TABENT_rec10.USRX8
     , SDD_TABENT_rec10.USRX9
     , SDD_TABENT_rec10.USRX10
     , SDD_TABENT_rec10.USRX11
     , SDD_TABENT_rec10.USRX12
     , SDD_TABENT_rec10.USRX13
     , SDD_TABENT_rec10.USRX14
     , SDD_TABENT_rec10.USRX15
     , SDD_TABENT_rec10.USRX16
     , SDD_TABENT_rec10.USRX17
     , SDD_TABENT_rec10.USRX18
     , SDD_TABENT_rec10.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_TABENT_rec10.irid, SDD_TABENT_rec10.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_TRG_rec11 in SDD_TRG_cur11 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_TRG
    values (
       SDD_TRG_rec11.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_TRG_rec11.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_TRG_rec11.TYPES
     , SDD_TRG_rec11.ELEMENT_TYPE_NAME
     , SDD_TRG_rec11.DATE_CREATED
     , SDD_TRG_rec11.CREATED_BY
     , SDD_TRG_rec11.DATE_CHANGED
     , SDD_TRG_rec11.CHANGED_BY
     , SDD_TRG_rec11.NOTM
     , SDD_TRG_rec11.TABLE_DEFINITION_REF
     , SDD_TRG_rec11.VIEW_DEFINITION_REF
     , SDD_TRG_rec11.NAME
     , SDD_TRG_rec11.PURPOSE
     , SDD_TRG_rec11.PLSQL_MODULE_REF
     , SDD_TRG_rec11.COMPLETE_FLAG
     , SDD_TRG_rec11.ENABLED_FLAG
     , SDD_TRG_rec11.EXECUTE_TIME
     , SDD_TRG_rec11.TRIGGER_LEVEL
     , SDD_TRG_rec11.TRIGGER_ON_INSERT
     , SDD_TRG_rec11.TRIGGER_ON_DELETE
     , SDD_TRG_rec11.TRIGGER_ON_UPDATE
     , SDD_TRG_rec11.FIRE_WHEN_PROPAGATED_FLAG
     , SDD_TRG_rec11.NEW_ALIAS
     , SDD_TRG_rec11.OLD_ALIAS
     , SDD_TRG_rec11.DATABASE_TRIGGER_FOR
     , SDD_TRG_rec11.USRX0
     , SDD_TRG_rec11.USRX1
     , SDD_TRG_rec11.USRX2
     , SDD_TRG_rec11.USRX3
     , SDD_TRG_rec11.USRX4
     , SDD_TRG_rec11.USRX5
     , SDD_TRG_rec11.USRX6
     , SDD_TRG_rec11.USRX7
     , SDD_TRG_rec11.USRX8
     , SDD_TRG_rec11.USRX9
     , SDD_TRG_rec11.USRX10
     , SDD_TRG_rec11.USRX11
     , SDD_TRG_rec11.USRX12
     , SDD_TRG_rec11.USRX13
     , SDD_TRG_rec11.USRX14
     , SDD_TRG_rec11.USRX15
     , SDD_TRG_rec11.USRX16
     , SDD_TRG_rec11.USRX17
     , SDD_TRG_rec11.USRX18
     , SDD_TRG_rec11.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_TRG_rec11.irid, SDD_TRG_rec11.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_TRGCOL_rec12 in SDD_TRGCOL_cur12 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_TRGCOL
    values (
       SDD_TRGCOL_rec12.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_TRGCOL_rec12.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_TRGCOL_rec12.TYPES
     , SDD_TRGCOL_rec12.ELEMENT_TYPE_NAME
     , SDD_TRGCOL_rec12.DATE_CREATED
     , SDD_TRGCOL_rec12.CREATED_BY
     , SDD_TRGCOL_rec12.DATE_CHANGED
     , SDD_TRGCOL_rec12.CHANGED_BY
     , SDD_TRGCOL_rec12.NOTM
     , SDD_TRGCOL_rec12.DATABASE_TRIGGER_REF
     , SDD_TRGCOL_rec12.COLUMN_REF
     , SDD_TRGCOL_rec12.TABLE_REFERENCE
     , SDD_TRGCOL_rec12.USRX0
     , SDD_TRGCOL_rec12.USRX1
     , SDD_TRGCOL_rec12.USRX2
     , SDD_TRGCOL_rec12.USRX3
     , SDD_TRGCOL_rec12.USRX4
     , SDD_TRGCOL_rec12.USRX5
     , SDD_TRGCOL_rec12.USRX6
     , SDD_TRGCOL_rec12.USRX7
     , SDD_TRGCOL_rec12.USRX8
     , SDD_TRGCOL_rec12.USRX9
     , SDD_TRGCOL_rec12.USRX10
     , SDD_TRGCOL_rec12.USRX11
     , SDD_TRGCOL_rec12.USRX12
     , SDD_TRGCOL_rec12.USRX13
     , SDD_TRGCOL_rec12.USRX14
     , SDD_TRGCOL_rec12.USRX15
     , SDD_TRGCOL_rec12.USRX16
     , SDD_TRGCOL_rec12.USRX17
     , SDD_TRGCOL_rec12.USRX18
     , SDD_TRGCOL_rec12.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_TRGCOL_rec12.irid, SDD_TRGCOL_rec12.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_VWTAB_rec13 in SDD_VWTAB_cur13 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_VWTAB
    values (
       SDD_VWTAB_rec13.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_VWTAB_rec13.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_VWTAB_rec13.TYPES
     , SDD_VWTAB_rec13.ELEMENT_TYPE_NAME
     , SDD_VWTAB_rec13.DATE_CREATED
     , SDD_VWTAB_rec13.CREATED_BY
     , SDD_VWTAB_rec13.DATE_CHANGED
     , SDD_VWTAB_rec13.CHANGED_BY
     , SDD_VWTAB_rec13.NOTM
     , SDD_VWTAB_rec13.VIEW_REF
     , SDD_VWTAB_rec13.TABLE_REF
     , SDD_VWTAB_rec13.SEQUENCE_NUMBER
     , SDD_VWTAB_rec13.ALIAS
     , SDD_VWTAB_rec13.SUBQUERY_USAGE_FLAG
     , SDD_VWTAB_rec13.USRX0
     , SDD_VWTAB_rec13.USRX1
     , SDD_VWTAB_rec13.USRX2
     , SDD_VWTAB_rec13.USRX3
     , SDD_VWTAB_rec13.USRX4
     , SDD_VWTAB_rec13.USRX5
     , SDD_VWTAB_rec13.USRX6
     , SDD_VWTAB_rec13.USRX7
     , SDD_VWTAB_rec13.USRX8
     , SDD_VWTAB_rec13.USRX9
     , SDD_VWTAB_rec13.USRX10
     , SDD_VWTAB_rec13.USRX11
     , SDD_VWTAB_rec13.USRX12
     , SDD_VWTAB_rec13.USRX13
     , SDD_VWTAB_rec13.USRX14
     , SDD_VWTAB_rec13.USRX15
     , SDD_VWTAB_rec13.USRX16
     , SDD_VWTAB_rec13.USRX17
     , SDD_VWTAB_rec13.USRX18
     , SDD_VWTAB_rec13.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_VWTAB_rec13.irid, SDD_VWTAB_rec13.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  jr_reg_ver.vercopy_dependent_objects(SDD_TAB_ver.ivid, new_ivid);
  return new_ivid;
end SDD_TAB_ver;
/
create or replace function PK_SDD_TAB (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_TAB the_tab_new, SDD_TAB the_tab_old
  where  the_tab_new.ivid = PK_SDD_TAB.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_TAB.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_TAB;
/
create or replace function FK_TAB_RFI (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.RECORD_FILE_REF ref_value
  from   i$SDD_TAB the_tab
  where  the_tab.ivid = FK_TAB_RFI.object_ivid
  and    the_tab.RECORD_FILE_REF is not null
  and    not exists (
             select null
             from   SDD_FIL foreign_tab
             where  the_tab.RECORD_FILE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5023, action);
  end loop;
  return is_ok;
end FK_TAB_RFI;
/
create or replace function FK_TAB_TO_OCL (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.CLUSTER_REF ref_value
  from   i$SDD_TAB the_tab
  where  the_tab.ivid = FK_TAB_TO_OCL.object_ivid
  and    the_tab.CLUSTER_REF is not null
  and    not exists (
             select null
             from   SDD_OCL foreign_tab
             where  the_tab.CLUSTER_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4992, action);
  end loop;
  return is_ok;
end FK_TAB_TO_OCL;
/
create or replace function FK_TAB_TO_OOT (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ORACLE_OBJECT_TYPE_REF ref_value
  from   i$SDD_TAB the_tab
  where  the_tab.ivid = FK_TAB_TO_OOT.object_ivid
  and    the_tab.ORACLE_OBJECT_TYPE_REF is not null
  and    not exists (
             select null
             from   SDD_ORT foreign_tab
             where  the_tab.ORACLE_OBJECT_TYPE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4858, action);
  end loop;
  return is_ok;
end FK_TAB_TO_OOT;
/
create or replace function PK_SDD_TABENT (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_TABENT the_tab_new, SDD_TABENT the_tab_old
  where  the_tab_new.ivid = PK_SDD_TABENT.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_TABENT.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_TABENT;
/
create or replace function FK_TABENT_TO_COL (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.COLUMN_REF ref_value
  from   i$SDD_TABENT the_tab
  where  the_tab.ivid = FK_TABENT_TO_COL.object_ivid
  and    the_tab.COLUMN_REF is not null
  and    not exists (
             select null
             from   SDD_COL foreign_tab
             where  the_tab.COLUMN_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5014, action);
  end loop;
  return is_ok;
end FK_TABENT_TO_COL;
/
create or replace function FK_TABENT_TO_ENT (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ENTITY_REF ref_value
  from   i$SDD_TABENT the_tab
  where  the_tab.ivid = FK_TABENT_TO_ENT.object_ivid
  and    the_tab.ENTITY_REF is not null
  and    not exists (
             select null
             from   SDD_ENT foreign_tab
             where  the_tab.ENTITY_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5002, action);
  end loop;
  return is_ok;
end FK_TABENT_TO_ENT;
/
create or replace function PK_SDD_TAG (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_TAG the_tab_new, SDD_TAG the_tab_old
  where  the_tab_new.ivid = PK_SDD_TAG.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_TAG.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_TAG;
/
create or replace function PK_SDD_TAGVAL (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_TAGVAL the_tab_new, SDD_TAGVAL the_tab_old
  where  the_tab_new.ivid = PK_SDD_TAGVAL.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_TAGVAL.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_TAGVAL;
/
create or replace function UK_TAGVAL (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_TAGVAL the_tab_new, SDD_TAGVAL the_tab_old
  where  the_tab_new.ivid = UK_TAGVAL.ivid
  and    the_tab_new.ELEMENT_REF = the_tab_old.ELEMENT_REF
  and    the_tab_new.TAG_REF = the_tab_old.TAG_REF
  and    the_tab_old.ivid != UK_TAGVAL.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end UK_TAGVAL;
/
create or replace function FK_TAGVAL_TO_TAG (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.TAG_REF ref_value
  from   i$SDD_TAGVAL the_tab
  where  the_tab.ivid = FK_TAGVAL_TO_TAG.object_ivid
  and    the_tab.TAG_REF is not null
  and    not exists (
             select null
             from   SDD_TAG foreign_tab
             where  the_tab.TAG_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5148, action);
  end loop;
  return is_ok;
end FK_TAGVAL_TO_TAG;
/
create or replace function PK_SDD_TBICOL (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_TBICOL the_tab_new, SDD_TBICOL the_tab_old
  where  the_tab_new.ivid = PK_SDD_TBICOL.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_TBICOL.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_TBICOL;
/
create or replace function FK_TBICOL_TO_COL (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.COLUMN_REF ref_value
  from   i$SDD_TBICOL the_tab
  where  the_tab.ivid = FK_TBICOL_TO_COL.object_ivid
  and    the_tab.COLUMN_REF is not null
  and    not exists (
             select null
             from   SDD_COL foreign_tab
             where  the_tab.COLUMN_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5014, action);
  end loop;
  return is_ok;
end FK_TBICOL_TO_COL;
/
create or replace function PK_SDD_TBP (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_TBP the_tab_new, SDD_TBP the_tab_old
  where  the_tab_new.ivid = PK_SDD_TBP.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_TBP.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_TBP;
/
create or replace function FK_TBP_TO_OSP (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.STORAGE_DEFINITION_REF ref_value
  from   i$SDD_TBP the_tab
  where  the_tab.ivid = FK_TBP_TO_OSP.object_ivid
  and    the_tab.STORAGE_DEFINITION_REF is not null
  and    not exists (
             select null
             from   SDD_OSP foreign_tab
             where  the_tab.STORAGE_DEFINITION_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5000, action);
  end loop;
  return is_ok;
end FK_TBP_TO_OSP;
/
create or replace function FK_TBP_TO_OTB (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.TABLESPACE_REF ref_value
  from   i$SDD_TBP the_tab
  where  the_tab.ivid = FK_TBP_TO_OTB.object_ivid
  and    the_tab.TABLESPACE_REF is not null
  and    not exists (
             select null
             from   SDD_OTB foreign_tab
             where  the_tab.TABLESPACE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5001, action);
  end loop;
  return is_ok;
end FK_TBP_TO_OTB;
/
create or replace function SDD_TER_ver (irid number, ivid number, copy_dependencies boolean default true) return number as
  new_ivid           number; -- new ivid of primary object
  new_secondary_ivid number; -- new ivid of secondary objects
  cursor SDD_TER_cur is
    select *
    from   i$SDD_TER the_tab
    where  the_tab.irid=SDD_TER_ver.irid
    and    the_tab.ivid=SDD_TER_ver.ivid;
  SDD_TER_rec SDD_TER_cur%ROWTYPE;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_TER_cur;
  fetch SDD_TER_cur into SDD_TER_rec;
  close SDD_TER_cur;
  insert into i$SDD_TER
  values (
    SDD_TER_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_TER_rec.TYPES
   ,SDD_TER_rec.ELEMENT_TYPE_NAME
   ,SDD_TER_rec.DATE_CREATED
   ,SDD_TER_rec.CREATED_BY
   ,SDD_TER_rec.DATE_CHANGED
   ,SDD_TER_rec.CHANGED_BY
   ,SDD_TER_rec.NOTM
   ,SDD_TER_rec.NAME
   ,SDD_TER_rec.REMARK
   ,SDD_TER_rec.GLOSSARY_GROUPING_CHARACTER
   ,SDD_TER_rec.USRX0
   ,SDD_TER_rec.USRX1
   ,SDD_TER_rec.USRX2
   ,SDD_TER_rec.USRX3
   ,SDD_TER_rec.USRX4
   ,SDD_TER_rec.USRX5
   ,SDD_TER_rec.USRX6
   ,SDD_TER_rec.USRX7
   ,SDD_TER_rec.USRX8
   ,SDD_TER_rec.USRX9
   ,SDD_TER_rec.USRX10
   ,SDD_TER_rec.USRX11
   ,SDD_TER_rec.USRX12
   ,SDD_TER_rec.USRX13
   ,SDD_TER_rec.USRX14
   ,SDD_TER_rec.USRX15
   ,SDD_TER_rec.USRX16
   ,SDD_TER_rec.USRX17
   ,SDD_TER_rec.USRX18
   ,SDD_TER_rec.USRX19
  );
  jr_reg_ver.vercopy_dependencies(SDD_TER_ver.irid, SDD_TER_ver.ivid, new_ivid, null, copy_dependencies);
  jr_reg_ver.vercopy_dependent_objects(SDD_TER_ver.ivid, new_ivid);
  return new_ivid;
end SDD_TER_ver;
/
create or replace function PK_SDD_TER (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_TER the_tab_new, SDD_TER the_tab_old
  where  the_tab_new.ivid = PK_SDD_TER.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_TER.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_TER;
/
create or replace function SDD_TMS_ver (irid number, ivid number, copy_dependencies boolean default true) return number as
  new_ivid           number; -- new ivid of primary object
  new_secondary_ivid number; -- new ivid of secondary objects
  cursor SDD_TMS_cur is
    select *
    from   i$SDD_TMS the_tab
    where  the_tab.irid=SDD_TMS_ver.irid
    and    the_tab.ivid=SDD_TMS_ver.ivid;
  SDD_TMS_rec SDD_TMS_cur%ROWTYPE;
  cursor SDD_MAP_cur1 is
    select *
    from i$SDD_MAP the_tab
    where the_tab.parent_ivid=SDD_TMS_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_TMS_cur;
  fetch SDD_TMS_cur into SDD_TMS_rec;
  close SDD_TMS_cur;
  insert into i$SDD_TMS
  values (
    SDD_TMS_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_TMS_rec.TYPES
   ,SDD_TMS_rec.ELEMENT_TYPE_NAME
   ,SDD_TMS_rec.DATE_CREATED
   ,SDD_TMS_rec.CREATED_BY
   ,SDD_TMS_rec.DATE_CHANGED
   ,SDD_TMS_rec.CHANGED_BY
   ,SDD_TMS_rec.NOTM
   ,SDD_TMS_rec.TRANSFORMATION_TYPE
   ,SDD_TMS_rec.REMARK
   ,SDD_TMS_rec.USRX0
   ,SDD_TMS_rec.USRX1
   ,SDD_TMS_rec.USRX2
   ,SDD_TMS_rec.USRX3
   ,SDD_TMS_rec.USRX4
   ,SDD_TMS_rec.USRX5
   ,SDD_TMS_rec.USRX6
   ,SDD_TMS_rec.USRX7
   ,SDD_TMS_rec.USRX8
   ,SDD_TMS_rec.USRX9
   ,SDD_TMS_rec.USRX10
   ,SDD_TMS_rec.USRX11
   ,SDD_TMS_rec.USRX12
   ,SDD_TMS_rec.USRX13
   ,SDD_TMS_rec.USRX14
   ,SDD_TMS_rec.USRX15
   ,SDD_TMS_rec.USRX16
   ,SDD_TMS_rec.USRX17
   ,SDD_TMS_rec.USRX18
   ,SDD_TMS_rec.USRX19
  );
  jr_reg_ver.vercopy_dependencies(SDD_TMS_ver.irid, SDD_TMS_ver.ivid, new_ivid, null, copy_dependencies);
  for SDD_MAP_rec1 in SDD_MAP_cur1 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_MAP
    values (
       SDD_MAP_rec1.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_MAP_rec1.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_MAP_rec1.TYPES
     , SDD_MAP_rec1.ELEMENT_TYPE_NAME
     , SDD_MAP_rec1.DATE_CREATED
     , SDD_MAP_rec1.CREATED_BY
     , SDD_MAP_rec1.DATE_CHANGED
     , SDD_MAP_rec1.CHANGED_BY
     , SDD_MAP_rec1.NOTM
     , SDD_MAP_rec1.TRANSFORMATION_SET_REF
     , SDD_MAP_rec1.SOURCE_CIELEMENT_REF
     , SDD_MAP_rec1.SOURCE_ELEMENT_TYPE
     , SDD_MAP_rec1.TARGET_CIELEMENT_REF
     , SDD_MAP_rec1.TARGET_ELEMENT_TYPE
     , SDD_MAP_rec1.CREATED_BY_TRANSFORMER_FLAG
     , SDD_MAP_rec1.PRIMARY_MAPPING_REF
     , SDD_MAP_rec1.ROLE_NAME
    );
  jr_reg_ver.vercopy_dependencies(SDD_MAP_rec1.irid, SDD_MAP_rec1.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  jr_reg_ver.vercopy_dependent_objects(SDD_TMS_ver.ivid, new_ivid);
  return new_ivid;
end SDD_TMS_ver;
/
create or replace function PK_SDD_TMS (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_TMS the_tab_new, SDD_TMS the_tab_old
  where  the_tab_new.ivid = PK_SDD_TMS.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_TMS.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_TMS;
/
create or replace function PK_SDD_TRA (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_TRA the_tab_new, SDD_TRA the_tab_old
  where  the_tab_new.ivid = PK_SDD_TRA.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_TRA.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_TRA;
/
create or replace function FK_TRA_TO_ACT2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.TARGET_ACTIVITY_REF ref_value
  from   i$SDD_TRA the_tab
  where  the_tab.ivid = FK_TRA_TO_ACT2.object_ivid
  and    the_tab.TARGET_ACTIVITY_REF is not null
  and    not exists (
             select null
             from   SDD_ACT foreign_tab
             where  the_tab.TARGET_ACTIVITY_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4843, action);
  end loop;
  return is_ok;
end FK_TRA_TO_ACT2;
/
create or replace function FK_TRA_TO_ACTORG2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.TARGET_ACT_USAGE_REF ref_value
  from   i$SDD_TRA the_tab
  where  the_tab.ivid = FK_TRA_TO_ACTORG2.object_ivid
  and    the_tab.TARGET_ACT_USAGE_REF is not null
  and    not exists (
             select null
             from   SDD_ACTORG foreign_tab
             where  the_tab.TARGET_ACT_USAGE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4829, action);
  end loop;
  return is_ok;
end FK_TRA_TO_ACTORG2;
/
create or replace function FK_TRA_TO_CLAEVC (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.EVENT_PUBLICATION_REF ref_value
  from   i$SDD_TRA the_tab
  where  the_tab.ivid = FK_TRA_TO_CLAEVC.object_ivid
  and    the_tab.EVENT_PUBLICATION_REF is not null
  and    not exists (
             select null
             from   SDD_CLAEVC foreign_tab
             where  the_tab.EVENT_PUBLICATION_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5081, action);
  end loop;
  return is_ok;
end FK_TRA_TO_CLAEVC;
/
create or replace function FK_TRA_TO_EVC2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.TARGET_EVENT_REF ref_value
  from   i$SDD_TRA the_tab
  where  the_tab.ivid = FK_TRA_TO_EVC2.object_ivid
  and    the_tab.TARGET_EVENT_REF is not null
  and    not exists (
             select null
             from   SDD_CLA foreign_tab
             where  the_tab.TARGET_EVENT_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4841, action);
  end loop;
  return is_ok;
end FK_TRA_TO_EVC2;
/
create or replace function FK_TRA_TO_EVC3 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.TRIGGER_EVENT_REF ref_value
  from   i$SDD_TRA the_tab
  where  the_tab.ivid = FK_TRA_TO_EVC3.object_ivid
  and    the_tab.TRIGGER_EVENT_REF is not null
  and    not exists (
             select null
             from   SDD_CLA foreign_tab
             where  the_tab.TRIGGER_EVENT_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4841, action);
  end loop;
  return is_ok;
end FK_TRA_TO_EVC3;
/
create or replace function FK_TRA_TO_EVS (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.EVENT_SUBSCRIPTION_REF ref_value
  from   i$SDD_TRA the_tab
  where  the_tab.ivid = FK_TRA_TO_EVS.object_ivid
  and    the_tab.EVENT_SUBSCRIPTION_REF is not null
  and    not exists (
             select null
             from   SDD_EVS foreign_tab
             where  the_tab.EVENT_SUBSCRIPTION_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5083, action);
  end loop;
  return is_ok;
end FK_TRA_TO_EVS;
/
create or replace function FK_TRA_TO_OST2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.TARGET_OBJECT_STATE_REF ref_value
  from   i$SDD_TRA the_tab
  where  the_tab.ivid = FK_TRA_TO_OST2.object_ivid
  and    the_tab.TARGET_OBJECT_STATE_REF is not null
  and    not exists (
             select null
             from   SDD_OST foreign_tab
             where  the_tab.TARGET_OBJECT_STATE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4831, action);
  end loop;
  return is_ok;
end FK_TRA_TO_OST2;
/
create or replace function FK_TRA_TO_PSE2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.TARGET_PSEUDOSTATE_REF ref_value
  from   i$SDD_TRA the_tab
  where  the_tab.ivid = FK_TRA_TO_PSE2.object_ivid
  and    the_tab.TARGET_PSEUDOSTATE_REF is not null
  and    not exists (
             select null
             from   SDD_PSE foreign_tab
             where  the_tab.TARGET_PSEUDOSTATE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4836, action);
  end loop;
  return is_ok;
end FK_TRA_TO_PSE2;
/
create or replace function FK_TRA_TO_RUL (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.NAMED_RULE_REF ref_value
  from   i$SDD_TRA the_tab
  where  the_tab.ivid = FK_TRA_TO_RUL.object_ivid
  and    the_tab.NAMED_RULE_REF is not null
  and    not exists (
             select null
             from   SDD_RUL foreign_tab
             where  the_tab.NAMED_RULE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4833, action);
  end loop;
  return is_ok;
end FK_TRA_TO_RUL;
/
create or replace function FK_TRA_TO_TRA (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.TRANSITION_REF ref_value
  from   i$SDD_TRA the_tab
  where  the_tab.ivid = FK_TRA_TO_TRA.object_ivid
  and    the_tab.TRANSITION_REF is not null
  and    not exists (
             select null
             from   SDD_TRA foreign_tab
             where  the_tab.TRANSITION_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4828, action);
  end loop;
  return is_ok;
end FK_TRA_TO_TRA;
/
create or replace function PK_SDD_TRG (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_TRG the_tab_new, SDD_TRG the_tab_old
  where  the_tab_new.ivid = PK_SDD_TRG.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_TRG.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_TRG;
/
create or replace function FK_TRG_TO_PLM (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.PLSQL_MODULE_REF ref_value
  from   i$SDD_TRG the_tab
  where  the_tab.ivid = FK_TRG_TO_PLM.object_ivid
  and    the_tab.PLSQL_MODULE_REF is not null
  and    not exists (
             select null
             from   SDD_MOD foreign_tab
             where  the_tab.PLSQL_MODULE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5022, action);
  end loop;
  return is_ok;
end FK_TRG_TO_PLM;
/
create or replace function PK_SDD_TRGCOL (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_TRGCOL the_tab_new, SDD_TRGCOL the_tab_old
  where  the_tab_new.ivid = PK_SDD_TRGCOL.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_TRGCOL.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_TRGCOL;
/
create or replace function FK_TRGCOL_TO_COL (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.COLUMN_REF ref_value
  from   i$SDD_TRGCOL the_tab
  where  the_tab.ivid = FK_TRGCOL_TO_COL.object_ivid
  and    the_tab.COLUMN_REF is not null
  and    not exists (
             select null
             from   SDD_COL foreign_tab
             where  the_tab.COLUMN_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5014, action);
  end loop;
  return is_ok;
end FK_TRGCOL_TO_COL;
/
create or replace function PK_SDD_TSQ (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_TSQ the_tab_new, SDD_TSQ the_tab_old
  where  the_tab_new.ivid = PK_SDD_TSQ.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_TSQ.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_TSQ;
/
create or replace function FK_TSQ_TO_OTB (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.TABLESPACE_REF ref_value
  from   i$SDD_TSQ the_tab
  where  the_tab.ivid = FK_TSQ_TO_OTB.object_ivid
  and    the_tab.TABLESPACE_REF is not null
  and    not exists (
             select null
             from   SDD_OTB foreign_tab
             where  the_tab.TABLESPACE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5001, action);
  end loop;
  return is_ok;
end FK_TSQ_TO_OTB;
/
create or replace function PK_SDD_UCA (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_UCA the_tab_new, SDD_UCA the_tab_old
  where  the_tab_new.ivid = PK_SDD_UCA.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_UCA.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_UCA;
/
create or replace function FK_UCA_TO_GEA (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.GENERAL_ACTION_REF ref_value
  from   i$SDD_UCA the_tab
  where  the_tab.ivid = FK_UCA_TO_GEA.object_ivid
  and    the_tab.GENERAL_ACTION_REF is not null
  and    not exists (
             select null
             from   SDD_UCA foreign_tab
             where  the_tab.GENERAL_ACTION_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5111, action);
  end loop;
  return is_ok;
end FK_UCA_TO_GEA;
/
create or replace function FK_UCA_TO_USC2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.USE_CASE_INVOKED_REF ref_value
  from   i$SDD_UCA the_tab
  where  the_tab.ivid = FK_UCA_TO_USC2.object_ivid
  and    the_tab.USE_CASE_INVOKED_REF is not null
  and    not exists (
             select null
             from   SDD_USC foreign_tab
             where  the_tab.USE_CASE_INVOKED_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5104, action);
  end loop;
  return is_ok;
end FK_UCA_TO_USC2;
/
create or replace function FK_UCA_TO_USCEVO (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.USE_CASE_EVENT_OUT_REF ref_value
  from   i$SDD_UCA the_tab
  where  the_tab.ivid = FK_UCA_TO_USCEVO.object_ivid
  and    the_tab.USE_CASE_EVENT_OUT_REF is not null
  and    not exists (
             select null
             from   SDD_USCEVO foreign_tab
             where  the_tab.USE_CASE_EVENT_OUT_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5108, action);
  end loop;
  return is_ok;
end FK_UCA_TO_USCEVO;
/
create or replace function SDD_UDE_ver (irid number, ivid number, copy_dependencies boolean default true) return number as
  new_ivid           number; -- new ivid of primary object
  new_secondary_ivid number; -- new ivid of secondary objects
  cursor SDD_UDE_cur is
    select *
    from   i$SDD_UDE the_tab
    where  the_tab.irid=SDD_UDE_ver.irid
    and    the_tab.ivid=SDD_UDE_ver.ivid;
  SDD_UDE_rec SDD_UDE_cur%ROWTYPE;
  cursor SDD_UDECLI_cur1 is
    select *
    from i$SDD_UDECLI the_tab
    where the_tab.parent_ivid=SDD_UDE_ver.ivid;
  cursor SDD_UDESUP_cur2 is
    select *
    from i$SDD_UDESUP the_tab
    where the_tab.parent_ivid=SDD_UDE_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_UDE_cur;
  fetch SDD_UDE_cur into SDD_UDE_rec;
  close SDD_UDE_cur;
  insert into i$SDD_UDE
  values (
    SDD_UDE_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_UDE_rec.TYPES
   ,SDD_UDE_rec.ELEMENT_TYPE_NAME
   ,SDD_UDE_rec.DATE_CREATED
   ,SDD_UDE_rec.CREATED_BY
   ,SDD_UDE_rec.DATE_CHANGED
   ,SDD_UDE_rec.CHANGED_BY
   ,SDD_UDE_rec.NOTM
   ,SDD_UDE_rec.NAME
   ,SDD_UDE_rec.TYPE
   ,SDD_UDE_rec.DEPENDENCY_SUBTYPE
  );
  jr_reg_ver.vercopy_dependencies(SDD_UDE_ver.irid, SDD_UDE_ver.ivid, new_ivid, null, copy_dependencies);
  for SDD_UDECLI_rec1 in SDD_UDECLI_cur1 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_UDECLI
    values (
       SDD_UDECLI_rec1.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_UDECLI_rec1.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_UDECLI_rec1.TYPES
     , SDD_UDECLI_rec1.ELEMENT_TYPE_NAME
     , SDD_UDECLI_rec1.DATE_CREATED
     , SDD_UDECLI_rec1.CREATED_BY
     , SDD_UDECLI_rec1.DATE_CHANGED
     , SDD_UDECLI_rec1.CHANGED_BY
     , SDD_UDECLI_rec1.NOTM
     , SDD_UDECLI_rec1.UML_DEPENDENCY_REF
     , SDD_UDECLI_rec1.CLIENT_ELEMENT_REF
     , SDD_UDECLI_rec1.CLIENT_ELEMENT_TYPE
    );
  jr_reg_ver.vercopy_dependencies(SDD_UDECLI_rec1.irid, SDD_UDECLI_rec1.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_UDESUP_rec2 in SDD_UDESUP_cur2 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_UDESUP
    values (
       SDD_UDESUP_rec2.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_UDESUP_rec2.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_UDESUP_rec2.TYPES
     , SDD_UDESUP_rec2.ELEMENT_TYPE_NAME
     , SDD_UDESUP_rec2.DATE_CREATED
     , SDD_UDESUP_rec2.CREATED_BY
     , SDD_UDESUP_rec2.DATE_CHANGED
     , SDD_UDESUP_rec2.CHANGED_BY
     , SDD_UDESUP_rec2.NOTM
     , SDD_UDESUP_rec2.UML_DEPENDENCY_REF
     , SDD_UDESUP_rec2.SUPPLIER_ELEMENT_REF
     , SDD_UDESUP_rec2.SUPPLIER_ELEMENT_TYPE
    );
  jr_reg_ver.vercopy_dependencies(SDD_UDESUP_rec2.irid, SDD_UDESUP_rec2.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  jr_reg_ver.vercopy_dependent_objects(SDD_UDE_ver.ivid, new_ivid);
  return new_ivid;
end SDD_UDE_ver;
/
create or replace function PK_SDD_UDE (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_UDE the_tab_new, SDD_UDE the_tab_old
  where  the_tab_new.ivid = PK_SDD_UDE.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_UDE.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_UDE;
/
create or replace function PK_SDD_UDECLI (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_UDECLI the_tab_new, SDD_UDECLI the_tab_old
  where  the_tab_new.ivid = PK_SDD_UDECLI.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_UDECLI.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_UDECLI;
/
create or replace function PK_SDD_UDESUP (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_UDESUP the_tab_new, SDD_UDESUP the_tab_old
  where  the_tab_new.ivid = PK_SDD_UDESUP.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_UDESUP.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_UDESUP;
/
create or replace function SDD_UDS_ver (irid number, ivid number, copy_dependencies boolean default true) return number as
  new_ivid           number; -- new ivid of primary object
  new_secondary_ivid number; -- new ivid of secondary objects
  cursor SDD_UDS_cur is
    select *
    from   i$SDD_UDS the_tab
    where  the_tab.irid=SDD_UDS_ver.irid
    and    the_tab.ivid=SDD_UDS_ver.ivid;
  SDD_UDS_rec SDD_UDS_cur%ROWTYPE;
  cursor SDD_SMI_cur1 is
    select *
    from i$SDD_SMI the_tab
    where the_tab.parent_ivid=SDD_UDS_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_UDS_cur;
  fetch SDD_UDS_cur into SDD_UDS_rec;
  close SDD_UDS_cur;
  insert into i$SDD_UDS
  values (
    SDD_UDS_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_UDS_rec.TYPES
   ,SDD_UDS_rec.ELEMENT_TYPE_NAME
   ,SDD_UDS_rec.DATE_CREATED
   ,SDD_UDS_rec.CREATED_BY
   ,SDD_UDS_rec.DATE_CHANGED
   ,SDD_UDS_rec.CHANGED_BY
   ,SDD_UDS_rec.NOTM
   ,SDD_UDS_rec.NAME
   ,SDD_UDS_rec.USRX0
   ,SDD_UDS_rec.USRX1
   ,SDD_UDS_rec.USRX2
   ,SDD_UDS_rec.USRX3
   ,SDD_UDS_rec.USRX4
   ,SDD_UDS_rec.USRX5
   ,SDD_UDS_rec.USRX6
   ,SDD_UDS_rec.USRX7
   ,SDD_UDS_rec.USRX8
   ,SDD_UDS_rec.USRX9
   ,SDD_UDS_rec.USRX10
   ,SDD_UDS_rec.USRX11
   ,SDD_UDS_rec.USRX12
   ,SDD_UDS_rec.USRX13
   ,SDD_UDS_rec.USRX14
   ,SDD_UDS_rec.USRX15
   ,SDD_UDS_rec.USRX16
   ,SDD_UDS_rec.USRX17
   ,SDD_UDS_rec.USRX18
   ,SDD_UDS_rec.USRX19
  );
  jr_reg_ver.vercopy_dependencies(SDD_UDS_ver.irid, SDD_UDS_ver.ivid, new_ivid, null, copy_dependencies);
  for SDD_SMI_rec1 in SDD_SMI_cur1 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_SMI
    values (
       SDD_SMI_rec1.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_SMI_rec1.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_SMI_rec1.TYPES
     , SDD_SMI_rec1.ELEMENT_TYPE_NAME
     , SDD_SMI_rec1.DATE_CREATED
     , SDD_SMI_rec1.CREATED_BY
     , SDD_SMI_rec1.DATE_CHANGED
     , SDD_SMI_rec1.CHANGED_BY
     , SDD_SMI_rec1.NOTM
     , SDD_SMI_rec1.USER_DEFINED_SET_REF
     , SDD_SMI_rec1.ELEMENT_REF
     , SDD_SMI_rec1.OLD_UID_NAME
     , SDD_SMI_rec1.ELEMENT_TYPE_FOR
     , SDD_SMI_rec1.USRX0
     , SDD_SMI_rec1.USRX1
     , SDD_SMI_rec1.USRX2
     , SDD_SMI_rec1.USRX3
     , SDD_SMI_rec1.USRX4
     , SDD_SMI_rec1.USRX5
     , SDD_SMI_rec1.USRX6
     , SDD_SMI_rec1.USRX7
     , SDD_SMI_rec1.USRX8
     , SDD_SMI_rec1.USRX9
     , SDD_SMI_rec1.USRX10
     , SDD_SMI_rec1.USRX11
     , SDD_SMI_rec1.USRX12
     , SDD_SMI_rec1.USRX13
     , SDD_SMI_rec1.USRX14
     , SDD_SMI_rec1.USRX15
     , SDD_SMI_rec1.USRX16
     , SDD_SMI_rec1.USRX17
     , SDD_SMI_rec1.USRX18
     , SDD_SMI_rec1.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_SMI_rec1.irid, SDD_SMI_rec1.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  jr_reg_ver.vercopy_dependent_objects(SDD_UDS_ver.ivid, new_ivid);
  return new_ivid;
end SDD_UDS_ver;
/
create or replace function PK_SDD_UDS (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_UDS the_tab_new, SDD_UDS the_tab_old
  where  the_tab_new.ivid = PK_SDD_UDS.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_UDS.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_UDS;
/
create or replace function SDD_UEE_ver (irid number, ivid number, copy_dependencies boolean default true) return number as
  new_ivid           number; -- new ivid of primary object
  new_secondary_ivid number; -- new ivid of secondary objects
  cursor SDD_UEE_cur is
    select *
    from   i$SDD_UEE the_tab
    where  the_tab.irid=SDD_UEE_ver.irid
    and    the_tab.ivid=SDD_UEE_ver.ivid;
  SDD_UEE_rec SDD_UEE_cur%ROWTYPE;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_UEE_cur;
  fetch SDD_UEE_cur into SDD_UEE_rec;
  close SDD_UEE_cur;
  insert into i$SDD_UEE
  values (
    SDD_UEE_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_UEE_rec.TYPES
   ,SDD_UEE_rec.ELEMENT_TYPE_NAME
   ,SDD_UEE_rec.DATE_CREATED
   ,SDD_UEE_rec.CREATED_BY
   ,SDD_UEE_rec.DATE_CHANGED
   ,SDD_UEE_rec.CHANGED_BY
   ,SDD_UEE_rec.NOTM
   ,SDD_UEE_rec.NAME
   ,SDD_UEE_rec.COMMENTS
   ,SDD_UEE_rec.USRX0
   ,SDD_UEE_rec.USRX1
   ,SDD_UEE_rec.USRX2
   ,SDD_UEE_rec.USRX3
   ,SDD_UEE_rec.USRX4
   ,SDD_UEE_rec.USRX5
   ,SDD_UEE_rec.USRX6
   ,SDD_UEE_rec.USRX7
   ,SDD_UEE_rec.USRX8
   ,SDD_UEE_rec.USRX9
   ,SDD_UEE_rec.USRX10
   ,SDD_UEE_rec.USRX11
   ,SDD_UEE_rec.USRX12
   ,SDD_UEE_rec.USRX13
   ,SDD_UEE_rec.USRX14
   ,SDD_UEE_rec.USRX15
   ,SDD_UEE_rec.USRX16
   ,SDD_UEE_rec.USRX17
   ,SDD_UEE_rec.USRX18
   ,SDD_UEE_rec.USRX19
  );
  jr_reg_ver.vercopy_dependencies(SDD_UEE_ver.irid, SDD_UEE_ver.ivid, new_ivid, null, copy_dependencies);
  jr_reg_ver.vercopy_dependent_objects(SDD_UEE_ver.ivid, new_ivid);
  return new_ivid;
end SDD_UEE_ver;
/
create or replace function PK_SDD_UEE (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_UEE the_tab_new, SDD_UEE the_tab_old
  where  the_tab_new.ivid = PK_SDD_UEE.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_UEE.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_UEE;
/
create or replace function PK_SDD_UES (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_UES the_tab_new, SDD_UES the_tab_old
  where  the_tab_new.ivid = PK_SDD_UES.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_UES.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_UES;
/
create or replace function UK_UES (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_UES the_tab_new, SDD_UES the_tab_old
  where  the_tab_new.ivid = UK_UES.ivid
  and    the_tab_new.PART_OF_REF = the_tab_old.PART_OF_REF
  and    the_tab_new.USE_OF_REF = the_tab_old.USE_OF_REF
  and    the_tab_new.ELEMENT_TYPE_NAME = the_tab_old.ELEMENT_TYPE_NAME
  and    the_tab_old.ivid != UK_UES.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end UK_UES;
/
create or replace function PK_SDD_UID (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_UID the_tab_new, SDD_UID the_tab_old
  where  the_tab_new.ivid = PK_SDD_UID.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_UID.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_UID;
/
create or replace function PK_SDD_UPR (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_UPR the_tab_new, SDD_UPR the_tab_old
  where  the_tab_new.ivid = PK_SDD_UPR.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_UPR.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_UPR;
/
create or replace function UK_UPR (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_UPR the_tab_new, SDD_UPR the_tab_old
  where  the_tab_new.ivid = UK_UPR.ivid
  and    the_tab_new.CIELEMENT_REF = the_tab_old.CIELEMENT_REF
  and    the_tab_new.PRODUCT_FLAVOR = the_tab_old.PRODUCT_FLAVOR
  and    the_tab_new.PREFERENCE_NAME = the_tab_old.PREFERENCE_NAME
  and    the_tab_old.ivid != UK_UPR.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end UK_UPR;
/
create or replace function SDD_URU_ver (irid number, ivid number, copy_dependencies boolean default true) return number as
  new_ivid           number; -- new ivid of primary object
  new_secondary_ivid number; -- new ivid of secondary objects
  cursor SDD_URU_cur is
    select *
    from   i$SDD_URU the_tab
    where  the_tab.irid=SDD_URU_ver.irid
    and    the_tab.ivid=SDD_URU_ver.ivid;
  SDD_URU_rec SDD_URU_cur%ROWTYPE;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_URU_cur;
  fetch SDD_URU_cur into SDD_URU_rec;
  close SDD_URU_cur;
  insert into i$SDD_URU
  values (
    SDD_URU_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_URU_rec.TYPES
   ,SDD_URU_rec.ELEMENT_TYPE_NAME
   ,SDD_URU_rec.DATE_CREATED
   ,SDD_URU_rec.CREATED_BY
   ,SDD_URU_rec.DATE_CHANGED
   ,SDD_URU_rec.CHANGED_BY
   ,SDD_URU_rec.NOTM
   ,SDD_URU_rec.NAME
  );
  jr_reg_ver.vercopy_dependencies(SDD_URU_ver.irid, SDD_URU_ver.ivid, new_ivid, null, copy_dependencies);
  jr_reg_ver.vercopy_dependent_objects(SDD_URU_ver.ivid, new_ivid);
  return new_ivid;
end SDD_URU_ver;
/
create or replace function PK_SDD_URU (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_URU the_tab_new, SDD_URU the_tab_old
  where  the_tab_new.ivid = PK_SDD_URU.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_URU.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_URU;
/
create or replace function FK_UCA_TO_USC2_d (
el_ivid number
 ,IRID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, child_tab.types
  from   SDD_UCA child_tab
  where  child_tab.USE_CASE_INVOKED_REF=FK_UCA_TO_USC2_d.IRID
  ;
 is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
    insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid)
    select o.irid, o.ivid, o.table_irid
    from   SDD_UCA child_tab, i$sdd_object_versions o
    where  child_tab.USE_CASE_INVOKED_REF=FK_UCA_TO_USC2_d.IRID
    and    child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(el_ivid,el_type,ref.irid,ref.types,action);
  end loop;
  return is_ok;
end FK_UCA_TO_USC2_d;
/
create or replace function FK_USCUSC_TO_USC2_d (
el_ivid number
 ,IRID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, child_tab.types
  from   SDD_USCUSC child_tab
  where  child_tab.SUPERTYPE_REF=FK_USCUSC_TO_USC2_d.IRID
  ;
 is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
    insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid)
    select o.irid, o.ivid, o.table_irid
    from   SDD_USCUSC child_tab, i$sdd_object_versions o
    where  child_tab.SUPERTYPE_REF=FK_USCUSC_TO_USC2_d.IRID
    and    child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(el_ivid,el_type,ref.irid,ref.types,action);
  end loop;
  return is_ok;
end FK_USCUSC_TO_USC2_d;
/
create or replace function SDD_USC_ver (irid number, ivid number, copy_dependencies boolean default true) return number as
  new_ivid           number; -- new ivid of primary object
  new_secondary_ivid number; -- new ivid of secondary objects
  cursor SDD_USC_cur is
    select *
    from   i$SDD_USC the_tab
    where  the_tab.irid=SDD_USC_ver.irid
    and    the_tab.ivid=SDD_USC_ver.ivid;
  SDD_USC_rec SDD_USC_cur%ROWTYPE;
  cursor SDD_UCA_cur1 is
    select *
    from i$SDD_UCA the_tab
    where the_tab.parent_ivid=SDD_USC_ver.ivid;
  cursor SDD_USCACR_cur2 is
    select *
    from i$SDD_USCACR the_tab
    where the_tab.parent_ivid=SDD_USC_ver.ivid;
  cursor SDD_USCE1_cur3 is
    select *
    from i$SDD_USCE1 the_tab
    where the_tab.parent_ivid=SDD_USC_ver.ivid;
  cursor SDD_USCEPA_cur4 is
    select *
    from i$SDD_USCEPA the_tab
    where the_tab.parent_ivid=SDD_USC_ver.ivid;
  cursor SDD_USCEVI_cur5 is
    select *
    from i$SDD_USCEVI the_tab
    where the_tab.parent_ivid=SDD_USC_ver.ivid;
  cursor SDD_USCEVO_cur6 is
    select *
    from i$SDD_USCEVO the_tab
    where the_tab.parent_ivid=SDD_USC_ver.ivid;
  cursor SDD_USCUSC_cur7 is
    select *
    from i$SDD_USCUSC the_tab
    where the_tab.parent_ivid=SDD_USC_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_USC_cur;
  fetch SDD_USC_cur into SDD_USC_rec;
  close SDD_USC_cur;
  insert into i$SDD_USC
  values (
    SDD_USC_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_USC_rec.TYPES
   ,SDD_USC_rec.ELEMENT_TYPE_NAME
   ,SDD_USC_rec.DATE_CREATED
   ,SDD_USC_rec.CREATED_BY
   ,SDD_USC_rec.DATE_CHANGED
   ,SDD_USC_rec.CHANGED_BY
   ,SDD_USC_rec.NOTM
   ,SDD_USC_rec.NAME
   ,SDD_USC_rec.PRE_RULE_REF
   ,SDD_USC_rec.POST_RULE_REF
   ,SDD_USC_rec.ICON_FILE_REF
  );
  jr_reg_ver.vercopy_dependencies(SDD_USC_ver.irid, SDD_USC_ver.ivid, new_ivid, null, copy_dependencies);
  for SDD_UCA_rec1 in SDD_UCA_cur1 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_UCA
    values (
       SDD_UCA_rec1.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_UCA_rec1.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_UCA_rec1.TYPES
     , SDD_UCA_rec1.ELEMENT_TYPE_NAME
     , SDD_UCA_rec1.DATE_CREATED
     , SDD_UCA_rec1.CREATED_BY
     , SDD_UCA_rec1.DATE_CHANGED
     , SDD_UCA_rec1.CHANGED_BY
     , SDD_UCA_rec1.NOTM
     , SDD_UCA_rec1.USE_CASE_REF
     , SDD_UCA_rec1.GENERAL_ACTION_REF
     , SDD_UCA_rec1.SEQUENCE_IN_PARENT
     , SDD_UCA_rec1.NAME
     , SDD_UCA_rec1.USE_CASE_EVENT_OUT_REF
     , SDD_UCA_rec1.TYPE
     , SDD_UCA_rec1.USE_CASE_INVOKED_REF
     , SDD_UCA_rec1.USE_CASE_ACTION_SUBTYPE
    );
  jr_reg_ver.vercopy_dependencies(SDD_UCA_rec1.irid, SDD_UCA_rec1.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_USCACR_rec2 in SDD_USCACR_cur2 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_USCACR
    values (
       SDD_USCACR_rec2.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_USCACR_rec2.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_USCACR_rec2.TYPES
     , SDD_USCACR_rec2.ELEMENT_TYPE_NAME
     , SDD_USCACR_rec2.DATE_CREATED
     , SDD_USCACR_rec2.CREATED_BY
     , SDD_USCACR_rec2.DATE_CHANGED
     , SDD_USCACR_rec2.CHANGED_BY
     , SDD_USCACR_rec2.NOTM
     , SDD_USCACR_rec2.USE_CASE_REF
     , SDD_USCACR_rec2.ACTOR_REF
     , SDD_USCACR_rec2.PRIMARY_FLAG
    );
  jr_reg_ver.vercopy_dependencies(SDD_USCACR_rec2.irid, SDD_USCACR_rec2.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_USCE1_rec3 in SDD_USCE1_cur3 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_USCE1
    values (
       SDD_USCE1_rec3.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_USCE1_rec3.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_USCE1_rec3.TYPES
     , SDD_USCE1_rec3.ELEMENT_TYPE_NAME
     , SDD_USCE1_rec3.DATE_CREATED
     , SDD_USCE1_rec3.CREATED_BY
     , SDD_USCE1_rec3.DATE_CHANGED
     , SDD_USCE1_rec3.CHANGED_BY
     , SDD_USCE1_rec3.NOTM
     , SDD_USCE1_rec3.USE_CASE_REF
     , SDD_USCE1_rec3.OBJECTIVE_REF
    );
  jr_reg_ver.vercopy_dependencies(SDD_USCE1_rec3.irid, SDD_USCE1_rec3.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_USCEPA_rec4 in SDD_USCEPA_cur4 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_USCEPA
    values (
       SDD_USCEPA_rec4.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_USCEPA_rec4.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_USCEPA_rec4.TYPES
     , SDD_USCEPA_rec4.ELEMENT_TYPE_NAME
     , SDD_USCEPA_rec4.DATE_CREATED
     , SDD_USCEPA_rec4.CREATED_BY
     , SDD_USCEPA_rec4.DATE_CHANGED
     , SDD_USCEPA_rec4.CHANGED_BY
     , SDD_USCEPA_rec4.NOTM
     , SDD_USCEPA_rec4.EXTENSION_POINT_REF
     , SDD_USCEPA_rec4.USE_CASE_REF
     , SDD_USCEPA_rec4.USE_CASE_FROM_REF
     , SDD_USCEPA_rec4.MINIMUM_MULTIPLICITY
     , SDD_USCEPA_rec4.MAXIMUM_MULTIPLICITY
     , SDD_USCEPA_rec4.NAMED_RULE_REF
     , SDD_USCEPA_rec4.SEQUENCE
    );
  jr_reg_ver.vercopy_dependencies(SDD_USCEPA_rec4.irid, SDD_USCEPA_rec4.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_USCEVI_rec5 in SDD_USCEVI_cur5 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_USCEVI
    values (
       SDD_USCEVI_rec5.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_USCEVI_rec5.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_USCEVI_rec5.TYPES
     , SDD_USCEVI_rec5.ELEMENT_TYPE_NAME
     , SDD_USCEVI_rec5.DATE_CREATED
     , SDD_USCEVI_rec5.CREATED_BY
     , SDD_USCEVI_rec5.DATE_CHANGED
     , SDD_USCEVI_rec5.CHANGED_BY
     , SDD_USCEVI_rec5.NOTM
     , SDD_USCEVI_rec5.USE_CASE_REF
     , SDD_USCEVI_rec5.EVENT_CLASSIFIER_REF
    );
  jr_reg_ver.vercopy_dependencies(SDD_USCEVI_rec5.irid, SDD_USCEVI_rec5.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_USCEVO_rec6 in SDD_USCEVO_cur6 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_USCEVO
    values (
       SDD_USCEVO_rec6.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_USCEVO_rec6.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_USCEVO_rec6.TYPES
     , SDD_USCEVO_rec6.ELEMENT_TYPE_NAME
     , SDD_USCEVO_rec6.DATE_CREATED
     , SDD_USCEVO_rec6.CREATED_BY
     , SDD_USCEVO_rec6.DATE_CHANGED
     , SDD_USCEVO_rec6.CHANGED_BY
     , SDD_USCEVO_rec6.NOTM
     , SDD_USCEVO_rec6.USE_CASE_REF
     , SDD_USCEVO_rec6.EVENT_CLASSIFIER_REF
    );
  jr_reg_ver.vercopy_dependencies(SDD_USCEVO_rec6.irid, SDD_USCEVO_rec6.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_USCUSC_rec7 in SDD_USCUSC_cur7 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_USCUSC
    values (
       SDD_USCUSC_rec7.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_USCUSC_rec7.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_USCUSC_rec7.TYPES
     , SDD_USCUSC_rec7.ELEMENT_TYPE_NAME
     , SDD_USCUSC_rec7.DATE_CREATED
     , SDD_USCUSC_rec7.CREATED_BY
     , SDD_USCUSC_rec7.DATE_CHANGED
     , SDD_USCUSC_rec7.CHANGED_BY
     , SDD_USCUSC_rec7.NOTM
     , SDD_USCUSC_rec7.SUBTYPE_REF
     , SDD_USCUSC_rec7.SUPERTYPE_REF
     , SDD_USCUSC_rec7.SEQUENCE
    );
  jr_reg_ver.vercopy_dependencies(SDD_USCUSC_rec7.irid, SDD_USCUSC_rec7.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  jr_reg_ver.vercopy_dependent_objects(SDD_USC_ver.ivid, new_ivid);
  return new_ivid;
end SDD_USC_ver;
/
create or replace function PK_SDD_USC (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_USC the_tab_new, SDD_USC the_tab_old
  where  the_tab_new.ivid = PK_SDD_USC.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_USC.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_USC;
/
create or replace function FK_USC_TO_FILES (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ICON_FILE_REF ref_value
  from   i$SDD_USC the_tab
  where  the_tab.ivid = FK_USC_TO_FILES.object_ivid
  and    the_tab.ICON_FILE_REF is not null
  and    not exists (
             select null
             from   SDD_FILES foreign_tab
             where  the_tab.ICON_FILE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4819, action);
  end loop;
  return is_ok;
end FK_USC_TO_FILES;
/
create or replace function FK_USC_TO_RUL (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.PRE_RULE_REF ref_value
  from   i$SDD_USC the_tab
  where  the_tab.ivid = FK_USC_TO_RUL.object_ivid
  and    the_tab.PRE_RULE_REF is not null
  and    not exists (
             select null
             from   SDD_RUL foreign_tab
             where  the_tab.PRE_RULE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4833, action);
  end loop;
  return is_ok;
end FK_USC_TO_RUL;
/
create or replace function FK_USC_TO_RUL2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.POST_RULE_REF ref_value
  from   i$SDD_USC the_tab
  where  the_tab.ivid = FK_USC_TO_RUL2.object_ivid
  and    the_tab.POST_RULE_REF is not null
  and    not exists (
             select null
             from   SDD_RUL foreign_tab
             where  the_tab.POST_RULE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4833, action);
  end loop;
  return is_ok;
end FK_USC_TO_RUL2;
/
create or replace function PK_SDD_USCACR (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_USCACR the_tab_new, SDD_USCACR the_tab_old
  where  the_tab_new.ivid = PK_SDD_USCACR.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_USCACR.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_USCACR;
/
create or replace function FK_USCACR_TO_ACR (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ACTOR_REF ref_value
  from   i$SDD_USCACR the_tab
  where  the_tab.ivid = FK_USCACR_TO_ACR.object_ivid
  and    the_tab.ACTOR_REF is not null
  and    not exists (
             select null
             from   SDD_ACR foreign_tab
             where  the_tab.ACTOR_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4840, action);
  end loop;
  return is_ok;
end FK_USCACR_TO_ACR;
/
create or replace function PK_SDD_USCE1 (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_USCE1 the_tab_new, SDD_USCE1 the_tab_old
  where  the_tab_new.ivid = PK_SDD_USCE1.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_USCE1.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_USCE1;
/
create or replace function FK_USCE1_TO_E1 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.OBJECTIVE_REF ref_value
  from   i$SDD_USCE1 the_tab
  where  the_tab.ivid = FK_USCE1_TO_E1.object_ivid
  and    the_tab.OBJECTIVE_REF is not null
  and    not exists (
             select null
             from   SDD_E1 foreign_tab
             where  the_tab.OBJECTIVE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4967, action);
  end loop;
  return is_ok;
end FK_USCE1_TO_E1;
/
create or replace function PK_SDD_USCEPA (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_USCEPA the_tab_new, SDD_USCEPA the_tab_old
  where  the_tab_new.ivid = PK_SDD_USCEPA.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_USCEPA.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_USCEPA;
/
create or replace function FK_USCEPA_TO_EPA (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.EXTENSION_POINT_REF ref_value
  from   i$SDD_USCEPA the_tab
  where  the_tab.ivid = FK_USCEPA_TO_EPA.object_ivid
  and    the_tab.EXTENSION_POINT_REF is not null
  and    not exists (
             select null
             from   SDD_UCA foreign_tab
             where  the_tab.EXTENSION_POINT_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5111, action);
  end loop;
  return is_ok;
end FK_USCEPA_TO_EPA;
/
create or replace function FK_USCEPA_TO_RUL (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.NAMED_RULE_REF ref_value
  from   i$SDD_USCEPA the_tab
  where  the_tab.ivid = FK_USCEPA_TO_RUL.object_ivid
  and    the_tab.NAMED_RULE_REF is not null
  and    not exists (
             select null
             from   SDD_RUL foreign_tab
             where  the_tab.NAMED_RULE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4833, action);
  end loop;
  return is_ok;
end FK_USCEPA_TO_RUL;
/
create or replace function FK_USCEPA_TO_USC2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.USE_CASE_FROM_REF ref_value
  from   i$SDD_USCEPA the_tab
  where  the_tab.ivid = FK_USCEPA_TO_USC2.object_ivid
  and    the_tab.USE_CASE_FROM_REF is not null
  and    not exists (
             select null
             from   SDD_USC foreign_tab
             where  the_tab.USE_CASE_FROM_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5104, action);
  end loop;
  return is_ok;
end FK_USCEPA_TO_USC2;
/
create or replace function PK_SDD_USCEVI (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_USCEVI the_tab_new, SDD_USCEVI the_tab_old
  where  the_tab_new.ivid = PK_SDD_USCEVI.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_USCEVI.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_USCEVI;
/
create or replace function FK_USCEVI_TO_EVC (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.EVENT_CLASSIFIER_REF ref_value
  from   i$SDD_USCEVI the_tab
  where  the_tab.ivid = FK_USCEVI_TO_EVC.object_ivid
  and    the_tab.EVENT_CLASSIFIER_REF is not null
  and    not exists (
             select null
             from   SDD_CLA foreign_tab
             where  the_tab.EVENT_CLASSIFIER_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4841, action);
  end loop;
  return is_ok;
end FK_USCEVI_TO_EVC;
/
create or replace function PK_SDD_USCEVO (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_USCEVO the_tab_new, SDD_USCEVO the_tab_old
  where  the_tab_new.ivid = PK_SDD_USCEVO.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_USCEVO.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_USCEVO;
/
create or replace function FK_USCEVO_TO_EVC (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.EVENT_CLASSIFIER_REF ref_value
  from   i$SDD_USCEVO the_tab
  where  the_tab.ivid = FK_USCEVO_TO_EVC.object_ivid
  and    the_tab.EVENT_CLASSIFIER_REF is not null
  and    not exists (
             select null
             from   SDD_CLA foreign_tab
             where  the_tab.EVENT_CLASSIFIER_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4841, action);
  end loop;
  return is_ok;
end FK_USCEVO_TO_EVC;
/
create or replace function PK_SDD_USCUSC (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_USCUSC the_tab_new, SDD_USCUSC the_tab_old
  where  the_tab_new.ivid = PK_SDD_USCUSC.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_USCUSC.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_USCUSC;
/
create or replace function UK_USCUSC_2 (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_USCUSC the_tab_new, SDD_USCUSC the_tab_old
  where  the_tab_new.ivid = UK_USCUSC_2.ivid
  and    the_tab_new.SUPERTYPE_REF = the_tab_old.SUPERTYPE_REF
  and    the_tab_new.SEQUENCE = the_tab_old.SEQUENCE
  and    the_tab_old.ivid != UK_USCUSC_2.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end UK_USCUSC_2;
/
create or replace function FK_USCUSC_TO_USC2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.SUPERTYPE_REF ref_value
  from   i$SDD_USCUSC the_tab
  where  the_tab.ivid = FK_USCUSC_TO_USC2.object_ivid
  and    the_tab.SUPERTYPE_REF is not null
  and    not exists (
             select null
             from   SDD_USC foreign_tab
             where  the_tab.SUPERTYPE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5104, action);
  end loop;
  return is_ok;
end FK_USCUSC_TO_USC2;
/
create or replace function PK_SDD_VAL (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_VAL the_tab_new, SDD_VAL the_tab_old
  where  the_tab_new.ivid = PK_SDD_VAL.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_VAL.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_VAL;
/
create or replace function FK_VAL_TO_GEC (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.GENERIC_CLASS_REF ref_value
  from   i$SDD_VAL the_tab
  where  the_tab.ivid = FK_VAL_TO_GEC.object_ivid
  and    the_tab.GENERIC_CLASS_REF is not null
  and    not exists (
             select null
             from   SDD_CLA foreign_tab
             where  the_tab.GENERIC_CLASS_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4841, action);
  end loop;
  return is_ok;
end FK_VAL_TO_GEC;
/
create or replace function PK_SDD_VALGAT (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_VALGAT the_tab_new, SDD_VALGAT the_tab_old
  where  the_tab_new.ivid = PK_SDD_VALGAT.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_VALGAT.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_VALGAT;
/
create or replace function FK_VALGAT_TO_GAT (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.GENERAL_ATTRIBUTE_REF ref_value
  from   i$SDD_VALGAT the_tab
  where  the_tab.ivid = FK_VALGAT_TO_GAT.object_ivid
  and    the_tab.GENERAL_ATTRIBUTE_REF is not null
  and    not exists (
             select null
             from   SDD_CAT foreign_tab
             where  the_tab.GENERAL_ATTRIBUTE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5066, action);
  end loop;
  return is_ok;
end FK_VALGAT_TO_GAT;
/
create or replace function FK_VLEU_TO_VLE_cmd (irid number, ivid number) return boolean as
cursor bad_cur is
  select child_tab.irid child_irid, child_tab.types child_type
        ,parent_tab.ivid par_ivid, parent_tab.types par_type
  from   SDD_VLEU child_tab, i$SDD_VLE parent_tab
  where  parent_tab.parent_ivid=FK_VLEU_TO_VLE_cmd.ivid
  and    child_tab.VIEW_LINK_END_REF=parent_tab.IRID
  ;
  is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
   insert into I$SDD_INVALID_OBJECTS(object_irid,object_ivid,table_irid)
    select o.irid,o.ivid,o.table_irid
      from SDD_VLEU child_tab
          ,i$SDD_VLE parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_VLEU_TO_VLE_cmd.ivid
       and child_tab.VIEW_LINK_END_REF=parent_tab.IRID
       and child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(ref.par_ivid,ref.par_type,ref.child_irid,ref.child_type,'DEL');
  end loop;
  return is_ok;
end FK_VLEU_TO_VLE_cmd;
/
create or replace function FK_VLEU_TO_VLE_d (
el_ivid number
 ,IRID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, child_tab.types
  from   SDD_VLEU child_tab
  where  child_tab.VIEW_LINK_END_REF=FK_VLEU_TO_VLE_d.IRID
  ;
 is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
    insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid)
    select o.irid, o.ivid, o.table_irid
    from   SDD_VLEU child_tab, i$sdd_object_versions o
    where  child_tab.VIEW_LINK_END_REF=FK_VLEU_TO_VLE_d.IRID
    and    child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(el_ivid,el_type,ref.irid,ref.types,action);
  end loop;
  return is_ok;
end FK_VLEU_TO_VLE_d;
/
create or replace function PK_SDD_VLE (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_VLE the_tab_new, SDD_VLE the_tab_old
  where  the_tab_new.ivid = PK_SDD_VLE.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_VLE.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_VLE;
/
create or replace function FK_VLE_TO_AEU (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ASSOC_END_USAGE_REF ref_value
  from   i$SDD_VLE the_tab
  where  the_tab.ivid = FK_VLE_TO_AEU.object_ivid
  and    the_tab.ASSOC_END_USAGE_REF is not null
  and    not exists (
             select null
             from   SDD_AEU foreign_tab
             where  the_tab.ASSOC_END_USAGE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5122, action);
  end loop;
  return is_ok;
end FK_VLE_TO_AEU;
/
create or replace function FK_VLE_TO_VOB (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.VIEW_OBJECT_REF ref_value
  from   i$SDD_VLE the_tab
  where  the_tab.ivid = FK_VLE_TO_VOB.object_ivid
  and    the_tab.VIEW_OBJECT_REF is not null
  and    not exists (
             select null
             from   SDD_CLA foreign_tab
             where  the_tab.VIEW_OBJECT_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4841, action);
  end loop;
  return is_ok;
end FK_VLE_TO_VOB;
/
create or replace function PK_SDD_VLEU (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_VLEU the_tab_new, SDD_VLEU the_tab_old
  where  the_tab_new.ivid = PK_SDD_VLEU.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_VLEU.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_VLEU;
/
create or replace function FK_VLEU_TO_VLE (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.VIEW_LINK_END_REF ref_value
  from   i$SDD_VLEU the_tab
  where  the_tab.ivid = FK_VLEU_TO_VLE.object_ivid
  and    the_tab.VIEW_LINK_END_REF is not null
  and    not exists (
             select null
             from   SDD_VLE foreign_tab
             where  the_tab.VIEW_LINK_END_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5119, action);
  end loop;
  return is_ok;
end FK_VLEU_TO_VLE;
/
create or replace function FK_VLEU_TO_VOU (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.VIEW_USAGE_REF ref_value
  from   i$SDD_VLEU the_tab
  where  the_tab.ivid = FK_VLEU_TO_VOU.object_ivid
  and    the_tab.VIEW_USAGE_REF is not null
  and    not exists (
             select null
             from   SDD_VOU foreign_tab
             where  the_tab.VIEW_USAGE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5126, action);
  end loop;
  return is_ok;
end FK_VLEU_TO_VOU;
/
create or replace function PK_SDD_VLEVOA (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_VLEVOA the_tab_new, SDD_VLEVOA the_tab_old
  where  the_tab_new.ivid = PK_SDD_VLEVOA.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_VLEVOA.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_VLEVOA;
/
create or replace function FK_VLEVOA_TO_VOA (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.VIEW_OBJECT_ATT_REF ref_value
  from   i$SDD_VLEVOA the_tab
  where  the_tab.ivid = FK_VLEVOA_TO_VOA.object_ivid
  and    the_tab.VIEW_OBJECT_ATT_REF is not null
  and    not exists (
             select null
             from   SDD_CAT foreign_tab
             where  the_tab.VIEW_OBJECT_ATT_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5066, action);
  end loop;
  return is_ok;
end FK_VLEVOA_TO_VOA;
/
create or replace function FK_VLU_TO_VLI_d (
el_ivid number
 ,IRID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, child_tab.types
  from   SDD_VLU child_tab
  where  child_tab.VIEW_LINK_REF=FK_VLU_TO_VLI_d.IRID
  ;
 is_ok boolean:=TRUE;
begin
  if jr_context.constraints=jr_context.CONSTRAINTS_DEFERRED then
    insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid)
    select o.irid, o.ivid, o.table_irid
    from   SDD_VLU child_tab, i$sdd_object_versions o
    where  child_tab.VIEW_LINK_REF=FK_VLU_TO_VLI_d.IRID
    and    child_tab.parent_ivid=o.ivid;
   return TRUE;
  end if;
  for ref in bad_cur loop
   is_ok:=FALSE;
   jr_error.post_ref_error(el_ivid,el_type,ref.irid,ref.types,action);
  end loop;
  return is_ok;
end FK_VLU_TO_VLI_d;
/
create or replace function SDD_VLI_ver (irid number, ivid number, copy_dependencies boolean default true) return number as
  new_ivid           number; -- new ivid of primary object
  new_secondary_ivid number; -- new ivid of secondary objects
  cursor SDD_VLI_cur is
    select *
    from   i$SDD_VLI the_tab
    where  the_tab.irid=SDD_VLI_ver.irid
    and    the_tab.ivid=SDD_VLI_ver.ivid;
  SDD_VLI_rec SDD_VLI_cur%ROWTYPE;
  cursor SDD_FILPAC_cur1 is
    select *
    from i$SDD_FILPAC the_tab
    where the_tab.parent_ivid=SDD_VLI_ver.ivid;
  cursor SDD_VLE_cur2 is
    select *
    from i$SDD_VLE the_tab
    where the_tab.parent_ivid=SDD_VLI_ver.ivid;
  cursor SDD_VLEVOA_cur3 is
    select *
    from i$SDD_VLEVOA the_tab
    where the_tab.parent_ivid=SDD_VLI_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_VLI_cur;
  fetch SDD_VLI_cur into SDD_VLI_rec;
  close SDD_VLI_cur;
  insert into i$SDD_VLI
  values (
    SDD_VLI_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_VLI_rec.TYPES
   ,SDD_VLI_rec.ELEMENT_TYPE_NAME
   ,SDD_VLI_rec.DATE_CREATED
   ,SDD_VLI_rec.CREATED_BY
   ,SDD_VLI_rec.DATE_CHANGED
   ,SDD_VLI_rec.CHANGED_BY
   ,SDD_VLI_rec.NOTM
   ,SDD_VLI_rec.NAME
  );
  jr_reg_ver.vercopy_dependencies(SDD_VLI_ver.irid, SDD_VLI_ver.ivid, new_ivid, null, copy_dependencies);
  for SDD_FILPAC_rec1 in SDD_FILPAC_cur1 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_FILPAC
    values (
       SDD_FILPAC_rec1.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_FILPAC_rec1.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_FILPAC_rec1.TYPES
     , SDD_FILPAC_rec1.ELEMENT_TYPE_NAME
     , SDD_FILPAC_rec1.DATE_CREATED
     , SDD_FILPAC_rec1.CREATED_BY
     , SDD_FILPAC_rec1.DATE_CHANGED
     , SDD_FILPAC_rec1.CHANGED_BY
     , SDD_FILPAC_rec1.NOTM
     , SDD_FILPAC_rec1.ASSOCIATION_REF
     , SDD_FILPAC_rec1.CLASSIFIER_REF
     , SDD_FILPAC_rec1.DIAGRAM_REF
     , SDD_FILPAC_rec1.VIEW_LINK_REF
     , SDD_FILPAC_rec1.PRIMARY_ACCESS_FILE_REF
     , SDD_FILPAC_rec1.TYPE
     , SDD_FILPAC_rec1.OUT_OF_SYNC_FLAG
     , SDD_FILPAC_rec1.VERSION
     , SDD_FILPAC_rec1.OS_TIMESTAMP
     , SDD_FILPAC_rec1.FILE_USAGE_FOR
     , SDD_FILPAC_rec1.CRC
    );
  jr_reg_ver.vercopy_dependencies(SDD_FILPAC_rec1.irid, SDD_FILPAC_rec1.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_VLE_rec2 in SDD_VLE_cur2 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_VLE
    values (
       SDD_VLE_rec2.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_VLE_rec2.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_VLE_rec2.TYPES
     , SDD_VLE_rec2.ELEMENT_TYPE_NAME
     , SDD_VLE_rec2.DATE_CREATED
     , SDD_VLE_rec2.CREATED_BY
     , SDD_VLE_rec2.DATE_CHANGED
     , SDD_VLE_rec2.CHANGED_BY
     , SDD_VLE_rec2.NOTM
     , SDD_VLE_rec2.VIEW_LINK_REF
     , SDD_VLE_rec2.NAME
     , SDD_VLE_rec2.VIEW_OBJECT_REF
     , SDD_VLE_rec2.MASTER_DETAIL_INDICATOR
     , SDD_VLE_rec2.NAVIGATION_TARGET_FLAG
     , SDD_VLE_rec2.UPDATE_FLAG
     , SDD_VLE_rec2.ACCESSOR_NAME
     , SDD_VLE_rec2.ASSOC_END_USAGE_REF
    );
  jr_reg_ver.vercopy_dependencies(SDD_VLE_rec2.irid, SDD_VLE_rec2.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_VLEVOA_rec3 in SDD_VLEVOA_cur3 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_VLEVOA
    values (
       SDD_VLEVOA_rec3.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_VLEVOA_rec3.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_VLEVOA_rec3.TYPES
     , SDD_VLEVOA_rec3.ELEMENT_TYPE_NAME
     , SDD_VLEVOA_rec3.DATE_CREATED
     , SDD_VLEVOA_rec3.CREATED_BY
     , SDD_VLEVOA_rec3.DATE_CHANGED
     , SDD_VLEVOA_rec3.CHANGED_BY
     , SDD_VLEVOA_rec3.NOTM
     , SDD_VLEVOA_rec3.VIEW_LINK_END_REF
     , SDD_VLEVOA_rec3.VIEW_OBJECT_ATT_REF
     , SDD_VLEVOA_rec3.SEQUENCE_NUMBER
    );
  jr_reg_ver.vercopy_dependencies(SDD_VLEVOA_rec3.irid, SDD_VLEVOA_rec3.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  jr_reg_ver.vercopy_dependent_objects(SDD_VLI_ver.ivid, new_ivid);
  return new_ivid;
end SDD_VLI_ver;
/
create or replace function PK_SDD_VLI (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_VLI the_tab_new, SDD_VLI the_tab_old
  where  the_tab_new.ivid = PK_SDD_VLI.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_VLI.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_VLI;
/
create or replace function PK_SDD_VLU (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_VLU the_tab_new, SDD_VLU the_tab_old
  where  the_tab_new.ivid = PK_SDD_VLU.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_VLU.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_VLU;
/
create or replace function FK_VLU_TO_VLI (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.VIEW_LINK_REF ref_value
  from   i$SDD_VLU the_tab
  where  the_tab.ivid = FK_VLU_TO_VLI.object_ivid
  and    the_tab.VIEW_LINK_REF is not null
  and    not exists (
             select null
             from   SDD_VLI foreign_tab
             where  the_tab.VIEW_LINK_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5117, action);
  end loop;
  return is_ok;
end FK_VLU_TO_VLI;
/
create or replace function PK_SDD_VOU (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_VOU the_tab_new, SDD_VOU the_tab_old
  where  the_tab_new.ivid = PK_SDD_VOU.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_VOU.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_VOU;
/
create or replace function FK_VOU_TO_VOB (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.VIEW_OBJECT_REF ref_value
  from   i$SDD_VOU the_tab
  where  the_tab.ivid = FK_VOU_TO_VOB.object_ivid
  and    the_tab.VIEW_OBJECT_REF is not null
  and    not exists (
             select null
             from   SDD_CLA foreign_tab
             where  the_tab.VIEW_OBJECT_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4841, action);
  end loop;
  return is_ok;
end FK_VOU_TO_VOB;
/
create or replace function PK_SDD_VWTAB (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_VWTAB the_tab_new, SDD_VWTAB the_tab_old
  where  the_tab_new.ivid = PK_SDD_VWTAB.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_VWTAB.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_VWTAB;
/
create or replace function FK_VWTAB_TO_TAB2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.TABLE_REF ref_value
  from   i$SDD_VWTAB the_tab
  where  the_tab.ivid = FK_VWTAB_TO_TAB2.object_ivid
  and    the_tab.TABLE_REF is not null
  and    not exists (
             select null
             from   SDD_TAB foreign_tab
             where  the_tab.TABLE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4982, action);
  end loop;
  return is_ok;
end FK_VWTAB_TO_TAB2;
/
create or replace function PK_SDD_WAT (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_WAT the_tab_new, SDD_WAT the_tab_old
  where  the_tab_new.ivid = PK_SDD_WAT.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_WAT.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_WAT;
/
create or replace function FK_WAT_TO_ADC (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ATTRIBUTE_DOMAIN_REF ref_value
  from   i$SDD_WAT the_tab
  where  the_tab.ivid = FK_WAT_TO_ADC.object_ivid
  and    the_tab.ATTRIBUTE_DOMAIN_REF is not null
  and    not exists (
             select null
             from   SDD_CLA foreign_tab
             where  the_tab.ATTRIBUTE_DOMAIN_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 4841, action);
  end loop;
  return is_ok;
end FK_WAT_TO_ADC;
/
create or replace function FK_WAT_TO_CAT (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.CLASSIFIER_ATTRIBUTE_REF ref_value
  from   i$SDD_WAT the_tab
  where  the_tab.ivid = FK_WAT_TO_CAT.object_ivid
  and    the_tab.CLASSIFIER_ATTRIBUTE_REF is not null
  and    not exists (
             select null
             from   SDD_CAT foreign_tab
             where  the_tab.CLASSIFIER_ATTRIBUTE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5066, action);
  end loop;
  return is_ok;
end FK_WAT_TO_CAT;
/
create or replace function PK_SDD_WIN (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_WIN the_tab_new, SDD_WIN the_tab_old
  where  the_tab_new.ivid = PK_SDD_WIN.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_WIN.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_WIN;
/
create or replace function FK_WIN_TO_GEM (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.GENERAL_MODULE_REF ref_value
  from   i$SDD_WIN the_tab
  where  the_tab.ivid = FK_WIN_TO_GEM.object_ivid
  and    the_tab.GENERAL_MODULE_REF is not null
  and    not exists (
             select null
             from   SDD_MOD foreign_tab
             where  the_tab.GENERAL_MODULE_REF = foreign_tab.IRID
             );
  is_ok boolean := true;
begin
  for ref_rec in bad_cur loop
    is_ok := false;
    jr_error.post_referencing_error(object_ivid, object_type_irid, ref_rec.ref_value
                                   , 5022, action);
  end loop;
  return is_ok;
end FK_WIN_TO_GEM;
/
create or replace function SDD_WIT_ver (irid number, ivid number, copy_dependencies boolean default true) return number as
  new_ivid           number; -- new ivid of primary object
  new_secondary_ivid number; -- new ivid of secondary objects
  cursor SDD_WIT_cur is
    select *
    from   i$SDD_WIT the_tab
    where  the_tab.irid=SDD_WIT_ver.irid
    and    the_tab.ivid=SDD_WIT_ver.ivid;
  SDD_WIT_rec SDD_WIT_cur%ROWTYPE;
  cursor SDD_OST_cur1 is
    select *
    from i$SDD_OST the_tab
    where the_tab.parent_ivid=SDD_WIT_ver.ivid;
  cursor SDD_OSTOST_cur2 is
    select *
    from i$SDD_OSTOST the_tab
    where the_tab.parent_ivid=SDD_WIT_ver.ivid;
  cursor SDD_SRU_cur3 is
    select *
    from i$SDD_SRU the_tab
    where the_tab.parent_ivid=SDD_WIT_ver.ivid;
  cursor SDD_MEMCOM_cur4 is
    select *
    from i$SDD_MEMCOM the_tab
    where the_tab.parent_ivid=SDD_WIT_ver.ivid;
  cursor SDD_TRA_cur5 is
    select *
    from i$SDD_TRA the_tab
    where the_tab.parent_ivid=SDD_WIT_ver.ivid;
  cursor SDD_WAT_cur6 is
    select *
    from i$SDD_WAT the_tab
    where the_tab.parent_ivid=SDD_WIT_ver.ivid;
  cursor SDD_WMT_cur7 is
    select *
    from i$SDD_WMT the_tab
    where the_tab.parent_ivid=SDD_WIT_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_WIT_cur;
  fetch SDD_WIT_cur into SDD_WIT_rec;
  close SDD_WIT_cur;
  insert into i$SDD_WIT
  values (
    SDD_WIT_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_WIT_rec.TYPES
   ,SDD_WIT_rec.ELEMENT_TYPE_NAME
   ,SDD_WIT_rec.DATE_CREATED
   ,SDD_WIT_rec.CREATED_BY
   ,SDD_WIT_rec.DATE_CHANGED
   ,SDD_WIT_rec.CHANGED_BY
   ,SDD_WIT_rec.NOTM
   ,SDD_WIT_rec.NAME
   ,SDD_WIT_rec.IMPLEMENTATION_NAME
   ,SDD_WIT_rec.SECURITY_LEVEL
  );
  jr_reg_ver.vercopy_dependencies(SDD_WIT_ver.irid, SDD_WIT_ver.ivid, new_ivid, null, copy_dependencies);
  for SDD_OST_rec1 in SDD_OST_cur1 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_OST
    values (
       SDD_OST_rec1.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_OST_rec1.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_OST_rec1.TYPES
     , SDD_OST_rec1.ELEMENT_TYPE_NAME
     , SDD_OST_rec1.DATE_CREATED
     , SDD_OST_rec1.CREATED_BY
     , SDD_OST_rec1.DATE_CHANGED
     , SDD_OST_rec1.CHANGED_BY
     , SDD_OST_rec1.NOTM
     , SDD_OST_rec1.CLASSIFIER_REF
     , SDD_OST_rec1.BUSINESS_OBJECT_REF
     , SDD_OST_rec1.NAME
     , SDD_OST_rec1.WORKFLOW_ITEM_TYPE_REF
     , SDD_OST_rec1.WORKFLOW_MESS_TYPE_REF
     , SDD_OST_rec1.ICON_FILE_REF
     , SDD_OST_rec1.OBJECT_STATE_FOR
    );
  jr_reg_ver.vercopy_dependencies(SDD_OST_rec1.irid, SDD_OST_rec1.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_OSTOST_rec2 in SDD_OSTOST_cur2 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_OSTOST
    values (
       SDD_OSTOST_rec2.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_OSTOST_rec2.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_OSTOST_rec2.TYPES
     , SDD_OSTOST_rec2.ELEMENT_TYPE_NAME
     , SDD_OSTOST_rec2.DATE_CREATED
     , SDD_OSTOST_rec2.CREATED_BY
     , SDD_OSTOST_rec2.DATE_CHANGED
     , SDD_OSTOST_rec2.CHANGED_BY
     , SDD_OSTOST_rec2.NOTM
     , SDD_OSTOST_rec2.OBJECT_STATE_OF_REF
     , SDD_OSTOST_rec2.OBJECT_STATE_ON_REF
    );
  jr_reg_ver.vercopy_dependencies(SDD_OSTOST_rec2.irid, SDD_OSTOST_rec2.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_SRU_rec3 in SDD_SRU_cur3 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_SRU
    values (
       SDD_SRU_rec3.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_SRU_rec3.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_SRU_rec3.TYPES
     , SDD_SRU_rec3.ELEMENT_TYPE_NAME
     , SDD_SRU_rec3.DATE_CREATED
     , SDD_SRU_rec3.CREATED_BY
     , SDD_SRU_rec3.DATE_CHANGED
     , SDD_SRU_rec3.CHANGED_BY
     , SDD_SRU_rec3.NOTM
     , SDD_SRU_rec3.OBJECT_STATE_REF
     , SDD_SRU_rec3.NAME
     , SDD_SRU_rec3.CONTEXT
     , SDD_SRU_rec3.METHOD_REF
     , SDD_SRU_rec3.LANGUAGE_REF
    );
  jr_reg_ver.vercopy_dependencies(SDD_SRU_rec3.irid, SDD_SRU_rec3.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_MEMCOM_rec4 in SDD_MEMCOM_cur4 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_MEMCOM
    values (
       SDD_MEMCOM_rec4.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_MEMCOM_rec4.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_MEMCOM_rec4.TYPES
     , SDD_MEMCOM_rec4.ELEMENT_TYPE_NAME
     , SDD_MEMCOM_rec4.DATE_CREATED
     , SDD_MEMCOM_rec4.CREATED_BY
     , SDD_MEMCOM_rec4.DATE_CHANGED
     , SDD_MEMCOM_rec4.CHANGED_BY
     , SDD_MEMCOM_rec4.NOTM
     , SDD_MEMCOM_rec4.NAMED_RULE_REF
     , SDD_MEMCOM_rec4.INTEGRITY_RULE_REF
     , SDD_MEMCOM_rec4.CROSS_OBJECT_RULE_REF
     , SDD_MEMCOM_rec4.STATE_RULE_REF
     , SDD_MEMCOM_rec4.ATTRIBUTE_DERIV_RULE_REF
     , SDD_MEMCOM_rec4.CLASSIFIER_ATTRIBUTE_REF
     , SDD_MEMCOM_rec4.ASSOCIATION_END_REF
     , SDD_MEMCOM_rec4.METHOD_REF
     , SDD_MEMCOM_rec4.MEMBER_COMPONENT_OF
     , SDD_MEMCOM_rec4.MEMBER_COMPONENT_IN
    );
  jr_reg_ver.vercopy_dependencies(SDD_MEMCOM_rec4.irid, SDD_MEMCOM_rec4.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_TRA_rec5 in SDD_TRA_cur5 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_TRA
    values (
       SDD_TRA_rec5.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_TRA_rec5.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_TRA_rec5.TYPES
     , SDD_TRA_rec5.ELEMENT_TYPE_NAME
     , SDD_TRA_rec5.DATE_CREATED
     , SDD_TRA_rec5.CREATED_BY
     , SDD_TRA_rec5.DATE_CHANGED
     , SDD_TRA_rec5.CHANGED_BY
     , SDD_TRA_rec5.NOTM
     , SDD_TRA_rec5.SOURCE_ACTIVITY_REF
     , SDD_TRA_rec5.SOURCE_ACT_USAGE_REF
     , SDD_TRA_rec5.SOURCE_EVENT_REF
     , SDD_TRA_rec5.SOURCE_OBJECT_STATE_REF
     , SDD_TRA_rec5.SOURCE_PSEUDOSTATE_REF
     , SDD_TRA_rec5.TARGET_ACTIVITY_REF
     , SDD_TRA_rec5.TARGET_ACT_USAGE_REF
     , SDD_TRA_rec5.TARGET_EVENT_REF
     , SDD_TRA_rec5.TARGET_OBJECT_STATE_REF
     , SDD_TRA_rec5.TARGET_PSEUDOSTATE_REF
     , SDD_TRA_rec5.SEQUENCE_NUMBER
     , SDD_TRA_rec5.NAMED_RULE_REF
     , SDD_TRA_rec5.PRIMARY_FLAG
     , SDD_TRA_rec5.TRANSITION_REF
     , SDD_TRA_rec5.EVENT_PUBLICATION_REF
     , SDD_TRA_rec5.EVENT_SUBSCRIPTION_REF
     , SDD_TRA_rec5.CREATABLE_FLAG
     , SDD_TRA_rec5.MESSAGING_AUDIT
     , SDD_TRA_rec5.CHANNEL_NAME
     , SDD_TRA_rec5.RETRIEVABLE_FLAG
     , SDD_TRA_rec5.CHANNEL_TYPE
     , SDD_TRA_rec5.UPDATABLE_FLAG
     , SDD_TRA_rec5.AUTOMATIC_INVOCATION_FLAG
     , SDD_TRA_rec5.DELETABLE_FLAG
     , SDD_TRA_rec5.TRIGGERING_FLAG
     , SDD_TRA_rec5.ACTIVITY_SIGNATURE_FLAG
     , SDD_TRA_rec5.TRIGGER_EVENT_REF
     , SDD_TRA_rec5.SOURCE_TYPE
     , SDD_TRA_rec5.TARGET_TYPE
    );
  jr_reg_ver.vercopy_dependencies(SDD_TRA_rec5.irid, SDD_TRA_rec5.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_WAT_rec6 in SDD_WAT_cur6 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_WAT
    values (
       SDD_WAT_rec6.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_WAT_rec6.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_WAT_rec6.TYPES
     , SDD_WAT_rec6.ELEMENT_TYPE_NAME
     , SDD_WAT_rec6.DATE_CREATED
     , SDD_WAT_rec6.CREATED_BY
     , SDD_WAT_rec6.DATE_CHANGED
     , SDD_WAT_rec6.CHANGED_BY
     , SDD_WAT_rec6.NOTM
     , SDD_WAT_rec6.WORKFLOW_ITEM_TYPE_REF
     , SDD_WAT_rec6.WORKFLOW_MESS_TYPE_REF
     , SDD_WAT_rec6.NAME
     , SDD_WAT_rec6.SEQUENCE
     , SDD_WAT_rec6.IMPLEMENTATION_NAME
     , SDD_WAT_rec6.SECURITY_LEVEL
     , SDD_WAT_rec6.CLASSIFIER_ATTRIBUTE_REF
     , SDD_WAT_rec6.TYPE
     , SDD_WAT_rec6.ATTRIBUTE_DOMAIN_REF
     , SDD_WAT_rec6.DEFAULT_VALUE
     , SDD_WAT_rec6.WORKFLOW_SUBTYPE
     , SDD_WAT_rec6.WORKFLOW_ATTRIBUTE_SUBTYPE
    );
  jr_reg_ver.vercopy_dependencies(SDD_WAT_rec6.irid, SDD_WAT_rec6.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_WMT_rec7 in SDD_WMT_cur7 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_WMT
    values (
       SDD_WMT_rec7.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_WMT_rec7.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_WMT_rec7.TYPES
     , SDD_WMT_rec7.ELEMENT_TYPE_NAME
     , SDD_WMT_rec7.DATE_CREATED
     , SDD_WMT_rec7.CREATED_BY
     , SDD_WMT_rec7.DATE_CHANGED
     , SDD_WMT_rec7.CHANGED_BY
     , SDD_WMT_rec7.NOTM
     , SDD_WMT_rec7.WORKFLOW_ITEM_TYPE_REF
     , SDD_WMT_rec7.NAME
     , SDD_WMT_rec7.IMPLEMENTATION_NAME
     , SDD_WMT_rec7.SECURITY_LEVEL
     , SDD_WMT_rec7.SUBJECT
     , SDD_WMT_rec7.DEFAULT_PRIORITY
    );
  jr_reg_ver.vercopy_dependencies(SDD_WMT_rec7.irid, SDD_WMT_rec7.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  jr_reg_ver.vercopy_dependent_objects(SDD_WIT_ver.ivid, new_ivid);
  return new_ivid;
end SDD_WIT_ver;
/
create or replace function PK_SDD_WIT (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_WIT the_tab_new, SDD_WIT the_tab_old
  where  the_tab_new.ivid = PK_SDD_WIT.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_WIT.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_WIT;
/
create or replace function PK_SDD_WMT (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_WMT the_tab_new, SDD_WMT the_tab_old
  where  the_tab_new.ivid = PK_SDD_WMT.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_WMT.ivid;
  dummy number;
begin
  open bad_cur;
  fetch bad_cur into dummy;
  if bad_cur%FOUND then
    close bad_cur;
    return FALSE;
  end if;
  close bad_cur;
  return TRUE;
end PK_SDD_WMT;
/
----- Added to create a policy function for container ----------------------------------------------------
CREATE OR REPLACE FUNCTION sdd_container_version_policy (schema varchar2, tablename varchar2)
RETURN VARCHAR2
AS
BEGIN
    if jr_context.workarea is null then 
     RETURN  'exists (select null
                      from sys.dual
                      where exists ( select NULL
                                     from   i$sdd_object_versions  ov 
                                     where  ov.ivid        = ivid 
                                     and    ov.wastebasket = jr_context.wastebasket
                                     group by 1
                                   )
                            and jr_acc_rights.can_sel(ivid, ''Y'') = ''Y'')';
    else 
      RETURN 'exists (select null
                      from sys.dual
                      where    exists (select NULL
                                       from   i$sdd_wa_context ctxt 
                                       where  ctxt.object_ivid   = ivid 
                                       and    ctxt.workarea_irid = jr_context.workarea
                                       and    ctxt.wastebasket   = jr_context.wastebasket
                                       group by 1
                                      )
                              and jr_acc_rights.can_sel(ivid, ''Y'') = ''Y'')';
    end if;
END;
/
----- Added to creare a policy function for PAC element --------------------------------------------------
CREATE OR REPLACE FUNCTION sdd_pac_version_policy (schema varchar2, tablename varchar2)
RETURN VARCHAR2
AS
BEGIN
    if jr_context.workarea is null then 
      RETURN 'exists   ( select NULL
                         from   i$sdd_object_versions  ov 
                         where  ov.ivid        = ivid 
                         and    ov.wastebasket = jr_context.wastebasket 
			             group by 1)';
    else 
      RETURN 'exists   ( select NULL
                         from   i$sdd_wa_context ctxt 
                         where  ctxt.object_ivid   = ivid 
                         and    ctxt.workarea_irid = jr_context.workarea 
                         and    ctxt.wastebasket   = jr_context.wastebasket 
			             group by 1)';
    end if;
END;
/

----- Added to create a policy function for SAC element --------------------------------------------------
/* This policy is used to add 'version resolution' subquery to the secondary access element views*/
CREATE OR REPLACE FUNCTION sdd_sac_version_policy (schema varchar2, tablename varchar2)
RETURN VARCHAR2
AS
BEGIN
if jr_context.workarea is null then 
      RETURN 'exists    ( select NULL
                          from   i$sdd_object_versions  ov 
                          where  ov.ivid        = parent_ivid
                          and    ov.wastebasket = jr_context.wastebasket 
			              group by 1)';
    else 
      RETURN 'exists    ( select NULL
                          from   i$sdd_wa_context ctxt 
                          where  ctxt.object_ivid   = parent_ivid
                          and    ctxt.workarea_irid = jr_context.workarea 
                          and    ctxt.wastebasket   = jr_context.wastebasket 
			              group by 1)';
    end if;
END;
/

                               
CREATE OR REPLACE FUNCTION sdd_module_version_policy (schema varchar2, tablename varchar2)
RETURN VARCHAR2
AS
BEGIN
    if jr_context.workarea is null then 
      RETURN 'exists  ( select NULL
                        from   i$sdd_object_versions  ov 
                        where  ov.ivid        = NVL(parent_ivid, '||tablename||'.ivid) 
                        and    ov.wastebasket = jr_context.wastebasket 
			            group by 1)';
    else 
      RETURN 'exists  ( select NULL
                        from   i$sdd_wa_context ctxt 
                        where  ctxt.object_ivid   = NVL(parent_ivid, '||tablename||'.ivid) 
                        and    ctxt.workarea_irid = jr_context.workarea 
                        and    ctxt.wastebasket   = jr_context.wastebasket 
			            group by 1)';
    end if;
END;
/
