create or replace function CK_APPLICATION_LOGIC_PK (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$CK_APPLICATION_LOGIC the_tab_new, CK_APPLICATION_LOGIC the_tab_old
  where  the_tab_new.ivid = CK_APPLICATION_LOGIC_PK.ivid
  and    the_tab_new.AL_ID = the_tab_old.AL_ID
  and    the_tab_old.ivid != CK_APPLICATION_LOGIC_PK.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 CK_APPLICATION_LOGIC_PK;
/
create or replace function SDD_NLS_MESSAGES_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_NLS_MESSAGES_cur is
    select *
    from   l$SDD_NLS_MESSAGES the_tab
    where  the_tab.irid=SDD_NLS_MESSAGES_ver.irid
    and    the_tab.ivid=SDD_NLS_MESSAGES_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  for SDD_NLS_MESSAGES_rec in SDD_NLS_MESSAGES_cur loop
  insert into l$SDD_NLS_MESSAGES
  values (
    SDD_NLS_MESSAGES_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_NLS_MESSAGES_rec.lid
   ,SDD_NLS_MESSAGES_rec.slid
   ,SDD_NLS_MESSAGES_rec.MSGNO
   ,SDD_NLS_MESSAGES_rec.MNEMONIC
   ,SDD_NLS_MESSAGES_rec.FACILITY
   ,SDD_NLS_MESSAGES_rec.SEVERITY
   ,SDD_NLS_MESSAGES_rec.MESSAGE_TEXT
   ,SDD_NLS_MESSAGES_rec.TRANSLATION_NOTES
   ,SDD_NLS_MESSAGES_rec.TYPES
   ,SDD_NLS_MESSAGES_rec.DATE_CREATED
   ,SDD_NLS_MESSAGES_rec.DATE_CHANGED
   ,SDD_NLS_MESSAGES_rec.CREATED_BY
   ,SDD_NLS_MESSAGES_rec.CHANGED_BY
   ,SDD_NLS_MESSAGES_rec.NOTM
  );
  jr_reg_ver.vercopy_dependencies(SDD_NLS_MESSAGES_ver.irid, SDD_NLS_MESSAGES_ver.ivid, new_ivid, null, copy_dependencies);
  end loop;
  return new_ivid;
end SDD_NLS_MESSAGES_ver;
/
comment on table l$SDD_NLS_MESSAGES is 'NLSable messages'
/
comment on table SDD_NLS_MESSAGES is 'NLSable messages'
/
create or replace function SDD_NLS_MESSAGES_PK (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   l$SDD_NLS_MESSAGES the_tab_new, SDD_NLS_MESSAGES the_tab_old
  where  the_tab_new.ivid = SDD_NLS_MESSAGES_PK.ivid
  and    the_tab_new.MSGNO = the_tab_old.MSGNO
  and    the_tab_old.ivid != SDD_NLS_MESSAGES_PK.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 SDD_NLS_MESSAGES_PK;
/
create or replace function SDD_NLS_MESSAGES_NAME (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   l$SDD_NLS_MESSAGES the_tab_new, SDD_NLS_MESSAGES the_tab_old
  where  the_tab_new.ivid = SDD_NLS_MESSAGES_NAME.ivid
  and    the_tab_new.MNEMONIC = the_tab_old.MNEMONIC
  and    the_tab_old.ivid != SDD_NLS_MESSAGES_NAME.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 SDD_NLS_MESSAGES_NAME;
/
create or replace function SDD_NLS_PROMPTS_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_NLS_PROMPTS_cur is
    select *
    from   l$SDD_NLS_PROMPTS the_tab
    where  the_tab.irid=SDD_NLS_PROMPTS_ver.irid
    and    the_tab.ivid=SDD_NLS_PROMPTS_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  for SDD_NLS_PROMPTS_rec in SDD_NLS_PROMPTS_cur loop
  insert into l$SDD_NLS_PROMPTS
  values (
    SDD_NLS_PROMPTS_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_NLS_PROMPTS_rec.lid
   ,SDD_NLS_PROMPTS_rec.slid
   ,SDD_NLS_PROMPTS_rec.PMPTNO
   ,SDD_NLS_PROMPTS_rec.PROMPT_TEXT
   ,SDD_NLS_PROMPTS_rec.TRANSLATION_NOTES
   ,SDD_NLS_PROMPTS_rec.TYPES
   ,SDD_NLS_PROMPTS_rec.DATE_CREATED
   ,SDD_NLS_PROMPTS_rec.DATE_CHANGED
   ,SDD_NLS_PROMPTS_rec.CREATED_BY
   ,SDD_NLS_PROMPTS_rec.CHANGED_BY
   ,SDD_NLS_PROMPTS_rec.NOTM
  );
  jr_reg_ver.vercopy_dependencies(SDD_NLS_PROMPTS_ver.irid, SDD_NLS_PROMPTS_ver.ivid, new_ivid, null, copy_dependencies);
  end loop;
  return new_ivid;
end SDD_NLS_PROMPTS_ver;
/
comment on table l$SDD_NLS_PROMPTS is 'NLSable prompts'
/
comment on table SDD_NLS_PROMPTS is 'NLSable prompts'
/
create or replace function SDD_PROMPTS_PK (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   l$SDD_NLS_PROMPTS the_tab_new, SDD_NLS_PROMPTS the_tab_old
  where  the_tab_new.ivid = SDD_PROMPTS_PK.ivid
  and    the_tab_new.PMPTNO = the_tab_old.PMPTNO
  and    the_tab_old.ivid != SDD_PROMPTS_PK.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 SDD_PROMPTS_PK;
/
create or replace function SDD_NLS_PROPLIST_ENTRIES_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_NLS_PROPLIST_ENTRIES_cur is
    select *
    from   l$SDD_NLS_PROPLIST_ENTRIES the_tab
    where  the_tab.irid=SDD_NLS_PROPLIST_ENTRIES_ver.irid
    and    the_tab.ivid=SDD_NLS_PROPLIST_ENTRIES_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  for SDD_NLS_PROPLIST_ENTRIES_rec in SDD_NLS_PROPLIST_ENTRIES_cur loop
  insert into l$SDD_NLS_PROPLIST_ENTRIES
  values (
    SDD_NLS_PROPLIST_ENTRIES_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_NLS_PROPLIST_ENTRIES_rec.lid
   ,SDD_NLS_PROPLIST_ENTRIES_rec.slid
   ,SDD_NLS_PROPLIST_ENTRIES_rec.PLID
   ,SDD_NLS_PROPLIST_ENTRIES_rec.PROPERTY
   ,SDD_NLS_PROPLIST_ENTRIES_rec.SEQ
   ,SDD_NLS_PROPLIST_ENTRIES_rec.VALUE
   ,SDD_NLS_PROPLIST_ENTRIES_rec.TYPES
   ,SDD_NLS_PROPLIST_ENTRIES_rec.DATE_CREATED
   ,SDD_NLS_PROPLIST_ENTRIES_rec.DATE_CHANGED
   ,SDD_NLS_PROPLIST_ENTRIES_rec.CREATED_BY
   ,SDD_NLS_PROPLIST_ENTRIES_rec.CHANGED_BY
   ,SDD_NLS_PROPLIST_ENTRIES_rec.NOTM
  );
  jr_reg_ver.vercopy_dependencies(SDD_NLS_PROPLIST_ENTRIES_ver.irid, SDD_NLS_PROPLIST_ENTRIES_ver.ivid, new_ivid, null, copy_dependencies);
  end loop;
  return new_ivid;
end SDD_NLS_PROPLIST_ENTRIES_ver;
/
comment on table l$SDD_NLS_PROPLIST_ENTRIES is 'NLSable property list entries (owned by proplists)'
/
comment on table SDD_NLS_PROPLIST_ENTRIES is 'NLSable property list entries (owned by proplists)'
/
create or replace function SDD_NLS_PL_ENTRIES_PK (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   l$SDD_NLS_PROPLIST_ENTRIES the_tab_new, SDD_NLS_PROPLIST_ENTRIES the_tab_old
  where  the_tab_new.ivid = SDD_NLS_PL_ENTRIES_PK.ivid
  and    the_tab_new.PLID = the_tab_old.PLID
  and    the_tab_new.PROPERTY = the_tab_old.PROPERTY
  and    the_tab_new.SEQ = the_tab_old.SEQ
  and    the_tab_old.ivid != SDD_NLS_PL_ENTRIES_PK.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 SDD_NLS_PL_ENTRIES_PK;
/
create or replace function SDD_NLS_PROPLIST_FK (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.PLID ref_value
  from   l$SDD_NLS_PROPLIST_ENTRIES the_tab
  where  the_tab.ivid = SDD_NLS_PROPLIST_FK.object_ivid
  and    the_tab.PLID is not null
  and    not exists (
             select null
             from   SDD_PROPERTY_LISTS foreign_tab
             where  the_tab.PLID = foreign_tab.PLID
             );
  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
                                   , 384781276385891573485388780199757881, action);
  end loop;
  return is_ok;
end SDD_NLS_PROPLIST_FK;
/
create or replace function SDD_NLS_RESOURCES_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_NLS_RESOURCES_cur is
    select *
    from   l$SDD_NLS_RESOURCES the_tab
    where  the_tab.irid=SDD_NLS_RESOURCES_ver.irid
    and    the_tab.ivid=SDD_NLS_RESOURCES_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  for SDD_NLS_RESOURCES_rec in SDD_NLS_RESOURCES_cur loop
  insert into l$SDD_NLS_RESOURCES
  values (
    SDD_NLS_RESOURCES_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_NLS_RESOURCES_rec.lid
   ,SDD_NLS_RESOURCES_rec.slid
   ,SDD_NLS_RESOURCES_rec.RESID
   ,SDD_NLS_RESOURCES_rec.MNEMONIC
   ,SDD_NLS_RESOURCES_rec.KIND
   ,SDD_NLS_RESOURCES_rec.RESOURCE_DATA
   ,SDD_NLS_RESOURCES_rec.TRANSLATION_NOTES
   ,SDD_NLS_RESOURCES_rec.TYPES
   ,SDD_NLS_RESOURCES_rec.DATE_CREATED
   ,SDD_NLS_RESOURCES_rec.DATE_CHANGED
   ,SDD_NLS_RESOURCES_rec.CREATED_BY
   ,SDD_NLS_RESOURCES_rec.CHANGED_BY
   ,SDD_NLS_RESOURCES_rec.NOTM
  );
  jr_reg_ver.vercopy_dependencies(SDD_NLS_RESOURCES_ver.irid, SDD_NLS_RESOURCES_ver.ivid, new_ivid, null, copy_dependencies);
  end loop;
  return new_ivid;
end SDD_NLS_RESOURCES_ver;
/
comment on table l$SDD_NLS_RESOURCES is 'NLSable resources'
/
comment on table SDD_NLS_RESOURCES is 'NLSable resources'
/
create or replace function SDD_RESOURCES_PK (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   l$SDD_NLS_RESOURCES the_tab_new, SDD_NLS_RESOURCES the_tab_old
  where  the_tab_new.ivid = SDD_RESOURCES_PK.ivid
  and    the_tab_new.RESID = the_tab_old.RESID
  and    the_tab_old.ivid != SDD_RESOURCES_PK.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 SDD_RESOURCES_PK;
/
create or replace function SDD_RESOURCES_MNEMONIC (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   l$SDD_NLS_RESOURCES the_tab_new, SDD_NLS_RESOURCES the_tab_old
  where  the_tab_new.ivid = SDD_RESOURCES_MNEMONIC.ivid
  and    the_tab_new.MNEMONIC = the_tab_old.MNEMONIC
  and    the_tab_old.ivid != SDD_RESOURCES_MNEMONIC.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 SDD_RESOURCES_MNEMONIC;
/
create or replace function SDD_NLS_PROPLIST_FK_d (
el_ivid number
 ,PLID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, 384781276385863239286491562328475705 types
  from   SDD_NLS_PROPLIST_ENTRIES child_tab
  where  child_tab.PLID=SDD_NLS_PROPLIST_FK_d.PLID
  ;
 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_NLS_PROPLIST_ENTRIES child_tab, i$sdd_object_versions o
    where  child_tab.PLID=SDD_NLS_PROPLIST_FK_d.PLID
    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 SDD_NLS_PROPLIST_FK_d;
/
create or replace function SDD_PROPLIST_FK_d (
el_ivid number
 ,PLID NUMBER
,el_type number
,action varchar2
) return boolean as
cursor bad_cur is
  select child_tab.irid, 384781276385901018218354519490185273 types
  from   SDD_PROPLIST_ENTRIES child_tab
  where  child_tab.PLID=SDD_PROPLIST_FK_d.PLID
  ;
 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_PROPLIST_ENTRIES child_tab, i$sdd_object_versions o
    where  child_tab.PLID=SDD_PROPLIST_FK_d.PLID
    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 SDD_PROPLIST_FK_d;
/
comment on column i$SDD_PROPERTY_LISTS.PLID is 'Unique numeric identifier'
/
comment on column SDD_PROPERTY_LISTS.PLID is 'Unique numeric identifier'
/
comment on column i$SDD_PROPERTY_LISTS.NAME is 'Property list name'
/
comment on column SDD_PROPERTY_LISTS.NAME is 'Property list name'
/
comment on column i$SDD_PROPERTY_LISTS.TRANSLATION_NOTES is 'Notes for translators (for entry tables)'
/
comment on column SDD_PROPERTY_LISTS.TRANSLATION_NOTES is 'Notes for translators (for entry tables)'
/
create or replace function SDD_PROPERTY_LISTS_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_PROPERTY_LISTS_cur is
    select *
    from   i$SDD_PROPERTY_LISTS the_tab
    where  the_tab.irid=SDD_PROPERTY_LISTS_ver.irid
    and    the_tab.ivid=SDD_PROPERTY_LISTS_ver.ivid;
  SDD_PROPERTY_LISTS_rec SDD_PROPERTY_LISTS_cur%ROWTYPE;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_PROPERTY_LISTS_cur;
  fetch SDD_PROPERTY_LISTS_cur into SDD_PROPERTY_LISTS_rec;
  close SDD_PROPERTY_LISTS_cur;
  insert into i$SDD_PROPERTY_LISTS
  values (
    SDD_PROPERTY_LISTS_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_PROPERTY_LISTS_rec.PLID
   ,SDD_PROPERTY_LISTS_rec.NAME
   ,SDD_PROPERTY_LISTS_rec.TRANSLATION_NOTES
   ,SDD_PROPERTY_LISTS_rec.TYPES
   ,SDD_PROPERTY_LISTS_rec.DATE_CREATED
   ,SDD_PROPERTY_LISTS_rec.DATE_CHANGED
   ,SDD_PROPERTY_LISTS_rec.CREATED_BY
   ,SDD_PROPERTY_LISTS_rec.CHANGED_BY
   ,SDD_PROPERTY_LISTS_rec.NOTM
  );
  jr_reg_ver.vercopy_dependencies(SDD_PROPERTY_LISTS_ver.irid, SDD_PROPERTY_LISTS_ver.ivid, new_ivid, null, copy_dependencies);
  return new_ivid;
end SDD_PROPERTY_LISTS_ver;
/
comment on table i$SDD_PROPERTY_LISTS is 'Property list master - owns two collection tables'
/
comment on table SDD_PROPERTY_LISTS is 'Property list master - owns two collection tables'
/
create or replace function SDD_PROPLISTS_PK (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_PROPERTY_LISTS the_tab_new, SDD_PROPERTY_LISTS the_tab_old
  where  the_tab_new.ivid = SDD_PROPLISTS_PK.ivid
  and    the_tab_new.PLID = the_tab_old.PLID
  and    the_tab_old.ivid != SDD_PROPLISTS_PK.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 SDD_PROPLISTS_PK;
/
create or replace function SDD_PROPLIST_ENTRIES_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_PROPLIST_ENTRIES_cur is
    select *
    from   i$SDD_PROPLIST_ENTRIES the_tab
    where  the_tab.irid=SDD_PROPLIST_ENTRIES_ver.irid
    and    the_tab.ivid=SDD_PROPLIST_ENTRIES_ver.ivid;
  SDD_PROPLIST_ENTRIES_rec SDD_PROPLIST_ENTRIES_cur%ROWTYPE;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_PROPLIST_ENTRIES_cur;
  fetch SDD_PROPLIST_ENTRIES_cur into SDD_PROPLIST_ENTRIES_rec;
  close SDD_PROPLIST_ENTRIES_cur;
  insert into i$SDD_PROPLIST_ENTRIES
  values (
    SDD_PROPLIST_ENTRIES_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_PROPLIST_ENTRIES_rec.PLID
   ,SDD_PROPLIST_ENTRIES_rec.PROPERTY
   ,SDD_PROPLIST_ENTRIES_rec.SEQ
   ,SDD_PROPLIST_ENTRIES_rec.VALUE
   ,SDD_PROPLIST_ENTRIES_rec.TYPES
   ,SDD_PROPLIST_ENTRIES_rec.DATE_CREATED
   ,SDD_PROPLIST_ENTRIES_rec.DATE_CHANGED
   ,SDD_PROPLIST_ENTRIES_rec.CREATED_BY
   ,SDD_PROPLIST_ENTRIES_rec.CHANGED_BY
   ,SDD_PROPLIST_ENTRIES_rec.NOTM
  );
  jr_reg_ver.vercopy_dependencies(SDD_PROPLIST_ENTRIES_ver.irid, SDD_PROPLIST_ENTRIES_ver.ivid, new_ivid, null, copy_dependencies);
  return new_ivid;
end SDD_PROPLIST_ENTRIES_ver;
/
comment on table i$SDD_PROPLIST_ENTRIES is 'property list entries (owned by sdd_property_lists)'
/
comment on table SDD_PROPLIST_ENTRIES is 'property list entries (owned by sdd_property_lists)'
/
create or replace function SDD_PL_ENTRIES_PK (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_PROPLIST_ENTRIES the_tab_new, SDD_PROPLIST_ENTRIES the_tab_old
  where  the_tab_new.ivid = SDD_PL_ENTRIES_PK.ivid
  and    the_tab_new.PLID = the_tab_old.PLID
  and    the_tab_new.PROPERTY = the_tab_old.PROPERTY
  and    the_tab_new.SEQ = the_tab_old.SEQ
  and    the_tab_old.ivid != SDD_PL_ENTRIES_PK.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 SDD_PL_ENTRIES_PK;
/
create or replace function SDD_PROPLIST_FK (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.PLID ref_value
  from   i$SDD_PROPLIST_ENTRIES the_tab
  where  the_tab.ivid = SDD_PROPLIST_FK.object_ivid
  and    the_tab.PLID is not null
  and    not exists (
             select null
             from   SDD_PROPERTY_LISTS foreign_tab
             where  the_tab.PLID = foreign_tab.PLID
             );
  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
                                   , 384781276385891573485388780199757881, action);
  end loop;
  return is_ok;
end SDD_PROPLIST_FK;
/
create or replace function SDD_WIDGETS_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_WIDGETS_cur is
    select *
    from   i$SDD_WIDGETS the_tab
    where  the_tab.irid=SDD_WIDGETS_ver.irid
    and    the_tab.ivid=SDD_WIDGETS_ver.ivid;
  SDD_WIDGETS_rec SDD_WIDGETS_cur%ROWTYPE;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_WIDGETS_cur;
  fetch SDD_WIDGETS_cur into SDD_WIDGETS_rec;
  close SDD_WIDGETS_cur;
  insert into i$SDD_WIDGETS
  values (
    SDD_WIDGETS_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_WIDGETS_rec.WID
   ,SDD_WIDGETS_rec.WIDGET_NAME
   ,SDD_WIDGETS_rec.WIDGET_TYPE
   ,SDD_WIDGETS_rec.DESCRIPTION
   ,SDD_WIDGETS_rec.NOTM
   ,SDD_WIDGETS_rec.DATE_CREATED
   ,SDD_WIDGETS_rec.CREATED_BY
   ,SDD_WIDGETS_rec.DATE_CHANGED
   ,SDD_WIDGETS_rec.CHANGED_BY
   ,SDD_WIDGETS_rec.TYPES
  );
  jr_reg_ver.vercopy_dependencies(SDD_WIDGETS_ver.irid, SDD_WIDGETS_ver.ivid, new_ivid, null, copy_dependencies);
  return new_ivid;
end SDD_WIDGETS_ver;
/
comment on table i$SDD_WIDGETS is 'Vanilla relational object'
/
comment on table SDD_WIDGETS is 'Vanilla relational object'
/
create or replace function SDD_WIDGETS_PK (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_WIDGETS the_tab_new, SDD_WIDGETS the_tab_old
  where  the_tab_new.ivid = SDD_WIDGETS_PK.ivid
  and    the_tab_new.WID = the_tab_old.WID
  and    the_tab_old.ivid != SDD_WIDGETS_PK.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 SDD_WIDGETS_PK;
/
create or replace function SDD_WIDGET_UNIQUE_NAME (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_WIDGETS the_tab_new, SDD_WIDGETS the_tab_old
  where  the_tab_new.ivid = SDD_WIDGET_UNIQUE_NAME.ivid
  and    the_tab_new.WIDGET_NAME = the_tab_old.WIDGET_NAME
  and    the_tab_old.ivid != SDD_WIDGET_UNIQUE_NAME.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 SDD_WIDGET_UNIQUE_NAME;
/
create or replace function PK_SDD_A1 (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_A1 the_tab_new, SDD_A1 the_tab_old
  where  the_tab_new.ivid = PK_SDD_A1.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_A1.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_A1;
/
create or replace function FK_A1_TO_E2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.CSF_REF ref_value
  from   i$SDD_A1 the_tab
  where  the_tab.ivid = FK_A1_TO_E2.object_ivid
  and    the_tab.CSF_REF is not null
  and    not exists (
             select null
             from   SDD_E2 foreign_tab
             where  the_tab.CSF_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
                                   , 4966, action);
  end loop;
  return is_ok;
end FK_A1_TO_E2;
/
create or replace function PK_SDD_A10 (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_A10 the_tab_new, SDD_A10 the_tab_old
  where  the_tab_new.ivid = PK_SDD_A10.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_A10.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_A10;
/
create or replace function FK_A10_TO_E5 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.PROBLEM_REF ref_value
  from   i$SDD_A10 the_tab
  where  the_tab.ivid = FK_A10_TO_E5.object_ivid
  and    the_tab.PROBLEM_REF is not null
  and    not exists (
             select null
             from   SDD_E5 foreign_tab
             where  the_tab.PROBLEM_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
                                   , 4963, action);
  end loop;
  return is_ok;
end FK_A10_TO_E5;
/
create or replace function PK_SDD_A11 (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_A11 the_tab_new, SDD_A11 the_tab_old
  where  the_tab_new.ivid = PK_SDD_A11.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_A11.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_A11;
/
create or replace function FK_A11_TO_FUN (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.FUNCTION_REF ref_value
  from   i$SDD_A11 the_tab
  where  the_tab.ivid = FK_A11_TO_FUN.object_ivid
  and    the_tab.FUNCTION_REF is not null
  and    not exists (
             select null
             from   SDD_FUN foreign_tab
             where  the_tab.FUNCTION_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
                                   , 5024, action);
  end loop;
  return is_ok;
end FK_A11_TO_FUN;
/
create or replace function PK_SDD_A2 (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_A2 the_tab_new, SDD_A2 the_tab_old
  where  the_tab_new.ivid = PK_SDD_A2.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_A2.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_A2;
/
create or replace function FK_A2_TO_MOD (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.MODULE_REF ref_value
  from   i$SDD_A2 the_tab
  where  the_tab.ivid = FK_A2_TO_MOD.object_ivid
  and    the_tab.MODULE_REF is not null
  and    not exists (
             select null
             from   SDD_MOD foreign_tab
             where  the_tab.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_A2_TO_MOD;
/
create or replace function PK_SDD_A20 (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_A20 the_tab_new, SDD_A20 the_tab_old
  where  the_tab_new.ivid = PK_SDD_A20.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_A20.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_A20;
/
create or replace function FK_A20_TO_E202 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.USE_OF_NODE_REF ref_value
  from   i$SDD_A20 the_tab
  where  the_tab.ivid = FK_A20_TO_E202.object_ivid
  and    the_tab.USE_OF_NODE_REF is not null
  and    not exists (
             select null
             from   SDD_E20 foreign_tab
             where  the_tab.USE_OF_NODE_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
                                   , 4961, action);
  end loop;
  return is_ok;
end FK_A20_TO_E202;
/
create or replace function PK_SDD_A21 (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_A21 the_tab_new, SDD_A21 the_tab_old
  where  the_tab_new.ivid = PK_SDD_A21.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_A21.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_A21;
/
create or replace function FK_A21_TO_E20 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.NODE_REF ref_value
  from   i$SDD_A21 the_tab
  where  the_tab.ivid = FK_A21_TO_E20.object_ivid
  and    the_tab.NODE_REF is not null
  and    not exists (
             select null
             from   SDD_E20 foreign_tab
             where  the_tab.NODE_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
                                   , 4961, action);
  end loop;
  return is_ok;
end FK_A21_TO_E20;
/
create or replace function PK_SDD_A23 (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_A23 the_tab_new, SDD_A23 the_tab_old
  where  the_tab_new.ivid = PK_SDD_A23.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_A23.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_A23;
/
create or replace function FK_A23_TO_MOD (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.MODULE_REF ref_value
  from   i$SDD_A23 the_tab
  where  the_tab.ivid = FK_A23_TO_MOD.object_ivid
  and    the_tab.MODULE_REF is not null
  and    not exists (
             select null
             from   SDD_MOD foreign_tab
             where  the_tab.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_A23_TO_MOD;
/
create or replace function PK_SDD_A24 (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_A24 the_tab_new, SDD_A24 the_tab_old
  where  the_tab_new.ivid = PK_SDD_A24.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_A24.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_A24;
/
create or replace function FK_A24_TO_BUN (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.BUSINESS_UNIT_REF ref_value
  from   i$SDD_A24 the_tab
  where  the_tab.ivid = FK_A24_TO_BUN.object_ivid
  and    the_tab.BUSINESS_UNIT_REF is not null
  and    not exists (
             select null
             from   SDD_BUN foreign_tab
             where  the_tab.BUSINESS_UNIT_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
                                   , 5005, action);
  end loop;
  return is_ok;
end FK_A24_TO_BUN;
/
create or replace function PK_SDD_A3 (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_A3 the_tab_new, SDD_A3 the_tab_old
  where  the_tab_new.ivid = PK_SDD_A3.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_A3.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_A3;
/
create or replace function FK_A3_TO_E3 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.KPI_REF ref_value
  from   i$SDD_A3 the_tab
  where  the_tab.ivid = FK_A3_TO_E3.object_ivid
  and    the_tab.KPI_REF is not null
  and    not exists (
             select null
             from   SDD_E3 foreign_tab
             where  the_tab.KPI_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
                                   , 4965, action);
  end loop;
  return is_ok;
end FK_A3_TO_E3;
/
create or replace function PK_SDD_A4 (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_A4 the_tab_new, SDD_A4 the_tab_old
  where  the_tab_new.ivid = PK_SDD_A4.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_A4.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_A4;
/
create or replace function FK_A4_TO_FUN (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.FUNCTION_REF ref_value
  from   i$SDD_A4 the_tab
  where  the_tab.ivid = FK_A4_TO_FUN.object_ivid
  and    the_tab.FUNCTION_REF is not null
  and    not exists (
             select null
             from   SDD_FUN foreign_tab
             where  the_tab.FUNCTION_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
                                   , 5024, action);
  end loop;
  return is_ok;
end FK_A4_TO_FUN;
/
create or replace function PK_SDD_A5 (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_A5 the_tab_new, SDD_A5 the_tab_old
  where  the_tab_new.ivid = PK_SDD_A5.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_A5.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_A5;
/
create or replace function FK_A5_TO_MOD (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.MODULE_REF ref_value
  from   i$SDD_A5 the_tab
  where  the_tab.ivid = FK_A5_TO_MOD.object_ivid
  and    the_tab.MODULE_REF is not null
  and    not exists (
             select null
             from   SDD_MOD foreign_tab
             where  the_tab.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_A5_TO_MOD;
/
create or replace function PK_SDD_A6 (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_A6 the_tab_new, SDD_A6 the_tab_old
  where  the_tab_new.ivid = PK_SDD_A6.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_A6.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_A6;
/
create or replace function FK_A6_TO_TAB (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_A6 the_tab
  where  the_tab.ivid = FK_A6_TO_TAB.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_A6_TO_TAB;
/
create or replace function PK_SDD_A7 (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_A7 the_tab_new, SDD_A7 the_tab_old
  where  the_tab_new.ivid = PK_SDD_A7.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_A7.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_A7;
/
create or replace function FK_A7_TO_MOD (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.MODULE_REF ref_value
  from   i$SDD_A7 the_tab
  where  the_tab.ivid = FK_A7_TO_MOD.object_ivid
  and    the_tab.MODULE_REF is not null
  and    not exists (
             select null
             from   SDD_MOD foreign_tab
             where  the_tab.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_A7_TO_MOD;
/
create or replace function PK_SDD_A8 (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_A8 the_tab_new, SDD_A8 the_tab_old
  where  the_tab_new.ivid = PK_SDD_A8.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_A8.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_A8;
/
create or replace function FK_A8_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_A8 the_tab
  where  the_tab.ivid = FK_A8_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_A8_TO_E1;
/
create or replace function PK_SDD_A9 (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_A9 the_tab_new, SDD_A9 the_tab_old
  where  the_tab_new.ivid = PK_SDD_A9.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_A9.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_A9;
/
create or replace function FK_A9_TO_BUN (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.BUSINESS_UNIT_REF ref_value
  from   i$SDD_A9 the_tab
  where  the_tab.ivid = FK_A9_TO_BUN.object_ivid
  and    the_tab.BUSINESS_UNIT_REF is not null
  and    not exists (
             select null
             from   SDD_BUN foreign_tab
             where  the_tab.BUSINESS_UNIT_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
                                   , 5005, action);
  end loop;
  return is_ok;
end FK_A9_TO_BUN;
/
create or replace function PK_SDD_ACI (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_ACI the_tab_new, SDD_ACI the_tab_old
  where  the_tab_new.ivid = PK_SDD_ACI.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_ACI.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_ACI;
/
create or replace function FK_ACI_TO_MCN2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.MCN_REF_TO ref_value
  from   i$SDD_ACI the_tab
  where  the_tab.ivid = FK_ACI_TO_MCN2.object_ivid
  and    the_tab.MCN_REF_TO is not null
  and    not exists (
             select null
             from   SDD_MCN foreign_tab
             where  the_tab.MCN_REF_TO = 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
                                   , 4918, action);
  end loop;
  return is_ok;
end FK_ACI_TO_MCN2;
/
create or replace function FK_ACI_TO_MODMOD (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.MODULE_NETWORK_REF ref_value
  from   i$SDD_ACI the_tab
  where  the_tab.ivid = FK_ACI_TO_MODMOD.object_ivid
  and    the_tab.MODULE_NETWORK_REF is not null
  and    not exists (
             select null
             from   SDD_MODMOD foreign_tab
             where  the_tab.MODULE_NETWORK_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
                                   , 5028, action);
  end loop;
  return is_ok;
end FK_ACI_TO_MODMOD;
/
create or replace function FK_ACRACR_TO_ACR2_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_ACRACR child_tab
  where  child_tab.SUPERTYPE_ACTOR_REF=FK_ACRACR_TO_ACR2_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_ACRACR child_tab, i$sdd_object_versions o
    where  child_tab.SUPERTYPE_ACTOR_REF=FK_ACRACR_TO_ACR2_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_ACRACR_TO_ACR2_d;
/
create or replace function SDD_ACR_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_ACR_cur is
    select *
    from   i$SDD_ACR the_tab
    where  the_tab.irid=SDD_ACR_ver.irid
    and    the_tab.ivid=SDD_ACR_ver.ivid;
  SDD_ACR_rec SDD_ACR_cur%ROWTYPE;
  cursor SDD_ACRACR_cur1 is
    select *
    from i$SDD_ACRACR the_tab
    where the_tab.parent_ivid=SDD_ACR_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_ACR_cur;
  fetch SDD_ACR_cur into SDD_ACR_rec;
  close SDD_ACR_cur;
  insert into i$SDD_ACR
  values (
    SDD_ACR_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_ACR_rec.TYPES
   ,SDD_ACR_rec.ELEMENT_TYPE_NAME
   ,SDD_ACR_rec.DATE_CREATED
   ,SDD_ACR_rec.CREATED_BY
   ,SDD_ACR_rec.DATE_CHANGED
   ,SDD_ACR_rec.CHANGED_BY
   ,SDD_ACR_rec.NOTM
   ,SDD_ACR_rec.NAME
   ,SDD_ACR_rec.EXTERNAL_FLAG
   ,SDD_ACR_rec.SYSTEM_FLAG
   ,SDD_ACR_rec.ICON_FILE_REF
   ,SDD_ACR_rec.EMAIL_ADDRESS
   ,SDD_ACR_rec.SECURITY_LEVEL
  );
  jr_reg_ver.vercopy_dependencies(SDD_ACR_ver.irid, SDD_ACR_ver.ivid, new_ivid, null, copy_dependencies);
  for SDD_ACRACR_rec1 in SDD_ACRACR_cur1 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_ACRACR
    values (
       SDD_ACRACR_rec1.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_ACRACR_rec1.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_ACRACR_rec1.TYPES
     , SDD_ACRACR_rec1.ELEMENT_TYPE_NAME
     , SDD_ACRACR_rec1.DATE_CREATED
     , SDD_ACRACR_rec1.CREATED_BY
     , SDD_ACRACR_rec1.DATE_CHANGED
     , SDD_ACRACR_rec1.CHANGED_BY
     , SDD_ACRACR_rec1.NOTM
     , SDD_ACRACR_rec1.SUPERTYPE_ACTOR_REF
     , SDD_ACRACR_rec1.SUBTYPE_ACTOR_REF
     , SDD_ACRACR_rec1.SEQUENCE
    );
  jr_reg_ver.vercopy_dependencies(SDD_ACRACR_rec1.irid, SDD_ACRACR_rec1.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  jr_reg_ver.vercopy_dependent_objects(SDD_ACR_ver.ivid, new_ivid);
  return new_ivid;
end SDD_ACR_ver;
/
create or replace function PK_SDD_ACR (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_ACR the_tab_new, SDD_ACR the_tab_old
  where  the_tab_new.ivid = PK_SDD_ACR.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_ACR.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_ACR;
/
create or replace function FK_ACR_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_ACR the_tab
  where  the_tab.ivid = FK_ACR_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_ACR_TO_FILES;
/
create or replace function PK_SDD_ACRACR (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_ACRACR the_tab_new, SDD_ACRACR the_tab_old
  where  the_tab_new.ivid = PK_SDD_ACRACR.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_ACRACR.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_ACRACR;
/
create or replace function UK_ACRACR_2 (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_ACRACR the_tab_new, SDD_ACRACR the_tab_old
  where  the_tab_new.ivid = UK_ACRACR_2.ivid
  and    the_tab_new.SUPERTYPE_ACTOR_REF = the_tab_old.SUPERTYPE_ACTOR_REF
  and    the_tab_new.SEQUENCE = the_tab_old.SEQUENCE
  and    the_tab_old.ivid != UK_ACRACR_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_ACRACR_2;
/
create or replace function FK_ACRACR_TO_ACR2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.SUPERTYPE_ACTOR_REF ref_value
  from   i$SDD_ACRACR the_tab
  where  the_tab.ivid = FK_ACRACR_TO_ACR2.object_ivid
  and    the_tab.SUPERTYPE_ACTOR_REF is not null
  and    not exists (
             select null
             from   SDD_ACR foreign_tab
             where  the_tab.SUPERTYPE_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_ACRACR_TO_ACR2;
/
create or replace function PK_SDD_ACRORG (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_ACRORG the_tab_new, SDD_ACRORG the_tab_old
  where  the_tab_new.ivid = PK_SDD_ACRORG.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_ACRORG.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_ACRORG;
/
create or replace function FK_ACRORG_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_ACRORG the_tab
  where  the_tab.ivid = FK_ACRORG_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_ACRORG_TO_ACR;
/
create or replace function SDD_ACT_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_ACT_cur is
    select *
    from   i$SDD_ACT the_tab
    where  the_tab.irid=SDD_ACT_ver.irid
    and    the_tab.ivid=SDD_ACT_ver.ivid;
  SDD_ACT_rec SDD_ACT_cur%ROWTYPE;
  cursor SDD_ACTACT_cur1 is
    select *
    from i$SDD_ACTACT the_tab
    where the_tab.parent_ivid=SDD_ACT_ver.ivid;
  cursor SDD_ACTE1_cur2 is
    select *
    from i$SDD_ACTE1 the_tab
    where the_tab.parent_ivid=SDD_ACT_ver.ivid;
  cursor SDD_ACTORG_cur3 is
    select *
    from i$SDD_ACTORG the_tab
    where the_tab.parent_ivid=SDD_ACT_ver.ivid;
  cursor SDD_ACUACR_cur4 is
    select *
    from i$SDD_ACUACR the_tab
    where the_tab.parent_ivid=SDD_ACT_ver.ivid;
  cursor SDD_TRA_cur5 is
    select *
    from i$SDD_TRA the_tab
    where the_tab.parent_ivid=SDD_ACT_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_ACT_cur;
  fetch SDD_ACT_cur into SDD_ACT_rec;
  close SDD_ACT_cur;
  insert into i$SDD_ACT
  values (
    SDD_ACT_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_ACT_rec.TYPES
   ,SDD_ACT_rec.ELEMENT_TYPE_NAME
   ,SDD_ACT_rec.DATE_CREATED
   ,SDD_ACT_rec.CREATED_BY
   ,SDD_ACT_rec.DATE_CHANGED
   ,SDD_ACT_rec.CHANGED_BY
   ,SDD_ACT_rec.NOTM
   ,SDD_ACT_rec.NAME
   ,SDD_ACT_rec.EXECUTION_MODE
   ,SDD_ACT_rec.METHOD_REF
   ,SDD_ACT_rec.EXECUTABLE_FILE_REF
   ,SDD_ACT_rec.PACKAGE_REF
   ,SDD_ACT_rec.ICON_FILE_REF
   ,SDD_ACT_rec.PRE_RULE_REF
   ,SDD_ACT_rec.USE_CASE_REF
   ,SDD_ACT_rec.GENERAL_ACTION_REF
   ,SDD_ACT_rec.POST_RULE_REF
   ,SDD_ACT_rec.DEF_MIN_DURATION
   ,SDD_ACT_rec.DEF_MIN_DURATION_UNIT
   ,SDD_ACT_rec.DEF_MAX_DURATION
   ,SDD_ACT_rec.DEF_MAX_DURATION_UNIT
   ,SDD_ACT_rec.DEF_TOTAL_DURATION
   ,SDD_ACT_rec.DEF_TOTAL_DURATION_UNIT
   ,SDD_ACT_rec.DEF_FREQUENCY
   ,SDD_ACT_rec.DEF_FREQUENCY_UNIT
   ,SDD_ACT_rec.DEF_TOTAL_COST_RATE
   ,SDD_ACT_rec.DEF_TOTAL_COST_RATE_UNIT
   ,SDD_ACT_rec.DEF_ADDITIONAL_COST_RATE
   ,SDD_ACT_rec.DEF_ADDITIONAL_COST_RATE_UNIT
   ,SDD_ACT_rec.DEF_QUALITY_PERCENT
   ,SDD_ACT_rec.DEF_VALUE_ADDED
   ,SDD_ACT_rec.DEF_EXECUTION_STRING
   ,SDD_ACT_rec.MESSAGING_ACTIVITY_TYPE
   ,SDD_ACT_rec.VOLATILE_EXECUTION_INDICATOR
   ,SDD_ACT_rec.MAPPING_FILE_REF
   ,SDD_ACT_rec.DEF_MESSAGING_PRIORITY
   ,SDD_ACT_rec.DEFAULT_MESSAGING_AUDIT
   ,SDD_ACT_rec.IMPLEMENTED_BY
   ,SDD_ACT_rec.ACTIVITY_DEFINITION_FOR
  );
  jr_reg_ver.vercopy_dependencies(SDD_ACT_ver.irid, SDD_ACT_ver.ivid, new_ivid, null, copy_dependencies);
  for SDD_ACTACT_rec1 in SDD_ACTACT_cur1 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_ACTACT
    values (
       SDD_ACTACT_rec1.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_ACTACT_rec1.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_ACTACT_rec1.TYPES
     , SDD_ACTACT_rec1.ELEMENT_TYPE_NAME
     , SDD_ACTACT_rec1.DATE_CREATED
     , SDD_ACTACT_rec1.CREATED_BY
     , SDD_ACTACT_rec1.DATE_CHANGED
     , SDD_ACTACT_rec1.CHANGED_BY
     , SDD_ACTACT_rec1.NOTM
     , SDD_ACTACT_rec1.PARENT_ACTIVITY_REF
     , SDD_ACTACT_rec1.CHILD_ACTIVITY_REF
    );
  jr_reg_ver.vercopy_dependencies(SDD_ACTACT_rec1.irid, SDD_ACTACT_rec1.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_ACTE1_rec2 in SDD_ACTE1_cur2 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_ACTE1
    values (
       SDD_ACTE1_rec2.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_ACTE1_rec2.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_ACTE1_rec2.TYPES
     , SDD_ACTE1_rec2.ELEMENT_TYPE_NAME
     , SDD_ACTE1_rec2.DATE_CREATED
     , SDD_ACTE1_rec2.CREATED_BY
     , SDD_ACTE1_rec2.DATE_CHANGED
     , SDD_ACTE1_rec2.CHANGED_BY
     , SDD_ACTE1_rec2.NOTM
     , SDD_ACTE1_rec2.ACTIVITY_DEFINITION_REF
     , SDD_ACTE1_rec2.OBJECTIVE_REF
    );
  jr_reg_ver.vercopy_dependencies(SDD_ACTE1_rec2.irid, SDD_ACTE1_rec2.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_ACTORG_rec3 in SDD_ACTORG_cur3 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_ACTORG
    values (
       SDD_ACTORG_rec3.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_ACTORG_rec3.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_ACTORG_rec3.TYPES
     , SDD_ACTORG_rec3.ELEMENT_TYPE_NAME
     , SDD_ACTORG_rec3.DATE_CREATED
     , SDD_ACTORG_rec3.CREATED_BY
     , SDD_ACTORG_rec3.DATE_CHANGED
     , SDD_ACTORG_rec3.CHANGED_BY
     , SDD_ACTORG_rec3.NOTM
     , SDD_ACTORG_rec3.ACTIVITY_REF
     , SDD_ACTORG_rec3.ORGANIZATION_UNIT_REF
     , SDD_ACTORG_rec3.SEQUENCE_NUMBER
     , SDD_ACTORG_rec3.ACTIVITY_USAGE_REF
     , SDD_ACTORG_rec3.MIN_DURATION
     , SDD_ACTORG_rec3.MIN_DURATION_UNIT
     , SDD_ACTORG_rec3.MAX_DURATION
     , SDD_ACTORG_rec3.MAX_DURATION_UNIT
     , SDD_ACTORG_rec3.TOTAL_DURATION
     , SDD_ACTORG_rec3.TOTAL_DURATION_UNIT
     , SDD_ACTORG_rec3.FREQUENCY
     , SDD_ACTORG_rec3.FREQUENCY_UNIT
     , SDD_ACTORG_rec3.TOTAL_COST_RATE
     , SDD_ACTORG_rec3.TOTAL_COST_RATE_UNIT
     , SDD_ACTORG_rec3.ADDITIONAL_COST_RATE
     , SDD_ACTORG_rec3.ADDITIONAL_COST_RATE_UNIT
     , SDD_ACTORG_rec3.QUALITY_PERCENT
     , SDD_ACTORG_rec3.VALUE_ADDED
     , SDD_ACTORG_rec3.EXECUTION_STRING
     , SDD_ACTORG_rec3.MULTIPLICITY
     , SDD_ACTORG_rec3.CPA_START_DATE
     , SDD_ACTORG_rec3.CPA_FINISH_DATE
     , SDD_ACTORG_rec3.CPA_RELATIVE_START_TIME
     , SDD_ACTORG_rec3.CPA_RELATIVE_FINISH_TIME
     , SDD_ACTORG_rec3.CRITICAL_PATH_FLAG
     , SDD_ACTORG_rec3.MESSAGING_PRIORITY
     , SDD_ACTORG_rec3.WF_ENABLED_FLAG
     , SDD_ACTORG_rec3.WF_IMPLEMENTATION_NAME
     , SDD_ACTORG_rec3.WF_TYPE
     , SDD_ACTORG_rec3.WF_RERUN_MODE
     , SDD_ACTORG_rec3.WF_SECURITY_LEVEL
     , SDD_ACTORG_rec3.WORKFLOW_ITEM_TYPE_REF
     , SDD_ACTORG_rec3.WORKFLOW_MESS_TYPE_REF
     , SDD_ACTORG_rec3.ACTIVITY_USAGE_ERROR_REF
    );
  jr_reg_ver.vercopy_dependencies(SDD_ACTORG_rec3.irid, SDD_ACTORG_rec3.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_ACUACR_rec4 in SDD_ACUACR_cur4 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_ACUACR
    values (
       SDD_ACUACR_rec4.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_ACUACR_rec4.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_ACUACR_rec4.TYPES
     , SDD_ACUACR_rec4.ELEMENT_TYPE_NAME
     , SDD_ACUACR_rec4.DATE_CREATED
     , SDD_ACUACR_rec4.CREATED_BY
     , SDD_ACUACR_rec4.DATE_CHANGED
     , SDD_ACUACR_rec4.CHANGED_BY
     , SDD_ACUACR_rec4.NOTM
     , SDD_ACUACR_rec4.ACTIVITY_USAGE_REF
     , SDD_ACUACR_rec4.ACTOR_REF
     , SDD_ACUACR_rec4.PRIMARY_FLAG
     , SDD_ACUACR_rec4.GROUP_FLAG
     , SDD_ACUACR_rec4.READ_FLAG
     , SDD_ACUACR_rec4.WRITE_FLAG
     , SDD_ACUACR_rec4.EXECUTE_FLAG
    );
  jr_reg_ver.vercopy_dependencies(SDD_ACUACR_rec4.irid, SDD_ACUACR_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;
  jr_reg_ver.vercopy_dependent_objects(SDD_ACT_ver.ivid, new_ivid);
  return new_ivid;
end SDD_ACT_ver;
/
create or replace function PK_SDD_ACT (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_ACT the_tab_new, SDD_ACT the_tab_old
  where  the_tab_new.ivid = PK_SDD_ACT.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_ACT.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_ACT;
/
create or replace function FK_ACT_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_ACT the_tab
  where  the_tab.ivid = FK_ACT_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_ACT_TO_FILES;
/
create or replace function FK_ACT_TO_FILES2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.EXECUTABLE_FILE_REF ref_value
  from   i$SDD_ACT the_tab
  where  the_tab.ivid = FK_ACT_TO_FILES2.object_ivid
  and    the_tab.EXECUTABLE_FILE_REF is not null
  and    not exists (
             select null
             from   SDD_FILES foreign_tab
             where  the_tab.EXECUTABLE_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_ACT_TO_FILES2;
/
create or replace function FK_ACT_TO_FILES3 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.MAPPING_FILE_REF ref_value
  from   i$SDD_ACT the_tab
  where  the_tab.ivid = FK_ACT_TO_FILES3.object_ivid
  and    the_tab.MAPPING_FILE_REF is not null
  and    not exists (
             select null
             from   SDD_FILES foreign_tab
             where  the_tab.MAPPING_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_ACT_TO_FILES3;
/
create or replace function FK_ACT_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_ACT the_tab
  where  the_tab.ivid = FK_ACT_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_ACT_TO_GEA;
/
create or replace function FK_ACT_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_ACT the_tab
  where  the_tab.ivid = FK_ACT_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_ACT_TO_MET;
/
create or replace function FK_ACT_TO_PCK (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.PACKAGE_REF ref_value
  from   i$SDD_ACT the_tab
  where  the_tab.ivid = FK_ACT_TO_PCK.object_ivid
  and    the_tab.PACKAGE_REF is not null
  and    not exists (
             select null
             from   SDD_FOLDERS foreign_tab
             where  the_tab.PACKAGE_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_ACT_TO_PCK;
/
create or replace function FK_ACT_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_ACT the_tab
  where  the_tab.ivid = FK_ACT_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_ACT_TO_RUL;
/
create or replace function FK_ACT_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_ACT the_tab
  where  the_tab.ivid = FK_ACT_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_ACT_TO_RUL2;
/
create or replace function FK_ACT_TO_USC (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.USE_CASE_REF ref_value
  from   i$SDD_ACT the_tab
  where  the_tab.ivid = FK_ACT_TO_USC.object_ivid
  and    the_tab.USE_CASE_REF is not null
  and    not exists (
             select null
             from   SDD_USC foreign_tab
             where  the_tab.USE_CASE_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_ACT_TO_USC;
/
create or replace function PK_SDD_ACTACT (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_ACTACT the_tab_new, SDD_ACTACT the_tab_old
  where  the_tab_new.ivid = PK_SDD_ACTACT.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_ACTACT.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_ACTACT;
/
create or replace function FK_ACTACT_TO_ACT2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.CHILD_ACTIVITY_REF ref_value
  from   i$SDD_ACTACT the_tab
  where  the_tab.ivid = FK_ACTACT_TO_ACT2.object_ivid
  and    the_tab.CHILD_ACTIVITY_REF is not null
  and    not exists (
             select null
             from   SDD_ACT foreign_tab
             where  the_tab.CHILD_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_ACTACT_TO_ACT2;
/
create or replace function PK_SDD_ACTE1 (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_ACTE1 the_tab_new, SDD_ACTE1 the_tab_old
  where  the_tab_new.ivid = PK_SDD_ACTE1.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_ACTE1.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_ACTE1;
/
create or replace function FK_ACTE1_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_ACTE1 the_tab
  where  the_tab.ivid = FK_ACTE1_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_ACTE1_TO_E1;
/
create or replace function PK_SDD_ACTORG (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_ACTORG the_tab_new, SDD_ACTORG the_tab_old
  where  the_tab_new.ivid = PK_SDD_ACTORG.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_ACTORG.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_ACTORG;
/
create or replace function FK_ACTORG_TO_ACTORG (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ACTIVITY_USAGE_REF ref_value
  from   i$SDD_ACTORG the_tab
  where  the_tab.ivid = FK_ACTORG_TO_ACTORG.object_ivid
  and    the_tab.ACTIVITY_USAGE_REF is not null
  and    not exists (
             select null
             from   SDD_ACTORG foreign_tab
             where  the_tab.ACTIVITY_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_ACTORG_TO_ACTORG;
/
create or replace function FK_ACTORG_TO_ACTORG2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ACTIVITY_USAGE_ERROR_REF ref_value
  from   i$SDD_ACTORG the_tab
  where  the_tab.ivid = FK_ACTORG_TO_ACTORG2.object_ivid
  and    the_tab.ACTIVITY_USAGE_ERROR_REF is not null
  and    not exists (
             select null
             from   SDD_ACTORG foreign_tab
             where  the_tab.ACTIVITY_USAGE_ERROR_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_ACTORG_TO_ACTORG2;
/
create or replace function FK_ACTORG_TO_ORG (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ORGANIZATION_UNIT_REF ref_value
  from   i$SDD_ACTORG the_tab
  where  the_tab.ivid = FK_ACTORG_TO_ORG.object_ivid
  and    the_tab.ORGANIZATION_UNIT_REF is not null
  and    not exists (
             select null
             from   SDD_ORG foreign_tab
             where  the_tab.ORGANIZATION_UNIT_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
                                   , 4837, action);
  end loop;
  return is_ok;
end FK_ACTORG_TO_ORG;
/
create or replace function FK_ACTORG_TO_WIT (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.WORKFLOW_ITEM_TYPE_REF ref_value
  from   i$SDD_ACTORG the_tab
  where  the_tab.ivid = FK_ACTORG_TO_WIT.object_ivid
  and    the_tab.WORKFLOW_ITEM_TYPE_REF is not null
  and    not exists (
             select null
             from   SDD_WIT foreign_tab
             where  the_tab.WORKFLOW_ITEM_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
                                   , 5150, action);
  end loop;
  return is_ok;
end FK_ACTORG_TO_WIT;
/
create or replace function FK_ACTORG_TO_WMT (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.WORKFLOW_MESS_TYPE_REF ref_value
  from   i$SDD_ACTORG the_tab
  where  the_tab.ivid = FK_ACTORG_TO_WMT.object_ivid
  and    the_tab.WORKFLOW_MESS_TYPE_REF is not null
  and    not exists (
             select null
             from   SDD_WMT foreign_tab
             where  the_tab.WORKFLOW_MESS_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
                                   , 5151, action);
  end loop;
  return is_ok;
end FK_ACTORG_TO_WMT;
/
create or replace function PK_SDD_ACUACR (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_ACUACR the_tab_new, SDD_ACUACR the_tab_old
  where  the_tab_new.ivid = PK_SDD_ACUACR.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_ACUACR.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_ACUACR;
/
create or replace function FK_ACUACR_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_ACUACR the_tab
  where  the_tab.ivid = FK_ACUACR_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_ACUACR_TO_ACR;
/
create or replace function PK_SDD_ADR (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_ADR the_tab_new, SDD_ADR the_tab_old
  where  the_tab_new.ivid = PK_SDD_ADR.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_ADR.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_ADR;
/
create or replace function FK_ADR_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_ADR the_tab
  where  the_tab.ivid = FK_ADR_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_ADR_TO_LAN;
/
create or replace function FK_ADR_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_ADR the_tab
  where  the_tab.ivid = FK_ADR_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_ADR_TO_MET;
/
create or replace function FK_AEU_TO_AEN_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_AEU child_tab, i$SDD_AEN parent_tab
  where  parent_tab.parent_ivid=FK_AEU_TO_AEN_cmd.ivid
  and    child_tab.ASSOCIATION_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_AEU child_tab
          ,i$SDD_AEN parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_AEU_TO_AEN_cmd.ivid
       and child_tab.ASSOCIATION_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_AEU_TO_AEN_cmd;
/
create or replace function FK_AEU_TO_AEN_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_AEU child_tab
  where  child_tab.ASSOCIATION_END_REF=FK_AEU_TO_AEN_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_AEU child_tab, i$sdd_object_versions o
    where  child_tab.ASSOCIATION_END_REF=FK_AEU_TO_AEN_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_AEU_TO_AEN_d;
/
create or replace function FK_CMA_TO_AEN_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_CMA child_tab, i$SDD_AEN parent_tab
  where  parent_tab.parent_ivid=FK_CMA_TO_AEN_cmd.ivid
  and    child_tab.ASSOCIATION_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_CMA child_tab
          ,i$SDD_AEN parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_CMA_TO_AEN_cmd.ivid
       and child_tab.ASSOCIATION_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_CMA_TO_AEN_cmd;
/
create or replace function FK_CMA_TO_AEN_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_CMA child_tab
  where  child_tab.ASSOCIATION_END_REF=FK_CMA_TO_AEN_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_CMA child_tab, i$sdd_object_versions o
    where  child_tab.ASSOCIATION_END_REF=FK_CMA_TO_AEN_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_CMA_TO_AEN_d;
/
create or replace function PK_SDD_AEN (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_AEN the_tab_new, SDD_AEN the_tab_old
  where  the_tab_new.ivid = PK_SDD_AEN.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_AEN.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_AEN;
/
create or replace function FK_AEN_TO_CLA (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.CLASSIFIER_REF ref_value
  from   i$SDD_AEN the_tab
  where  the_tab.ivid = FK_AEN_TO_CLA.object_ivid
  and    the_tab.CLASSIFIER_REF is not null
  and    not exists (
             select null
             from   SDD_CLA foreign_tab
             where  the_tab.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_AEN_TO_CLA;
/
create or replace function FK_AEN_TO_EOC (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ENTITY_OBJECT_REF ref_value
  from   i$SDD_AEN the_tab
  where  the_tab.ivid = FK_AEN_TO_EOC.object_ivid
  and    the_tab.ENTITY_OBJECT_REF is not null
  and    not exists (
             select null
             from   SDD_CLA foreign_tab
             where  the_tab.ENTITY_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_AEN_TO_EOC;
/
create or replace function FK_AEN_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_AEN the_tab
  where  the_tab.ivid = FK_AEN_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_AEN_TO_GEC;
/
create or replace function FK_AEN_TO_INC (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.INTERFACE_CLASSIFIER_REF ref_value
  from   i$SDD_AEN the_tab
  where  the_tab.ivid = FK_AEN_TO_INC.object_ivid
  and    the_tab.INTERFACE_CLASSIFIER_REF is not null
  and    not exists (
             select null
             from   SDD_CLA foreign_tab
             where  the_tab.INTERFACE_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_AEN_TO_INC;
/
create or replace function FK_AEN_TO_UNR (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.UNIQUENESS_RULE_REF ref_value
  from   i$SDD_AEN the_tab
  where  the_tab.ivid = FK_AEN_TO_UNR.object_ivid
  and    the_tab.UNIQUENESS_RULE_REF is not null
  and    not exists (
             select null
             from   SDD_CRU foreign_tab
             where  the_tab.UNIQUENESS_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
                                   , 5087, action);
  end loop;
  return is_ok;
end FK_AEN_TO_UNR;
/
create or replace function PK_SDD_AENEAT (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_AENEAT the_tab_new, SDD_AENEAT the_tab_old
  where  the_tab_new.ivid = PK_SDD_AENEAT.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_AENEAT.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_AENEAT;
/
create or replace function FK_AENEAT_TO_EAT (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.EO_ATTRIBUTE_FROM_REF ref_value
  from   i$SDD_AENEAT the_tab
  where  the_tab.ivid = FK_AENEAT_TO_EAT.object_ivid
  and    the_tab.EO_ATTRIBUTE_FROM_REF is not null
  and    not exists (
             select null
             from   SDD_CAT foreign_tab
             where  the_tab.EO_ATTRIBUTE_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
                                   , 5066, action);
  end loop;
  return is_ok;
end FK_AENEAT_TO_EAT;
/
create or replace function FK_AENEAT_TO_EAT2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.EO_ATTRIBUTE_TO_REF ref_value
  from   i$SDD_AENEAT the_tab
  where  the_tab.ivid = FK_AENEAT_TO_EAT2.object_ivid
  and    the_tab.EO_ATTRIBUTE_TO_REF is not null
  and    not exists (
             select null
             from   SDD_CAT foreign_tab
             where  the_tab.EO_ATTRIBUTE_TO_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_AENEAT_TO_EAT2;
/
create or replace function FK_VLE_TO_AEU_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_VLE child_tab, i$SDD_AEU parent_tab
  where  parent_tab.parent_ivid=FK_VLE_TO_AEU_cmd.ivid
  and    child_tab.ASSOC_END_USAGE_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_VLE child_tab
          ,i$SDD_AEU parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_VLE_TO_AEU_cmd.ivid
       and child_tab.ASSOC_END_USAGE_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_VLE_TO_AEU_cmd;
/
create or replace function FK_VLE_TO_AEU_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_VLE child_tab
  where  child_tab.ASSOC_END_USAGE_REF=FK_VLE_TO_AEU_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_VLE child_tab, i$sdd_object_versions o
    where  child_tab.ASSOC_END_USAGE_REF=FK_VLE_TO_AEU_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_VLE_TO_AEU_d;
/
create or replace function PK_SDD_AEU (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_AEU the_tab_new, SDD_AEU the_tab_old
  where  the_tab_new.ivid = PK_SDD_AEU.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_AEU.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_AEU;
/
create or replace function FK_AEU_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_AEU the_tab
  where  the_tab.ivid = FK_AEU_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_AEU_TO_AEN;
/
create or replace function PK_SDD_AMCAMC (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_AMCAMC the_tab_new, SDD_AMCAMC the_tab_old
  where  the_tab_new.ivid = PK_SDD_AMCAMC.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_AMCAMC.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_AMCAMC;
/
create or replace function FK_AMCAMC_TO_AMC2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.CHILD_APP_MODULE_REF ref_value
  from   i$SDD_AMCAMC the_tab
  where  the_tab.ivid = FK_AMCAMC_TO_AMC2.object_ivid
  and    the_tab.CHILD_APP_MODULE_REF is not null
  and    not exists (
             select null
             from   SDD_CLA foreign_tab
             where  the_tab.CHILD_APP_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
                                   , 4841, action);
  end loop;
  return is_ok;
end FK_AMCAMC_TO_AMC2;
/
create or replace function PK_SDD_AMCBOB (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_AMCBOB the_tab_new, SDD_AMCBOB the_tab_old
  where  the_tab_new.ivid = PK_SDD_AMCBOB.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_AMCBOB.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_AMCBOB;
/
create or replace function FK_AMCBOB_TO_BOB (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.BUSINESS_OBJECT_REF ref_value
  from   i$SDD_AMCBOB the_tab
  where  the_tab.ivid = FK_AMCBOB_TO_BOB.object_ivid
  and    the_tab.BUSINESS_OBJECT_REF is not null
  and    not exists (
             select null
             from   SDD_BOB foreign_tab
             where  the_tab.BUSINESS_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
                                   , 5076, action);
  end loop;
  return is_ok;
end FK_AMCBOB_TO_BOB;
/
create or replace function PK_SDD_AMCPRJ (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_AMCPRJ the_tab_new, SDD_AMCPRJ the_tab_old
  where  the_tab_new.ivid = PK_SDD_AMCPRJ.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_AMCPRJ.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_AMCPRJ;
/
create or replace function FK_AMCPRJ_TO_PRJ (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.PROJECT_REF ref_value
  from   i$SDD_AMCPRJ the_tab
  where  the_tab.ivid = FK_AMCPRJ_TO_PRJ.object_ivid
  and    the_tab.PROJECT_REF is not null
  and    not exists (
             select null
             from   SDD_FOLDERS foreign_tab
             where  the_tab.PROJECT_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_AMCPRJ_TO_PRJ;
/
create or replace function FK_PVL_TO_ARG2_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_PVL child_tab, i$SDD_ARG parent_tab
  where  parent_tab.parent_ivid=FK_PVL_TO_ARG2_cmd.ivid
  and    child_tab.CALLED_ARGUMENT_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_PVL child_tab
          ,i$SDD_ARG parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_PVL_TO_ARG2_cmd.ivid
       and child_tab.CALLED_ARGUMENT_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_PVL_TO_ARG2_cmd;
/
create or replace function FK_PVL_TO_ARG2_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_PVL child_tab
  where  child_tab.CALLED_ARGUMENT_REF=FK_PVL_TO_ARG2_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_PVL child_tab, i$sdd_object_versions o
    where  child_tab.CALLED_ARGUMENT_REF=FK_PVL_TO_ARG2_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_PVL_TO_ARG2_d;
/
create or replace function PK_SDD_ARG (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_ARG the_tab_new, SDD_ARG the_tab_old
  where  the_tab_new.ivid = PK_SDD_ARG.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_ARG.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_ARG;
/
create or replace function FK_ARG_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_ARG the_tab
  where  the_tab.ivid = FK_ARG_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_ARG_TO_COL;
/
create or replace function FK_ARG_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_ARG the_tab
  where  the_tab.ivid = FK_ARG_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_ARG_TO_DAT;
/
create or replace function FK_ARG_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_ARG the_tab
  where  the_tab.ivid = FK_ARG_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_ARG_TO_DOM;
/
create or replace function FK_ARG_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_ARG the_tab
  where  the_tab.ivid = FK_ARG_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_ARG_TO_GEM;
/
create or replace function FK_ARG_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_ARG the_tab
  where  the_tab.ivid = FK_ARG_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_ARG_TO_ORT;
/
create or replace function FK_ARG_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_ARG the_tab
  where  the_tab.ivid = FK_ARG_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_ARG_TO_PLM;
/
create or replace function FK_ARG_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_ARG the_tab
  where  the_tab.ivid = FK_ARG_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_ARG_TO_TBL;
/
create or replace function PK_SDD_ARGITE (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_ARGITE the_tab_new, SDD_ARGITE the_tab_old
  where  the_tab_new.ivid = PK_SDD_ARGITE.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_ARGITE.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_ARGITE;
/
create or replace function FK_ARGITE_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_ARGITE the_tab
  where  the_tab.ivid = FK_ARGITE_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_ARGITE_TO_ITE;
/
create or replace function SDD_ASS_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_ASS_cur is
    select *
    from   i$SDD_ASS the_tab
    where  the_tab.irid=SDD_ASS_ver.irid
    and    the_tab.ivid=SDD_ASS_ver.ivid;
  SDD_ASS_rec SDD_ASS_cur%ROWTYPE;
  cursor SDD_AEN_cur1 is
    select *
    from i$SDD_AEN the_tab
    where the_tab.parent_ivid=SDD_ASS_ver.ivid;
  cursor SDD_AENEAT_cur2 is
    select *
    from i$SDD_AENEAT the_tab
    where the_tab.parent_ivid=SDD_ASS_ver.ivid;
  cursor SDD_ASSASS_cur3 is
    select *
    from i$SDD_ASSASS the_tab
    where the_tab.parent_ivid=SDD_ASS_ver.ivid;
  cursor SDD_CATAEN_cur4 is
    select *
    from i$SDD_CATAEN the_tab
    where the_tab.parent_ivid=SDD_ASS_ver.ivid;
  cursor SDD_FILPAC_cur5 is
    select *
    from i$SDD_FILPAC the_tab
    where the_tab.parent_ivid=SDD_ASS_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_ASS_cur;
  fetch SDD_ASS_cur into SDD_ASS_rec;
  close SDD_ASS_cur;
  insert into i$SDD_ASS
  values (
    SDD_ASS_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_ASS_rec.TYPES
   ,SDD_ASS_rec.ELEMENT_TYPE_NAME
   ,SDD_ASS_rec.DATE_CREATED
   ,SDD_ASS_rec.CREATED_BY
   ,SDD_ASS_rec.DATE_CHANGED
   ,SDD_ASS_rec.CHANGED_BY
   ,SDD_ASS_rec.NOTM
   ,SDD_ASS_rec.NAME
   ,SDD_ASS_rec.VERB_NAME
   ,SDD_ASS_rec.ANALYSIS_TYPE_FLAG
   ,SDD_ASS_rec.DERIVED_FLAG
   ,SDD_ASS_rec.ICON_FILE_REF
   ,SDD_ASS_rec.BUSINESS_OBJECT_REF
   ,SDD_ASS_rec.ASSOCIATION_REF
   ,SDD_ASS_rec.IMPLEMENT_AS_REF_FLAG
   ,SDD_ASS_rec.ENTITY_OBJECT_REF
   ,SDD_ASS_rec.GENERIC_CLASS_REF
   ,SDD_ASS_rec.ASSOCIATION_FOR
  );
  jr_reg_ver.vercopy_dependencies(SDD_ASS_ver.irid, SDD_ASS_ver.ivid, new_ivid, null, copy_dependencies);
  for SDD_AEN_rec1 in SDD_AEN_cur1 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_AEN
    values (
       SDD_AEN_rec1.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_AEN_rec1.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_AEN_rec1.TYPES
     , SDD_AEN_rec1.ELEMENT_TYPE_NAME
     , SDD_AEN_rec1.DATE_CREATED
     , SDD_AEN_rec1.CREATED_BY
     , SDD_AEN_rec1.DATE_CHANGED
     , SDD_AEN_rec1.CHANGED_BY
     , SDD_AEN_rec1.NOTM
     , SDD_AEN_rec1.ASSOCIATION_REF
     , SDD_AEN_rec1.NAME
     , SDD_AEN_rec1.SEQUENCE
     , SDD_AEN_rec1.VISIBILITY
     , SDD_AEN_rec1.SCOPE
     , SDD_AEN_rec1.SERIALIZABLE_FLAG
     , SDD_AEN_rec1.ENTITY_OBJECT_REF
     , SDD_AEN_rec1.VOLATILE_FLAG
     , SDD_AEN_rec1.GENERIC_CLASS_REF
     , SDD_AEN_rec1.INTERFACE_CLASSIFIER_REF
     , SDD_AEN_rec1.UNIQUENESS_RULE_REF
     , SDD_AEN_rec1.AGGREGATION
     , SDD_AEN_rec1.NAVIGATION_TARGET_FLAG
     , SDD_AEN_rec1.CHANGE_RESTRICTION
     , SDD_AEN_rec1.MINIMUM_MULTIPLICITY
     , SDD_AEN_rec1.MAXIMUM_MULTIPLICITY
     , SDD_AEN_rec1.ORDERED_FLAG
     , SDD_AEN_rec1.CLASSIFIER_REF
     , SDD_AEN_rec1.GENERATE_CLASS_MEMBER_FLAG
     , SDD_AEN_rec1.PERSISTENT_FLAG
     , SDD_AEN_rec1.SORT_ORDER_SEQUENCE
     , SDD_AEN_rec1.SORT_ORDER_DIRECTION
     , SDD_AEN_rec1.COR_DEPTH_LEVEL
     , SDD_AEN_rec1.DEFAULT_COLUMN_NAME
     , SDD_AEN_rec1.DEFAULT_DB_COLLECTION_NAME
     , SDD_AEN_rec1.DEFAULT_DB_COLLECTION_TYPE
     , SDD_AEN_rec1.DB_COLLECTION_AS_REFS_FLAG
     , SDD_AEN_rec1.STORE_REF_WITH_ROWID_FLAG
     , SDD_AEN_rec1.ASSOCIATION_ROLE_IN
    );
  jr_reg_ver.vercopy_dependencies(SDD_AEN_rec1.irid, SDD_AEN_rec1.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_AENEAT_rec2 in SDD_AENEAT_cur2 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_AENEAT
    values (
       SDD_AENEAT_rec2.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_AENEAT_rec2.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_AENEAT_rec2.TYPES
     , SDD_AENEAT_rec2.ELEMENT_TYPE_NAME
     , SDD_AENEAT_rec2.DATE_CREATED
     , SDD_AENEAT_rec2.CREATED_BY
     , SDD_AENEAT_rec2.DATE_CHANGED
     , SDD_AENEAT_rec2.CHANGED_BY
     , SDD_AENEAT_rec2.NOTM
     , SDD_AENEAT_rec2.ASSOCIATION_END_REF
     , SDD_AENEAT_rec2.EO_ATTRIBUTE_FROM_REF
     , SDD_AENEAT_rec2.EO_ATTRIBUTE_TO_REF
     , SDD_AENEAT_rec2.SEQUENCE
    );
  jr_reg_ver.vercopy_dependencies(SDD_AENEAT_rec2.irid, SDD_AENEAT_rec2.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_ASSASS_rec3 in SDD_ASSASS_cur3 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_ASSASS
    values (
       SDD_ASSASS_rec3.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_ASSASS_rec3.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_ASSASS_rec3.TYPES
     , SDD_ASSASS_rec3.ELEMENT_TYPE_NAME
     , SDD_ASSASS_rec3.DATE_CREATED
     , SDD_ASSASS_rec3.CREATED_BY
     , SDD_ASSASS_rec3.DATE_CHANGED
     , SDD_ASSASS_rec3.CHANGED_BY
     , SDD_ASSASS_rec3.NOTM
     , SDD_ASSASS_rec3.PART_OF_ASSOC_END_REF
     , SDD_ASSASS_rec3.USE_OF_ASSOC_END_REF
    );
  jr_reg_ver.vercopy_dependencies(SDD_ASSASS_rec3.irid, SDD_ASSASS_rec3.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_CATAEN_rec4 in SDD_CATAEN_cur4 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_CATAEN
    values (
       SDD_CATAEN_rec4.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_CATAEN_rec4.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_CATAEN_rec4.TYPES
     , SDD_CATAEN_rec4.ELEMENT_TYPE_NAME
     , SDD_CATAEN_rec4.DATE_CREATED
     , SDD_CATAEN_rec4.CREATED_BY
     , SDD_CATAEN_rec4.DATE_CHANGED
     , SDD_CATAEN_rec4.CHANGED_BY
     , SDD_CATAEN_rec4.NOTM
     , SDD_CATAEN_rec4.ASSOCIATION_END_REF
     , SDD_CATAEN_rec4.EO_ATTRIBUTE_REF
     , SDD_CATAEN_rec4.GENERAL_ATTRIBUTE_REF
     , SDD_CATAEN_rec4.SEQUENCE
     , SDD_CATAEN_rec4.QUALIFIED_BY
    );
  jr_reg_ver.vercopy_dependencies(SDD_CATAEN_rec4.irid, SDD_CATAEN_rec4.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_FILPAC_rec5 in SDD_FILPAC_cur5 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_FILPAC
    values (
       SDD_FILPAC_rec5.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_FILPAC_rec5.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_FILPAC_rec5.TYPES
     , SDD_FILPAC_rec5.ELEMENT_TYPE_NAME
     , SDD_FILPAC_rec5.DATE_CREATED
     , SDD_FILPAC_rec5.CREATED_BY
     , SDD_FILPAC_rec5.DATE_CHANGED
     , SDD_FILPAC_rec5.CHANGED_BY
     , SDD_FILPAC_rec5.NOTM
     , SDD_FILPAC_rec5.ASSOCIATION_REF
     , SDD_FILPAC_rec5.CLASSIFIER_REF
     , SDD_FILPAC_rec5.DIAGRAM_REF
     , SDD_FILPAC_rec5.VIEW_LINK_REF
     , SDD_FILPAC_rec5.PRIMARY_ACCESS_FILE_REF
     , SDD_FILPAC_rec5.TYPE
     , SDD_FILPAC_rec5.OUT_OF_SYNC_FLAG
     , SDD_FILPAC_rec5.VERSION
     , SDD_FILPAC_rec5.OS_TIMESTAMP
     , SDD_FILPAC_rec5.FILE_USAGE_FOR
     , SDD_FILPAC_rec5.CRC
    );
  jr_reg_ver.vercopy_dependencies(SDD_FILPAC_rec5.irid, SDD_FILPAC_rec5.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  jr_reg_ver.vercopy_dependent_objects(SDD_ASS_ver.ivid, new_ivid);
  return new_ivid;
end SDD_ASS_ver;
/
create or replace function PK_SDD_ASS (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_ASS the_tab_new, SDD_ASS the_tab_old
  where  the_tab_new.ivid = PK_SDD_ASS.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_ASS.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_ASS;
/
create or replace function FK_ASS_TO_ASS (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ASSOCIATION_REF ref_value
  from   i$SDD_ASS the_tab
  where  the_tab.ivid = FK_ASS_TO_ASS.object_ivid
  and    the_tab.ASSOCIATION_REF is not null
  and    not exists (
             select null
             from   SDD_ASS foreign_tab
             where  the_tab.ASSOCIATION_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
                                   , 5086, action);
  end loop;
  return is_ok;
end FK_ASS_TO_ASS;
/
create or replace function FK_ASS_TO_BOB (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.BUSINESS_OBJECT_REF ref_value
  from   i$SDD_ASS the_tab
  where  the_tab.ivid = FK_ASS_TO_BOB.object_ivid
  and    the_tab.BUSINESS_OBJECT_REF is not null
  and    not exists (
             select null
             from   SDD_BOB foreign_tab
             where  the_tab.BUSINESS_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
                                   , 5076, action);
  end loop;
  return is_ok;
end FK_ASS_TO_BOB;
/
create or replace function FK_ASS_TO_EOC (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ENTITY_OBJECT_REF ref_value
  from   i$SDD_ASS the_tab
  where  the_tab.ivid = FK_ASS_TO_EOC.object_ivid
  and    the_tab.ENTITY_OBJECT_REF is not null
  and    not exists (
             select null
             from   SDD_CLA foreign_tab
             where  the_tab.ENTITY_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_ASS_TO_EOC;
/
create or replace function FK_ASS_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_ASS the_tab
  where  the_tab.ivid = FK_ASS_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_ASS_TO_FILES;
/
create or replace function FK_ASS_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_ASS the_tab
  where  the_tab.ivid = FK_ASS_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_ASS_TO_GEC;
/
create or replace function PK_SDD_ASSASS (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_ASSASS the_tab_new, SDD_ASSASS the_tab_old
  where  the_tab_new.ivid = PK_SDD_ASSASS.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_ASSASS.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_ASSASS;
/
create or replace function FK_ASSASS_TO_AEN2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.USE_OF_ASSOC_END_REF ref_value
  from   i$SDD_ASSASS the_tab
  where  the_tab.ivid = FK_ASSASS_TO_AEN2.object_ivid
  and    the_tab.USE_OF_ASSOC_END_REF is not null
  and    not exists (
             select null
             from   SDD_AEN foreign_tab
             where  the_tab.USE_OF_ASSOC_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_ASSASS_TO_AEN2;
/
create or replace function FK_ENTUIE_TO_ATT_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_ATT parent_tab
  where  parent_tab.parent_ivid=FK_ENTUIE_TO_ATT_cmd.ivid
  and    child_tab.ATTRIBUTE_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_ATT parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_ENTUIE_TO_ATT_cmd.ivid
       and child_tab.ATTRIBUTE_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_ATT_cmd;
/
create or replace function FK_ENTUIE_TO_ATT_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.ATTRIBUTE_REF=FK_ENTUIE_TO_ATT_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.ATTRIBUTE_REF=FK_ENTUIE_TO_ATT_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_ATT_d;
/
create or replace function FK_EVT_TO_ATT_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_EVT child_tab, i$SDD_ATT parent_tab
  where  parent_tab.parent_ivid=FK_EVT_TO_ATT_cmd.ivid
  and    child_tab.ATTRIBUTE_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_EVT child_tab
          ,i$SDD_ATT parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_EVT_TO_ATT_cmd.ivid
       and child_tab.ATTRIBUTE_REF=parent_tab.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(ref.par_ivid,ref.par_type,ref.child_irid,ref.child_type,'DEL');
  end loop;
  return is_ok;
end FK_EVT_TO_ATT_cmd;
/
create or replace function FK_EVT_TO_ATT_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_EVT child_tab
  where  child_tab.ATTRIBUTE_REF=FK_EVT_TO_ATT_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_EVT child_tab, i$sdd_object_versions o
    where  child_tab.ATTRIBUTE_REF=FK_EVT_TO_ATT_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_EVT_TO_ATT_d;
/
create or replace function PK_SDD_ATT (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_ATT the_tab_new, SDD_ATT the_tab_old
  where  the_tab_new.ivid = PK_SDD_ATT.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_ATT.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_ATT;
/
create or replace function FK_ATT_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_ATT the_tab
  where  the_tab.ivid = FK_ATT_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_ATT_TO_DOM;
/
create or replace function PK_SDD_ATV (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_ATV the_tab_new, SDD_ATV the_tab_old
  where  the_tab_new.ivid = PK_SDD_ATV.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_ATV.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_ATV;
/
create or replace function SDD_BAT_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_BAT_cur is
    select *
    from   i$SDD_BAT the_tab
    where  the_tab.irid=SDD_BAT_ver.irid
    and    the_tab.ivid=SDD_BAT_ver.ivid;
  SDD_BAT_rec SDD_BAT_cur%ROWTYPE;
  cursor SDD_BLI_cur1 is
    select *
    from i$SDD_BLI the_tab
    where the_tab.parent_ivid=SDD_BAT_ver.ivid;
  cursor SDD_COB_cur2 is
    select *
    from i$SDD_COB the_tab
    where the_tab.parent_ivid=SDD_BAT_ver.ivid;
  cursor SDD_SOU_cur3 is
    select *
    from i$SDD_SOU the_tab
    where the_tab.parent_ivid=SDD_BAT_ver.ivid;
  cursor SDD_BRU_cur4 is
    select *
    from i$SDD_BRU the_tab
    where the_tab.parent_ivid=SDD_BAT_ver.ivid;
  cursor SDD_BRUBLI_cur5 is
    select *
    from i$SDD_BRUBLI the_tab
    where the_tab.parent_ivid=SDD_BAT_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_BAT_cur;
  fetch SDD_BAT_cur into SDD_BAT_rec;
  close SDD_BAT_cur;
  insert into i$SDD_BAT
  values (
    SDD_BAT_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_BAT_rec.TYPES
   ,SDD_BAT_rec.ELEMENT_TYPE_NAME
   ,SDD_BAT_rec.DATE_CREATED
   ,SDD_BAT_rec.CREATED_BY
   ,SDD_BAT_rec.DATE_CHANGED
   ,SDD_BAT_rec.CHANGED_BY
   ,SDD_BAT_rec.NOTM
   ,SDD_BAT_rec.NAME
   ,SDD_BAT_rec.PURPOSE
   ,SDD_BAT_rec.PERSISTENT_FLAG
   ,SDD_BAT_rec.USRX0
   ,SDD_BAT_rec.USRX1
   ,SDD_BAT_rec.USRX2
   ,SDD_BAT_rec.USRX3
   ,SDD_BAT_rec.USRX4
   ,SDD_BAT_rec.USRX5
   ,SDD_BAT_rec.USRX6
   ,SDD_BAT_rec.USRX7
   ,SDD_BAT_rec.USRX8
   ,SDD_BAT_rec.USRX9
   ,SDD_BAT_rec.USRX10
   ,SDD_BAT_rec.USRX11
   ,SDD_BAT_rec.USRX12
   ,SDD_BAT_rec.USRX13
   ,SDD_BAT_rec.USRX14
   ,SDD_BAT_rec.USRX15
   ,SDD_BAT_rec.USRX16
   ,SDD_BAT_rec.USRX17
   ,SDD_BAT_rec.USRX18
   ,SDD_BAT_rec.USRX19
  );
  jr_reg_ver.vercopy_dependencies(SDD_BAT_ver.irid, SDD_BAT_ver.ivid, new_ivid, null, copy_dependencies);
  for SDD_BLI_rec1 in SDD_BLI_cur1 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_BLI
    values (
       SDD_BLI_rec1.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_BLI_rec1.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_BLI_rec1.TYPES
     , SDD_BLI_rec1.ELEMENT_TYPE_NAME
     , SDD_BLI_rec1.DATE_CREATED
     , SDD_BLI_rec1.CREATED_BY
     , SDD_BLI_rec1.DATE_CHANGED
     , SDD_BLI_rec1.CHANGED_BY
     , SDD_BLI_rec1.NOTM
     , SDD_BLI_rec1.BATCH_REF
     , SDD_BLI_rec1.SEQUENCE
     , SDD_BLI_rec1.BATCHLINE_MODE
     , SDD_BLI_rec1.TYPE
     , SDD_BLI_rec1.GENERAL_MODULE_REF
     , SDD_BLI_rec1.DATABASE_USER_REF
     , SDD_BLI_rec1.SOURCE_PATHNAME
     , SDD_BLI_rec1.SEARCH_PATH
     , SDD_BLI_rec1.STOP_ON_ERROR_FLAG
     , SDD_BLI_rec1.USRX0
     , SDD_BLI_rec1.USRX1
     , SDD_BLI_rec1.USRX2
     , SDD_BLI_rec1.USRX3
     , SDD_BLI_rec1.USRX4
     , SDD_BLI_rec1.USRX5
     , SDD_BLI_rec1.USRX6
     , SDD_BLI_rec1.USRX7
     , SDD_BLI_rec1.USRX8
     , SDD_BLI_rec1.USRX9
     , SDD_BLI_rec1.USRX10
     , SDD_BLI_rec1.USRX11
     , SDD_BLI_rec1.USRX12
     , SDD_BLI_rec1.USRX13
     , SDD_BLI_rec1.USRX14
     , SDD_BLI_rec1.USRX15
     , SDD_BLI_rec1.USRX16
     , SDD_BLI_rec1.USRX17
     , SDD_BLI_rec1.USRX18
     , SDD_BLI_rec1.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_BLI_rec1.irid, SDD_BLI_rec1.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_COB_rec2 in SDD_COB_cur2 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_COB
    values (
       SDD_COB_rec2.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_COB_rec2.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_COB_rec2.TYPES
     , SDD_COB_rec2.ELEMENT_TYPE_NAME
     , SDD_COB_rec2.DATE_CREATED
     , SDD_COB_rec2.CREATED_BY
     , SDD_COB_rec2.DATE_CHANGED
     , SDD_COB_rec2.CHANGED_BY
     , SDD_COB_rec2.NOTM
     , SDD_COB_rec2.BATCHLINE_REF
     , SDD_COB_rec2.TYPE
     , SDD_COB_rec2.NAME
     , SDD_COB_rec2.VB_FORM_NAME
     , SDD_COB_rec2.VB_MODULE_NAME
     , SDD_COB_rec2.USRX0
     , SDD_COB_rec2.USRX1
     , SDD_COB_rec2.USRX2
     , SDD_COB_rec2.USRX3
     , SDD_COB_rec2.USRX4
     , SDD_COB_rec2.USRX5
     , SDD_COB_rec2.USRX6
     , SDD_COB_rec2.USRX7
     , SDD_COB_rec2.USRX8
     , SDD_COB_rec2.USRX9
     , SDD_COB_rec2.USRX10
     , SDD_COB_rec2.USRX11
     , SDD_COB_rec2.USRX12
     , SDD_COB_rec2.USRX13
     , SDD_COB_rec2.USRX14
     , SDD_COB_rec2.USRX15
     , SDD_COB_rec2.USRX16
     , SDD_COB_rec2.USRX17
     , SDD_COB_rec2.USRX18
     , SDD_COB_rec2.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_COB_rec2.irid, SDD_COB_rec2.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_SOU_rec3 in SDD_SOU_cur3 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_SOU
    values (
       SDD_SOU_rec3.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_SOU_rec3.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_SOU_rec3.TYPES
     , SDD_SOU_rec3.ELEMENT_TYPE_NAME
     , SDD_SOU_rec3.DATE_CREATED
     , SDD_SOU_rec3.CREATED_BY
     , SDD_SOU_rec3.DATE_CHANGED
     , SDD_SOU_rec3.CHANGED_BY
     , SDD_SOU_rec3.NOTM
     , SDD_SOU_rec3.BATCHLINE_REF
     , SDD_SOU_rec3.CIELEMENT_REF
     , SDD_SOU_rec3.ELEMENT_TYPE_FOR
     , SDD_SOU_rec3.USRX0
     , SDD_SOU_rec3.USRX1
     , SDD_SOU_rec3.USRX2
     , SDD_SOU_rec3.USRX3
     , SDD_SOU_rec3.USRX4
     , SDD_SOU_rec3.USRX5
     , SDD_SOU_rec3.USRX6
     , SDD_SOU_rec3.USRX7
     , SDD_SOU_rec3.USRX8
     , SDD_SOU_rec3.USRX9
     , SDD_SOU_rec3.USRX10
     , SDD_SOU_rec3.USRX11
     , SDD_SOU_rec3.USRX12
     , SDD_SOU_rec3.USRX13
     , SDD_SOU_rec3.USRX14
     , SDD_SOU_rec3.USRX15
     , SDD_SOU_rec3.USRX16
     , SDD_SOU_rec3.USRX17
     , SDD_SOU_rec3.USRX18
     , SDD_SOU_rec3.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_SOU_rec3.irid, SDD_SOU_rec3.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_BRU_rec4 in SDD_BRU_cur4 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_BRU
    values (
       SDD_BRU_rec4.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_BRU_rec4.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_BRU_rec4.TYPES
     , SDD_BRU_rec4.ELEMENT_TYPE_NAME
     , SDD_BRU_rec4.DATE_CREATED
     , SDD_BRU_rec4.CREATED_BY
     , SDD_BRU_rec4.DATE_CHANGED
     , SDD_BRU_rec4.CHANGED_BY
     , SDD_BRU_rec4.NOTM
     , SDD_BRU_rec4.BATCH_REF
     , SDD_BRU_rec4.BATCH_LABEL
     , SDD_BRU_rec4.STATUS
     , SDD_BRU_rec4.DATE_TIME_STARTED
     , SDD_BRU_rec4.DATE_TIME_COMPLETED
     , SDD_BRU_rec4.USRX0
     , SDD_BRU_rec4.USRX1
     , SDD_BRU_rec4.USRX2
     , SDD_BRU_rec4.USRX3
     , SDD_BRU_rec4.USRX4
     , SDD_BRU_rec4.USRX5
     , SDD_BRU_rec4.USRX6
     , SDD_BRU_rec4.USRX7
     , SDD_BRU_rec4.USRX8
     , SDD_BRU_rec4.USRX9
     , SDD_BRU_rec4.USRX10
     , SDD_BRU_rec4.USRX11
     , SDD_BRU_rec4.USRX12
     , SDD_BRU_rec4.USRX13
     , SDD_BRU_rec4.USRX14
     , SDD_BRU_rec4.USRX15
     , SDD_BRU_rec4.USRX16
     , SDD_BRU_rec4.USRX17
     , SDD_BRU_rec4.USRX18
     , SDD_BRU_rec4.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_BRU_rec4.irid, SDD_BRU_rec4.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_BRUBLI_rec5 in SDD_BRUBLI_cur5 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_BRUBLI
    values (
       SDD_BRUBLI_rec5.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_BRUBLI_rec5.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_BRUBLI_rec5.TYPES
     , SDD_BRUBLI_rec5.ELEMENT_TYPE_NAME
     , SDD_BRUBLI_rec5.DATE_CREATED
     , SDD_BRUBLI_rec5.CREATED_BY
     , SDD_BRUBLI_rec5.DATE_CHANGED
     , SDD_BRUBLI_rec5.CHANGED_BY
     , SDD_BRUBLI_rec5.NOTM
     , SDD_BRUBLI_rec5.BATCH_RUN_REF
     , SDD_BRUBLI_rec5.BATCHLINE_REF
     , SDD_BRUBLI_rec5.STATUS
     , SDD_BRUBLI_rec5.DATE_TIME_STARTED
     , SDD_BRUBLI_rec5.DATE_TIME_COMPLETED
     , SDD_BRUBLI_rec5.USRX0
     , SDD_BRUBLI_rec5.USRX1
     , SDD_BRUBLI_rec5.USRX2
     , SDD_BRUBLI_rec5.USRX3
     , SDD_BRUBLI_rec5.USRX4
     , SDD_BRUBLI_rec5.USRX5
     , SDD_BRUBLI_rec5.USRX6
     , SDD_BRUBLI_rec5.USRX7
     , SDD_BRUBLI_rec5.USRX8
     , SDD_BRUBLI_rec5.USRX9
     , SDD_BRUBLI_rec5.USRX10
     , SDD_BRUBLI_rec5.USRX11
     , SDD_BRUBLI_rec5.USRX12
     , SDD_BRUBLI_rec5.USRX13
     , SDD_BRUBLI_rec5.USRX14
     , SDD_BRUBLI_rec5.USRX15
     , SDD_BRUBLI_rec5.USRX16
     , SDD_BRUBLI_rec5.USRX17
     , SDD_BRUBLI_rec5.USRX18
     , SDD_BRUBLI_rec5.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_BRUBLI_rec5.irid, SDD_BRUBLI_rec5.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  jr_reg_ver.vercopy_dependent_objects(SDD_BAT_ver.ivid, new_ivid);
  return new_ivid;
end SDD_BAT_ver;
/
create or replace function PK_SDD_BAT (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_BAT the_tab_new, SDD_BAT the_tab_old
  where  the_tab_new.ivid = PK_SDD_BAT.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_BAT.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_BAT;
/
create or replace function PK_SDD_BLI (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_BLI the_tab_new, SDD_BLI the_tab_old
  where  the_tab_new.ivid = PK_SDD_BLI.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_BLI.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_BLI;
/
create or replace function FK_BLI_TO_DBU (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.DATABASE_USER_REF ref_value
  from   i$SDD_BLI the_tab
  where  the_tab.ivid = FK_BLI_TO_DBU.object_ivid
  and    the_tab.DATABASE_USER_REF is not null
  and    not exists (
             select null
             from   SDD_DBU foreign_tab
             where  the_tab.DATABASE_USER_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_BLI_TO_DBU;
/
create or replace function FK_BLI_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_BLI the_tab
  where  the_tab.ivid = FK_BLI_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_BLI_TO_GEM;
/
create or replace function SDD_BOB_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_BOB_cur is
    select *
    from   i$SDD_BOB the_tab
    where  the_tab.irid=SDD_BOB_ver.irid
    and    the_tab.ivid=SDD_BOB_ver.ivid;
  SDD_BOB_rec SDD_BOB_cur%ROWTYPE;
  cursor SDD_BOBINC_cur1 is
    select *
    from i$SDD_BOBINC the_tab
    where the_tab.parent_ivid=SDD_BOB_ver.ivid;
  cursor SDD_OST_cur2 is
    select *
    from i$SDD_OST the_tab
    where the_tab.parent_ivid=SDD_BOB_ver.ivid;
  cursor SDD_OSTOST_cur3 is
    select *
    from i$SDD_OSTOST the_tab
    where the_tab.parent_ivid=SDD_BOB_ver.ivid;
  cursor SDD_SRU_cur4 is
    select *
    from i$SDD_SRU the_tab
    where the_tab.parent_ivid=SDD_BOB_ver.ivid;
  cursor SDD_MEMCOM_cur5 is
    select *
    from i$SDD_MEMCOM the_tab
    where the_tab.parent_ivid=SDD_BOB_ver.ivid;
  cursor SDD_TRA_cur6 is
    select *
    from i$SDD_TRA the_tab
    where the_tab.parent_ivid=SDD_BOB_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_BOB_cur;
  fetch SDD_BOB_cur into SDD_BOB_rec;
  close SDD_BOB_cur;
  insert into i$SDD_BOB
  values (
    SDD_BOB_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_BOB_rec.TYPES
   ,SDD_BOB_rec.ELEMENT_TYPE_NAME
   ,SDD_BOB_rec.DATE_CREATED
   ,SDD_BOB_rec.CREATED_BY
   ,SDD_BOB_rec.DATE_CHANGED
   ,SDD_BOB_rec.CHANGED_BY
   ,SDD_BOB_rec.NOTM
   ,SDD_BOB_rec.ENTITY_OBJECT_REF
   ,SDD_BOB_rec.GENERIC_CLASS_REF
   ,SDD_BOB_rec.NAME
   ,SDD_BOB_rec.ICON_FILE_REF
   ,SDD_BOB_rec.BUSINESS_OBJECT_TOP
  );
  jr_reg_ver.vercopy_dependencies(SDD_BOB_ver.irid, SDD_BOB_ver.ivid, new_ivid, null, copy_dependencies);
  for SDD_BOBINC_rec1 in SDD_BOBINC_cur1 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_BOBINC
    values (
       SDD_BOBINC_rec1.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_BOBINC_rec1.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_BOBINC_rec1.TYPES
     , SDD_BOBINC_rec1.ELEMENT_TYPE_NAME
     , SDD_BOBINC_rec1.DATE_CREATED
     , SDD_BOBINC_rec1.CREATED_BY
     , SDD_BOBINC_rec1.DATE_CHANGED
     , SDD_BOBINC_rec1.CHANGED_BY
     , SDD_BOBINC_rec1.NOTM
     , SDD_BOBINC_rec1.BUSINESS_OBJECT_REF
     , SDD_BOBINC_rec1.INTERFACE_CLASSIFIER_REF
     , SDD_BOBINC_rec1.PRIMARY_FLAG
    );
  jr_reg_ver.vercopy_dependencies(SDD_BOBINC_rec1.irid, SDD_BOBINC_rec1.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_OST_rec2 in SDD_OST_cur2 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_OST
    values (
       SDD_OST_rec2.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_OST_rec2.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_OST_rec2.TYPES
     , SDD_OST_rec2.ELEMENT_TYPE_NAME
     , SDD_OST_rec2.DATE_CREATED
     , SDD_OST_rec2.CREATED_BY
     , SDD_OST_rec2.DATE_CHANGED
     , SDD_OST_rec2.CHANGED_BY
     , SDD_OST_rec2.NOTM
     , SDD_OST_rec2.CLASSIFIER_REF
     , SDD_OST_rec2.BUSINESS_OBJECT_REF
     , SDD_OST_rec2.NAME
     , SDD_OST_rec2.WORKFLOW_ITEM_TYPE_REF
     , SDD_OST_rec2.WORKFLOW_MESS_TYPE_REF
     , SDD_OST_rec2.ICON_FILE_REF
     , SDD_OST_rec2.OBJECT_STATE_FOR
    );
  jr_reg_ver.vercopy_dependencies(SDD_OST_rec2.irid, SDD_OST_rec2.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_OSTOST_rec3 in SDD_OSTOST_cur3 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_OSTOST
    values (
       SDD_OSTOST_rec3.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_OSTOST_rec3.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_OSTOST_rec3.TYPES
     , SDD_OSTOST_rec3.ELEMENT_TYPE_NAME
     , SDD_OSTOST_rec3.DATE_CREATED
     , SDD_OSTOST_rec3.CREATED_BY
     , SDD_OSTOST_rec3.DATE_CHANGED
     , SDD_OSTOST_rec3.CHANGED_BY
     , SDD_OSTOST_rec3.NOTM
     , SDD_OSTOST_rec3.OBJECT_STATE_OF_REF
     , SDD_OSTOST_rec3.OBJECT_STATE_ON_REF
    );
  jr_reg_ver.vercopy_dependencies(SDD_OSTOST_rec3.irid, SDD_OSTOST_rec3.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_SRU_rec4 in SDD_SRU_cur4 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_SRU
    values (
       SDD_SRU_rec4.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_SRU_rec4.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_SRU_rec4.TYPES
     , SDD_SRU_rec4.ELEMENT_TYPE_NAME
     , SDD_SRU_rec4.DATE_CREATED
     , SDD_SRU_rec4.CREATED_BY
     , SDD_SRU_rec4.DATE_CHANGED
     , SDD_SRU_rec4.CHANGED_BY
     , SDD_SRU_rec4.NOTM
     , SDD_SRU_rec4.OBJECT_STATE_REF
     , SDD_SRU_rec4.NAME
     , SDD_SRU_rec4.CONTEXT
     , SDD_SRU_rec4.METHOD_REF
     , SDD_SRU_rec4.LANGUAGE_REF
    );
  jr_reg_ver.vercopy_dependencies(SDD_SRU_rec4.irid, SDD_SRU_rec4.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_MEMCOM_rec5 in SDD_MEMCOM_cur5 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_MEMCOM
    values (
       SDD_MEMCOM_rec5.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_MEMCOM_rec5.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_MEMCOM_rec5.TYPES
     , SDD_MEMCOM_rec5.ELEMENT_TYPE_NAME
     , SDD_MEMCOM_rec5.DATE_CREATED
     , SDD_MEMCOM_rec5.CREATED_BY
     , SDD_MEMCOM_rec5.DATE_CHANGED
     , SDD_MEMCOM_rec5.CHANGED_BY
     , SDD_MEMCOM_rec5.NOTM
     , SDD_MEMCOM_rec5.NAMED_RULE_REF
     , SDD_MEMCOM_rec5.INTEGRITY_RULE_REF
     , SDD_MEMCOM_rec5.CROSS_OBJECT_RULE_REF
     , SDD_MEMCOM_rec5.STATE_RULE_REF
     , SDD_MEMCOM_rec5.ATTRIBUTE_DERIV_RULE_REF
     , SDD_MEMCOM_rec5.CLASSIFIER_ATTRIBUTE_REF
     , SDD_MEMCOM_rec5.ASSOCIATION_END_REF
     , SDD_MEMCOM_rec5.METHOD_REF
     , SDD_MEMCOM_rec5.MEMBER_COMPONENT_OF
     , SDD_MEMCOM_rec5.MEMBER_COMPONENT_IN
    );
  jr_reg_ver.vercopy_dependencies(SDD_MEMCOM_rec5.irid, SDD_MEMCOM_rec5.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_TRA_rec6 in SDD_TRA_cur6 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_TRA
    values (
       SDD_TRA_rec6.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_TRA_rec6.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_TRA_rec6.TYPES
     , SDD_TRA_rec6.ELEMENT_TYPE_NAME
     , SDD_TRA_rec6.DATE_CREATED
     , SDD_TRA_rec6.CREATED_BY
     , SDD_TRA_rec6.DATE_CHANGED
     , SDD_TRA_rec6.CHANGED_BY
     , SDD_TRA_rec6.NOTM
     , SDD_TRA_rec6.SOURCE_ACTIVITY_REF
     , SDD_TRA_rec6.SOURCE_ACT_USAGE_REF
     , SDD_TRA_rec6.SOURCE_EVENT_REF
     , SDD_TRA_rec6.SOURCE_OBJECT_STATE_REF
     , SDD_TRA_rec6.SOURCE_PSEUDOSTATE_REF
     , SDD_TRA_rec6.TARGET_ACTIVITY_REF
     , SDD_TRA_rec6.TARGET_ACT_USAGE_REF
     , SDD_TRA_rec6.TARGET_EVENT_REF
     , SDD_TRA_rec6.TARGET_OBJECT_STATE_REF
     , SDD_TRA_rec6.TARGET_PSEUDOSTATE_REF
     , SDD_TRA_rec6.SEQUENCE_NUMBER
     , SDD_TRA_rec6.NAMED_RULE_REF
     , SDD_TRA_rec6.PRIMARY_FLAG
     , SDD_TRA_rec6.TRANSITION_REF
     , SDD_TRA_rec6.EVENT_PUBLICATION_REF
     , SDD_TRA_rec6.EVENT_SUBSCRIPTION_REF
     , SDD_TRA_rec6.CREATABLE_FLAG
     , SDD_TRA_rec6.MESSAGING_AUDIT
     , SDD_TRA_rec6.CHANNEL_NAME
     , SDD_TRA_rec6.RETRIEVABLE_FLAG
     , SDD_TRA_rec6.CHANNEL_TYPE
     , SDD_TRA_rec6.UPDATABLE_FLAG
     , SDD_TRA_rec6.AUTOMATIC_INVOCATION_FLAG
     , SDD_TRA_rec6.DELETABLE_FLAG
     , SDD_TRA_rec6.TRIGGERING_FLAG
     , SDD_TRA_rec6.ACTIVITY_SIGNATURE_FLAG
     , SDD_TRA_rec6.TRIGGER_EVENT_REF
     , SDD_TRA_rec6.SOURCE_TYPE
     , SDD_TRA_rec6.TARGET_TYPE
    );
  jr_reg_ver.vercopy_dependencies(SDD_TRA_rec6.irid, SDD_TRA_rec6.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  jr_reg_ver.vercopy_dependent_objects(SDD_BOB_ver.ivid, new_ivid);
  return new_ivid;
end SDD_BOB_ver;
/
create or replace function PK_SDD_BOB (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_BOB the_tab_new, SDD_BOB the_tab_old
  where  the_tab_new.ivid = PK_SDD_BOB.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_BOB.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_BOB;
/
create or replace function FK_BOB_TO_EOC (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ENTITY_OBJECT_REF ref_value
  from   i$SDD_BOB the_tab
  where  the_tab.ivid = FK_BOB_TO_EOC.object_ivid
  and    the_tab.ENTITY_OBJECT_REF is not null
  and    not exists (
             select null
             from   SDD_CLA foreign_tab
             where  the_tab.ENTITY_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_BOB_TO_EOC;
/
create or replace function FK_BOB_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_BOB the_tab
  where  the_tab.ivid = FK_BOB_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_BOB_TO_FILES;
/
create or replace function FK_BOB_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_BOB the_tab
  where  the_tab.ivid = FK_BOB_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_BOB_TO_GEC;
/
create or replace function PK_SDD_BOBINC (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_BOBINC the_tab_new, SDD_BOBINC the_tab_old
  where  the_tab_new.ivid = PK_SDD_BOBINC.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_BOBINC.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_BOBINC;
/
create or replace function FK_BOBINC_TO_INC (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.INTERFACE_CLASSIFIER_REF ref_value
  from   i$SDD_BOBINC the_tab
  where  the_tab.ivid = FK_BOBINC_TO_INC.object_ivid
  and    the_tab.INTERFACE_CLASSIFIER_REF is not null
  and    not exists (
             select null
             from   SDD_CLA foreign_tab
             where  the_tab.INTERFACE_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_BOBINC_TO_INC;
/
create or replace function PK_SDD_BRL (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_BRL the_tab_new, SDD_BRL the_tab_old
  where  the_tab_new.ivid = PK_SDD_BRL.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_BRL.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_BRL;
/
create or replace function FK_BRL_TO_DBU (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.DATABASE_USER_REF ref_value
  from   i$SDD_BRL the_tab
  where  the_tab.ivid = FK_BRL_TO_DBU.object_ivid
  and    the_tab.DATABASE_USER_REF is not null
  and    not exists (
             select null
             from   SDD_DBU foreign_tab
             where  the_tab.DATABASE_USER_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_BRL_TO_DBU;
/
create or replace function FK_BRL_TO_VWTAB (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.RELATION_SELECTION_REF ref_value
  from   i$SDD_BRL the_tab
  where  the_tab.ivid = FK_BRL_TO_VWTAB.object_ivid
  and    the_tab.RELATION_SELECTION_REF is not null
  and    not exists (
             select null
             from   SDD_VWTAB foreign_tab
             where  the_tab.RELATION_SELECTION_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
                                   , 5026, action);
  end loop;
  return is_ok;
end FK_BRL_TO_VWTAB;
/
create or replace function PK_SDD_BRU (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_BRU the_tab_new, SDD_BRU the_tab_old
  where  the_tab_new.ivid = PK_SDD_BRU.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_BRU.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_BRU;
/
create or replace function PK_SDD_BRUBLI (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_BRUBLI the_tab_new, SDD_BRUBLI the_tab_old
  where  the_tab_new.ivid = PK_SDD_BRUBLI.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_BRUBLI.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_BRUBLI;
/
create or replace function FK_BRUBLI_TO_BLI (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.BATCHLINE_REF ref_value
  from   i$SDD_BRUBLI the_tab
  where  the_tab.ivid = FK_BRUBLI_TO_BLI.object_ivid
  and    the_tab.BATCHLINE_REF is not null
  and    not exists (
             select null
             from   SDD_BLI foreign_tab
             where  the_tab.BATCHLINE_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
                                   , 5099, action);
  end loop;
  return is_ok;
end FK_BRUBLI_TO_BLI;
/
create or replace function FK_A24_TO_BUN_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_A24 child_tab
  where  child_tab.BUSINESS_UNIT_REF=FK_A24_TO_BUN_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_A24 child_tab, i$sdd_object_versions o
    where  child_tab.BUSINESS_UNIT_REF=FK_A24_TO_BUN_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_A24_TO_BUN_d;
/
create or replace function FK_A9_TO_BUN_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_A9 child_tab
  where  child_tab.BUSINESS_UNIT_REF=FK_A9_TO_BUN_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_A9 child_tab, i$sdd_object_versions o
    where  child_tab.BUSINESS_UNIT_REF=FK_A9_TO_BUN_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_A9_TO_BUN_d;
/
create or replace function FK_DST_TO_BUN_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_DST child_tab
  where  child_tab.BUSINESS_UNIT_REF=FK_DST_TO_BUN_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_DST child_tab, i$sdd_object_versions o
    where  child_tab.BUSINESS_UNIT_REF=FK_DST_TO_BUN_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_DST_TO_BUN_d;
/
create or replace function FK_ENTBUN_TO_BUN_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_ENTBUN child_tab
  where  child_tab.BUSINESS_UNIT_REF=FK_ENTBUN_TO_BUN_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_ENTBUN child_tab, i$sdd_object_versions o
    where  child_tab.BUSINESS_UNIT_REF=FK_ENTBUN_TO_BUN_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_ENTBUN_TO_BUN_d;
/
create or replace function FK_EXT_TO_BUN_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_EXT child_tab
  where  child_tab.BUSINESS_UNIT_REF=FK_EXT_TO_BUN_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_EXT child_tab, i$sdd_object_versions o
    where  child_tab.BUSINESS_UNIT_REF=FK_EXT_TO_BUN_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_EXT_TO_BUN_d;
/
create or replace function FK_FUNBUN_TO_BUN_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_FUNBUN child_tab
  where  child_tab.BUSINESS_UNIT_REF=FK_FUNBUN_TO_BUN_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_FUNBUN child_tab, i$sdd_object_versions o
    where  child_tab.BUSINESS_UNIT_REF=FK_FUNBUN_TO_BUN_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_FUNBUN_TO_BUN_d;
/
create or replace function FK_MODBUN_TO_BUN_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_MODBUN child_tab
  where  child_tab.BUSINESS_UNIT_REF=FK_MODBUN_TO_BUN_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_MODBUN child_tab, i$sdd_object_versions o
    where  child_tab.BUSINESS_UNIT_REF=FK_MODBUN_TO_BUN_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_MODBUN_TO_BUN_d;
/
create or replace function SDD_BUN_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_BUN_cur is
    select *
    from   i$SDD_BUN the_tab
    where  the_tab.irid=SDD_BUN_ver.irid
    and    the_tab.ivid=SDD_BUN_ver.ivid;
  SDD_BUN_rec SDD_BUN_cur%ROWTYPE;
  cursor SDD_A10_cur1 is
    select *
    from i$SDD_A10 the_tab
    where the_tab.parent_ivid=SDD_BUN_ver.ivid;
  cursor SDD_A8_cur2 is
    select *
    from i$SDD_A8 the_tab
    where the_tab.parent_ivid=SDD_BUN_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_BUN_cur;
  fetch SDD_BUN_cur into SDD_BUN_rec;
  close SDD_BUN_cur;
  insert into i$SDD_BUN
  values (
    SDD_BUN_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_BUN_rec.TYPES
   ,SDD_BUN_rec.ELEMENT_TYPE_NAME
   ,SDD_BUN_rec.DATE_CREATED
   ,SDD_BUN_rec.CREATED_BY
   ,SDD_BUN_rec.DATE_CHANGED
   ,SDD_BUN_rec.CHANGED_BY
   ,SDD_BUN_rec.NOTM
   ,SDD_BUN_rec.SHORT_NAME
   ,SDD_BUN_rec.NAME
   ,SDD_BUN_rec.PARENT_REF
   ,SDD_BUN_rec.SEQUENCE_IN_PARENT
   ,SDD_BUN_rec.REMARK
   ,SDD_BUN_rec.PRIMARY_LOCATION
   ,SDD_BUN_rec.PRIMARY_CONTACT
   ,SDD_BUN_rec.HEADCOUNT
   ,SDD_BUN_rec.ROLE_COST_RATE
   ,SDD_BUN_rec.ROLE_COST_RATE_UNIT
   ,SDD_BUN_rec.ROLE_RESPONSIBILITIES
   ,SDD_BUN_rec.ROLE_SKILL_1
   ,SDD_BUN_rec.ROLE_SKILL_2
   ,SDD_BUN_rec.ROLE_SKILL_3
   ,SDD_BUN_rec.ROLE_SKILL_4
   ,SDD_BUN_rec.ROLE_FLAG
   ,SDD_BUN_rec.ICON_FILE
   ,SDD_BUN_rec.EXPORT_ID
   ,SDD_BUN_rec.IMAGE_FILE
   ,SDD_BUN_rec.SOUND_FILE
   ,SDD_BUN_rec.VIDEO_FILE
   ,SDD_BUN_rec.EXECUTION_STRING
   ,SDD_BUN_rec.NOTE_TYPE
   ,SDD_BUN_rec.NOTE_TEXT
   ,SDD_BUN_rec.NOTE_PICTURE_FILE
   ,SDD_BUN_rec.USRX0
   ,SDD_BUN_rec.USRX1
   ,SDD_BUN_rec.USRX2
   ,SDD_BUN_rec.USRX3
   ,SDD_BUN_rec.USRX4
   ,SDD_BUN_rec.USRX5
   ,SDD_BUN_rec.USRX6
   ,SDD_BUN_rec.USRX7
   ,SDD_BUN_rec.USRX8
   ,SDD_BUN_rec.USRX9
   ,SDD_BUN_rec.USRX10
   ,SDD_BUN_rec.USRX11
   ,SDD_BUN_rec.USRX12
   ,SDD_BUN_rec.USRX13
   ,SDD_BUN_rec.USRX14
   ,SDD_BUN_rec.USRX15
   ,SDD_BUN_rec.USRX16
   ,SDD_BUN_rec.USRX17
   ,SDD_BUN_rec.USRX18
   ,SDD_BUN_rec.USRX19
  );
  jr_reg_ver.vercopy_dependencies(SDD_BUN_ver.irid, SDD_BUN_ver.ivid, new_ivid, null, copy_dependencies);
  for SDD_A10_rec1 in SDD_A10_cur1 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_A10
    values (
       SDD_A10_rec1.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_A10_rec1.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_A10_rec1.TYPES
     , SDD_A10_rec1.ELEMENT_TYPE_NAME
     , SDD_A10_rec1.DATE_CREATED
     , SDD_A10_rec1.CREATED_BY
     , SDD_A10_rec1.DATE_CHANGED
     , SDD_A10_rec1.CHANGED_BY
     , SDD_A10_rec1.NOTM
     , SDD_A10_rec1.BUSINESS_UNIT_REF
     , SDD_A10_rec1.PROBLEM_REF
     , SDD_A10_rec1.CDATE_INCURRED
     , SDD_A10_rec1.CONTACT
     , SDD_A10_rec1.SEVERITY_LEVEL
     , SDD_A10_rec1.COMMENTS
     , SDD_A10_rec1.USRX0
     , SDD_A10_rec1.USRX4
     , SDD_A10_rec1.USRX5
     , SDD_A10_rec1.USRX6
     , SDD_A10_rec1.USRX7
     , SDD_A10_rec1.USRX8
     , SDD_A10_rec1.USRX9
     , SDD_A10_rec1.USRX10
     , SDD_A10_rec1.USRX11
     , SDD_A10_rec1.USRX12
     , SDD_A10_rec1.USRX13
     , SDD_A10_rec1.USRX14
     , SDD_A10_rec1.USRX15
     , SDD_A10_rec1.USRX16
     , SDD_A10_rec1.USRX17
     , SDD_A10_rec1.USRX18
     , SDD_A10_rec1.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_A10_rec1.irid, SDD_A10_rec1.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_A8_rec2 in SDD_A8_cur2 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_A8
    values (
       SDD_A8_rec2.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_A8_rec2.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_A8_rec2.TYPES
     , SDD_A8_rec2.ELEMENT_TYPE_NAME
     , SDD_A8_rec2.DATE_CREATED
     , SDD_A8_rec2.CREATED_BY
     , SDD_A8_rec2.DATE_CHANGED
     , SDD_A8_rec2.CHANGED_BY
     , SDD_A8_rec2.NOTM
     , SDD_A8_rec2.OBJECTIVE_REF
     , SDD_A8_rec2.BUSINESS_UNIT_REF
     , SDD_A8_rec2.COMMENTS
     , SDD_A8_rec2.SET_BY
     , SDD_A8_rec2.DATE_PLACED
     , SDD_A8_rec2.VALUE
     , SDD_A8_rec2.UNIT_OF_MEASURE
     , SDD_A8_rec2.CDATE_REQUIRED
     , SDD_A8_rec2.ACHIEVEMENT_COMMENT
     , SDD_A8_rec2.USRX0
     , SDD_A8_rec2.USRX7
     , SDD_A8_rec2.USRX8
     , SDD_A8_rec2.USRX9
     , SDD_A8_rec2.USRX10
     , SDD_A8_rec2.USRX11
     , SDD_A8_rec2.USRX12
     , SDD_A8_rec2.USRX13
     , SDD_A8_rec2.USRX14
     , SDD_A8_rec2.USRX15
     , SDD_A8_rec2.USRX16
     , SDD_A8_rec2.USRX17
     , SDD_A8_rec2.USRX18
     , SDD_A8_rec2.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_A8_rec2.irid, SDD_A8_rec2.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  jr_reg_ver.vercopy_dependent_objects(SDD_BUN_ver.ivid, new_ivid);
  return new_ivid;
end SDD_BUN_ver;
/
create or replace function PK_SDD_BUN (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_BUN the_tab_new, SDD_BUN the_tab_old
  where  the_tab_new.ivid = PK_SDD_BUN.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_BUN.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_BUN;
/
create or replace function FK_BUN_TO_BUN (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.PARENT_REF ref_value
  from   i$SDD_BUN the_tab
  where  the_tab.ivid = FK_BUN_TO_BUN.object_ivid
  and    the_tab.PARENT_REF is not null
  and    not exists (
             select null
             from   SDD_BUN foreign_tab
             where  the_tab.PARENT_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
                                   , 5005, action);
  end loop;
  return is_ok;
end FK_BUN_TO_BUN;
/
create or replace function FK_CAT_TO_EAT_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_CAT child_tab, i$SDD_CAT parent_tab
  where  parent_tab.parent_ivid=FK_CAT_TO_EAT_cmd.ivid
  and    child_tab.EO_ATTRIBUTE_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_CAT child_tab
          ,i$SDD_CAT parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_CAT_TO_EAT_cmd.ivid
       and child_tab.EO_ATTRIBUTE_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_CAT_TO_EAT_cmd;
/
create or replace function FK_CAT_TO_EAT_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_CAT child_tab
  where  child_tab.EO_ATTRIBUTE_REF=FK_CAT_TO_EAT_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_CAT child_tab, i$sdd_object_versions o
    where  child_tab.EO_ATTRIBUTE_REF=FK_CAT_TO_EAT_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_CAT_TO_EAT_d;
/
create or replace function FK_CMA_TO_CAT2_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_CMA child_tab, i$SDD_CAT parent_tab
  where  parent_tab.parent_ivid=FK_CMA_TO_CAT2_cmd.ivid
  and    child_tab.CLASSIFIER_ATT_FROM_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_CMA child_tab
          ,i$SDD_CAT parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_CMA_TO_CAT2_cmd.ivid
       and child_tab.CLASSIFIER_ATT_FROM_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_CMA_TO_CAT2_cmd;
/
create or replace function FK_CMA_TO_CAT2_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_CMA child_tab
  where  child_tab.CLASSIFIER_ATT_FROM_REF=FK_CMA_TO_CAT2_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_CMA child_tab, i$sdd_object_versions o
    where  child_tab.CLASSIFIER_ATT_FROM_REF=FK_CMA_TO_CAT2_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_CMA_TO_CAT2_d;
/
create or replace function FK_VALGAT_TO_GAT_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_VALGAT child_tab, i$SDD_CAT parent_tab
  where  parent_tab.parent_ivid=FK_VALGAT_TO_GAT_cmd.ivid
  and    child_tab.GENERAL_ATTRIBUTE_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_VALGAT child_tab
          ,i$SDD_CAT parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_VALGAT_TO_GAT_cmd.ivid
       and child_tab.GENERAL_ATTRIBUTE_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_VALGAT_TO_GAT_cmd;
/
create or replace function FK_VALGAT_TO_GAT_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_VALGAT child_tab
  where  child_tab.GENERAL_ATTRIBUTE_REF=FK_VALGAT_TO_GAT_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_VALGAT child_tab, i$sdd_object_versions o
    where  child_tab.GENERAL_ATTRIBUTE_REF=FK_VALGAT_TO_GAT_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_VALGAT_TO_GAT_d;
/
create or replace function PK_SDD_CAT (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_CAT the_tab_new, SDD_CAT the_tab_old
  where  the_tab_new.ivid = PK_SDD_CAT.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_CAT.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_CAT;
/
create or replace function UK_HANDCRAFTED_CAT (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_CAT the_tab_new, SDD_CAT the_tab_old
  where  the_tab_new.ivid = UK_HANDCRAFTED_CAT.ivid
  and    the_tab_new.GENERIC_CLASS_REF = the_tab_old.GENERIC_CLASS_REF
  and    the_tab_new.EVENT_CLASSIFIER_REF = the_tab_old.EVENT_CLASSIFIER_REF
  and    the_tab_new.INTERFACE_CLASSIFIER_REF = the_tab_old.INTERFACE_CLASSIFIER_REF
  and    the_tab_new.ENTITY_OBJECT_REF = the_tab_old.ENTITY_OBJECT_REF
  and    the_tab_new.VIEW_OBJECT_REF = the_tab_old.VIEW_OBJECT_REF
  and    the_tab_new.NAME = the_tab_old.NAME
  and    the_tab_old.ivid != UK_HANDCRAFTED_CAT.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_HANDCRAFTED_CAT;
/
create or replace function FK_CAT_TO_CLA (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.CLASSIFIER_REF ref_value
  from   i$SDD_CAT the_tab
  where  the_tab.ivid = FK_CAT_TO_CLA.object_ivid
  and    the_tab.CLASSIFIER_REF is not null
  and    not exists (
             select null
             from   SDD_CLA foreign_tab
             where  the_tab.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_CAT_TO_CLA;
/
create or replace function FK_CAT_TO_CLA2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.COLLECT_CLASSSIFIER_REF ref_value
  from   i$SDD_CAT the_tab
  where  the_tab.ivid = FK_CAT_TO_CLA2.object_ivid
  and    the_tab.COLLECT_CLASSSIFIER_REF is not null
  and    not exists (
             select null
             from   SDD_CLA foreign_tab
             where  the_tab.COLLECT_CLASSSIFIER_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_CAT_TO_CLA2;
/
create or replace function FK_CAT_TO_EAT (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.EO_ATTRIBUTE_REF ref_value
  from   i$SDD_CAT the_tab
  where  the_tab.ivid = FK_CAT_TO_EAT.object_ivid
  and    the_tab.EO_ATTRIBUTE_REF is not null
  and    not exists (
             select null
             from   SDD_CAT foreign_tab
             where  the_tab.EO_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_CAT_TO_EAT;
/
create or replace function FK_CAT_TO_EOU (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ENTITY_OBJECT_USAGE_REF ref_value
  from   i$SDD_CAT the_tab
  where  the_tab.ivid = FK_CAT_TO_EOU.object_ivid
  and    the_tab.ENTITY_OBJECT_USAGE_REF is not null
  and    not exists (
             select null
             from   SDD_EOU foreign_tab
             where  the_tab.ENTITY_OBJECT_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
                                   , 5123, action);
  end loop;
  return is_ok;
end FK_CAT_TO_EOU;
/
create or replace function PK_SDD_CATAEN (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_CATAEN the_tab_new, SDD_CATAEN the_tab_old
  where  the_tab_new.ivid = PK_SDD_CATAEN.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_CATAEN.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_CATAEN;
/
create or replace function FK_CATAEN_TO_EAT (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.EO_ATTRIBUTE_REF ref_value
  from   i$SDD_CATAEN the_tab
  where  the_tab.ivid = FK_CATAEN_TO_EAT.object_ivid
  and    the_tab.EO_ATTRIBUTE_REF is not null
  and    not exists (
             select null
             from   SDD_CAT foreign_tab
             where  the_tab.EO_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_CATAEN_TO_EAT;
/
create or replace function FK_CATAEN_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_CATAEN the_tab
  where  the_tab.ivid = FK_CATAEN_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_CATAEN_TO_GAT;
/
create or replace function PK_SDD_CATEAT (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_CATEAT the_tab_new, SDD_CATEAT the_tab_old
  where  the_tab_new.ivid = PK_SDD_CATEAT.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_CATEAT.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_CATEAT;
/
create or replace function FK_CATEAT_TO_EAT (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.EO_ATTRIBUTE_REF ref_value
  from   i$SDD_CATEAT the_tab
  where  the_tab.ivid = FK_CATEAT_TO_EAT.object_ivid
  and    the_tab.EO_ATTRIBUTE_REF is not null
  and    not exists (
             select null
             from   SDD_CAT foreign_tab
             where  the_tab.EO_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_CATEAT_TO_EAT;
/
create or replace function PK_SDD_CCD (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_CCD the_tab_new, SDD_CCD the_tab_old
  where  the_tab_new.ivid = PK_SDD_CCD.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_CCD.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_CCD;
/
create or replace function SDD_CDE_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_CDE_cur is
    select *
    from   i$SDD_CDE the_tab
    where  the_tab.irid=SDD_CDE_ver.irid
    and    the_tab.ivid=SDD_CDE_ver.ivid;
  SDD_CDE_rec SDD_CDE_cur%ROWTYPE;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_CDE_cur;
  fetch SDD_CDE_cur into SDD_CDE_rec;
  close SDD_CDE_cur;
  insert into i$SDD_CDE
  values (
    SDD_CDE_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_CDE_rec.TYPES
   ,SDD_CDE_rec.ELEMENT_TYPE_NAME
   ,SDD_CDE_rec.DATE_CREATED
   ,SDD_CDE_rec.CREATED_BY
   ,SDD_CDE_rec.DATE_CHANGED
   ,SDD_CDE_rec.CHANGED_BY
   ,SDD_CDE_rec.NOTM
   ,SDD_CDE_rec.DEFINITION_TYPE
   ,SDD_CDE_rec.CLASS_SET_CODE_TYPE
   ,SDD_CDE_rec.PRIMARY_ACCESS_FILE_REF
  );
  jr_reg_ver.vercopy_dependencies(SDD_CDE_ver.irid, SDD_CDE_ver.ivid, new_ivid, null, copy_dependencies);
  jr_reg_ver.vercopy_dependent_objects(SDD_CDE_ver.ivid, new_ivid);
  return new_ivid;
end SDD_CDE_ver;
/
create or replace function PK_SDD_CDE (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_CDE the_tab_new, SDD_CDE the_tab_old
  where  the_tab_new.ivid = PK_SDD_CDE.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_CDE.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_CDE;
/
create or replace function FK_CDE_TO_FILES (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.PRIMARY_ACCESS_FILE_REF ref_value
  from   i$SDD_CDE the_tab
  where  the_tab.ivid = FK_CDE_TO_FILES.object_ivid
  and    the_tab.PRIMARY_ACCESS_FILE_REF is not null
  and    not exists (
             select null
             from   SDD_FILES foreign_tab
             where  the_tab.PRIMARY_ACCESS_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_CDE_TO_FILES;
/
create or replace function FK_AMCAMC_TO_AMC2_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_AMCAMC child_tab
  where  child_tab.CHILD_APP_MODULE_REF=FK_AMCAMC_TO_AMC2_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_AMCAMC child_tab, i$sdd_object_versions o
    where  child_tab.CHILD_APP_MODULE_REF=FK_AMCAMC_TO_AMC2_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_AMCAMC_TO_AMC2_d;
/
create or replace function FK_BOB_TO_EOC_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_BOB child_tab
  where  child_tab.ENTITY_OBJECT_REF=FK_BOB_TO_EOC_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_BOB child_tab, i$sdd_object_versions o
    where  child_tab.ENTITY_OBJECT_REF=FK_BOB_TO_EOC_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_BOB_TO_EOC_d;
/
create or replace function FK_BOB_TO_GEC_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_BOB child_tab
  where  child_tab.GENERIC_CLASS_REF=FK_BOB_TO_GEC_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_BOB child_tab, i$sdd_object_versions o
    where  child_tab.GENERIC_CLASS_REF=FK_BOB_TO_GEC_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_BOB_TO_GEC_d;
/
create or replace function FK_CAT_TO_CLA_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_CAT child_tab
  where  child_tab.CLASSIFIER_REF=FK_CAT_TO_CLA_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_CAT child_tab, i$sdd_object_versions o
    where  child_tab.CLASSIFIER_REF=FK_CAT_TO_CLA_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_CAT_TO_CLA_d;
/
create or replace function FK_CLA_TO_CLA_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_CLA child_tab
  where  child_tab.CLASSIFIER_REF=FK_CLA_TO_CLA_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_CLA child_tab, i$sdd_object_versions o
    where  child_tab.CLASSIFIER_REF=FK_CLA_TO_CLA_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_CLA_TO_CLA_d;
/
create or replace function FK_CLA_TO_GEC_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_CLA child_tab
  where  child_tab.GENERIC_CLASS_REF=FK_CLA_TO_GEC_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_CLA child_tab, i$sdd_object_versions o
    where  child_tab.GENERIC_CLASS_REF=FK_CLA_TO_GEC_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_CLA_TO_GEC_d;
/
create or replace function FK_CLACLA_TO_CLA2_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_CLACLA child_tab
  where  child_tab.SUPERTYPE_REF=FK_CLACLA_TO_CLA2_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_CLACLA child_tab, i$sdd_object_versions o
    where  child_tab.SUPERTYPE_REF=FK_CLACLA_TO_CLA2_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_CLACLA_TO_CLA2_d;
/
create or replace function FK_CLAINC_TO_INC_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_CLAINC child_tab
  where  child_tab.INTERFACE_CLASSIFIER_REF=FK_CLAINC_TO_INC_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_CLAINC child_tab, i$sdd_object_versions o
    where  child_tab.INTERFACE_CLASSIFIER_REF=FK_CLAINC_TO_INC_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_CLAINC_TO_INC_d;
/
create or replace function FK_EOU_TO_EOC_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_EOU child_tab
  where  child_tab.ENTITY_OBJECT_REF=FK_EOU_TO_EOC_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_EOU child_tab, i$sdd_object_versions o
    where  child_tab.ENTITY_OBJECT_REF=FK_EOU_TO_EOC_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_EOU_TO_EOC_d;
/
create or replace function FK_EVS_TO_EVC_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_EVS child_tab
  where  child_tab.EVENT_CLASSIFIER_REF=FK_EVS_TO_EVC_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_EVS child_tab, i$sdd_object_versions o
    where  child_tab.EVENT_CLASSIFIER_REF=FK_EVS_TO_EVC_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_EVS_TO_EVC_d;
/
create or replace function FK_MET_TO_CLA2_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_MET child_tab
  where  child_tab.RETURN_CLASSIFIER_REF=FK_MET_TO_CLA2_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_MET child_tab, i$sdd_object_versions o
    where  child_tab.RETURN_CLASSIFIER_REF=FK_MET_TO_CLA2_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_MET_TO_CLA2_d;
/
create or replace function FK_MPA_TO_CLA_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_MPA child_tab
  where  child_tab.CLASSIFIER_REF=FK_MPA_TO_CLA_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_MPA child_tab, i$sdd_object_versions o
    where  child_tab.CLASSIFIER_REF=FK_MPA_TO_CLA_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_MPA_TO_CLA_d;
/
create or replace function FK_PSTADC_TO_ADC_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_PSTADC child_tab
  where  child_tab.ATTRIBUTE_DOMAIN_REF=FK_PSTADC_TO_ADC_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_PSTADC child_tab, i$sdd_object_versions o
    where  child_tab.ATTRIBUTE_DOMAIN_REF=FK_PSTADC_TO_ADC_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_PSTADC_TO_ADC_d;
/
create or replace function FK_VAL_TO_GEC_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_VAL child_tab
  where  child_tab.GENERIC_CLASS_REF=FK_VAL_TO_GEC_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_VAL child_tab, i$sdd_object_versions o
    where  child_tab.GENERIC_CLASS_REF=FK_VAL_TO_GEC_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_VAL_TO_GEC_d;
/
create or replace function FK_VOU_TO_VOB_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_VOU child_tab
  where  child_tab.VIEW_OBJECT_REF=FK_VOU_TO_VOB_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_VOU child_tab, i$sdd_object_versions o
    where  child_tab.VIEW_OBJECT_REF=FK_VOU_TO_VOB_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_VOU_TO_VOB_d;
/
create or replace function SDD_CLA_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_CLA_cur is
    select *
    from   i$SDD_CLA the_tab
    where  the_tab.irid=SDD_CLA_ver.irid
    and    the_tab.ivid=SDD_CLA_ver.ivid;
  SDD_CLA_rec SDD_CLA_cur%ROWTYPE;
  cursor SDD_AMCAMC_cur1 is
    select *
    from i$SDD_AMCAMC the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_AMCBOB_cur2 is
    select *
    from i$SDD_AMCBOB the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_AMCPRJ_cur3 is
    select *
    from i$SDD_AMCPRJ the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_CAT_cur4 is
    select *
    from i$SDD_CAT the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_ADR_cur5 is
    select *
    from i$SDD_ADR the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_MEMCOM_cur6 is
    select *
    from i$SDD_MEMCOM the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_CATEAT_cur7 is
    select *
    from i$SDD_CATEAT the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_CLAAEN_cur8 is
    select *
    from i$SDD_CLAAEN the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_CLACLA_cur9 is
    select *
    from i$SDD_CLACLA the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_CLAEVC_cur10 is
    select *
    from i$SDD_CLAEVC the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_CLAINC_cur11 is
    select *
    from i$SDD_CLAINC the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_CRU_cur12 is
    select *
    from i$SDD_CRU the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_DATCOM_cur13 is
    select *
    from i$SDD_DATCOM the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_VAL_cur14 is
    select *
    from i$SDD_VAL the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_VALGAT_cur15 is
    select *
    from i$SDD_VALGAT the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_CSG_cur16 is
    select *
    from i$SDD_CSG the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_EOU_cur17 is
    select *
    from i$SDD_EOU the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_AEU_cur18 is
    select *
    from i$SDD_AEU the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_EVS_cur19 is
    select *
    from i$SDD_EVS the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_SUD_cur20 is
    select *
    from i$SDD_SUD the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_FILPAC_cur21 is
    select *
    from i$SDD_FILPAC the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_FSE_cur22 is
    select *
    from i$SDD_FSE the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_MET_cur23 is
    select *
    from i$SDD_MET the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_EVH_cur24 is
    select *
    from i$SDD_EVH the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_CMA_cur25 is
    select *
    from i$SDD_CMA the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_EVR_cur26 is
    select *
    from i$SDD_EVR the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_METRUL_cur27 is
    select *
    from i$SDD_METRUL the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_MPA_cur28 is
    select *
    from i$SDD_MPA the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_SBA_cur29 is
    select *
    from i$SDD_SBA the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_OST_cur30 is
    select *
    from i$SDD_OST the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_OSTOST_cur31 is
    select *
    from i$SDD_OSTOST the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_SRU_cur32 is
    select *
    from i$SDD_SRU the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_TRA_cur33 is
    select *
    from i$SDD_TRA the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_VLU_cur34 is
    select *
    from i$SDD_VLU the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_VLEU_cur35 is
    select *
    from i$SDD_VLEU the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
  cursor SDD_VOU_cur36 is
    select *
    from i$SDD_VOU the_tab
    where the_tab.parent_ivid=SDD_CLA_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_CLA_cur;
  fetch SDD_CLA_cur into SDD_CLA_rec;
  close SDD_CLA_cur;
  insert into i$SDD_CLA
  values (
    SDD_CLA_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_CLA_rec.TYPES
   ,SDD_CLA_rec.ELEMENT_TYPE_NAME
   ,SDD_CLA_rec.DATE_CREATED
   ,SDD_CLA_rec.CREATED_BY
   ,SDD_CLA_rec.DATE_CHANGED
   ,SDD_CLA_rec.CHANGED_BY
   ,SDD_CLA_rec.NOTM
   ,SDD_CLA_rec.NAME
   ,SDD_CLA_rec.ANALYSIS_TYPE_FLAG
   ,SDD_CLA_rec.ICON_FILE_REF
   ,SDD_CLA_rec.AUTHOR
   ,SDD_CLA_rec.INTERFACE_CLASSIFIER_REF
   ,SDD_CLA_rec.CLASS_NAME
   ,SDD_CLA_rec.RICH_INTERFACE_FLAG
   ,SDD_CLA_rec.TYPE
   ,SDD_CLA_rec.ACTIVE_FLAG
   ,SDD_CLA_rec.DURATION
   ,SDD_CLA_rec.LARGE_OBJECT_FLAG
   ,SDD_CLA_rec.EXTERNAL_FLAG
   ,SDD_CLA_rec.ABSTRACT_FLAG
   ,SDD_CLA_rec.DURATION_UNIT
   ,SDD_CLA_rec.LEAF_FLAG
   ,SDD_CLA_rec.FREQUENCY
   ,SDD_CLA_rec.ROOT_FLAG
   ,SDD_CLA_rec.FREQUENCY_UNIT
   ,SDD_CLA_rec.CALL_MODE
   ,SDD_CLA_rec.SIGNAL_MODE
   ,SDD_CLA_rec.DEFAULT_DB_OBJECT_NAME
   ,SDD_CLA_rec.OBJECT_STATE_REF
   ,SDD_CLA_rec.DEFAULT_DB_OBJECT_TYPE
   ,SDD_CLA_rec.PERSISTENT_FLAG
   ,SDD_CLA_rec.WHEN_OCCURS
   ,SDD_CLA_rec.FILE_SCOPE
   ,SDD_CLA_rec.CLASSIFIER_REF
   ,SDD_CLA_rec.IMPLEMENTATION_TARGET
   ,SDD_CLA_rec.BUSINESS_OBJECT_REF
   ,SDD_CLA_rec.MANDATORY_FLAG
   ,SDD_CLA_rec.DEFAULT_VALUE
   ,SDD_CLA_rec.QUERYABLE_FLAG
   ,SDD_CLA_rec.BASE_SCALAR_DATATYPE
   ,SDD_CLA_rec.MAXIMUM_LENGTH
   ,SDD_CLA_rec.DECIMAL_PLACES
   ,SDD_CLA_rec.GENERIC_CLASS_REF
   ,SDD_CLA_rec.UPDATABLE_FLAG
   ,SDD_CLA_rec.GENERATE_ACCESSORS_FLAG
   ,SDD_CLA_rec.CREATE_SERVER_MAPPING_FLAG
   ,SDD_CLA_rec.COR_DEPTH_LEVEL
   ,SDD_CLA_rec.TIME_OUT_LIMIT
   ,SDD_CLA_rec.TIME_OUT_LIMIT_UNIT
   ,SDD_CLA_rec.FETCH_MODE
   ,SDD_CLA_rec.DEFAULT_COLUMN_DATATYPE
   ,SDD_CLA_rec.FETCH_SIZE
   ,SDD_CLA_rec.MAX_FETCH_SIZE
   ,SDD_CLA_rec.SQL_ALIAS
   ,SDD_CLA_rec.USE_CASE_REF
   ,SDD_CLA_rec.ACTOR_REF
   ,SDD_CLA_rec.O8I_TARGET_FLAG
   ,SDD_CLA_rec.VISIBROKER_TARGET_FLAG
   ,SDD_CLA_rec.EJB_TARGET_FLAG
   ,SDD_CLA_rec.REALIZATION_OF
   ,SDD_CLA_rec.EMBEDABLE_VALIDATOR
   ,SDD_CLA_rec.CLASSIFIER_SUBTYPE
   ,SDD_CLA_rec.PRIMITIVE_FLAG
   ,SDD_CLA_rec.SYSTEM_ELEMENT_FLAG
   ,SDD_CLA_rec.DATATYPE_FORMAT
  );
  jr_reg_ver.vercopy_dependencies(SDD_CLA_ver.irid, SDD_CLA_ver.ivid, new_ivid, null, copy_dependencies);
  for SDD_AMCAMC_rec1 in SDD_AMCAMC_cur1 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_AMCAMC
    values (
       SDD_AMCAMC_rec1.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_AMCAMC_rec1.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_AMCAMC_rec1.TYPES
     , SDD_AMCAMC_rec1.ELEMENT_TYPE_NAME
     , SDD_AMCAMC_rec1.DATE_CREATED
     , SDD_AMCAMC_rec1.CREATED_BY
     , SDD_AMCAMC_rec1.DATE_CHANGED
     , SDD_AMCAMC_rec1.CHANGED_BY
     , SDD_AMCAMC_rec1.NOTM
     , SDD_AMCAMC_rec1.PARENT_APP_MODULE_REF
     , SDD_AMCAMC_rec1.CHILD_APP_MODULE_REF
     , SDD_AMCAMC_rec1.ROLE_NAME
     , SDD_AMCAMC_rec1.SAME_TRANSACTION_FLAG
    );
  jr_reg_ver.vercopy_dependencies(SDD_AMCAMC_rec1.irid, SDD_AMCAMC_rec1.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_AMCBOB_rec2 in SDD_AMCBOB_cur2 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_AMCBOB
    values (
       SDD_AMCBOB_rec2.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_AMCBOB_rec2.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_AMCBOB_rec2.TYPES
     , SDD_AMCBOB_rec2.ELEMENT_TYPE_NAME
     , SDD_AMCBOB_rec2.DATE_CREATED
     , SDD_AMCBOB_rec2.CREATED_BY
     , SDD_AMCBOB_rec2.DATE_CHANGED
     , SDD_AMCBOB_rec2.CHANGED_BY
     , SDD_AMCBOB_rec2.NOTM
     , SDD_AMCBOB_rec2.APPLICATION_MODULE_REF
     , SDD_AMCBOB_rec2.BUSINESS_OBJECT_REF
    );
  jr_reg_ver.vercopy_dependencies(SDD_AMCBOB_rec2.irid, SDD_AMCBOB_rec2.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_AMCPRJ_rec3 in SDD_AMCPRJ_cur3 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_AMCPRJ
    values (
       SDD_AMCPRJ_rec3.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_AMCPRJ_rec3.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_AMCPRJ_rec3.TYPES
     , SDD_AMCPRJ_rec3.ELEMENT_TYPE_NAME
     , SDD_AMCPRJ_rec3.DATE_CREATED
     , SDD_AMCPRJ_rec3.CREATED_BY
     , SDD_AMCPRJ_rec3.DATE_CHANGED
     , SDD_AMCPRJ_rec3.CHANGED_BY
     , SDD_AMCPRJ_rec3.NOTM
     , SDD_AMCPRJ_rec3.APPLICATION_MODULE_REF
     , SDD_AMCPRJ_rec3.PROJECT_REF
     , SDD_AMCPRJ_rec3.REMOTE_TARGET_TYPE
    );
  jr_reg_ver.vercopy_dependencies(SDD_AMCPRJ_rec3.irid, SDD_AMCPRJ_rec3.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_CAT_rec4 in SDD_CAT_cur4 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_CAT
    values (
       SDD_CAT_rec4.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_CAT_rec4.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_CAT_rec4.TYPES
     , SDD_CAT_rec4.ELEMENT_TYPE_NAME
     , SDD_CAT_rec4.DATE_CREATED
     , SDD_CAT_rec4.CREATED_BY
     , SDD_CAT_rec4.DATE_CHANGED
     , SDD_CAT_rec4.CHANGED_BY
     , SDD_CAT_rec4.NOTM
     , SDD_CAT_rec4.GENERIC_CLASS_REF
     , SDD_CAT_rec4.VIEW_OBJECT_REF
     , SDD_CAT_rec4.ENTITY_OBJECT_REF
     , SDD_CAT_rec4.EVENT_CLASSIFIER_REF
     , SDD_CAT_rec4.INTERFACE_CLASSIFIER_REF
     , SDD_CAT_rec4.GENERAL_ATTRIBUTE_FOR
     , SDD_CAT_rec4.ATTRIBUTE_DOMAIN_REF
     , SDD_CAT_rec4.MINIMUM_MULTIPLICITY
     , SDD_CAT_rec4.NAME
     , SDD_CAT_rec4.CHANGE_RESTRICTION
     , SDD_CAT_rec4.MAXIMUM_MULTIPLICITY
     , SDD_CAT_rec4.CLASSIFIER_ATTRIBUTE_SUBTYPE
     , SDD_CAT_rec4.CLASSIFIER_REF
     , SDD_CAT_rec4.SERIALIZABLE_FLAG
     , SDD_CAT_rec4.DATATYPE_FORMAT
     , SDD_CAT_rec4.VOLATILE_FLAG
     , SDD_CAT_rec4.DECIMAL_PLACES
     , SDD_CAT_rec4.DEFAULT_VALUE
     , SDD_CAT_rec4.DISPLAY_FLAG
     , SDD_CAT_rec4.GENERATE_CLASS_MEMBER_FLAG
     , SDD_CAT_rec4.SQL_ALIAS
     , SDD_CAT_rec4.PROGRAMMED_UPDATE_FLAG
     , SDD_CAT_rec4.ENTITY_OBJECT_USAGE_REF
     , SDD_CAT_rec4.EO_ATTRIBUTE_REF
     , SDD_CAT_rec4.MAXIMUM_LENGTH
     , SDD_CAT_rec4.PROMPT
     , SDD_CAT_rec4.SCALAR_DATATYPE
     , SDD_CAT_rec4.SEQUENCE
     , SDD_CAT_rec4.STATIC_FLAG
     , SDD_CAT_rec4.VISIBILITY
     , SDD_CAT_rec4.MODIFICATION_FLAG
     , SDD_CAT_rec4.DEFAULT_COLUMN_DATATYPE
     , SDD_CAT_rec4.DEFAULT_COLUMN_NAME
     , SDD_CAT_rec4.PERSISTENT_FLAG
     , SDD_CAT_rec4.JDBC_TYPE
     , SDD_CAT_rec4.PSEUDOCOLUMN_FLAG
     , SDD_CAT_rec4.COLLECT_CLASSSIFIER_REF
     , SDD_CAT_rec4.SORT_ORDER_DIRECTION
     , SDD_CAT_rec4.SORT_ORDER_SEQUENCE
     , SDD_CAT_rec4.CREATABLE_FLAG
     , SDD_CAT_rec4.RETRIEVABLE_FLAG
     , SDD_CAT_rec4.UPDATABLE_FLAG
     , SDD_CAT_rec4.DELETABLE_FLAG
     , SDD_CAT_rec4.DEFAULT_DB_COLLECTION_NAME
     , SDD_CAT_rec4.DB_COLLECTION_AS_REFS_FLAG
    );
  jr_reg_ver.vercopy_dependencies(SDD_CAT_rec4.irid, SDD_CAT_rec4.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_ADR_rec5 in SDD_ADR_cur5 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_ADR
    values (
       SDD_ADR_rec5.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_ADR_rec5.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_ADR_rec5.TYPES
     , SDD_ADR_rec5.ELEMENT_TYPE_NAME
     , SDD_ADR_rec5.DATE_CREATED
     , SDD_ADR_rec5.CREATED_BY
     , SDD_ADR_rec5.DATE_CHANGED
     , SDD_ADR_rec5.CHANGED_BY
     , SDD_ADR_rec5.NOTM
     , SDD_ADR_rec5.CLASSIFIER_ATTRIBUTE_REF
     , SDD_ADR_rec5.NAME
     , SDD_ADR_rec5.CONTEXT
     , SDD_ADR_rec5.METHOD_REF
     , SDD_ADR_rec5.LANGUAGE_REF
    );
  jr_reg_ver.vercopy_dependencies(SDD_ADR_rec5.irid, SDD_ADR_rec5.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_MEMCOM_rec6 in SDD_MEMCOM_cur6 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_MEMCOM
    values (
       SDD_MEMCOM_rec6.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_MEMCOM_rec6.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_MEMCOM_rec6.TYPES
     , SDD_MEMCOM_rec6.ELEMENT_TYPE_NAME
     , SDD_MEMCOM_rec6.DATE_CREATED
     , SDD_MEMCOM_rec6.CREATED_BY
     , SDD_MEMCOM_rec6.DATE_CHANGED
     , SDD_MEMCOM_rec6.CHANGED_BY
     , SDD_MEMCOM_rec6.NOTM
     , SDD_MEMCOM_rec6.NAMED_RULE_REF
     , SDD_MEMCOM_rec6.INTEGRITY_RULE_REF
     , SDD_MEMCOM_rec6.CROSS_OBJECT_RULE_REF
     , SDD_MEMCOM_rec6.STATE_RULE_REF
     , SDD_MEMCOM_rec6.ATTRIBUTE_DERIV_RULE_REF
     , SDD_MEMCOM_rec6.CLASSIFIER_ATTRIBUTE_REF
     , SDD_MEMCOM_rec6.ASSOCIATION_END_REF
     , SDD_MEMCOM_rec6.METHOD_REF
     , SDD_MEMCOM_rec6.MEMBER_COMPONENT_OF
     , SDD_MEMCOM_rec6.MEMBER_COMPONENT_IN
    );
  jr_reg_ver.vercopy_dependencies(SDD_MEMCOM_rec6.irid, SDD_MEMCOM_rec6.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_CATEAT_rec7 in SDD_CATEAT_cur7 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_CATEAT
    values (
       SDD_CATEAT_rec7.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_CATEAT_rec7.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_CATEAT_rec7.TYPES
     , SDD_CATEAT_rec7.ELEMENT_TYPE_NAME
     , SDD_CATEAT_rec7.DATE_CREATED
     , SDD_CATEAT_rec7.CREATED_BY
     , SDD_CATEAT_rec7.DATE_CHANGED
     , SDD_CATEAT_rec7.CHANGED_BY
     , SDD_CATEAT_rec7.NOTM
     , SDD_CATEAT_rec7.GENERAL_ATTRIBUTE_REF
     , SDD_CATEAT_rec7.EO_ATTRIBUTE_REF
    );
  jr_reg_ver.vercopy_dependencies(SDD_CATEAT_rec7.irid, SDD_CATEAT_rec7.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_CLAAEN_rec8 in SDD_CLAAEN_cur8 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_CLAAEN
    values (
       SDD_CLAAEN_rec8.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_CLAAEN_rec8.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_CLAAEN_rec8.TYPES
     , SDD_CLAAEN_rec8.ELEMENT_TYPE_NAME
     , SDD_CLAAEN_rec8.DATE_CREATED
     , SDD_CLAAEN_rec8.CREATED_BY
     , SDD_CLAAEN_rec8.DATE_CHANGED
     , SDD_CLAAEN_rec8.CHANGED_BY
     , SDD_CLAAEN_rec8.NOTM
     , SDD_CLAAEN_rec8.INTERFACE_CLASSIFIER_REF
     , SDD_CLAAEN_rec8.ASSOCIATION_END_REF
    );
  jr_reg_ver.vercopy_dependencies(SDD_CLAAEN_rec8.irid, SDD_CLAAEN_rec8.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_CLACLA_rec9 in SDD_CLACLA_cur9 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_CLACLA
    values (
       SDD_CLACLA_rec9.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_CLACLA_rec9.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_CLACLA_rec9.TYPES
     , SDD_CLACLA_rec9.ELEMENT_TYPE_NAME
     , SDD_CLACLA_rec9.DATE_CREATED
     , SDD_CLACLA_rec9.CREATED_BY
     , SDD_CLACLA_rec9.DATE_CHANGED
     , SDD_CLACLA_rec9.CHANGED_BY
     , SDD_CLACLA_rec9.NOTM
     , SDD_CLACLA_rec9.SUBTYPE_REF
     , SDD_CLACLA_rec9.SUPERTYPE_REF
     , SDD_CLACLA_rec9.SEQUENCE
     , SDD_CLACLA_rec9.SPEC_GROUP_REF
     , SDD_CLACLA_rec9.VISIBILITY
    );
  jr_reg_ver.vercopy_dependencies(SDD_CLACLA_rec9.irid, SDD_CLACLA_rec9.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_CLAEVC_rec10 in SDD_CLAEVC_cur10 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_CLAEVC
    values (
       SDD_CLAEVC_rec10.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_CLAEVC_rec10.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_CLAEVC_rec10.TYPES
     , SDD_CLAEVC_rec10.ELEMENT_TYPE_NAME
     , SDD_CLAEVC_rec10.DATE_CREATED
     , SDD_CLAEVC_rec10.CREATED_BY
     , SDD_CLAEVC_rec10.DATE_CHANGED
     , SDD_CLAEVC_rec10.CHANGED_BY
     , SDD_CLAEVC_rec10.NOTM
     , SDD_CLAEVC_rec10.CLASSIFIER_REF
     , SDD_CLAEVC_rec10.EVENT_CLASSIFIER_REF
    );
  jr_reg_ver.vercopy_dependencies(SDD_CLAEVC_rec10.irid, SDD_CLAEVC_rec10.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_CLAINC_rec11 in SDD_CLAINC_cur11 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_CLAINC
    values (
       SDD_CLAINC_rec11.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_CLAINC_rec11.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_CLAINC_rec11.TYPES
     , SDD_CLAINC_rec11.ELEMENT_TYPE_NAME
     , SDD_CLAINC_rec11.DATE_CREATED
     , SDD_CLAINC_rec11.CREATED_BY
     , SDD_CLAINC_rec11.DATE_CHANGED
     , SDD_CLAINC_rec11.CHANGED_BY
     , SDD_CLAINC_rec11.NOTM
     , SDD_CLAINC_rec11.CLASSIFIER_REF
     , SDD_CLAINC_rec11.INTERFACE_CLASSIFIER_REF
     , SDD_CLAINC_rec11.SEQUENCE
     , SDD_CLAINC_rec11.VISIBILITY
     , SDD_CLAINC_rec11.INTERFACE_TYPE
     , SDD_CLAINC_rec11.INTERFACE_USAGE_BY
    );
  jr_reg_ver.vercopy_dependencies(SDD_CLAINC_rec11.irid, SDD_CLAINC_rec11.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_CRU_rec12 in SDD_CRU_cur12 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_CRU
    values (
       SDD_CRU_rec12.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_CRU_rec12.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_CRU_rec12.TYPES
     , SDD_CRU_rec12.ELEMENT_TYPE_NAME
     , SDD_CRU_rec12.DATE_CREATED
     , SDD_CRU_rec12.CREATED_BY
     , SDD_CRU_rec12.DATE_CHANGED
     , SDD_CRU_rec12.CHANGED_BY
     , SDD_CRU_rec12.NOTM
     , SDD_CRU_rec12.ENTITY_OBJECT_REF
     , SDD_CRU_rec12.GENERIC_CLASS_REF
     , SDD_CRU_rec12.VIEW_OBJECT_REF
     , SDD_CRU_rec12.CLASSIFIER_ATTRIBUTE_REF
     , SDD_CRU_rec12.INTERFACE_CLASSIFIER_REF
     , SDD_CRU_rec12.NAME
     , SDD_CRU_rec12.CONTEXT
     , SDD_CRU_rec12.SHORT_DESCRIPTION
     , SDD_CRU_rec12.METHOD_REF
     , SDD_CRU_rec12.LANGUAGE_REF
     , SDD_CRU_rec12.DESIGNATED_PRIMARY_KEY_FLAG
     , SDD_CRU_rec12.DATABASE_CHECK_CONSTRAINT_FLAG
     , SDD_CRU_rec12.SEQUENCE
     , SDD_CRU_rec12.VALIDATOR_OPERATOR
     , SDD_CRU_rec12.CLASSIFIER_RULE_SUBTYPE
     , SDD_CRU_rec12.CLASSIFIER_RULE_FOR
    );
  jr_reg_ver.vercopy_dependencies(SDD_CRU_rec12.irid, SDD_CRU_rec12.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_DATCOM_rec13 in SDD_DATCOM_cur13 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_DATCOM
    values (
       SDD_DATCOM_rec13.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_DATCOM_rec13.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_DATCOM_rec13.TYPES
     , SDD_DATCOM_rec13.ELEMENT_TYPE_NAME
     , SDD_DATCOM_rec13.DATE_CREATED
     , SDD_DATCOM_rec13.CREATED_BY
     , SDD_DATCOM_rec13.DATE_CHANGED
     , SDD_DATCOM_rec13.CHANGED_BY
     , SDD_DATCOM_rec13.NOTM
     , SDD_DATCOM_rec13.UNIQUENESS_RULE_REF
     , SDD_DATCOM_rec13.ARC_RULE_REF
     , SDD_DATCOM_rec13.CLASSIFIER_ATTRIBUTE_REF
     , SDD_DATCOM_rec13.ASSOCIATION_END_REF
     , SDD_DATCOM_rec13.SEQUENCE
     , SDD_DATCOM_rec13.DATA_COMPONENT_OF
     , SDD_DATCOM_rec13.DATA_COMPONENT_IN
    );
  jr_reg_ver.vercopy_dependencies(SDD_DATCOM_rec13.irid, SDD_DATCOM_rec13.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_VAL_rec14 in SDD_VAL_cur14 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_VAL
    values (
       SDD_VAL_rec14.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_VAL_rec14.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_VAL_rec14.TYPES
     , SDD_VAL_rec14.ELEMENT_TYPE_NAME
     , SDD_VAL_rec14.DATE_CREATED
     , SDD_VAL_rec14.CREATED_BY
     , SDD_VAL_rec14.DATE_CHANGED
     , SDD_VAL_rec14.CHANGED_BY
     , SDD_VAL_rec14.NOTM
     , SDD_VAL_rec14.ATTRIBUTE_DOMAIN_REF
     , SDD_VAL_rec14.INTEGRITY_RULE_REF
     , SDD_VAL_rec14.NAME
     , SDD_VAL_rec14.GENERIC_CLASS_REF
     , SDD_VAL_rec14.INVERSE_FLAG
     , SDD_VAL_rec14.SEQUENCE
     , SDD_VAL_rec14.RULE_IMPLEMENTATION
     , SDD_VAL_rec14.BC4J_VALIDATION_TYPE
     , SDD_VAL_rec14.VALIDATOR_USAGE_BY
    );
  jr_reg_ver.vercopy_dependencies(SDD_VAL_rec14.irid, SDD_VAL_rec14.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_VALGAT_rec15 in SDD_VALGAT_cur15 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_VALGAT
    values (
       SDD_VALGAT_rec15.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_VALGAT_rec15.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_VALGAT_rec15.TYPES
     , SDD_VALGAT_rec15.ELEMENT_TYPE_NAME
     , SDD_VALGAT_rec15.DATE_CREATED
     , SDD_VALGAT_rec15.CREATED_BY
     , SDD_VALGAT_rec15.DATE_CHANGED
     , SDD_VALGAT_rec15.CHANGED_BY
     , SDD_VALGAT_rec15.NOTM
     , SDD_VALGAT_rec15.GENERAL_ATTRIBUTE_REF
     , SDD_VALGAT_rec15.VALIDATOR_REF
     , SDD_VALGAT_rec15.VALUE
     , SDD_VALGAT_rec15.MEANING
     , SDD_VALGAT_rec15.SEQUENCE
    );
  jr_reg_ver.vercopy_dependencies(SDD_VALGAT_rec15.irid, SDD_VALGAT_rec15.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_CSG_rec16 in SDD_CSG_cur16 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_CSG
    values (
       SDD_CSG_rec16.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_CSG_rec16.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_CSG_rec16.TYPES
     , SDD_CSG_rec16.ELEMENT_TYPE_NAME
     , SDD_CSG_rec16.DATE_CREATED
     , SDD_CSG_rec16.CREATED_BY
     , SDD_CSG_rec16.DATE_CHANGED
     , SDD_CSG_rec16.CHANGED_BY
     , SDD_CSG_rec16.NOTM
     , SDD_CSG_rec16.CLASSIFIER_REF
     , SDD_CSG_rec16.NAME
     , SDD_CSG_rec16.OVERLAPPING_FLAG
     , SDD_CSG_rec16.COMPLETE_FLAG
    );
  jr_reg_ver.vercopy_dependencies(SDD_CSG_rec16.irid, SDD_CSG_rec16.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_EOU_rec17 in SDD_EOU_cur17 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_EOU
    values (
       SDD_EOU_rec17.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_EOU_rec17.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_EOU_rec17.TYPES
     , SDD_EOU_rec17.ELEMENT_TYPE_NAME
     , SDD_EOU_rec17.DATE_CREATED
     , SDD_EOU_rec17.CREATED_BY
     , SDD_EOU_rec17.DATE_CHANGED
     , SDD_EOU_rec17.CHANGED_BY
     , SDD_EOU_rec17.NOTM
     , SDD_EOU_rec17.VIEW_OBJECT_REF
     , SDD_EOU_rec17.NAME
     , SDD_EOU_rec17.ENTITY_OBJECT_REF
     , SDD_EOU_rec17.SEQUENCE_NUMBER
     , SDD_EOU_rec17.SQL_ALIAS
     , SDD_EOU_rec17.PRIMARY_FLAG
     , SDD_EOU_rec17.REQUERY_FLAG
    );
  jr_reg_ver.vercopy_dependencies(SDD_EOU_rec17.irid, SDD_EOU_rec17.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_AEU_rec18 in SDD_AEU_cur18 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_AEU
    values (
       SDD_AEU_rec18.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_AEU_rec18.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_AEU_rec18.TYPES
     , SDD_AEU_rec18.ELEMENT_TYPE_NAME
     , SDD_AEU_rec18.DATE_CREATED
     , SDD_AEU_rec18.CREATED_BY
     , SDD_AEU_rec18.DATE_CHANGED
     , SDD_AEU_rec18.CHANGED_BY
     , SDD_AEU_rec18.NOTM
     , SDD_AEU_rec18.ENTITY_OBJECT_USAGE_REF
     , SDD_AEU_rec18.ASSOCIATION_END_REF
     , SDD_AEU_rec18.ASSOC_END_USAGE_REF
    );
  jr_reg_ver.vercopy_dependencies(SDD_AEU_rec18.irid, SDD_AEU_rec18.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_EVS_rec19 in SDD_EVS_cur19 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_EVS
    values (
       SDD_EVS_rec19.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_EVS_rec19.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_EVS_rec19.TYPES
     , SDD_EVS_rec19.ELEMENT_TYPE_NAME
     , SDD_EVS_rec19.DATE_CREATED
     , SDD_EVS_rec19.CREATED_BY
     , SDD_EVS_rec19.DATE_CHANGED
     , SDD_EVS_rec19.CHANGED_BY
     , SDD_EVS_rec19.NOTM
     , SDD_EVS_rec19.CLASSIFIER_REF
     , SDD_EVS_rec19.EVENT_CLASSIFIER_REF
     , SDD_EVS_rec19.SCOPE
     , SDD_EVS_rec19.UML_TYPE_FLAG
    );
  jr_reg_ver.vercopy_dependencies(SDD_EVS_rec19.irid, SDD_EVS_rec19.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_SUD_rec20 in SDD_SUD_cur20 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_SUD
    values (
       SDD_SUD_rec20.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_SUD_rec20.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_SUD_rec20.TYPES
     , SDD_SUD_rec20.ELEMENT_TYPE_NAME
     , SDD_SUD_rec20.DATE_CREATED
     , SDD_SUD_rec20.CREATED_BY
     , SDD_SUD_rec20.DATE_CHANGED
     , SDD_SUD_rec20.CHANGED_BY
     , SDD_SUD_rec20.NOTM
     , SDD_SUD_rec20.EVENT_SUBSCRIPTION_REF
     , SDD_SUD_rec20.EVENT_PUBLICATION_REF
     , SDD_SUD_rec20.ASSOCIATION_END_REF
     , SDD_SUD_rec20.SCOPE
    );
  jr_reg_ver.vercopy_dependencies(SDD_SUD_rec20.irid, SDD_SUD_rec20.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_FILPAC_rec21 in SDD_FILPAC_cur21 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_FILPAC
    values (
       SDD_FILPAC_rec21.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_FILPAC_rec21.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_FILPAC_rec21.TYPES
     , SDD_FILPAC_rec21.ELEMENT_TYPE_NAME
     , SDD_FILPAC_rec21.DATE_CREATED
     , SDD_FILPAC_rec21.CREATED_BY
     , SDD_FILPAC_rec21.DATE_CHANGED
     , SDD_FILPAC_rec21.CHANGED_BY
     , SDD_FILPAC_rec21.NOTM
     , SDD_FILPAC_rec21.ASSOCIATION_REF
     , SDD_FILPAC_rec21.CLASSIFIER_REF
     , SDD_FILPAC_rec21.DIAGRAM_REF
     , SDD_FILPAC_rec21.VIEW_LINK_REF
     , SDD_FILPAC_rec21.PRIMARY_ACCESS_FILE_REF
     , SDD_FILPAC_rec21.TYPE
     , SDD_FILPAC_rec21.OUT_OF_SYNC_FLAG
     , SDD_FILPAC_rec21.VERSION
     , SDD_FILPAC_rec21.OS_TIMESTAMP
     , SDD_FILPAC_rec21.FILE_USAGE_FOR
     , SDD_FILPAC_rec21.CRC
    );
  jr_reg_ver.vercopy_dependencies(SDD_FILPAC_rec21.irid, SDD_FILPAC_rec21.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_FSE_rec22 in SDD_FSE_cur22 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_FSE
    values (
       SDD_FSE_rec22.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_FSE_rec22.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_FSE_rec22.TYPES
     , SDD_FSE_rec22.ELEMENT_TYPE_NAME
     , SDD_FSE_rec22.DATE_CREATED
     , SDD_FSE_rec22.CREATED_BY
     , SDD_FSE_rec22.DATE_CHANGED
     , SDD_FSE_rec22.CHANGED_BY
     , SDD_FSE_rec22.NOTM
     , SDD_FSE_rec22.CLASSIFIER_REF
     , SDD_FSE_rec22.LANGUAGE_NAME
     , SDD_FSE_rec22.CODE_SECTION_TYPE
     , SDD_FSE_rec22.SEQUENCE_NUMBER
     , SDD_FSE_rec22.PRIMARY_ACCESS_FILE_REF
    );
  jr_reg_ver.vercopy_dependencies(SDD_FSE_rec22.irid, SDD_FSE_rec22.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_MET_rec23 in SDD_MET_cur23 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_MET
    values (
       SDD_MET_rec23.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_MET_rec23.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_MET_rec23.TYPES
     , SDD_MET_rec23.ELEMENT_TYPE_NAME
     , SDD_MET_rec23.DATE_CREATED
     , SDD_MET_rec23.CREATED_BY
     , SDD_MET_rec23.DATE_CHANGED
     , SDD_MET_rec23.CHANGED_BY
     , SDD_MET_rec23.NOTM
     , SDD_MET_rec23.CLASSIFIER_REF
     , SDD_MET_rec23.NAME
     , SDD_MET_rec23.SEQUENCE
     , SDD_MET_rec23.VISIBILITY
     , SDD_MET_rec23.MODIFIES_STATE_FLAG
     , SDD_MET_rec23.CONSTRUCTOR_FLAG
     , SDD_MET_rec23.STATIC_FLAG
     , SDD_MET_rec23.IMPLEMENTATION_TIER
     , SDD_MET_rec23.OVERRIDABLE
     , SDD_MET_rec23.OVERRIDING_METHOD_REF
     , SDD_MET_rec23.ELEVATED_METHOD_REF
     , SDD_MET_rec23.NATIVE_FLAG
     , SDD_MET_rec23.SYNCHRONIZED_FLAG
     , SDD_MET_rec23.EXPORTED_FLAG
     , SDD_MET_rec23.RETURN_TYPE_SCALAR
     , SDD_MET_rec23.RETURN_CLASSIFIER_REF
     , SDD_MET_rec23.COLLECT_CLASSIFIER_REF
     , SDD_MET_rec23.RETURN_COLLECTION_SIZE
     , SDD_MET_rec23.RETURN_TYPE_DEFINED_BY
     , SDD_MET_rec23.INTERNAL_NAME
    );
  jr_reg_ver.vercopy_dependencies(SDD_MET_rec23.irid, SDD_MET_rec23.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_EVH_rec24 in SDD_EVH_cur24 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_EVH
    values (
       SDD_EVH_rec24.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_EVH_rec24.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_EVH_rec24.TYPES
     , SDD_EVH_rec24.ELEMENT_TYPE_NAME
     , SDD_EVH_rec24.DATE_CREATED
     , SDD_EVH_rec24.CREATED_BY
     , SDD_EVH_rec24.DATE_CHANGED
     , SDD_EVH_rec24.CHANGED_BY
     , SDD_EVH_rec24.NOTM
     , SDD_EVH_rec24.METHOD_REF
     , SDD_EVH_rec24.EVENT_SUBSCRIPTION_REF
     , SDD_EVH_rec24.PRIMARY_FLAG
     , SDD_EVH_rec24.SUBSCRIPTION_DETAIL_REF
     , SDD_EVH_rec24.DEFAULT_SEQUENCE_NUMBER
     , SDD_EVH_rec24.EVENT_HANDLER_FOR
    );
  jr_reg_ver.vercopy_dependencies(SDD_EVH_rec24.irid, SDD_EVH_rec24.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_CMA_rec25 in SDD_CMA_cur25 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_CMA
    values (
       SDD_CMA_rec25.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_CMA_rec25.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_CMA_rec25.TYPES
     , SDD_CMA_rec25.ELEMENT_TYPE_NAME
     , SDD_CMA_rec25.DATE_CREATED
     , SDD_CMA_rec25.CREATED_BY
     , SDD_CMA_rec25.DATE_CHANGED
     , SDD_CMA_rec25.CHANGED_BY
     , SDD_CMA_rec25.NOTM
     , SDD_CMA_rec25.EVENT_RAISER_REF
     , SDD_CMA_rec25.EVENT_HANDLER_REF
     , SDD_CMA_rec25.CLASSIFIER_ATTRIBUTE_REF
     , SDD_CMA_rec25.EVENT_CLASSIFIER_REF
     , SDD_CMA_rec25.CLASSIFIER_ATT_FROM_REF
     , SDD_CMA_rec25.ASSOCIATION_END_REF
     , SDD_CMA_rec25.METHOD_PARAMETER_REF
     , SDD_CMA_rec25.EVENT_RAISER_FROM_REF
     , SDD_CMA_rec25.PASSED_VALUE
     , SDD_CMA_rec25.CONTEXT_MAPPING_FROM
     , SDD_CMA_rec25.CONTEXT_MAPPING_TO
     , SDD_CMA_rec25.CONTEXT_MAPPING_FOR
    );
  jr_reg_ver.vercopy_dependencies(SDD_CMA_rec25.irid, SDD_CMA_rec25.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_EVR_rec26 in SDD_EVR_cur26 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_EVR
    values (
       SDD_EVR_rec26.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_EVR_rec26.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_EVR_rec26.TYPES
     , SDD_EVR_rec26.ELEMENT_TYPE_NAME
     , SDD_EVR_rec26.DATE_CREATED
     , SDD_EVR_rec26.CREATED_BY
     , SDD_EVR_rec26.DATE_CHANGED
     , SDD_EVR_rec26.CHANGED_BY
     , SDD_EVR_rec26.NOTM
     , SDD_EVR_rec26.METHOD_REF
     , SDD_EVR_rec26.EVENT_PUBLICATION_REF
     , SDD_EVR_rec26.OCCURRENCES
     , SDD_EVR_rec26.SEQUENCE
    );
  jr_reg_ver.vercopy_dependencies(SDD_EVR_rec26.irid, SDD_EVR_rec26.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_METRUL_rec27 in SDD_METRUL_cur27 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_METRUL
    values (
       SDD_METRUL_rec27.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_METRUL_rec27.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_METRUL_rec27.TYPES
     , SDD_METRUL_rec27.ELEMENT_TYPE_NAME
     , SDD_METRUL_rec27.DATE_CREATED
     , SDD_METRUL_rec27.CREATED_BY
     , SDD_METRUL_rec27.DATE_CHANGED
     , SDD_METRUL_rec27.CHANGED_BY
     , SDD_METRUL_rec27.NOTM
     , SDD_METRUL_rec27.NAMED_RULE_REF
     , SDD_METRUL_rec27.CLASSIFIER_RULE_REF
     , SDD_METRUL_rec27.METHOD_REF
     , SDD_METRUL_rec27.CALL_TYPE
     , SDD_METRUL_rec27.STATE_RULE_REF
     , SDD_METRUL_rec27.ATTRIBUTE_DERIV_RULE_REF
     , SDD_METRUL_rec27.CROSS_OBJECT_RULE_REF
     , SDD_METRUL_rec27.SEQUENCE
     , SDD_METRUL_rec27.INLINE_FLAG
     , SDD_METRUL_rec27.METHOD_RULE_USAGE_OF
    );
  jr_reg_ver.vercopy_dependencies(SDD_METRUL_rec27.irid, SDD_METRUL_rec27.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_MPA_rec28 in SDD_MPA_cur28 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_MPA
    values (
       SDD_MPA_rec28.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_MPA_rec28.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_MPA_rec28.TYPES
     , SDD_MPA_rec28.ELEMENT_TYPE_NAME
     , SDD_MPA_rec28.DATE_CREATED
     , SDD_MPA_rec28.CREATED_BY
     , SDD_MPA_rec28.DATE_CHANGED
     , SDD_MPA_rec28.CHANGED_BY
     , SDD_MPA_rec28.NOTM
     , SDD_MPA_rec28.METHOD_REF
     , SDD_MPA_rec28.NAME
     , SDD_MPA_rec28.SEQUENCE
     , SDD_MPA_rec28.SCALAR_DATATYPE
     , SDD_MPA_rec28.CLASSIFIER_REF
     , SDD_MPA_rec28.CALL_TYPE
     , SDD_MPA_rec28.DEFAULT_VALUE
     , SDD_MPA_rec28.COLLECT_CLASSIFIER_REF
     , SDD_MPA_rec28.COLLECTION_SIZE
     , SDD_MPA_rec28.DATATYPE_FORMAT
    );
  jr_reg_ver.vercopy_dependencies(SDD_MPA_rec28.irid, SDD_MPA_rec28.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_SBA_rec29 in SDD_SBA_cur29 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_SBA
    values (
       SDD_SBA_rec29.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_SBA_rec29.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_SBA_rec29.TYPES
     , SDD_SBA_rec29.ELEMENT_TYPE_NAME
     , SDD_SBA_rec29.DATE_CREATED
     , SDD_SBA_rec29.CREATED_BY
     , SDD_SBA_rec29.DATE_CHANGED
     , SDD_SBA_rec29.CHANGED_BY
     , SDD_SBA_rec29.NOTM
     , SDD_SBA_rec29.METHOD_REF
     , SDD_SBA_rec29.EVENT_SUBSCRIPTION_REF
     , SDD_SBA_rec29.SUBSCRIPTION_DETAIL_REF
     , SDD_SBA_rec29.START_OR_STOP
     , SDD_SBA_rec29.SEQUENCE
     , SDD_SBA_rec29.EVENT_ACTIVATION_OF
    );
  jr_reg_ver.vercopy_dependencies(SDD_SBA_rec29.irid, SDD_SBA_rec29.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_OST_rec30 in SDD_OST_cur30 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_OST
    values (
       SDD_OST_rec30.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_OST_rec30.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_OST_rec30.TYPES
     , SDD_OST_rec30.ELEMENT_TYPE_NAME
     , SDD_OST_rec30.DATE_CREATED
     , SDD_OST_rec30.CREATED_BY
     , SDD_OST_rec30.DATE_CHANGED
     , SDD_OST_rec30.CHANGED_BY
     , SDD_OST_rec30.NOTM
     , SDD_OST_rec30.CLASSIFIER_REF
     , SDD_OST_rec30.BUSINESS_OBJECT_REF
     , SDD_OST_rec30.NAME
     , SDD_OST_rec30.WORKFLOW_ITEM_TYPE_REF
     , SDD_OST_rec30.WORKFLOW_MESS_TYPE_REF
     , SDD_OST_rec30.ICON_FILE_REF
     , SDD_OST_rec30.OBJECT_STATE_FOR
    );
  jr_reg_ver.vercopy_dependencies(SDD_OST_rec30.irid, SDD_OST_rec30.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_OSTOST_rec31 in SDD_OSTOST_cur31 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_OSTOST
    values (
       SDD_OSTOST_rec31.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_OSTOST_rec31.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_OSTOST_rec31.TYPES
     , SDD_OSTOST_rec31.ELEMENT_TYPE_NAME
     , SDD_OSTOST_rec31.DATE_CREATED
     , SDD_OSTOST_rec31.CREATED_BY
     , SDD_OSTOST_rec31.DATE_CHANGED
     , SDD_OSTOST_rec31.CHANGED_BY
     , SDD_OSTOST_rec31.NOTM
     , SDD_OSTOST_rec31.OBJECT_STATE_OF_REF
     , SDD_OSTOST_rec31.OBJECT_STATE_ON_REF
    );
  jr_reg_ver.vercopy_dependencies(SDD_OSTOST_rec31.irid, SDD_OSTOST_rec31.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_SRU_rec32 in SDD_SRU_cur32 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_SRU
    values (
       SDD_SRU_rec32.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_SRU_rec32.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_SRU_rec32.TYPES
     , SDD_SRU_rec32.ELEMENT_TYPE_NAME
     , SDD_SRU_rec32.DATE_CREATED
     , SDD_SRU_rec32.CREATED_BY
     , SDD_SRU_rec32.DATE_CHANGED
     , SDD_SRU_rec32.CHANGED_BY
     , SDD_SRU_rec32.NOTM
     , SDD_SRU_rec32.OBJECT_STATE_REF
     , SDD_SRU_rec32.NAME
     , SDD_SRU_rec32.CONTEXT
     , SDD_SRU_rec32.METHOD_REF
     , SDD_SRU_rec32.LANGUAGE_REF
    );
  jr_reg_ver.vercopy_dependencies(SDD_SRU_rec32.irid, SDD_SRU_rec32.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_TRA_rec33 in SDD_TRA_cur33 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_TRA
    values (
       SDD_TRA_rec33.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_TRA_rec33.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_TRA_rec33.TYPES
     , SDD_TRA_rec33.ELEMENT_TYPE_NAME
     , SDD_TRA_rec33.DATE_CREATED
     , SDD_TRA_rec33.CREATED_BY
     , SDD_TRA_rec33.DATE_CHANGED
     , SDD_TRA_rec33.CHANGED_BY
     , SDD_TRA_rec33.NOTM
     , SDD_TRA_rec33.SOURCE_ACTIVITY_REF
     , SDD_TRA_rec33.SOURCE_ACT_USAGE_REF
     , SDD_TRA_rec33.SOURCE_EVENT_REF
     , SDD_TRA_rec33.SOURCE_OBJECT_STATE_REF
     , SDD_TRA_rec33.SOURCE_PSEUDOSTATE_REF
     , SDD_TRA_rec33.TARGET_ACTIVITY_REF
     , SDD_TRA_rec33.TARGET_ACT_USAGE_REF
     , SDD_TRA_rec33.TARGET_EVENT_REF
     , SDD_TRA_rec33.TARGET_OBJECT_STATE_REF
     , SDD_TRA_rec33.TARGET_PSEUDOSTATE_REF
     , SDD_TRA_rec33.SEQUENCE_NUMBER
     , SDD_TRA_rec33.NAMED_RULE_REF
     , SDD_TRA_rec33.PRIMARY_FLAG
     , SDD_TRA_rec33.TRANSITION_REF
     , SDD_TRA_rec33.EVENT_PUBLICATION_REF
     , SDD_TRA_rec33.EVENT_SUBSCRIPTION_REF
     , SDD_TRA_rec33.CREATABLE_FLAG
     , SDD_TRA_rec33.MESSAGING_AUDIT
     , SDD_TRA_rec33.CHANNEL_NAME
     , SDD_TRA_rec33.RETRIEVABLE_FLAG
     , SDD_TRA_rec33.CHANNEL_TYPE
     , SDD_TRA_rec33.UPDATABLE_FLAG
     , SDD_TRA_rec33.AUTOMATIC_INVOCATION_FLAG
     , SDD_TRA_rec33.DELETABLE_FLAG
     , SDD_TRA_rec33.TRIGGERING_FLAG
     , SDD_TRA_rec33.ACTIVITY_SIGNATURE_FLAG
     , SDD_TRA_rec33.TRIGGER_EVENT_REF
     , SDD_TRA_rec33.SOURCE_TYPE
     , SDD_TRA_rec33.TARGET_TYPE
    );
  jr_reg_ver.vercopy_dependencies(SDD_TRA_rec33.irid, SDD_TRA_rec33.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_VLU_rec34 in SDD_VLU_cur34 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_VLU
    values (
       SDD_VLU_rec34.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_VLU_rec34.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_VLU_rec34.TYPES
     , SDD_VLU_rec34.ELEMENT_TYPE_NAME
     , SDD_VLU_rec34.DATE_CREATED
     , SDD_VLU_rec34.CREATED_BY
     , SDD_VLU_rec34.DATE_CHANGED
     , SDD_VLU_rec34.CHANGED_BY
     , SDD_VLU_rec34.NOTM
     , SDD_VLU_rec34.APPLICATION_MODULE_REF
     , SDD_VLU_rec34.NAME
     , SDD_VLU_rec34.VIEW_LINK_REF
    );
  jr_reg_ver.vercopy_dependencies(SDD_VLU_rec34.irid, SDD_VLU_rec34.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_VLEU_rec35 in SDD_VLEU_cur35 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_VLEU
    values (
       SDD_VLEU_rec35.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_VLEU_rec35.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_VLEU_rec35.TYPES
     , SDD_VLEU_rec35.ELEMENT_TYPE_NAME
     , SDD_VLEU_rec35.DATE_CREATED
     , SDD_VLEU_rec35.CREATED_BY
     , SDD_VLEU_rec35.DATE_CHANGED
     , SDD_VLEU_rec35.CHANGED_BY
     , SDD_VLEU_rec35.NOTM
     , SDD_VLEU_rec35.VIEW_LINK_USAGE_REF
     , SDD_VLEU_rec35.VIEW_LINK_END_REF
     , SDD_VLEU_rec35.VIEW_USAGE_REF
    );
  jr_reg_ver.vercopy_dependencies(SDD_VLEU_rec35.irid, SDD_VLEU_rec35.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_VOU_rec36 in SDD_VOU_cur36 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_VOU
    values (
       SDD_VOU_rec36.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_VOU_rec36.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_VOU_rec36.TYPES
     , SDD_VOU_rec36.ELEMENT_TYPE_NAME
     , SDD_VOU_rec36.DATE_CREATED
     , SDD_VOU_rec36.CREATED_BY
     , SDD_VOU_rec36.DATE_CHANGED
     , SDD_VOU_rec36.CHANGED_BY
     , SDD_VOU_rec36.NOTM
     , SDD_VOU_rec36.APPLICATION_MODULE_REF
     , SDD_VOU_rec36.NAME
     , SDD_VOU_rec36.VIEW_OBJECT_REF
    );
  jr_reg_ver.vercopy_dependencies(SDD_VOU_rec36.irid, SDD_VOU_rec36.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  jr_reg_ver.vercopy_dependent_objects(SDD_CLA_ver.ivid, new_ivid);
  return new_ivid;
end SDD_CLA_ver;
/
create or replace function PK_SDD_CLA (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_CLA the_tab_new, SDD_CLA the_tab_old
  where  the_tab_new.ivid = PK_SDD_CLA.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_CLA.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_CLA;
/
create or replace function FK_CLA_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_CLA the_tab
  where  the_tab.ivid = FK_CLA_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_CLA_TO_ACR;
/
create or replace function FK_CLA_TO_BOB (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.BUSINESS_OBJECT_REF ref_value
  from   i$SDD_CLA the_tab
  where  the_tab.ivid = FK_CLA_TO_BOB.object_ivid
  and    the_tab.BUSINESS_OBJECT_REF is not null
  and    not exists (
             select null
             from   SDD_BOB foreign_tab
             where  the_tab.BUSINESS_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
                                   , 5076, action);
  end loop;
  return is_ok;
end FK_CLA_TO_BOB;
/
create or replace function FK_CLA_TO_CLA (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.CLASSIFIER_REF ref_value
  from   i$SDD_CLA the_tab
  where  the_tab.ivid = FK_CLA_TO_CLA.object_ivid
  and    the_tab.CLASSIFIER_REF is not null
  and    not exists (
             select null
             from   SDD_CLA foreign_tab
             where  the_tab.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_CLA_TO_CLA;
/
create or replace function FK_CLA_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_CLA the_tab
  where  the_tab.ivid = FK_CLA_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_CLA_TO_FILES;
/
create or replace function FK_CLA_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_CLA the_tab
  where  the_tab.ivid = FK_CLA_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_CLA_TO_GEC;
/
create or replace function FK_CLA_TO_INC (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.INTERFACE_CLASSIFIER_REF ref_value
  from   i$SDD_CLA the_tab
  where  the_tab.ivid = FK_CLA_TO_INC.object_ivid
  and    the_tab.INTERFACE_CLASSIFIER_REF is not null
  and    not exists (
             select null
             from   SDD_CLA foreign_tab
             where  the_tab.INTERFACE_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_CLA_TO_INC;
/
create or replace function FK_CLA_TO_OST (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.OBJECT_STATE_REF ref_value
  from   i$SDD_CLA the_tab
  where  the_tab.ivid = FK_CLA_TO_OST.object_ivid
  and    the_tab.OBJECT_STATE_REF is not null
  and    not exists (
             select null
             from   SDD_OST foreign_tab
             where  the_tab.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_CLA_TO_OST;
/
create or replace function FK_CLA_TO_USC (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.USE_CASE_REF ref_value
  from   i$SDD_CLA the_tab
  where  the_tab.ivid = FK_CLA_TO_USC.object_ivid
  and    the_tab.USE_CASE_REF is not null
  and    not exists (
             select null
             from   SDD_USC foreign_tab
             where  the_tab.USE_CASE_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_CLA_TO_USC;
/
create or replace function PK_SDD_CLAAEN (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_CLAAEN the_tab_new, SDD_CLAAEN the_tab_old
  where  the_tab_new.ivid = PK_SDD_CLAAEN.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_CLAAEN.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_CLAAEN;
/
create or replace function FK_CLAAEN_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_CLAAEN the_tab
  where  the_tab.ivid = FK_CLAAEN_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_CLAAEN_TO_AEN;
/
create or replace function PK_SDD_CLACLA (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_CLACLA the_tab_new, SDD_CLACLA the_tab_old
  where  the_tab_new.ivid = PK_SDD_CLACLA.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_CLACLA.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_CLACLA;
/
create or replace function UK_CLACLA_2 (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_CLACLA the_tab_new, SDD_CLACLA the_tab_old
  where  the_tab_new.ivid = UK_CLACLA_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_CLACLA_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_CLACLA_2;
/
create or replace function FK_CLACLA_TO_CLA2 (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_CLACLA the_tab
  where  the_tab.ivid = FK_CLACLA_TO_CLA2.object_ivid
  and    the_tab.SUPERTYPE_REF is not null
  and    not exists (
             select null
             from   SDD_CLA 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
                                   , 4841, action);
  end loop;
  return is_ok;
end FK_CLACLA_TO_CLA2;
/
create or replace function FK_CLACLA_TO_CSG (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.SPEC_GROUP_REF ref_value
  from   i$SDD_CLACLA the_tab
  where  the_tab.ivid = FK_CLACLA_TO_CSG.object_ivid
  and    the_tab.SPEC_GROUP_REF is not null
  and    not exists (
             select null
             from   SDD_CSG foreign_tab
             where  the_tab.SPEC_GROUP_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
                                   , 5069, action);
  end loop;
  return is_ok;
end FK_CLACLA_TO_CSG;
/
create or replace function FK_EVR_TO_CLAEVC_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_EVR child_tab, i$SDD_CLAEVC parent_tab
  where  parent_tab.parent_ivid=FK_EVR_TO_CLAEVC_cmd.ivid
  and    child_tab.EVENT_PUBLICATION_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_EVR child_tab
          ,i$SDD_CLAEVC parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_EVR_TO_CLAEVC_cmd.ivid
       and child_tab.EVENT_PUBLICATION_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_EVR_TO_CLAEVC_cmd;
/
create or replace function FK_EVR_TO_CLAEVC_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_EVR child_tab
  where  child_tab.EVENT_PUBLICATION_REF=FK_EVR_TO_CLAEVC_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_EVR child_tab, i$sdd_object_versions o
    where  child_tab.EVENT_PUBLICATION_REF=FK_EVR_TO_CLAEVC_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_EVR_TO_CLAEVC_d;
/
create or replace function PK_SDD_CLAEVC (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_CLAEVC the_tab_new, SDD_CLAEVC the_tab_old
  where  the_tab_new.ivid = PK_SDD_CLAEVC.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_CLAEVC.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_CLAEVC;
/
create or replace function FK_CLAEVC_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_CLAEVC the_tab
  where  the_tab.ivid = FK_CLAEVC_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_CLAEVC_TO_EVC;
/
create or replace function PK_SDD_CLAINC (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_CLAINC the_tab_new, SDD_CLAINC the_tab_old
  where  the_tab_new.ivid = PK_SDD_CLAINC.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_CLAINC.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_CLAINC;
/
create or replace function FK_CLAINC_TO_INC (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.INTERFACE_CLASSIFIER_REF ref_value
  from   i$SDD_CLAINC the_tab
  where  the_tab.ivid = FK_CLAINC_TO_INC.object_ivid
  and    the_tab.INTERFACE_CLASSIFIER_REF is not null
  and    not exists (
             select null
             from   SDD_CLA foreign_tab
             where  the_tab.INTERFACE_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_CLAINC_TO_INC;
/
create or replace function PK_SDD_CMA (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_CMA the_tab_new, SDD_CMA the_tab_old
  where  the_tab_new.ivid = PK_SDD_CMA.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_CMA.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_CMA;
/
create or replace function FK_CMA_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_CMA the_tab
  where  the_tab.ivid = FK_CMA_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_CMA_TO_AEN;
/
create or replace function FK_CMA_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_CMA the_tab
  where  the_tab.ivid = FK_CMA_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_CMA_TO_CAT;
/
create or replace function FK_CMA_TO_CAT2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.CLASSIFIER_ATT_FROM_REF ref_value
  from   i$SDD_CMA the_tab
  where  the_tab.ivid = FK_CMA_TO_CAT2.object_ivid
  and    the_tab.CLASSIFIER_ATT_FROM_REF is not null
  and    not exists (
             select null
             from   SDD_CAT foreign_tab
             where  the_tab.CLASSIFIER_ATT_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
                                   , 5066, action);
  end loop;
  return is_ok;
end FK_CMA_TO_CAT2;
/
create or replace function FK_CMA_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_CMA the_tab
  where  the_tab.ivid = FK_CMA_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_CMA_TO_EVC;
/
create or replace function FK_CMA_TO_EVR2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.EVENT_RAISER_FROM_REF ref_value
  from   i$SDD_CMA the_tab
  where  the_tab.ivid = FK_CMA_TO_EVR2.object_ivid
  and    the_tab.EVENT_RAISER_FROM_REF is not null
  and    not exists (
             select null
             from   SDD_EVR foreign_tab
             where  the_tab.EVENT_RAISER_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
                                   , 5082, action);
  end loop;
  return is_ok;
end FK_CMA_TO_EVR2;
/
create or replace function FK_CMA_TO_MPA (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.METHOD_PARAMETER_REF ref_value
  from   i$SDD_CMA the_tab
  where  the_tab.ivid = FK_CMA_TO_MPA.object_ivid
  and    the_tab.METHOD_PARAMETER_REF is not null
  and    not exists (
             select null
             from   SDD_MPA foreign_tab
             where  the_tab.METHOD_PARAMETER_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
                                   , 5070, action);
  end loop;
  return is_ok;
end FK_CMA_TO_MPA;
/
create or replace function PK_SDD_CNU (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_CNU the_tab_new, SDD_CNU the_tab_old
  where  the_tab_new.ivid = PK_SDD_CNU.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_CNU.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_CNU;
/
create or replace function FK_CNU_TO_OCO (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.CONSTRAINT_REF ref_value
  from   i$SDD_CNU the_tab
  where  the_tab.ivid = FK_CNU_TO_OCO.object_ivid
  and    the_tab.CONSTRAINT_REF is not null
  and    not exists (
             select null
             from   SDD_OCO foreign_tab
             where  the_tab.CONSTRAINT_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
                                   , 5027, action);
  end loop;
  return is_ok;
end FK_CNU_TO_OCO;
/
create or replace function PK_SDD_COB (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_COB the_tab_new, SDD_COB the_tab_old
  where  the_tab_new.ivid = PK_SDD_COB.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_COB.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_COB;
/
create or replace function FK_ITE_TO_COL_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_ITE child_tab, i$SDD_COL parent_tab
  where  parent_tab.parent_ivid=FK_ITE_TO_COL_cmd.ivid
  and    child_tab.COLUMN_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_ITE child_tab
          ,i$SDD_COL parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_ITE_TO_COL_cmd.ivid
       and child_tab.COLUMN_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_ITE_TO_COL_cmd;
/
create or replace function FK_ITE_TO_COL_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_ITE child_tab
  where  child_tab.COLUMN_REF=FK_ITE_TO_COL_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_ITE child_tab, i$sdd_object_versions o
    where  child_tab.COLUMN_REF=FK_ITE_TO_COL_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_ITE_TO_COL_d;
/
create or replace function FK_ITM_TO_COL_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_COL parent_tab
  where  parent_tab.parent_ivid=FK_ITM_TO_COL_cmd.ivid
  and    child_tab.COLUMN_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_COL parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_ITM_TO_COL_cmd.ivid
       and child_tab.COLUMN_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_COL_cmd;
/
create or replace function FK_ITM_TO_COL_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.COLUMN_REF=FK_ITM_TO_COL_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.COLUMN_REF=FK_ITM_TO_COL_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_COL_d;
/
create or replace function FK_OKY_TO_COL2_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_OKY child_tab, i$SDD_COL parent_tab
  where  parent_tab.parent_ivid=FK_OKY_TO_COL2_cmd.ivid
  and    child_tab.FOREIGN_COLUMN_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_OKY child_tab
          ,i$SDD_COL parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_OKY_TO_COL2_cmd.ivid
       and child_tab.FOREIGN_COLUMN_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_OKY_TO_COL2_cmd;
/
create or replace function FK_OKY_TO_COL2_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_OKY child_tab
  where  child_tab.FOREIGN_COLUMN_REF=FK_OKY_TO_COL2_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_OKY child_tab, i$sdd_object_versions o
    where  child_tab.FOREIGN_COLUMN_REF=FK_OKY_TO_COL2_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_OKY_TO_COL2_d;
/
create or replace function FK_TABENT_TO_COL_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_TABENT child_tab, i$SDD_COL parent_tab
  where  parent_tab.parent_ivid=FK_TABENT_TO_COL_cmd.ivid
  and    child_tab.COLUMN_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_TABENT child_tab
          ,i$SDD_COL parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_TABENT_TO_COL_cmd.ivid
       and child_tab.COLUMN_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_TABENT_TO_COL_cmd;
/
create or replace function FK_TABENT_TO_COL_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_TABENT child_tab
  where  child_tab.COLUMN_REF=FK_TABENT_TO_COL_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_TABENT child_tab, i$sdd_object_versions o
    where  child_tab.COLUMN_REF=FK_TABENT_TO_COL_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_TABENT_TO_COL_d;
/
create or replace function FK_TRGCOL_TO_COL_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_TRGCOL child_tab, i$SDD_COL parent_tab
  where  parent_tab.parent_ivid=FK_TRGCOL_TO_COL_cmd.ivid
  and    child_tab.COLUMN_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_TRGCOL child_tab
          ,i$SDD_COL parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_TRGCOL_TO_COL_cmd.ivid
       and child_tab.COLUMN_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_TRGCOL_TO_COL_cmd;
/
create or replace function FK_TRGCOL_TO_COL_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_TRGCOL child_tab
  where  child_tab.COLUMN_REF=FK_TRGCOL_TO_COL_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_TRGCOL child_tab, i$sdd_object_versions o
    where  child_tab.COLUMN_REF=FK_TRGCOL_TO_COL_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_TRGCOL_TO_COL_d;
/
create or replace function PK_SDD_COL (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_COL the_tab_new, SDD_COL the_tab_old
  where  the_tab_new.ivid = PK_SDD_COL.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_COL.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_COL;
/
create or replace function FK_COL_TO_ATT (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.SOURCE_ATTRIBUTE_REF ref_value
  from   i$SDD_COL the_tab
  where  the_tab.ivid = FK_COL_TO_ATT.object_ivid
  and    the_tab.SOURCE_ATTRIBUTE_REF is not null
  and    not exists (
             select null
             from   SDD_ATT foreign_tab
             where  the_tab.SOURCE_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
                                   , 5010, action);
  end loop;
  return is_ok;
end FK_COL_TO_ATT;
/
create or replace function FK_COL_TO_CCD (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.CLUSTER_COLUMN_REF ref_value
  from   i$SDD_COL the_tab
  where  the_tab.ivid = FK_COL_TO_CCD.object_ivid
  and    the_tab.CLUSTER_COLUMN_REF is not null
  and    not exists (
             select null
             from   SDD_CCD foreign_tab
             where  the_tab.CLUSTER_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
                                   , 5032, action);
  end loop;
  return is_ok;
end FK_COL_TO_CCD;
/
create or replace function FK_COL_TO_COL (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.BASE_COLUMN_REF ref_value
  from   i$SDD_COL the_tab
  where  the_tab.ivid = FK_COL_TO_COL.object_ivid
  and    the_tab.BASE_COLUMN_REF is not null
  and    not exists (
             select null
             from   SDD_COL foreign_tab
             where  the_tab.BASE_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_COL_TO_COL;
/
create or replace function FK_COL_TO_COL2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.COLUMN_DENORMALISED_FROM ref_value
  from   i$SDD_COL the_tab
  where  the_tab.ivid = FK_COL_TO_COL2.object_ivid
  and    the_tab.COLUMN_DENORMALISED_FROM is not null
  and    not exists (
             select null
             from   SDD_COL foreign_tab
             where  the_tab.COLUMN_DENORMALISED_FROM = 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_COL_TO_COL2;
/
create or replace function FK_COL_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_COL the_tab
  where  the_tab.ivid = FK_COL_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_COL_TO_DOM;
/
create or replace function FK_COL_TO_JCO (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.CONSTRAINT_DENORMALISED_VIA ref_value
  from   i$SDD_COL the_tab
  where  the_tab.ivid = FK_COL_TO_JCO.object_ivid
  and    the_tab.CONSTRAINT_DENORMALISED_VIA is not null
  and    not exists (
             select null
             from   SDD_OCO foreign_tab
             where  the_tab.CONSTRAINT_DENORMALISED_VIA = 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
                                   , 5027, action);
  end loop;
  return is_ok;
end FK_COL_TO_JCO;
/
create or replace function FK_COL_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_COL the_tab
  where  the_tab.ivid = FK_COL_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_COL_TO_ORT;
/
create or replace function FK_COL_TO_OSQ (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.SEQUENCE_REF ref_value
  from   i$SDD_COL the_tab
  where  the_tab.ivid = FK_COL_TO_OSQ.object_ivid
  and    the_tab.SEQUENCE_REF is not null
  and    not exists (
             select null
             from   SDD_OSQ foreign_tab
             where  the_tab.SEQUENCE_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
                                   , 4999, action);
  end loop;
  return is_ok;
end FK_COL_TO_OSQ;
/
create or replace function FK_COL_TO_TBL (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.SCOPE_TABLE_REF ref_value
  from   i$SDD_COL the_tab
  where  the_tab.ivid = FK_COL_TO_TBL.object_ivid
  and    the_tab.SCOPE_TABLE_REF is not null
  and    not exists (
             select null
             from   SDD_TAB foreign_tab
             where  the_tab.SCOPE_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_COL_TO_TBL;
/
create or replace function FK_COL_TO_VWTAB (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.RELATION_SELECTION_REF ref_value
  from   i$SDD_COL the_tab
  where  the_tab.ivid = FK_COL_TO_VWTAB.object_ivid
  and    the_tab.RELATION_SELECTION_REF is not null
  and    not exists (
             select null
             from   SDD_VWTAB foreign_tab
             where  the_tab.RELATION_SELECTION_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
                                   , 5026, action);
  end loop;
  return is_ok;
end FK_COL_TO_VWTAB;
/
create or replace function SDD_COM_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_COM_cur is
    select *
    from   i$SDD_COM the_tab
    where  the_tab.irid=SDD_COM_ver.irid
    and    the_tab.ivid=SDD_COM_ver.ivid;
  SDD_COM_rec SDD_COM_cur%ROWTYPE;
  cursor SDD_COMNOD_cur1 is
    select *
    from i$SDD_COMNOD the_tab
    where the_tab.parent_ivid=SDD_COM_ver.ivid;
  cursor SDD_COMODB_cur2 is
    select *
    from i$SDD_COMODB the_tab
    where the_tab.parent_ivid=SDD_COM_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_COM_cur;
  fetch SDD_COM_cur into SDD_COM_rec;
  close SDD_COM_cur;
  insert into i$SDD_COM
  values (
    SDD_COM_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_COM_rec.TYPES
   ,SDD_COM_rec.ELEMENT_TYPE_NAME
   ,SDD_COM_rec.DATE_CREATED
   ,SDD_COM_rec.CREATED_BY
   ,SDD_COM_rec.DATE_CHANGED
   ,SDD_COM_rec.CHANGED_BY
   ,SDD_COM_rec.NOTM
   ,SDD_COM_rec.NAME
   ,SDD_COM_rec.PROTOCOL
   ,SDD_COM_rec.REMARK
   ,SDD_COM_rec.USRX0
   ,SDD_COM_rec.USRX1
   ,SDD_COM_rec.USRX2
   ,SDD_COM_rec.USRX3
   ,SDD_COM_rec.USRX4
   ,SDD_COM_rec.USRX5
   ,SDD_COM_rec.USRX6
   ,SDD_COM_rec.USRX7
   ,SDD_COM_rec.USRX8
   ,SDD_COM_rec.USRX9
   ,SDD_COM_rec.USRX10
   ,SDD_COM_rec.USRX11
   ,SDD_COM_rec.USRX12
   ,SDD_COM_rec.USRX13
   ,SDD_COM_rec.USRX14
   ,SDD_COM_rec.USRX15
   ,SDD_COM_rec.USRX16
   ,SDD_COM_rec.USRX17
   ,SDD_COM_rec.USRX18
   ,SDD_COM_rec.USRX19
  );
  jr_reg_ver.vercopy_dependencies(SDD_COM_ver.irid, SDD_COM_ver.ivid, new_ivid, null, copy_dependencies);
  for SDD_COMNOD_rec1 in SDD_COMNOD_cur1 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_COMNOD
    values (
       SDD_COMNOD_rec1.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_COMNOD_rec1.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_COMNOD_rec1.TYPES
     , SDD_COMNOD_rec1.ELEMENT_TYPE_NAME
     , SDD_COMNOD_rec1.DATE_CREATED
     , SDD_COMNOD_rec1.CREATED_BY
     , SDD_COMNOD_rec1.DATE_CHANGED
     , SDD_COMNOD_rec1.CHANGED_BY
     , SDD_COMNOD_rec1.NOTM
     , SDD_COMNOD_rec1.COMMUNITY_REF
     , SDD_COMNOD_rec1.NODE_REF
     , SDD_COMNOD_rec1.USRX0
     , SDD_COMNOD_rec1.USRX1
     , SDD_COMNOD_rec1.USRX2
     , SDD_COMNOD_rec1.USRX3
     , SDD_COMNOD_rec1.USRX4
     , SDD_COMNOD_rec1.USRX5
     , SDD_COMNOD_rec1.USRX6
     , SDD_COMNOD_rec1.USRX7
     , SDD_COMNOD_rec1.USRX8
     , SDD_COMNOD_rec1.USRX9
     , SDD_COMNOD_rec1.USRX10
     , SDD_COMNOD_rec1.USRX11
     , SDD_COMNOD_rec1.USRX12
     , SDD_COMNOD_rec1.USRX13
     , SDD_COMNOD_rec1.USRX14
     , SDD_COMNOD_rec1.USRX15
     , SDD_COMNOD_rec1.USRX16
     , SDD_COMNOD_rec1.USRX17
     , SDD_COMNOD_rec1.USRX18
     , SDD_COMNOD_rec1.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_COMNOD_rec1.irid, SDD_COMNOD_rec1.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_COMODB_rec2 in SDD_COMODB_cur2 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_COMODB
    values (
       SDD_COMODB_rec2.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_COMODB_rec2.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_COMODB_rec2.TYPES
     , SDD_COMODB_rec2.ELEMENT_TYPE_NAME
     , SDD_COMODB_rec2.DATE_CREATED
     , SDD_COMODB_rec2.CREATED_BY
     , SDD_COMODB_rec2.DATE_CHANGED
     , SDD_COMODB_rec2.CHANGED_BY
     , SDD_COMODB_rec2.NOTM
     , SDD_COMODB_rec2.COMMUNITY_REF
     , SDD_COMODB_rec2.ORACLE_DATABASE_REF
     , SDD_COMODB_rec2.USRX0
     , SDD_COMODB_rec2.USRX1
     , SDD_COMODB_rec2.USRX2
     , SDD_COMODB_rec2.USRX3
     , SDD_COMODB_rec2.USRX4
     , SDD_COMODB_rec2.USRX5
     , SDD_COMODB_rec2.USRX6
     , SDD_COMODB_rec2.USRX7
     , SDD_COMODB_rec2.USRX8
     , SDD_COMODB_rec2.USRX9
     , SDD_COMODB_rec2.USRX10
     , SDD_COMODB_rec2.USRX11
     , SDD_COMODB_rec2.USRX12
     , SDD_COMODB_rec2.USRX13
     , SDD_COMODB_rec2.USRX14
     , SDD_COMODB_rec2.USRX15
     , SDD_COMODB_rec2.USRX16
     , SDD_COMODB_rec2.USRX17
     , SDD_COMODB_rec2.USRX18
     , SDD_COMODB_rec2.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_COMODB_rec2.irid, SDD_COMODB_rec2.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  jr_reg_ver.vercopy_dependent_objects(SDD_COM_ver.ivid, new_ivid);
  return new_ivid;
end SDD_COM_ver;
/
create or replace function PK_SDD_COM (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_COM the_tab_new, SDD_COM the_tab_old
  where  the_tab_new.ivid = PK_SDD_COM.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_COM.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_COM;
/
create or replace function PK_SDD_COMNOD (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_COMNOD the_tab_new, SDD_COMNOD the_tab_old
  where  the_tab_new.ivid = PK_SDD_COMNOD.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_COMNOD.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_COMNOD;
/
create or replace function FK_COMNOD_TO_E20 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.NODE_REF ref_value
  from   i$SDD_COMNOD the_tab
  where  the_tab.ivid = FK_COMNOD_TO_E20.object_ivid
  and    the_tab.NODE_REF is not null
  and    not exists (
             select null
             from   SDD_E20 foreign_tab
             where  the_tab.NODE_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
                                   , 4961, action);
  end loop;
  return is_ok;
end FK_COMNOD_TO_E20;
/
create or replace function PK_SDD_COMODB (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_COMODB the_tab_new, SDD_COMODB the_tab_old
  where  the_tab_new.ivid = PK_SDD_COMODB.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_COMODB.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_COMODB;
/
create or replace function FK_COMODB_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_COMODB the_tab
  where  the_tab.ivid = FK_COMODB_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_COMODB_TO_ORC;
/
create or replace function SDD_COR_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_COR_cur is
    select *
    from   i$SDD_COR the_tab
    where  the_tab.irid=SDD_COR_ver.irid
    and    the_tab.ivid=SDD_COR_ver.ivid;
  SDD_COR_rec SDD_COR_cur%ROWTYPE;
  cursor SDD_CORI_cur1 is
    select *
    from i$SDD_CORI the_tab
    where the_tab.parent_ivid=SDD_COR_ver.ivid;
  cursor SDD_MEMCOM_cur2 is
    select *
    from i$SDD_MEMCOM the_tab
    where the_tab.parent_ivid=SDD_COR_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_COR_cur;
  fetch SDD_COR_cur into SDD_COR_rec;
  close SDD_COR_cur;
  insert into i$SDD_COR
  values (
    SDD_COR_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_COR_rec.TYPES
   ,SDD_COR_rec.ELEMENT_TYPE_NAME
   ,SDD_COR_rec.DATE_CREATED
   ,SDD_COR_rec.CREATED_BY
   ,SDD_COR_rec.DATE_CHANGED
   ,SDD_COR_rec.CHANGED_BY
   ,SDD_COR_rec.NOTM
   ,SDD_COR_rec.NAME
   ,SDD_COR_rec.SHORT_DESCRIPTION
  );
  jr_reg_ver.vercopy_dependencies(SDD_COR_ver.irid, SDD_COR_ver.ivid, new_ivid, null, copy_dependencies);
  for SDD_CORI_rec1 in SDD_CORI_cur1 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_CORI
    values (
       SDD_CORI_rec1.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_CORI_rec1.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_CORI_rec1.TYPES
     , SDD_CORI_rec1.ELEMENT_TYPE_NAME
     , SDD_CORI_rec1.DATE_CREATED
     , SDD_CORI_rec1.CREATED_BY
     , SDD_CORI_rec1.DATE_CHANGED
     , SDD_CORI_rec1.CHANGED_BY
     , SDD_CORI_rec1.NOTM
     , SDD_CORI_rec1.CLASSIFIER_ATTRIBUTE_REF
     , SDD_CORI_rec1.CROSS_OBJECT_RULE_REF
     , SDD_CORI_rec1.OPERATOR
     , SDD_CORI_rec1.CONTEXT
     , SDD_CORI_rec1.METHOD_REF
     , SDD_CORI_rec1.LANGUAGE_REF
    );
  jr_reg_ver.vercopy_dependencies(SDD_CORI_rec1.irid, SDD_CORI_rec1.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_MEMCOM_rec2 in SDD_MEMCOM_cur2 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_MEMCOM
    values (
       SDD_MEMCOM_rec2.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_MEMCOM_rec2.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_MEMCOM_rec2.TYPES
     , SDD_MEMCOM_rec2.ELEMENT_TYPE_NAME
     , SDD_MEMCOM_rec2.DATE_CREATED
     , SDD_MEMCOM_rec2.CREATED_BY
     , SDD_MEMCOM_rec2.DATE_CHANGED
     , SDD_MEMCOM_rec2.CHANGED_BY
     , SDD_MEMCOM_rec2.NOTM
     , SDD_MEMCOM_rec2.NAMED_RULE_REF
     , SDD_MEMCOM_rec2.INTEGRITY_RULE_REF
     , SDD_MEMCOM_rec2.CROSS_OBJECT_RULE_REF
     , SDD_MEMCOM_rec2.STATE_RULE_REF
     , SDD_MEMCOM_rec2.ATTRIBUTE_DERIV_RULE_REF
     , SDD_MEMCOM_rec2.CLASSIFIER_ATTRIBUTE_REF
     , SDD_MEMCOM_rec2.ASSOCIATION_END_REF
     , SDD_MEMCOM_rec2.METHOD_REF
     , SDD_MEMCOM_rec2.MEMBER_COMPONENT_OF
     , SDD_MEMCOM_rec2.MEMBER_COMPONENT_IN
    );
  jr_reg_ver.vercopy_dependencies(SDD_MEMCOM_rec2.irid, SDD_MEMCOM_rec2.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  jr_reg_ver.vercopy_dependent_objects(SDD_COR_ver.ivid, new_ivid);
  return new_ivid;
end SDD_COR_ver;
/
create or replace function PK_SDD_COR (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_COR the_tab_new, SDD_COR the_tab_old
  where  the_tab_new.ivid = PK_SDD_COR.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_COR.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_COR;
/
create or replace function PK_SDD_CORI (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_CORI the_tab_new, SDD_CORI the_tab_old
  where  the_tab_new.ivid = PK_SDD_CORI.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_CORI.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_CORI;
/
create or replace function FK_CORI_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_CORI the_tab
  where  the_tab.ivid = FK_CORI_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_CORI_TO_CAT;
/
create or replace function FK_CORI_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_CORI the_tab
  where  the_tab.ivid = FK_CORI_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_CORI_TO_LAN;
/
create or replace function FK_CORI_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_CORI the_tab
  where  the_tab.ivid = FK_CORI_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_CORI_TO_MET;
/
create or replace function FK_ITM_TO_CQA_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_CQA parent_tab
  where  parent_tab.parent_ivid=FK_ITM_TO_CQA_cmd.ivid
  and    child_tab.CQA_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_CQA parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_ITM_TO_CQA_cmd.ivid
       and child_tab.CQA_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_CQA_cmd;
/
create or replace function FK_ITM_TO_CQA_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.CQA_REF=FK_ITM_TO_CQA_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.CQA_REF=FK_ITM_TO_CQA_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_CQA_d;
/
create or replace function FK_OKY_TO_CQA2_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_OKY child_tab, i$SDD_CQA parent_tab
  where  parent_tab.parent_ivid=FK_OKY_TO_CQA2_cmd.ivid
  and    child_tab.FOREIGN_CQA_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_OKY child_tab
          ,i$SDD_CQA parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_OKY_TO_CQA2_cmd.ivid
       and child_tab.FOREIGN_CQA_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_OKY_TO_CQA2_cmd;
/
create or replace function FK_OKY_TO_CQA2_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_OKY child_tab
  where  child_tab.FOREIGN_CQA_REF=FK_OKY_TO_CQA2_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_OKY child_tab, i$sdd_object_versions o
    where  child_tab.FOREIGN_CQA_REF=FK_OKY_TO_CQA2_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_OKY_TO_CQA2_d;
/
create or replace function PK_SDD_CQA (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_CQA the_tab_new, SDD_CQA the_tab_old
  where  the_tab_new.ivid = PK_SDD_CQA.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_CQA.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_CQA;
/
create or replace function FK_CQA_TO_CCD (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.CLUSTER_COLUMN_REF ref_value
  from   i$SDD_CQA the_tab
  where  the_tab.ivid = FK_CQA_TO_CCD.object_ivid
  and    the_tab.CLUSTER_COLUMN_REF is not null
  and    not exists (
             select null
             from   SDD_CCD foreign_tab
             where  the_tab.CLUSTER_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
                                   , 5032, action);
  end loop;
  return is_ok;
end FK_CQA_TO_CCD;
/
create or replace function FK_CQA_TO_TBL2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.SCOPE_TABLE_REF ref_value
  from   i$SDD_CQA the_tab
  where  the_tab.ivid = FK_CQA_TO_TBL2.object_ivid
  and    the_tab.SCOPE_TABLE_REF is not null
  and    not exists (
             select null
             from   SDD_TAB foreign_tab
             where  the_tab.SCOPE_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_CQA_TO_TBL2;
/
create or replace function PK_SDD_CQACOL (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_CQACOL the_tab_new, SDD_CQACOL the_tab_old
  where  the_tab_new.ivid = PK_SDD_CQACOL.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_CQACOL.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_CQACOL;
/
create or replace function FK_CQACOL_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_CQACOL the_tab
  where  the_tab.ivid = FK_CQACOL_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_CQACOL_TO_COL;
/
create or replace function PK_SDD_CRU (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_CRU the_tab_new, SDD_CRU the_tab_old
  where  the_tab_new.ivid = PK_SDD_CRU.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_CRU.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_CRU;
/
create or replace function FK_CRU_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_CRU the_tab
  where  the_tab.ivid = FK_CRU_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_CRU_TO_CAT;
/
create or replace function FK_CRU_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_CRU the_tab
  where  the_tab.ivid = FK_CRU_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_CRU_TO_LAN;
/
create or replace function FK_CRU_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_CRU the_tab
  where  the_tab.ivid = FK_CRU_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_CRU_TO_MET;
/
create or replace function PK_SDD_CSG (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_CSG the_tab_new, SDD_CSG the_tab_old
  where  the_tab_new.ivid = PK_SDD_CSG.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_CSG.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_CSG;
/
create or replace function PK_SDD_CST (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_CST the_tab_new, SDD_CST the_tab_old
  where  the_tab_new.ivid = PK_SDD_CST.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_CST.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_CST;
/
create or replace function FK_CST_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_CST the_tab
  where  the_tab.ivid = FK_CST_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_CST_TO_COL;
/
create or replace function FK_CST_TO_CQA (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.CQA_REF ref_value
  from   i$SDD_CST the_tab
  where  the_tab.ivid = FK_CST_TO_CQA.object_ivid
  and    the_tab.CQA_REF is not null
  and    not exists (
             select null
             from   SDD_CQA foreign_tab
             where  the_tab.CQA_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
                                   , 4856, action);
  end loop;
  return is_ok;
end FK_CST_TO_CQA;
/
create or replace function FK_CST_TO_LST (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.LOB_STORAGE_REF ref_value
  from   i$SDD_CST the_tab
  where  the_tab.ivid = FK_CST_TO_LST.object_ivid
  and    the_tab.LOB_STORAGE_REF is not null
  and    not exists (
             select null
             from   SDD_LST foreign_tab
             where  the_tab.LOB_STORAGE_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
                                   , 4859, action);
  end loop;
  return is_ok;
end FK_CST_TO_LST;
/
create or replace function FK_CST_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_CST the_tab
  where  the_tab.ivid = FK_CST_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_CST_TO_OSP;
/
create or replace function FK_CST_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_CST the_tab
  where  the_tab.ivid = FK_CST_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_CST_TO_OTB;
/
create or replace function FK_ARG_TO_DAT_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_ARG child_tab, i$SDD_DAT parent_tab
  where  parent_tab.parent_ivid=FK_ARG_TO_DAT_cmd.ivid
  and    child_tab.DATASTRUCTURE_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_ARG child_tab
          ,i$SDD_DAT parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_ARG_TO_DAT_cmd.ivid
       and child_tab.DATASTRUCTURE_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_ARG_TO_DAT_cmd;
/
create or replace function FK_ARG_TO_DAT_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_ARG child_tab
  where  child_tab.DATASTRUCTURE_REF=FK_ARG_TO_DAT_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_ARG child_tab, i$sdd_object_versions o
    where  child_tab.DATASTRUCTURE_REF=FK_ARG_TO_DAT_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_ARG_TO_DAT_d;
/
create or replace function FK_ITM_TO_DAT2_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_DAT parent_tab
  where  parent_tab.parent_ivid=FK_ITM_TO_DAT2_cmd.ivid
  and    child_tab.DATASTRUCTURE_REF2=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_DAT parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_ITM_TO_DAT2_cmd.ivid
       and child_tab.DATASTRUCTURE_REF2=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_DAT2_cmd;
/
create or replace function FK_ITM_TO_DAT2_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.DATASTRUCTURE_REF2=FK_ITM_TO_DAT2_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.DATASTRUCTURE_REF2=FK_ITM_TO_DAT2_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_DAT2_d;
/
create or replace function FK_PGD_TO_DAT_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_PGD child_tab, i$SDD_DAT parent_tab
  where  parent_tab.parent_ivid=FK_PGD_TO_DAT_cmd.ivid
  and    child_tab.DATASTRUCTURE_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_PGD child_tab
          ,i$SDD_DAT parent_tab
          ,I$SDD_OBJECT_VERSIONS o
     where parent_tab.parent_ivid=FK_PGD_TO_DAT_cmd.ivid
       and child_tab.DATASTRUCTURE_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_PGD_TO_DAT_cmd;
/
create or replace function FK_PGD_TO_DAT_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_PGD child_tab
  where  child_tab.DATASTRUCTURE_REF=FK_PGD_TO_DAT_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_PGD child_tab, i$sdd_object_versions o
    where  child_tab.DATASTRUCTURE_REF=FK_PGD_TO_DAT_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_PGD_TO_DAT_d;
/
create or replace function PK_SDD_DAT (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_DAT the_tab_new, SDD_DAT the_tab_old
  where  the_tab_new.ivid = PK_SDD_DAT.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_DAT.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_DAT;
/
create or replace function FK_DAT_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_DAT the_tab
  where  the_tab.ivid = FK_DAT_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_DAT_TO_PLM;
/
create or replace function PK_SDD_DATCOM (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_DATCOM the_tab_new, SDD_DATCOM the_tab_old
  where  the_tab_new.ivid = PK_SDD_DATCOM.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_DATCOM.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_DATCOM;
/
create or replace function FK_DATCOM_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_DATCOM the_tab
  where  the_tab.ivid = FK_DATCOM_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_DATCOM_TO_AEN;
/
create or replace function FK_DATCOM_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_DATCOM the_tab
  where  the_tab.ivid = FK_DATCOM_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_DATCOM_TO_CAT;
/
create or replace function PK_SDD_DBU (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_DBU the_tab_new, SDD_DBU the_tab_old
  where  the_tab_new.ivid = PK_SDD_DBU.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_DBU.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_DBU;
/
create or replace function FK_DBU_TO_DPR (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.DATABASE_PROFILE_REF ref_value
  from   i$SDD_DBU the_tab
  where  the_tab.ivid = FK_DBU_TO_DPR.object_ivid
  and    the_tab.DATABASE_PROFILE_REF is not null
  and    not exists (
             select null
             from   SDD_DPR foreign_tab
             where  the_tab.DATABASE_PROFILE_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
                                   , 4885, action);
  end loop;
  return is_ok;
end FK_DBU_TO_DPR;
/
create or replace function FK_DBU_TO_OTB (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.DEFAULT_TABLESPACE_REF ref_value
  from   i$SDD_DBU the_tab
  where  the_tab.ivid = FK_DBU_TO_OTB.object_ivid
  and    the_tab.DEFAULT_TABLESPACE_REF is not null
  and    not exists (
             select null
             from   SDD_OTB foreign_tab
             where  the_tab.DEFAULT_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_DBU_TO_OTB;
/
create or replace function FK_DBU_TO_OTB2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.TEMP_TABLESPACE_REF ref_value
  from   i$SDD_DBU the_tab
  where  the_tab.ivid = FK_DBU_TO_OTB2.object_ivid
  and    the_tab.TEMP_TABLESPACE_REF is not null
  and    not exists (
             select null
             from   SDD_OTB foreign_tab
             where  the_tab.TEMP_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_DBU_TO_OTB2;
/
create or replace function PK_SDD_DBUGRP (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_DBUGRP the_tab_new, SDD_DBUGRP the_tab_old
  where  the_tab_new.ivid = PK_SDD_DBUGRP.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_DBUGRP.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_DBUGRP;
/
create or replace function FK_DBUGRP_TO_GRP (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ROLE_REF ref_value
  from   i$SDD_DBUGRP the_tab
  where  the_tab.ivid = FK_DBUGRP_TO_GRP.object_ivid
  and    the_tab.ROLE_REF is not null
  and    not exists (
             select null
             from   SDD_GRP foreign_tab
             where  the_tab.ROLE_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
                                   , 5031, action);
  end loop;
  return is_ok;
end FK_DBUGRP_TO_GRP;
/
create or replace function PK_SDD_DBUMOD (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_DBUMOD the_tab_new, SDD_DBUMOD the_tab_old
  where  the_tab_new.ivid = PK_SDD_DBUMOD.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_DBUMOD.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_DBUMOD;
/
create or replace function FK_DBUMOD_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_DBUMOD the_tab
  where  the_tab.ivid = FK_DBUMOD_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_DBUMOD_TO_GEM;
/
create or replace function PK_SDD_DEU (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_DEU the_tab_new, SDD_DEU the_tab_old
  where  the_tab_new.ivid = PK_SDD_DEU.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_DEU.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_DEU;
/
create or replace function PK_SDD_DFI (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_DFI the_tab_new, SDD_DFI the_tab_old
  where  the_tab_new.ivid = PK_SDD_DFI.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_DFI.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_DFI;
/
create or replace function PK_SDD_DFL (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_DFL the_tab_new, SDD_DFL the_tab_old
  where  the_tab_new.ivid = PK_SDD_DFL.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_DFL.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_DFL;
/
create or replace function FK_DFL_TO_DST2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.DATASTORE_DEST_REF ref_value
  from   i$SDD_DFL the_tab
  where  the_tab.ivid = FK_DFL_TO_DST2.object_ivid
  and    the_tab.DATASTORE_DEST_REF is not null
  and    not exists (
             select null
             from   SDD_DST foreign_tab
             where  the_tab.DATASTORE_DEST_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
                                   , 5007, action);
  end loop;
  return is_ok;
end FK_DFL_TO_DST2;
/
create or replace function FK_DFL_TO_EXT2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.EXTERNAL_DEST_REF ref_value
  from   i$SDD_DFL the_tab
  where  the_tab.ivid = FK_DFL_TO_EXT2.object_ivid
  and    the_tab.EXTERNAL_DEST_REF is not null
  and    not exists (
             select null
             from   SDD_EXT foreign_tab
             where  the_tab.EXTERNAL_DEST_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
                                   , 4938, action);
  end loop;
  return is_ok;
end FK_DFL_TO_EXT2;
/
create or replace function FK_DFL_TO_FUN2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.FUNCTION_DEST_REF ref_value
  from   i$SDD_DFL the_tab
  where  the_tab.ivid = FK_DFL_TO_FUN2.object_ivid
  and    the_tab.FUNCTION_DEST_REF is not null
  and    not exists (
             select null
             from   SDD_FUN foreign_tab
             where  the_tab.FUNCTION_DEST_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
                                   , 5024, action);
  end loop;
  return is_ok;
end FK_DFL_TO_FUN2;
/
create or replace function PK_SDD_DFLATT (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_DFLATT the_tab_new, SDD_DFLATT the_tab_old
  where  the_tab_new.ivid = PK_SDD_DFLATT.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_DFLATT.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_DFLATT;
/
create or replace function FK_DFLATT_TO_ATT (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ATTRIBUTE_REF ref_value
  from   i$SDD_DFLATT the_tab
  where  the_tab.ivid = FK_DFLATT_TO_ATT.object_ivid
  and    the_tab.ATTRIBUTE_REF is not null
  and    not exists (
             select null
             from   SDD_ATT foreign_tab
             where  the_tab.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
                                   , 5010, action);
  end loop;
  return is_ok;
end FK_DFLATT_TO_ATT;
/
create or replace function PK_SDD_DFLDIT (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_DFLDIT the_tab_new, SDD_DFLDIT the_tab_old
  where  the_tab_new.ivid = PK_SDD_DFLDIT.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_DFLDIT.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_DFLDIT;
/
create or replace function FK_DFLDIT_TO_DIT (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.DATA_ITEM_REF ref_value
  from   i$SDD_DFLDIT the_tab
  where  the_tab.ivid = FK_DFLDIT_TO_DIT.object_ivid
  and    the_tab.DATA_ITEM_REF is not null
  and    not exists (
             select null
             from   SDD_DIT foreign_tab
             where  the_tab.DATA_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
                                   , 5008, action);
  end loop;
  return is_ok;
end FK_DFLDIT_TO_DIT;
/
create or replace function SDD_DIA_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_DIA_cur is
    select *
    from   i$SDD_DIA the_tab
    where  the_tab.irid=SDD_DIA_ver.irid
    and    the_tab.ivid=SDD_DIA_ver.ivid;
  SDD_DIA_rec SDD_DIA_cur%ROWTYPE;
  cursor SDD_DEU_cur1 is
    select *
    from i$SDD_DEU the_tab
    where the_tab.parent_ivid=SDD_DIA_ver.ivid;
  cursor SDD_DIAGRAM_SEGMENTS_cur2 is
    select *
    from i$SDD_DIAGRAM_SEGMENTS the_tab
    where the_tab.parent_ivid=SDD_DIA_ver.ivid;
  cursor SDD_FILPAC_cur3 is
    select *
    from i$SDD_FILPAC the_tab
    where the_tab.parent_ivid=SDD_DIA_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_DIA_cur;
  fetch SDD_DIA_cur into SDD_DIA_rec;
  close SDD_DIA_cur;
  insert into i$SDD_DIA
  values (
    SDD_DIA_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_DIA_rec.TYPES
   ,SDD_DIA_rec.ELEMENT_TYPE_NAME
   ,SDD_DIA_rec.DATE_CREATED
   ,SDD_DIA_rec.CREATED_BY
   ,SDD_DIA_rec.DATE_CHANGED
   ,SDD_DIA_rec.CHANGED_BY
   ,SDD_DIA_rec.NOTM
   ,SDD_DIA_rec.NAME
   ,SDD_DIA_rec.DIAGRAM_TYPE
   ,SDD_DIA_rec.TITLE
   ,SDD_DIA_rec.AUTHOR
   ,SDD_DIA_rec.SCENARIO
   ,SDD_DIA_rec.SUB_DIAGRAM_TYPE
   ,SDD_DIA_rec.SUB_DIAGRAM_ID
   ,SDD_DIA_rec.USRX0
   ,SDD_DIA_rec.USRX1
   ,SDD_DIA_rec.USRX2
   ,SDD_DIA_rec.USRX3
   ,SDD_DIA_rec.USRX4
   ,SDD_DIA_rec.USRX5
   ,SDD_DIA_rec.USRX6
   ,SDD_DIA_rec.USRX7
   ,SDD_DIA_rec.USRX8
   ,SDD_DIA_rec.USRX9
   ,SDD_DIA_rec.USRX10
   ,SDD_DIA_rec.USRX11
   ,SDD_DIA_rec.USRX12
   ,SDD_DIA_rec.USRX13
   ,SDD_DIA_rec.USRX14
   ,SDD_DIA_rec.USRX15
   ,SDD_DIA_rec.USRX16
   ,SDD_DIA_rec.USRX17
   ,SDD_DIA_rec.USRX18
   ,SDD_DIA_rec.USRX19
   ,SDD_DIA_rec.DTD_FILENAME
   ,SDD_DIA_rec.PACKAGE_REF
  );
  jr_reg_ver.vercopy_dependencies(SDD_DIA_ver.irid, SDD_DIA_ver.ivid, new_ivid, null, copy_dependencies);
  for SDD_DEU_rec1 in SDD_DEU_cur1 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_DEU
    values (
       SDD_DEU_rec1.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_DEU_rec1.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_DEU_rec1.TYPES
     , SDD_DEU_rec1.ELEMENT_TYPE_NAME
     , SDD_DEU_rec1.DATE_CREATED
     , SDD_DEU_rec1.CREATED_BY
     , SDD_DEU_rec1.DATE_CHANGED
     , SDD_DEU_rec1.CHANGED_BY
     , SDD_DEU_rec1.NOTM
     , SDD_DEU_rec1.DIAGRAM_REF
     , SDD_DEU_rec1.CIELEMENT_REF
     , SDD_DEU_rec1.SEQUENCE
     , SDD_DEU_rec1.NUMBER_OF_TIMES
     , SDD_DEU_rec1.ELEMENT_TYPE_FOR
    );
  jr_reg_ver.vercopy_dependencies(SDD_DEU_rec1.irid, SDD_DEU_rec1.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_DIAGRAM_SEGMENTS_rec2 in SDD_DIAGRAM_SEGMENTS_cur2 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_DIAGRAM_SEGMENTS
    values (
       SDD_DIAGRAM_SEGMENTS_rec2.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_DIAGRAM_SEGMENTS_rec2.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_DIAGRAM_SEGMENTS_rec2.TYPES
     , SDD_DIAGRAM_SEGMENTS_rec2.DIAGRAM_REF
     , SDD_DIAGRAM_SEGMENTS_rec2.GRAPHICAL_DATA
     , SDD_DIAGRAM_SEGMENTS_rec2.SEQUENCE
     , SDD_DIAGRAM_SEGMENTS_rec2.ELEMENT_TYPE_NAME
     , SDD_DIAGRAM_SEGMENTS_rec2.DATE_CREATED
     , SDD_DIAGRAM_SEGMENTS_rec2.DATE_CHANGED
     , SDD_DIAGRAM_SEGMENTS_rec2.CREATED_BY
     , SDD_DIAGRAM_SEGMENTS_rec2.CHANGED_BY
     , SDD_DIAGRAM_SEGMENTS_rec2.NOTM
    );
  jr_reg_ver.vercopy_dependencies(SDD_DIAGRAM_SEGMENTS_rec2.irid, SDD_DIAGRAM_SEGMENTS_rec2.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_FILPAC_rec3 in SDD_FILPAC_cur3 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_FILPAC
    values (
       SDD_FILPAC_rec3.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_FILPAC_rec3.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_FILPAC_rec3.TYPES
     , SDD_FILPAC_rec3.ELEMENT_TYPE_NAME
     , SDD_FILPAC_rec3.DATE_CREATED
     , SDD_FILPAC_rec3.CREATED_BY
     , SDD_FILPAC_rec3.DATE_CHANGED
     , SDD_FILPAC_rec3.CHANGED_BY
     , SDD_FILPAC_rec3.NOTM
     , SDD_FILPAC_rec3.ASSOCIATION_REF
     , SDD_FILPAC_rec3.CLASSIFIER_REF
     , SDD_FILPAC_rec3.DIAGRAM_REF
     , SDD_FILPAC_rec3.VIEW_LINK_REF
     , SDD_FILPAC_rec3.PRIMARY_ACCESS_FILE_REF
     , SDD_FILPAC_rec3.TYPE
     , SDD_FILPAC_rec3.OUT_OF_SYNC_FLAG
     , SDD_FILPAC_rec3.VERSION
     , SDD_FILPAC_rec3.OS_TIMESTAMP
     , SDD_FILPAC_rec3.FILE_USAGE_FOR
     , SDD_FILPAC_rec3.CRC
    );
  jr_reg_ver.vercopy_dependencies(SDD_FILPAC_rec3.irid, SDD_FILPAC_rec3.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  jr_reg_ver.vercopy_dependent_objects(SDD_DIA_ver.ivid, new_ivid);
  return new_ivid;
end SDD_DIA_ver;
/
create or replace function PK_SDD_DIA (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_DIA the_tab_new, SDD_DIA the_tab_old
  where  the_tab_new.ivid = PK_SDD_DIA.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_DIA.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_DIA;
/
create or replace function FK_DIA_TO_PCK (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.PACKAGE_REF ref_value
  from   i$SDD_DIA the_tab
  where  the_tab.ivid = FK_DIA_TO_PCK.object_ivid
  and    the_tab.PACKAGE_REF is not null
  and    not exists (
             select null
             from   SDD_FOLDERS foreign_tab
             where  the_tab.PACKAGE_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
                                   , 4845, action);
  end loop;
  return is_ok;
end FK_DIA_TO_PCK;
/
create or replace function PK_SDD_DIAGRAM_SEGMENTS (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_DIAGRAM_SEGMENTS the_tab_new, SDD_DIAGRAM_SEGMENTS the_tab_old
  where  the_tab_new.ivid = PK_SDD_DIAGRAM_SEGMENTS.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_DIAGRAM_SEGMENTS.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_DIAGRAM_SEGMENTS;
/
create or replace function PK_SDD_DIR (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_DIR the_tab_new, SDD_DIR the_tab_old
  where  the_tab_new.ivid = PK_SDD_DIR.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_DIR.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_DIR;
/
create or replace function SDD_DIT_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_DIT_cur is
    select *
    from   i$SDD_DIT the_tab
    where  the_tab.irid=SDD_DIT_ver.irid
    and    the_tab.ivid=SDD_DIT_ver.ivid;
  SDD_DIT_rec SDD_DIT_cur%ROWTYPE;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_DIT_cur;
  fetch SDD_DIT_cur into SDD_DIT_rec;
  close SDD_DIT_cur;
  insert into i$SDD_DIT
  values (
    SDD_DIT_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_DIT_rec.TYPES
   ,SDD_DIT_rec.ELEMENT_TYPE_NAME
   ,SDD_DIT_rec.DATE_CREATED
   ,SDD_DIT_rec.CREATED_BY
   ,SDD_DIT_rec.DATE_CHANGED
   ,SDD_DIT_rec.CHANGED_BY
   ,SDD_DIT_rec.NOTM
   ,SDD_DIT_rec.NAME
   ,SDD_DIT_rec.FORMAT
   ,SDD_DIT_rec.MAXIMUM_LENGTH
   ,SDD_DIT_rec.AVERAGE_LENGTH
   ,SDD_DIT_rec.DECIMAL_PLACES
   ,SDD_DIT_rec.UNIT_OF_MEASURE
   ,SDD_DIT_rec.DERIVATION
   ,SDD_DIT_rec.AUTHORITY
   ,SDD_DIT_rec.RESPONSIBLE
   ,SDD_DIT_rec.NOTES
   ,SDD_DIT_rec.USRX0
   ,SDD_DIT_rec.USRX1
   ,SDD_DIT_rec.USRX2
   ,SDD_DIT_rec.USRX3
   ,SDD_DIT_rec.USRX4
   ,SDD_DIT_rec.USRX5
   ,SDD_DIT_rec.USRX6
   ,SDD_DIT_rec.USRX7
   ,SDD_DIT_rec.USRX8
   ,SDD_DIT_rec.USRX9
   ,SDD_DIT_rec.USRX10
   ,SDD_DIT_rec.USRX11
   ,SDD_DIT_rec.USRX12
   ,SDD_DIT_rec.USRX13
   ,SDD_DIT_rec.USRX14
   ,SDD_DIT_rec.USRX15
   ,SDD_DIT_rec.USRX16
   ,SDD_DIT_rec.USRX17
   ,SDD_DIT_rec.USRX18
   ,SDD_DIT_rec.USRX19
  );
  jr_reg_ver.vercopy_dependencies(SDD_DIT_ver.irid, SDD_DIT_ver.ivid, new_ivid, null, copy_dependencies);
  jr_reg_ver.vercopy_dependent_objects(SDD_DIT_ver.ivid, new_ivid);
  return new_ivid;
end SDD_DIT_ver;
/
create or replace function PK_SDD_DIT (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_DIT the_tab_new, SDD_DIT the_tab_old
  where  the_tab_new.ivid = PK_SDD_DIT.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_DIT.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_DIT;
/
create or replace function SDD_DOC_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_DOC_cur is
    select *
    from   i$SDD_DOC the_tab
    where  the_tab.irid=SDD_DOC_ver.irid
    and    the_tab.ivid=SDD_DOC_ver.ivid;
  SDD_DOC_rec SDD_DOC_cur%ROWTYPE;
  cursor SDD_DOCXXX_cur1 is
    select *
    from i$SDD_DOCXXX the_tab
    where the_tab.parent_ivid=SDD_DOC_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_DOC_cur;
  fetch SDD_DOC_cur into SDD_DOC_rec;
  close SDD_DOC_cur;
  insert into i$SDD_DOC
  values (
    SDD_DOC_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_DOC_rec.TYPES
   ,SDD_DOC_rec.ELEMENT_TYPE_NAME
   ,SDD_DOC_rec.DATE_CREATED
   ,SDD_DOC_rec.CREATED_BY
   ,SDD_DOC_rec.DATE_CHANGED
   ,SDD_DOC_rec.CHANGED_BY
   ,SDD_DOC_rec.NOTM
   ,SDD_DOC_rec.NAME
   ,SDD_DOC_rec.AUTHOR
   ,SDD_DOC_rec.DOCUMENT_TYPE
   ,SDD_DOC_rec.STATUS
   ,SDD_DOC_rec.FORMAT
   ,SDD_DOC_rec.SOURCE_PATH
   ,SDD_DOC_rec.LIBRARY_REFERENCE
   ,SDD_DOC_rec.DOCUMENT_VERSION
   ,SDD_DOC_rec.DATE_DOCUMENT_CREATED
   ,SDD_DOC_rec.DATE_DOCUMENT_CHANGED
   ,SDD_DOC_rec.DOCUMENT_CHANGED_BY
   ,SDD_DOC_rec.AUTHORISATION_DATE
   ,SDD_DOC_rec.AUTHORISATION_ID
   ,SDD_DOC_rec.REMARK
   ,SDD_DOC_rec.USRX0
   ,SDD_DOC_rec.USRX1
   ,SDD_DOC_rec.USRX2
   ,SDD_DOC_rec.USRX3
   ,SDD_DOC_rec.USRX4
   ,SDD_DOC_rec.USRX5
   ,SDD_DOC_rec.USRX6
   ,SDD_DOC_rec.USRX7
   ,SDD_DOC_rec.USRX8
   ,SDD_DOC_rec.USRX9
   ,SDD_DOC_rec.USRX10
   ,SDD_DOC_rec.USRX11
   ,SDD_DOC_rec.USRX12
   ,SDD_DOC_rec.USRX13
   ,SDD_DOC_rec.USRX14
   ,SDD_DOC_rec.USRX15
   ,SDD_DOC_rec.USRX16
   ,SDD_DOC_rec.USRX17
   ,SDD_DOC_rec.USRX18
   ,SDD_DOC_rec.USRX19
  );
  jr_reg_ver.vercopy_dependencies(SDD_DOC_ver.irid, SDD_DOC_ver.ivid, new_ivid, null, copy_dependencies);
  for SDD_DOCXXX_rec1 in SDD_DOCXXX_cur1 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_DOCXXX
    values (
       SDD_DOCXXX_rec1.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_DOCXXX_rec1.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_DOCXXX_rec1.TYPES
     , SDD_DOCXXX_rec1.ELEMENT_TYPE_NAME
     , SDD_DOCXXX_rec1.DATE_CREATED
     , SDD_DOCXXX_rec1.CREATED_BY
     , SDD_DOCXXX_rec1.DATE_CHANGED
     , SDD_DOCXXX_rec1.CHANGED_BY
     , SDD_DOCXXX_rec1.NOTM
     , SDD_DOCXXX_rec1.DOCUMENT_REF
     , SDD_DOCXXX_rec1.ELEMENT_REF
     , SDD_DOCXXX_rec1.ELEMENT_TYPE_FOR
     , SDD_DOCXXX_rec1.USRX0
     , SDD_DOCXXX_rec1.USRX1
     , SDD_DOCXXX_rec1.USRX2
     , SDD_DOCXXX_rec1.USRX3
     , SDD_DOCXXX_rec1.USRX4
     , SDD_DOCXXX_rec1.USRX5
     , SDD_DOCXXX_rec1.USRX6
     , SDD_DOCXXX_rec1.USRX7
     , SDD_DOCXXX_rec1.USRX8
     , SDD_DOCXXX_rec1.USRX9
     , SDD_DOCXXX_rec1.USRX10
     , SDD_DOCXXX_rec1.USRX11
     , SDD_DOCXXX_rec1.USRX12
     , SDD_DOCXXX_rec1.USRX13
     , SDD_DOCXXX_rec1.USRX14
     , SDD_DOCXXX_rec1.USRX15
     , SDD_DOCXXX_rec1.USRX16
     , SDD_DOCXXX_rec1.USRX17
     , SDD_DOCXXX_rec1.USRX18
     , SDD_DOCXXX_rec1.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_DOCXXX_rec1.irid, SDD_DOCXXX_rec1.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  jr_reg_ver.vercopy_dependent_objects(SDD_DOC_ver.ivid, new_ivid);
  return new_ivid;
end SDD_DOC_ver;
/
create or replace function PK_SDD_DOC (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_DOC the_tab_new, SDD_DOC the_tab_old
  where  the_tab_new.ivid = PK_SDD_DOC.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_DOC.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_DOC;
/
create or replace function PK_SDD_DOCXXX (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_DOCXXX the_tab_new, SDD_DOCXXX the_tab_old
  where  the_tab_new.ivid = PK_SDD_DOCXXX.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_DOCXXX.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_DOCXXX;
/
create or replace function PK_SDD_DOG (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_DOG the_tab_new, SDD_DOG the_tab_old
  where  the_tab_new.ivid = PK_SDD_DOG.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_DOG.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_DOG;
/
create or replace function FK_DOG_TO_DIR (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.DIRECTORY_REF ref_value
  from   i$SDD_DOG the_tab
  where  the_tab.ivid = FK_DOG_TO_DIR.object_ivid
  and    the_tab.DIRECTORY_REF is not null
  and    not exists (
             select null
             from   SDD_DIR foreign_tab
             where  the_tab.DIRECTORY_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
                                   , 4860, action);
  end loop;
  return is_ok;
end FK_DOG_TO_DIR;
/
create or replace function FK_DOG_TO_JMI (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.JMI_REF ref_value
  from   i$SDD_DOG the_tab
  where  the_tab.ivid = FK_DOG_TO_JMI.object_ivid
  and    the_tab.JMI_REF is not null
  and    not exists (
             select null
             from   SDD_DOI foreign_tab
             where  the_tab.JMI_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
                                   , 4899, action);
  end loop;
  return is_ok;
end FK_DOG_TO_JMI;
/
create or replace function FK_DOG_TO_PMI (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_DOG the_tab
  where  the_tab.ivid = FK_DOG_TO_PMI.object_ivid
  and    the_tab.PLSQL_MODULE_REF is not null
  and    not exists (
             select null
             from   SDD_DOI 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
                                   , 4899, action);
  end loop;
  return is_ok;
end FK_DOG_TO_PMI;
/
create or replace function FK_DOG_TO_QUI (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.QUI_REF ref_value
  from   i$SDD_DOG the_tab
  where  the_tab.ivid = FK_DOG_TO_QUI.object_ivid
  and    the_tab.QUI_REF is not null
  and    not exists (
             select null
             from   SDD_QUI foreign_tab
             where  the_tab.QUI_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
                                   , 5142, action);
  end loop;
  return is_ok;
end FK_DOG_TO_QUI;
/
create or replace function FK_DOG_TO_SNI (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.SNAPSHOT_REF ref_value
  from   i$SDD_DOG the_tab
  where  the_tab.ivid = FK_DOG_TO_SNI.object_ivid
  and    the_tab.SNAPSHOT_REF is not null
  and    not exists (
             select null
             from   SDD_DOI foreign_tab
             where  the_tab.SNAPSHOT_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
                                   , 4899, action);
  end loop;
  return is_ok;
end FK_DOG_TO_SNI;
/
create or replace function FK_DOG_TO_SQI (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.SEQUENCE_REF ref_value
  from   i$SDD_DOG the_tab
  where  the_tab.ivid = FK_DOG_TO_SQI.object_ivid
  and    the_tab.SEQUENCE_REF is not null
  and    not exists (
             select null
             from   SDD_DOI foreign_tab
             where  the_tab.SEQUENCE_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
                                   , 4899, action);
  end loop;
  return is_ok;
end FK_DOG_TO_SQI;
/
create or replace function FK_DOG_TO_TBI (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_DOG the_tab
  where  the_tab.ivid = FK_DOG_TO_TBI.object_ivid
  and    the_tab.TABLE_REF is not null
  and    not exists (
             select null
             from   SDD_DOI 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
                                   , 4899, action);
  end loop;
  return is_ok;
end FK_DOG_TO_TBI;
/
create or replace function FK_DOG_TO_VWI (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.VIEW_REF ref_value
  from   i$SDD_DOG the_tab
  where  the_tab.ivid = FK_DOG_TO_VWI.object_ivid
  and    the_tab.VIEW_REF is not null
  and    not exists (
             select null
             from   SDD_DOI foreign_tab
             where  the_tab.VIEW_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
                                   , 4899, action);
  end loop;
  return is_ok;
end FK_DOG_TO_VWI;
/
create or replace function PK_SDD_DOI (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_DOI the_tab_new, SDD_DOI the_tab_old
  where  the_tab_new.ivid = PK_SDD_DOI.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_DOI.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_DOI;
/
create or replace function FK_DOI_TO_DBU2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.DATABASE_USER_REF2 ref_value
  from   i$SDD_DOI the_tab
  where  the_tab.ivid = FK_DOI_TO_DBU2.object_ivid
  and    the_tab.DATABASE_USER_REF2 is not null
  and    not exists (
             select null
             from   SDD_DBU foreign_tab
             where  the_tab.DATABASE_USER_REF2 = 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_DOI_TO_DBU2;
/
create or replace function FK_DOI_TO_DBU3 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ORACLE_TYPE_DBU_REF ref_value
  from   i$SDD_DOI the_tab
  where  the_tab.ivid = FK_DOI_TO_DBU3.object_ivid
  and    the_tab.ORACLE_TYPE_DBU_REF is not null
  and    not exists (
             select null
             from   SDD_DBU foreign_tab
             where  the_tab.ORACLE_TYPE_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_DOI_TO_DBU3;
/
create or replace function FK_DOI_TO_DIR (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.DIRECTORY_REF ref_value
  from   i$SDD_DOI the_tab
  where  the_tab.ivid = FK_DOI_TO_DIR.object_ivid
  and    the_tab.DIRECTORY_REF is not null
  and    not exists (
             select null
             from   SDD_DIR foreign_tab
             where  the_tab.DIRECTORY_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
                                   , 4860, action);
  end loop;
  return is_ok;
end FK_DOI_TO_DIR;
/
create or replace function FK_DOI_TO_JAM (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.JAVA_MODULE_REF ref_value
  from   i$SDD_DOI the_tab
  where  the_tab.ivid = FK_DOI_TO_JAM.object_ivid
  and    the_tab.JAVA_MODULE_REF is not null
  and    not exists (
             select null
             from   SDD_MOD foreign_tab
             where  the_tab.JAVA_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_DOI_TO_JAM;
/
create or replace function FK_DOI_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_DOI the_tab
  where  the_tab.ivid = FK_DOI_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_DOI_TO_OCL;
/
create or replace function FK_DOI_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_DOI the_tab
  where  the_tab.ivid = FK_DOI_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_DOI_TO_OSP;
/
create or replace function FK_DOI_TO_OSP2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.SNAP_LOG_STORAGE_REF ref_value
  from   i$SDD_DOI the_tab
  where  the_tab.ivid = FK_DOI_TO_OSP2.object_ivid
  and    the_tab.SNAP_LOG_STORAGE_REF is not null
  and    not exists (
             select null
             from   SDD_OSP foreign_tab
             where  the_tab.SNAP_LOG_STORAGE_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_DOI_TO_OSP2;
/
create or replace function FK_DOI_TO_OSQ (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.SEQUENCE_REF ref_value
  from   i$SDD_DOI the_tab
  where  the_tab.ivid = FK_DOI_TO_OSQ.object_ivid
  and    the_tab.SEQUENCE_REF is not null
  and    not exists (
             select null
             from   SDD_OSQ foreign_tab
             where  the_tab.SEQUENCE_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
                                   , 4999, action);
  end loop;
  return is_ok;
end FK_DOI_TO_OSQ;
/
create or replace function FK_DOI_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_DOI the_tab
  where  the_tab.ivid = FK_DOI_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_DOI_TO_OTB;
/
create or replace function FK_DOI_TO_OTB2 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.OVERFLOW_TABLESPACE_REF ref_value
  from   i$SDD_DOI the_tab
  where  the_tab.ivid = FK_DOI_TO_OTB2.object_ivid
  and    the_tab.OVERFLOW_TABLESPACE_REF is not null
  and    not exists (
             select null
             from   SDD_OTB foreign_tab
             where  the_tab.OVERFLOW_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_DOI_TO_OTB2;
/
create or replace function FK_DOI_TO_OTB3 (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.SNAP_LOG_TABLESPACE_REF ref_value
  from   i$SDD_DOI the_tab
  where  the_tab.ivid = FK_DOI_TO_OTB3.object_ivid
  and    the_tab.SNAP_LOG_TABLESPACE_REF is not null
  and    not exists (
             select null
             from   SDD_OTB foreign_tab
             where  the_tab.SNAP_LOG_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_DOI_TO_OTB3;
/
create or replace function FK_DOI_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_DOI the_tab
  where  the_tab.ivid = FK_DOI_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_DOI_TO_PLM;
/
create or replace function FK_DOI_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_DOI the_tab
  where  the_tab.ivid = FK_DOI_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_DOI_TO_QTD;
/
create or replace function FK_DOI_TO_RPG (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.REPLICATION_GROUP_REF ref_value
  from   i$SDD_DOI the_tab
  where  the_tab.ivid = FK_DOI_TO_RPG.object_ivid
  and    the_tab.REPLICATION_GROUP_REF is not null
  and    not exists (
             select null
             from   SDD_RPG foreign_tab
             where  the_tab.REPLICATION_GROUP_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
                                   , 4894, action);
  end loop;
  return is_ok;
end FK_DOI_TO_RPG;
/
create or replace function FK_DOI_TO_SNP (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.SNAPSHOT_DEFINITION_REF ref_value
  from   i$SDD_DOI the_tab
  where  the_tab.ivid = FK_DOI_TO_SNP.object_ivid
  and    the_tab.SNAPSHOT_DEFINITION_REF is not null
  and    not exists (
             select null
             from   SDD_TAB foreign_tab
             where  the_tab.SNAPSHOT_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_DOI_TO_SNP;
/
create or replace function FK_DOI_TO_SRG (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.SNAPSHOT_GROUP_REF ref_value
  from   i$SDD_DOI the_tab
  where  the_tab.ivid = FK_DOI_TO_SRG.object_ivid
  and    the_tab.SNAPSHOT_GROUP_REF is not null
  and    not exists (
             select null
             from   SDD_SRG foreign_tab
             where  the_tab.SNAPSHOT_GROUP_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
                                   , 4891, action);
  end loop;
  return is_ok;
end FK_DOI_TO_SRG;
/
create or replace function FK_DOI_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_DOI the_tab
  where  the_tab.ivid = FK_DOI_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_DOI_TO_TBL;
/
create or replace function FK_DOI_TO_VW (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.VIEW_DEFINITION_REF ref_value
  from   i$SDD_DOI the_tab
  where  the_tab.ivid = FK_DOI_TO_VW.object_ivid
  and    the_tab.VIEW_DEFINITION_REF is not null
  and    not exists (
             select null
             from   SDD_TAB foreign_tab
             where  the_tab.VIEW_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_DOI_TO_VW;
/
create or replace function FK_ARG_TO_DOM_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_ARG child_tab
  where  child_tab.DOMAIN_REF=FK_ARG_TO_DOM_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_ARG child_tab, i$sdd_object_versions o
    where  child_tab.DOMAIN_REF=FK_ARG_TO_DOM_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_ARG_TO_DOM_d;
/
create or replace function FK_ATT_TO_DOM_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_ATT child_tab
  where  child_tab.DOMAIN_REF=FK_ATT_TO_DOM_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_ATT child_tab, i$sdd_object_versions o
    where  child_tab.DOMAIN_REF=FK_ATT_TO_DOM_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_ATT_TO_DOM_d;
/
create or replace function FK_COL_TO_DOM_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.DOMAIN_REF=FK_COL_TO_DOM_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.DOMAIN_REF=FK_COL_TO_DOM_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_DOM_d;
/
create or replace function FK_DOM_TO_DOM_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_DOM child_tab
  where  child_tab.SUPERTYPE_REF=FK_DOM_TO_DOM_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_DOM child_tab, i$sdd_object_versions o
    where  child_tab.SUPERTYPE_REF=FK_DOM_TO_DOM_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_DOM_TO_DOM_d;
/
create or replace function FK_ITE_TO_DOM_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_ITE child_tab
  where  child_tab.DOMAIN_REF=FK_ITE_TO_DOM_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_ITE child_tab, i$sdd_object_versions o
    where  child_tab.DOMAIN_REF=FK_ITE_TO_DOM_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_ITE_TO_DOM_d;
/
create or replace function FK_ITM_TO_DOM_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.DOMAIN_REF=FK_ITM_TO_DOM_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.DOMAIN_REF=FK_ITM_TO_DOM_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_DOM_d;
/
create or replace function FK_PGD_TO_DOM_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_PGD child_tab
  where  child_tab.DOMAIN_REF=FK_PGD_TO_DOM_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_PGD child_tab, i$sdd_object_versions o
    where  child_tab.DOMAIN_REF=FK_PGD_TO_DOM_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_PGD_TO_DOM_d;
/
create or replace function SDD_DOM_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_DOM_cur is
    select *
    from   i$SDD_DOM the_tab
    where  the_tab.irid=SDD_DOM_ver.irid
    and    the_tab.ivid=SDD_DOM_ver.ivid;
  SDD_DOM_rec SDD_DOM_cur%ROWTYPE;
  cursor SDD_ATV_cur1 is
    select *
    from i$SDD_ATV the_tab
    where the_tab.parent_ivid=SDD_DOM_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_DOM_cur;
  fetch SDD_DOM_cur into SDD_DOM_rec;
  close SDD_DOM_cur;
  insert into i$SDD_DOM
  values (
    SDD_DOM_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_DOM_rec.TYPES
   ,SDD_DOM_rec.ELEMENT_TYPE_NAME
   ,SDD_DOM_rec.DATE_CREATED
   ,SDD_DOM_rec.CREATED_BY
   ,SDD_DOM_rec.DATE_CHANGED
   ,SDD_DOM_rec.CHANGED_BY
   ,SDD_DOM_rec.NOTM
   ,SDD_DOM_rec.NAME
   ,SDD_DOM_rec.SUPERTYPE_REF
   ,SDD_DOM_rec.AUTHORITY
   ,SDD_DOM_rec.FORMAT
   ,SDD_DOM_rec.AVERAGE_ATTRIBUTE_LENGTH
   ,SDD_DOM_rec.MAXIMUM_ATTRIBUTE_LENGTH
   ,SDD_DOM_rec.ATTRIBUTE_PRECISION
   ,SDD_DOM_rec.UNIT_OF_MEASURE
   ,SDD_DOM_rec.DERIVATION
   ,SDD_DOM_rec.DATATYPE
   ,SDD_DOM_rec.AVERAGE_COLUMN_LENGTH
   ,SDD_DOM_rec.MAXIMUM_COLUMN_LENGTH
   ,SDD_DOM_rec.COLUMN_PRECISION
   ,SDD_DOM_rec.SOFT_LOV
   ,SDD_DOM_rec.DEFAULT_VALUE
   ,SDD_DOM_rec.NULL_VALUE
   ,SDD_DOM_rec.DESCRIPTION
   ,SDD_DOM_rec.DEFAULT_VALUE_TYPE
   ,SDD_DOM_rec.USRX0
   ,SDD_DOM_rec.USRX1
   ,SDD_DOM_rec.USRX2
   ,SDD_DOM_rec.USRX3
   ,SDD_DOM_rec.USRX4
   ,SDD_DOM_rec.USRX5
   ,SDD_DOM_rec.USRX6
   ,SDD_DOM_rec.USRX7
   ,SDD_DOM_rec.USRX8
   ,SDD_DOM_rec.USRX9
   ,SDD_DOM_rec.USRX10
   ,SDD_DOM_rec.USRX11
   ,SDD_DOM_rec.USRX12
   ,SDD_DOM_rec.USRX13
   ,SDD_DOM_rec.USRX14
   ,SDD_DOM_rec.USRX15
   ,SDD_DOM_rec.USRX16
   ,SDD_DOM_rec.USRX17
   ,SDD_DOM_rec.USRX18
   ,SDD_DOM_rec.USRX19
  );
  jr_reg_ver.vercopy_dependencies(SDD_DOM_ver.irid, SDD_DOM_ver.ivid, new_ivid, null, copy_dependencies);
  for SDD_ATV_rec1 in SDD_ATV_cur1 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_ATV
    values (
       SDD_ATV_rec1.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_ATV_rec1.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_ATV_rec1.TYPES
     , SDD_ATV_rec1.ELEMENT_TYPE_NAME
     , SDD_ATV_rec1.DATE_CREATED
     , SDD_ATV_rec1.CREATED_BY
     , SDD_ATV_rec1.DATE_CHANGED
     , SDD_ATV_rec1.CHANGED_BY
     , SDD_ATV_rec1.NOTM
     , SDD_ATV_rec1.ATTRIBUTE_REF
     , SDD_ATV_rec1.DOMAIN_REF
     , SDD_ATV_rec1.COLUMN_REF
     , SDD_ATV_rec1.MODULE_ARGUMENT_REF
     , SDD_ATV_rec1.UNBOUND_ITEM_REF
     , SDD_ATV_rec1.LOW_VALUE
     , SDD_ATV_rec1.HIGH_VALUE
     , SDD_ATV_rec1.ABBREVIATION
     , SDD_ATV_rec1.LOW_VALUE_TYPE
     , SDD_ATV_rec1.MEANING
     , SDD_ATV_rec1.HIGH_VALUE_TYPE
     , SDD_ATV_rec1.RADIO_SEQUENCE
     , SDD_ATV_rec1.ATTRIBUTE_VALUE_FOR
     , SDD_ATV_rec1.USRX0
     , SDD_ATV_rec1.USRX1
     , SDD_ATV_rec1.USRX2
     , SDD_ATV_rec1.USRX3
     , SDD_ATV_rec1.USRX4
     , SDD_ATV_rec1.USRX5
     , SDD_ATV_rec1.USRX6
     , SDD_ATV_rec1.USRX7
     , SDD_ATV_rec1.USRX8
     , SDD_ATV_rec1.USRX9
     , SDD_ATV_rec1.USRX10
     , SDD_ATV_rec1.USRX11
     , SDD_ATV_rec1.USRX12
     , SDD_ATV_rec1.USRX13
     , SDD_ATV_rec1.USRX14
     , SDD_ATV_rec1.USRX15
     , SDD_ATV_rec1.USRX16
     , SDD_ATV_rec1.USRX17
     , SDD_ATV_rec1.USRX18
     , SDD_ATV_rec1.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_ATV_rec1.irid, SDD_ATV_rec1.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  jr_reg_ver.vercopy_dependent_objects(SDD_DOM_ver.ivid, new_ivid);
  return new_ivid;
end SDD_DOM_ver;
/
create or replace function PK_SDD_DOM (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_DOM the_tab_new, SDD_DOM the_tab_old
  where  the_tab_new.ivid = PK_SDD_DOM.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_DOM.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_DOM;
/
create or replace function FK_DOM_TO_DOM (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_DOM the_tab
  where  the_tab.ivid = FK_DOM_TO_DOM.object_ivid
  and    the_tab.SUPERTYPE_REF is not null
  and    not exists (
             select null
             from   SDD_DOM 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
                                   , 5020, action);
  end loop;
  return is_ok;
end FK_DOM_TO_DOM;
/
create or replace function PK_SDD_DPR (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_DPR the_tab_new, SDD_DPR the_tab_old
  where  the_tab_new.ivid = PK_SDD_DPR.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_DPR.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_DPR;
/
create or replace function FK_DFL_TO_DST2_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_DFL child_tab
  where  child_tab.DATASTORE_DEST_REF=FK_DFL_TO_DST2_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_DFL child_tab, i$sdd_object_versions o
    where  child_tab.DATASTORE_DEST_REF=FK_DFL_TO_DST2_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_DFL_TO_DST2_d;
/
create or replace function SDD_DST_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_DST_cur is
    select *
    from   i$SDD_DST the_tab
    where  the_tab.irid=SDD_DST_ver.irid
    and    the_tab.ivid=SDD_DST_ver.ivid;
  SDD_DST_rec SDD_DST_cur%ROWTYPE;
  cursor SDD_DFL_cur1 is
    select *
    from i$SDD_DFL the_tab
    where the_tab.parent_ivid=SDD_DST_ver.ivid;
  cursor SDD_DFLATT_cur2 is
    select *
    from i$SDD_DFLATT the_tab
    where the_tab.parent_ivid=SDD_DST_ver.ivid;
  cursor SDD_DFLDIT_cur3 is
    select *
    from i$SDD_DFLDIT the_tab
    where the_tab.parent_ivid=SDD_DST_ver.ivid;
  cursor SDD_DSTATT_cur4 is
    select *
    from i$SDD_DSTATT the_tab
    where the_tab.parent_ivid=SDD_DST_ver.ivid;
  cursor SDD_DSTDIT_cur5 is
    select *
    from i$SDD_DSTDIT the_tab
    where the_tab.parent_ivid=SDD_DST_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_DST_cur;
  fetch SDD_DST_cur into SDD_DST_rec;
  close SDD_DST_cur;
  insert into i$SDD_DST
  values (
    SDD_DST_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_DST_rec.TYPES
   ,SDD_DST_rec.ELEMENT_TYPE_NAME
   ,SDD_DST_rec.DATE_CREATED
   ,SDD_DST_rec.CREATED_BY
   ,SDD_DST_rec.DATE_CHANGED
   ,SDD_DST_rec.CHANGED_BY
   ,SDD_DST_rec.NOTM
   ,SDD_DST_rec.SHORT_IDENTIFIER
   ,SDD_DST_rec.NAME
   ,SDD_DST_rec.DATASTORE_TYPE
   ,SDD_DST_rec.REMARK
   ,SDD_DST_rec.BUSINESS_UNIT_REF
   ,SDD_DST_rec.FUNCTION_REF
   ,SDD_DST_rec.STORE_TYPE
   ,SDD_DST_rec.BPR_USE_IN_GENERATE_FLAG
   ,SDD_DST_rec.CRITICAL_PATH_FLAG
   ,SDD_DST_rec.CPA_START_DATE
   ,SDD_DST_rec.CPA_FINISH_DATE
   ,SDD_DST_rec.CPA_RELATIVE_START_TIME
   ,SDD_DST_rec.CPA_RELATIVE_FINISH_TIME
   ,SDD_DST_rec.PERSON_COST_RATE
   ,SDD_DST_rec.PERSON_COST_RATE_UNIT
   ,SDD_DST_rec.OVERHEAD_COST_RATE
   ,SDD_DST_rec.OVERHEAD_COST_RATE_UNIT
   ,SDD_DST_rec.TOTAL_COST_RATE
   ,SDD_DST_rec.TOTAL_COST_RATE_UNIT
   ,SDD_DST_rec.EXPORT_ID
   ,SDD_DST_rec.ADDITIONAL_COST_RATE
   ,SDD_DST_rec.ADDITIONAL_COST_RATE_UNIT
   ,SDD_DST_rec.PRIOR_DELAY_TIME
   ,SDD_DST_rec.PRIOR_DELAY_TIME_UNIT
   ,SDD_DST_rec.WORK_TIME
   ,SDD_DST_rec.WORK_TIME_UNIT
   ,SDD_DST_rec.QUALITY_CHECK_TIME
   ,SDD_DST_rec.QUALITY_CHECK_TIME_UNIT
   ,SDD_DST_rec.POST_DELAY_TIME
   ,SDD_DST_rec.POST_DELAY_TIME_UNIT
   ,SDD_DST_rec.TOTAL_TIME
   ,SDD_DST_rec.TOTAL_TIME_UNIT
   ,SDD_DST_rec.MEASURED_TIME_1
   ,SDD_DST_rec.MEASURED_TIME_2
   ,SDD_DST_rec.MEASURED_TIME_3
   ,SDD_DST_rec.MEASURED_TIME_UNIT
   ,SDD_DST_rec.FREQUENCY
   ,SDD_DST_rec.FREQUENCY_UNIT
   ,SDD_DST_rec.MINIMUM_VOLUME
   ,SDD_DST_rec.AVERAGE_VOLUME
   ,SDD_DST_rec.MAXIMUM_VOLUME
   ,SDD_DST_rec.QUALITY_PERCENT
   ,SDD_DST_rec.VALUE_ADDED
   ,SDD_DST_rec.RESOURCE_REQUIRED_1
   ,SDD_DST_rec.RESOURCE_REQUIRED_2
   ,SDD_DST_rec.RESOURCE_REQUIRED_3
   ,SDD_DST_rec.RESOURCE_REQUIRED_4
   ,SDD_DST_rec.ICON_FILE
   ,SDD_DST_rec.IMAGE_FILE
   ,SDD_DST_rec.SOUND_FILE
   ,SDD_DST_rec.VIDEO_FILE
   ,SDD_DST_rec.EXECUTION_STRING
   ,SDD_DST_rec.NOTE_TYPE
   ,SDD_DST_rec.NOTE_TEXT
   ,SDD_DST_rec.NOTE_PICTURE_FILE
   ,SDD_DST_rec.USRX0
   ,SDD_DST_rec.USRX1
   ,SDD_DST_rec.USRX2
   ,SDD_DST_rec.USRX3
   ,SDD_DST_rec.USRX4
   ,SDD_DST_rec.USRX5
   ,SDD_DST_rec.USRX6
   ,SDD_DST_rec.USRX7
   ,SDD_DST_rec.USRX8
   ,SDD_DST_rec.USRX9
   ,SDD_DST_rec.USRX10
   ,SDD_DST_rec.USRX11
   ,SDD_DST_rec.USRX12
   ,SDD_DST_rec.USRX13
   ,SDD_DST_rec.USRX14
   ,SDD_DST_rec.USRX15
   ,SDD_DST_rec.USRX16
   ,SDD_DST_rec.USRX17
   ,SDD_DST_rec.USRX18
   ,SDD_DST_rec.USRX19
  );
  jr_reg_ver.vercopy_dependencies(SDD_DST_ver.irid, SDD_DST_ver.ivid, new_ivid, null, copy_dependencies);
  for SDD_DFL_rec1 in SDD_DFL_cur1 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_DFL
    values (
       SDD_DFL_rec1.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_DFL_rec1.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_DFL_rec1.TYPES
     , SDD_DFL_rec1.ELEMENT_TYPE_NAME
     , SDD_DFL_rec1.DATE_CREATED
     , SDD_DFL_rec1.CREATED_BY
     , SDD_DFL_rec1.DATE_CHANGED
     , SDD_DFL_rec1.CHANGED_BY
     , SDD_DFL_rec1.NOTM
     , SDD_DFL_rec1.FUNCTION_SOURCE_REF
     , SDD_DFL_rec1.DATASTORE_SOURCE_REF
     , SDD_DFL_rec1.EXTERNAL_SOURCE_REF
     , SDD_DFL_rec1.NAME
     , SDD_DFL_rec1.CLASSIFICATION
     , SDD_DFL_rec1.DESCRIPTION
     , SDD_DFL_rec1.FUNCTION_DEST_REF
     , SDD_DFL_rec1.DATASTORE_DEST_REF
     , SDD_DFL_rec1.EXTERNAL_DEST_REF
     , SDD_DFL_rec1.ACTIVATE_FLOW_FLAG
     , SDD_DFL_rec1.AND_OR_FLAG
     , SDD_DFL_rec1.BPR_USE_IN_GENERATE_FLAG
     , SDD_DFL_rec1.CRITICAL_PATH_FLAG
     , SDD_DFL_rec1.CPA_START_DATE
     , SDD_DFL_rec1.CPA_FINISH_DATE
     , SDD_DFL_rec1.CPA_RELATIVE_START_TIME
     , SDD_DFL_rec1.CPA_RELATIVE_FINISH_TIME
     , SDD_DFL_rec1.FLOW_PERCENT
     , SDD_DFL_rec1.FLOW_RULE
     , SDD_DFL_rec1.FLOW_TYPE
     , SDD_DFL_rec1.INVISIBLE_FLAG
     , SDD_DFL_rec1.SIGNIFICANT_AT_SOURCE
     , SDD_DFL_rec1.SIGNIFICANT_AT_DEST
     , SDD_DFL_rec1.EXPORT_ID
     , SDD_DFL_rec1.PERSON_COST_RATE
     , SDD_DFL_rec1.PERSON_COST_RATE_UNIT
     , SDD_DFL_rec1.OVERHEAD_COST_RATE
     , SDD_DFL_rec1.OVERHEAD_COST_RATE_UNIT
     , SDD_DFL_rec1.TOTAL_COST_RATE
     , SDD_DFL_rec1.DESTINATION_TYPE
     , SDD_DFL_rec1.SOURCE_TYPE
     , SDD_DFL_rec1.TOTAL_COST_RATE_UNIT
     , SDD_DFL_rec1.ADDITIONAL_COST_RATE
     , SDD_DFL_rec1.ADDITIONAL_COST_RATE_UNIT
     , SDD_DFL_rec1.PRIOR_DELAY_TIME
     , SDD_DFL_rec1.PRIOR_DELAY_TIME_UNIT
     , SDD_DFL_rec1.WORK_TIME
     , SDD_DFL_rec1.WORK_TIME_UNIT
     , SDD_DFL_rec1.QUALITY_CHECK_TIME
     , SDD_DFL_rec1.QUALITY_CHECK_TIME_UNIT
     , SDD_DFL_rec1.POST_DELAY_TIME
     , SDD_DFL_rec1.POST_DELAY_TIME_UNIT
     , SDD_DFL_rec1.TOTAL_TIME
     , SDD_DFL_rec1.TOTAL_TIME_UNIT
     , SDD_DFL_rec1.MEASURED_TIME_1
     , SDD_DFL_rec1.MEASURED_TIME_2
     , SDD_DFL_rec1.MEASURED_TIME_3
     , SDD_DFL_rec1.MEASURED_TIME_UNIT
     , SDD_DFL_rec1.FREQUENCY
     , SDD_DFL_rec1.FREQUENCY_UNIT
     , SDD_DFL_rec1.QUALITY_PERCENT
     , SDD_DFL_rec1.VALUE_ADDED
     , SDD_DFL_rec1.RESOURCE_REQUIRED_1
     , SDD_DFL_rec1.RESOURCE_REQUIRED_2
     , SDD_DFL_rec1.RESOURCE_REQUIRED_3
     , SDD_DFL_rec1.RESOURCE_REQUIRED_4
     , SDD_DFL_rec1.ICON_FILE
     , SDD_DFL_rec1.IMAGE_FILE
     , SDD_DFL_rec1.SOUND_FILE
     , SDD_DFL_rec1.VIDEO_FILE
     , SDD_DFL_rec1.EXECUTION_STRING
     , SDD_DFL_rec1.NOTE_TYPE
     , SDD_DFL_rec1.NOTE_TEXT
     , SDD_DFL_rec1.NOTE_PICTURE_FILE
     , SDD_DFL_rec1.USRX0
     , SDD_DFL_rec1.USRX1
     , SDD_DFL_rec1.USRX2
     , SDD_DFL_rec1.USRX3
     , SDD_DFL_rec1.USRX4
     , SDD_DFL_rec1.USRX5
     , SDD_DFL_rec1.USRX6
     , SDD_DFL_rec1.USRX7
     , SDD_DFL_rec1.USRX8
     , SDD_DFL_rec1.USRX9
     , SDD_DFL_rec1.USRX10
     , SDD_DFL_rec1.USRX11
     , SDD_DFL_rec1.USRX12
     , SDD_DFL_rec1.USRX13
     , SDD_DFL_rec1.USRX14
     , SDD_DFL_rec1.USRX15
     , SDD_DFL_rec1.USRX16
     , SDD_DFL_rec1.USRX17
     , SDD_DFL_rec1.USRX18
     , SDD_DFL_rec1.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_DFL_rec1.irid, SDD_DFL_rec1.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_DFLATT_rec2 in SDD_DFLATT_cur2 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_DFLATT
    values (
       SDD_DFLATT_rec2.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_DFLATT_rec2.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_DFLATT_rec2.TYPES
     , SDD_DFLATT_rec2.ELEMENT_TYPE_NAME
     , SDD_DFLATT_rec2.DATE_CREATED
     , SDD_DFLATT_rec2.CREATED_BY
     , SDD_DFLATT_rec2.DATE_CHANGED
     , SDD_DFLATT_rec2.CHANGED_BY
     , SDD_DFLATT_rec2.NOTM
     , SDD_DFLATT_rec2.DATAFLOW_REF
     , SDD_DFLATT_rec2.ATTRIBUTE_REF
     , SDD_DFLATT_rec2.ENTITY_REFERENCE
     , SDD_DFLATT_rec2.USRX0
     , SDD_DFLATT_rec2.USRX1
     , SDD_DFLATT_rec2.USRX2
     , SDD_DFLATT_rec2.USRX3
     , SDD_DFLATT_rec2.USRX4
     , SDD_DFLATT_rec2.USRX5
     , SDD_DFLATT_rec2.USRX6
     , SDD_DFLATT_rec2.USRX7
     , SDD_DFLATT_rec2.USRX8
     , SDD_DFLATT_rec2.USRX9
     , SDD_DFLATT_rec2.USRX10
     , SDD_DFLATT_rec2.USRX11
     , SDD_DFLATT_rec2.USRX12
     , SDD_DFLATT_rec2.USRX13
     , SDD_DFLATT_rec2.USRX14
     , SDD_DFLATT_rec2.USRX15
     , SDD_DFLATT_rec2.USRX16
     , SDD_DFLATT_rec2.USRX17
     , SDD_DFLATT_rec2.USRX18
     , SDD_DFLATT_rec2.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_DFLATT_rec2.irid, SDD_DFLATT_rec2.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_DFLDIT_rec3 in SDD_DFLDIT_cur3 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_DFLDIT
    values (
       SDD_DFLDIT_rec3.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_DFLDIT_rec3.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_DFLDIT_rec3.TYPES
     , SDD_DFLDIT_rec3.ELEMENT_TYPE_NAME
     , SDD_DFLDIT_rec3.DATE_CREATED
     , SDD_DFLDIT_rec3.CREATED_BY
     , SDD_DFLDIT_rec3.DATE_CHANGED
     , SDD_DFLDIT_rec3.CHANGED_BY
     , SDD_DFLDIT_rec3.NOTM
     , SDD_DFLDIT_rec3.DATAFLOW_REF
     , SDD_DFLDIT_rec3.DATA_ITEM_REF
     , SDD_DFLDIT_rec3.USRX0
     , SDD_DFLDIT_rec3.USRX1
     , SDD_DFLDIT_rec3.USRX2
     , SDD_DFLDIT_rec3.USRX3
     , SDD_DFLDIT_rec3.USRX4
     , SDD_DFLDIT_rec3.USRX5
     , SDD_DFLDIT_rec3.USRX6
     , SDD_DFLDIT_rec3.USRX7
     , SDD_DFLDIT_rec3.USRX8
     , SDD_DFLDIT_rec3.USRX9
     , SDD_DFLDIT_rec3.USRX10
     , SDD_DFLDIT_rec3.USRX11
     , SDD_DFLDIT_rec3.USRX12
     , SDD_DFLDIT_rec3.USRX13
     , SDD_DFLDIT_rec3.USRX14
     , SDD_DFLDIT_rec3.USRX15
     , SDD_DFLDIT_rec3.USRX16
     , SDD_DFLDIT_rec3.USRX17
     , SDD_DFLDIT_rec3.USRX18
     , SDD_DFLDIT_rec3.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_DFLDIT_rec3.irid, SDD_DFLDIT_rec3.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_DSTATT_rec4 in SDD_DSTATT_cur4 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_DSTATT
    values (
       SDD_DSTATT_rec4.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_DSTATT_rec4.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_DSTATT_rec4.TYPES
     , SDD_DSTATT_rec4.ELEMENT_TYPE_NAME
     , SDD_DSTATT_rec4.DATE_CREATED
     , SDD_DSTATT_rec4.CREATED_BY
     , SDD_DSTATT_rec4.DATE_CHANGED
     , SDD_DSTATT_rec4.CHANGED_BY
     , SDD_DSTATT_rec4.NOTM
     , SDD_DSTATT_rec4.DATASTORE_REF
     , SDD_DSTATT_rec4.ATTRIBUTE_REF
     , SDD_DSTATT_rec4.ENTITY_REFERENCE
     , SDD_DSTATT_rec4.USRX0
     , SDD_DSTATT_rec4.USRX1
     , SDD_DSTATT_rec4.USRX2
     , SDD_DSTATT_rec4.USRX3
     , SDD_DSTATT_rec4.USRX4
     , SDD_DSTATT_rec4.USRX5
     , SDD_DSTATT_rec4.USRX6
     , SDD_DSTATT_rec4.USRX7
     , SDD_DSTATT_rec4.USRX8
     , SDD_DSTATT_rec4.USRX9
     , SDD_DSTATT_rec4.USRX10
     , SDD_DSTATT_rec4.USRX11
     , SDD_DSTATT_rec4.USRX12
     , SDD_DSTATT_rec4.USRX13
     , SDD_DSTATT_rec4.USRX14
     , SDD_DSTATT_rec4.USRX15
     , SDD_DSTATT_rec4.USRX16
     , SDD_DSTATT_rec4.USRX17
     , SDD_DSTATT_rec4.USRX18
     , SDD_DSTATT_rec4.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_DSTATT_rec4.irid, SDD_DSTATT_rec4.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_DSTDIT_rec5 in SDD_DSTDIT_cur5 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_DSTDIT
    values (
       SDD_DSTDIT_rec5.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_DSTDIT_rec5.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_DSTDIT_rec5.TYPES
     , SDD_DSTDIT_rec5.ELEMENT_TYPE_NAME
     , SDD_DSTDIT_rec5.DATE_CREATED
     , SDD_DSTDIT_rec5.CREATED_BY
     , SDD_DSTDIT_rec5.DATE_CHANGED
     , SDD_DSTDIT_rec5.CHANGED_BY
     , SDD_DSTDIT_rec5.NOTM
     , SDD_DSTDIT_rec5.DATASTORE_REF
     , SDD_DSTDIT_rec5.DATA_ITEM_REF
     , SDD_DSTDIT_rec5.USRX0
     , SDD_DSTDIT_rec5.USRX1
     , SDD_DSTDIT_rec5.USRX2
     , SDD_DSTDIT_rec5.USRX3
     , SDD_DSTDIT_rec5.USRX4
     , SDD_DSTDIT_rec5.USRX5
     , SDD_DSTDIT_rec5.USRX6
     , SDD_DSTDIT_rec5.USRX7
     , SDD_DSTDIT_rec5.USRX8
     , SDD_DSTDIT_rec5.USRX9
     , SDD_DSTDIT_rec5.USRX10
     , SDD_DSTDIT_rec5.USRX11
     , SDD_DSTDIT_rec5.USRX12
     , SDD_DSTDIT_rec5.USRX13
     , SDD_DSTDIT_rec5.USRX14
     , SDD_DSTDIT_rec5.USRX15
     , SDD_DSTDIT_rec5.USRX16
     , SDD_DSTDIT_rec5.USRX17
     , SDD_DSTDIT_rec5.USRX18
     , SDD_DSTDIT_rec5.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_DSTDIT_rec5.irid, SDD_DSTDIT_rec5.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  jr_reg_ver.vercopy_dependent_objects(SDD_DST_ver.ivid, new_ivid);
  return new_ivid;
end SDD_DST_ver;
/
create or replace function PK_SDD_DST (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_DST the_tab_new, SDD_DST the_tab_old
  where  the_tab_new.ivid = PK_SDD_DST.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_DST.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_DST;
/
create or replace function FK_DST_TO_BUN (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.BUSINESS_UNIT_REF ref_value
  from   i$SDD_DST the_tab
  where  the_tab.ivid = FK_DST_TO_BUN.object_ivid
  and    the_tab.BUSINESS_UNIT_REF is not null
  and    not exists (
             select null
             from   SDD_BUN foreign_tab
             where  the_tab.BUSINESS_UNIT_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
                                   , 5005, action);
  end loop;
  return is_ok;
end FK_DST_TO_BUN;
/
create or replace function FK_DST_TO_FUN (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.FUNCTION_REF ref_value
  from   i$SDD_DST the_tab
  where  the_tab.ivid = FK_DST_TO_FUN.object_ivid
  and    the_tab.FUNCTION_REF is not null
  and    not exists (
             select null
             from   SDD_FUN foreign_tab
             where  the_tab.FUNCTION_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
                                   , 5024, action);
  end loop;
  return is_ok;
end FK_DST_TO_FUN;
/
create or replace function PK_SDD_DSTATT (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_DSTATT the_tab_new, SDD_DSTATT the_tab_old
  where  the_tab_new.ivid = PK_SDD_DSTATT.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_DSTATT.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_DSTATT;
/
create or replace function FK_DSTATT_TO_ATT (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.ATTRIBUTE_REF ref_value
  from   i$SDD_DSTATT the_tab
  where  the_tab.ivid = FK_DSTATT_TO_ATT.object_ivid
  and    the_tab.ATTRIBUTE_REF is not null
  and    not exists (
             select null
             from   SDD_ATT foreign_tab
             where  the_tab.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
                                   , 5010, action);
  end loop;
  return is_ok;
end FK_DSTATT_TO_ATT;
/
create or replace function PK_SDD_DSTDIT (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_DSTDIT the_tab_new, SDD_DSTDIT the_tab_old
  where  the_tab_new.ivid = PK_SDD_DSTDIT.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_DSTDIT.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_DSTDIT;
/
create or replace function FK_DSTDIT_TO_DIT (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.DATA_ITEM_REF ref_value
  from   i$SDD_DSTDIT the_tab
  where  the_tab.ivid = FK_DSTDIT_TO_DIT.object_ivid
  and    the_tab.DATA_ITEM_REF is not null
  and    not exists (
             select null
             from   SDD_DIT foreign_tab
             where  the_tab.DATA_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
                                   , 5008, action);
  end loop;
  return is_ok;
end FK_DSTDIT_TO_DIT;
/
create or replace function PK_SDD_DSY (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_DSY the_tab_new, SDD_DSY the_tab_old
  where  the_tab_new.ivid = PK_SDD_DSY.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_DSY.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_DSY;
/
create or replace function FK_DSY_TO_JAM (object_ivid number, object_type_irid number, action varchar2) return boolean as
cursor bad_cur is
  select
    the_tab.JAVA_MODULE_REF ref_value
  from   i$SDD_DSY the_tab
  where  the_tab.ivid = FK_DSY_TO_JAM.object_ivid
  and    the_tab.JAVA_MODULE_REF is not null
  and    not exists (
             select null
             from   SDD_MOD foreign_tab
             where  the_tab.JAVA_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_DSY_TO_JAM;
/
create or replace function FK_DSY_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_DSY the_tab
  where  the_tab.ivid = FK_DSY_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_DSY_TO_PLM;
/
create or replace function SDD_E1_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_E1_cur is
    select *
    from   i$SDD_E1 the_tab
    where  the_tab.irid=SDD_E1_ver.irid
    and    the_tab.ivid=SDD_E1_ver.ivid;
  SDD_E1_rec SDD_E1_cur%ROWTYPE;
  cursor SDD_A1_cur1 is
    select *
    from i$SDD_A1 the_tab
    where the_tab.parent_ivid=SDD_E1_ver.ivid;
  cursor SDD_A2_cur2 is
    select *
    from i$SDD_A2 the_tab
    where the_tab.parent_ivid=SDD_E1_ver.ivid;
  cursor SDD_A3_cur3 is
    select *
    from i$SDD_A3 the_tab
    where the_tab.parent_ivid=SDD_E1_ver.ivid;
  cursor SDD_A4_cur4 is
    select *
    from i$SDD_A4 the_tab
    where the_tab.parent_ivid=SDD_E1_ver.ivid;
begin
  new_ivid := jr_system_util.get_new_ivid;
  open SDD_E1_cur;
  fetch SDD_E1_cur into SDD_E1_rec;
  close SDD_E1_cur;
  insert into i$SDD_E1
  values (
    SDD_E1_rec.irid -- irid
   ,new_ivid -- ivid
   ,SDD_E1_rec.TYPES
   ,SDD_E1_rec.ELEMENT_TYPE_NAME
   ,SDD_E1_rec.DATE_CREATED
   ,SDD_E1_rec.CREATED_BY
   ,SDD_E1_rec.DATE_CHANGED
   ,SDD_E1_rec.CHANGED_BY
   ,SDD_E1_rec.NOTM
   ,SDD_E1_rec.NAME
   ,SDD_E1_rec.TYPE
   ,SDD_E1_rec.OBJECTIVE_REF
   ,SDD_E1_rec.VALUE
   ,SDD_E1_rec.SET_BY
   ,SDD_E1_rec.UNIT_OF_MEASURE
   ,SDD_E1_rec.PLANNING_HORIZON
   ,SDD_E1_rec.CDATE_REQUIRED
   ,SDD_E1_rec.RANKING
   ,SDD_E1_rec.ACHIEVEMENT_COMMENT
   ,SDD_E1_rec.COMMENTS
   ,SDD_E1_rec.USRX0
   ,SDD_E1_rec.USRX9
   ,SDD_E1_rec.USRX10
   ,SDD_E1_rec.USRX11
   ,SDD_E1_rec.USRX12
   ,SDD_E1_rec.USRX13
   ,SDD_E1_rec.USRX14
   ,SDD_E1_rec.USRX15
   ,SDD_E1_rec.USRX16
   ,SDD_E1_rec.USRX17
   ,SDD_E1_rec.USRX18
   ,SDD_E1_rec.USRX19
  );
  jr_reg_ver.vercopy_dependencies(SDD_E1_ver.irid, SDD_E1_ver.ivid, new_ivid, null, copy_dependencies);
  for SDD_A1_rec1 in SDD_A1_cur1 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_A1
    values (
       SDD_A1_rec1.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_A1_rec1.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_A1_rec1.TYPES
     , SDD_A1_rec1.ELEMENT_TYPE_NAME
     , SDD_A1_rec1.DATE_CREATED
     , SDD_A1_rec1.CREATED_BY
     , SDD_A1_rec1.DATE_CHANGED
     , SDD_A1_rec1.CHANGED_BY
     , SDD_A1_rec1.NOTM
     , SDD_A1_rec1.OBJECTIVE_REF
     , SDD_A1_rec1.CSF_REF
     , SDD_A1_rec1.REASON
     , SDD_A1_rec1.CONTRIBUTION
     , SDD_A1_rec1.VALUE
     , SDD_A1_rec1.UNIT_OF_MEASURE
     , SDD_A1_rec1.COMMENTS
     , SDD_A1_rec1.USRX0
     , SDD_A1_rec1.USRX5
     , SDD_A1_rec1.USRX6
     , SDD_A1_rec1.USRX7
     , SDD_A1_rec1.USRX8
     , SDD_A1_rec1.USRX9
     , SDD_A1_rec1.USRX10
     , SDD_A1_rec1.USRX11
     , SDD_A1_rec1.USRX12
     , SDD_A1_rec1.USRX13
     , SDD_A1_rec1.USRX14
     , SDD_A1_rec1.USRX15
     , SDD_A1_rec1.USRX16
     , SDD_A1_rec1.USRX17
     , SDD_A1_rec1.USRX18
     , SDD_A1_rec1.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_A1_rec1.irid, SDD_A1_rec1.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_A2_rec2 in SDD_A2_cur2 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_A2
    values (
       SDD_A2_rec2.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_A2_rec2.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_A2_rec2.TYPES
     , SDD_A2_rec2.ELEMENT_TYPE_NAME
     , SDD_A2_rec2.DATE_CREATED
     , SDD_A2_rec2.CREATED_BY
     , SDD_A2_rec2.DATE_CHANGED
     , SDD_A2_rec2.CHANGED_BY
     , SDD_A2_rec2.NOTM
     , SDD_A2_rec2.OBJECTIVE_REF
     , SDD_A2_rec2.MODULE_REF
     , SDD_A2_rec2.CDATE_PLACED
     , SDD_A2_rec2.VALUE
     , SDD_A2_rec2.UNIT_OF_MEASURE
     , SDD_A2_rec2.CDATE_REQUIRED
     , SDD_A2_rec2.ACHIEVEMENT_COMMENT
     , SDD_A2_rec2.CONFORMANCE
     , SDD_A2_rec2.COMMENTS
     , SDD_A2_rec2.USRX0
     , SDD_A2_rec2.USRX7
     , SDD_A2_rec2.USRX8
     , SDD_A2_rec2.USRX9
     , SDD_A2_rec2.USRX10
     , SDD_A2_rec2.USRX11
     , SDD_A2_rec2.USRX12
     , SDD_A2_rec2.USRX13
     , SDD_A2_rec2.USRX14
     , SDD_A2_rec2.USRX15
     , SDD_A2_rec2.USRX16
     , SDD_A2_rec2.USRX17
     , SDD_A2_rec2.USRX18
     , SDD_A2_rec2.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_A2_rec2.irid, SDD_A2_rec2.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_A3_rec3 in SDD_A3_cur3 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_A3
    values (
       SDD_A3_rec3.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_A3_rec3.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_A3_rec3.TYPES
     , SDD_A3_rec3.ELEMENT_TYPE_NAME
     , SDD_A3_rec3.DATE_CREATED
     , SDD_A3_rec3.CREATED_BY
     , SDD_A3_rec3.DATE_CHANGED
     , SDD_A3_rec3.CHANGED_BY
     , SDD_A3_rec3.NOTM
     , SDD_A3_rec3.OBJECTIVE_REF
     , SDD_A3_rec3.KPI_REF
     , SDD_A3_rec3.REASON
     , SDD_A3_rec3.COMMENTS
     , SDD_A3_rec3.USRX0
     , SDD_A3_rec3.USRX2
     , SDD_A3_rec3.USRX3
     , SDD_A3_rec3.USRX4
     , SDD_A3_rec3.USRX5
     , SDD_A3_rec3.USRX6
     , SDD_A3_rec3.USRX7
     , SDD_A3_rec3.USRX8
     , SDD_A3_rec3.USRX9
     , SDD_A3_rec3.USRX10
     , SDD_A3_rec3.USRX11
     , SDD_A3_rec3.USRX12
     , SDD_A3_rec3.USRX13
     , SDD_A3_rec3.USRX14
     , SDD_A3_rec3.USRX15
     , SDD_A3_rec3.USRX16
     , SDD_A3_rec3.USRX17
     , SDD_A3_rec3.USRX18
     , SDD_A3_rec3.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_A3_rec3.irid, SDD_A3_rec3.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  for SDD_A4_rec4 in SDD_A4_cur4 loop
    new_secondary_ivid := jr_system_util.get_new_ivid;
    insert into i$SDD_A4
    values (
       SDD_A4_rec4.irid    -- irid
     , new_secondary_ivid                   -- ivid
     , SDD_A4_rec4.pac_ref -- pac_ref
     , new_ivid                             -- parent_ivid
     , SDD_A4_rec4.TYPES
     , SDD_A4_rec4.ELEMENT_TYPE_NAME
     , SDD_A4_rec4.DATE_CREATED
     , SDD_A4_rec4.CREATED_BY
     , SDD_A4_rec4.DATE_CHANGED
     , SDD_A4_rec4.CHANGED_BY
     , SDD_A4_rec4.NOTM
     , SDD_A4_rec4.OBJECTIVE_REF
     , SDD_A4_rec4.FUNCTION_REF
     , SDD_A4_rec4.TYPE
     , SDD_A4_rec4.PLACED_BY
     , SDD_A4_rec4.DATE_PLACED
     , SDD_A4_rec4.VALUE
     , SDD_A4_rec4.UNIT_OF_MEASURE
     , SDD_A4_rec4.DATE_REQUIRED
     , SDD_A4_rec4.ACHIEVEMENT_COMMENT
     , SDD_A4_rec4.COMMENTS
     , SDD_A4_rec4.USRX0
     , SDD_A4_rec4.USRX8
     , SDD_A4_rec4.USRX9
     , SDD_A4_rec4.USRX10
     , SDD_A4_rec4.USRX11
     , SDD_A4_rec4.USRX12
     , SDD_A4_rec4.USRX13
     , SDD_A4_rec4.USRX14
     , SDD_A4_rec4.USRX15
     , SDD_A4_rec4.USRX16
     , SDD_A4_rec4.USRX17
     , SDD_A4_rec4.USRX18
     , SDD_A4_rec4.USRX19
    );
  jr_reg_ver.vercopy_dependencies(SDD_A4_rec4.irid, SDD_A4_rec4.ivid, new_secondary_ivid, new_ivid, copy_dependencies);
  end loop;
  jr_reg_ver.vercopy_dependent_objects(SDD_E1_ver.ivid, new_ivid);
  return new_ivid;
end SDD_E1_ver;
/
create or replace function PK_SDD_E1 (irid number, ivid number) return boolean as
  cursor bad_cur is
  select null
  from   i$SDD_E1 the_tab_new, SDD_E1 the_tab_old
  where  the_tab_new.ivid = PK_SDD_E1.ivid
  and    the_tab_new.IRID = the_tab_old.IRID
  and    the_tab_old.ivid != PK_SDD_E1.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_E1;
/
create or replace function FK_E1_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_E1 the_tab
  where  the_tab.ivid = FK_E1_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_E1_TO_E1;
/
create or replace function SDD_E2_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_E2_cur is
