---------------------------------------------
-- Export file for user NITIL              --
-- Created by ppk on 2007.04.23., 13:45:56 --
---------------------------------------------

prompt
prompt Creating table CG_CODE_CONTROLS
prompt ===============================
prompt
create table CG_CODE_CONTROLS
(
  CC_DOMAIN     VARCHAR2(30) not null,
  CC_COMMENT    VARCHAR2(240),
  CC_NEXT_VALUE NUMBER(15) not null,
  CC_INCREMENT  NUMBER(15) default 1
)
tablespace NITIL
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table CG_REF_CODES
prompt ===========================
prompt
create table CG_REF_CODES
(
  RV_DOMAIN       VARCHAR2(100) not null,
  RV_LOW_VALUE    VARCHAR2(240) not null,
  RV_HIGH_VALUE   VARCHAR2(240),
  RV_ABBREVIATION VARCHAR2(240),
  RV_MEANING      VARCHAR2(240)
)
tablespace NITIL
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index X_CG_REF_CODES_1 on CG_REF_CODES (RV_DOMAIN, RV_LOW_VALUE)
  tablespace NITIL
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_CI_PROPERTY_TYPES
prompt ====================================
prompt
create table NIT_CI_PROPERTY_TYPES
(
  ID               INTEGER not null,
  CREATION_DATE    DATE not null,
  CREATED_BY       VARCHAR2(30) not null,
  LAST_UPDATE_DATE DATE not null,
  LAST_UPDATED_BY  VARCHAR2(30) not null,
  NAME             VARCHAR2(100) not null,
  TYPE_NAME        VARCHAR2(30) default 'varchar2' not null,
  MIME_TYPE        VARCHAR2(100),
  DESCRIPTION      VARCHAR2(1000),
  COMMENTS         VARCHAR2(1000)
)
tablespace NITIL
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_CI_PROPERTY_TYPES
  add constraint NIT_CPK_CIPT primary key (ID)
  using index 
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_CUK_CIPT on NIT_CI_PROPERTY_TYPES (NAME)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_CI_TYPES
prompt ===========================
prompt
create table NIT_CI_TYPES
(
  ID                 INTEGER not null,
  CREATION_DATE      DATE not null,
  CREATED_BY         VARCHAR2(30) not null,
  LAST_UPDATE_DATE   DATE not null,
  LAST_UPDATED_BY    VARCHAR2(30) not null,
  CIT_ID             INTEGER,
  NAME               VARCHAR2(100) not null,
  NEED_PO            VARCHAR2(1) default 'N' not null,
  COULD_IN_STOCK     VARCHAR2(1) default 'Y' not null,
  ORDER_IN_LIST      INTEGER default 0 not null,
  ABBREVIATION       VARCHAR2(30),
  NAMING_PATTERN     VARCHAR2(1000),
  DESCRIPTION        VARCHAR2(1000),
  COMMENTS           VARCHAR2(1000),
  ICON_NAME          VARCHAR2(100),
  COULD_IN_INVENTORY VARCHAR2(1) default 'N' not null,
  IS_IMPORTABLE      VARCHAR2(1) default 'N' not null,
  IMP_SOURCE_MODULE  VARCHAR2(20) default 'SMS',
  IMP_SOURCE_NAME    VARCHAR2(200),
  IMP_WHERE_CLAUSE   VARCHAR2(1000) default '1=1',
  IMP_NAME_ATTRIB    VARCHAR2(1000),
  IMP_AUTO_IMPORT    VARCHAR2(1) default 'N'
)
tablespace NITIL
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_CI_TYPES
  add constraint NIT_CPK_CIT primary key (ID)
  using index 
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_CI_TYPES
  add constraint NIT_CUK_CIT unique (NAME)
  using index 
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_CI_TYPES
  add constraint NIT_CFK_CIT_CIT foreign key (CIT_ID)
  references NIT_CI_TYPES (ID);
alter table NIT_CI_TYPES
  add constraint AVCON_1152194129_COULD_000
  check (COULD_IN_STOCK IN ('N', 'Y'));
alter table NIT_CI_TYPES
  add constraint AVCON_1152194129_NEED__000
  check (NEED_PO IN ('N', 'Y'));
alter table NIT_CI_TYPES
  add constraint AVCON_1169557883_COULD_001
  check (COULD_IN_INVENTORY IN ('N', 'Y'));
alter table NIT_CI_TYPES
  add constraint AVCON_1169557883_IS_IM_000
  check (IS_IMPORTABLE IN ('N', 'Y'));
create bitmap index NIT_IDX_CIT_AUTO_IMPORT on NIT_CI_TYPES (IMP_AUTO_IMPORT)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create bitmap index NIT_IDX_CIT_IMPORTABLE on NIT_CI_TYPES (IS_IMPORTABLE)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create bitmap index NIT_IDX_CIT_INVENTORY on NIT_CI_TYPES (COULD_IN_INVENTORY)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create bitmap index NIT_IDX_CIT_NEEDPO on NIT_CI_TYPES (NEED_PO)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IDX_CIT_ORDER_IN_LIST on NIT_CI_TYPES (ORDER_IN_LIST, CIT_ID)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create bitmap index NIT_IDX_CIT_STOCK on NIT_CI_TYPES (COULD_IN_STOCK)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IFK_CIT_CIT on NIT_CI_TYPES (CIT_ID)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_CI_PROPERTIES
prompt ================================
prompt
create table NIT_CI_PROPERTIES
(
  ID                INTEGER not null,
  CREATION_DATE     DATE not null,
  CREATED_BY        VARCHAR2(30) not null,
  LAST_UPDATE_DATE  DATE not null,
  LAST_UPDATED_BY   VARCHAR2(30) not null,
  CIPT_ID           INTEGER not null,
  CIT_ID            INTEGER not null,
  CIP_ID_ANCIENT    INTEGER,
  CIP_ID            INTEGER,
  REQUIRED          VARCHAR2(1) default 'N' not null,
  SET_LIKE          VARCHAR2(1) default 'N' not null,
  IS_INHERITED      VARCHAR2(1) default 'N' not null,
  ORDER_IN_LIST     INTEGER default 0 not null,
  DESCRIPTION       VARCHAR2(1000),
  COMMENTS          VARCHAR2(1000),
  IS_IMPORTABLE     VARCHAR2(1) default 'N' not null,
  IMP_SOURCE_MODULE VARCHAR2(20) default 'SMS',
  IMP_SOURCE_NAME   VARCHAR2(200),
  IMP_AUTO_CIPV     VARCHAR2(1) default 'N',
  IMP_CASCADE_CIP   VARCHAR2(1) default 'N',
  IMP_CASCADE_CIPV  VARCHAR2(1) default 'N',
  IMP_AUTO_IMPORT   VARCHAR2(1) default 'N'
)
tablespace NITIL
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_CI_PROPERTIES
  add constraint NITIL_CPK_CIP primary key (ID)
  using index 
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_CI_PROPERTIES
  add constraint NIT_CUK_CIP unique (CIPT_ID, CIT_ID)
  using index 
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_CI_PROPERTIES
  add constraint NIT_CFK_CIP_CIP foreign key (CIP_ID)
  references NIT_CI_PROPERTIES (ID);
alter table NIT_CI_PROPERTIES
  add constraint NIT_CFK_CIP_CIPT foreign key (CIPT_ID)
  references NIT_CI_PROPERTY_TYPES (ID);
alter table NIT_CI_PROPERTIES
  add constraint NIT_CFK_CIP_CIP2 foreign key (CIP_ID_ANCIENT)
  references NIT_CI_PROPERTIES (ID);
alter table NIT_CI_PROPERTIES
  add constraint NIT_CFK_CIP_CIT foreign key (CIT_ID)
  references NIT_CI_TYPES (ID);
alter table NIT_CI_PROPERTIES
  add constraint AVCON_1152194129_IS_IN_000
  check (IS_INHERITED IN ('N', 'Y'));
alter table NIT_CI_PROPERTIES
  add constraint AVCON_1152194129_REQUI_000
  check (REQUIRED IN ('N', 'Y'));
alter table NIT_CI_PROPERTIES
  add constraint AVCON_1152194129_SET_L_000
  check (SET_LIKE IN ('N', 'Y'));
alter table NIT_CI_PROPERTIES
  add constraint AVCON_1169557883_IMP_A_000
  check (IMP_AUTO_CIPV IN ('N', 'Y'));
alter table NIT_CI_PROPERTIES
  add constraint AVCON_1169557883_IMP_C_000
  check (IMP_CASCADE_CIP IN ('N', 'Y'));
alter table NIT_CI_PROPERTIES
  add constraint AVCON_1169557883_IMP_C_001
  check (IMP_CASCADE_CIPV IN ('N', 'Y'));
alter table NIT_CI_PROPERTIES
  add constraint AVCON_1169557883_IS_IM_001
  check (IS_IMPORTABLE IN ('N', 'Y'));
create bitmap index NIT_IDX_CIP_AUTO_IMPORT on NIT_CI_PROPERTIES (IMP_AUTO_IMPORT)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create bitmap index NIT_IDX_CIP_IS_IMPORTABLE on NIT_CI_PROPERTIES (IS_IMPORTABLE)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create bitmap index NIT_IDX_CIP_IS_INHERITED on NIT_CI_PROPERTIES (IS_INHERITED)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IDX_CIP_ORDER on NIT_CI_PROPERTIES (CIP_ID_ANCIENT, ORDER_IN_LIST)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create bitmap index NIT_IDX_CIP_REQUIRED on NIT_CI_PROPERTIES (REQUIRED)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create bitmap index NIT_IDX_CIP_SETLIKE on NIT_CI_PROPERTIES (SET_LIKE)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IFK_CIP_CIP on NIT_CI_PROPERTIES (CIP_ID)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IFK_CIP_CIP_ANCIENT on NIT_CI_PROPERTIES (CIP_ID_ANCIENT)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IFK_CIP_CIPT on NIT_CI_PROPERTIES (CIPT_ID)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IFK_CIP_CIT on NIT_CI_PROPERTIES (CIT_ID)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_CI_PROPERTY_VALUES
prompt =====================================
prompt
create table NIT_CI_PROPERTY_VALUES
(
  ID               INTEGER not null,
  CREATION_DATE    DATE not null,
  CREATED_BY       VARCHAR2(30) not null,
  LAST_UPDATE_DATE DATE not null,
  LAST_UPDATED_BY  VARCHAR2(30) not null,
  CIP_ID           INTEGER not null,
  IS_DEFAULT       VARCHAR2(1) default 'N' not null,
  ORDER_IN_LIST    INTEGER default 0 not null,
  VALUE            VARCHAR2(4000) not null,
  DESCRIPTION      VARCHAR2(1000),
  COMMENTS         VARCHAR2(1000)
)
tablespace NITIL
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_CI_PROPERTY_VALUES
  add constraint NIT_CPK_CIPV primary key (ID)
  using index 
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_CI_PROPERTY_VALUES
  add constraint NIT_CUK_CIPV unique (CIP_ID, VALUE)
  using index 
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_CI_PROPERTY_VALUES
  add constraint NIT_CFK_CIPV_CIP foreign key (CIP_ID)
  references NIT_CI_PROPERTIES (ID);
alter table NIT_CI_PROPERTY_VALUES
  add constraint AVCON_1152194129_IS_DE_000
  check (IS_DEFAULT IN ('N', 'Y'));
create index NIT_IDX_CIPV_ORDER on NIT_CI_PROPERTY_VALUES (ORDER_IN_LIST, CIP_ID)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_OPERATIONS
prompt =============================
prompt
create table NIT_OPERATIONS
(
  ID               INTEGER not null,
  CREATION_DATE    DATE not null,
  CREATED_BY       VARCHAR2(30) not null,
  LAST_UPDATE_DATE DATE not null,
  LAST_UPDATED_BY  VARCHAR2(30) not null,
  USR_ID           INTEGER not null,
  TYPE_NAME        VARCHAR2(20) default 'routine' not null,
  STATUS           VARCHAR2(20) not null,
  OP_TIME          DATE default CURRENT_DATE not null,
  USERS            VARCHAR2(1000),
  COMMENTS         VARCHAR2(1000)
)
tablespace NITIL
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_OPERATIONS
  add constraint NIT_CPK_OPN primary key (ID)
  using index 
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_CFK_OPN_USR on NIT_OPERATIONS (USR_ID)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create bitmap index NIT_IDX_OPN_STATUS on NIT_OPERATIONS (STATUS)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create bitmap index NIT_IDX_OPN_TYPE on NIT_OPERATIONS (TYPE_NAME)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_CONFIG_ITEMS
prompt ===============================
prompt
create table NIT_CONFIG_ITEMS
(
  ID                INTEGER not null,
  CREATION_DATE     DATE not null,
  CREATED_BY        VARCHAR2(30) not null,
  LAST_UPDATE_DATE  DATE not null,
  LAST_UPDATED_BY   VARCHAR2(30) not null,
  CIT_ID            INTEGER not null,
  OPN_ID            INTEGER not null,
  NAME              VARCHAR2(100) not null,
  STATUS            VARCHAR2(20) not null,
  OBSOLETE          VARCHAR2(1) default 'L' not null,
  VALID_FROM        DATE not null,
  VALID_UNTIL       DATE not null,
  COMMENTS          VARCHAR2(1000),
  SMS_ID            VARCHAR2(200),
  LAST_REFRESH_DATE DATE
)
tablespace NITIL
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_CONFIG_ITEMS
  add constraint NIT_CPK_CI primary key (ID)
  using index 
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_CONFIG_ITEMS
  add constraint NIT_CFK_CI_CIT foreign key (CIT_ID)
  references NIT_CI_TYPES (ID);
alter table NIT_CONFIG_ITEMS
  add constraint NIT_CFK_CI_OPN foreign key (OPN_ID)
  references NIT_OPERATIONS (ID);
create index NIT_CUK_CI_NAME on NIT_CONFIG_ITEMS (NAME)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create bitmap index NIT_IDX_CI_OBSOLETE on NIT_CONFIG_ITEMS (OBSOLETE)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IDX_CI_SMS_ID on NIT_CONFIG_ITEMS (SMS_ID)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create bitmap index NIT_IDX_CI_STATUS on NIT_CONFIG_ITEMS (STATUS)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IDX_CI_VALID_FROM on NIT_CONFIG_ITEMS (VALID_FROM)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IDX_CI_VALID_UNTIL on NIT_CONFIG_ITEMS (VALID_UNTIL)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_CI_ATTRIBUTES
prompt ================================
prompt
create table NIT_CI_ATTRIBUTES
(
  ID                INTEGER not null,
  CREATION_DATE     DATE not null,
  CREATED_BY        VARCHAR2(30) not null,
  LAST_UPDATE_DATE  DATE not null,
  LAST_UPDATED_BY   VARCHAR2(30) not null,
  CI_ID             INTEGER not null,
  CIP_ID            INTEGER not null,
  OPN_ID            INTEGER not null,
  CIPV_ID           INTEGER,
  STATUS            VARCHAR2(20) not null,
  OBSOLETE          VARCHAR2(1) default 'L' not null,
  VALID_FROM        DATE not null,
  VALID_UNTIL       DATE not null,
  DATA              VARCHAR2(4000) not null,
  COMMENTS          VARCHAR2(1000),
  SMS_ID            VARCHAR2(200),
  LAST_REFRESH_DATE DATE
)
tablespace NITIL
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_CI_ATTRIBUTES
  add constraint NIT_CPK_CIA primary key (ID)
  using index 
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_CI_ATTRIBUTES
  add constraint NIT_CFK_CIA_CI foreign key (CI_ID)
  references NIT_CONFIG_ITEMS (ID);
alter table NIT_CI_ATTRIBUTES
  add constraint NIT_CFK_CIA_CIP foreign key (CIP_ID)
  references NIT_CI_PROPERTIES (ID);
alter table NIT_CI_ATTRIBUTES
  add constraint NIT_CFK_CIA_CIPV foreign key (CIPV_ID)
  references NIT_CI_PROPERTY_VALUES (ID);
alter table NIT_CI_ATTRIBUTES
  add constraint NIT_CFK_CIA_OPN foreign key (OPN_ID)
  references NIT_OPERATIONS (ID);
create bitmap index NIT_IDX_CIA_OBSOLETE on NIT_CI_ATTRIBUTES (OBSOLETE)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IDX_CIA_SMS_ID on NIT_CI_ATTRIBUTES (SMS_ID)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create bitmap index NIT_IDX_CIA_STATUS on NIT_CI_ATTRIBUTES (STATUS)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IDX_CIA_VALID_FROM on NIT_CI_ATTRIBUTES (VALID_FROM)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IDX_CIA_VALID_UNTIL on NIT_CI_ATTRIBUTES (VALID_UNTIL)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IFK_CIA_CI on NIT_CI_ATTRIBUTES (CI_ID)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IFK_CIA_CIP on NIT_CI_ATTRIBUTES (CIP_ID)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IFK_CIA_CIPV on NIT_CI_ATTRIBUTES (CIPV_ID)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IFK_CIA_OPN on NIT_CI_ATTRIBUTES (OPN_ID)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_CI_TYPE_RELATIONS
prompt ====================================
prompt
create table NIT_CI_TYPE_RELATIONS
(
  ID               INTEGER not null,
  CREATION_DATE    DATE not null,
  CREATED_BY       VARCHAR2(30) not null,
  LAST_UPDATE_DATE DATE not null,
  LAST_UPDATED_BY  VARCHAR2(30) not null,
  CIT_ID_FROM      INTEGER not null,
  CIT_ID_TO        INTEGER not null,
  CITRT_ID         INTEGER not null,
  ORDER_IN_LIST    INTEGER default 0 not null,
  DESCRIPTION      VARCHAR2(1000),
  COMMENTS         VARCHAR2(1000)
)
tablespace NITIL
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_CI_TYPE_RELATIONS
  add constraint NIT_CPK_CITR primary key (ID)
  using index 
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_CI_TYPE_RELATIONS
  add constraint NIT_CUK_CITR unique (CITRT_ID, CIT_ID_FROM, CIT_ID_TO)
  using index 
  tablespace NITIL
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_CI_TYPE_RELATIONS
  add constraint NIT_CFK_CITR_CIT_FROM foreign key (CIT_ID_FROM)
  references NIT_CI_TYPES (ID);
alter table NIT_CI_TYPE_RELATIONS
  add constraint NIT_CFK_CITR_CIT_TO foreign key (CIT_ID_TO)
  references NIT_CI_TYPES (ID);
create index NIT_IDX_CITR_ORDER on NIT_CI_TYPE_RELATIONS (CIT_ID_FROM, CIT_ID_TO, CITRT_ID, ORDER_IN_LIST)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IFK_CITR_CIT_FROM on NIT_CI_TYPE_RELATIONS (CIT_ID_FROM)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IFK_CITR_CITRT on NIT_CI_TYPE_RELATIONS (CITRT_ID)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IFK_CITR_CIT_TO on NIT_CI_TYPE_RELATIONS (CIT_ID_TO)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_CI_RELATIONS
prompt ===============================
prompt
create table NIT_CI_RELATIONS
(
  ID               INTEGER not null,
  CREATION_DATE    DATE not null,
  CREATED_BY       VARCHAR2(30) not null,
  LAST_UPDATE_DATE DATE not null,
  LAST_UPDATED_BY  VARCHAR2(30) not null,
  CI_ID_FROM       INTEGER not null,
  CI_ID_TO         INTEGER not null,
  CITR_ID          INTEGER not null,
  OPN_ID           INTEGER not null,
  STATUS           VARCHAR2(20) not null,
  OBSOLETE         VARCHAR2(1) default 'L' not null,
  VALID_FROM       DATE not null,
  VALID_UNTIL      DATE not null,
  COMMENTS         VARCHAR2(1000)
)
tablespace NITIL
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_CI_RELATIONS
  add constraint NIT_CPK_CIR primary key (ID)
  using index 
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_CI_RELATIONS
  add constraint NIT_CFK_CIR foreign key (CITR_ID)
  references NIT_CI_TYPE_RELATIONS (ID);
alter table NIT_CI_RELATIONS
  add constraint NIT_CFK_CIR_CI_FROM foreign key (CI_ID_FROM)
  references NIT_CONFIG_ITEMS (ID);
alter table NIT_CI_RELATIONS
  add constraint NIT_CFK_CIR_CI_TO foreign key (CI_ID_TO)
  references NIT_CONFIG_ITEMS (ID);
alter table NIT_CI_RELATIONS
  add constraint NIT_CFK_CIR_OPN foreign key (OPN_ID)
  references NIT_OPERATIONS (ID);
alter table NIT_CI_RELATIONS
  add constraint NIT_CTC_CIR_SELF_REF_DENY
  check (CI_ID_FROM <> CI_ID_TO);
create bitmap index NIT_IDX_CIR_OBSOLETE on NIT_CI_RELATIONS (OBSOLETE)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create bitmap index NIT_IDX_CIR_STATUS on NIT_CI_RELATIONS (STATUS)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IDX_CIR_VALID_FROM on NIT_CI_RELATIONS (VALID_FROM)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IDX_CIR_VALID_UNTIL on NIT_CI_RELATIONS (VALID_UNTIL)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IFK_CIR_CI_FROM on NIT_CI_RELATIONS (CI_ID_FROM)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IFK_CIR_CI_TO on NIT_CI_RELATIONS (CI_ID_TO)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IFK_CIR_CITR on NIT_CI_RELATIONS (CITR_ID)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IFK_CIR_OPN on NIT_CI_RELATIONS (OPN_ID)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_CIT_RELATION_TYPES
prompt =====================================
prompt
create table NIT_CIT_RELATION_TYPES
(
  ID               INTEGER not null,
  CREATION_DATE    DATE not null,
  CREATED_BY       VARCHAR2(30) not null,
  LAST_UPDATE_DATE DATE not null,
  LAST_UPDATED_BY  VARCHAR2(30) not null,
  NAME             VARCHAR2(100) not null,
  DESCRIPTION      VARCHAR2(1000),
  COMMENTS         VARCHAR2(1000)
)
tablespace NITIL
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_CIT_RELATION_TYPES
  add constraint NIT_CPK_CITRT primary key (ID)
  using index 
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_CIT_RELATION_TYPES
  add constraint NIT_CUK_CITRT unique (NAME)
  using index 
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_EXCEPTIONS
prompt =============================
prompt
create table NIT_EXCEPTIONS
(
  ID              INTEGER not null,
  NAME            VARCHAR2(100) not null,
  CODE            VARCHAR2(30) not null,
  MESSAGE         VARCHAR2(1000),
  IN_ENGINE       VARCHAR2(1) default 'N' not null,
  HOSTNAME        VARCHAR2(1000),
  USERNAME        VARCHAR2(100),
  STAMP           DATE,
  MODULE_NAME     VARCHAR2(1000) not null,
  MODULE_VERSION  VARCHAR2(100) not null,
  SUBPROGRAM_NAME VARCHAR2(1000) not null,
  CALL_PARAMETERS VARCHAR2(1000),
  ERROR_STACK     VARCHAR2(1000),
  CALL_STACK      VARCHAR2(1000),
  BACKTRACE       VARCHAR2(1000),
  LINE_NO         INTEGER
)
tablespace NITIL
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_EXCEPTIONS
  add constraint NIT_CPK_EX primary key (ID)
  using index 
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_EXCEPTIONS
  add constraint AVCON_1152194129_IN_EN_000
  check (IN_ENGINE IN ('N', 'Y'));

prompt
prompt Creating table NIT_LOCATIONS
prompt ============================
prompt
create table NIT_LOCATIONS
(
  ID               INTEGER not null,
  CREATION_DATE    DATE not null,
  CREATED_BY       VARCHAR2(30) not null,
  LAST_UPDATE_DATE DATE not null,
  LAST_UPDATED_BY  VARCHAR2(30) not null,
  LCN_ID           INTEGER,
  NAME             VARCHAR2(100) not null,
  ABBREVIATION     VARCHAR2(30),
  NAMING_PATTERN   VARCHAR2(1000),
  DESCRIPTION      VARCHAR2(1000),
  COMMENTS         VARCHAR2(1000),
  ICON_NAME        VARCHAR2(100),
  MAP              VARCHAR2(500)
)
tablespace NITIL
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_LOCATIONS
  add constraint NIT_CPK_LCN primary key (ID)
  using index 
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_LOCATIONS
  add constraint NIT_CUK_LCN unique (NAME)
  using index 
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_LOCATIONS
  add constraint NIT_CFK_LCN foreign key (LCN_ID)
  references NIT_LOCATIONS (ID);
create index NIT_IFK_LCN_LCN on NIT_LOCATIONS (LCN_ID)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_MESSAGES
prompt ===========================
prompt
create table NIT_MESSAGES
(
  ID               INTEGER not null,
  CREATION_DATE    DATE not null,
  CREATED_BY       VARCHAR2(30) not null,
  LAST_UPDATE_DATE DATE not null,
  LAST_UPDATED_BY  VARCHAR2(30) not null,
  CODE             VARCHAR2(30) not null,
  LANGUAGE         VARCHAR2(4) default 'US' not null,
  SOURCE_LANG      VARCHAR2(4) default 'US' not null,
  MESSAGE          VARCHAR2(1000) not null,
  HINT             VARCHAR2(1000),
  USED_IN          VARCHAR2(1000),
  COMMENTS         VARCHAR2(1000)
)
tablespace NITIL
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_MESSAGES
  add constraint NIT_CPK_MSG primary key (ID)
  using index 
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_MESSAGES
  add constraint NIT_CUK_MSG unique (CODE, LANGUAGE)
  using index 
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_MESSAGES
  add constraint AVCON_1160724272_LANGU_000
  check (LANGUAGE IN ('HU', 'US'));
alter table NIT_MESSAGES
  add constraint AVCON_1160724272_SOURC_000
  check (SOURCE_LANG IN ('HU', 'US'));

prompt
prompt Creating table NIT_PARAMETERS
prompt =============================
prompt
create table NIT_PARAMETERS
(
  ID               INTEGER not null,
  CREATION_DATE    DATE,
  LAST_UPDATE_DATE DATE,
  CREATED_BY       VARCHAR2(30),
  NAME             VARCHAR2(100) not null,
  VALUE            VARCHAR2(4000) not null,
  DATA_TYPE        VARCHAR2(30) default 'varchar2',
  IS_SETTING       VARCHAR2(1) default 'N',
  LAST_UPDATED_BY  VARCHAR2(30)
)
tablespace NITIL
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_PARAMETERS
  add constraint NIT_CPK_PARAM primary key (ID)
  using index 
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_PARAMETERS
  add constraint NIT_CUK_PARAM unique (NAME, VALUE)
  using index 
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_PARAMETERS
  add constraint AVCON_1168957425_IS_SE_000
  check (IS_SETTING IN ('N', 'Y'));

prompt
prompt Creating table NIT_POSITIONS
prompt ============================
prompt
create table NIT_POSITIONS
(
  ID               INTEGER not null,
  CREATION_DATE    DATE not null,
  CREATED_BY       VARCHAR2(30) not null,
  LAST_UPDATE_DATE DATE not null,
  LAST_UPDATED_BY  VARCHAR2(30) not null,
  CI_ID            INTEGER not null,
  LCN_ID           INTEGER not null,
  OPN_ID           INTEGER not null,
  STATUS           VARCHAR2(20) not null,
  OBSOLETE         VARCHAR2(1) default 'L' not null,
  VALID_FROM       DATE not null,
  VALID_UNTIL      DATE not null,
  COMMENTS         VARCHAR2(1000)
)
tablespace NITIL
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_POSITIONS
  add constraint NIT_CPK_PSN primary key (ID)
  using index 
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_POSITIONS
  add constraint NIT_CFK_PSN_CI foreign key (CI_ID)
  references NIT_CONFIG_ITEMS (ID);
alter table NIT_POSITIONS
  add constraint NIT_CFK_PSN_LCN foreign key (LCN_ID)
  references NIT_LOCATIONS (ID);
alter table NIT_POSITIONS
  add constraint NIT_CFK_PSN_OPN foreign key (OPN_ID)
  references NIT_OPERATIONS (ID);
create bitmap index NIT_IDX_PSN_OBSOLETE on NIT_POSITIONS (OBSOLETE)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create bitmap index NIT_IDX_PSN_STATUS on NIT_POSITIONS (STATUS)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IDX_PSN_VALID_FROM on NIT_POSITIONS (VALID_FROM)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IDX_PSN_VALID_UNTIL on NIT_POSITIONS (VALID_UNTIL)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 512K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IFK_PSN_CI on NIT_POSITIONS (CI_ID)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IFK_PSN_LCN on NIT_POSITIONS (LCN_ID)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IFK_PSN_OPN on NIT_POSITIONS (OPN_ID)
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_SMS_ADD_REMOVE_PROGRAMS
prompt ==========================================
prompt
create table NIT_SMS_ADD_REMOVE_PROGRAMS
(
  SMS_ID      VARCHAR2(123) not null,
  RESOURCE_ID INTEGER,
  GROUP_ID    INTEGER,
  REVISION_ID INTEGER,
  AGENT_ID    INTEGER,
  TIMESTAMP   DATE,
  PRODID      VARCHAR2(300),
  DISPLAYNAME VARCHAR2(300),
  INSTALLDATE VARCHAR2(300),
  PUBLISHER   VARCHAR2(300),
  VERSION     VARCHAR2(300)
)
tablespace SMS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_ADD_REMOVE_PROGRAMS
  add constraint NIT_CPK_SMS_PROG primary key (SMS_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_ADD_REMOVE_PROGRAMS
  add constraint NIT_CUK_SMS_PROG unique (RESOURCE_ID, GROUP_ID, REVISION_ID, AGENT_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_SMS_CDROM
prompt ============================
prompt
create table NIT_SMS_CDROM
(
  SMS_ID       VARCHAR2(123) not null,
  RESOURCE_ID  INTEGER,
  GROUP_ID     INTEGER,
  REVISION_ID  INTEGER,
  AGENT_ID     INTEGER,
  TIMESTAMP    DATE,
  AVAILABILITY INTEGER,
  DESCRIPTION  VARCHAR2(600),
  DEVICEID     VARCHAR2(300),
  DRIVE        VARCHAR2(300),
  MANUFACTURER VARCHAR2(300),
  MEDIATYPE    VARCHAR2(300),
  SCSITARGETID INTEGER,
  SYSTEMNAME   VARCHAR2(300),
  VOLUMENAME   VARCHAR2(600)
)
tablespace SMS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_CDROM
  add constraint NIT_CPK_SMS_CDROM primary key (SMS_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_CDROM
  add constraint NIT_CUK_SMS_CDROM unique (RESOURCE_ID, GROUP_ID, REVISION_ID, AGENT_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_SMS_COMPUTER_SYSTEM
prompt ======================================
prompt
create table NIT_SMS_COMPUTER_SYSTEM
(
  SMS_ID             VARCHAR2(123) not null,
  RESOURCE_ID        INTEGER,
  GROUP_ID           INTEGER,
  REVISION_ID        INTEGER,
  AGENT_ID           INTEGER,
  TIMESTAMP          DATE,
  CURRENTTIMEZONE    INTEGER,
  DESCRIPTION        VARCHAR2(600),
  DOMAIN             VARCHAR2(300),
  MODEL              VARCHAR2(300),
  NAME               VARCHAR2(300),
  ROLES              VARCHAR2(300),
  STATUS             VARCHAR2(300),
  USERNAME           VARCHAR2(300),
  DOMAINROLE         INTEGER,
  MANUFACTURER       VARCHAR2(300),
  NUMBEROFPROCESSORS INTEGER,
  SYSTEMTYPE         VARCHAR2(300),
  PAUSEAFTERRESET    VARCHAR2(300)
)
tablespace SMS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_COMPUTER_SYSTEM
  add constraint NIT_CPK_SMS_COMP primary key (SMS_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_COMPUTER_SYSTEM
  add constraint NIT_CUK_SMS_COMP unique (RESOURCE_ID, GROUP_ID, REVISION_ID, AGENT_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
create index NIT_IDX_COMPUTER_SYSTEM_SMS_ID on NIT_SMS_COMPUTER_SYSTEM (SUBSTR(SMS_ID,1,INSTR(SMS_ID,'#',1,3)))
  tablespace NITIL
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_SMS_DESKTOP_MONITOR
prompt ======================================
prompt
create table NIT_SMS_DESKTOP_MONITOR
(
  SMS_ID                VARCHAR2(123) not null,
  RESOURCE_ID           INTEGER,
  GROUP_ID              INTEGER,
  REVISION_ID           INTEGER,
  AGENT_ID              INTEGER,
  TIMESTAMP             DATE,
  DESCRIPTION           VARCHAR2(300),
  DEVICEID              VARCHAR2(300),
  DISPLAYTYPE           INTEGER,
  MONITORMANUFACTURER   VARCHAR2(300),
  MONITORTYPE           VARCHAR2(300),
  NAME                  VARCHAR2(300),
  PIXELSPERXLOGICALINCH INTEGER,
  PIXELSPERYLOGICALINCH INTEGER,
  SCREENHEIGHT          INTEGER,
  SCREENWIDTH           INTEGER
)
tablespace SMS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_DESKTOP_MONITOR
  add constraint NIT_CPK_SMS_MONITOR primary key (SMS_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_DESKTOP_MONITOR
  add constraint NIT_CUK_SMS_MONITOR unique (RESOURCE_ID, GROUP_ID, REVISION_ID, AGENT_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_SMS_DISK
prompt ===========================
prompt
create table NIT_SMS_DISK
(
  SMS_ID          VARCHAR2(123) not null,
  RESOURCE_ID     INTEGER,
  GROUP_ID        INTEGER,
  REVISION_ID     INTEGER,
  AGENT_ID        INTEGER,
  TIMESTAMP       DATE,
  AVAILABILITY    INTEGER,
  DESCRIPTION     VARCHAR2(600),
  DEVICEID        VARCHAR2(300),
  DISK_INDEX      INTEGER,
  INTERFACETYPE   VARCHAR2(300),
  MANUFACTURER    VARCHAR2(300),
  MEDIATYPE       VARCHAR2(300),
  NAME            VARCHAR2(300),
  PARTITIONS      INTEGER,
  PNPDEVICEID     VARCHAR2(300),
  SCSIBUS         INTEGER,
  SCSILOGICALUNIT INTEGER,
  SCSIPORT        INTEGER,
  SCSITARGETID    INTEGER,
  DISKSIZE        INTEGER,
  SYSTEMNAME      VARCHAR2(300),
  TOTALCYLINDERS  VARCHAR2(300),
  TOTALSECTORS    VARCHAR2(300),
  TOTALTRACKS     VARCHAR2(300)
)
tablespace SMS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_DISK
  add constraint NIT_CPK_SMS_DISK primary key (SMS_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_DISK
  add constraint NIT_CUK_SMS_DISK unique (RESOURCE_ID, GROUP_ID, REVISION_ID, AGENT_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_SMS_IDE_CONTROLLER
prompt =====================================
prompt
create table NIT_SMS_IDE_CONTROLLER
(
  SMS_ID       VARCHAR2(123) not null,
  RESOURCE_ID  INTEGER,
  GROUP_ID     INTEGER,
  REVISION_ID  INTEGER,
  AGENT_ID     INTEGER,
  TIMESTAMP    DATE,
  AVAILABILITY INTEGER,
  DESCRIPTION  VARCHAR2(300),
  DEVICEID     VARCHAR2(300),
  MANUFACTURER VARCHAR2(300),
  NAME         VARCHAR2(300),
  STATUS       VARCHAR2(300)
)
tablespace SMS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_IDE_CONTROLLER
  add constraint NIT_CPK_SMS_IDE primary key (SMS_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_IDE_CONTROLLER
  add constraint NIT_CUK_SMS_IDE unique (RESOURCE_ID, GROUP_ID, REVISION_ID, AGENT_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_SMS_MODEM_DEVICE
prompt ===================================
prompt
create table NIT_SMS_MODEM_DEVICE
(
  SMS_ID                  VARCHAR2(123) not null,
  RESOURCE_ID             INTEGER,
  GROUP_ID                INTEGER,
  REVISION_ID             INTEGER,
  AGENT_ID                INTEGER,
  TIMESTAMP               DATE,
  ANSWERMODE              VARCHAR2(300),
  DEVICEID                VARCHAR2(300),
  DEVICETYPE              VARCHAR2(300),
  MODEM_INDEX             INTEGER,
  MAXBAUDRATETOPHONE      INTEGER,
  MAXBAUDRATETOSERIALPORT INTEGER,
  MODEL                   VARCHAR2(300),
  NAME                    VARCHAR2(300),
  PROPERTIES              VARCHAR2(300),
  STATUS                  VARCHAR2(300),
  STRINGFORMAT            VARCHAR2(300),
  SYSTEMNAME              VARCHAR2(300),
  VOICESWITHFEATURE       VARCHAR2(300)
)
tablespace SMS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_MODEM_DEVICE
  add constraint NIT_CPK_SMS_MODEM primary key (SMS_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_MODEM_DEVICE
  add constraint NIT_SMS_CUK_MODEM unique (RESOURCE_ID, GROUP_ID, REVISION_ID, AGENT_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_SMS_MOTHERBOARD_DEVICE
prompt =========================================
prompt
create table NIT_SMS_MOTHERBOARD_DEVICE
(
  SMS_ID           VARCHAR2(123) not null,
  RESOURCE_ID      INTEGER,
  GROUP_ID         INTEGER,
  REVISION_ID      INTEGER,
  AGENT_ID         INTEGER,
  TIMESTAMP        DATE,
  DESCRIPTION      VARCHAR2(600),
  DEVICEID         VARCHAR2(300),
  PRIMARYBUSTYPE   VARCHAR2(300),
  REVISIONNUMBER   VARCHAR2(300),
  SECONDARYBUSTYPE VARCHAR2(300),
  STATUS           VARCHAR2(300),
  STATUSINFO       VARCHAR2(300),
  SYSTEMNAME       VARCHAR2(300)
)
tablespace SMS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_MOTHERBOARD_DEVICE
  add constraint NIT_CPK_SMS_MOBO primary key (SMS_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_MOTHERBOARD_DEVICE
  add constraint NIT_CUK_SMS_MOBO unique (RESOURCE_ID, GROUP_ID, REVISION_ID, AGENT_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_SMS_NETWORK_ADAPTER
prompt ======================================
prompt
create table NIT_SMS_NETWORK_ADAPTER
(
  SMS_ID       VARCHAR2(123) not null,
  RESOURCE_ID  INTEGER,
  GROUP_ID     INTEGER,
  REVISION_ID  INTEGER,
  AGENT_ID     INTEGER,
  TIMESTAMP    DATE,
  ADAPTERTYPE  VARCHAR2(300),
  DESCRIPTION  VARCHAR2(600),
  DEVICEID     VARCHAR2(300),
  MACADDRESS   VARCHAR2(300),
  MANUFACTURER VARCHAR2(300),
  NAME         VARCHAR2(300),
  PRODUCTNAME  VARCHAR2(300),
  SERVICENAME  VARCHAR2(300),
  STATUS       VARCHAR2(300),
  MAXSPEED     VARCHAR2(300),
  SPEED        VARCHAR2(300)
)
tablespace SMS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_NETWORK_ADAPTER
  add constraint NIT_CPK_SMS_NIC primary key (SMS_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_NETWORK_ADAPTER
  add constraint NIT_CUK_SMS_NIC unique (RESOURCE_ID, GROUP_ID, REVISION_ID, AGENT_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_SMS_NETWORK_ADAPTER_CONFIG
prompt =============================================
prompt
create table NIT_SMS_NETWORK_ADAPTER_CONFIG
(
  SMS_ID           VARCHAR2(123) not null,
  RESOURCE_ID      INTEGER,
  GROUP_ID         INTEGER,
  REVISION_ID      INTEGER,
  AGENT_ID         INTEGER,
  TIMESTAMP        DATE,
  DEFAULTIPGATEWAY VARCHAR2(300),
  DHCPENABLED      INTEGER,
  IPADDRESS        VARCHAR2(300),
  IPSUBNET         VARCHAR2(300),
  MACADDRESS       VARCHAR2(300),
  SERVICENAME      VARCHAR2(300),
  DHCPSERVER       VARCHAR2(300),
  IPENABLED        INTEGER,
  IPXENABLED       INTEGER
)
tablespace SMS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_NETWORK_ADAPTER_CONFIG
  add constraint NIT_CPK_SMS_NIC_CFG primary key (SMS_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_NETWORK_ADAPTER_CONFIG
  add constraint NIT_CUK_SMS_NIC_CFG unique (RESOURCE_ID, GROUP_ID, REVISION_ID, AGENT_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_SMS_OPERATING_SYSTEM
prompt =======================================
prompt
create table NIT_SMS_OPERATING_SYSTEM
(
  SMS_ID                 VARCHAR2(123) not null,
  RESOURCE_ID            INTEGER,
  GROUP_ID               INTEGER,
  REVISION_ID            INTEGER,
  AGENT_ID               INTEGER,
  TIMESTAMP              DATE,
  BOOTDEVICE             VARCHAR2(300),
  BUILDNUMBER            VARCHAR2(300),
  CAPTION                VARCHAR2(300),
  COUNTRYCODE            VARCHAR2(300),
  CSDVERSION             VARCHAR2(300),
  DESCRIPTION            VARCHAR2(600),
  FREEPHYSICALMEMORY     INTEGER,
  FREEVIRTUALMEMORY      INTEGER,
  INSTALLDATE            DATE,
  LASTBOOTUPTIME         DATE,
  LOCALE                 VARCHAR2(300),
  MANUFACTURER           VARCHAR2(300),
  MAXNUMBEROFPROCESSES   VARCHAR2(300),
  NAME                   VARCHAR2(300),
  OSLANGUAGE             INTEGER,
  SYSTEMDIRECTORY        VARCHAR2(300),
  TOTALSWAPSPACESIZE     INTEGER,
  TOTALVIRTUALMEMORYSIZE INTEGER,
  TOTALVISIBLEMEMORYSIZE INTEGER,
  VERSION                VARCHAR2(300),
  WINDOWSDIRECTORY       VARCHAR2(300)
)
tablespace SMS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_OPERATING_SYSTEM
  add constraint NIT_CPK_SMS_OS primary key (SMS_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_OPERATING_SYSTEM
  add constraint NIT_CUK_SMS_OS unique (RESOURCE_ID, GROUP_ID, REVISION_ID, AGENT_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_SMS_PARALLEL_PORT
prompt ====================================
prompt
create table NIT_SMS_PARALLEL_PORT
(
  SMS_ID       VARCHAR2(123) not null,
  RESOURCE_ID  INTEGER,
  GROUP_ID     INTEGER,
  REVISION_ID  INTEGER,
  AGENT_ID     INTEGER,
  TIMESTAMP    DATE,
  AVAILABILITY INTEGER,
  CAPABILITIES VARCHAR2(300),
  DEVICEID     VARCHAR2(300),
  NAME         VARCHAR2(300),
  STATUS       VARCHAR2(300)
)
tablespace SMS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_PARALLEL_PORT
  add constraint NIT_CPK_SMS_PARPORT primary key (SMS_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_PARALLEL_PORT
  add constraint NIT_CUK_SMS_PARPORT unique (RESOURCE_ID, GROUP_ID, REVISION_ID, AGENT_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_SMS_PC_BIOS
prompt ==============================
prompt
create table NIT_SMS_PC_BIOS
(
  SMS_ID                VARCHAR2(123) not null,
  RESOURCE_ID           INTEGER,
  GROUP_ID              INTEGER,
  REVISION_ID           INTEGER,
  AGENT_ID              INTEGER,
  TIMESTAMP             DATE,
  DESCRIPTION           VARCHAR2(600),
  MANUFACTURER          VARCHAR2(600),
  NAME                  VARCHAR2(300),
  RELEASEDATE           DATE,
  SERIALNUMBER          VARCHAR2(300),
  SMBIOSBIOSVERSION     VARCHAR2(300),
  SOFTWAREELEMENTID     VARCHAR2(300),
  SOFTWAREELEMENTSTATE  INTEGER,
  TARGETOPERATINGSYSTEM INTEGER,
  VERSION               VARCHAR2(300)
)
tablespace SMS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_PC_BIOS
  add constraint NIT_CPK_SMS_BIOS primary key (SMS_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_PC_BIOS
  add constraint NIT_CUK_SMS_BIOS unique (RESOURCE_ID, GROUP_ID, REVISION_ID, AGENT_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_SMS_PROCESSOR
prompt ================================
prompt
create table NIT_SMS_PROCESSOR
(
  SMS_ID            VARCHAR2(123) not null,
  RESOURCE_ID       INTEGER,
  GROUP_ID          INTEGER,
  REVISION_ID       INTEGER,
  AGENT_ID          INTEGER,
  TIMESTAMP         DATE,
  ADDRESSWIDTH      INTEGER,
  CURRENTCLOCKSPEED INTEGER,
  DATAWIDTH         INTEGER,
  DEVICEID          VARCHAR2(300),
  FAMILY            INTEGER,
  MANUFACTURER      VARCHAR2(300),
  MAXCLOCKSPEED     INTEGER,
  NAME              VARCHAR2(300),
  PROCESSORID       VARCHAR2(300),
  PROCESSORTYPE     INTEGER,
  REVISION          INTEGER,
  SOCKETDESIGNATION VARCHAR2(300),
  STATUS            VARCHAR2(300),
  SYSTEMNAME        VARCHAR2(300),
  VERSION           VARCHAR2(300)
)
tablespace SMS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_PROCESSOR
  add constraint NIT_CPK_SMS_PROC primary key (SMS_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_PROCESSOR
  add constraint NIT_CUK_SMS_PROC unique (RESOURCE_ID, GROUP_ID, REVISION_ID, AGENT_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_SMS_SCSI_CONTROLLER
prompt ======================================
prompt
create table NIT_SMS_SCSI_CONTROLLER
(
  SMS_ID          VARCHAR2(123) not null,
  RESOURCE_ID     INTEGER,
  GROUP_ID        INTEGER,
  REVISION_ID     INTEGER,
  AGENT_ID        INTEGER,
  TIMESTAMP       DATE,
  AVAILABILITY    INTEGER,
  DESCRIPTION     VARCHAR2(600),
  DEVICEID        VARCHAR2(300),
  DRIVERNAME      VARCHAR2(300),
  HARDWAREVERSION VARCHAR2(300),
  SCSI_INDEX      INTEGER,
  MANUFACTURER    VARCHAR2(300),
  NAME            VARCHAR2(300),
  STATUS          VARCHAR2(300),
  MAXTRANSFERRATE VARCHAR2(300)
)
tablespace SMS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_SCSI_CONTROLLER
  add constraint NIT_CPK_SMS_SCSI primary key (SMS_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_SCSI_CONTROLLER
  add constraint NIT_CUK_SMS_SCSI unique (RESOURCE_ID, GROUP_ID, REVISION_ID, AGENT_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_SMS_SERVICE
prompt ==============================
prompt
create table NIT_SMS_SERVICE
(
  SMS_ID      VARCHAR2(123) not null,
  RESOURCE_ID INTEGER,
  GROUP_ID    INTEGER,
  REVISION_ID INTEGER,
  AGENT_ID    INTEGER,
  TIMESTAMP   DATE,
  DISPLAYNAME VARCHAR2(300),
  NAME        VARCHAR2(300),
  PATHNAME    VARCHAR2(600),
  SERVICETYPE VARCHAR2(300),
  STARTED     INTEGER,
  STARTMODE   VARCHAR2(300),
  STARTNAME   VARCHAR2(300),
  STATE       VARCHAR2(300),
  STATUS      VARCHAR2(300)
)
tablespace SMS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_SERVICE
  add constraint NIT_CPK_SMS_SERVICE primary key (SMS_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_SERVICE
  add constraint NIT_CUK_SMS_SERVICE unique (RESOURCE_ID, GROUP_ID, REVISION_ID, AGENT_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_SMS_SOUND_DEVICE
prompt ===================================
prompt
create table NIT_SMS_SOUND_DEVICE
(
  SMS_ID       VARCHAR2(123) not null,
  RESOURCE_ID  INTEGER,
  GROUP_ID     INTEGER,
  REVISION_ID  INTEGER,
  AGENT_ID     INTEGER,
  TIMESTAMP    DATE,
  AVAILABILITY INTEGER,
  DESCRIPTION  VARCHAR2(600),
  DEVICEID     VARCHAR2(300),
  INSTALLDATE  DATE,
  MANUFACTURER VARCHAR2(300),
  NAME         VARCHAR2(300),
  PNPDEVICEID  VARCHAR2(300),
  PRODUCTNAME  VARCHAR2(300),
  STATUS       VARCHAR2(300)
)
tablespace SMS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_SOUND_DEVICE
  add constraint NIT_CPK_SMS_SOUND primary key (SMS_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_SOUND_DEVICE
  add constraint NIT_CUK_SMS_SOUND unique (RESOURCE_ID, GROUP_ID, REVISION_ID, AGENT_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_SMS_SYSTEM_ENCLOSURE
prompt =======================================
prompt
create table NIT_SMS_SYSTEM_ENCLOSURE
(
  SMS_ID         VARCHAR2(123) not null,
  RESOURCE_ID    INTEGER,
  GROUP_ID       INTEGER,
  REVISION_ID    INTEGER,
  AGENT_ID       INTEGER,
  TIMESTAMP      DATE,
  CHASSISTYPES   VARCHAR2(100),
  MANUFACTURER   VARCHAR2(300),
  SERIALNUMBER   VARCHAR2(300),
  SMBIOSASSETTAG VARCHAR2(300),
  TAG            VARCHAR2(300)
)
tablespace SMS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_SYSTEM_ENCLOSURE
  add constraint NIT_CPK_SMS_SYSTEM_ENC primary key (SMS_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_SYSTEM_ENCLOSURE
  add constraint NIT_SMS_CUK_SYSTEM_ENC unique (RESOURCE_ID, GROUP_ID, REVISION_ID, AGENT_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_SMS_TAPE_DRIVE
prompt =================================
prompt
create table NIT_SMS_TAPE_DRIVE
(
  SMS_ID       VARCHAR2(123) not null,
  RESOURCE_ID  INTEGER,
  GROUP_ID     INTEGER,
  REVISION_ID  INTEGER,
  AGENT_ID     INTEGER,
  TIMESTAMP    VARCHAR2(300),
  AVAILABILITY INTEGER,
  DESCRIPTION  VARCHAR2(600),
  DEVICEID     VARCHAR2(300),
  MEDIATYPE    VARCHAR2(300),
  NAME         VARCHAR2(300),
  STATUS       VARCHAR2(300)
)
tablespace SMS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_TAPE_DRIVE
  add constraint NIT_CPK_SMS_TAPE primary key (SMS_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_TAPE_DRIVE
  add constraint NIT_CUK_SMS_TAPE unique (RESOURCE_ID, GROUP_ID, REVISION_ID, AGENT_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_SMS_USB_CONTROLLER
prompt =====================================
prompt
create table NIT_SMS_USB_CONTROLLER
(
  SMS_ID       VARCHAR2(123) not null,
  RESOURCE_ID  INTEGER,
  GROUP_ID     INTEGER,
  REVISION_ID  INTEGER,
  AGENT_ID     INTEGER,
  TIMESTAMP    DATE,
  AVAILABILITY INTEGER,
  DESCRIPTION  VARCHAR2(300),
  DEVICEID     VARCHAR2(300),
  NAME         VARCHAR2(300)
)
tablespace SMS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_USB_CONTROLLER
  add constraint NIT_CPK_SMS_USB primary key (SMS_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_USB_CONTROLLER
  add constraint NIT_CUK_SMS_USB unique (RESOURCE_ID, GROUP_ID, REVISION_ID, AGENT_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_SMS_X86_PC_MEMORY
prompt ====================================
prompt
create table NIT_SMS_X86_PC_MEMORY
(
  SMS_ID                 VARCHAR2(123) not null,
  RESOURCE_ID            INTEGER,
  GROUP_ID               INTEGER,
  REVISION_ID            INTEGER,
  AGENT_ID               INTEGER,
  TIMESTAMP              DATE,
  AVAILABLEVIRTUALMEMORY INTEGER,
  NAME                   VARCHAR2(300),
  TOTALPAGEFILESPACE     INTEGER,
  TOTALPHYSICALMEMORY    INTEGER,
  TOTALVIRTUALMEMORY     INTEGER
)
tablespace SMS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_X86_PC_MEMORY
  add constraint NIT_CPK_SMS_MEM primary key (SMS_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_SMS_X86_PC_MEMORY
  add constraint NIT_CUK_SMS_MEM unique (RESOURCE_ID, GROUP_ID, REVISION_ID, AGENT_ID)
  using index 
  tablespace SMS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );

prompt
prompt Creating table NIT_USERS
prompt ========================
prompt
create table NIT_USERS
(
  ID               INTEGER not null,
  CREATION_DATE    DATE not null,
  CREATED_BY       VARCHAR2(30) not null,
  LAST_UPDATE_DATE DATE not null,
  LAST_UPDATED_BY  VARCHAR2(30) not null,
  USERNAME         VARCHAR2(60) not null,
  REALNAME         VARCHAR2(100),
  EMAIL            VARCHAR2(1000) not null,
  COMMENTS         VARCHAR2(1000),
  LANGUAGE         VARCHAR2(4) default 'US' not null,
  ROLE             VARCHAR2(30)
)
tablespace NITIL
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_USERS
  add constraint NIT_CPK_USR primary key (ID)
  using index 
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_USERS
  add constraint NIT_CUK_USR unique (USERNAME)
  using index 
  tablespace NITILX
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 512K
    minextents 1
    maxextents unlimited
    pctincrease 0
  );
alter table NIT_USERS
  add constraint AVCON_1169557883_LANGU_001
  check (LANGUAGE IN ('HU', 'US'));

prompt
prompt Creating sequence NIT_SEQ
prompt =========================
prompt
create sequence NIT_SEQ
minvalue 60011371
maxvalue 999999999999999999999999999
start with 82001912
increment by 1
cache 20;

prompt
prompt Creating package NIT_ERROR_P
prompt ============================
prompt
CREATE OR REPLACE PACKAGE nit_error_p AUTHID CURRENT_USER IS

   FUNCTION package_version RETURN VARCHAR2;

   PROCEDURE enable_ex_logging;
   PROCEDURE disable_ex_logging;
   FUNCTION get_ex_logging RETURN CHAR;

   PROCEDURE log_exception(ex_backtrace_str IN VARCHAR2
                          ,ex_call_str      IN VARCHAR2
                          ,ex_error_str     IN VARCHAR2
                          ,ex_in_engine     IN VARCHAR2
                          ,ex_module        IN VARCHAR2
                          ,ex_version       IN VARCHAR2
                          ,ex_sub           IN VARCHAR2
                          ,ex_params        IN VARCHAR2);

   -----------------------------------------------------------------------------
   -- Name:        GetErrors
   -- Description: Pops all messages off the stack and returns them in the order
   --              in which they were raised.
   -- Parameters:  none
   -- Returns:     The messages

   FUNCTION geterrors RETURN VARCHAR2;

   -----------------------------------------------------------------------------
   -- Name:        pop
   -- Description: Take a message off stack
   --              Gets the error message that was last raised and removes it
   --              from the error stack.
   -- Parameters:  msg     Text message
   -- Returns:     TRUE    Message popped successfully
   --              FALSE   Stack was empty

   FUNCTION pop(msg OUT VARCHAR2) RETURN BOOLEAN;

   -----------------------------------------------------------------------------
   -- Name:        pop (overload)
   -- Description: Take a message off stack with full info
   -- Parameters:  msg      Ttext message
   --              error    ERRor or WARNing
   --              msg_type ORA, API or user TLA
   --              msg_id   Id of message
   --              loc      Location where error occured
   -- Returns:     TRUE     Message popped successfully
   --              FALSE    Stack was empty

   FUNCTION pop(msg      OUT VARCHAR2
               ,error    OUT VARCHAR2
               ,msg_type OUT VARCHAR2
               ,msgid    OUT INTEGER
               ,loc      OUT VARCHAR2) RETURN BOOLEAN;

   -----------------------------------------------------------------------------
   -- Name:        pop_head
   -- Description: Take a message off stack from head
   --              Gets the error message that was last raised and removes it
   --              from the error stack.
   -- Parameters:  msg     Text message
   -- Returns:     TRUE    Message popped successfully
   --              FALSE   Stack was empty
   -----------------------------------------------------------------------------
   FUNCTION pop_head(msg OUT VARCHAR2) RETURN BOOLEAN;


   -----------------------------------------------------------------------------
   -- Name:        pop_head (overload)
   -- Description: Take a message off stack from head with full info
   -- Parameters:  msg      Ttext message
   --              error    ERRor or WARNing
   --              msg_type ORA, API or user TLA
   --              msg_id   Id of message
   --              loc      Location where error occured
   -- Returns:     TRUE     Message popped successfully
   --              FALSE    Stack was empty
   -----------------------------------------------------------------------------
   FUNCTION pop_head(msg      OUT VARCHAR2
                    ,error    OUT VARCHAR2
                    ,msg_type OUT VARCHAR2
                    ,msgid    OUT INTEGER
                    ,loc      OUT VARCHAR2) RETURN BOOLEAN;

   -----------------------------------------------------------------------------
   -- Name:        raise_failure
   --
   -- Description: To raise the cg$error failure exception handler

   PROCEDURE raise_failure;

   -----------------------------------------------------------------------------
   -- Name:        clear
   -- Description: Clears the stack
   -- Parameters:  none

   PROCEDURE clear;

   -----------------------------------------------------------------------------
   -- Name:        push
   --
   -- Description: Put a message on stack with full info
   --
   -- Parameters:  msg      Text message
   --              error    ERRor or WARNing
   --              msg_type ORA, API or user TLA
   --              msg_id   Id of message
   --              loc      Location where error occured

   PROCEDURE push(msg      IN VARCHAR2
                 ,error    IN VARCHAR2 DEFAULT 'E'
                 ,msg_type IN VARCHAR2 DEFAULT NULL
                 ,msgid    IN INTEGER DEFAULT 0
                 ,loc      IN VARCHAR2 DEFAULT NULL);

   -----------------------------------------------------------------------------
   -- Name:        MsgGetText
   -- Description: Provides a mechanism for text translation.
   -- Parameters:  p_MsgNo    The Id of the message
   --              p_DfltText The Default Text
   --              p_Subst1 (to 4) Substitution strings
   --              p_LangId   The Language ID
   -- Returns:    Translated message

   FUNCTION msggettext(p_msgno    IN NUMBER
                      ,p_dflttext IN VARCHAR2 DEFAULT NULL
                      ,p_subst1   IN VARCHAR2 DEFAULT NULL
                      ,p_subst2   IN VARCHAR2 DEFAULT NULL
                      ,p_subst3   IN VARCHAR2 DEFAULT NULL
                      ,p_subst4   IN VARCHAR2 DEFAULT NULL
                      ,p_langid   IN NUMBER DEFAULT NULL) RETURN VARCHAR2;

   -----------------------------------------------------------------------------
   -- Name:        parse_constraint
   -- Description: Isolate constraint name from an Oracle error message
   -- Parameters:  msg     The actual Oracle error message
   --              type    type of constraint to find
   --                      (ERR_FOREIGN_KEY     Foreign key,
   --                       ERR_CHECK_CON       Check,
   --                       ERR_UNIQUE_KEY      Unique key,
   --                       ERR_DELETE_RESTRICT Restricted delete)
   -- Returns:     con_name Constraint found (NULL if none found)

   FUNCTION parse_constraint(msg  IN VARCHAR2
                            ,TYPE IN INTEGER) RETURN VARCHAR2;

   -----------------------------------------------------------------------------
   -- Az error elj?r?s a szabv?nyos m?dja, hogy egy szerver-oldali PL/SQL-elj?r?s
   -- kiv?ltsa az ?ltala v?rt ?s ?szlelt hib?t.
   -- (A v?ratlan hib?k kijelz?se maradhat a k?rnyezet hat?sk?r?ben, pl. unhandled
   -- exception)
   --
   -- Param?terek:
   -- p_msg    A hiba?zenet neve vagy sz?vege
   --   (ha XXX-nnnnn alak?, akkor az elj?r?s megpr?b?lja
   --  sz?vegg? konvert?lni a PUB_UZENETEK_V n?zetb?l,
   --  ek?zben kicser?li a <p1>...<p4> sztringeket.
   -- p_error    A hiba s?lyoss?g?t jelz? karakter ('E'rror, 'W'arning)
   -- p_raise_flag Logikai ?rt?k: kell-e az elj?r?s v?g?n raise_failure?
   -- p_p1   Az 1. behelyettes?tend? v?ltoz?
   -- p_p2   A 2. behelyettes?tend? v?ltoz?
   -- p_p3   A 3. behelyettes?tend? v?ltoz?
   -- p_p4   A 4. behelyettes?tend? v?ltoz?

   PROCEDURE error(p_msg        VARCHAR2
                  ,p_error      VARCHAR2 DEFAULT 'E'
                  ,p_raise_flag BOOLEAN DEFAULT TRUE
                  ,p_p1         VARCHAR2 DEFAULT NULL
                  ,p_p2         VARCHAR2 DEFAULT NULL
                  ,p_p3         VARCHAR2 DEFAULT NULL
                  ,p_p4         VARCHAR2 DEFAULT NULL);
   --
   -- Exception raised when any API validation fails
   --
   cg$error EXCEPTION;
   --
   -- Standard Oracle Errors that are caught and processed by the API
   --
   mandatory_missing EXCEPTION;
   check_violation EXCEPTION;
   fk_violation EXCEPTION;
   upd_mandatory_null EXCEPTION;
   delete_restrict EXCEPTION;
   uk_violation EXCEPTION;
   resource_busy EXCEPTION;
   no_data_found EXCEPTION;
   trg_mutate EXCEPTION;


   err_uk_update            CONSTANT VARCHAR2(240) := 'Unique key <p1> not updateable';
   err_fk_trans             CONSTANT VARCHAR2(240) := 'Foreign key <p1> not transferable';
   err_del_restrict         CONSTANT VARCHAR2(240) := 'Cannot delete <p1> row, matching <p2> found';
   val_mand                 CONSTANT VARCHAR2(240) := 'Value for <p1> is required';
   row_mod                  CONSTANT VARCHAR2(240) := 'Update failed - please re-query as value for <p1> has been modified by another user<p2><p3>';
   row_lck                  CONSTANT VARCHAR2(240) := 'Row is locked by another user';
   row_del                  CONSTANT VARCHAR2(240) := 'Row no longer exists';
   apimsg_pk_violat         CONSTANT VARCHAR2(240) := 'Primary key <p1> on table <p2> violated';
   apimsg_uk_violat         CONSTANT VARCHAR2(240) := 'Unique constraint <p1> on table <p2> violated';
   apimsg_fk_violat         CONSTANT VARCHAR2(240) := 'Foreign key <p1> on table <p2> violated';
   apimsg_ck_violat         CONSTANT VARCHAR2(240) := 'Check constraint <p1> on table <p2> violated';
   apimsg_arc_mand_violat   CONSTANT VARCHAR2(240) := 'Mandatory Arc <p1> on <p2> has not been satisfied';
   apimsg_arc_violat        CONSTANT VARCHAR2(240) := 'Too many members in Arc <p1> on <p2>';
   apimsg_rv_tab_not_found  CONSTANT VARCHAR2(240) := 'Reference code table <p1> has not been created used for <p2>';
   apimsg_rv_lookup_fail    CONSTANT VARCHAR2(240) := 'Invalid value <p1> for column <p2>.<p3>';
   apimsg_rv_lookup_do_fail CONSTANT VARCHAR2(240) := 'Invalid value <p1> in domain <p2> for column <p3>.<p4>';
   apimsg_code_ctl_locked   CONSTANT VARCHAR2(240) := 'Control table sequence value <p1> is being used by another user';
   apimsg_fk_value_required CONSTANT VARCHAR2(240) := 'Value required for <p1> foreign key';
   apimsg_casc_error        CONSTANT VARCHAR2(240) := 'Error in cascade <p1>';
   apimsg_do_lookup_do_fail CONSTANT VARCHAR2(240) := 'Invalid values in domain constraint <p1> referring domain table <p2> for table <p3>';

   api_unique_key_update  CONSTANT INTEGER := 1001;
   api_foreign_key_trans  CONSTANT INTEGER := 1002;
   api_modified           CONSTANT INTEGER := 1003;
   api_ck_con_violated    CONSTANT INTEGER := 1004;
   api_fk_con_violated    CONSTANT INTEGER := 1005;
   api_uq_con_violated    CONSTANT INTEGER := 1006;
   api_pk_con_violated    CONSTANT INTEGER := 1007;
   api_mand_column_isnull CONSTANT INTEGER := 1008;
   api_mand_arc_empty     CONSTANT INTEGER := 1009;
   api_arc_too_many_val   CONSTANT INTEGER := 1010;
   api_del_restrict       CONSTANT INTEGER := 1011;
   api_rv_tab_not_found   CONSTANT INTEGER := 1012;
   api_rv_lookup_fail     CONSTANT INTEGER := 1013;
   api_rv_lookup_do_fail  CONSTANT INTEGER := 1014;
   api_code_ctl_locked    CONSTANT INTEGER := 1015;
   api_fk_value_required  CONSTANT INTEGER := 1016;
   api_casc_error         CONSTANT INTEGER := 1017;
   api_row_mod            CONSTANT INTEGER := 1018;
   api_row_lck            CONSTANT INTEGER := 1019;
   api_row_del            CONSTANT INTEGER := 1020;

   err_foreign_key     CONSTANT INTEGER := -2291;
   err_check_con       CONSTANT INTEGER := -2290;
   err_unique_key      CONSTANT INTEGER := -1;
   err_mand_missing    CONSTANT INTEGER := -1400;
   err_update_mand     CONSTANT INTEGER := -1407;
   err_resource_busy   CONSTANT INTEGER := -54;
   err_no_data         CONSTANT INTEGER := 1403;
   err_delete_restrict CONSTANT INTEGER := -2292;

   PRAGMA EXCEPTION_INIT(mandatory_missing
                        ,-1400);
   PRAGMA EXCEPTION_INIT(check_violation
                        ,-2290);
   PRAGMA EXCEPTION_INIT(fk_violation
                        ,-2291);
   PRAGMA EXCEPTION_INIT(upd_mandatory_null
                        ,-1407);
   PRAGMA EXCEPTION_INIT(delete_restrict
                        ,-2292);
   PRAGMA EXCEPTION_INIT(uk_violation
                        ,-0001);
   PRAGMA EXCEPTION_INIT(resource_busy
                        ,-0054);
   PRAGMA EXCEPTION_INIT(trg_mutate
                        ,-4091);

   --   PRAGMA EXCEPTION_INIT(cg$error,           -20999);

   -- Az al?bbi konstanst ?s az ut?na l?v? pl/sql t?blaelem-m?retet szinkronban kell tartani!
   k_msg_size CONSTANT PLS_INTEGER := 512;
   TYPE cg$err_msg_t IS TABLE OF VARCHAR2(512) INDEX BY BINARY_INTEGER;
   -- Az el?bbi t?blaelem-m?retet ?s a k_msg_size konstanst szinkronban kell tartani!

   TYPE cg$err_error_t IS TABLE OF VARCHAR2(1) INDEX BY BINARY_INTEGER;
   TYPE cg$err_msg_type_t IS TABLE OF VARCHAR2(3) INDEX BY BINARY_INTEGER;
   TYPE cg$err_msgid_t IS TABLE OF INTEGER INDEX BY BINARY_INTEGER;
   TYPE cg$err_loc_t IS TABLE OF VARCHAR2(240) INDEX BY BINARY_INTEGER;
   cg$err_tab_i INTEGER := 1;

   ------------------------------------------------------------------------------
   -- A convert_to_text funkci? megk?s?rli ?tford?tani a hibak?dot hiba?zenett?.
   -- Ha siker?lt, az elej?re teszi a hibak?dot is.

   FUNCTION convert_to_text(p_msg VARCHAR2
                           ,p_p1  VARCHAR2 DEFAULT NULL
                           ,p_p2  VARCHAR2 DEFAULT NULL
                           ,p_p3  VARCHAR2 DEFAULT NULL
                           ,p_p4  VARCHAR2 DEFAULT NULL) RETURN VARCHAR2;

   FUNCTION get_hint(p_msg VARCHAR2) RETURN VARCHAR2;
END nit_error_p;
/

prompt
prompt Creating synonym CG$ERRORS
prompt ==========================
prompt
create or replace synonym CG$ERRORS
  for NITIL.NIT_ERROR_P;

prompt
prompt Creating view CG_CODE_CONTROLS_V
prompt ================================
prompt
CREATE OR REPLACE VIEW CG_CODE_CONTROLS_V AS
SELECT CG_CODE_CONTROLS.CC_DOMAIN CC_DOMAIN
,CG_CODE_CONTROLS.CC_COMMENT CC_COMMENT
,CG_CODE_CONTROLS.CC_NEXT_VALUE CC_NEXT_VALUE
,CG_CODE_CONTROLS.CC_INCREMENT CC_INCREMENT
FROM CG_CODE_CONTROLS
/

prompt
prompt Creating view NIT_CI_PROPERTIES_V
prompt =================================
prompt
CREATE OR REPLACE VIEW NIT_CI_PROPERTIES_V AS
SELECT "ID","CREATION_DATE","CREATED_BY","LAST_UPDATE_DATE","LAST_UPDATED_BY","CIPT_ID","CIT_ID","CIP_ID_ANCIENT","CIP_ID","REQUIRED","SET_LIKE","IS_INHERITED","ORDER_IN_LIST","DESCRIPTION","COMMENTS" FROM NIT_CI_PROPERTIES
/

prompt
prompt Creating view NIT_CI_PROPERTY_TYPES_V
prompt =====================================
prompt
CREATE OR REPLACE VIEW NIT_CI_PROPERTY_TYPES_V AS
SELECT CIPT.ID ID
,CIPT.CREATION_DATE CREATION_DATE
,CIPT.CREATED_BY CREATED_BY
,CIPT.LAST_UPDATE_DATE LAST_UPDATE_DATE
,CIPT.LAST_UPDATED_BY LAST_UPDATED_BY
,CIPT.NAME NAME
,CIPT.TYPE_NAME TYPE_NAME
,CIPT.MIME_TYPE MIME_TYPE
,CIPT.DESCRIPTION DESCRIPTION
,CIPT.COMMENTS COMMENTS
FROM NIT_CI_PROPERTY_TYPES CIPT
/

prompt
prompt Creating view NIT_CI_PROPERTY_VALUES_V
prompt ======================================
prompt
CREATE OR REPLACE VIEW NIT_CI_PROPERTY_VALUES_V AS
SELECT "ID","CREATION_DATE","CREATED_BY","LAST_UPDATE_DATE","LAST_UPDATED_BY","CIP_ID","IS_DEFAULT","ORDER_IN_LIST","VALUE","DESCRIPTION","COMMENTS" FROM NIT_CI_PROPERTY_VALUES
/

prompt
prompt Creating view NIT_CIT_RELATION_TYPES_V
prompt ======================================
prompt
CREATE OR REPLACE VIEW NIT_CIT_RELATION_TYPES_V AS
SELECT CITRT.ID ID
,CITRT.CREATION_DATE CREATION_DATE
,CITRT.CREATED_BY CREATED_BY
,CITRT.LAST_UPDATE_DATE LAST_UPDATE_DATE
,CITRT.LAST_UPDATED_BY LAST_UPDATED_BY
,CITRT.NAME NAME
,CITRT.DESCRIPTION DESCRIPTION
,CITRT.COMMENTS COMMENTS
FROM NIT_CIT_RELATION_TYPES CITRT
/

prompt
prompt Creating view NIT_CI_TYPE_RELATIONS_V
prompt =====================================
prompt
CREATE OR REPLACE VIEW NIT_CI_TYPE_RELATIONS_V AS
SELECT "ID","CREATION_DATE","CREATED_BY","LAST_UPDATE_DATE","LAST_UPDATED_BY","CIT_ID_FROM","CIT_ID_TO","CITRT_ID","ORDER_IN_LIST","DESCRIPTION","COMMENTS" FROM NIT_CI_TYPE_RELATIONS
/

prompt
prompt Creating view NIT_CI_TYPES_V
prompt ============================
prompt
CREATE OR REPLACE VIEW NIT_CI_TYPES_V AS
SELECT CIT.ID ID
,CIT.CREATION_DATE CREATION_DATE
,CIT.CREATED_BY CREATED_BY
,CIT.LAST_UPDATE_DATE LAST_UPDATE_DATE
,CIT.LAST_UPDATED_BY LAST_UPDATED_BY
,CIT.CIT_ID CIT_ID
,CIT.NAME NAME
,CIT.NEED_PO NEED_PO
,CIT.COULD_IN_STOCK COULD_IN_STOCK
,CIT.ORDER_IN_LIST ORDER_IN_LIST
,CIT.ABBREVIATION ABBREVIATION
,CIT.NAMING_PATTERN NAMING_PATTERN
,CIT.DESCRIPTION DESCRIPTION
,CIT.COMMENTS COMMENTS
,CIT.ICON_NAME ICON_NAME
FROM NIT_CI_TYPES CIT
/

prompt
prompt Creating package CG$NIT_CI_PROPERTY_TYPES
prompt =========================================
prompt
CREATE OR REPLACE PACKAGE cg$nit_ci_property_types AUTHID CURRENT_USER IS


   called_from_package BOOLEAN := FALSE;

   --  Repository User-Defined Error Messages
   nit_cpk_cipt CONSTANT VARCHAR2(240) := '';
   nit_cuk_cipt CONSTANT VARCHAR2(240) := 'NIT-00064';

   --  Column := prompts. Format PSEQNO_COL
   p10id               CONSTANT VARCHAR2(240) := 'Id';
   p15creation_date    CONSTANT VARCHAR2(240) := 'Creation Date';
   p16created_by       CONSTANT VARCHAR2(240) := 'Created By';
   p19last_update_date CONSTANT VARCHAR2(240) := 'Last Update Date';
   p20last_updated_by  CONSTANT VARCHAR2(240) := 'Last Updated By';
   p30name             CONSTANT VARCHAR2(240) := 'Name';
   p51type_name        CONSTANT VARCHAR2(240) := 'Type Name';
   p61mime_type        CONSTANT VARCHAR2(240) := 'Mime Type';
   p66description      CONSTANT VARCHAR2(240) := 'Description';
   p71comments         CONSTANT VARCHAR2(240) := 'Comment';

   cg$row nit_ci_property_types%ROWTYPE;

   --  NIT_CI_PROPERTY_TYPES row type variable
   TYPE cg$row_type IS RECORD(
       id               cg$row.id%TYPE
      ,creation_date    cg$row.creation_date%TYPE
      ,created_by       cg$row.created_by%TYPE
      ,last_update_date cg$row.last_update_date%TYPE
      ,last_updated_by  cg$row.last_updated_by%TYPE
      ,NAME             cg$row.NAME%TYPE
      ,type_name        cg$row.type_name%TYPE
      ,mime_type        cg$row.mime_type%TYPE
      ,description      cg$row.description%TYPE
      ,comments         cg$row.comments%TYPE
      ,the_rowid        ROWID);

   --  NIT_CI_PROPERTY_TYPES indicator type variable
   TYPE cg$ind_type IS RECORD(
       id               BOOLEAN := FALSE
      ,creation_date    BOOLEAN := FALSE
      ,created_by       BOOLEAN := FALSE
      ,last_update_date BOOLEAN := FALSE
      ,last_updated_by  BOOLEAN := FALSE
      ,NAME             BOOLEAN := FALSE
      ,type_name        BOOLEAN := FALSE
      ,mime_type        BOOLEAN := FALSE
      ,description      BOOLEAN := FALSE
      ,comments         BOOLEAN := FALSE);

   cg$ind_true cg$ind_type;

   --  NIT_CI_PROPERTY_TYPES primary key type variable
   TYPE cg$pk_type IS RECORD(
       id        cg$row.id%TYPE
      ,the_rowid ROWID);

   --  PL/SQL Table Type variable for triggers
   TYPE cg$table_type IS TABLE OF nit_ci_property_types%ROWTYPE INDEX BY BINARY_INTEGER;
   cg$table cg$table_type;

   TYPE cg$tableind_type IS TABLE OF cg$ind_type INDEX BY BINARY_INTEGER;
   cg$tableind cg$tableind_type;
   idx         BINARY_INTEGER := 1;

   PROCEDURE ins(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_ins IN BOOLEAN := TRUE);
   PROCEDURE upd(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_upd IN BOOLEAN := TRUE
                ,cg$pk  IN cg$row_type := NULL);
   PROCEDURE del(cg$pk  IN cg$pk_type
                ,do_del IN BOOLEAN := TRUE);
   PROCEDURE lck(cg$old_rec  IN cg$row_type
                ,cg$old_ind  IN cg$ind_type
                ,nowait_flag IN BOOLEAN := TRUE);
   PROCEDURE slct(cg$sel_rec IN OUT cg$row_type);

   PROCEDURE validate_domain(cg$rec IN OUT cg$row_type
                            ,cg$ind IN cg$ind_type := cg$ind_true);

END cg$nit_ci_property_types;
/

prompt
prompt Creating package NIT_CI_PROPERTY_TYPES_P
prompt ========================================
prompt
CREATE OR REPLACE PACKAGE nit_ci_property_types_p AUTHID CURRENT_USER IS

   FUNCTION package_version RETURN VARCHAR2;

   FUNCTION get_po_cipt_name RETURN VARCHAR2;

   FUNCTION get_name_cipt_name RETURN VARCHAR2;

   FUNCTION get_status_cipt_name RETURN VARCHAR2;

   FUNCTION get_inventory_num_cipt_name RETURN VARCHAR2;

   FUNCTION get_ed_cipt_name RETURN VARCHAR2;

   PROCEDURE pre_dml(p_rec IN OUT cg$nit_ci_property_types.cg$row_type
                    ,p_ind IN OUT cg$nit_ci_property_types.cg$ind_type
                    ,p_op  IN VARCHAR2);

   PROCEDURE pre_del(p_id IN nit_ci_property_types.id%TYPE);

END nit_ci_property_types_p;
/

prompt
prompt Creating view NIT_F_CIA_MAIN_V
prompt ==============================
prompt
CREATE OR REPLACE VIEW NIT_F_CIA_MAIN_V AS
SELECT
   cia.id
  ,cia.ci_id
  ,cia.cip_id
  ,cia.opn_id
  ,cia.cipv_id
  ,cia.sms_id
  ,cipt.name AS CIPT_NAME
  ,cip.required
  ,cip.set_like
  ,cia.status
  ,cia.obsolete
  ,cia.valid_from
  ,cia.valid_until
  ,cia.data
  ,cia.comments
  ,cia.last_refresh_date
  ,cip.order_in_list
FROM nit_ci_attributes cia
    ,nit_ci_properties cip
    ,nit_ci_property_types cipt
WHERE cia.cip_id = cip.id
  AND cip.cipt_id = cipt.id
  AND cipt.name <> nit_ci_property_types_p.get_name_cipt_name
  AND cipt.name <> nit_ci_property_types_p.get_status_cipt_name
/

prompt
prompt Creating type NIT_NUM_CT
prompt ========================
prompt
CREATE OR REPLACE TYPE "NIT_NUM_CT" IS TABLE OF NUMBER;
/

prompt
prompt Creating type NIT_STRING_CT
prompt ===========================
prompt
CREATE OR REPLACE TYPE "NIT_STRING_CT" IS TABLE OF VARCHAR2(300);
/

prompt
prompt Creating package NIT_CORE_P
prompt ===========================
prompt
CREATE OR REPLACE PACKAGE nit_core_p AUTHID CURRENT_USER IS

   ci_props_statuses CONSTANT nit_string_ct := nit_string_ct('planned'
                                                            ,'approved'
                                                            ,'tested'
                                                            ,'done');
   planned_idx       CONSTANT PLS_INTEGER := 1;
   approved_idx      CONSTANT PLS_INTEGER := 2;
   tested_idx        CONSTANT PLS_INTEGER := 3;
   done_idx          CONSTANT PLS_INTEGER := 4;

   ci_statuses     CONSTANT nit_string_ct := nit_string_ct('ordered'
                                                          ,'in use'
                                                          ,'planned'
                                                          ,'end of life'
                                                          ,'approved'
                                                          ,'tested'
                                                          ,'in stock');
   ci_ordered_idx  CONSTANT PLS_INTEGER := 1;
   ci_in_use_idx   CONSTANT PLS_INTEGER := 2;
   ci_planned_idx  CONSTANT PLS_INTEGER := 3;
   ci_eol_idx      CONSTANT PLS_INTEGER := 4;
   ci_approved_idx CONSTANT PLS_INTEGER := 5;
   ci_tested_idx   CONSTANT PLS_INTEGER := 6;
   ci_in_stock_idx CONSTANT PLS_INTEGER := 7;

   -- Public function and procedure declarations
   FUNCTION package_version RETURN VARCHAR2;

   PROCEDURE set_validity(p_valid_from  IN OUT nit_ci_attributes.valid_from%TYPE
                         ,p_valid_until IN OUT nit_ci_attributes.valid_until%TYPE
                         ,p_op          IN nit_ci_attributes.opn_id%TYPE);

   FUNCTION tokenize(p_str   IN VARCHAR2
                    ,p_delim IN VARCHAR2
                    ,p_start IN INTEGER) RETURN nit_string_ct;
   FUNCTION convert(p_coll IN nit_string_ct) RETURN VARCHAR2;

   FUNCTION convert(p_coll IN VARCHAR2) RETURN nit_string_ct;

   FUNCTION char_to_bool(p_char IN CHAR) RETURN BOOLEAN;
   FUNCTION bool_to_char(p_bool IN BOOLEAN) RETURN CHAR;

   FUNCTION exists_in(p_coll    IN nit_string_ct
                     ,p_element IN VARCHAR2) RETURN CHAR;

   FUNCTION exists_in(p_coll    IN nit_num_ct
                     ,p_element IN NUMBER) RETURN CHAR;

   PROCEDURE send_mail(p_mail_addresses IN VARCHAR2
                      ,subject          IN VARCHAR2
                      ,message          IN VARCHAR2);
   FUNCTION validate_email_address(p_email IN VARCHAR2) RETURN CHAR;

   PROCEDURE set_audit(p_creation_date IN OUT DATE
                      ,p_created_by    IN OUT VARCHAR2
                      ,p_last_upd_date IN OUT DATE
                      ,p_last_upd_by   IN OUT VARCHAR2
                      ,p_operation     IN VARCHAR2 DEFAULT 'INS');

   PROCEDURE caseconv(p_str IN OUT NOCOPY VARCHAR2);

   FUNCTION get_allowed_statuses_props(p_status IN nit_ci_relations.status%TYPE)
      RETURN nit_string_ct;

   FUNCTION get_allowed_statuses_ci(p_status IN nit_ci_relations.status%TYPE)
      RETURN nit_string_ct;

   FUNCTION get_allowed_obsoletes(p_obsolete IN nit_ci_relations.obsolete%TYPE)
      RETURN nit_string_ct;

   FUNCTION is_allowed_obsolete_chg(from_obs IN nit_ci_relations.obsolete%TYPE
                                   ,to_obs   IN nit_ci_relations.obsolete%TYPE)
      RETURN CHAR;

   FUNCTION is_allowed_ci_props_status_chg(from_status IN nit_ci_relations.status%TYPE
                                          ,to_status   IN nit_ci_relations.status%TYPE)
      RETURN CHAR;

   FUNCTION is_allowed_ci_status_chg(from_status IN nit_config_items.status%TYPE
                                    ,to_status   IN nit_config_items.status%TYPE)
      RETURN CHAR;

   FUNCTION is_ci_status_chg_downgrade(from_status IN nit_config_items.status%TYPE
                                      ,to_status   IN nit_config_items.status%TYPE)
      RETURN CHAR;

   FUNCTION is_compat_ci_props_ci(p_ci_props_status IN VARCHAR2
                                 ,p_ci_status       IN VARCHAR2) RETURN CHAR;

   FUNCTION get_infinite_date RETURN DATE;

   FUNCTION get_negative_infinite_date RETURN DATE;

   FUNCTION push(p_time IN DATE) RETURN DATE;

   FUNCTION push_back(p_time IN DATE) RETURN DATE;

   FUNCTION get_session_user_id RETURN nit_users.id%TYPE;

   FUNCTION get_ci_eol_status_name RETURN VARCHAR2;

   FUNCTION get_parameter_value(p_name IN nit_parameters.NAME%TYPE)
      RETURN nit_parameters%ROWTYPE;

   FUNCTION getp(p_name IN nit_parameters.NAME%TYPE) RETURN VARCHAR2;

   FUNCTION getpi(p_name IN nit_parameters.NAME%TYPE) RETURN INTEGER;

   FUNCTION getpn(p_name IN nit_parameters.NAME%TYPE) RETURN NUMBER;

   FUNCTION getpd(p_name IN nit_parameters.NAME%TYPE) RETURN DATE;

   FUNCTION getpts(p_name IN nit_parameters.NAME%TYPE) RETURN TIMESTAMP;

END nit_core_p;
/

prompt
prompt Creating package NIT_F_CI_P
prompt ===========================
prompt
CREATE OR REPLACE PACKAGE nit_f_ci_p AUTHID CURRENT_USER IS

   FUNCTION package_version RETURN VARCHAR2;

   TYPE rt_ci IS RECORD(
       id                nit_config_items.id%TYPE
      ,cit_id            nit_config_items.cit_id%TYPE
      ,opn_id            nit_config_items.opn_id%TYPE
      ,pos_id            nit_positions.id%TYPE
      ,lcn_id            nit_locations.id%TYPE
      ,sms_id            nit_config_items.sms_id%TYPE
      ,NAME              nit_config_items.NAME%TYPE
      ,status            nit_config_items.status%TYPE
      ,obsolete          nit_config_items.obsolete%TYPE
      ,location          nit_locations.NAME%TYPE
      ,pos_status        nit_positions.status%TYPE
      ,pos_obsolete      nit_positions.obsolete%TYPE
      ,valid_from        nit_config_items.valid_from%TYPE
      ,valid_until       nit_config_items.valid_until%TYPE
      ,pos_valid_from    nit_positions.valid_from%TYPE
      ,pos_valid_until   nit_positions.valid_until%TYPE
      ,comments          nit_config_items.comments%TYPE
      ,last_refresh_date nit_config_items.last_refresh_date%TYPE);


   TYPE it_ci IS RECORD(
       id                BOOLEAN
      ,cit_id            BOOLEAN
      ,opn_id            BOOLEAN
      ,pos_id            BOOLEAN
      ,lcn_id            BOOLEAN
      ,sms_id            BOOLEAN
      ,NAME              BOOLEAN
      ,status            BOOLEAN
      ,obsolete          BOOLEAN
      ,location          BOOLEAN
      ,pos_status        BOOLEAN
      ,pos_obsolete      BOOLEAN
      ,valid_from        BOOLEAN
      ,valid_until       BOOLEAN
      ,pos_valid_from    BOOLEAN
      ,pos_valid_until   BOOLEAN
      ,comments          BOOLEAN
      ,last_refresh_date BOOLEAN);

   PROCEDURE ci_ins(p_rec IN OUT rt_ci
                   ,p_ind IN it_ci);
   PROCEDURE ci_upd(p_rec IN OUT rt_ci
                   ,p_ind IN it_ci);
   PROCEDURE ci_lck(p_rec IN OUT rt_ci
                   ,p_ind IN it_ci);
   --   PROCEDURE ci_del(p_rec IN OUT rt_ci);

   PROCEDURE init_ci_archive_ids(p_cit_id        IN nit_ci_types.id%TYPE
                                ,p_ci_id         IN nit_config_items.id%TYPE
                                ,p_show_children IN VARCHAR2);

   FUNCTION get_ci_archive_ci_id RETURN NUMBER;

   FUNCTION get_default_name(p_rec IN rt_ci) RETURN VARCHAR2;

   PROCEDURE ci_refresh(p_id IN nit_config_items.id%TYPE);

   PROCEDURE cia_refresh(p_id IN nit_ci_attributes.id%TYPE);

END nit_f_ci_p;
/

prompt
prompt Creating view NIT_F_CI_ARCHIVE_V
prompt ================================
prompt
CREATE OR REPLACE VIEW NIT_F_CI_ARCHIVE_V AS
SELECT "OPN_ID","CI_ID","PSN_ID","CIT_NAME","NAME","STATUS","LOCATION","PSN_STATUS","VALID_FROM","VALID_UNTIL" FROM
(
(
    SELECT psn.opn_id AS opn_id,
           psn.ci_id AS ci_id,
           psn.id AS psn_id,
           cit.name AS cit_name,
           NVL(cia_name.name,ci.name) AS name,
           NVL(cia_status.status,ci.status) AS status,
           lcn.name AS location,
           psn.status AS psn_status,
           greatest(psn.valid_from,nvl(cia_name.valid_from,nit_core_p.get_negative_infinite_date),nvl(cia_status.valid_from,nit_core_p.get_negative_infinite_date)) AS valid_from,
           least(psn.valid_until,nvl(cia_name.valid_until,nit_core_p.get_infinite_date),nvl(cia_status.valid_until,nit_core_p.get_infinite_date)) AS valid_until
      FROM nit_positions psn
          ,(
             SELECT cia.data AS name
                   ,cia.valid_from
                   ,cia.valid_until
             FROM nit_ci_attributes cia
                 ,nit_ci_properties cip
                 ,nit_ci_property_types cipt
             WHERE cia.ci_id = nit_f_ci_p.get_ci_archive_ci_id
               AND cia.cip_id = cip.id
               AND cipt.name = nit_ci_property_types_p.get_name_cipt_name
               AND cip.cipt_id = cipt.id
            ) cia_name
          ,(
             SELECT cia.data AS status
                   ,cia.valid_from
                   ,cia.valid_until
             FROM nit_ci_attributes cia
                 ,nit_ci_properties cip
                 ,nit_ci_property_types cipt
             WHERE cia.ci_id = nit_f_ci_p.get_ci_archive_ci_id
               AND cia.cip_id = cip.id
               AND cipt.name = nit_ci_property_types_p.get_status_cipt_name
               AND cip.cipt_id = cipt.id
            ) cia_status
           ,nit_config_items ci
           ,nit_ci_types cit
           ,nit_locations lcn
      WHERE psn.ci_id = nit_f_ci_p.get_ci_archive_ci_id
        AND cia_name.valid_from(+)  <= psn.valid_from
        AND cia_name.valid_until(+) >= psn.valid_from
        AND cia_status.valid_from(+)  <= psn.valid_from
        AND cia_status.valid_until(+) >= psn.valid_from
        AND ci.id = psn.ci_id
        AND ci.cit_id = cit.id
        AND psn.lcn_id = lcn.id
    UNION
    SELECT cia_name.opn_id AS opn_id
          ,psn.ci_id AS ci_id
          ,psn.id AS psn_id
          ,cit.name AS cit_name
          ,NVL(cia_name.data,ci.name) AS name
          ,NVL(cia_status.data,ci.status) AS status
          ,lcn.name AS location
          ,psn.status AS psn_status
          ,greatest(psn.valid_from,nvl(cia_name.valid_from,nit_core_p.get_negative_infinite_date),nvl(cia_status.valid_from,nit_core_p.get_negative_infinite_date)) AS valid_from
          ,least(psn.valid_until,nvl(cia_name.valid_until,nit_core_p.get_infinite_date),nvl(cia_status.valid_until,nit_core_p.get_infinite_date)) AS valid_until
    FROM nit_ci_attributes cia_name
        ,nit_ci_properties cip_name
        ,nit_ci_property_types cipt_name
        ,(
            SELECT *
            FROM nit_ci_attributes cia_status
                ,nit_ci_properties cip_status
                ,nit_ci_property_types cipt_status
            WHERE cia_status.id = nit_f_ci_p.get_ci_archive_ci_id
              AND cia_status.cip_id = cip_status.id
              AND cipt_status.name = nit_ci_property_types_p.get_status_cipt_name
              AND cip_status.cipt_id = cipt_status.id
         ) cia_status
        ,nit_positions psn
        ,nit_config_items ci
        ,nit_ci_types cit
        ,nit_locations lcn
    WHERE cia_name.ci_id = nit_f_ci_p.get_ci_archive_ci_id
      AND cia_name.cip_id = cip_name.id
      AND cipt_name.name = nit_ci_property_types_p.get_name_cipt_name
      AND cip_name.cipt_id = cipt_name.id
      AND cia_name.ci_id = cia_status.ci_id(+)
      AND psn.valid_from <= cia_name.valid_from
      AND psn.valid_until >= cia_name.valid_from
      AND cia_status.valid_from(+)  <= cia_name.valid_from
      AND cia_status.valid_until(+) >= cia_name.valid_from
      AND ci.id = cia_name.ci_id
      AND ci.cit_id = cit.id
      AND psn.ci_id = cia_name.ci_id
      AND psn.lcn_id = lcn.id
    UNION
    SELECT cia_name.opn_id AS opn_id
          ,psn.ci_id AS ci_id
          ,psn.id AS psn_id
          ,cit.name AS cit_name
          ,NVL(cia_name.data,ci.name) AS name
          ,NVL(cia_status.data,ci.status) AS status
          ,lcn.name AS location
          ,psn.status AS psn_status
          ,greatest(psn.valid_from,nvl(cia_name.valid_from,nit_core_p.get_negative_infinite_date),nvl(cia_status.valid_from,nit_core_p.get_negative_infinite_date)) AS valid_from
          ,least(psn.valid_until,nvl(cia_name.valid_until,nit_core_p.get_infinite_date),nvl(cia_status.valid_until,nit_core_p.get_infinite_date)) AS valid_until
    FROM nit_ci_attributes cia_status
        ,nit_ci_properties cip_status
        ,nit_ci_property_types cipt_status
        ,(
            SELECT *
            FROM nit_ci_attributes cia_name
                ,nit_ci_properties cip_name
                ,nit_ci_property_types cipt_name
            WHERE cia_name.id = nit_f_ci_p.get_ci_archive_ci_id
              AND cia_name.cip_id = cip_name.id
              AND cipt_name.name = nit_ci_property_types_p.get_name_cipt_name
              AND cip_name.cipt_id = cipt_name.id
         ) cia_name
        ,nit_positions psn
        ,nit_config_items ci
        ,nit_ci_types cit
        ,nit_locations lcn
    WHERE cia_status.ci_id = nit_f_ci_p.get_ci_archive_ci_id
      AND cia_status.cip_id = cip_status.id
      AND cipt_status.name = nit_ci_property_types_p.get_status_cipt_name
      AND cip_status.cipt_id = cipt_status.id
      AND cia_status.ci_id = cia_name.ci_id(+)
      AND psn.valid_from <= cia_status.valid_from
      AND psn.valid_until >= cia_status.valid_from
      AND cia_name.valid_from(+)  <= cia_status.valid_from
      AND cia_name.valid_until(+) >= cia_status.valid_from
      AND ci.id = cia_status.ci_id
      AND ci.cit_id = cit.id
      AND psn.ci_id = cia_status.ci_id
      AND psn.lcn_id = lcn.id
)
MINUS
(
    SELECT psn.opn_id AS opn_id,
           psn.ci_id AS ci_id,
           psn.id AS psn_id,
           cit.name AS cit_name,
           ci.name AS name,
           ci.status AS status,
           lcn.name AS location,
           psn.status AS psn_status,
           psn.valid_from AS valid_from,
           psn.valid_until AS valid_until
     FROM nit_positions psn
         ,nit_config_items ci
         ,nit_ci_types cit
         ,nit_locations lcn
     WHERE psn.ci_id = nit_f_ci_p.get_ci_archive_ci_id
       AND psn.obsolete = 'L'
       AND ci.id = psn.ci_id
       AND ci.cit_id = cit.id
       AND psn.lcn_id = lcn.id
)
)
ORDER BY ci_id, valid_from, valid_until
/

prompt
prompt Creating type NIT_CI_ATTRIBUTES_OT
prompt ==================================
prompt
CREATE OR REPLACE TYPE NIT_CI_ATTRIBUTES_OT AS OBJECT
 (ID INTEGER
 ,CREATION_DATE DATE
 ,CREATED_BY VARCHAR2(30)
 ,LAST_UPDATE_DATE DATE
 ,LAST_UPDATED_BY VARCHAR2(30)
 ,CI_ID INTEGER
 ,CIP_ID INTEGER
 ,OPN_ID INTEGER
 ,CIPV_ID INTEGER
 ,SMS_ID VARCHAR2(200)
 ,STATUS VARCHAR2(20)
 ,OBSOLETE VARCHAR2(1)
 ,VALID_FROM DATE
 ,VALID_UNTIL DATE
 ,DATA VARCHAR2(4000)
 ,COMMENTS VARCHAR2(1000)
 ,LAST_REFRESH_DATE DATE
 );
/

prompt
prompt Creating type NIT_CI_ATTRIBUTES_CT
prompt ==================================
prompt
CREATE OR REPLACE TYPE "NIT_CI_ATTRIBUTES_CT" IS TABLE OF NIT_CI_ATTRIBUTES_OT;
/

prompt
prompt Creating package NIT_F_CIA_P
prompt ============================
prompt
CREATE OR REPLACE PACKAGE nit_f_cia_p AUTHID CURRENT_USER IS

   FUNCTION package_version RETURN VARCHAR2;

   TYPE rt_cia IS RECORD(
       id                nit_ci_attributes.id%TYPE
      ,ci_id             nit_ci_attributes.ci_id%TYPE
      ,cip_id            nit_ci_attributes.cip_id%TYPE
      ,opn_id            nit_ci_attributes.opn_id%TYPE
      ,cipv_id           nit_ci_attributes.cipv_id%TYPE
      ,sms_id            nit_ci_attributes.sms_id%TYPE
      ,status            nit_ci_attributes.status%TYPE
      ,obsolete          nit_ci_attributes.obsolete%TYPE
      ,valid_from        nit_ci_attributes.valid_from%TYPE
      ,valid_until       nit_ci_attributes.valid_until%TYPE
      ,data              nit_ci_attributes.data%TYPE
      ,comments          nit_ci_attributes.comments%TYPE
      ,last_refresh_date nit_ci_attributes.last_refresh_date%TYPE);

   TYPE it_cia IS RECORD(
       id                BOOLEAN
      ,ci_id             BOOLEAN
      ,cip_id            BOOLEAN
      ,opn_id            BOOLEAN
      ,cipv_id           BOOLEAN
      ,sms_id            BOOLEAN
      ,status            BOOLEAN
      ,obsolete          BOOLEAN
      ,valid_from        BOOLEAN
      ,valid_until       BOOLEAN
      ,data              BOOLEAN
      ,comments          BOOLEAN
      ,last_refresh_date BOOLEAN);

   PROCEDURE cia_ins(p_rec IN OUT rt_cia
                    ,p_ind IN it_cia);
   PROCEDURE cia_upd(p_rec IN OUT rt_cia
                    ,p_ind IN it_cia);
   PROCEDURE cia_lck(p_rec IN OUT rt_cia
                    ,p_ind IN it_cia);
   PROCEDURE cia_del(p_rec IN OUT rt_cia);

   PROCEDURE init_cia_id(p_id IN nit_ci_attributes.id%TYPE);

   FUNCTION get_cia_revisions RETURN nit_ci_attributes_ct;

END nit_f_cia_p;
/

prompt
prompt Creating view NIT_F_CIA_REVISIONS_V
prompt ===================================
prompt
CREATE OR REPLACE VIEW NIT_F_CIA_REVISIONS_V AS
SELECT cipt.name AS cipt_name
      ,cia.data
      ,cia.status
      ,cia.valid_from
      ,cia.valid_until
FROM TABLE(nit_f_cia_p.get_cia_revisions) cia
    ,nit_ci_properties cip
    ,nit_ci_property_types cipt
WHERE cia.cip_id = cip.id
  AND cip.cipt_id = cipt.id
/

prompt
prompt Creating view NIT_F_CI_BROWSE_V
prompt ===============================
prompt
CREATE OR REPLACE VIEW NIT_F_CI_BROWSE_V AS
SELECT /*+ FIRST_ROWS(15) */
       ci.id AS id
      ,ci.cit_id AS cit_id
      ,cit.name AS cit_name
      ,ci.name AS name
      ,ci.status AS status
      ,lcn.name AS location
      ,psn.status AS psn_status
      ,ci.valid_from AS valid_from
      ,ci.valid_until AS valid_until
--      ,ci.last_refresh_date
FROM nit_config_items ci,
     nit_ci_types cit,
     nit_positions psn,
     nit_locations lcn
WHERE ci.cit_id = cit.id AND
      psn.ci_id = ci.id AND
      psn.obsolete = 'L' AND
      psn.lcn_id = lcn.id
/

prompt
prompt Creating view NIT_F_CI_DETAILS_V
prompt ================================
prompt
CREATE OR REPLACE VIEW NIT_F_CI_DETAILS_V AS
SELECT ci.id AS id
      ,ci.cit_id AS cit_id
      ,ci.opn_id AS opn_id
      ,psn.id AS psn_id
      ,lcn.id AS lcn_id
      ,ci.sms_id
      ,ci.obsolete AS obsolete
      ,psn.obsolete AS psn_obsolete
      ,cit.name AS cit_name
      ,ci.name AS name
      ,ci.status AS status
      ,lcn.name AS location
      ,lcn.map AS lcn_map
      ,psn.status AS psn_status
      ,ci.valid_from AS valid_from
      ,ci.valid_until AS valid_until
      ,psn.valid_from AS psn_valid_from
      ,psn.valid_until AS psn_valid_until
      ,ci.comments AS comments
      ,ci.last_refresh_date
FROM nit_config_items ci,
     nit_ci_types cit,
     nit_positions psn,
     nit_locations lcn
WHERE ci.obsolete = 'L' AND
      ci.cit_id = cit.id AND
      psn.ci_id = ci.id AND
      psn.obsolete = 'L' AND
      psn.lcn_id = lcn.id
/

prompt
prompt Creating view NIT_F_CI_LIFE_CIA_V
prompt =================================
prompt
CREATE OR REPLACE VIEW NIT_F_CI_LIFE_CIA_V AS
SELECT opn.id AS opn_id
      ,DECODE(cia.obsolete,'D','deleted',nvl2(lead(cia.id) over (partition by cia.cip_id order by cia.valid_from),'modified','created')) AS opn_description
      ,opn.op_time
      ,usr.username
      ,cia.id
      ,cia.ci_id
      ,cipt.name AS cipt_name
      ,cia.data
      ,cia.status
      ,cia.valid_from
      ,cia.valid_until
      ,cia.comments
      -- a v?ltozott ?rt?kek
      ,lead(cia.data) over (partition by cia.cip_id order by cia.valid_from) AS next_data
      ,lead(cia.status) over (partition by cia.cip_id order by cia.valid_from) AS next_status
      ,lead(cia.valid_from) over (partition by cia.cip_id order by cia.valid_from) AS next_valid_from
      ,lead(cia.valid_until) over (partition by cia.cip_id order by cia.valid_from) AS next_valid_until
      --
FROM nit_operations opn
    ,nit_ci_attributes cia
    ,nit_ci_properties cip
    ,nit_ci_property_types cipt
    ,nit_users usr
WHERE opn.id = cia.opn_id
  AND cia.ci_id = nit_f_ci_p.get_ci_archive_ci_id
  AND cia.cip_id = cip.id
  AND cipt.name <> nit_ci_property_types_p.get_name_cipt_name
  AND cipt.name <> nit_ci_property_types_p.get_status_cipt_name
  AND cip.cipt_id = cipt.id
  AND opn.usr_id = usr.id
/

prompt
prompt Creating view NIT_F_CI_LIFE_CI_BROWSE_V
prompt =======================================
prompt
CREATE OR REPLACE VIEW NIT_F_CI_LIFE_CI_BROWSE_V AS
SELECT ci.id AS id
      ,ci.cit_id AS cit_id
      ,cit.name AS cit_name
      ,ci.name AS name
      ,ci.status AS status
      ,lcn.name AS location
      ,psn.status AS psn_status
      ,ci.valid_from AS valid_from
      ,ci.valid_until AS valid_until
FROM nit_config_items ci,
     nit_ci_types cit,
     nit_positions psn,
     nit_locations lcn
WHERE ci.cit_id = cit.id AND
      psn.ci_id = ci.id AND
      psn.obsolete = 'L' AND
      psn.lcn_id = lcn.id
/

prompt
prompt Creating view NIT_F_CI_LIFE_CIR_V
prompt =================================
prompt
CREATE OR REPLACE VIEW NIT_F_CI_LIFE_CIR_V AS
SELECT opn.id AS opn_id
      ,DECODE(cir.obsolete,'D','deleted',nvl2(lead(cir.id) over (partition by cir.ci_id_from, cir.ci_id_to order by cir.valid_from),'modified','created')) AS opn_description
      ,opn.op_time
      ,usr.username
      ,cir.id
      ,cir.ci_id_from
      ,cir.citr_id
      ,cir.ci_id_to
      ,cit1.name AS cit_name_from
      ,ci1.name AS ci_name_from
      ,citrt.name AS citrt_name
      ,cit2.name AS cit_name_to
      ,ci2.name AS ci_name_to
      ,cir.status
      ,cir.obsolete
      ,cir.valid_from
      ,cir.valid_until
      ,lead(cir.status) over (partition by cir.ci_id_from, cir.ci_id_to order by cir.valid_from) AS next_status
      ,lead(cir.valid_from) over (partition by cir.ci_id_from, cir.ci_id_to order by cir.valid_from) AS next_valid_from
      ,lead(cir.valid_until) over (partition by cir.ci_id_from, cir.ci_id_to order by cir.valid_from) AS next_valid_until
FROM nit_operations opn
    ,nit_ci_relations cir
    ,nit_ci_type_relations citr
    ,nit_cit_relation_types citrt
    ,nit_config_items ci1
    ,nit_config_items ci2
    ,nit_ci_types cit1
    ,nit_ci_types cit2
    ,nit_users usr
WHERE opn.id = cir.opn_id
  AND (cir.ci_id_from = nit_f_ci_p.get_ci_archive_ci_id OR cir.ci_id_to = nit_f_ci_p.get_ci_archive_ci_id)
  AND cir.ci_id_from = ci1.id
  AND ci1.cit_id = cit1.id
  AND cir.ci_id_to = ci2.id
  AND ci2.cit_id = cit2.id
  AND cir.citr_id = citr.id
  AND citr.citrt_id = citrt.id
  AND opn.usr_id = usr.id
/

prompt
prompt Creating type NIT_CI_LIFE_OPN_DESCRIPTION_OT
prompt ============================================
prompt
CREATE OR REPLACE TYPE "NIT_CI_LIFE_OPN_DESCRIPTION_OT"                                                                          AS OBJECT
(
   opn_id          NUMBER,
   opn_description VARCHAR2(10),
   ci_id           NUMBER,
   psn_id          NUMBER,
   cia_name_id     NUMBER,
   cia_status_id   NUMBER,
   valid_from      DATE,
   valid_until     DATE
)
/

prompt
prompt Creating package NIT_F_OPN_P
prompt ============================
prompt
CREATE OR REPLACE PACKAGE nit_f_opn_p AUTHID CURRENT_USER IS

   opn_description CONSTANT nit_string_ct := nit_string_ct('created'
                                                          ,'modified'
                                                          ,'deleted');

   created_idx  CONSTANT PLS_INTEGER := 1;
   modified_idx CONSTANT PLS_INTEGER := 2;
   deleted_idx  CONSTANT PLS_INTEGER := 3;

   --------------------------------------------------------------------------------------------------------------

   FUNCTION package_version RETURN VARCHAR2;

   FUNCTION get_opn_created_name RETURN VARCHAR2;

   FUNCTION get_opn_modified_name RETURN VARCHAR2;

   FUNCTION get_opn_deleted_name RETURN VARCHAR2;

   FUNCTION start_operation(p_type_name IN VARCHAR2 DEFAULT 'requested')
      RETURN nit_operations.id%TYPE;

   PROCEDURE stop_operation(p_id IN nit_operations.id%TYPE);

   PROCEDURE fail_operation(p_id IN nit_operations.id%TYPE);

   FUNCTION get_ci_life_opn_description(p_id   IN nit_config_items.id%TYPE
                                       ,p_type IN VARCHAR2)
      RETURN nit_ci_life_opn_description_ot;

   PROCEDURE init_ci_life_opn_descr(p_id IN nit_config_items.id%TYPE);

   FUNCTION get_ci_life_opn_descr_ci_id RETURN nit_num_ct;

END nit_f_opn_p;
/

prompt
prompt Creating view NIT_F_CI_LIFE_CI_V
prompt ================================
prompt
CREATE OR REPLACE VIEW NIT_F_CI_LIFE_CI_V AS
SELECT t1.opn_id
      ,t1.opn_description
      ,t1.op_time
      ,t1.username
      ,t1.ci_id
      ,t1.psn_id
      ,t1.cia_name_id
      ,t1.cia_status_id
      ,t1.cit_id
      ,t1.cit_name
      ,t1.name
      ,t1.status
      ,t1.location
      ,t1.psn_status
      ,t1.valid_from
      ,t1.valid_until
      ,t2.name AS next_name
      ,t2.status AS next_status
      ,t2.location AS next_location
      ,t2.psn_status AS next_psn_status
      ,t2.valid_from AS next_valid_from
      ,t2.valid_until AS next_valid_until
FROM
(
SELECT DISTINCT
       cilv.opn_desc_obj.opn_id AS opn_id,
       cilv.opn_desc_obj.opn_description AS opn_description,
       opn.op_time,
       usr.username,
       cilv.opn_desc_obj.ci_id AS ci_id,
       cilv.opn_desc_obj.psn_id AS psn_id,
       cilv.opn_desc_obj.cia_name_id AS cia_name_id,
       cilv.opn_desc_obj.cia_status_id AS cia_status_id,
       ci.cit_id,
       cit.name AS CIT_NAME,
       NVL2(cilv.opn_desc_obj.cia_name_id,cia1.data,ci.name) AS name,
       NVL2(cilv.opn_desc_obj.cia_status_id,cia2.data,ci.status) AS status,
       lcn.name AS LOCATION,
       psn.status AS PSN_STATUS,
       cilv.opn_desc_obj.valid_from AS valid_from,
       cilv.opn_desc_obj.valid_until AS valid_until
FROM (
      (SELECT nit_f_opn_p.get_ci_life_opn_description(ci.id,'CI') AS opn_desc_obj
      FROM   nit_config_items ci
      WHERE ci.id = nit_f_ci_p.get_ci_archive_ci_id)
      UNION ALL
      (SELECT nit_f_opn_p.get_ci_life_opn_description(cia.id,'CIA') AS opn_desc_obj
       FROM nit_ci_attributes cia,
            nit_ci_properties cip,
            nit_ci_property_types cipt
       WHERE cia.ci_id = nit_f_ci_p.get_ci_archive_ci_id AND
             cia.cip_id = cip.id AND
             cip.cipt_id = cipt.id AND
             (cipt.name = nit_ci_property_types_p.get_name_cipt_name
              OR cipt.name = nit_ci_property_types_p.get_status_cipt_name))
     UNION ALL
     (SELECT nit_f_opn_p.get_ci_life_opn_description(psn.id,'PSN') AS opn_desc_obj
      FROM nit_positions psn
      WHERE psn.ci_id = nit_f_ci_p.get_ci_archive_ci_id AND
            psn.obsolete = 'A'
     )
     ) cilv,
     nit_operations opn,
     nit_users usr,
     nit_config_items ci,
     nit_ci_types cit,
     nit_positions psn,
     nit_locations lcn,
     nit_ci_attributes cia1,
     nit_ci_attributes cia2
WHERE cilv.opn_desc_obj.opn_id = opn.id AND
      opn.usr_id = usr.id AND
      cilv.opn_desc_obj.ci_id = ci.id AND
      ci.cit_id = cit.id AND
      cilv.opn_desc_obj.psn_id = psn.id AND
      psn.lcn_id = lcn.id AND
      cilv.opn_desc_obj.cia_name_id = cia1.id(+) AND
      cilv.opn_desc_obj.cia_status_id = cia2.id(+)
) t1
,
(
SELECT DISTINCT
       cilv.opn_desc_obj.ci_id AS ci_id,
       NVL2(cilv.opn_desc_obj.cia_name_id,cia1.data,ci.name) AS name,
       NVL2(cilv.opn_desc_obj.cia_status_id,cia2.data,ci.status) AS status,
       lcn.name AS LOCATION,
       psn.status AS PSN_STATUS,
       cilv.opn_desc_obj.valid_from AS valid_from,
       cilv.opn_desc_obj.valid_until AS valid_until
FROM (
      (SELECT nit_f_opn_p.get_ci_life_opn_description(cia.id,'CIA') AS opn_desc_obj
       FROM nit_ci_attributes cia,
            nit_ci_properties cip,
            nit_ci_property_types cipt
       WHERE cia.ci_id = nit_f_ci_p.get_ci_archive_ci_id AND
             cia.cip_id = cip.id AND
             cip.cipt_id = cipt.id AND
             (cipt.name = nit_ci_property_types_p.get_name_cipt_name
              OR cipt.name = nit_ci_property_types_p.get_status_cipt_name))
     UNION ALL
     (SELECT nit_f_opn_p.get_ci_life_opn_description(psn.id,'PSN') AS opn_desc_obj
      FROM nit_positions psn
      WHERE psn.ci_id = nit_f_ci_p.get_ci_archive_ci_id)
     ) cilv,
     nit_config_items ci,
     nit_positions psn,
     nit_locations lcn,
     nit_ci_attributes cia1,
     nit_ci_attributes cia2
WHERE cilv.opn_desc_obj.ci_id = ci.id AND
      cilv.opn_desc_obj.psn_id = psn.id AND
      psn.lcn_id = lcn.id AND
      cilv.opn_desc_obj.cia_name_id = cia1.id(+) AND
      cilv.opn_desc_obj.cia_status_id = cia2.id(+)
) t2
WHERE t1.ci_id = t2.ci_id(+) AND
      nit_core_p.push(t1.valid_until) = t2.valid_from(+)
/

prompt
prompt Creating view NIT_F_CI_MAIN_V
prompt =============================
prompt
CREATE OR REPLACE VIEW NIT_F_CI_MAIN_V AS
SELECT ci.id
        ,ci.cit_id
        ,ci.opn_id
        ,ci.sms_id
        ,cit.name AS CIT_NAME
        ,ci.name
        ,ci.status
        ,ci.obsolete
        ,ci.valid_from
        ,ci.valid_until
        ,pos.id AS POS_ID
        ,pos.lcn_id
        ,pos.status AS POS_STATUS
        ,pos.obsolete AS POS_OBSOLETE
        ,pos.valid_from AS POS_VALID_FROM
        ,pos.valid_until AS POS_VALID_UNTIL
        ,lcn.name AS LOCATION
        ,ci.comments
  FROM nit_config_items ci
      ,nit_ci_types cit
      ,nit_positions pos
      ,nit_locations lcn
  WHERE ci.cit_id = cit.id
        AND pos.ci_id = ci.id
        AND pos.lcn_id = lcn.id
/

prompt
prompt Creating view NIT_F_CIP_AFF_V
prompt =============================
prompt
CREATE OR REPLACE VIEW NIT_F_CIP_AFF_V AS
SELECT cip.id AS id,
       cip.cip_id AS parent_id,
--       cip.cip_id_ancient,
       cit.id AS cit_id,
       CIPT.NAME,
       cit.NAME AS cit_name
FROM nit_ci_types cit, nit_ci_property_types cipt, nit_ci_properties cip
WHERE cip.cit_id = cit.id AND cip.cipt_id = cipt.id AND cip.is_inherited = 'Y'
/

prompt
prompt Creating view NIT_F_CIP_INSTALL_V
prompt =================================
prompt
CREATE OR REPLACE VIEW NIT_F_CIP_INSTALL_V AS
SELECT cip.id AS cip_id
      ,cip.cit_id
      ,cip.cipt_id
      ,cipt.name
      ,cipv.value
      ,cipv.description
      ,cipv.comments
      ,cip.order_in_list
FROM nit_ci_properties cip
    ,nit_ci_property_types cipt
    ,nit_ci_property_values cipv
WHERE cip.cipt_id = cipt.id
  AND cipv.cip_id = cip.id
/

prompt
prompt Creating view NIT_F_CIPT_MAIN_V
prompt ===============================
prompt
CREATE OR REPLACE VIEW NIT_F_CIPT_MAIN_V AS
SELECT
   cipt.id
  ,cipt.name
  ,cipt.type_name
  ,cipt.description
  ,cipt.comments
FROM nit_ci_property_types cipt
/

prompt
prompt Creating view NIT_F_CIPV_AFF_V
prompt ==============================
prompt
CREATE OR REPLACE VIEW NIT_F_CIPV_AFF_V AS
SELECT cipv.id AS cipv_id,
       cip.id AS id,
       cip.cip_id AS parent_id,
       cit.id AS cit_id,
       CIPT.NAME,
       cit.NAME AS cit_name,
       cipv.value
FROM nit_ci_types cit, nit_ci_property_types cipt, nit_ci_properties cip, nit_ci_property_values cipv
WHERE cip.cit_id = cit.id AND cip.cipt_id = cipt.id AND cip.is_inherited = 'Y' AND cip.set_like = 'Y' AND cipv.cip_id = cip.id
/

prompt
prompt Creating view NIT_F_CIR_MAIN_V
prompt ==============================
prompt
CREATE OR REPLACE VIEW NIT_F_CIR_MAIN_V AS
SELECT cir.id
      ,cit_from.id AS CIT_ID_FROM
      ,cir.ci_id_from
      ,cit_to.id AS CIT_ID_TO
      ,cir.ci_id_to
      ,cir.citr_id
      ,cir.opn_id
      ,ci_from.name AS CI_NAME_FROM
      ,cit_from.name AS CIT_NAME_FROM
      ,ci_to.name AS CI_NAME_TO
      ,cit_to.name AS CIT_NAME_TO
      ,citrt.name AS CITRT_NAME
      ,cir.status
      ,cir.obsolete
      ,cir.valid_from
      ,cir.valid_until
      ,cir.comments
      FROM nit_ci_relations cir
          ,nit_config_items ci_from
          ,nit_config_items ci_to
          ,nit_ci_types cit_from
          ,nit_ci_types cit_to
          ,nit_ci_type_relations citr
          ,nit_cit_relation_types citrt
      WHERE cir.ci_id_from = ci_from.id
         AND cir.ci_id_to = ci_to.id
         AND ci_from.cit_id = cit_from.id
         AND ci_to.cit_id = cit_to.id
         AND cir.citr_id = citr.id
         AND citr.citrt_id = citrt.id
/

prompt
prompt Creating view NIT_F_CIT_CIPT_MAIN_V
prompt ===================================
prompt
CREATE OR REPLACE VIEW NIT_F_CIT_CIPT_MAIN_V AS
SELECT
   cipt.id
  ,cipt.name
  ,cipt.type_name
  ,cipt.description
  ,cipt.comments
FROM nit_ci_property_types cipt
/

prompt
prompt Creating view NIT_F_CIT_CIP_V
prompt =============================
prompt
CREATE OR REPLACE VIEW NIT_F_CIT_CIP_V AS
SELECT
   CIP.ID AS ID
	,CIT.ID 		AS CIT_ID
	,CIPT.ID 	AS CIPT_ID
  ,CIP.CIP_ID AS CIP_ID
	,CIT.NAME 	AS CIT_NAME
	,CIPT.NAME 	AS CIPT_NAME
	,CIPT.TYPE_NAME
	,CIT.ORDER_IN_LIST AS CIT_ORDER
	,CIP.ORDER_IN_LIST AS CIP_ORDER
	,CIP.IS_INHERITED
  ,CIP.IS_IMPORTABLE
  ,CIP.IMP_AUTO_IMPORT
	,CIP.REQUIRED
	,CIP.SET_LIKE
	,CIP.DESCRIPTION
	,CIP.COMMENTS
FROM 	NIT_CI_TYPES CIT,
      NIT_CI_PROPERTIES CIP,
      NIT_CI_PROPERTY_TYPES CIPT
WHERE
	CIP.CIT_ID = CIT.ID AND
	CIP.CIPT_ID = CIPT.ID
/

prompt
prompt Creating view NIT_F_CIT_CIPV_V
prompt ==============================
prompt
CREATE OR REPLACE VIEW NIT_F_CIT_CIPV_V AS
SELECT
   cit.id AS cit_id
  ,cipt.id AS cipt_id
  ,cip.id AS cip_id
  ,cipv.id
  ,cit.name AS cit_name
  ,cipt.name AS cipt_name
  ,cipv.value
  ,cipv.is_default
  ,cipv.order_in_list as cipv_order
  ,cipv.description
  ,cipv.comments
FROM 	nit_ci_types cit,
	    nit_ci_properties cip,
      nit_ci_property_types cipt,
      nit_ci_property_values cipv
WHERE cip.cit_id = cit.id AND
	    cip.cipt_id = cipt.id AND
	    cipv.cip_id = cip.id and
      cip.set_like = 'Y'
/

prompt
prompt Creating view NIT_F_CIT_CITR_V
prompt ==============================
prompt
CREATE OR REPLACE VIEW NIT_F_CIT_CITR_V AS
SELECT
   citr.id
  ,citr.cit_id_from
  ,citr.cit_id_to
  ,citrt.id AS citrt_id
  ,cit_from.name AS cit_name_from
  ,citrt.name AS citrt_name
  ,cit_to.name AS cit_name_to
  ,citr.order_in_list AS citr_order
  ,cit_from.order_in_list AS cit_order_from
  ,cit_to.order_in_list AS cit_order_to
  ,citr.description
  ,citr.comments
FROM 	nit_ci_types cit_from
	   ,nit_ci_type_relations citr
     ,nit_ci_types cit_to
     ,nit_cit_relation_types citrt
WHERE
      citr.cit_id_from = cit_from.id AND
      citr.cit_id_to = cit_to.id AND
      citr.citrt_id = citrt.id
/

prompt
prompt Creating view NIT_F_CIT_MAIN_V
prompt ==============================
prompt
CREATE OR REPLACE VIEW NIT_F_CIT_MAIN_V AS
SELECT
	 cit.id
	,cit.cit_id
	,cit.name
	,cit2.name as parent_name
  ,cit.need_po AS need_po
  ,cit.could_in_stock AS could_in_stock
  ,cit.could_in_inventory AS could_in_inventory
  ,cit.order_in_list AS order_in_list
	,cit.abbreviation
	,cit.naming_pattern
	,cit.description
	,cit.comments
  ,cit.is_importable
  ,cit.imp_auto_import
FROM nit_ci_types cit, nit_ci_types cit2 where cit.cit_id = cit2.id (+)
/

prompt
prompt Creating view NIT_F_CITRT_AFF_V
prompt ===============================
prompt
CREATE OR REPLACE VIEW NIT_F_CITRT_AFF_V AS
SELECT
       CITRT.id,
       CITR.id AS citr_id,
       cit_id_from,
       cit_id_to,
       CITRT.NAME,
       cit_from.name AS cit_name_from,
       cit_to.name AS cit_name_to
FROM nit_cit_relation_types citrt, nit_ci_type_relations citr, nit_ci_types cit_from, nit_ci_types cit_to
WHERE citr.citrt_id = citrt.id AND
      citr.cit_id_from = cit_from.id AND
      citr.cit_id_to   = cit_to.id
/

prompt
prompt Creating view NIT_F_CITRT_MAIN_V
prompt ================================
prompt
CREATE OR REPLACE VIEW NIT_F_CITRT_MAIN_V AS
SELECT
   citrt.id
  ,citrt.name
  ,citrt.description
  ,citrt.comments
FROM nit_cit_relation_types citrt
/

prompt
prompt Creating view NIT_F_CIT_TREE_V
prompt ==============================
prompt
CREATE OR REPLACE VIEW NIT_F_CIT_TREE_V AS
SELECT (CASE WHEN LEVEL <= nit_core_p.getpi('tree depth') THEN 1 ELSE -1 END) AS NODE_STATE
      ,LEVEL AS "LEVEL"
      ,NAME AS LABEL
      ,'page_white_gear' AS ICON_NAME
      ,TO_CHAR(ID) AS VALUE
      ,TO_CHAR(ORDER_IN_LIST) AS "ORDER"
FROM NIT_CI_TYPES
CONNECT BY PRIOR ID = CIT_ID
START WITH CIT_ID IS NULL
ORDER SIBLINGS BY ORDER_IN_LIST
/

prompt
prompt Creating view NIT_F_LCN_MAIN_V
prompt ==============================
prompt
CREATE OR REPLACE VIEW NIT_F_LCN_MAIN_V AS
SELECT
	 lcn.id
	,lcn.lcn_id
	,lcn.name
	,lcn2.name as parent_name
	,lcn.abbreviation
	,lcn.naming_pattern
	,lcn.map
	,lcn.description
	,lcn.comments
FROM nit_locations lcn, nit_locations lcn2 where lcn.lcn_id = lcn2.id (+)
/

prompt
prompt Creating view NIT_F_LCN_TREE_V
prompt ==============================
prompt
CREATE OR REPLACE VIEW NIT_F_LCN_TREE_V AS
SELECT (CASE WHEN LEVEL <= nit_core_p.getpi('tree depth') THEN 1 ELSE -1 END) AS NODE_STATE
      ,LEVEL AS "LEVEL"
      ,NAME AS LABEL
      ,'page_white_world' AS ICON_NAME
      ,TO_CHAR(ID) AS VALUE
FROM NIT_LOCATIONS
CONNECT BY PRIOR ID = LCN_ID
START WITH LCN_ID IS NULL
ORDER SIBLINGS BY NAME
/

prompt
prompt Creating view NIT_F_MSG_MAIN_V
prompt ==============================
prompt
CREATE OR REPLACE VIEW NIT_F_MSG_MAIN_V AS
SELECT MSG.ID ID
      ,MSG.CODE CODE
      ,MSG.MESSAGE MESSAGE
      ,MSG.USED_IN USED_IN
      ,MSG.HINT HINT
      ,MSG.COMMENTS COMMENTS
FROM NIT_MESSAGES MSG
/

prompt
prompt Creating view NIT_F_PSN_MAIN_V
prompt ==============================
prompt
CREATE OR REPLACE VIEW NIT_F_PSN_MAIN_V AS
SELECT psn.id
      ,psn.ci_id
      ,psn.lcn_id
      ,psn.opn_id
      ,lcn.NAME AS lcn_name
      ,cit.NAME AS cit_name
      ,ci.NAME AS ci_name
      ,psn.status
      ,psn.obsolete
      ,psn.valid_from
      ,psn.valid_until
      ,psn.comments
FROM   nit_positions    psn
      ,nit_locations    lcn
      ,nit_config_items ci
      ,nit_ci_types     cit
WHERE  psn.lcn_id = lcn.id AND
       psn.ci_id = ci.id AND
       ci.cit_id = cit.id
/

prompt
prompt Creating view NIT_F_REP_NAMES_V
prompt ===============================
prompt
CREATE OR REPLACE VIEW NIT_F_REP_NAMES_V AS
SELECT ci.id AS report_id
      ,ci.name AS report_name
FROM nit_config_items ci
WHERE ci.obsolete = 'L'
  AND ci.cit_id IN (
                    SELECT cit.id
                    FROM nit_ci_types cit
                    CONNECT BY PRIOR cit.id = cit.cit_id
                    START WITH cit.name = nit_core_p.getp('report')
                   )
/

prompt
prompt Creating view NIT_F_REP_PARAMETERS_V
prompt ====================================
prompt
CREATE OR REPLACE VIEW NIT_F_REP_PARAMETERS_V AS
SELECT cia.ci_id AS report_id
      ,cip.id AS parameter_id
      ,cipt.name AS parameter_label
      ,CASE cipt.name
          WHEN 'report output type' THEN 'destype'
          WHEN 'report output format' THEN 'desformat'
          ELSE REPLACE(SUBSTR(cipt.name,8),' ','_')
       END AS parameter_name
      ,nvl(cia.data,cipv.value) AS default_value
      ,cipt.type_name AS parameter_type
      ,cip.required AS required
      ,cipt.comments AS hint
      ,cip.order_in_list AS parameter_order
      ,cipt.description AS lov_select
FROM nit_ci_attributes cia
    ,nit_ci_properties cip
    ,nit_ci_property_values cipv
    ,nit_ci_property_types cipt
WHERE cia.obsolete = 'L'
  AND cia.cip_id = cip.id
  AND cia.cipv_id = cipv.id (+)
  AND cipv.is_default (+) = 'Y'
  AND cip.cipt_id = cipt.id
/

prompt
prompt Creating view NIT_F_USR_MAIN_V
prompt ==============================
prompt
CREATE OR REPLACE VIEW NIT_F_USR_MAIN_V AS
SELECT
	 usr.id
	,usr.username
	,usr.realname
	,usr.language
	,usr.email
  ,usr.role
	,usr.comments
FROM nit_users usr
/

prompt
prompt Creating package CG$NIT_CI_ATTRIBUTES
prompt =====================================
prompt
CREATE OR REPLACE PACKAGE cg$nit_ci_attributes AUTHID CURRENT_USER IS

   called_from_package BOOLEAN := FALSE;

   --  Repository User-Defined Error Messages
   nit_cpk_cia      CONSTANT VARCHAR2(240) := '';
   nit_cfk_cia_cip  CONSTANT VARCHAR2(240) := '';
   nitil_cfk_cia_ci CONSTANT VARCHAR2(240) := '';
   nit_cfk_cia_civ  CONSTANT VARCHAR2(240) := '';
   nit_cfk_cia_opn  CONSTANT VARCHAR2(240) := '';

   --  Column default prompts. Format PSEQNO_COL
   p5id                  CONSTANT VARCHAR2(240) := 'Id';
   p10creation_date      CONSTANT VARCHAR2(240) := 'Creation Date';
   p15created_by         CONSTANT VARCHAR2(240) := 'Created By';
   p18last_update_date   CONSTANT VARCHAR2(240) := 'Last Update Date';
   p19last_updated_by    CONSTANT VARCHAR2(240) := 'Last Updated By';
   p25ci_id              CONSTANT VARCHAR2(240) := 'Ci Id';
   p35cip_id             CONSTANT VARCHAR2(240) := 'Cip Id';
   p55opn_id             CONSTANT VARCHAR2(240) := 'Op Id';
   p60cipv_id            CONSTANT VARCHAR2(240) := 'Civ Id';
   p62sms_id             CONSTANT VARCHAR2(240) := 'Sms Id';
   p65status             CONSTANT VARCHAR2(240) := 'Status';
   p105obsolete          CONSTANT VARCHAR2(240) := 'Obsolete';
   p115valid_from        CONSTANT VARCHAR2(240) := 'Valid From';
   p125valid_until       CONSTANT VARCHAR2(240) := 'Valid Until';
   p135data              CONSTANT VARCHAR2(240) := 'Data';
   p145comments          CONSTANT VARCHAR2(240) := 'Comment';
   p155last_refresh_date CONSTANT VARCHAR2(240) := 'Last Refresh Date';

   cg$row nit_ci_attributes%ROWTYPE;

   --  NIT_CI_ATTRIBUTES row type variable
   TYPE cg$row_type IS RECORD(
       id                cg$row.id%TYPE
      ,creation_date     cg$row.creation_date%TYPE
      ,created_by        cg$row.created_by%TYPE
      ,last_update_date  cg$row.last_update_date%TYPE
      ,last_updated_by   cg$row.last_updated_by%TYPE
      ,ci_id             cg$row.ci_id%TYPE
      ,cip_id            cg$row.cip_id%TYPE
      ,opn_id            cg$row.opn_id%TYPE
      ,cipv_id           cg$row.cipv_id%TYPE
      ,sms_id            cg$row.sms_id%TYPE
      ,status            cg$row.status%TYPE
      ,obsolete          cg$row.obsolete%TYPE
      ,valid_from        cg$row.valid_from%TYPE
      ,valid_until       cg$row.valid_until%TYPE
      ,data              cg$row.data%TYPE
      ,comments          cg$row.comments%TYPE
      ,last_refresh_date cg$row.last_refresh_date%TYPE
      ,the_rowid         ROWID);

   --  NIT_CI_ATTRIBUTES indicator type variable
   TYPE cg$ind_type IS RECORD(
       id                BOOLEAN := FALSE
      ,creation_date     BOOLEAN := FALSE
      ,created_by        BOOLEAN := FALSE
      ,last_update_date  BOOLEAN := FALSE
      ,last_updated_by   BOOLEAN := FALSE
      ,ci_id             BOOLEAN := FALSE
      ,cip_id            BOOLEAN := FALSE
      ,opn_id            BOOLEAN := FALSE
      ,cipv_id           BOOLEAN := FALSE
      ,sms_id            BOOLEAN := FALSE
      ,status            BOOLEAN := FALSE
      ,obsolete          BOOLEAN := FALSE
      ,valid_from        BOOLEAN := FALSE
      ,valid_until       BOOLEAN := FALSE
      ,data              BOOLEAN := FALSE
      ,comments          BOOLEAN := FALSE
      ,last_refresh_date BOOLEAN := FALSE);

   cg$ind_true cg$ind_type;

   --  NIT_CI_ATTRIBUTES primary key type variable
   TYPE cg$pk_type IS RECORD(
       id        cg$row.id%TYPE
      ,the_rowid ROWID);

   --  PL/SQL Table Type variable for triggers
   TYPE cg$table_type IS TABLE OF nit_ci_attributes%ROWTYPE INDEX BY BINARY_INTEGER;
   cg$table cg$table_type;

   TYPE cg$tableind_type IS TABLE OF cg$ind_type INDEX BY BINARY_INTEGER;
   cg$tableind cg$tableind_type;
   idx         BINARY_INTEGER := 1;

   PROCEDURE ins(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_ins IN BOOLEAN DEFAULT TRUE);
   PROCEDURE upd(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_upd IN BOOLEAN DEFAULT TRUE
                ,cg$pk  IN cg$row_type DEFAULT NULL);
   PROCEDURE del(cg$pk  IN cg$pk_type
                ,do_del IN BOOLEAN DEFAULT TRUE);
   PROCEDURE lck(cg$old_rec  IN cg$row_type
                ,cg$old_ind  IN cg$ind_type
                ,nowait_flag IN BOOLEAN DEFAULT TRUE);
   PROCEDURE slct(cg$sel_rec IN OUT cg$row_type);

   PROCEDURE validate_domain(cg$rec IN OUT cg$row_type
                            ,cg$ind IN cg$ind_type DEFAULT cg$ind_true);

END cg$nit_ci_attributes;
/

prompt
prompt Creating package CG$NIT_CI_PROPERTIES
prompt =====================================
prompt
CREATE OR REPLACE PACKAGE cg$nit_ci_properties AUTHID CURRENT_USER IS


   called_from_package BOOLEAN := FALSE;

   --  Repository User-Defined Error Messages
   nitil_cpk_cip           CONSTANT VARCHAR2(240) := '';
   nit_cuk_cip             CONSTANT VARCHAR2(240) := '';
   nit_cfk_cip_cipt        CONSTANT VARCHAR2(240) := '';
   nit_cfk_cip_cip         CONSTANT VARCHAR2(240) := '';
   nit_cfk_cip_cit         CONSTANT VARCHAR2(240) := '';
   nit_cfk_cip_cip_ancient CONSTANT VARCHAR2(240) := '';

   --  Column default prompts. Format PSEQNO_COL
   p10id                 CONSTANT VARCHAR2(240) := 'Id';
   p15creation_date      CONSTANT VARCHAR2(240) := 'Creation Date';
   p16created_by         CONSTANT VARCHAR2(240) := 'Created By';
   p19last_update_date   CONSTANT VARCHAR2(240) := 'Last Update Date';
   p20last_updated_by    CONSTANT VARCHAR2(240) := 'Last Updated By';
   p26cipt_id            CONSTANT VARCHAR2(240) := 'Cipt Id';
   p36cit_id             CONSTANT VARCHAR2(240) := 'Cit Id';
   p46cip_id_ancient     CONSTANT VARCHAR2(240) := 'Ancient Id';
   p56cip_id             CONSTANT VARCHAR2(240) := 'Cip Id';
   p76required           CONSTANT VARCHAR2(240) := 'Required';
   p86set_like           CONSTANT VARCHAR2(240) := 'Set Like';
   p91is_inherited       CONSTANT VARCHAR2(240) := 'Is Inherited';
   p96is_importable      CONSTANT VARCHAR2(240) := 'Is Importable';
   p106order_in_list     CONSTANT VARCHAR2(240) := 'Order In List';
   p116description       CONSTANT VARCHAR2(240) := 'Description';
   p130comments          CONSTANT VARCHAR2(240) := 'Comment';
   p140imp_source_module CONSTANT VARCHAR2(240) := 'Imp Source Module';
   p150imp_source_name   CONSTANT VARCHAR2(240) := 'Imp Source Name';
   p160imp_auto_cipv     CONSTANT VARCHAR2(240) := 'Imp Auto Cipv';
   p170imp_cascade_cip   CONSTANT VARCHAR2(240) := 'Imp Cascade';
   p180imp_cascade_cipv  CONSTANT VARCHAR2(240) := 'Imp Cascade Cipv';
   p190imp_auto_import   CONSTANT VARCHAR2(240) := 'Imp Auto Import';

   cg$row nit_ci_properties%ROWTYPE;

   --  NIT_CI_PROPERTIES row type variable
   TYPE cg$row_type IS RECORD(
       id                cg$row.id%TYPE
      ,creation_date     cg$row.creation_date%TYPE
      ,created_by        cg$row.created_by%TYPE
      ,last_update_date  cg$row.last_update_date%TYPE
      ,last_updated_by   cg$row.last_updated_by%TYPE
      ,cipt_id           cg$row.cipt_id%TYPE
      ,cit_id            cg$row.cit_id%TYPE
      ,cip_id_ancient    cg$row.cip_id_ancient%TYPE
      ,cip_id            cg$row.cip_id%TYPE
      ,required          cg$row.required%TYPE
      ,set_like          cg$row.set_like%TYPE
      ,is_inherited      cg$row.is_inherited%TYPE
      ,is_importable     cg$row.is_importable%TYPE
      ,order_in_list     cg$row.order_in_list%TYPE
      ,description       cg$row.description%TYPE
      ,comments          cg$row.comments%TYPE
      ,imp_source_module cg$row.imp_source_module%TYPE
      ,imp_source_name   cg$row.imp_source_name%TYPE
      ,imp_auto_cipv     cg$row.imp_auto_cipv%TYPE
      ,imp_cascade_cip   cg$row.imp_cascade_cip%TYPE
      ,imp_cascade_cipv  cg$row.imp_cascade_cipv%TYPE
      ,imp_auto_import   cg$row.imp_auto_import%TYPE
      ,the_rowid         ROWID);

   --  NIT_CI_PROPERTIES indicator type variable
   TYPE cg$ind_type IS RECORD(
       id                BOOLEAN DEFAULT FALSE
      ,creation_date     BOOLEAN DEFAULT FALSE
      ,created_by        BOOLEAN DEFAULT FALSE
      ,last_update_date  BOOLEAN DEFAULT FALSE
      ,last_updated_by   BOOLEAN DEFAULT FALSE
      ,cipt_id           BOOLEAN DEFAULT FALSE
      ,cit_id            BOOLEAN DEFAULT FALSE
      ,cip_id_ancient    BOOLEAN DEFAULT FALSE
      ,cip_id            BOOLEAN DEFAULT FALSE
      ,required          BOOLEAN DEFAULT FALSE
      ,set_like          BOOLEAN DEFAULT FALSE
      ,is_inherited      BOOLEAN DEFAULT FALSE
      ,is_importable     BOOLEAN DEFAULT FALSE
      ,order_in_list     BOOLEAN DEFAULT FALSE
      ,description       BOOLEAN DEFAULT FALSE
      ,comments          BOOLEAN DEFAULT FALSE
      ,imp_source_module BOOLEAN DEFAULT FALSE
      ,imp_source_name   BOOLEAN DEFAULT FALSE
      ,imp_auto_cipv     BOOLEAN DEFAULT FALSE
      ,imp_cascade_cip   BOOLEAN DEFAULT FALSE
      ,imp_cascade_cipv  BOOLEAN DEFAULT FALSE
      ,imp_auto_import   BOOLEAN DEFAULT FALSE);

   cg$ind_true cg$ind_type;

   --  NIT_CI_PROPERTIES primary key type variable
   TYPE cg$pk_type IS RECORD(
       id        cg$row.id%TYPE
      ,the_rowid ROWID);

   --  PL/SQL Table Type variable for triggers
   TYPE cg$table_type IS TABLE OF nit_ci_properties%ROWTYPE INDEX BY BINARY_INTEGER;
   cg$table cg$table_type;

   TYPE cg$tableind_type IS TABLE OF cg$ind_type INDEX BY BINARY_INTEGER;
   cg$tableind cg$tableind_type;
   idx         BINARY_INTEGER := 1;

   PROCEDURE ins(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_ins IN BOOLEAN DEFAULT TRUE);
   PROCEDURE upd(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_upd IN BOOLEAN DEFAULT TRUE
                ,cg$pk  IN cg$row_type DEFAULT NULL);
   PROCEDURE del(cg$pk  IN cg$pk_type
                ,do_del IN BOOLEAN DEFAULT TRUE);
   PROCEDURE lck(cg$old_rec  IN cg$row_type
                ,cg$old_ind  IN cg$ind_type
                ,nowait_flag IN BOOLEAN DEFAULT TRUE);
   PROCEDURE slct(cg$sel_rec IN OUT cg$row_type);

   PROCEDURE validate_domain(cg$rec IN OUT cg$row_type
                            ,cg$ind IN cg$ind_type DEFAULT cg$ind_true);

END cg$nit_ci_properties;
/

prompt
prompt Creating package CG$NIT_CI_PROPERTY_VALUES
prompt ==========================================
prompt
CREATE OR REPLACE PACKAGE cg$nit_ci_property_values AUTHID CURRENT_USER IS

   called_from_package BOOLEAN := FALSE;

   --  Repository User-Defined Error Messages
   nit_cpk_cipv      CONSTANT VARCHAR2(240) := '';
   nit_cuk_cipv      CONSTANT VARCHAR2(240) := '';
   nitil_cipv_cip_fk CONSTANT VARCHAR2(240) := '';

   --  Column default prompts. Format PSEQNO_COL
   p10id               CONSTANT VARCHAR2(240) := 'Id';
   p15creation_date    CONSTANT VARCHAR2(240) := 'Creation Date';
   p16created_by       CONSTANT VARCHAR2(240) := 'Created By';
   p19last_update_date CONSTANT VARCHAR2(240) := 'Last Update Date';
   p24last_updated_by  CONSTANT VARCHAR2(240) := 'Last Updated By';
   p30cip_id           CONSTANT VARCHAR2(240) := 'Cip Id';
   p50is_default       CONSTANT VARCHAR2(240) := 'Is Default';
   p60order_in_list    CONSTANT VARCHAR2(240) := 'Order In List';
   p65value            CONSTANT VARCHAR2(240) := 'Value';
   p70description      CONSTANT VARCHAR2(240) := 'Description';
   p80comments         CONSTANT VARCHAR2(240) := 'Comment';

   cg$row nit_ci_property_values%ROWTYPE;

   --  NIT_CI_PROPERTY_VALUES row type variable
   TYPE cg$row_type IS RECORD(
       id               cg$row.id%TYPE
      ,creation_date    cg$row.creation_date%TYPE
      ,created_by       cg$row.created_by%TYPE
      ,last_update_date cg$row.last_update_date%TYPE
      ,last_updated_by  cg$row.last_updated_by%TYPE
      ,cip_id           cg$row.cip_id%TYPE
      ,is_default       cg$row.is_default%TYPE
      ,order_in_list    cg$row.order_in_list%TYPE
      ,VALUE            cg$row.VALUE%TYPE
      ,description      cg$row.description%TYPE
      ,comments         cg$row.comments%TYPE
      ,the_rowid        ROWID);

   --  NIT_CI_PROPERTY_VALUES indicator type variable
   TYPE cg$ind_type IS RECORD(
       id               BOOLEAN DEFAULT FALSE
      ,creation_date    BOOLEAN DEFAULT FALSE
      ,created_by       BOOLEAN DEFAULT FALSE
      ,last_update_date BOOLEAN DEFAULT FALSE
      ,last_updated_by  BOOLEAN DEFAULT FALSE
      ,cip_id           BOOLEAN DEFAULT FALSE
      ,is_default       BOOLEAN DEFAULT FALSE
      ,order_in_list    BOOLEAN DEFAULT FALSE
      ,VALUE            BOOLEAN DEFAULT FALSE
      ,description      BOOLEAN DEFAULT FALSE
      ,comments         BOOLEAN DEFAULT FALSE);

   cg$ind_true cg$ind_type;

   --  NIT_CI_PROPERTY_VALUES primary key type variable
   TYPE cg$pk_type IS RECORD(
       id        cg$row.id%TYPE
      ,the_rowid ROWID);

   --  PL/SQL Table Type variable for triggers
   TYPE cg$table_type IS TABLE OF nit_ci_property_values%ROWTYPE INDEX BY BINARY_INTEGER;
   cg$table cg$table_type;

   TYPE cg$tableind_type IS TABLE OF cg$ind_type INDEX BY BINARY_INTEGER;
   cg$tableind cg$tableind_type;
   idx         BINARY_INTEGER := 1;

   PROCEDURE ins(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_ins IN BOOLEAN DEFAULT TRUE);
   PROCEDURE upd(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_upd IN BOOLEAN DEFAULT TRUE
                ,cg$pk  IN cg$row_type DEFAULT NULL);
   PROCEDURE del(cg$pk  IN cg$pk_type
                ,do_del IN BOOLEAN DEFAULT TRUE);
   PROCEDURE lck(cg$old_rec  IN cg$row_type
                ,cg$old_ind  IN cg$ind_type
                ,nowait_flag IN BOOLEAN DEFAULT TRUE);
   PROCEDURE slct(cg$sel_rec IN OUT cg$row_type);

END cg$nit_ci_property_values;
/

prompt
prompt Creating package CG$NIT_CI_RELATIONS
prompt ====================================
prompt
CREATE OR REPLACE PACKAGE cg$nit_ci_relations AUTHID CURRENT_USER IS


   called_from_package BOOLEAN := FALSE;

   --  Repository User-Defined Error Messages
   nit_cpk_cir               CONSTANT VARCHAR2(240) := '';
   nit_ctc_cir_self_ref_deny CONSTANT VARCHAR(240) := '';
   nit_cfk_cir_ci_to         CONSTANT VARCHAR2(240) := '';
   nit_cfk_cir_ci_from       CONSTANT VARCHAR2(240) := '';
   nit_cfk_cir_citr          CONSTANT VARCHAR2(240) := '';
   nit_cfk_cir_opn           CONSTANT VARCHAR2(240) := '';

   --  Column default prompts. Format PSEQNO_COL
   p10id               CONSTANT VARCHAR2(240) := 'Id';
   p15creation_date    CONSTANT VARCHAR2(240) := 'Creation Date';
   p16created_by       CONSTANT VARCHAR2(240) := 'Created By';
   p19last_update_date CONSTANT VARCHAR2(240) := 'Last Update Date';
   p24last_updated_by  CONSTANT VARCHAR2(240) := 'Last Updated By';
   p27ci_id_from       CONSTANT VARCHAR2(240) := 'Ci Id1';
   p28ci_id_to         CONSTANT VARCHAR2(240) := 'Ci Id2';
   p30citr_id          CONSTANT VARCHAR2(240) := 'Citr Id';
   p40opn_id           CONSTANT VARCHAR2(240) := 'Op Id';
   p70status           CONSTANT VARCHAR2(240) := 'Status';
   p110obsolete        CONSTANT VARCHAR2(240) := 'Obsolete';
   p120valid_from      CONSTANT VARCHAR2(240) := 'Valid From';
   p130valid_until     CONSTANT VARCHAR2(240) := 'Valid Until';
   p140comments        CONSTANT VARCHAR2(240) := 'Comment';

   cg$row nit_ci_relations%ROWTYPE;

   --  NIT_CI_RELATIONS row type variable
   TYPE cg$row_type IS RECORD(
       id               cg$row.id%TYPE
      ,creation_date    cg$row.creation_date%TYPE
      ,created_by       cg$row.created_by%TYPE
      ,last_update_date cg$row.last_update_date%TYPE
      ,last_updated_by  cg$row.last_updated_by%TYPE
      ,ci_id_from       cg$row.ci_id_from%TYPE
      ,ci_id_to         cg$row.ci_id_to%TYPE
      ,citr_id          cg$row.citr_id%TYPE
      ,opn_id           cg$row.opn_id%TYPE
      ,status           cg$row.status%TYPE
      ,obsolete         cg$row.obsolete%TYPE
      ,valid_from       cg$row.valid_from%TYPE
      ,valid_until      cg$row.valid_until%TYPE
      ,comments         cg$row.comments%TYPE
      ,the_rowid        ROWID);

   --  NIT_CI_RELATIONS indicator type variable
   TYPE cg$ind_type IS RECORD(
       id               BOOLEAN DEFAULT FALSE
      ,creation_date    BOOLEAN DEFAULT FALSE
      ,created_by       BOOLEAN DEFAULT FALSE
      ,last_update_date BOOLEAN DEFAULT FALSE
      ,last_updated_by  BOOLEAN DEFAULT FALSE
      ,ci_id_from       BOOLEAN DEFAULT FALSE
      ,ci_id_to         BOOLEAN DEFAULT FALSE
      ,citr_id          BOOLEAN DEFAULT FALSE
      ,opn_id           BOOLEAN DEFAULT FALSE
      ,status           BOOLEAN DEFAULT FALSE
      ,obsolete         BOOLEAN DEFAULT FALSE
      ,valid_from       BOOLEAN DEFAULT FALSE
      ,valid_until      BOOLEAN DEFAULT FALSE
      ,comments         BOOLEAN DEFAULT FALSE);

   cg$ind_true cg$ind_type;

   --  NIT_CI_RELATIONS primary key type variable
   TYPE cg$pk_type IS RECORD(
       id        cg$row.id%TYPE
      ,the_rowid ROWID);

   --  PL/SQL Table Type variable for triggers
   TYPE cg$table_type IS TABLE OF nit_ci_relations%ROWTYPE INDEX BY BINARY_INTEGER;
   cg$table cg$table_type;

   TYPE cg$tableind_type IS TABLE OF cg$ind_type INDEX BY BINARY_INTEGER;
   cg$tableind cg$tableind_type;
   idx         BINARY_INTEGER := 1;

   PROCEDURE ins(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_ins IN BOOLEAN DEFAULT TRUE);
   PROCEDURE upd(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_upd IN BOOLEAN DEFAULT TRUE
                ,cg$pk  IN cg$row_type DEFAULT NULL);
   PROCEDURE del(cg$pk  IN cg$pk_type
                ,do_del IN BOOLEAN DEFAULT TRUE);
   PROCEDURE lck(cg$old_rec  IN cg$row_type
                ,cg$old_ind  IN cg$ind_type
                ,nowait_flag IN BOOLEAN DEFAULT TRUE);
   PROCEDURE slct(cg$sel_rec IN OUT cg$row_type);

   PROCEDURE validate_domain(cg$rec IN OUT cg$row_type
                            ,cg$ind IN cg$ind_type DEFAULT cg$ind_true);

END cg$nit_ci_relations;
/

prompt
prompt Creating package CG$NIT_CIT_RELATION_TYPES
prompt ==========================================
prompt
CREATE OR REPLACE PACKAGE cg$nit_cit_relation_types AUTHID CURRENT_USER IS


   called_from_package BOOLEAN := FALSE;

   --  Repository User-Defined Error Messages
   nit_cpk_citrt CONSTANT VARCHAR2(240) := '';
   nit_cuk_citrt CONSTANT VARCHAR2(240) := 'NIT-00063';

   --  Column default prompts. Format PSEQNO_COL
   p5id                CONSTANT VARCHAR2(240) := 'Id';
   p10creation_date    CONSTANT VARCHAR2(240) := 'Creation Date';
   p15created_by       CONSTANT VARCHAR2(240) := 'Created By';
   p18last_update_date CONSTANT VARCHAR2(240) := 'Last Update Date';
   p19last_updated_by  CONSTANT VARCHAR2(240) := 'Last Updated User';
   p36name             CONSTANT VARCHAR2(240) := 'Name';
   p66description      CONSTANT VARCHAR2(240) := 'Description';
   p76comments         CONSTANT VARCHAR2(240) := 'Comment';

   cg$row nit_cit_relation_types%ROWTYPE;

   --  NIT_CIT_RELATION_TYPES row type variable
   TYPE cg$row_type IS RECORD(
       id               cg$row.id%TYPE
      ,creation_date    cg$row.creation_date%TYPE
      ,created_by       cg$row.created_by%TYPE
      ,last_update_date cg$row.last_update_date%TYPE
      ,last_updated_by  cg$row.last_updated_by%TYPE
      ,NAME             cg$row.NAME%TYPE
      ,description      cg$row.description%TYPE
      ,comments         cg$row.comments%TYPE
      ,the_rowid        ROWID);

   --  NIT_CIT_RELATION_TYPES indicator type variable
   TYPE cg$ind_type IS RECORD(
       id               BOOLEAN DEFAULT FALSE
      ,creation_date    BOOLEAN DEFAULT FALSE
      ,created_by       BOOLEAN DEFAULT FALSE
      ,last_update_date BOOLEAN DEFAULT FALSE
      ,last_updated_by  BOOLEAN DEFAULT FALSE
      ,NAME             BOOLEAN DEFAULT FALSE
      ,description      BOOLEAN DEFAULT FALSE
      ,comments         BOOLEAN DEFAULT FALSE);

   cg$ind_true cg$ind_type;

   --  NIT_CIT_RELATION_TYPES primary key type variable
   TYPE cg$pk_type IS RECORD(
       id        cg$row.id%TYPE
      ,the_rowid ROWID);

   --  PL/SQL Table Type variable for triggers
   TYPE cg$table_type IS TABLE OF nit_cit_relation_types%ROWTYPE INDEX BY BINARY_INTEGER;
   cg$table cg$table_type;

   TYPE cg$tableind_type IS TABLE OF cg$ind_type INDEX BY BINARY_INTEGER;
   cg$tableind cg$tableind_type;
   idx         BINARY_INTEGER := 1;

   PROCEDURE ins(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_ins IN BOOLEAN DEFAULT TRUE);
   PROCEDURE upd(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_upd IN BOOLEAN DEFAULT TRUE
                ,cg$pk  IN cg$row_type DEFAULT NULL);
   PROCEDURE del(cg$pk  IN cg$pk_type
                ,do_del IN BOOLEAN DEFAULT TRUE);
   PROCEDURE lck(cg$old_rec  IN cg$row_type
                ,cg$old_ind  IN cg$ind_type
                ,nowait_flag IN BOOLEAN DEFAULT TRUE);
   PROCEDURE slct(cg$sel_rec IN OUT cg$row_type);

END cg$nit_cit_relation_types;
/

prompt
prompt Creating package CG$NIT_CI_TYPE_RELATIONS
prompt =========================================
prompt
CREATE OR REPLACE PACKAGE cg$nit_ci_type_relations AUTHID CURRENT_USER IS


   called_from_package BOOLEAN := FALSE;

   --  Repository User-Defined Error Messages
   nit_cpk_citr          CONSTANT VARCHAR2(240) := '';
   nit_cuk_citr          CONSTANT VARCHAR2(240) := '';
   nit_cfk_citr_citrt    CONSTANT VARCHAR2(240) := '';
   nit_cfk_citr_cit_from CONSTANT VARCHAR2(240) := '';
   nit_cfk_citr_cit_to   CONSTANT VARCHAR2(240) := '';

   --  Column default prompts. Format PSEQNO_COL
   p10id               CONSTANT VARCHAR2(240) := 'Id';
   p15creation_date    CONSTANT VARCHAR2(240) := 'Creation Date';
   p16created_by       CONSTANT VARCHAR2(240) := 'Created By';
   p19last_update_date CONSTANT VARCHAR2(240) := 'Last Update Date';
   p24last_updated_by  CONSTANT VARCHAR2(240) := 'Last Updated By';
   p27cit_id_from      CONSTANT VARCHAR2(240) := 'Cit Id1';
   p28cit_id_to        CONSTANT VARCHAR2(240) := 'Cit Id2';
   p30citrt_id         CONSTANT VARCHAR2(240) := 'Citrt Id';
   p60order_in_list    CONSTANT VARCHAR2(240) := 'Order In List';
   p100description     CONSTANT VARCHAR2(240) := 'Description';
   p110comments        CONSTANT VARCHAR2(240) := 'Comment';

   cg$row nit_ci_type_relations%ROWTYPE;

   --  NIT_CI_TYPE_RELATIONS row type variable
   TYPE cg$row_type IS RECORD(
       id               cg$row.id%TYPE
      ,creation_date    cg$row.creation_date%TYPE
      ,created_by       cg$row.created_by%TYPE
      ,last_update_date cg$row.last_update_date%TYPE
      ,last_updated_by  cg$row.last_updated_by%TYPE
      ,cit_id_from      cg$row.cit_id_from%TYPE
      ,cit_id_to        cg$row.cit_id_to%TYPE
      ,citrt_id         cg$row.citrt_id%TYPE
      ,order_in_list    cg$row.order_in_list%TYPE
      ,description      cg$row.description%TYPE
      ,comments         cg$row.comments%TYPE
      ,the_rowid        ROWID);

   --  NIT_CI_TYPE_RELATIONS indicator type variable
   TYPE cg$ind_type IS RECORD(
       id               BOOLEAN DEFAULT FALSE
      ,creation_date    BOOLEAN DEFAULT FALSE
      ,created_by       BOOLEAN DEFAULT FALSE
      ,last_update_date BOOLEAN DEFAULT FALSE
      ,last_updated_by  BOOLEAN DEFAULT FALSE
      ,cit_id_from      BOOLEAN DEFAULT FALSE
      ,cit_id_to        BOOLEAN DEFAULT FALSE
      ,citrt_id         BOOLEAN DEFAULT FALSE
      ,order_in_list    BOOLEAN DEFAULT FALSE
      ,description      BOOLEAN DEFAULT FALSE
      ,comments         BOOLEAN DEFAULT FALSE);

   cg$ind_true cg$ind_type;

   --  NIT_CI_TYPE_RELATIONS primary key type variable
   TYPE cg$pk_type IS RECORD(
       id        cg$row.id%TYPE
      ,the_rowid ROWID);

   --  PL/SQL Table Type variable for triggers
   TYPE cg$table_type IS TABLE OF nit_ci_type_relations%ROWTYPE INDEX BY BINARY_INTEGER;
   cg$table cg$table_type;

   TYPE cg$tableind_type IS TABLE OF cg$ind_type INDEX BY BINARY_INTEGER;
   cg$tableind cg$tableind_type;
   idx         BINARY_INTEGER := 1;

   PROCEDURE ins(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_ins IN BOOLEAN DEFAULT TRUE);
   PROCEDURE upd(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_upd IN BOOLEAN DEFAULT TRUE
                ,cg$pk  IN cg$row_type DEFAULT NULL);
   PROCEDURE del(cg$pk  IN cg$pk_type
                ,do_del IN BOOLEAN DEFAULT TRUE);
   PROCEDURE lck(cg$old_rec  IN cg$row_type
                ,cg$old_ind  IN cg$ind_type
                ,nowait_flag IN BOOLEAN DEFAULT TRUE);
   PROCEDURE slct(cg$sel_rec IN OUT cg$row_type);
END cg$nit_ci_type_relations;
/

prompt
prompt Creating package CG$NIT_CI_TYPES
prompt ================================
prompt
CREATE OR REPLACE PACKAGE cg$nit_ci_types AUTHID CURRENT_USER IS


   called_from_package BOOLEAN := FALSE;

   --  Repository User-Defined Error Messages
   nit_cpk_cit     CONSTANT VARCHAR2(240) := '';
   nit_cuk_cit     CONSTANT VARCHAR2(240) := 'NIT-00067';
   nit_cfk_cit_cit CONSTANT VARCHAR2(240) := '';

   --  Column default prompts. Format PSEQNO_COL
   p10id                 CONSTANT VARCHAR2(240) := 'Id';
   p15creation_date      CONSTANT VARCHAR2(240) := 'Creation Date';
   p16created_by         CONSTANT VARCHAR2(240) := 'Created By';
   p19last_update_date   CONSTANT VARCHAR2(240) := 'Last Update Date';
   p24last_updated_by    CONSTANT VARCHAR2(240) := 'Last Updated By';
   p30cit_id             CONSTANT VARCHAR2(240) := 'Parent Id';
   p40name               CONSTANT VARCHAR2(240) := 'Name';
   p50need_po            CONSTANT VARCHAR2(240) := 'Need Po';
   p60could_in_stock     CONSTANT VARCHAR2(240) := 'Could In Stock';
   p70could_in_inventory CONSTANT VARCHAR2(240) := 'Could In Inventory';
   p80order_in_list      CONSTANT VARCHAR2(240) := 'Order In List';
   p90abbreviation       CONSTANT VARCHAR2(240) := 'Abbreviation';
   p100naming_pattern    CONSTANT VARCHAR2(240) := 'Naming Pattern';
   p110description       CONSTANT VARCHAR2(240) := 'Description';
   p120comments          CONSTANT VARCHAR2(240) := 'Comment';
   p130icon_name         CONSTANT VARCHAR2(240) := 'Icon Name';
   p140is_importable     CONSTANT VARCHAR2(240) := 'Is Importable';
   p150imp_source_module CONSTANT VARCHAR2(240) := 'Imp Type';
   p150imp_source_name   CONSTANT VARCHAR2(240) := 'Imp Source Name';
   p170imp_where_clause  CONSTANT VARCHAR2(240) := 'Imp Where Clause';
   p190imp_name_attrib   CONSTANT VARCHAR2(240) := 'Imp Name Attrib';
   p200imp_auto_import   CONSTANT VARCHAR2(240) := 'Imp Auto Import';

   cg$row nit_ci_types%ROWTYPE;

   --  NIT_CI_TYPES row type variable
   TYPE cg$row_type IS RECORD(
       id                 cg$row.id%TYPE
      ,creation_date      cg$row.creation_date%TYPE
      ,created_by         cg$row.created_by%TYPE
      ,last_update_date   cg$row.last_update_date%TYPE
      ,last_updated_by    cg$row.last_updated_by%TYPE
      ,cit_id             cg$row.cit_id%TYPE
      ,NAME               cg$row.NAME%TYPE
      ,need_po            cg$row.need_po%TYPE
      ,could_in_stock     cg$row.could_in_stock%TYPE
      ,could_in_inventory cg$row.could_in_inventory%TYPE
      ,order_in_list      cg$row.order_in_list%TYPE
      ,abbreviation       cg$row.abbreviation%TYPE
      ,naming_pattern     cg$row.naming_pattern%TYPE
      ,description        cg$row.description%TYPE
      ,comments           cg$row.comments%TYPE
      ,icon_name          cg$row.icon_name%TYPE
      ,is_importable      cg$row.is_importable%TYPE
      ,imp_source_module  cg$row.imp_source_module%TYPE
      ,imp_source_name    cg$row.imp_source_name%TYPE
      ,imp_where_clause   cg$row.imp_where_clause%TYPE
      ,imp_name_attrib    cg$row.imp_name_attrib%TYPE
      ,imp_auto_import    cg$row.imp_auto_import%TYPE
      ,the_rowid          ROWID);

   --  NIT_CI_TYPES indicator type variable
   TYPE cg$ind_type IS RECORD(
       id                 BOOLEAN DEFAULT FALSE
      ,creation_date      BOOLEAN DEFAULT FALSE
      ,created_by         BOOLEAN DEFAULT FALSE
      ,last_update_date   BOOLEAN DEFAULT FALSE
      ,last_updated_by    BOOLEAN DEFAULT FALSE
      ,cit_id             BOOLEAN DEFAULT FALSE
      ,NAME               BOOLEAN DEFAULT FALSE
      ,need_po            BOOLEAN DEFAULT FALSE
      ,could_in_stock     BOOLEAN DEFAULT FALSE
      ,could_in_inventory BOOLEAN DEFAULT FALSE
      ,order_in_list      BOOLEAN DEFAULT FALSE
      ,abbreviation       BOOLEAN DEFAULT FALSE
      ,naming_pattern     BOOLEAN DEFAULT FALSE
      ,description        BOOLEAN DEFAULT FALSE
      ,comments           BOOLEAN DEFAULT FALSE
      ,icon_name          BOOLEAN DEFAULT FALSE
      ,is_importable      BOOLEAN DEFAULT FALSE
      ,imp_source_module  BOOLEAN DEFAULT FALSE
      ,imp_source_name    BOOLEAN DEFAULT FALSE
      ,imp_where_clause   BOOLEAN DEFAULT FALSE
      ,imp_name_attrib    BOOLEAN DEFAULT FALSE
      ,imp_auto_import    BOOLEAN DEFAULT FALSE);

   cg$ind_true cg$ind_type;

   --  NIT_CI_TYPES primary key type variable
   TYPE cg$pk_type IS RECORD(
       id        cg$row.id%TYPE
      ,the_rowid ROWID);

   --  PL/SQL Table Type variable for triggers
   TYPE cg$table_type IS TABLE OF nit_ci_types%ROWTYPE INDEX BY BINARY_INTEGER;
   cg$table cg$table_type;

   TYPE cg$tableind_type IS TABLE OF cg$ind_type INDEX BY BINARY_INTEGER;
   cg$tableind cg$tableind_type;
   idx         BINARY_INTEGER := 1;

   PROCEDURE ins(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_ins IN BOOLEAN DEFAULT TRUE);
   PROCEDURE upd(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_upd IN BOOLEAN DEFAULT TRUE
                ,cg$pk  IN cg$row_type DEFAULT NULL);
   PROCEDURE del(cg$pk  IN cg$pk_type
                ,do_del IN BOOLEAN DEFAULT TRUE);
   PROCEDURE lck(cg$old_rec  IN cg$row_type
                ,cg$old_ind  IN cg$ind_type
                ,nowait_flag IN BOOLEAN DEFAULT TRUE);
   PROCEDURE slct(cg$sel_rec IN OUT cg$row_type);

   PROCEDURE validate_domain(cg$rec IN OUT cg$row_type
                            ,cg$ind IN cg$ind_type DEFAULT cg$ind_true);

END cg$nit_ci_types;
/

prompt
prompt Creating package CG$NIT_CONFIG_ITEMS
prompt ====================================
prompt
CREATE OR REPLACE PACKAGE cg$nit_config_items AUTHID CURRENT_USER IS


   called_from_package BOOLEAN := FALSE;

   --  Repository User-Defined Error Messages
   nit_cpk_ci     CONSTANT VARCHAR2(240) := '';
   nit_cfk_ci_cit CONSTANT VARCHAR2(240) := '';
   nit_cfk_ci_opn CONSTANT VARCHAR2(240) := '';

   --  Column default prompts. Format PSEQNO_COL
   p10id                 CONSTANT VARCHAR2(240) := 'Id';
   p15creation_date      CONSTANT VARCHAR2(240) := 'Creation Date';
   p16created_by         CONSTANT VARCHAR2(240) := 'Created By';
   p19last_update_date   CONSTANT VARCHAR2(240) := 'Last Update Date';
   p24last_updated_by    CONSTANT VARCHAR2(240) := 'Last Updated By';
   p30cit_id             CONSTANT VARCHAR2(240) := 'Cit Id';
   p40opn_id             CONSTANT VARCHAR2(240) := 'Op Id';
   p42sms_id             CONSTANT VARCHAR2(240) := 'Sms Ids';
   p45name               CONSTANT VARCHAR2(240) := 'Name';
   p50status             CONSTANT VARCHAR2(240) := 'Status';
   p80obsolete           CONSTANT VARCHAR2(240) := 'Obsolete';
   p90valid_from         CONSTANT VARCHAR2(240) := 'Valid From';
   p100valid_until       CONSTANT VARCHAR2(240) := 'Valid Until';
   p110comments          CONSTANT VARCHAR2(240) := 'Comment';
   p155last_refresh_date CONSTANT VARCHAR2(240) := 'Last Refresh Date';

   cg$row nit_config_items%ROWTYPE;

   --  NIT_CONFIG_ITEMS row type variable
   TYPE cg$row_type IS RECORD(
       id                cg$row.id%TYPE
      ,creation_date     cg$row.creation_date%TYPE
      ,created_by        cg$row.created_by%TYPE
      ,last_update_date  cg$row.last_update_date%TYPE
      ,last_updated_by   cg$row.last_updated_by%TYPE
      ,cit_id            cg$row.cit_id%TYPE
      ,opn_id            cg$row.opn_id%TYPE
      ,sms_id            cg$row.sms_id%TYPE
      ,NAME              cg$row.NAME%TYPE
      ,status            cg$row.status%TYPE
      ,obsolete          cg$row.obsolete%TYPE
      ,valid_from        cg$row.valid_from%TYPE
      ,valid_until       cg$row.valid_until%TYPE
      ,comments          cg$row.comments%TYPE
      ,last_refresh_date cg$row.last_refresh_date%TYPE
      ,the_rowid         ROWID);

   --  NIT_CONFIG_ITEMS indicator type variable
   TYPE cg$ind_type IS RECORD(
       id                BOOLEAN DEFAULT FALSE
      ,creation_date     BOOLEAN DEFAULT FALSE
      ,created_by        BOOLEAN DEFAULT FALSE
      ,last_update_date  BOOLEAN DEFAULT FALSE
      ,last_updated_by   BOOLEAN DEFAULT FALSE
      ,cit_id            BOOLEAN DEFAULT FALSE
      ,opn_id            BOOLEAN DEFAULT FALSE
      ,sms_id            BOOLEAN DEFAULT FALSE
      ,NAME              BOOLEAN DEFAULT FALSE
      ,status            BOOLEAN DEFAULT FALSE
      ,obsolete          BOOLEAN DEFAULT FALSE
      ,valid_from        BOOLEAN DEFAULT FALSE
      ,valid_until       BOOLEAN DEFAULT FALSE
      ,comments          BOOLEAN DEFAULT FALSE
      ,last_refresh_date BOOLEAN DEFAULT FALSE);

   cg$ind_true cg$ind_type;

   --  NIT_CONFIG_ITEMS primary key type variable
   TYPE cg$pk_type IS RECORD(
       id        cg$row.id%TYPE
      ,the_rowid ROWID);

   --  PL/SQL Table Type variable for triggers
   TYPE cg$table_type IS TABLE OF nit_config_items%ROWTYPE INDEX BY BINARY_INTEGER;
   cg$table cg$table_type;

   TYPE cg$tableind_type IS TABLE OF cg$ind_type INDEX BY BINARY_INTEGER;
   cg$tableind cg$tableind_type;
   idx         BINARY_INTEGER := 1;

   PROCEDURE ins(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_ins IN BOOLEAN DEFAULT TRUE);
   PROCEDURE upd(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_upd IN BOOLEAN DEFAULT TRUE
                ,cg$pk  IN cg$row_type DEFAULT NULL);
   PROCEDURE del(cg$pk  IN cg$pk_type
                ,do_del IN BOOLEAN DEFAULT TRUE);
   PROCEDURE lck(cg$old_rec  IN cg$row_type
                ,cg$old_ind  IN cg$ind_type
                ,nowait_flag IN BOOLEAN DEFAULT TRUE);
   PROCEDURE slct(cg$sel_rec IN OUT cg$row_type);

   PROCEDURE validate_domain(cg$rec IN OUT cg$row_type
                            ,cg$ind IN cg$ind_type DEFAULT cg$ind_true);
END cg$nit_config_items;
/

prompt
prompt Creating package CG$NIT_LOCATIONS
prompt =================================
prompt
CREATE OR REPLACE PACKAGE cg$nit_locations AUTHID CURRENT_USER IS


   called_from_package BOOLEAN := FALSE;

   --  Repository User-Defined Error Messages
   nit_cpk_lcn     CONSTANT VARCHAR2(240) := '';
   nit_cuk_lcn     CONSTANT VARCHAR2(240) := 'NIT-00066';
   nit_cfk_lcn_lcn CONSTANT VARCHAR2(240) := '';

   --  Column default prompts. Format PSEQNO_COL
   p10id               CONSTANT VARCHAR2(240) := 'Id';
   p15creation_date    CONSTANT VARCHAR2(240) := 'Creation Date';
   p16created_by       CONSTANT VARCHAR2(240) := 'Created By';
   p19last_update_date CONSTANT VARCHAR2(240) := 'Last Update Date';
   p24last_updated_by  CONSTANT VARCHAR2(240) := 'Last Updated By';
   p30lcn_id           CONSTANT VARCHAR2(240) := 'Parent Id';
   p40name             CONSTANT VARCHAR2(240) := 'Name';
   p60abbreviation     CONSTANT VARCHAR2(240) := 'Abbreviation';
   p70naming_pattern   CONSTANT VARCHAR2(240) := 'Naming Pattern';
   p80description      CONSTANT VARCHAR2(240) := 'Description';
   p90comments         CONSTANT VARCHAR2(240) := 'Comment';
   p100icon_name       CONSTANT VARCHAR2(240) := 'Icon Name';
   p110map             CONSTANT VARCHAR2(240) := 'Map';

   cg$row nit_locations%ROWTYPE;

   --  NIT_LOCATIONS row type variable
   TYPE cg$row_type IS RECORD(
       id               cg$row.id%TYPE
      ,creation_date    cg$row.creation_date%TYPE
      ,created_by       cg$row.created_by%TYPE
      ,last_update_date cg$row.last_update_date%TYPE
      ,last_updated_by  cg$row.last_updated_by%TYPE
      ,lcn_id           cg$row.lcn_id%TYPE
      ,NAME             cg$row.NAME%TYPE
      ,abbreviation     cg$row.abbreviation%TYPE
      ,naming_pattern   cg$row.naming_pattern%TYPE
      ,description      cg$row.description%TYPE
      ,comments         cg$row.comments%TYPE
      ,icon_name        cg$row.icon_name%TYPE
      ,MAP              cg$row.MAP%TYPE
      ,the_rowid        ROWID);

   --  NIT_LOCATIONS indicator type variable
   TYPE cg$ind_type IS RECORD(
       id               BOOLEAN DEFAULT FALSE
      ,creation_date    BOOLEAN DEFAULT FALSE
      ,created_by       BOOLEAN DEFAULT FALSE
      ,last_update_date BOOLEAN DEFAULT FALSE
      ,last_updated_by  BOOLEAN DEFAULT FALSE
      ,lcn_id           BOOLEAN DEFAULT FALSE
      ,NAME             BOOLEAN DEFAULT FALSE
      ,abbreviation     BOOLEAN DEFAULT FALSE
      ,naming_pattern   BOOLEAN DEFAULT FALSE
      ,description      BOOLEAN DEFAULT FALSE
      ,comments         BOOLEAN DEFAULT FALSE
      ,icon_name        BOOLEAN DEFAULT FALSE
      ,MAP              BOOLEAN DEFAULT FALSE);

   cg$ind_true cg$ind_type;

   --  NIT_LOCATIONS primary key type variable
   TYPE cg$pk_type IS RECORD(
       id        cg$row.id%TYPE
      ,the_rowid ROWID);

   --  PL/SQL Table Type variable for triggers
   TYPE cg$table_type IS TABLE OF nit_locations%ROWTYPE INDEX BY BINARY_INTEGER;
   cg$table cg$table_type;

   TYPE cg$tableind_type IS TABLE OF cg$ind_type INDEX BY BINARY_INTEGER;
   cg$tableind cg$tableind_type;
   idx         BINARY_INTEGER := 1;

   PROCEDURE ins(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_ins IN BOOLEAN DEFAULT TRUE);
   PROCEDURE upd(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_upd IN BOOLEAN DEFAULT TRUE
                ,cg$pk  IN cg$row_type DEFAULT NULL);
   PROCEDURE del(cg$pk  IN cg$pk_type
                ,do_del IN BOOLEAN DEFAULT TRUE);
   PROCEDURE lck(cg$old_rec  IN cg$row_type
                ,cg$old_ind  IN cg$ind_type
                ,nowait_flag IN BOOLEAN DEFAULT TRUE);
   PROCEDURE slct(cg$sel_rec IN OUT cg$row_type);

END cg$nit_locations;
/

prompt
prompt Creating package CG$NIT_MESSAGES
prompt ================================
prompt
CREATE OR REPLACE PACKAGE cg$nit_messages AUTHID CURRENT_USER IS


   called_from_package BOOLEAN := FALSE;

   --  Repository User-Defined Error Messages
   nit_cpk_msg CONSTANT VARCHAR2(240) := '';
   nit_cuk_msg CONSTANT VARCHAR2(240) := '';

   --  Column default prompts. Format PSEQNO_COL
   p10id               CONSTANT VARCHAR2(240) := 'Id';
   p15creation_date    CONSTANT VARCHAR2(240) := 'Creation Date';
   p16created_by       CONSTANT VARCHAR2(240) := 'Created By';
   p19last_update_date CONSTANT VARCHAR2(240) := 'Last Update Date';
   p24last_updated_by  CONSTANT VARCHAR2(240) := 'Last Updated By';
   p29code             CONSTANT VARCHAR2(240) := 'Code';
   p34language         CONSTANT VARCHAR2(240) := 'Lang';
   p42source_lang      CONSTANT VARCHAR2(240) := 'Source Lang';
   p50message          CONSTANT VARCHAR2(240) := 'Message';
   p70hint             CONSTANT VARCHAR2(240) := 'Hint';
   p80used_in          CONSTANT VARCHAR2(240) := 'Used In';
   p90comments         CONSTANT VARCHAR2(240) := 'Comments';

   cg$row nit_messages%ROWTYPE;

   --  NIT_MESSAGES row type variable
   TYPE cg$row_type IS RECORD(
       id               cg$row.id%TYPE
      ,creation_date    cg$row.creation_date%TYPE
      ,created_by       cg$row.created_by%TYPE
      ,last_update_date cg$row.last_update_date%TYPE
      ,last_updated_by  cg$row.last_updated_by%TYPE
      ,code             cg$row.code%TYPE
      ,LANGUAGE         cg$row.LANGUAGE%TYPE
      ,source_lang      cg$row.source_lang%TYPE
      ,message          cg$row.message%TYPE
      ,hint             cg$row.hint%TYPE
      ,used_in          cg$row.used_in%TYPE
      ,comments         cg$row.comments%TYPE
      ,the_rowid        ROWID);

   --  NIT_MESSAGES indicator type variable
   TYPE cg$ind_type IS RECORD(
       id               BOOLEAN DEFAULT FALSE
      ,creation_date    BOOLEAN DEFAULT FALSE
      ,created_by       BOOLEAN DEFAULT FALSE
      ,last_update_date BOOLEAN DEFAULT FALSE
      ,last_updated_by  BOOLEAN DEFAULT FALSE
      ,code             BOOLEAN DEFAULT FALSE
      ,LANGUAGE         BOOLEAN DEFAULT FALSE
      ,source_lang      BOOLEAN DEFAULT FALSE
      ,message          BOOLEAN DEFAULT FALSE
      ,hint             BOOLEAN DEFAULT FALSE
      ,used_in          BOOLEAN DEFAULT FALSE
      ,comments         BOOLEAN DEFAULT FALSE);

   cg$ind_true cg$ind_type;

   --  NIT_MESSAGES primary key type variable
   TYPE cg$pk_type IS RECORD(
       id        cg$row.id%TYPE
      ,the_rowid ROWID);

   --  PL/SQL Table Type variable for triggers
   TYPE cg$table_type IS TABLE OF nit_messages%ROWTYPE INDEX BY BINARY_INTEGER;
   cg$table cg$table_type;

   TYPE cg$tableind_type IS TABLE OF cg$ind_type INDEX BY BINARY_INTEGER;
   cg$tableind cg$tableind_type;
   idx         BINARY_INTEGER := 1;

   PROCEDURE ins(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_ins IN BOOLEAN DEFAULT TRUE);
   PROCEDURE upd(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_upd IN BOOLEAN DEFAULT TRUE
                ,cg$pk  IN cg$row_type DEFAULT NULL);
   PROCEDURE del(cg$pk  IN cg$pk_type
                ,do_del IN BOOLEAN DEFAULT TRUE);
   PROCEDURE lck(cg$old_rec  IN cg$row_type
                ,cg$old_ind  IN cg$ind_type
                ,nowait_flag IN BOOLEAN DEFAULT TRUE);
   PROCEDURE slct(cg$sel_rec IN OUT cg$row_type);

   PROCEDURE validate_arc(cg$rec IN OUT cg$row_type);

   PROCEDURE validate_domain(cg$rec IN OUT cg$row_type
                            ,cg$ind IN cg$ind_type DEFAULT cg$ind_true);

   PROCEDURE validate_foreign_keys_ins(cg$rec IN cg$row_type);
   PROCEDURE validate_foreign_keys_upd(cg$rec     IN cg$row_type
                                      ,cg$old_rec IN cg$row_type
                                      ,cg$ind     IN cg$ind_type);
   PROCEDURE validate_foreign_keys_del(cg$rec IN cg$row_type);

   PROCEDURE validate_domain_cascade_delete(cg$old_rec IN cg$row_type);
   PROCEDURE validate_domain_cascade_update(cg$old_rec IN cg$row_type);

   PROCEDURE cascade_update(cg$new_rec IN OUT cg$row_type
                           ,cg$old_rec IN cg$row_type);
   PROCEDURE domain_cascade_update(cg$new_rec IN OUT cg$row_type
                                  ,cg$new_ind IN OUT cg$ind_type
                                  ,cg$old_rec IN cg$row_type);
   PROCEDURE domain_cascade_upd(cg$rec     IN OUT cg$row_type
                               ,cg$ind     IN OUT cg$ind_type
                               ,cg$old_rec IN cg$row_type);

   PROCEDURE cascade_delete(cg$old_rec IN OUT cg$row_type);
   PROCEDURE domain_cascade_delete(cg$old_rec IN cg$row_type);

   PROCEDURE upd_denorm2(cg$rec IN cg$row_type
                        ,cg$ind IN cg$ind_type);
   PROCEDURE upd_oper_denorm2(cg$rec     IN cg$row_type
                             ,cg$old_rec IN cg$row_type
                             ,cg$ind     IN cg$ind_type
                             ,operation  IN VARCHAR2 DEFAULT 'UPD');
END cg$nit_messages;
/

prompt
prompt Creating package CG$NIT_OPERATIONS
prompt ==================================
prompt
CREATE OR REPLACE PACKAGE cg$nit_operations AUTHID CURRENT_USER IS


   called_from_package BOOLEAN := FALSE;

   --  Repository User-Defined Error Messages
   nit_cpk_opn     CONSTANT VARCHAR2(240) := '';
   nit_cfk_opn_usr CONSTANT VARCHAR2(240) := '';

   --  Column default prompts. Format PSEQNO_COL
   p10id               CONSTANT VARCHAR2(240) := 'Id';
   p15creation_date    CONSTANT VARCHAR2(240) := 'Creation Date';
   p16created_by       CONSTANT VARCHAR2(240) := 'Created By';
   p19last_update_date CONSTANT VARCHAR2(240) := 'Last Update Date';
   p24last_updated_by  CONSTANT VARCHAR2(240) := 'Last Updated By';
   p30usr_id           CONSTANT VARCHAR2(240) := 'User Id';
   p40type_name        CONSTANT VARCHAR2(240) := 'Type Name';
   p50status           CONSTANT VARCHAR2(240) := 'Status';
   p60op_time          CONSTANT VARCHAR2(240) := 'Op Time';
   p70users            CONSTANT VARCHAR2(240) := 'Users';
   p80comments         CONSTANT VARCHAR2(240) := 'Comment';

   cg$row nit_operations%ROWTYPE;

   --  NIT_OPERATIONS row type variable
   TYPE cg$row_type IS RECORD(
       id               cg$row.id%TYPE
      ,creation_date    cg$row.creation_date%TYPE
      ,created_by       cg$row.created_by%TYPE
      ,last_update_date cg$row.last_update_date%TYPE
      ,last_updated_by  cg$row.last_updated_by%TYPE
      ,usr_id           cg$row.usr_id%TYPE
      ,type_name        cg$row.type_name%TYPE
      ,status           cg$row.status%TYPE
      ,op_time          cg$row.op_time%TYPE
      ,users            cg$row.users%TYPE
      ,comments         cg$row.comments%TYPE
      ,the_rowid        ROWID);

   --  NIT_OPERATIONS indicator type variable
   TYPE cg$ind_type IS RECORD(
       id               BOOLEAN DEFAULT FALSE
      ,creation_date    BOOLEAN DEFAULT FALSE
      ,created_by       BOOLEAN DEFAULT FALSE
      ,last_update_date BOOLEAN DEFAULT FALSE
      ,last_updated_by  BOOLEAN DEFAULT FALSE
      ,usr_id           BOOLEAN DEFAULT FALSE
      ,type_name        BOOLEAN DEFAULT FALSE
      ,status           BOOLEAN DEFAULT FALSE
      ,op_time          BOOLEAN DEFAULT FALSE
      ,users            BOOLEAN DEFAULT FALSE
      ,comments         BOOLEAN DEFAULT FALSE);

   cg$ind_true cg$ind_type;

   --  NIT_OPERATIONS primary key type variable
   TYPE cg$pk_type IS RECORD(
       id        cg$row.id%TYPE
      ,the_rowid ROWID);

   --  PL/SQL Table Type variable for triggers
   TYPE cg$table_type IS TABLE OF nit_operations%ROWTYPE INDEX BY BINARY_INTEGER;
   cg$table cg$table_type;

   TYPE cg$tableind_type IS TABLE OF cg$ind_type INDEX BY BINARY_INTEGER;
   cg$tableind cg$tableind_type;
   idx         BINARY_INTEGER := 1;

   PROCEDURE ins(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_ins IN BOOLEAN DEFAULT TRUE);
   PROCEDURE upd(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_upd IN BOOLEAN DEFAULT TRUE
                ,cg$pk  IN cg$row_type DEFAULT NULL);
   PROCEDURE del(cg$pk  IN cg$pk_type
                ,do_del IN BOOLEAN DEFAULT TRUE);
   PROCEDURE lck(cg$old_rec  IN cg$row_type
                ,cg$old_ind  IN cg$ind_type
                ,nowait_flag IN BOOLEAN DEFAULT TRUE);
   PROCEDURE slct(cg$sel_rec IN OUT cg$row_type);

   PROCEDURE validate_domain(cg$rec IN OUT cg$row_type
                            ,cg$ind IN cg$ind_type DEFAULT cg$ind_true);
END cg$nit_operations;
/

prompt
prompt Creating package CG$NIT_POSITIONS
prompt =================================
prompt
CREATE OR REPLACE PACKAGE cg$nit_positions AUTHID CURRENT_USER IS


   called_from_package BOOLEAN := FALSE;

   --  Repository User-Defined Error Messages
   nit_cpk_psn     CONSTANT VARCHAR2(240) := '';
   nit_cfk_psn_opn CONSTANT VARCHAR2(240) := '';
   nit_cfk_psn_ci  CONSTANT VARCHAR2(240) := '';
   nit_cfk_psn_lcn CONSTANT VARCHAR2(240) := '';

   --  Column default prompts. Format PSEQNO_COL
   p10id               CONSTANT VARCHAR2(240) := 'Id';
   p15creation_date    CONSTANT VARCHAR2(240) := 'Creation Date';
   p16created_by       CONSTANT VARCHAR2(240) := 'Created By';
   p19last_update_date CONSTANT VARCHAR2(240) := 'Last Update Date';
   p24last_updated_by  CONSTANT VARCHAR2(240) := 'Last Updated By';
   p26ci_id            CONSTANT VARCHAR2(240) := 'Ci Id';
   p34lcn_id           CONSTANT VARCHAR2(240) := 'Loc Id';
   p50opn_id           CONSTANT VARCHAR2(240) := 'Op Id';
   p60status           CONSTANT VARCHAR2(240) := 'Status';
   p80obsolete         CONSTANT VARCHAR2(240) := 'Obsolete';
   p90valid_from       CONSTANT VARCHAR2(240) := 'Valid From';
   p100valid_until     CONSTANT VARCHAR2(240) := 'Valid Until';
   p110comments        CONSTANT VARCHAR2(240) := 'Comment';

   cg$row nit_positions%ROWTYPE;

   --  NIT_POSITIONS row type variable
   TYPE cg$row_type IS RECORD(
       id               cg$row.id%TYPE
      ,creation_date    cg$row.creation_date%TYPE
      ,created_by       cg$row.created_by%TYPE
      ,last_update_date cg$row.last_update_date%TYPE
      ,last_updated_by  cg$row.last_updated_by%TYPE
      ,ci_id            cg$row.ci_id%TYPE
      ,lcn_id           cg$row.lcn_id%TYPE
      ,opn_id           cg$row.opn_id%TYPE
      ,status           cg$row.status%TYPE
      ,obsolete         cg$row.obsolete%TYPE
      ,valid_from       cg$row.valid_from%TYPE
      ,valid_until      cg$row.valid_until%TYPE
      ,comments         cg$row.comments%TYPE
      ,the_rowid        ROWID);

   --  NIT_POSITIONS indicator type variable
   TYPE cg$ind_type IS RECORD(
       id               BOOLEAN DEFAULT FALSE
      ,creation_date    BOOLEAN DEFAULT FALSE
      ,created_by       BOOLEAN DEFAULT FALSE
      ,last_update_date BOOLEAN DEFAULT FALSE
      ,last_updated_by  BOOLEAN DEFAULT FALSE
      ,ci_id            BOOLEAN DEFAULT FALSE
      ,lcn_id           BOOLEAN DEFAULT FALSE
      ,opn_id           BOOLEAN DEFAULT FALSE
      ,status           BOOLEAN DEFAULT FALSE
      ,obsolete         BOOLEAN DEFAULT FALSE
      ,valid_from       BOOLEAN DEFAULT FALSE
      ,valid_until      BOOLEAN DEFAULT FALSE
      ,comments         BOOLEAN DEFAULT FALSE);

   cg$ind_true cg$ind_type;

   --  NIT_POSITIONS primary key type variable
   TYPE cg$pk_type IS RECORD(
       id        cg$row.id%TYPE
      ,the_rowid ROWID);

   --  PL/SQL Table Type variable for triggers
   TYPE cg$table_type IS TABLE OF nit_positions%ROWTYPE INDEX BY BINARY_INTEGER;
   cg$table cg$table_type;

   TYPE cg$tableind_type IS TABLE OF cg$ind_type INDEX BY BINARY_INTEGER;
   cg$tableind cg$tableind_type;
   idx         BINARY_INTEGER := 1;

   PROCEDURE ins(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_ins IN BOOLEAN DEFAULT TRUE);
   PROCEDURE upd(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_upd IN BOOLEAN DEFAULT TRUE
                ,cg$pk  IN cg$row_type DEFAULT NULL);
   PROCEDURE del(cg$pk  IN cg$pk_type
                ,do_del IN BOOLEAN DEFAULT TRUE);
   PROCEDURE lck(cg$old_rec  IN cg$row_type
                ,cg$old_ind  IN cg$ind_type
                ,nowait_flag IN BOOLEAN DEFAULT TRUE);
   PROCEDURE slct(cg$sel_rec IN OUT cg$row_type);

   --   PROCEDURE validate_arc(cg$rec IN OUT cg$row_type);

   PROCEDURE validate_domain(cg$rec IN OUT cg$row_type
                            ,cg$ind IN cg$ind_type DEFAULT cg$ind_true);

END cg$nit_positions;
/

prompt
prompt Creating package CG$NIT_USERS
prompt =============================
prompt
CREATE OR REPLACE PACKAGE cg$nit_users AUTHID CURRENT_USER IS


   called_from_package BOOLEAN := FALSE;

   --  Repository User-Defined Error Messages
   nit_cpk_usr CONSTANT VARCHAR2(240) := '';
   nit_cuk_usr CONSTANT VARCHAR2(240) := 'NIT-00065';

   --  Column default prompts. Format PSEQNO_COL
   p10id               CONSTANT VARCHAR2(240) := 'Id';
   p15creation_date    CONSTANT VARCHAR2(240) := 'Creation Date';
   p16created_by       CONSTANT VARCHAR2(240) := 'Created By';
   p19last_update_date CONSTANT VARCHAR2(240) := 'Last Update Date';
   p24last_updated_by  CONSTANT VARCHAR2(240) := 'Last Updated By';
   p30username         CONSTANT VARCHAR2(240) := 'Username';
   p40realname         CONSTANT VARCHAR2(240) := 'Realname';
   p50email            CONSTANT VARCHAR2(240) := 'Email';
   p55language         CONSTANT VARCHAR2(240) := 'Language';
   p60comments         CONSTANT VARCHAR2(240) := 'Comment';
   p70role             CONSTANT VARCHAR2(240) := 'Role';

   cg$row nit_users%ROWTYPE;

   --  NIT_USERS row type variable
   TYPE cg$row_type IS RECORD(
       id               cg$row.id%TYPE
      ,creation_date    cg$row.creation_date%TYPE
      ,created_by       cg$row.created_by%TYPE
      ,last_update_date cg$row.last_update_date%TYPE
      ,last_updated_by  cg$row.last_updated_by%TYPE
      ,username         cg$row.username%TYPE
      ,realname         cg$row.realname%TYPE
      ,email            cg$row.email%TYPE
      ,LANGUAGE         cg$row.LANGUAGE%TYPE
      ,comments         cg$row.comments%TYPE
      ,role             cg$row.role%TYPE
      ,the_rowid        ROWID);

   --  NIT_USERS indicator type variable
   TYPE cg$ind_type IS RECORD(
       id               BOOLEAN DEFAULT FALSE
      ,creation_date    BOOLEAN DEFAULT FALSE
      ,created_by       BOOLEAN DEFAULT FALSE
      ,last_update_date BOOLEAN DEFAULT FALSE
      ,last_updated_by  BOOLEAN DEFAULT FALSE
      ,username         BOOLEAN DEFAULT FALSE
      ,realname         BOOLEAN DEFAULT FALSE
      ,email            BOOLEAN DEFAULT FALSE
      ,LANGUAGE         BOOLEAN DEFAULT FALSE
      ,comments         BOOLEAN DEFAULT FALSE
      ,role             BOOLEAN DEFAULT FALSE);

   cg$ind_true cg$ind_type;

   --  NIT_USERS primary key type variable
   TYPE cg$pk_type IS RECORD(
       id        cg$row.id%TYPE
      ,the_rowid ROWID);

   --  PL/SQL Table Type variable for triggers
   TYPE cg$table_type IS TABLE OF nit_users%ROWTYPE INDEX BY BINARY_INTEGER;
   cg$table cg$table_type;

   TYPE cg$tableind_type IS TABLE OF cg$ind_type INDEX BY BINARY_INTEGER;
   cg$tableind cg$tableind_type;
   idx         BINARY_INTEGER := 1;

   PROCEDURE ins(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_ins IN BOOLEAN DEFAULT TRUE);
   PROCEDURE upd(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_upd IN BOOLEAN DEFAULT TRUE
                ,cg$pk  IN cg$row_type DEFAULT NULL);
   PROCEDURE del(cg$pk  IN cg$pk_type
                ,do_del IN BOOLEAN DEFAULT TRUE);
   PROCEDURE lck(cg$old_rec  IN cg$row_type
                ,cg$old_ind  IN cg$ind_type
                ,nowait_flag IN BOOLEAN DEFAULT TRUE);
   PROCEDURE slct(cg$sel_rec IN OUT cg$row_type);
END cg$nit_users;
/

prompt
prompt Creating type NIT_CARD_OT
prompt =========================
prompt
CREATE OR REPLACE TYPE "NIT_CARD_OT"                                                                          AS OBJECT
 (MODULE VARCHAR2(60)
 ,VERSION VARCHAR2(100)



 )
/

prompt
prompt Creating type NIT_CARD_CT
prompt =========================
prompt
CREATE OR REPLACE TYPE "NIT_CARD_CT" AS TABLE OF NIT_CARD_OT
/

prompt
prompt Creating package NIT_CARD_P
prompt ===========================
prompt
CREATE OR REPLACE PACKAGE nit_card_p AUTHID CURRENT_USER IS
   TYPE module_tab_type IS TABLE OF VARCHAR2(60) INDEX BY BINARY_INTEGER;
   TYPE version_tab_type IS TABLE OF VARCHAR2(100) INDEX BY BINARY_INTEGER;

   g_max_module_len  CONSTANT NUMBER := 60;
   g_max_version_len CONSTANT NUMBER := 100;

   module_tab  module_tab_type;
   version_tab version_tab_type;

   -----------------------------------------------------------------------

   FUNCTION package_version RETURN VARCHAR2;

   -----------------------------------------------------------------------

   PROCEDURE log(p_module  VARCHAR2
                ,p_version VARCHAR2);

   -----------------------------------------------------------------------

   FUNCTION get_log RETURN VARCHAR2;

   -----------------------------------------------------------------------

   FUNCTION get_log_recordset RETURN nit_card_ct;

-----------------------------------------------------------------------
END nit_card_p;
/

prompt
prompt Creating package NIT_CI_ATTRIBUTES_P
prompt ====================================
prompt
CREATE OR REPLACE PACKAGE nit_ci_attributes_p AUTHID CURRENT_USER IS

   FUNCTION package_version RETURN VARCHAR2;

   PROCEDURE archiving(p_rec     IN OUT cg$nit_ci_attributes.cg$row_type
                      ,p_old_rec IN OUT cg$nit_ci_attributes.cg$row_type);

   PROCEDURE pre_dml(p_rec IN OUT cg$nit_ci_attributes.cg$row_type
                    ,p_ind IN OUT cg$nit_ci_attributes.cg$ind_type
                    ,p_op  IN VARCHAR2);

   PROCEDURE pre_upd(p_rec IN OUT cg$nit_ci_attributes.cg$row_type
                    ,p_ind IN OUT cg$nit_ci_attributes.cg$ind_type);


END nit_ci_attributes_p;
/

prompt
prompt Creating type NIT_CI_PROPERTIES_OT
prompt ==================================
prompt
CREATE OR REPLACE TYPE "NIT_CI_PROPERTIES_OT"                                                                          AS OBJECT
(ID                            INTEGER
,CREATION_DATE                 DATE
,CREATED_BY                    VARCHAR2(30)
,LAST_UPDATE_DATE              DATE
,LAST_UPDATED_BY               VARCHAR2(30)
,CIPT_ID                       INTEGER
,CIT_ID                        INTEGER
,CIP_ID_ANCIENT                INTEGER
,CIP_ID                        INTEGER
,REQUIRED                      VARCHAR2(1)
,SET_LIKE                      VARCHAR2(1)
,IS_INHERITED                  VARCHAR2(1)
,ORDER_IN_LIST                 SMALLINT
,DESCRIPTION                   VARCHAR2(1000)
,COMMENTS                      VARCHAR2(1000)
)
/

prompt
prompt Creating type NIT_CI_PROPERTIES_CT
prompt ==================================
prompt
CREATE OR REPLACE TYPE "NIT_CI_PROPERTIES_CT" IS TABLE OF NIT_CI_PROPERTIES_OT;
/

prompt
prompt Creating package NIT_CI_PROPERTIES_P
prompt ====================================
prompt
CREATE OR REPLACE PACKAGE nit_ci_properties_p AUTHID CURRENT_USER IS

   FUNCTION package_version RETURN VARCHAR2;

   PROCEDURE pre_dml(p_rec IN OUT cg$nit_ci_properties.cg$row_type
                    ,p_ind IN OUT cg$nit_ci_properties.cg$ind_type
                    ,p_op  IN VARCHAR2);

   PROCEDURE pre_del(p_id IN nit_ci_properties.id%TYPE);

   PROCEDURE pre_upd(p_rec IN OUT cg$nit_ci_properties.cg$row_type
                    ,p_ind IN OUT cg$nit_ci_properties.cg$ind_type);

   -- Type-Specific Knowledge

   PROCEDURE set_inherited(p_rec IN OUT cg$nit_ci_properties.cg$row_type
                          ,p_ind IN OUT cg$nit_ci_properties.cg$ind_type);

   FUNCTION is_deletable(p_id IN nit_ci_properties.id%TYPE) RETURN CHAR;

   PROCEDURE set_order_before(p_rec IN OUT cg$nit_ci_properties.cg$row_type
                             ,p_id  IN nit_ci_properties.id%TYPE);

   PROCEDURE set_order_after(p_rec IN OUT cg$nit_ci_properties.cg$row_type
                            ,p_id  IN nit_ci_properties.id%TYPE);

   --   PROCEDURE special_cip_ins(p_cit_id    IN nit_ci_types.id%TYPE
   --                            ,p_cipt_name IN nit_ci_property_types.NAME%TYPE);

   PROCEDURE cascade_ins(p_rec IN OUT cg$nit_ci_properties.cg$row_type
                        ,p_ind IN OUT cg$nit_ci_properties.cg$ind_type);

   PROCEDURE cascade_upd(p_rec IN OUT cg$nit_ci_properties.cg$row_type
                        ,p_ind IN OUT cg$nit_ci_properties.cg$ind_type);

   FUNCTION is_child_of(p_parent IN nit_ci_properties.id%TYPE
                       ,p_child  IN nit_ci_properties.id%TYPE) RETURN CHAR;

   FUNCTION is_direct_child_of(p_parent IN nit_ci_properties.id%TYPE
                              ,p_child  IN nit_ci_properties.id%TYPE) RETURN CHAR;

   FUNCTION is_parent_of(p_parent IN nit_ci_properties.id%TYPE
                        ,p_child  IN nit_ci_properties.id%TYPE) RETURN CHAR;

   FUNCTION is_direct_parent_of(p_parent IN nit_ci_properties.id%TYPE
                               ,p_child  IN nit_ci_properties.id%TYPE) RETURN CHAR;

   FUNCTION is_brother_of(p_child1 IN nit_ci_properties.id%TYPE
                         ,p_child2 IN nit_ci_properties.id%TYPE) RETURN CHAR;

   FUNCTION get_children(p_id IN nit_ci_properties.id%TYPE)
      RETURN nit_ci_properties_ct;

   FUNCTION get_parents_by_inherit(p_id IN nit_ci_properties.id%TYPE)
      RETURN nit_ci_properties_ct;

   FUNCTION get_parents_by_rev_inherit(p_id IN nit_ci_properties.id%TYPE)
      RETURN nit_ci_properties_ct;

   FUNCTION get_brothers(p_id IN nit_ci_properties.id%TYPE)
      RETURN nit_ci_properties_ct;

   FUNCTION get_direct_children(p_id IN nit_ci_properties.id%TYPE)
      RETURN nit_ci_properties_ct;

   FUNCTION get_direct_parent(p_id IN nit_ci_properties.id%TYPE)
      RETURN nit_ci_properties%ROWTYPE;

   FUNCTION is_root(p_id IN nit_ci_properties.id%TYPE) RETURN CHAR;

   FUNCTION is_leaf(p_id IN nit_ci_properties.id%TYPE) RETURN CHAR;

END nit_ci_properties_p;
/

prompt
prompt Creating type NIT_CI_PROPERTY_VALUES_OT
prompt =======================================
prompt
CREATE OR REPLACE TYPE "NIT_CI_PROPERTY_VALUES_OT"                                                                          AS OBJECT
(ID                            INTEGER
,CREATION_DATE                 DATE
,CREATED_BY                    VARCHAR2(30)
,LAST_UPDATE_DATE              DATE
,LAST_UPDATED_BY               VARCHAR2(30)
,CIP_ID                        INTEGER
,IS_DEFAULT                    VARCHAR2(1)
,ORDER_IN_LIST                 SMALLINT
,VALUE                         VARCHAR2(4000)
,DESCRIPTION                   VARCHAR2(1000)
,COMMENTS                      VARCHAR2(1000)
)
/

prompt
prompt Creating type NIT_CI_PROPERTY_VALUES_CT
prompt =======================================
prompt
CREATE OR REPLACE TYPE "NIT_CI_PROPERTY_VALUES_CT" IS TABLE OF NIT_CI_PROPERTY_VALUES_OT;
/

prompt
prompt Creating package NIT_CI_PROPERTY_VALUES_P
prompt =========================================
prompt
CREATE OR REPLACE PACKAGE nit_ci_property_values_p AUTHID CURRENT_USER IS

   PROCEDURE pre_dml(p_rec IN OUT cg$nit_ci_property_values.cg$row_type
                    ,p_ind IN OUT cg$nit_ci_property_values.cg$ind_type
                    ,p_op  IN VARCHAR2);

   FUNCTION is_child_of(p_parent IN nit_ci_property_values.id%TYPE
                       ,p_child  IN nit_ci_property_values.id%TYPE) RETURN CHAR;

   FUNCTION is_direct_child_of(p_parent IN nit_ci_property_values.id%TYPE
                              ,p_child  IN nit_ci_property_values.id%TYPE)
      RETURN CHAR;

   FUNCTION is_parent_of(p_parent IN nit_ci_property_values.id%TYPE
                        ,p_child  IN nit_ci_property_values.id%TYPE) RETURN CHAR;

   FUNCTION is_direct_parent_of(p_parent IN nit_ci_property_values.id%TYPE
                               ,p_child  IN nit_ci_property_values.id%TYPE)
      RETURN CHAR;

   FUNCTION is_brother_of(p_child1 IN nit_ci_property_values.id%TYPE
                         ,p_child2 IN nit_ci_property_values.id%TYPE) RETURN CHAR;

   FUNCTION get_children(p_id    IN nit_ci_property_values.id%TYPE
                        ,p_value IN nit_ci_property_values.VALUE%TYPE DEFAULT NULL)
      RETURN nit_num_ct;

   FUNCTION get_parents_by_inherit(p_id IN nit_ci_property_values.id%TYPE)
      RETURN nit_ci_property_values_ct;

   FUNCTION get_parents_by_rev_inherit(p_id IN nit_ci_property_values.id%TYPE)
      RETURN nit_ci_property_values_ct;

   FUNCTION get_brothers(p_id IN nit_ci_property_values.id%TYPE)
      RETURN nit_ci_property_values_ct;

   FUNCTION get_direct_children(p_id IN nit_ci_property_values.id%TYPE)
      RETURN nit_ci_property_values_ct;

   FUNCTION get_direct_parent(p_id IN nit_ci_property_values.id%TYPE)
      RETURN nit_ci_property_values%ROWTYPE;

   FUNCTION is_root(p_id IN nit_ci_property_values.id%TYPE) RETURN CHAR;

   FUNCTION is_leaf(p_id IN nit_ci_property_values.id%TYPE) RETURN CHAR;

   PROCEDURE pre_ins(p_rec cg$nit_ci_property_values.cg$row_type
                    ,p_ind cg$nit_ci_property_values.cg$ind_type);

   PROCEDURE pre_del(p_pk_rec cg$nit_ci_property_values.cg$pk_type);

   PROCEDURE cascade_ins(p_rec cg$nit_ci_property_values.cg$row_type
                        ,p_ind cg$nit_ci_property_values.cg$ind_type);

   PROCEDURE cascade_upd(p_rec       IN cg$nit_ci_property_values.cg$row_type
                        ,p_ind       IN cg$nit_ci_property_values.cg$ind_type
                        ,p_old_value IN nit_ci_property_values.VALUE%TYPE);

   PROCEDURE cascade_del(p_id IN nit_ci_property_values.id%TYPE);

   FUNCTION is_default_value(p_id IN nit_ci_property_values.id%TYPE) RETURN CHAR;

   FUNCTION is_inherited(p_id IN nit_ci_property_values.id%TYPE) RETURN CHAR;

   PROCEDURE sort_all(p_attr      IN VARCHAR2
                     ,p_direction IN VARCHAR2);
   PROCEDURE sort_current_level(p_attr      IN VARCHAR2
                               ,p_direction IN VARCHAR2
                               ,from_id     IN nit_ci_properties.id%TYPE);

   FUNCTION get_default_value(p_id IN nit_ci_properties.id%TYPE) RETURN VARCHAR2;

   FUNCTION has_default_value(p_id IN nit_ci_properties.id%TYPE) RETURN CHAR;

   PROCEDURE set_order_before(p_rec IN OUT cg$nit_ci_property_values.cg$row_type
                             ,p_id  IN nit_ci_property_values.id%TYPE);

   PROCEDURE set_order_after(p_rec IN OUT cg$nit_ci_property_values.cg$row_type
                            ,p_id  IN nit_ci_property_values.id%TYPE);
END nit_ci_property_values_p;
/

prompt
prompt Creating package NIT_CI_RELATIONS_P
prompt ===================================
prompt
CREATE OR REPLACE PACKAGE nit_ci_relations_p AUTHID CURRENT_USER IS

   FUNCTION get_relation_type(p_id IN nit_ci_relations.id%TYPE) RETURN VARCHAR2;

   PROCEDURE archiving(p_rec     IN OUT cg$nit_ci_relations.cg$row_type
                      ,p_old_rec IN OUT cg$nit_ci_relations.cg$row_type);

   PROCEDURE pre_dml(p_rec IN OUT cg$nit_ci_relations.cg$row_type
                    ,p_ind IN OUT cg$nit_ci_relations.cg$ind_type
                    ,p_op  IN VARCHAR2);

   PROCEDURE pre_upd(p_rec IN OUT cg$nit_ci_relations.cg$row_type
                    ,p_ind IN OUT cg$nit_ci_relations.cg$ind_type);

   PROCEDURE create_cir(p_ci_id nit_config_items.id%TYPE);

END nit_ci_relations_p;
/

prompt
prompt Creating package NIT_CIT_RELATION_TYPES_P
prompt =========================================
prompt
CREATE OR REPLACE PACKAGE nit_cit_relation_types_p AUTHID CURRENT_USER IS

   FUNCTION package_version RETURN VARCHAR2;

   PROCEDURE pre_dml(p_rec IN OUT cg$nit_cit_relation_types.cg$row_type
                    ,p_ind IN OUT cg$nit_cit_relation_types.cg$ind_type
                    ,p_op  IN VARCHAR2);

   PROCEDURE pre_del(p_id IN nit_cit_relation_types.id%TYPE);

   PROCEDURE cascade_del(p_id IN nit_cit_relation_types.id%TYPE);

   FUNCTION is_deletable(p_id IN nit_cit_relation_types.id%TYPE) RETURN CHAR;

   FUNCTION is_one_directional(p_name IN nit_cit_relation_types.NAME%TYPE)
      RETURN CHAR;

   FUNCTION is_bidirectional(p_name IN nit_cit_relation_types.NAME%TYPE)
      RETURN CHAR;

   FUNCTION get_contains_rel_name RETURN VARCHAR2;

   FUNCTION get_installed_on_rel_name RETURN VARCHAR2;

END nit_cit_relation_types_p;
/

prompt
prompt Creating package NIT_CI_TYPE_RELATIONS_P
prompt ========================================
prompt
CREATE OR REPLACE PACKAGE nit_ci_type_relations_p AUTHID CURRENT_USER IS

   FUNCTION package_version RETURN VARCHAR2;

   PROCEDURE pre_dml(p_rec IN OUT cg$nit_ci_type_relations.cg$row_type
                    ,p_ind IN OUT cg$nit_ci_type_relations.cg$ind_type
                    ,p_op  IN VARCHAR2);

   PROCEDURE set_order_before(p_rec IN OUT cg$nit_ci_type_relations.cg$row_type
                             ,p_id  IN nit_ci_type_relations.id%TYPE);

   PROCEDURE set_order_after(p_rec IN OUT cg$nit_ci_type_relations.cg$row_type
                            ,p_id  IN nit_ci_type_relations.id%TYPE);

   FUNCTION is_bidirectional(p_id IN nit_ci_type_relations.id%TYPE) RETURN CHAR;

   PROCEDURE make_bidirectional(p_id IN nit_ci_type_relations.id%TYPE);
END nit_ci_type_relations_p;
/

prompt
prompt Creating type NIT_CI_TYPES_OT
prompt =============================
prompt
CREATE OR REPLACE TYPE "NIT_CI_TYPES_OT"                                                                          AS OBJECT
(ID                            INTEGER
,CREATION_DATE                 DATE
,CREATED_BY                    VARCHAR2(30)
,LAST_UPDATE_DATE              DATE
,LAST_UPDATED_BY               VARCHAR2(30)
,CIT_ID                        INTEGER
,NAME                          VARCHAR2(100)
,NEED_PO                       VARCHAR2(1)
,COULD_IN_STOCK                VARCHAR2(1)
,ORDER_IN_LIST                 SMALLINT
,ABBREVIATION                  VARCHAR2(30)
,NAMING_PATTERN                VARCHAR2(1000)
,DESCRIPTION                   VARCHAR2(1000)
,COMMENTS                      VARCHAR2(1000)
,ICON_NAME                     VARCHAR2(100)
)
/

prompt
prompt Creating type NIT_CI_TYPES_CT
prompt =============================
prompt
CREATE OR REPLACE TYPE "NIT_CI_TYPES_CT" IS TABLE OF NIT_CI_TYPES_OT;
/

prompt
prompt Creating package NIT_CI_TYPES_P
prompt ===============================
prompt
CREATE OR REPLACE PACKAGE nit_ci_types_p AUTHID CURRENT_USER IS

   /* FIXME : kateg?ria t?rl?sekor valahogy tudatnom kell, hogy a
   hozz? tartoz?, esetlegesen nem t?r?lheto attrib?tumok
   elt?vol?that?ak. */
   is_deleting VARCHAR2(1) := 'N';

   FUNCTION package_version RETURN VARCHAR2;

   PROCEDURE pre_dml(p_rec IN OUT cg$nit_ci_types.cg$row_type
                    ,p_ind IN OUT cg$nit_ci_types.cg$ind_type
                    ,p_op  IN VARCHAR2);

   PROCEDURE pre_del(p_id IN nit_ci_types.id%TYPE);

   /*   PROCEDURE post_ins(p_rec IN OUT cg$nit_ci_types.cg$row_type
                        ,p_ind IN OUT cg$nit_ci_types.cg$ind_type);
   */

   /*PROCEDURE post_upd(p_rec     IN OUT cg$nit_ci_types.cg$row_type
                     ,p_ind     IN OUT cg$nit_ci_types.cg$ind_type
                     ,p_old_rec IN OUT cg$nit_ci_types.cg$row_type);
   */

   FUNCTION get_default_name(p_rec IN OUT cg$nit_ci_types.cg$row_type)
      RETURN nit_ci_types.NAME%TYPE;

   FUNCTION get_default_naming_pattern(p_rec IN cg$nit_ci_types.cg$row_type)
      RETURN nit_ci_types.naming_pattern%TYPE;

   FUNCTION get_root_id RETURN nit_ci_types.id%TYPE;

   FUNCTION is_child_of(p_parent IN nit_ci_types.id%TYPE
                       ,p_child  IN nit_ci_types.id%TYPE) RETURN CHAR;

   FUNCTION is_direct_child_of(p_parent IN nit_ci_types.id%TYPE
                              ,p_child  IN nit_ci_types.id%TYPE) RETURN CHAR;
   FUNCTION is_parent_of(p_parent IN nit_ci_types.id%TYPE
                        ,p_child  IN nit_ci_types.id%TYPE) RETURN CHAR;
   FUNCTION is_direct_parent_of(p_parent IN nit_ci_types.id%TYPE
                               ,p_child  IN nit_ci_types.id%TYPE) RETURN CHAR;

   FUNCTION is_brother_of(p_child1 IN nit_ci_types.id%TYPE
                         ,p_child2 IN nit_ci_types.id%TYPE) RETURN CHAR;

   FUNCTION get_children(p_id IN nit_ci_types.id%TYPE) RETURN nit_ci_types_ct;

   FUNCTION get_children_ids(p_id IN nit_ci_types.id%TYPE) RETURN nit_num_ct;

   FUNCTION get_parents_by_inherit(p_id IN nit_ci_types.id%TYPE)
      RETURN nit_ci_types_ct;

   FUNCTION get_parents_by_rev_inherit(p_id IN nit_ci_types.id%TYPE)
      RETURN nit_ci_types_ct;

   FUNCTION get_parent_ids_by_inherit(p_id IN nit_ci_types.id%TYPE)
      RETURN nit_num_ct;

   FUNCTION get_brothers(p_id IN nit_ci_types.id%TYPE) RETURN nit_ci_types_ct;

   FUNCTION get_direct_children(p_id IN nit_ci_types.id%TYPE)
      RETURN nit_ci_types_ct;

   FUNCTION get_direct_parent(p_id IN nit_ci_types.id%TYPE)
      RETURN nit_ci_types%ROWTYPE;

   FUNCTION is_root(p_id IN nit_ci_types.id%TYPE) RETURN CHAR;

   FUNCTION is_leaf(p_id IN nit_ci_types.id%TYPE) RETURN CHAR;

   PROCEDURE set_order_before(p_rec IN OUT cg$nit_ci_types.cg$row_type
                             ,p_id  IN nit_ci_types.id%TYPE);

   PROCEDURE set_order_after(p_rec IN OUT cg$nit_ci_types.cg$row_type
                            ,p_id  IN nit_ci_types.id%TYPE);

   PROCEDURE sort_all(p_attr      IN VARCHAR2
                     ,p_direction IN VARCHAR2);

   PROCEDURE sort_sublevels(p_attr      IN VARCHAR2
                           ,p_direction IN VARCHAR2
                           ,from_id     IN nit_ci_types.id%TYPE);

   PROCEDURE sort_current_level(p_attr      IN VARCHAR2
                               ,p_direction IN VARCHAR2
                               ,from_id     IN nit_ci_types.id%TYPE);

   PROCEDURE cascade_ins(p_rec IN OUT cg$nit_ci_types.cg$row_type);

   PROCEDURE cascade_upd(p_rec IN OUT cg$nit_ci_types.cg$row_type);

   PROCEDURE cascade_del(p_id IN OUT nit_ci_types.id%TYPE);

   FUNCTION get_could_in_stock_default(p_rec IN cg$nit_ci_types.cg$row_type)
      RETURN CHAR;

   FUNCTION get_need_po_default(p_rec IN cg$nit_ci_types.cg$row_type) RETURN CHAR;

END nit_ci_types_p;
/

prompt
prompt Creating package NIT_CONFIG_ITEMS_P
prompt ===================================
prompt
CREATE OR REPLACE PACKAGE nit_config_items_p AUTHID CURRENT_USER IS

   PROCEDURE pre_dml(p_rec IN OUT cg$nit_config_items.cg$row_type
                    ,p_ind IN OUT cg$nit_config_items.cg$ind_type
                    ,p_op  IN VARCHAR2);

   PROCEDURE pre_ins(p_rec IN OUT cg$nit_config_items.cg$row_type
                    ,p_ind IN OUT cg$nit_config_items.cg$ind_type);

   PROCEDURE pre_upd(p_rec IN OUT cg$nit_config_items.cg$row_type
                    ,p_ind IN OUT cg$nit_config_items.cg$ind_type);

   PROCEDURE post_ins(p_rec IN OUT cg$nit_config_items.cg$row_type
                     ,p_ind IN OUT cg$nit_config_items.cg$ind_type);

   PROCEDURE cascade_upd(p_rec IN OUT cg$nit_config_items.cg$row_type
                        ,p_ind IN OUT cg$nit_config_items.cg$ind_type);

   FUNCTION get_default_name(p_rec IN cg$nit_config_items.cg$row_type)
      RETURN VARCHAR2;

   FUNCTION get_default_name(p_cit_id IN nit_ci_types.id%TYPE) RETURN VARCHAR2;

   FUNCTION get_serial_suffix(s VARCHAR2) RETURN VARCHAR2;
END nit_config_items_p;
/

prompt
prompt Creating package NIT_F_CIPT_P
prompt =============================
prompt
CREATE OR REPLACE PACKAGE nit_f_cipt_p AUTHID CURRENT_USER IS

   FUNCTION package_version RETURN VARCHAR2;

   TYPE rt_cipt IS RECORD(
       id          nit_ci_property_types.id%TYPE
      ,NAME        nit_ci_property_types.NAME%TYPE
      ,type_name   nit_ci_property_types.type_name%TYPE
      ,description nit_ci_property_types.description%TYPE
      ,comments    nit_ci_property_types.comments%TYPE);

   TYPE it_cipt IS RECORD( -- indicator type
       id          BOOLEAN
      ,NAME        BOOLEAN
      ,type_name   BOOLEAN
      ,description BOOLEAN
      ,comments    BOOLEAN);

   PROCEDURE cipt_ins(p_rec IN OUT rt_cipt
                     ,p_ind IN it_cipt);
   PROCEDURE cipt_upd(p_rec IN OUT rt_cipt
                     ,p_ind IN it_cipt);
   PROCEDURE cipt_lck(p_rec IN OUT rt_cipt
                     ,p_ind IN it_cipt);
   PROCEDURE cipt_del(p_rec IN OUT rt_cipt);

END nit_f_cipt_p;
/

prompt
prompt Creating package NIT_F_CIR_P
prompt ============================
prompt
CREATE OR REPLACE PACKAGE nit_f_cir_p AUTHID CURRENT_USER IS

   FUNCTION package_version RETURN VARCHAR2;

   TYPE rt_cir IS RECORD(
       id          nit_ci_relations.id%TYPE
      ,ci_id_from  nit_ci_relations.ci_id_from%TYPE
      ,ci_id_to    nit_ci_relations.ci_id_to%TYPE
      ,citr_id     nit_ci_relations.citr_id%TYPE
      ,opn_id      nit_ci_relations.opn_id%TYPE
      ,status      nit_ci_relations.status%TYPE
      ,obsolete    nit_ci_relations.obsolete%TYPE
      ,valid_from  nit_ci_relations.valid_from%TYPE
      ,valid_until nit_ci_relations.valid_until%TYPE
      ,comments    nit_ci_relations.comments%TYPE);

   TYPE it_cir IS RECORD(
       id          BOOLEAN
      ,ci_id_from  BOOLEAN
      ,ci_id_to    BOOLEAN
      ,citr_id     BOOLEAN
      ,opn_id      BOOLEAN
      ,status      BOOLEAN
      ,obsolete    BOOLEAN
      ,valid_from  BOOLEAN
      ,valid_until BOOLEAN
      ,comments    BOOLEAN);

   PROCEDURE cir_ins(p_rec IN OUT rt_cir
                    ,p_ind IN it_cir);
   PROCEDURE cir_upd(p_rec IN OUT rt_cir
                    ,p_ind IN it_cir);
   PROCEDURE cir_lck(p_rec IN OUT rt_cir
                    ,p_ind IN it_cir);
   PROCEDURE cir_del(p_rec IN OUT rt_cir);

END nit_f_cir_p;
/

prompt
prompt Creating package NIT_F_CIT_CIP_P
prompt ================================
prompt
CREATE OR REPLACE PACKAGE nit_f_cit_cip_p AUTHID CURRENT_USER IS

   FUNCTION package_version RETURN VARCHAR2;

   TYPE rt_cit_cip IS RECORD( -- record type
       id            nit_ci_properties.id%TYPE
      ,cit_id        nit_ci_properties.cit_id%TYPE
      ,cipt_id       nit_ci_properties.cipt_id%TYPE
      ,cip_id        nit_ci_properties.cip_id%TYPE
      ,cit_name      nit_ci_types.NAME%TYPE
      ,cipt_name     nit_ci_property_types.NAME%TYPE
      ,type_name     nit_ci_property_types.type_name%TYPE
      ,cit_order     nit_ci_types.order_in_list%TYPE
      ,cip_order     nit_ci_properties.order_in_list%TYPE
      ,is_inherited  nit_ci_properties.is_inherited%TYPE
      ,is_importable nit_ci_properties.is_importable%TYPE
      ,auto_import   nit_ci_properties.imp_auto_import%TYPE
      ,required      nit_ci_properties.required%TYPE
      ,set_like      nit_ci_properties.set_like%TYPE
      ,description   nit_ci_properties.description%TYPE
      ,comments      nit_ci_properties.comments%TYPE);


   TYPE it_cit_cip IS RECORD( -- indicator type
       id            BOOLEAN
      ,cit_id        BOOLEAN
      ,cipt_id       BOOLEAN
      ,cip_id        BOOLEAN
      ,cit_name      BOOLEAN
      ,cipt_name     BOOLEAN
      ,type_name     BOOLEAN
      ,cit_order     BOOLEAN
      ,cip_order     BOOLEAN
      ,is_inherited  BOOLEAN
      ,is_importable BOOLEAN
      ,auto_import   BOOLEAN
      ,required      BOOLEAN
      ,set_like      BOOLEAN
      ,description   BOOLEAN
      ,comments      BOOLEAN);

   PROCEDURE cit_cip_ins(p_rec IN OUT rt_cit_cip
                        ,p_ind IN it_cit_cip);

   PROCEDURE cit_cip_upd(p_rec     IN OUT rt_cit_cip
                        ,p_ind     IN it_cit_cip
                        ,p_cascade IN BOOLEAN);

   PROCEDURE cit_cip_lck(p_rec IN OUT rt_cit_cip
                        ,p_ind IN it_cit_cip);

   PROCEDURE cit_cip_del(p_rec     IN OUT rt_cit_cip
                        ,p_cascade IN BOOLEAN);

END nit_f_cit_cip_p;
/

prompt
prompt Creating package NIT_F_CIT_CIPV_P
prompt =================================
prompt
CREATE OR REPLACE PACKAGE nit_f_cit_cipv_p AUTHID CURRENT_USER IS

   FUNCTION package_version RETURN VARCHAR2;

   TYPE rt_cit_cipv IS RECORD( -- record type
       id          nit_ci_property_values.id%TYPE
      ,cit_id      nit_ci_properties.cit_id%TYPE
      ,cipt_id     nit_ci_properties.cipt_id%TYPE
      ,cip_id      nit_ci_property_values.cip_id%TYPE
      ,cit_name    nit_ci_types.NAME%TYPE
      ,cipt_name   nit_ci_property_types.NAME%TYPE
      ,VALUE       nit_ci_property_values.VALUE%TYPE
      ,is_default  nit_ci_property_values.is_default%TYPE
      ,cipv_order  nit_ci_property_values.order_in_list%TYPE
      ,description nit_ci_property_values.description%TYPE
      ,comments    nit_ci_property_values.comments%TYPE);


   TYPE it_cit_cipv IS RECORD( -- indicator type
       id          BOOLEAN
      ,cit_id      BOOLEAN
      ,cipt_id     BOOLEAN
      ,cip_id      BOOLEAN
      ,cit_name    BOOLEAN
      ,cipt_name   BOOLEAN
      ,VALUE       BOOLEAN
      ,is_default  BOOLEAN
      ,cipv_order  BOOLEAN
      ,description BOOLEAN
      ,comments    BOOLEAN);

   PROCEDURE cit_cipv_ins(p_rec IN OUT rt_cit_cipv
                         ,p_ind IN it_cit_cipv);
   PROCEDURE cit_cipv_upd(p_rec     IN OUT rt_cit_cipv
                         ,p_ind     IN it_cit_cipv
                         ,p_cascade IN BOOLEAN);
   PROCEDURE cit_cipv_lck(p_rec IN OUT rt_cit_cipv
                         ,p_ind IN it_cit_cipv);
   PROCEDURE cit_cipv_del(p_rec     IN OUT rt_cit_cipv
                         ,p_cascade IN BOOLEAN);

END nit_f_cit_cipv_p;
/

prompt
prompt Creating package NIT_F_CIT_CITR_P
prompt =================================
prompt
CREATE OR REPLACE PACKAGE nit_f_cit_citr_p AUTHID CURRENT_USER IS

   FUNCTION package_version RETURN VARCHAR2;

   TYPE rt_cit_citr IS RECORD( -- record type
       id             nit_ci_type_relations.id%TYPE
      ,cit_id_from    nit_ci_type_relations.cit_id_from%TYPE
      ,cit_id_to      nit_ci_type_relations.cit_id_to%TYPE
      ,citrt_id       nit_ci_type_relations.citrt_id%TYPE
      ,cit_name_from  nit_ci_types.NAME%TYPE
      ,citrt_name     nit_cit_relation_types.NAME%TYPE
      ,cit_name_to    nit_ci_types.NAME%TYPE
      ,citr_order     nit_ci_type_relations.order_in_list%TYPE
      ,cit_order_from nit_ci_types.order_in_list%TYPE
      ,cit_order_to   nit_ci_types.order_in_list%TYPE
      ,description    nit_ci_type_relations.description%TYPE
      ,comments       nit_ci_type_relations.comments%TYPE);

   TYPE it_cit_citr IS RECORD( -- indicator type
       id             BOOLEAN
      ,cit_id_from    BOOLEAN
      ,cit_id_to      BOOLEAN
      ,citrt_id       BOOLEAN
      ,cit_name_from  BOOLEAN
      ,citrt_name     BOOLEAN
      ,cit_name_to    BOOLEAN
      ,citr_order     BOOLEAN
      ,cit_order_from BOOLEAN
      ,cit_order_to   BOOLEAN
      ,description    BOOLEAN
      ,comments       BOOLEAN);

   PROCEDURE cit_citr_ins(p_rec IN OUT rt_cit_citr
                         ,p_ind IN it_cit_citr);
   PROCEDURE cit_citr_upd(p_rec IN OUT rt_cit_citr
                         ,p_ind IN it_cit_citr);
   PROCEDURE cit_citr_lck(p_rec IN OUT rt_cit_citr
                         ,p_ind IN it_cit_citr);
   PROCEDURE cit_citr_del(p_rec IN OUT rt_cit_citr);

END nit_f_cit_citr_p;
/

prompt
prompt Creating package NIT_F_CIT_P
prompt ============================
prompt
CREATE OR REPLACE PACKAGE nit_f_cit_p AUTHID CURRENT_USER IS

   FUNCTION package_version RETURN VARCHAR2;

   TYPE rt_cit IS RECORD( -- record type
       id                 nit_ci_types.id%TYPE
      ,cit_id             nit_ci_types.cit_id%TYPE
      ,NAME               nit_ci_types.NAME%TYPE
      ,abbreviation       nit_ci_types.abbreviation%TYPE
      ,naming_pattern     nit_ci_types.naming_pattern%TYPE
      ,need_po            nit_ci_types.need_po%TYPE
      ,could_in_stock     nit_ci_types.could_in_stock%TYPE
      ,could_in_inventory nit_ci_types.could_in_inventory%TYPE
      ,order_in_list      nit_ci_types.order_in_list%TYPE
      ,description        nit_ci_types.description%TYPE
      ,comments           nit_ci_types.comments%TYPE
      ,is_importable      nit_ci_types.is_importable%TYPE
      ,auto_import        nit_ci_types.imp_auto_import%TYPE);

   TYPE it_cit IS RECORD( -- indicator type
       id                 BOOLEAN
      ,cit_id             BOOLEAN
      ,NAME               BOOLEAN
      ,abbreviation       BOOLEAN
      ,naming_pattern     BOOLEAN
      ,need_po            BOOLEAN
      ,could_in_stock     BOOLEAN
      ,could_in_inventory BOOLEAN
      ,order_in_list      BOOLEAN
      ,description        BOOLEAN
      ,comments           BOOLEAN
      ,is_importable      BOOLEAN
      ,auto_import        BOOLEAN);

   PROCEDURE cit_ins(p_rec IN OUT rt_cit
                    ,p_ind IN it_cit);
   PROCEDURE cit_upd(p_rec     IN OUT rt_cit
                    ,p_ind     IN it_cit
                    ,p_cascade IN BOOLEAN);
   PROCEDURE cit_lck(p_rec IN OUT rt_cit
                    ,p_ind IN it_cit);
   PROCEDURE cit_del(p_rec IN OUT rt_cit);

   PROCEDURE set_default_name(p_rec IN OUT rt_cit);

   PROCEDURE set_default_naming_pattern(p_rec IN OUT rt_cit);

   PROCEDURE set_could_in_stock_default(p_rec IN OUT rt_cit);

   PROCEDURE set_need_po_default(p_rec IN OUT rt_cit);

END nit_f_cit_p;
/

prompt
prompt Creating package NIT_F_CITRT_P
prompt ==============================
prompt
CREATE OR REPLACE PACKAGE nit_f_citrt_p AUTHID CURRENT_USER IS

   FUNCTION package_version RETURN VARCHAR2;

   TYPE rt_citrt IS RECORD(
       id          nit_cit_relation_types.id%TYPE
      ,NAME        nit_cit_relation_types.NAME%TYPE
      ,description nit_cit_relation_types.description%TYPE
      ,comments    nit_cit_relation_types.comments%TYPE);

   TYPE it_citrt IS RECORD(
       id          BOOLEAN
      ,NAME        BOOLEAN
      ,description BOOLEAN
      ,comments    BOOLEAN);

   PROCEDURE citrt_ins(p_rec IN OUT rt_citrt
                      ,p_ind IN it_citrt);
   PROCEDURE citrt_upd(p_rec IN OUT rt_citrt
                      ,p_ind IN it_citrt);
   PROCEDURE citrt_lck(p_rec IN OUT rt_citrt
                      ,p_ind IN it_citrt);
   PROCEDURE citrt_del(p_rec     IN OUT rt_citrt
                      ,p_cascade IN BOOLEAN);

END nit_f_citrt_p;
/

prompt
prompt Creating package NIT_F_LCN_P
prompt ============================
prompt
CREATE OR REPLACE PACKAGE nit_f_lcn_p AUTHID CURRENT_USER IS

   FUNCTION package_version RETURN VARCHAR2;

   TYPE rt_lcn IS RECORD( -- record type
       id             nit_locations.id%TYPE
      ,lcn_id         nit_locations.lcn_id%TYPE
      ,NAME           nit_locations.NAME%TYPE
      ,abbreviation   nit_locations.abbreviation%TYPE
      ,naming_pattern nit_locations.naming_pattern%TYPE
      ,description    nit_locations.description%TYPE
      ,comments       nit_locations.comments%TYPE);

   TYPE it_lcn IS RECORD( -- indicator type
       id             BOOLEAN
      ,lcn_id         BOOLEAN
      ,NAME           BOOLEAN
      ,abbreviation   BOOLEAN
      ,naming_pattern BOOLEAN
      ,description    BOOLEAN
      ,comments       BOOLEAN);

   PROCEDURE lcn_ins(p_rec IN OUT rt_lcn
                    ,p_ind IN it_lcn);
   PROCEDURE lcn_upd(p_rec IN OUT rt_lcn
                    ,p_ind IN it_lcn);
   PROCEDURE lcn_lck(p_rec IN OUT rt_lcn
                    ,p_ind IN it_lcn);
   PROCEDURE lcn_del(p_rec IN OUT rt_lcn);

   PROCEDURE set_default_name(p_rec IN OUT rt_lcn);

   PROCEDURE set_default_naming_pattern(p_rec IN OUT rt_lcn);

END nit_f_lcn_p;
/

prompt
prompt Creating package NIT_F_MSG_P
prompt ============================
prompt
CREATE OR REPLACE PACKAGE nit_f_msg_p AUTHID CURRENT_USER IS

   FUNCTION package_version RETURN VARCHAR2;

   TYPE rt_msg IS RECORD(
       id       nit_messages.id%TYPE
      ,code     nit_messages.code%TYPE
      ,message  nit_messages.message%TYPE
      ,used_in  nit_messages.used_in%TYPE
      ,hint     nit_messages.hint%TYPE
      ,comments nit_messages.comments%TYPE);

   TYPE it_msg IS RECORD(
       id       BOOLEAN
      ,code     BOOLEAN
      ,message  BOOLEAN
      ,used_in  BOOLEAN
      ,hint     BOOLEAN
      ,comments BOOLEAN);

   PROCEDURE msg_ins(p_rec IN OUT rt_msg
                    ,p_ind IN it_msg);

   PROCEDURE msg_upd(p_rec IN OUT rt_msg
                    ,p_ind IN it_msg);

   PROCEDURE msg_lck(p_rec IN OUT rt_msg
                    ,p_ind IN it_msg);

   PROCEDURE msg_del(p_rec IN OUT rt_msg);

END nit_f_msg_p;
/

prompt
prompt Creating package NIT_F_USR_P
prompt ============================
prompt
CREATE OR REPLACE PACKAGE nit_f_usr_p AUTHID CURRENT_USER IS

   FUNCTION package_version RETURN VARCHAR2;

   TYPE rt_usr IS RECORD(
       id       nit_users.id%TYPE
      ,username nit_users.username%TYPE
      ,realname nit_users.realname%TYPE
      ,LANGUAGE nit_users.LANGUAGE%TYPE
      ,email    nit_users.email%TYPE
      ,comments nit_users.comments%TYPE);

   TYPE it_usr IS RECORD(
       id       BOOLEAN
      ,username BOOLEAN
      ,realname BOOLEAN
      ,LANGUAGE BOOLEAN
      ,email    BOOLEAN
      ,comments BOOLEAN);

   PROCEDURE usr_ins(p_rec IN OUT rt_usr
                    ,p_ind IN it_usr);
   PROCEDURE usr_upd(p_rec IN OUT rt_usr
                    ,p_ind IN it_usr);
   PROCEDURE usr_lck(p_rec IN OUT rt_usr
                    ,p_ind IN it_usr);
   PROCEDURE usr_del(p_rec IN OUT rt_usr);

END nit_f_usr_p;
/

prompt
prompt Creating package NIT_IMPORTER_P
prompt ===============================
prompt
CREATE OR REPLACE PACKAGE nit_importer_p AS

   /*****************************************************************************************
      NAME:       nit_importer_p
      PURPOSE:    Importing SMS (MS SQL) Datas to NItil (Oracle)
   
      REVISIONS:
      Ver        Date        Author                      Description
      ---------  ----------  ---------------         ------------------------------------
      0.1.0.1    2007.01.27. Szabolcs Hodosi/DEB/NIC     Created this package spec.
   ******************************************************************************************/

   FUNCTION get_sms_id(presourceid IN INTEGER
                      ,pgroupid    IN INTEGER
                      ,previsionid IN INTEGER
                      ,pagentid    IN INTEGER) RETURN VARCHAR2;

   FUNCTION get_resource_id(psms_id IN VARCHAR2) RETURN INTEGER DETERMINISTIC;

   FUNCTION get_group_id(psms_id IN VARCHAR2) RETURN INTEGER DETERMINISTIC;

   FUNCTION get_revision_id(psms_id IN VARCHAR2) RETURN INTEGER;

   FUNCTION get_agent_id(psms_id IN VARCHAR2) RETURN INTEGER;

   PROCEDURE ci_refresh(p_id IN nit_config_items.id%TYPE);

   PROCEDURE all_ci_refresh(p_force BOOLEAN);

   PROCEDURE cia_refresh(p_id IN nit_ci_attributes.id%TYPE);

   PROCEDURE all_cia_refresh(p_force BOOLEAN);

   PROCEDURE migrate_all_new_ci(p_force BOOLEAN);

   PROCEDURE migrate_all_new_cia(p_force BOOLEAN);

   PROCEDURE create_cir;

END nit_importer_p;
/

prompt
prompt Creating type NIT_LOCATIONS_OT
prompt ==============================
prompt
CREATE OR REPLACE TYPE "NIT_LOCATIONS_OT"                                                                          AS OBJECT
(ID                            INTEGER
,CREATION_DATE                 DATE
,CREATED_BY                    VARCHAR2(30)
,LAST_UPDATE_DATE              DATE
,LAST_UPDATED_BY               VARCHAR2(30)
,LCN_ID                        INTEGER
,NAME                          VARCHAR2(100)
,ABBREVIATION                  VARCHAR2(30)
,NAMING_PATTERN                VARCHAR2(1000)
,DESCRIPTION                   VARCHAR2(1000)
,COMMENTS                      VARCHAR2(1000)
,ICON_NAME                     VARCHAR2(100)
)
/

prompt
prompt Creating type NIT_LOCATIONS_CT
prompt ==============================
prompt
CREATE OR REPLACE TYPE "NIT_LOCATIONS_CT" IS TABLE OF NIT_LOCATIONS_OT;
/

prompt
prompt Creating package NIT_LOCATIONS_P
prompt ================================
prompt
CREATE OR REPLACE PACKAGE nit_locations_p AUTHID CURRENT_USER IS

   PROCEDURE pre_dml(p_rec IN OUT cg$nit_locations.cg$row_type
                    ,p_ind IN OUT cg$nit_locations.cg$ind_type
                    ,p_op  IN VARCHAR2);
   PROCEDURE pre_del(p_id IN nit_locations.id%TYPE);

   FUNCTION is_deletable(p_id IN nit_locations.id%TYPE) RETURN CHAR;

   FUNCTION package_version RETURN VARCHAR2;

   FUNCTION is_virtual(p_id IN nit_locations.id%TYPE) RETURN CHAR;

   FUNCTION is_mutable(p_id IN nit_locations.id%TYPE) RETURN CHAR;

   FUNCTION is_stock(p_id IN nit_locations.id%TYPE) RETURN CHAR;

   FUNCTION is_root(p_id IN nit_locations.id%TYPE) RETURN CHAR;

   FUNCTION is_leaf(p_id IN nit_locations.id%TYPE) RETURN CHAR;

   FUNCTION get_stock_id RETURN nit_locations.id%TYPE;

   FUNCTION get_virtual_id RETURN nit_locations.id%TYPE;

   FUNCTION get_mutable_id RETURN nit_locations.id%TYPE;

   FUNCTION get_root_id RETURN nit_locations.id%TYPE;

   FUNCTION get_default_name(p_rec IN OUT cg$nit_locations.cg$row_type)
      RETURN nit_locations.NAME%TYPE;

   FUNCTION get_default_naming_pattern(p_rec IN cg$nit_locations.cg$row_type)
      RETURN nit_locations.naming_pattern%TYPE;

   FUNCTION is_child_of(p_parent IN nit_locations.id%TYPE
                       ,p_child  IN nit_locations.id%TYPE) RETURN CHAR;

   FUNCTION is_direct_child_of(p_parent IN nit_locations.id%TYPE
                              ,p_child  IN nit_locations.id%TYPE) RETURN CHAR;
   FUNCTION is_parent_of(p_parent IN nit_locations.id%TYPE
                        ,p_child  IN nit_locations.id%TYPE) RETURN CHAR;
   FUNCTION is_direct_parent_of(p_parent IN nit_locations.id%TYPE
                               ,p_child  IN nit_locations.id%TYPE) RETURN CHAR;

   FUNCTION is_brother_of(p_child1 IN nit_locations.id%TYPE
                         ,p_child2 IN nit_locations.id%TYPE) RETURN CHAR;

   FUNCTION get_children(p_id IN nit_locations.id%TYPE) RETURN nit_locations_ct;

   FUNCTION get_parents_by_inherit(p_id IN nit_locations.id%TYPE)
      RETURN nit_locations_ct;

   FUNCTION get_parents_by_rev_inherit(p_id IN nit_locations.id%TYPE)
      RETURN nit_locations_ct;

   FUNCTION get_brothers(p_id IN nit_locations.id%TYPE) RETURN nit_locations_ct;

   FUNCTION get_direct_children(p_id IN nit_locations.id%TYPE)
      RETURN nit_locations_ct;

   FUNCTION get_direct_parent(p_id IN nit_locations.id%TYPE)
      RETURN nit_locations%ROWTYPE;

   FUNCTION get_direct_parent_obj(p_id IN nit_locations.id%TYPE)
      RETURN nit_locations_ot;

   PROCEDURE cascade_upd(p_rec IN OUT cg$nit_locations.cg$row_type);

   PROCEDURE cascade_del(p_id IN OUT nit_locations.id%TYPE);

END nit_locations_p;
/

prompt
prompt Creating package NIT_OPERATIONS_P
prompt =================================
prompt
CREATE OR REPLACE PACKAGE nit_operations_p AUTHID CURRENT_USER IS

   allowed_statuses CONSTANT nit_string_ct := nit_string_ct('started'
                                                           ,'failed'
                                                           ,'finished');

   operation_types CONSTANT nit_string_ct := nit_string_ct('routine'
                                                          ,'emergency'
                                                          ,'requested');

   started_idx   CONSTANT PLS_INTEGER := 1;
   failed_idx    CONSTANT PLS_INTEGER := 2;
   finished_idx  CONSTANT PLS_INTEGER := 3;
   routine_idx   CONSTANT PLS_INTEGER := 1;
   emergency_idx CONSTANT PLS_INTEGER := 2;
   requested_idx CONSTANT PLS_INTEGER := 3;

   FUNCTION package_version RETURN VARCHAR2;

   FUNCTION get_opn_failed_name RETURN VARCHAR2;

   FUNCTION get_opn_routine_name RETURN VARCHAR2;

   FUNCTION get_opn_emergency_name RETURN VARCHAR2;

   FUNCTION get_opn_requested_name RETURN VARCHAR2;

   FUNCTION start_operation(p_rec IN OUT cg$nit_operations.cg$row_type)
      RETURN nit_operations.id%TYPE;
   PROCEDURE stop_operation(p_id IN nit_operations.id%TYPE);
   PROCEDURE fail_operation(p_id IN nit_operations.id%TYPE);

   FUNCTION start_inner_operation RETURN nit_operations.id%TYPE;
   FUNCTION get_status(p_id nit_operations.id%TYPE) RETURN VARCHAR2;
END nit_operations_p;
/

prompt
prompt Creating package NIT_POSITIONS_P
prompt ================================
prompt
CREATE OR REPLACE PACKAGE nit_positions_p AUTHID CURRENT_USER IS

   FUNCTION package_version RETURN VARCHAR2;

   PROCEDURE pre_dml(p_rec IN OUT cg$nit_positions.cg$row_type
                    ,p_ind IN OUT cg$nit_positions.cg$ind_type
                    ,p_op  IN VARCHAR2);

   PROCEDURE archiving(p_rec     IN OUT cg$nit_positions.cg$row_type
                      ,p_old_rec IN OUT cg$nit_positions.cg$row_type);

   PROCEDURE pre_upd(p_rec IN OUT cg$nit_positions.cg$row_type
                    ,p_ind IN OUT cg$nit_positions.cg$ind_type);

   PROCEDURE cascade_upd(p_rec IN OUT cg$nit_positions.cg$row_type
                        ,p_ind IN OUT cg$nit_positions.cg$ind_type);

END nit_positions_p;
/

prompt
prompt Creating package NIT_USERS_P
prompt ============================
prompt
CREATE OR REPLACE PACKAGE nit_users_p AUTHID CURRENT_USER IS
   greeting_msg CONSTANT VARCHAR2(1000) := 'Welcome to nit';

   FUNCTION package_version RETURN VARCHAR2;

   PROCEDURE pre_dml(p_rec IN OUT cg$nit_users.cg$row_type
                    ,p_ind IN OUT cg$nit_users.cg$ind_type
                    ,p_op  IN VARCHAR2);

   PROCEDURE post_ins(p_rec IN OUT cg$nit_users.cg$row_type
                     ,p_ind IN OUT cg$nit_users.cg$ind_type);

   PROCEDURE pre_del(p_id IN nit_users.id%TYPE);

   PROCEDURE send_mail(p_id      IN nit_users.id%TYPE
                      ,p_subject IN VARCHAR2
                      ,p_message IN VARCHAR2);

   FUNCTION is_deletable(p_id IN nit_users.id%TYPE) RETURN CHAR;

END nit_users_p;
/

prompt
prompt Creating type NIT_CI_ARCHIVE_OT
prompt ===============================
prompt
CREATE OR REPLACE TYPE "NIT_CI_ARCHIVE_OT" AS OBJECT
(
   opn_id        NUMBER,
   ci_id         NUMBER,
   psn_id        NUMBER,
   cia_name_id   NUMBER,
   cia_status_id NUMBER,
   valid_from    DATE,
   valid_until   DATE
)
/

prompt
prompt Creating type NIT_CONFIG_ITEMS_OT
prompt =================================
prompt
CREATE OR REPLACE TYPE NIT_CONFIG_ITEMS_OT AS OBJECT
 (ID INTEGER
 ,CREATION_DATE DATE
 ,CREATED_BY VARCHAR2(30)
 ,LAST_UPDATE_DATE DATE
 ,LAST_UPDATED_BY VARCHAR2(30)
 ,CIT_ID INTEGER
 ,OPN_ID INTEGER
 ,SMS_ID VARCHAR2(200)
 ,NAME VARCHAR2(100)
 ,STATUS VARCHAR2(20)
 ,OBSOLETE VARCHAR2(1)
 ,VALID_FROM DATE
 ,VALID_UNTIL DATE
 ,COMMENTS VARCHAR2(1000)
 ,LAST_REFRESH_DATE DATE
 );
/

prompt
prompt Creating type NIT_CONFIG_ITEMS_CT
prompt =================================
prompt
CREATE OR REPLACE TYPE "NIT_CONFIG_ITEMS_CT" IS TABLE OF NIT_CONFIG_ITEMS_OT;
/

prompt
prompt Creating package body CG$NIT_CI_ATTRIBUTES
prompt ==========================================
prompt
CREATE OR REPLACE PACKAGE BODY cg$nit_ci_attributes IS

   PROCEDURE validate_mandatory(cg$val_rec IN cg$row_type
                               ,loc        IN VARCHAR2 DEFAULT '');
   PROCEDURE up_autogen_columns(cg$rec    IN OUT cg$row_type
                               ,cg$ind    IN OUT cg$ind_type
                               ,operation IN VARCHAR2 DEFAULT 'INS'
                               ,do_denorm IN BOOLEAN DEFAULT TRUE);
   PROCEDURE err_msg(msg  IN VARCHAR2
                    ,TYPE IN INTEGER
                    ,loc  IN VARCHAR2 DEFAULT '');

   --------------------------------------------------------------------------------
   -- Name:        raise_uk_not_updateable
   --
   -- Description: Raise appropriate error when unique key updated
   --
   -- Parameters:  none
   --------------------------------------------------------------------------------
   PROCEDURE raise_uk_not_updateable(uk IN VARCHAR2) IS
   BEGIN
      cg$errors.push(cg$errors.msggettext(cg$errors.api_unique_key_update
                                         ,cg$errors.err_uk_update
                                         ,uk)
                    ,'E'
                    ,'API'
                    ,cg$errors.api_unique_key_update
                    ,'cg$NIT_CI_ATTRIBUTES.raise_uk_not_updateable');
      cg$errors.raise_failure;
   END raise_uk_not_updateable;

   --------------------------------------------------------------------------------
   -- Name:        raise_fk_not_transferable
   --
   -- Description: Raise appropriate error when foreign key updated
   --
   -- Parameters:  none
   --------------------------------------------------------------------------------
   PROCEDURE raise_fk_not_transferable(fk IN VARCHAR2) IS
   BEGIN
      cg$errors.push(cg$errors.msggettext(cg$errors.api_foreign_key_trans
                                         ,cg$errors.err_fk_trans
                                         ,fk)
                    ,'E'
                    ,'API'
                    ,cg$errors.api_foreign_key_trans
                    ,'cg$NIT_CI_ATTRIBUTES.raise_fk_not_transferable');
      cg$errors.raise_failure;
   END raise_fk_not_transferable;

   --------------------------------------------------------------------------------
   -- Name:        up_autogen_columns
   --
   -- Description: Specific autogeneration of column values and conversion to
   --              uppercase
   --
   -- Parameters:  cg$rec    Record of row to be manipulated
   --              cg$ind    Indicators for row
   --              operation Procedure where this procedure was called
   --------------------------------------------------------------------------------
   PROCEDURE up_autogen_columns(cg$rec    IN OUT cg$row_type
                               ,cg$ind    IN OUT cg$ind_type
                               ,operation IN VARCHAR2 DEFAULT 'INS'
                               ,do_denorm IN BOOLEAN DEFAULT TRUE) IS
   BEGIN
      IF (operation = 'INS') THEN
         BEGIN
            IF (cg$ind.id = FALSE OR cg$rec.id IS NULL) THEN
               SELECT nit_seq.NEXTVAL
               INTO   cg$rec.id
               FROM   dual;
               cg$ind.id := TRUE;
            END IF;
         EXCEPTION
            WHEN OTHERS THEN
               cg$errors.push(SQLERRM
                             ,'E'
                             ,'ORA'
                             ,SQLCODE
                             ,'cg$NIT_CI_ATTRIBUTES.up_autogen.ID.OTHERS');
               cg$errors.raise_failure;
         END;
         NULL;
      ELSE
         -- (operation = 'UPD')
         NULL;
      END IF; -- (operation = 'INS') ELSE (operation = 'UPD')

      -- Statements executed for both 'INS' and 'UPD'

   EXCEPTION
      WHEN no_data_found THEN
         NULL;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_ATTRIBUTES.up_autogen_columns');
         cg$errors.raise_failure;
   END up_autogen_columns;

   --------------------------------------------------------------------------------
   -- Name:        validate_mandatory
   --
   -- Description: Checks all mandatory columns are not null and raises appropriate
   --              error if not satisfied
   --
   -- Parameters:  cg$val_rec Record of row to be checked
   --              loc        Place where this procedure was called for error
   --                         trapping
   --------------------------------------------------------------------------------
   PROCEDURE validate_mandatory(cg$val_rec IN cg$row_type
                               ,loc        IN VARCHAR2 DEFAULT '') IS
   BEGIN
      IF (cg$val_rec.id IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p5id)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.creation_date IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p10creation_date)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.created_by IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p15created_by)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.last_update_date IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p18last_update_date)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.last_updated_by IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p19last_updated_by)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.ci_id IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p25ci_id)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.cip_id IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p35cip_id)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.opn_id IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p55opn_id)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.status IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p65status)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.obsolete IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p105obsolete)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.valid_from IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p115valid_from)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.valid_until IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p125valid_until)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.data IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p135data)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      NULL;
   END validate_mandatory;
   --------------------------------------------------------------------------------
   -- Name:        slct
   --
   -- Description: Selects into the given parameter all the attributes for the row
   --              given by the primary key
   --
   -- Parameters:  cg$sel_rec  Record of row to be selected into using its PK
   --------------------------------------------------------------------------------
   PROCEDURE slct(cg$sel_rec IN OUT cg$row_type) IS

   BEGIN

      IF cg$sel_rec.the_rowid IS NULL THEN
         SELECT id
               ,creation_date
               ,created_by
               ,last_update_date
               ,last_updated_by
               ,ci_id
               ,cip_id
               ,opn_id
               ,cipv_id
               ,sms_id
               ,status
               ,obsolete
               ,valid_from
               ,valid_until
               ,data
               ,comments
               ,last_refresh_date
               ,ROWID
         INTO   cg$sel_rec.id
               ,cg$sel_rec.creation_date
               ,cg$sel_rec.created_by
               ,cg$sel_rec.last_update_date
               ,cg$sel_rec.last_updated_by
               ,cg$sel_rec.ci_id
               ,cg$sel_rec.cip_id
               ,cg$sel_rec.opn_id
               ,cg$sel_rec.cipv_id
               ,cg$sel_rec.sms_id
               ,cg$sel_rec.status
               ,cg$sel_rec.obsolete
               ,cg$sel_rec.valid_from
               ,cg$sel_rec.valid_until
               ,cg$sel_rec.data
               ,cg$sel_rec.comments
               ,cg$sel_rec.last_refresh_date
               ,cg$sel_rec.the_rowid
         FROM   nit_ci_attributes
         WHERE  id = cg$sel_rec.id;
      ELSE
         SELECT id
               ,creation_date
               ,created_by
               ,last_update_date
               ,last_updated_by
               ,ci_id
               ,cip_id
               ,opn_id
               ,cipv_id
               ,sms_id
               ,status
               ,obsolete
               ,valid_from
               ,valid_until
               ,data
               ,comments
               ,last_refresh_date
               ,ROWID
         INTO   cg$sel_rec.id
               ,cg$sel_rec.creation_date
               ,cg$sel_rec.created_by
               ,cg$sel_rec.last_update_date
               ,cg$sel_rec.last_updated_by
               ,cg$sel_rec.ci_id
               ,cg$sel_rec.cip_id
               ,cg$sel_rec.opn_id
               ,cg$sel_rec.cipv_id
               ,cg$sel_rec.sms_id
               ,cg$sel_rec.status
               ,cg$sel_rec.obsolete
               ,cg$sel_rec.valid_from
               ,cg$sel_rec.valid_until
               ,cg$sel_rec.data
               ,cg$sel_rec.comments
               ,cg$sel_rec.last_refresh_date
               ,cg$sel_rec.the_rowid
         FROM   nit_ci_attributes
         WHERE  ROWID = cg$sel_rec.the_rowid;
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_ATTRIBUTES.slct.others');
         cg$errors.raise_failure;

   END slct;

   --------------------------------------------------------------------------------
   -- Name:        validate_domain
   --
   -- Description: Checks against reference table for values lying in a domain
   --
   -- Parameters:  cg$rec     Record of NIT_CI_ATTRIBUTES current values
   --------------------------------------------------------------------------------
   PROCEDURE validate_domain(cg$rec IN OUT cg$row_type
                            ,cg$ind IN cg$ind_type DEFAULT cg$ind_true) IS
      FOUND BOOLEAN;
      no_tabview EXCEPTION;
      PRAGMA EXCEPTION_INIT(no_tabview
                           ,-942);
   BEGIN
      FOUND := FALSE;
      IF (cg$ind.status AND cg$rec.status IS NOT NULL) THEN
         FOR c IN (SELECT rv_low_value
                         ,rv_high_value
                   FROM   cg_ref_codes
                   WHERE  rv_domain = 'OPERATABLE_STATUS')
         LOOP
            IF (c.rv_high_value IS NULL AND cg$rec.status = c.rv_low_value) OR
               (c.rv_high_value IS NOT NULL AND
               cg$rec.status BETWEEN c.rv_low_value AND c.rv_high_value) THEN
               FOUND := TRUE;
               EXIT;
            END IF;
         END LOOP;

         IF (NOT FOUND) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_rv_lookup_fail
                                               ,cg$errors.apimsg_rv_lookup_fail
                                               ,cg$rec.status
                                               ,'NIT_CI_ATTRIBUTES'
                                               ,'STATUS')
                          ,'E'
                          ,'API'
                          ,cg$errors.api_rv_lookup_fail
                          ,'cg$NIT_CI_ATTRIBUTES.v_domain.no_data_found');
            cg$errors.raise_failure;
         END IF;
      END IF;

      FOUND := FALSE;
      IF (cg$ind.obsolete AND cg$rec.obsolete IS NOT NULL) THEN
         FOR c IN (SELECT rv_low_value
                         ,rv_high_value
                   FROM   cg_ref_codes
                   WHERE  rv_domain = 'OBSOLETE')
         LOOP
            IF (c.rv_high_value IS NULL AND cg$rec.obsolete = c.rv_low_value) OR
               (c.rv_high_value IS NOT NULL AND
               cg$rec.obsolete BETWEEN c.rv_low_value AND c.rv_high_value) THEN
               FOUND := TRUE;
               EXIT;
            END IF;
         END LOOP;

         IF (NOT FOUND) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_rv_lookup_fail
                                               ,cg$errors.apimsg_rv_lookup_fail
                                               ,cg$rec.obsolete
                                               ,'NIT_CI_ATTRIBUTES'
                                               ,'OBSOLETE')
                          ,'E'
                          ,'API'
                          ,cg$errors.api_rv_lookup_fail
                          ,'cg$NIT_CI_ATTRIBUTES.v_domain.no_data_found');
            cg$errors.raise_failure;
         END IF;
      END IF;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         cg$errors.raise_failure;
      WHEN no_tabview THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_rv_tab_not_found
                                            ,cg$errors.apimsg_rv_tab_not_found
                                            ,'CG_REF_CODES'
                                            ,'NIT_CI_ATTRIBUTES')
                       ,'E'
                       ,'API'
                       ,cg$errors.api_rv_tab_not_found
                       ,'cg$NIT_CI_ATTRIBUTES.v_domain.no_reftable_found');
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_ATTRIBUTES.v_domain.others');
         cg$errors.raise_failure;
   END validate_domain;

   --------------------------------------------------------------------------------
   -- Name:        err_msg
   --
   -- Description: Pushes onto stack appropriate user defined error message
   --              depending on the rule violated
   --
   -- Parameters:  msg     Oracle error message
   --              type    Type of violation e.g. check_constraint: ERR_CHECK_CON
   --              loc     Place where this procedure was called for error
   --                      trapping
   --------------------------------------------------------------------------------
   PROCEDURE err_msg(msg  IN VARCHAR2
                    ,TYPE IN INTEGER
                    ,loc  IN VARCHAR2 DEFAULT '') IS
      con_name VARCHAR2(240);
   BEGIN
      con_name := cg$errors.parse_constraint(msg
                                            ,TYPE);
      IF (con_name = 'NIT_CPK_CIA') THEN
         cg$errors.push(NVL(nit_cpk_cia
                           ,cg$errors.msggettext(cg$errors.api_pk_con_violated
                                                ,cg$errors.apimsg_pk_violat
                                                ,'NIT_CPK_CIA'
                                                ,'NIT_CI_ATTRIBUTES'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_pk_con_violated
                       ,loc);

      ELSIF (con_name = 'NIT_CFK_CIA_CIP') THEN
         cg$errors.push(NVL(nit_cfk_cia_cip
                           ,cg$errors.msggettext(cg$errors.api_fk_con_violated
                                                ,cg$errors.apimsg_fk_violat
                                                ,'NIT_CFK_CIA_CIP'
                                                ,'NIT_CI_ATTRIBUTES'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_fk_con_violated
                       ,loc);
      ELSIF (con_name = 'NITIL_CFK_CIA_CI') THEN
         cg$errors.push(NVL(nitil_cfk_cia_ci
                           ,cg$errors.msggettext(cg$errors.api_fk_con_violated
                                                ,cg$errors.apimsg_fk_violat
                                                ,'NITIL_CFK_CIA_CI'
                                                ,'NIT_CI_ATTRIBUTES'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_fk_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CFK_CIA_CIV') THEN
         cg$errors.push(NVL(nit_cfk_cia_civ
                           ,cg$errors.msggettext(cg$errors.api_fk_con_violated
                                                ,cg$errors.apimsg_fk_violat
                                                ,'NIT_CFK_CIA_CIV'
                                                ,'NIT_CI_ATTRIBUTES'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_fk_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CFK_CIA_OPN') THEN
         cg$errors.push(NVL(nit_cfk_cia_opn
                           ,cg$errors.msggettext(cg$errors.api_fk_con_violated
                                                ,cg$errors.apimsg_fk_violat
                                                ,'NIT_CFK_CIA_OPN'
                                                ,'NIT_CI_ATTRIBUTES'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_fk_con_violated
                       ,loc);
      ELSE
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,loc);
      END IF;
   END err_msg;

   --------------------------------------------------------------------------------
   -- Name:        ins
   --
   -- Description: API insert procedure
   --
   -- Parameters:  cg$rec  Record of row to be inserted
   --              cg$ind  Record of columns specifically set
   --              do_ins  Whether we want the actual INSERT to occur
   --------------------------------------------------------------------------------
   PROCEDURE ins(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_ins IN BOOLEAN DEFAULT TRUE) IS

      --  Constant default values

      d105_obsolete CONSTANT nit_ci_attributes.obsolete%TYPE := 'L';

   BEGIN
      --  Application_logic Pre-Insert <<Start>>
      BEGIN
         nit_ci_attributes_p.pre_dml(cg$rec
                                    ,cg$ind
                                    ,'INS');
      END;
      --  Application_logic Pre-Insert << End >>

      --  Defaulted

      IF NOT (cg$ind.obsolete) THEN
         cg$rec.obsolete := d105_obsolete;
      END IF;
      --  Auto-generated and uppercased columns

      up_autogen_columns(cg$rec
                        ,cg$ind
                        ,'INS'
                        ,do_ins);

      called_from_package := TRUE;

      IF (do_ins) THEN
         validate_domain(cg$rec);

         INSERT INTO nit_ci_attributes
            (id
            ,creation_date
            ,created_by
            ,last_update_date
            ,last_updated_by
            ,ci_id
            ,cip_id
            ,opn_id
            ,cipv_id
            ,sms_id
            ,status
            ,obsolete
            ,valid_from
            ,valid_until
            ,data
            ,comments
            ,last_refresh_date)
         VALUES
            (cg$rec.id
            ,cg$rec.creation_date
            ,cg$rec.created_by
            ,cg$rec.last_update_date
            ,cg$rec.last_updated_by
            ,cg$rec.ci_id
            ,cg$rec.cip_id
            ,cg$rec.opn_id
            ,cg$rec.cipv_id
            ,cg$rec.sms_id
            ,cg$rec.status
            ,cg$rec.obsolete
            ,cg$rec.valid_from
            ,cg$rec.valid_until
            ,cg$rec.data
            ,cg$rec.comments
            ,cg$rec.last_refresh_date)
         RETURNING id, creation_date, created_by, last_update_date, last_updated_by, ci_id, cip_id, opn_id, cipv_id, sms_id, status, obsolete, valid_from, valid_until, data, comments, last_refresh_date, ROWID INTO cg$rec.id, cg$rec.creation_date, cg$rec.created_by, cg$rec.last_update_date, cg$rec.last_updated_by, cg$rec.ci_id, cg$rec.cip_id, cg$rec.opn_id, cg$rec.cipv_id, cg$rec.sms_id, cg$rec.status, cg$rec.obsolete, cg$rec.valid_from, cg$rec.valid_until, cg$rec.data, cg$rec.comments, cg$rec.last_refresh_date, cg$rec.the_rowid;
      END IF;

      called_from_package := FALSE;

      --  Application logic Post-Insert <<Start>>
      --  Application logic Post-Insert << End >>

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.mandatory_missing THEN
         validate_mandatory(cg$rec
                           ,'cg$NIT_CI_ATTRIBUTES.ins.mandatory_missing');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.check_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_check_con
                ,'cg$NIT_CI_ATTRIBUTES.ins.check_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.fk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_foreign_key
                ,'cg$NIT_CI_ATTRIBUTES.ins.fk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.uk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_unique_key
                ,'cg$NIT_CI_ATTRIBUTES.ins.uk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_ATTRIBUTES.ins.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END ins;

   --------------------------------------------------------------------------------
   -- Name:        upd
   --
   -- Description: API update procedure
   --
   -- Parameters:  cg$rec  Record of row to be updated
   --              cg$ind  Record of columns specifically set
   --              do_upd  Whether we want the actual UPDATE to occur
   --------------------------------------------------------------------------------
   PROCEDURE upd(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_upd IN BOOLEAN DEFAULT TRUE
                ,cg$pk  IN cg$row_type DEFAULT NULL) IS
      cg$upd_rec cg$row_type;
      cg$old_rec cg$row_type;
   BEGIN
      --  Application_logic Pre-Update <<Start>>
      BEGIN
         nit_ci_attributes_p.pre_dml(cg$rec
                                    ,cg$ind
                                    ,'UPD');
         nit_ci_attributes_p.pre_upd(cg$rec
                                    ,cg$ind);
      END;
      --  Application_logic Pre-Update << End >>

      IF (cg$pk.id IS NULL) THEN
         cg$upd_rec.id := cg$rec.id;
      ELSE
         cg$upd_rec.id := cg$pk.id;
      END IF;

      cg$old_rec.id := cg$upd_rec.id;

      IF (cg$pk.the_rowid IS NULL) THEN
         cg$upd_rec.the_rowid := cg$rec.the_rowid;
      ELSE
         cg$upd_rec.the_rowid := cg$pk.the_rowid;
      END IF;

      cg$old_rec.the_rowid := cg$upd_rec.the_rowid;

      IF (do_upd) THEN

         slct(cg$upd_rec);

         --  Report error if attempt to update non transferable Foreign Key NIT_CFK_CIA_CIP
         IF (cg$ind.cip_id AND cg$rec.cip_id != cg$upd_rec.cip_id) THEN
            raise_fk_not_transferable('NIT_CFK_CIA_CIP');
         END IF;
         IF (cg$ind.cip_id AND cg$rec.cip_id IS NULL AND
            cg$upd_rec.cip_id IS NOT NULL) THEN
            raise_fk_not_transferable('NIT_CFK_CIA_CIP');
         END IF;
         IF (cg$ind.cip_id AND cg$rec.cip_id IS NOT NULL AND
            cg$upd_rec.cip_id IS NULL) THEN
            raise_fk_not_transferable('NIT_CFK_CIA_CIP');
         END IF;
         --  Report error if attempt to update non transferable Foreign Key NIT_CFK_CIA_OPN
         IF (cg$ind.opn_id AND cg$rec.opn_id != cg$upd_rec.opn_id) THEN
            raise_fk_not_transferable('NIT_CFK_CIA_OPN');
         END IF;
         IF (cg$ind.opn_id AND cg$rec.opn_id IS NULL AND
            cg$upd_rec.opn_id IS NOT NULL) THEN
            raise_fk_not_transferable('NIT_CFK_CIA_OPN');
         END IF;
         IF (cg$ind.opn_id AND cg$rec.opn_id IS NOT NULL AND
            cg$upd_rec.opn_id IS NULL) THEN
            raise_fk_not_transferable('NIT_CFK_CIA_OPN');
         END IF;

         --  Report error if attempt to update non updateable Primary Key NIT_CPK_CIA
         IF (cg$ind.id AND cg$rec.id != cg$upd_rec.id) THEN
            raise_uk_not_updateable('NIT_CPK_CIA');
         END IF;

         IF NOT (cg$ind.id) THEN
            cg$rec.id := cg$upd_rec.id;
         END IF;
         IF NOT (cg$ind.creation_date) THEN
            cg$rec.creation_date := cg$upd_rec.creation_date;
         END IF;
         IF NOT (cg$ind.created_by) THEN
            cg$rec.created_by := cg$upd_rec.created_by;
         END IF;
         IF NOT (cg$ind.last_update_date) THEN
            cg$rec.last_update_date := cg$upd_rec.last_update_date;
         END IF;
         IF NOT (cg$ind.last_updated_by) THEN
            cg$rec.last_updated_by := cg$upd_rec.last_updated_by;
         END IF;
         IF NOT (cg$ind.ci_id) THEN
            cg$rec.ci_id := cg$upd_rec.ci_id;
         END IF;
         IF NOT (cg$ind.cip_id) THEN
            cg$rec.cip_id := cg$upd_rec.cip_id;
         END IF;
         IF NOT (cg$ind.opn_id) THEN
            cg$rec.opn_id := cg$upd_rec.opn_id;
         END IF;
         IF NOT (cg$ind.cipv_id) THEN
            cg$rec.cipv_id := cg$upd_rec.cipv_id;
         END IF;
         IF NOT (cg$ind.sms_id) THEN
            cg$rec.sms_id := cg$upd_rec.sms_id;
         END IF;
         IF NOT (cg$ind.status) THEN
            cg$rec.status := cg$upd_rec.status;
         END IF;
         IF NOT (cg$ind.obsolete) THEN
            cg$rec.obsolete := cg$upd_rec.obsolete;
         END IF;
         IF NOT (cg$ind.valid_from) THEN
            cg$rec.valid_from := cg$upd_rec.valid_from;
         END IF;
         IF NOT (cg$ind.valid_until) THEN
            cg$rec.valid_until := cg$upd_rec.valid_until;
         END IF;
         IF NOT (cg$ind.data) THEN
            cg$rec.data := cg$upd_rec.data;
         END IF;
         IF NOT (cg$ind.comments) THEN
            cg$rec.comments := cg$upd_rec.comments;
         END IF;
         IF NOT (cg$ind.last_refresh_date) THEN
            cg$rec.last_refresh_date := cg$upd_rec.last_refresh_date;
         END IF;
      ELSE
         -- Perform checks if called from a trigger
         -- Indicators are only set on changed values
         --  Report error if attempt to update non transferable Foreign Key NIT_CFK_CIA_CIP
         IF (cg$ind.cip_id) THEN
            raise_fk_not_transferable('NIT_CFK_CIA_CIP');
         END IF;
         --  Report error if attempt to update non transferable Foreign Key NIT_CFK_CIA_OPN
         IF (cg$ind.opn_id) THEN
            raise_fk_not_transferable('NIT_CFK_CIA_OPN');
         END IF;
         --  Report error if attempt to update non updateable Primary Key NIT_CPK_CIA
         IF (cg$ind.id) THEN
            raise_uk_not_updateable('NIT_CPK_CIA');
         END IF;
      END IF;

      up_autogen_columns(cg$rec
                        ,cg$ind
                        ,'UPD'
                        ,do_upd); --  Auto-generated and uppercased columns

      --  Now do update if updateable columns exist
      IF (do_upd) THEN
         DECLARE
            called_from BOOLEAN := called_from_package;
         BEGIN
            called_from_package := TRUE;

            slct(cg$old_rec);

            validate_domain(cg$rec
                           ,cg$ind);

            IF cg$rec.the_rowid IS NULL THEN
               UPDATE nit_ci_attributes
               SET    creation_date     = cg$rec.creation_date
                     ,created_by        = cg$rec.created_by
                     ,last_update_date  = cg$rec.last_update_date
                     ,last_updated_by   = cg$rec.last_updated_by
                     ,ci_id             = cg$rec.ci_id
                     ,cip_id            = cg$rec.cip_id
                     ,opn_id            = cg$rec.opn_id
                     ,cipv_id           = cg$rec.cipv_id
                     ,sms_id            = cg$rec.sms_id
                     ,status            = cg$rec.status
                     ,obsolete          = cg$rec.obsolete
                     ,valid_from        = cg$rec.valid_from
                     ,valid_until       = cg$rec.valid_until
                     ,data              = cg$rec.data
                     ,comments          = cg$rec.comments
                     ,last_refresh_date = cg$rec.last_refresh_date
               WHERE  id = cg$rec.id RETURNING id, creation_date, created_by,
                last_update_date, last_updated_by, ci_id, cip_id, opn_id,
                cipv_id, sms_id, status, obsolete, valid_from,
                valid_until, data, comments, last_refresh_date, ROWID INTO
                cg$rec.id, cg$rec.creation_date, cg$rec.created_by,
                cg$rec.last_update_date, cg$rec.last_updated_by,
                cg$rec.ci_id, cg$rec.cip_id, cg$rec.opn_id,
                cg$rec.cipv_id, cg$rec.sms_id, cg$rec.status,
                cg$rec.obsolete, cg$rec.valid_from, cg$rec.valid_until,
                cg$rec.data, cg$rec.comments, cg$rec.last_refresh_date,
                cg$rec.the_rowid;
            ELSE
               UPDATE nit_ci_attributes
               SET    creation_date     = cg$rec.creation_date
                     ,created_by        = cg$rec.created_by
                     ,last_update_date  = cg$rec.last_update_date
                     ,last_updated_by   = cg$rec.last_updated_by
                     ,ci_id             = cg$rec.ci_id
                     ,cip_id            = cg$rec.cip_id
                     ,opn_id            = cg$rec.opn_id
                     ,cipv_id           = cg$rec.cipv_id
                     ,sms_id            = cg$rec.sms_id
                     ,status            = cg$rec.status
                     ,obsolete          = cg$rec.obsolete
                     ,valid_from        = cg$rec.valid_from
                     ,valid_until       = cg$rec.valid_until
                     ,data              = cg$rec.data
                     ,comments          = cg$rec.comments
                     ,last_refresh_date = cg$rec.last_refresh_date
               WHERE  ROWID = cg$rec.the_rowid RETURNING id, creation_date,
                created_by, last_update_date, last_updated_by, ci_id,
                cip_id, opn_id, cipv_id, sms_id, status, obsolete,
                valid_from, valid_until, data, comments,
                last_refresh_date, ROWID INTO cg$rec.id,
                cg$rec.creation_date, cg$rec.created_by,
                cg$rec.last_update_date, cg$rec.last_updated_by,
                cg$rec.ci_id, cg$rec.cip_id, cg$rec.opn_id,
                cg$rec.cipv_id, cg$rec.sms_id, cg$rec.status,
                cg$rec.obsolete, cg$rec.valid_from, cg$rec.valid_until,
                cg$rec.data, cg$rec.comments, cg$rec.last_refresh_date,
                cg$rec.the_rowid;
            END IF;

            slct(cg$rec);

            called_from_package := called_from;
         END;
      END IF;

      IF NOT (do_upd) THEN
         cg$table(idx).id := cg$rec.id;
         cg$tableind(idx).id := cg$ind.id;
         cg$table(idx).creation_date := cg$rec.creation_date;
         cg$tableind(idx).creation_date := cg$ind.creation_date;
         cg$table(idx).created_by := cg$rec.created_by;
         cg$tableind(idx).created_by := cg$ind.created_by;
         cg$table(idx).last_update_date := cg$rec.last_update_date;
         cg$tableind(idx).last_update_date := cg$ind.last_update_date;
         cg$table(idx).last_updated_by := cg$rec.last_updated_by;
         cg$tableind(idx).last_updated_by := cg$ind.last_updated_by;
         cg$table(idx).ci_id := cg$rec.ci_id;
         cg$tableind(idx).ci_id := cg$ind.ci_id;
         cg$table(idx).cip_id := cg$rec.cip_id;
         cg$tableind(idx).cip_id := cg$ind.cip_id;
         cg$table(idx).opn_id := cg$rec.opn_id;
         cg$tableind(idx).opn_id := cg$ind.opn_id;
         cg$table(idx).cipv_id := cg$rec.cipv_id;
         cg$tableind(idx).cipv_id := cg$ind.cipv_id;
         cg$table(idx).sms_id := cg$rec.sms_id;
         cg$tableind(idx).sms_id := cg$ind.sms_id;
         cg$table(idx).status := cg$rec.status;
         cg$tableind(idx).status := cg$ind.status;
         cg$table(idx).obsolete := cg$rec.obsolete;
         cg$tableind(idx).obsolete := cg$ind.obsolete;
         cg$table(idx).valid_from := cg$rec.valid_from;
         cg$tableind(idx).valid_from := cg$ind.valid_from;
         cg$table(idx).valid_until := cg$rec.valid_until;
         cg$tableind(idx).valid_until := cg$ind.valid_until;
         cg$table(idx).data := cg$rec.data;
         cg$tableind(idx).data := cg$ind.data;
         cg$table(idx).comments := cg$rec.comments;
         cg$tableind(idx).comments := cg$ind.comments;
         cg$table(idx).last_refresh_date := cg$rec.last_refresh_date;
         cg$tableind(idx).last_refresh_date := cg$ind.last_refresh_date;
         idx := idx + 1;
      END IF;

      --  Application_logic Post-Update <<Start>>
      --  Application_logic Post-Update << End >>

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.upd_mandatory_null THEN
         validate_mandatory(cg$rec
                           ,'cg$NIT_CI_ATTRIBUTES.upd.upd_mandatory_null');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.check_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_check_con
                ,'cg$NIT_CI_ATTRIBUTES.upd.check_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.fk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_foreign_key
                ,'cg$NIT_CI_ATTRIBUTES.upd.fk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.uk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_unique_key
                ,'cg$NIT_CI_ATTRIBUTES.upd.uk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_ATTRIBUTES.upd.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END upd;

   --------------------------------------------------------------------------------
   -- Name:        del
   --
   -- Description: API delete procedure
   --
   -- Parameters:  cg$pk  Primary key record of row to be deleted
   --------------------------------------------------------------------------------
   PROCEDURE del(cg$pk  IN cg$pk_type
                ,do_del IN BOOLEAN DEFAULT TRUE) IS
   BEGIN
      --  Application_logic Pre-Delete <<Start>>
      BEGIN
         raise_application_error(-20001
                                ,'FIXME:?gy nem t?rl?nk.. ?rd ?t a k?dod.. Ezt az ?zenetet ki kell szedni ha ?les lesz a rendszer');
      END;
      --  Application_logic Pre-Delete << End >>

      --  Delete the record

      called_from_package := TRUE;

      IF (do_del) THEN
         DECLARE
            cg$rec cg$row_type;
         BEGIN
            cg$rec.id := cg$pk.id;
            slct(cg$rec);

            IF cg$pk.the_rowid IS NULL THEN
               DELETE nit_ci_attributes
               WHERE  id = cg$pk.id;
            ELSE
               DELETE nit_ci_attributes
               WHERE  ROWID = cg$pk.the_rowid;
            END IF;
         END;
      END IF;

      called_from_package := FALSE;

      --  Application_logic Post-Delete <<Start>>
      --  Application_logic Post-Delete << End >>

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.delete_restrict THEN
         err_msg(SQLERRM
                ,cg$errors.err_delete_restrict
                ,'cg$NIT_CI_ATTRIBUTES.del.delete_restrict');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN no_data_found THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_row_del
                                            ,cg$errors.row_del)
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_ATTRIBUTES.del.no_data_found');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_ATTRIBUTES.del.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END del;

   --------------------------------------------------------------------------------
   -- Name:        lck
   --
   -- Description: API lock procedure
   --
   -- Parameters:  cg$old_rec  Calling apps view of record of row to be locked
   --              cg$old_ind  Record of columns to raise error if modified
   --              nowait_flag TRUE lock with NOWAIT, FALSE don't fail if busy
   --------------------------------------------------------------------------------
   PROCEDURE lck(cg$old_rec  IN cg$row_type
                ,cg$old_ind  IN cg$ind_type
                ,nowait_flag IN BOOLEAN DEFAULT TRUE) IS
      cg$tmp_rec   cg$row_type;
      any_modified BOOLEAN := FALSE;

   BEGIN
      --  Application_logic Pre-Lock <<Start>>
      --  Application_logic Pre-Lock << End >>

      --  Do the row lock

      BEGIN
         IF (nowait_flag) THEN
            IF cg$old_rec.the_rowid IS NULL THEN
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,ci_id
                     ,cip_id
                     ,opn_id
                     ,cipv_id
                     ,sms_id
                     ,status
                     ,obsolete
                     ,valid_from
                     ,valid_until
                     ,data
                     ,comments
                     ,last_refresh_date
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.ci_id
                     ,cg$tmp_rec.cip_id
                     ,cg$tmp_rec.opn_id
                     ,cg$tmp_rec.cipv_id
                     ,cg$tmp_rec.sms_id
                     ,cg$tmp_rec.status
                     ,cg$tmp_rec.obsolete
                     ,cg$tmp_rec.valid_from
                     ,cg$tmp_rec.valid_until
                     ,cg$tmp_rec.data
                     ,cg$tmp_rec.comments
                     ,cg$tmp_rec.last_refresh_date
               FROM   nit_ci_attributes
               WHERE  id = cg$old_rec.id
               FOR    UPDATE NOWAIT;
            ELSE
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,ci_id
                     ,cip_id
                     ,opn_id
                     ,cipv_id
                     ,sms_id
                     ,status
                     ,obsolete
                     ,valid_from
                     ,valid_until
                     ,data
                     ,comments
                     ,last_refresh_date
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.ci_id
                     ,cg$tmp_rec.cip_id
                     ,cg$tmp_rec.opn_id
                     ,cg$tmp_rec.cipv_id
                     ,cg$tmp_rec.sms_id
                     ,cg$tmp_rec.status
                     ,cg$tmp_rec.obsolete
                     ,cg$tmp_rec.valid_from
                     ,cg$tmp_rec.valid_until
                     ,cg$tmp_rec.data
                     ,cg$tmp_rec.comments
                     ,cg$tmp_rec.last_refresh_date
               FROM   nit_ci_attributes
               WHERE  ROWID = cg$old_rec.the_rowid
               FOR    UPDATE NOWAIT;
            END IF;
         ELSE
            IF cg$old_rec.the_rowid IS NULL THEN
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,ci_id
                     ,cip_id
                     ,opn_id
                     ,cipv_id
                     ,sms_id
                     ,status
                     ,obsolete
                     ,valid_from
                     ,valid_until
                     ,data
                     ,comments
                     ,last_refresh_date
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.ci_id
                     ,cg$tmp_rec.cip_id
                     ,cg$tmp_rec.opn_id
                     ,cg$tmp_rec.cipv_id
                     ,cg$tmp_rec.sms_id
                     ,cg$tmp_rec.status
                     ,cg$tmp_rec.obsolete
                     ,cg$tmp_rec.valid_from
                     ,cg$tmp_rec.valid_until
                     ,cg$tmp_rec.data
                     ,cg$tmp_rec.comments
                     ,cg$tmp_rec.last_refresh_date
               FROM   nit_ci_attributes
               WHERE  id = cg$old_rec.id
               FOR    UPDATE;
            ELSE
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,ci_id
                     ,cip_id
                     ,opn_id
                     ,cipv_id
                     ,sms_id
                     ,status
                     ,obsolete
                     ,valid_from
                     ,valid_until
                     ,data
                     ,comments
                     ,last_refresh_date
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.ci_id
                     ,cg$tmp_rec.cip_id
                     ,cg$tmp_rec.opn_id
                     ,cg$tmp_rec.cipv_id
                     ,cg$tmp_rec.sms_id
                     ,cg$tmp_rec.status
                     ,cg$tmp_rec.obsolete
                     ,cg$tmp_rec.valid_from
                     ,cg$tmp_rec.valid_until
                     ,cg$tmp_rec.data
                     ,cg$tmp_rec.comments
                     ,cg$tmp_rec.last_refresh_date
               FROM   nit_ci_attributes
               WHERE  ROWID = cg$old_rec.the_rowid
               FOR    UPDATE;
            END IF;
         END IF;

      EXCEPTION
         WHEN cg$errors.cg$error THEN
            cg$errors.raise_failure;
         WHEN cg$errors.resource_busy THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_lck
                                               ,cg$errors.row_lck)
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_CI_ATTRIBUTES.lck.resource_busy');
            cg$errors.raise_failure;
         WHEN no_data_found THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_del
                                               ,cg$errors.row_del)
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_CI_ATTRIBUTES.lck.no_data_found');
            cg$errors.raise_failure;
         WHEN OTHERS THEN
            cg$errors.push(SQLERRM
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_CI_ATTRIBUTES.lck.others');
            cg$errors.raise_failure;
      END;

      -- Optional Columns

      IF (cg$old_ind.cipv_id) THEN
         IF (cg$tmp_rec.cipv_id IS NOT NULL AND cg$old_rec.cipv_id IS NOT NULL) THEN
            IF (cg$tmp_rec.cipv_id != cg$old_rec.cipv_id) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p60cipv_id)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_ATTRIBUTES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.cipv_id IS NOT NULL OR
               cg$old_rec.cipv_id IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p60cipv_id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_ATTRIBUTES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.sms_id) THEN
         IF (cg$tmp_rec.sms_id IS NOT NULL AND cg$old_rec.sms_id IS NOT NULL) THEN
            IF (cg$tmp_rec.sms_id != cg$old_rec.sms_id) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p62sms_id)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_ATTRIBUTES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.sms_id IS NOT NULL OR cg$old_rec.sms_id IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p62sms_id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_ATTRIBUTES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.comments) THEN
         IF (cg$tmp_rec.comments IS NOT NULL AND
            cg$old_rec.comments IS NOT NULL) THEN
            IF (cg$tmp_rec.comments != cg$old_rec.comments) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p145comments)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_ATTRIBUTES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.comments IS NOT NULL OR
               cg$old_rec.comments IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p145comments)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_ATTRIBUTES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.last_refresh_date) THEN
         IF (cg$tmp_rec.last_refresh_date IS NOT NULL AND
            cg$old_rec.last_refresh_date IS NOT NULL) THEN
            IF (cg$tmp_rec.last_refresh_date != cg$old_rec.last_refresh_date) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p155last_refresh_date)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_ATTRIBUTES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.last_refresh_date IS NOT NULL OR
               cg$old_rec.last_refresh_date IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p155last_refresh_date)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_ATTRIBUTES.lck');
            any_modified := TRUE;
         END IF;
      END IF;

      -- Mandatory Columns

      IF (cg$old_ind.id) THEN
         IF (cg$tmp_rec.id != cg$old_rec.id) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p5id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_ATTRIBUTES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.creation_date) THEN
         IF (cg$tmp_rec.creation_date != cg$old_rec.creation_date) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p10creation_date)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_ATTRIBUTES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.created_by) THEN
         IF (cg$tmp_rec.created_by != cg$old_rec.created_by) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p15created_by)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_ATTRIBUTES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.last_update_date) THEN
         IF (cg$tmp_rec.last_update_date != cg$old_rec.last_update_date) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p18last_update_date)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_ATTRIBUTES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.last_updated_by) THEN
         IF (cg$tmp_rec.last_updated_by != cg$old_rec.last_updated_by) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p19last_updated_by)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_ATTRIBUTES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.ci_id) THEN
         IF (cg$tmp_rec.ci_id != cg$old_rec.ci_id) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p25ci_id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_ATTRIBUTES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.cip_id) THEN
         IF (cg$tmp_rec.cip_id != cg$old_rec.cip_id) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p35cip_id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_ATTRIBUTES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.opn_id) THEN
         IF (cg$tmp_rec.opn_id != cg$old_rec.opn_id) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p55opn_id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_ATTRIBUTES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.status) THEN
         IF (cg$tmp_rec.status != cg$old_rec.status) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p65status)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_ATTRIBUTES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.obsolete) THEN
         IF (cg$tmp_rec.obsolete != cg$old_rec.obsolete) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p105obsolete)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_ATTRIBUTES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.valid_from) THEN
         IF (cg$tmp_rec.valid_from != cg$old_rec.valid_from) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p115valid_from)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_ATTRIBUTES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.valid_until) THEN
         IF (cg$tmp_rec.valid_until != cg$old_rec.valid_until) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p125valid_until)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_ATTRIBUTES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.data) THEN
         IF (cg$tmp_rec.data != cg$old_rec.data) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p135data)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_ATTRIBUTES.lck');
            any_modified := TRUE;
         END IF;
      END IF;

      IF (any_modified) THEN
         cg$errors.raise_failure;
      END IF;

      --  Application_logic Post-Lock <<Start>>
      --  Application_logic Post-Lock << End >>

   END lck;

BEGIN
   cg$ind_true.id                := TRUE;
   cg$ind_true.creation_date     := TRUE;
   cg$ind_true.created_by        := TRUE;
   cg$ind_true.last_update_date  := TRUE;
   cg$ind_true.last_updated_by   := TRUE;
   cg$ind_true.ci_id             := TRUE;
   cg$ind_true.cip_id            := TRUE;
   cg$ind_true.opn_id            := TRUE;
   cg$ind_true.cipv_id           := TRUE;
   cg$ind_true.sms_id            := TRUE;
   cg$ind_true.status            := TRUE;
   cg$ind_true.obsolete          := TRUE;
   cg$ind_true.valid_from        := TRUE;
   cg$ind_true.valid_until       := TRUE;
   cg$ind_true.data              := TRUE;
   cg$ind_true.comments          := TRUE;
   cg$ind_true.last_refresh_date := TRUE;

END cg$nit_ci_attributes;
/

prompt
prompt Creating package body CG$NIT_CI_PROPERTIES
prompt ==========================================
prompt
CREATE OR REPLACE PACKAGE BODY cg$nit_ci_properties IS

   PROCEDURE validate_mandatory(cg$val_rec IN cg$row_type
                               ,loc        IN VARCHAR2 DEFAULT '');
   PROCEDURE up_autogen_columns(cg$rec    IN OUT cg$row_type
                               ,cg$ind    IN OUT cg$ind_type
                               ,operation IN VARCHAR2 DEFAULT 'INS'
                               ,do_denorm IN BOOLEAN DEFAULT TRUE);
   PROCEDURE err_msg(msg  IN VARCHAR2
                    ,TYPE IN INTEGER
                    ,loc  IN VARCHAR2 DEFAULT '');

   --------------------------------------------------------------------------------
   -- Name:        raise_uk_not_updateable
   --
   -- Description: Raise appropriate error when unique key updated
   --
   -- Parameters:  none
   --------------------------------------------------------------------------------
   PROCEDURE raise_uk_not_updateable(uk IN VARCHAR2) IS
   BEGIN
      cg$errors.push(cg$errors.msggettext(cg$errors.api_unique_key_update
                                         ,cg$errors.err_uk_update
                                         ,uk)
                    ,'E'
                    ,'API'
                    ,cg$errors.api_unique_key_update
                    ,'cg$NIT_CI_PROPERTIES.raise_uk_not_updateable');
      cg$errors.raise_failure;
   END raise_uk_not_updateable;


   --------------------------------------------------------------------------------
   -- Name:        raise_fk_not_transferable
   --
   -- Description: Raise appropriate error when foreign key updated
   --
   -- Parameters:  none
   --------------------------------------------------------------------------------
   PROCEDURE raise_fk_not_transferable(fk IN VARCHAR2) IS
   BEGIN
      cg$errors.push(cg$errors.msggettext(cg$errors.api_foreign_key_trans
                                         ,cg$errors.err_fk_trans
                                         ,fk)
                    ,'E'
                    ,'API'
                    ,cg$errors.api_foreign_key_trans
                    ,'cg$NIT_CI_PROPERTIES.raise_fk_not_transferable');
      cg$errors.raise_failure;
   END raise_fk_not_transferable;


   --------------------------------------------------------------------------------
   -- Name:        up_autogen_columns
   --
   -- Description: Specific autogeneration of column values and conversion to
   --              uppercase
   --
   -- Parameters:  cg$rec    Record of row to be manipulated
   --              cg$ind    Indicators for row
   --              operation Procedure where this procedure was called
   --------------------------------------------------------------------------------
   PROCEDURE up_autogen_columns(cg$rec    IN OUT cg$row_type
                               ,cg$ind    IN OUT cg$ind_type
                               ,operation IN VARCHAR2 DEFAULT 'INS'
                               ,do_denorm IN BOOLEAN DEFAULT TRUE) IS
   BEGIN
      IF (operation = 'INS') THEN
         BEGIN
            IF (cg$ind.id = FALSE OR cg$rec.id IS NULL) THEN
               SELECT nit_seq.NEXTVAL
               INTO   cg$rec.id
               FROM   dual;
               cg$ind.id := TRUE;
            END IF;
         EXCEPTION
            WHEN OTHERS THEN
               cg$errors.push(SQLERRM
                             ,'E'
                             ,'ORA'
                             ,SQLCODE
                             ,'cg$NIT_CI_PROPERTIES.up_autogen.ID.OTHERS');
               cg$errors.raise_failure;
         END;
      ELSE
         -- (operation = 'UPD')
         NULL;
      END IF; -- (operation = 'INS') ELSE (operation = 'UPD')

      -- Statements executed for both 'INS' and 'UPD'

      cg$rec.required     := upper(cg$rec.required);
      cg$rec.set_like     := upper(cg$rec.set_like);
      cg$rec.is_inherited := upper(cg$rec.is_inherited);

   EXCEPTION
      WHEN no_data_found THEN
         NULL;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_PROPERTIES.up_autogen_columns');
         cg$errors.raise_failure;
   END up_autogen_columns;


   --------------------------------------------------------------------------------
   -- Name:        validate_mandatory
   --
   -- Description: Checks all mandatory columns are not null and raises appropriate
   --              error if not satisfied
   --
   -- Parameters:  cg$val_rec Record of row to be checked
   --              loc        Place where this procedure was called for error
   --                         trapping
   --------------------------------------------------------------------------------
   PROCEDURE validate_mandatory(cg$val_rec IN cg$row_type
                               ,loc        IN VARCHAR2 DEFAULT '') IS
   BEGIN
      IF (cg$val_rec.id IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p10id)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.creation_date IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p15creation_date)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.created_by IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p16created_by)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.last_update_date IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p19last_update_date)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.last_updated_by IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p20last_updated_by)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.cipt_id IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p26cipt_id)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.cit_id IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p36cit_id)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.required IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p76required)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.set_like IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p86set_like)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.is_inherited IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p91is_inherited)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.is_importable IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p96is_importable)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.order_in_list IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p106order_in_list)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.imp_auto_import IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p190imp_auto_import)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      NULL;
   END validate_mandatory;

   --------------------------------------------------------------------------------
   -- Name:        slct
   --
   -- Description: Selects into the given parameter all the attributes for the row
   --              given by the primary key
   --
   -- Parameters:  cg$sel_rec  Record of row to be selected into using its PK
   --------------------------------------------------------------------------------
   PROCEDURE slct(cg$sel_rec IN OUT cg$row_type) IS

   BEGIN

      IF cg$sel_rec.the_rowid IS NULL THEN
         SELECT id
               ,creation_date
               ,created_by
               ,last_update_date
               ,last_updated_by
               ,cipt_id
               ,cit_id
               ,cip_id_ancient
               ,cip_id
               ,required
               ,set_like
               ,is_inherited
               ,is_importable
               ,order_in_list
               ,description
               ,comments
               ,imp_source_module
               ,imp_source_name
               ,imp_auto_cipv
               ,imp_cascade_cip
               ,imp_cascade_cipv
               ,imp_auto_import
               ,ROWID
         INTO   cg$sel_rec.id
               ,cg$sel_rec.creation_date
               ,cg$sel_rec.created_by
               ,cg$sel_rec.last_update_date
               ,cg$sel_rec.last_updated_by
               ,cg$sel_rec.cipt_id
               ,cg$sel_rec.cit_id
               ,cg$sel_rec.cip_id_ancient
               ,cg$sel_rec.cip_id
               ,cg$sel_rec.required
               ,cg$sel_rec.set_like
               ,cg$sel_rec.is_inherited
               ,cg$sel_rec.is_importable
               ,cg$sel_rec.order_in_list
               ,cg$sel_rec.description
               ,cg$sel_rec.comments
               ,cg$sel_rec.imp_source_module
               ,cg$sel_rec.imp_source_name
               ,cg$sel_rec.imp_auto_cipv
               ,cg$sel_rec.imp_cascade_cip
               ,cg$sel_rec.imp_cascade_cipv
               ,cg$sel_rec.imp_auto_import
               ,cg$sel_rec.the_rowid
         FROM   nit_ci_properties
         WHERE  id = cg$sel_rec.id;
      ELSE
         SELECT id
               ,creation_date
               ,created_by
               ,last_update_date
               ,last_updated_by
               ,cipt_id
               ,cit_id
               ,cip_id_ancient
               ,cip_id
               ,required
               ,set_like
               ,is_inherited
               ,is_importable
               ,order_in_list
               ,description
               ,comments
               ,imp_source_module
               ,imp_source_name
               ,imp_auto_cipv
               ,imp_cascade_cip
               ,imp_cascade_cipv
               ,imp_auto_import
               ,ROWID
         INTO   cg$sel_rec.id
               ,cg$sel_rec.creation_date
               ,cg$sel_rec.created_by
               ,cg$sel_rec.last_update_date
               ,cg$sel_rec.last_updated_by
               ,cg$sel_rec.cipt_id
               ,cg$sel_rec.cit_id
               ,cg$sel_rec.cip_id_ancient
               ,cg$sel_rec.cip_id
               ,cg$sel_rec.required
               ,cg$sel_rec.set_like
               ,cg$sel_rec.is_inherited
               ,cg$sel_rec.is_importable
               ,cg$sel_rec.order_in_list
               ,cg$sel_rec.description
               ,cg$sel_rec.comments
               ,cg$sel_rec.imp_source_module
               ,cg$sel_rec.imp_source_name
               ,cg$sel_rec.imp_auto_cipv
               ,cg$sel_rec.imp_cascade_cip
               ,cg$sel_rec.imp_cascade_cipv
               ,cg$sel_rec.imp_auto_import
               ,cg$sel_rec.the_rowid
         FROM   nit_ci_properties
         WHERE  ROWID = cg$sel_rec.the_rowid;
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_PROPERTIES.slct.others');
         cg$errors.raise_failure;

   END slct;

   --------------------------------------------------------------------------------
   -- Name:        validate_domain
   --
   -- Description: Checks against reference table for values lying in a domain
   --
   -- Parameters:  cg$rec     Record of NIT_CI_PROPERTIES current values
   --------------------------------------------------------------------------------
   PROCEDURE validate_domain(cg$rec IN OUT cg$row_type
                            ,cg$ind IN cg$ind_type DEFAULT cg$ind_true) IS
      FOUND BOOLEAN;
      no_tabview EXCEPTION;
      PRAGMA EXCEPTION_INIT(no_tabview
                           ,-942);
   BEGIN

      FOUND := FALSE;
      IF (cg$ind.imp_source_module AND cg$rec.imp_source_module IS NOT NULL) THEN
         FOR c IN (SELECT rv_low_value
                         ,rv_high_value
                   FROM   cg_ref_codes
                   WHERE  rv_domain = 'IMP_SOURCE_MODULE_DOMAIN') LOOP
            IF (c.rv_high_value IS NULL AND
               cg$rec.imp_source_module = c.rv_low_value) OR
               (c.rv_high_value IS NOT NULL AND
               cg$rec.imp_source_module BETWEEN c.rv_low_value AND
               c.rv_high_value) THEN
               FOUND := TRUE;
               EXIT;
            END IF;
         END LOOP;

         IF (NOT FOUND) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_rv_lookup_fail
                                               ,cg$errors.apimsg_rv_lookup_fail
                                               ,cg$rec.imp_source_module
                                               ,'NIT_CI_PROPERTIES'
                                               ,'IMP_SOURCE_MODULE')
                          ,'E'
                          ,'API'
                          ,cg$errors.api_rv_lookup_fail
                          ,'cg$NIT_CI_PROPERTIES.v_domain.no_data_found');
            cg$errors.raise_failure;
         END IF;
      END IF;
   EXCEPTION
      WHEN cg$errors.cg$error THEN
         cg$errors.raise_failure;
      WHEN no_tabview THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_rv_tab_not_found
                                            ,cg$errors.apimsg_rv_tab_not_found
                                            ,'CG_REF_CODES'
                                            ,'NIT_CI_PROPERTIES')
                       ,'E'
                       ,'API'
                       ,cg$errors.api_rv_tab_not_found
                       ,'cg$NIT_CI_PROPERTIES.v_domain.no_reftable_found');
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_PROPERTIES.v_domain.others');
         cg$errors.raise_failure;
   END validate_domain;


   --------------------------------------------------------------------------------
   -- Name:        err_msg
   --
   -- Description: Pushes onto stack appropriate user defined error message
   --              depending on the rule violated
   --
   -- Parameters:  msg     Oracle error message
   --              type    Type of violation e.g. check_constraint: ERR_CHECK_CON
   --              loc     Place where this procedure was called for error
   --                      trapping
   --------------------------------------------------------------------------------
   PROCEDURE err_msg(msg  IN VARCHAR2
                    ,TYPE IN INTEGER
                    ,loc  IN VARCHAR2 DEFAULT '') IS
      con_name VARCHAR2(240);
   BEGIN
      con_name := cg$errors.parse_constraint(msg
                                            ,TYPE);
      IF (con_name = 'NITIL_CPK_CIP') THEN
         cg$errors.push(NVL(nitil_cpk_cip
                           ,cg$errors.msggettext(cg$errors.api_pk_con_violated
                                                ,cg$errors.apimsg_pk_violat
                                                ,'NITIL_CPK_CIP'
                                                ,'NIT_CI_PROPERTIES'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_pk_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CUK_CIP') THEN
         cg$errors.push(NVL(nit_cuk_cip
                           ,cg$errors.msggettext(cg$errors.api_uq_con_violated
                                                ,cg$errors.apimsg_uk_violat
                                                ,'NIT_CUK_CIP'
                                                ,'NIT_CI_PROPERTIES'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_uq_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CFK_CIP_CIP_ANCIENT' AND
            TYPE = cg$errors.err_delete_restrict) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_del_restrict
                                            ,cg$errors.err_del_restrict
                                            ,'NIT_CI_PROPERTIES'
                                            ,'NIT_CI_PROPERTIES')
                       ,'E'
                       ,'API'
                       ,cg$errors.api_del_restrict
                       ,loc);
      ELSIF (con_name = 'NIT_CFK_CIP_CIP' AND
            TYPE = cg$errors.err_delete_restrict) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_del_restrict
                                            ,cg$errors.err_del_restrict
                                            ,'NIT_CI_PROPERTIES'
                                            ,'NIT_CI_PROPERTIES')
                       ,'E'
                       ,'API'
                       ,cg$errors.api_del_restrict
                       ,loc);

      ELSIF (con_name = 'NIT_CFK_CIP_CIPT') THEN
         cg$errors.push(NVL(nit_cfk_cip_cipt
                           ,cg$errors.msggettext(cg$errors.api_fk_con_violated
                                                ,cg$errors.apimsg_fk_violat
                                                ,'NIT_CFK_CIP_CIPT'
                                                ,'NIT_CI_PROPERTIES'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_fk_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CFK_CIP_CIP') THEN
         cg$errors.push(NVL(nit_cfk_cip_cip
                           ,cg$errors.msggettext(cg$errors.api_fk_con_violated
                                                ,cg$errors.apimsg_fk_violat
                                                ,'NIT_CFK_CIP_CIP'
                                                ,'NIT_CI_PROPERTIES'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_fk_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CFK_CIP_CIT') THEN
         cg$errors.push(NVL(nit_cfk_cip_cit
                           ,cg$errors.msggettext(cg$errors.api_fk_con_violated
                                                ,cg$errors.apimsg_fk_violat
                                                ,'NIT_CFK_CIP_CIT'
                                                ,'NIT_CI_PROPERTIES'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_fk_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CFK_CIP_CIP_ANCIENT') THEN
         cg$errors.push(NVL(nit_cfk_cip_cip_ancient
                           ,cg$errors.msggettext(cg$errors.api_fk_con_violated
                                                ,cg$errors.apimsg_fk_violat
                                                ,'NIT_CFK_CIP_CIP_ANCIENT'
                                                ,'NIT_CI_PROPERTIES'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_fk_con_violated
                       ,loc);
      ELSE
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,loc);
      END IF;
   END err_msg;

   --------------------------------------------------------------------------------
   -- Name:        ins
   --
   -- Description: API insert procedure
   --
   -- Parameters:  cg$rec  Record of row to be inserted
   --              cg$ind  Record of columns specifically set
   --              do_ins  Whether we want the actual INSERT to occur
   --------------------------------------------------------------------------------
   PROCEDURE ins(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_ins IN BOOLEAN DEFAULT TRUE) IS

      --  Constant default values

      d76_required           CONSTANT nit_ci_properties.required%TYPE := 'N';
      d86_set_like           CONSTANT nit_ci_properties.set_like%TYPE := 'N';
      d91_is_inherited       CONSTANT nit_ci_properties.is_inherited%TYPE := 'N';
      d96_is_importable      CONSTANT nit_ci_properties.is_importable%TYPE := 'N';
      d106_order_in_list     CONSTANT nit_ci_properties.order_in_list%TYPE := 0;
      d140_imp_source_module CONSTANT nit_ci_properties.imp_source_module%TYPE := 'SMS';
      d160_imp_auto_cipv     CONSTANT nit_ci_properties.imp_auto_cipv%TYPE := 'N';
      d170_imp_cascade_cip   CONSTANT nit_ci_properties.imp_cascade_cip%TYPE := 'N';
      d180_imp_cascade_cipv  CONSTANT nit_ci_properties.imp_cascade_cipv%TYPE := 'N';
      d190_imp_auto_import   CONSTANT nit_ci_properties.imp_auto_import%TYPE := 'N';

   BEGIN
      nit_ci_properties_p.pre_dml(cg$rec
                                 ,cg$ind
                                 ,'INS');

      --  Defaulted

      IF NOT (cg$ind.required) THEN
         cg$rec.required := d76_required;
      END IF;
      IF NOT (cg$ind.set_like) THEN
         cg$rec.set_like := d86_set_like;
      END IF;
      IF NOT (cg$ind.is_inherited) THEN
         cg$rec.is_inherited := d91_is_inherited;
      END IF;
      IF NOT (cg$ind.is_importable) THEN
         cg$rec.is_importable := d96_is_importable;
      END IF;
      IF NOT (cg$ind.order_in_list) THEN
         cg$rec.order_in_list := d106_order_in_list;
      END IF;
      IF NOT (cg$ind.imp_source_module) THEN
         cg$rec.imp_source_module := d140_imp_source_module;
      END IF;
      IF NOT (cg$ind.imp_auto_cipv) THEN
         cg$rec.imp_auto_cipv := d160_imp_auto_cipv;
      END IF;
      IF NOT (cg$ind.imp_cascade_cip) THEN
         cg$rec.imp_cascade_cip := d170_imp_cascade_cip;
      END IF;
      IF NOT (cg$ind.imp_cascade_cipv) THEN
         cg$rec.imp_cascade_cipv := d180_imp_cascade_cipv;
      END IF;
      IF NOT (cg$ind.imp_auto_import) THEN
         cg$rec.imp_auto_import := d190_imp_auto_import;
      END IF;
      --  Auto-generated and uppercased columns

      up_autogen_columns(cg$rec
                        ,cg$ind
                        ,'INS'
                        ,do_ins);

      called_from_package := TRUE;

      IF (do_ins) THEN
         validate_domain(cg$rec);

         INSERT INTO nit_ci_properties
            (id
            ,creation_date
            ,created_by
            ,last_update_date
            ,last_updated_by
            ,cipt_id
            ,cit_id
            ,cip_id_ancient
            ,cip_id
            ,required
            ,set_like
            ,is_inherited
            ,is_importable
            ,order_in_list
            ,description
            ,comments
            ,imp_source_module
            ,imp_source_name
            ,imp_auto_cipv
            ,imp_cascade_cip
            ,imp_cascade_cipv
            ,imp_auto_import)
         VALUES
            (cg$rec.id
            ,cg$rec.creation_date
            ,cg$rec.created_by
            ,cg$rec.last_update_date
            ,cg$rec.last_updated_by
            ,cg$rec.cipt_id
            ,cg$rec.cit_id
            ,cg$rec.cip_id_ancient
            ,cg$rec.cip_id
            ,cg$rec.required
            ,cg$rec.set_like
            ,cg$rec.is_inherited
            ,cg$rec.is_importable
            ,cg$rec.order_in_list
            ,cg$rec.description
            ,cg$rec.comments
            ,cg$rec.imp_source_module
            ,cg$rec.imp_source_name
            ,cg$rec.imp_auto_cipv
            ,cg$rec.imp_cascade_cip
            ,cg$rec.imp_cascade_cipv
            ,cg$rec.imp_auto_import)
         RETURNING id, creation_date, created_by, last_update_date, last_updated_by, cipt_id, cit_id, cip_id_ancient, cip_id, required, set_like, is_inherited, is_importable, order_in_list, description, comments, imp_source_module, imp_source_name, imp_auto_cipv, imp_cascade_cip, imp_cascade_cipv, imp_auto_import, ROWID INTO cg$rec.id, cg$rec.creation_date, cg$rec.created_by, cg$rec.last_update_date, cg$rec.last_updated_by, cg$rec.cipt_id, cg$rec.cit_id, cg$rec.cip_id_ancient, cg$rec.cip_id, cg$rec.required, cg$rec.set_like, cg$rec.is_inherited, cg$rec.is_importable, cg$rec.order_in_list, cg$rec.description, cg$rec.comments, cg$rec.imp_source_module, cg$rec.imp_source_name, cg$rec.imp_auto_cipv, cg$rec.imp_cascade_cip, cg$rec.imp_cascade_cipv, cg$rec.imp_auto_import, cg$rec.the_rowid;
      END IF;

      called_from_package := FALSE;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.mandatory_missing THEN
         validate_mandatory(cg$rec
                           ,'cg$NIT_CI_PROPERTIES.ins.mandatory_missing');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.check_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_check_con
                ,'cg$NIT_CI_PROPERTIES.ins.check_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.fk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_foreign_key
                ,'cg$NIT_CI_PROPERTIES.ins.fk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.uk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_unique_key
                ,'cg$NIT_CI_PROPERTIES.ins.uk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_PROPERTIES.ins.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END ins;


   --------------------------------------------------------------------------------
   -- Name:        upd
   --
   -- Description: API update procedure
   --
   -- Parameters:  cg$rec  Record of row to be updated
   --              cg$ind  Record of columns specifically set
   --              do_upd  Whether we want the actual UPDATE to occur
   --------------------------------------------------------------------------------
   PROCEDURE upd(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_upd IN BOOLEAN DEFAULT TRUE
                ,cg$pk  IN cg$row_type DEFAULT NULL) IS
      cg$upd_rec cg$row_type;
      cg$old_rec cg$row_type;
   BEGIN
      --  Application_logic Pre-Update <<Start>>
      BEGIN
         nit_ci_properties_p.pre_dml(cg$rec
                                    ,cg$ind
                                    ,'UPD');
         nit_ci_properties_p.pre_upd(cg$rec
                                    ,cg$ind);
      END;
      --  Application_logic Pre-Update << End >>


      IF (cg$pk.id IS NULL) THEN
         cg$upd_rec.id := cg$rec.id;
      ELSE
         cg$upd_rec.id := cg$pk.id;
      END IF;
      cg$old_rec.id := cg$upd_rec.id;

      IF (cg$pk.the_rowid IS NULL) THEN
         cg$upd_rec.the_rowid := cg$rec.the_rowid;
      ELSE
         cg$upd_rec.the_rowid := cg$pk.the_rowid;
      END IF;
      cg$old_rec.the_rowid := cg$upd_rec.the_rowid;

      IF (do_upd) THEN

         slct(cg$upd_rec);

         --  Report error if attempt to update non transferable Foreign Key NIT_CFK_CIP_CIPT
         IF (cg$ind.cipt_id AND cg$rec.cipt_id != cg$upd_rec.cipt_id) THEN
            raise_fk_not_transferable('NIT_CFK_CIP_CIPT');
         END IF;
         IF (cg$ind.cipt_id AND cg$rec.cipt_id IS NULL AND
            cg$upd_rec.cipt_id IS NOT NULL) THEN
            raise_fk_not_transferable('NIT_CFK_CIP_CIPT');
         END IF;
         IF (cg$ind.cipt_id AND cg$rec.cipt_id IS NOT NULL AND
            cg$upd_rec.cipt_id IS NULL) THEN
            raise_fk_not_transferable('NIT_CFK_CIP_CIPT');
         END IF;
         --  Report error if attempt to update non transferable Foreign Key NIT_CFK_CIP_CIT
         IF (cg$ind.cit_id AND cg$rec.cit_id != cg$upd_rec.cit_id) THEN
            raise_fk_not_transferable('NIT_CFK_CIP_CIT');
         END IF;
         IF (cg$ind.cit_id AND cg$rec.cit_id IS NULL AND
            cg$upd_rec.cit_id IS NOT NULL) THEN
            raise_fk_not_transferable('NIT_CFK_CIP_CIT');
         END IF;
         IF (cg$ind.cit_id AND cg$rec.cit_id IS NOT NULL AND
            cg$upd_rec.cit_id IS NULL) THEN
            raise_fk_not_transferable('NIT_CFK_CIP_CIT');
         END IF;

         --  Report error if attempt to update non updateable Primary Key NITIL_CPK_CIP
         IF (cg$ind.id AND cg$rec.id != cg$upd_rec.id) THEN
            raise_uk_not_updateable('NITIL_CPK_CIP');
         END IF;
         IF NOT (cg$ind.id) THEN
            cg$rec.id := cg$upd_rec.id;
         END IF;
         IF NOT (cg$ind.creation_date) THEN
            cg$rec.creation_date := cg$upd_rec.creation_date;
         END IF;
         IF NOT (cg$ind.created_by) THEN
            cg$rec.created_by := cg$upd_rec.created_by;
         END IF;
         IF NOT (cg$ind.last_update_date) THEN
            cg$rec.last_update_date := cg$upd_rec.last_update_date;
         END IF;
         IF NOT (cg$ind.last_updated_by) THEN
            cg$rec.last_updated_by := cg$upd_rec.last_updated_by;
         END IF;
         IF NOT (cg$ind.cipt_id) THEN
            cg$rec.cipt_id := cg$upd_rec.cipt_id;
         END IF;
         IF NOT (cg$ind.cit_id) THEN
            cg$rec.cit_id := cg$upd_rec.cit_id;
         END IF;
         IF NOT (cg$ind.cip_id_ancient) THEN
            cg$rec.cip_id_ancient := cg$upd_rec.cip_id_ancient;
         END IF;
         IF NOT (cg$ind.cip_id) THEN
            cg$rec.cip_id := cg$upd_rec.cip_id;
         END IF;
         IF NOT (cg$ind.required) THEN
            cg$rec.required := cg$upd_rec.required;
         END IF;
         IF NOT (cg$ind.set_like) THEN
            cg$rec.set_like := cg$upd_rec.set_like;
         END IF;
         IF NOT (cg$ind.is_inherited) THEN
            cg$rec.is_inherited := cg$upd_rec.is_inherited;
         END IF;
         IF NOT (cg$ind.is_importable) THEN
            cg$rec.is_importable := cg$upd_rec.is_importable;
         END IF;
         IF NOT (cg$ind.order_in_list) THEN
            cg$rec.order_in_list := cg$upd_rec.order_in_list;
         END IF;
         IF NOT (cg$ind.description) THEN
            cg$rec.description := cg$upd_rec.description;
         END IF;
         IF NOT (cg$ind.comments) THEN
            cg$rec.comments := cg$upd_rec.comments;
         END IF;
         IF NOT (cg$ind.imp_source_module) THEN
            cg$rec.imp_source_module := cg$upd_rec.imp_source_module;
         END IF;
         IF NOT (cg$ind.imp_source_name) THEN
            cg$rec.imp_source_name := cg$upd_rec.imp_source_name;
         END IF;
         IF NOT (cg$ind.imp_auto_cipv) THEN
            cg$rec.imp_auto_cipv := cg$upd_rec.imp_auto_cipv;
         END IF;
         IF NOT (cg$ind.imp_cascade_cip) THEN
            cg$rec.imp_cascade_cip := cg$upd_rec.imp_cascade_cip;
         END IF;
         IF NOT (cg$ind.imp_cascade_cipv) THEN
            cg$rec.imp_cascade_cipv := cg$upd_rec.imp_cascade_cipv;
         END IF;
         IF NOT (cg$ind.imp_auto_import) THEN
            cg$rec.imp_auto_import := cg$upd_rec.imp_auto_import;
         END IF;
      ELSE
         -- Perform checks if called from a trigger
         -- Indicators are only set on changed values
         --  Report error if attempt to update non transferable Foreign Key NIT_CFK_CIP_CIPT
         IF (cg$ind.cipt_id) THEN
            raise_fk_not_transferable('NIT_CFK_CIP_CIPT');
         END IF;
         --  Report error if attempt to update non transferable Foreign Key NIT_CFK_CIP_CIT
         IF (cg$ind.cit_id) THEN
            raise_fk_not_transferable('NIT_CFK_CIP_CIT');
         END IF;
         --  Report error if attempt to update non updateable Primary Key NITIL_CPK_CIP
         IF (cg$ind.id) THEN
            raise_uk_not_updateable('NITIL_CPK_CIP');
         END IF;
      END IF;

      up_autogen_columns(cg$rec
                        ,cg$ind
                        ,'UPD'
                        ,do_upd); --  Auto-generated and uppercased columns

      --  Now do update if updateable columns exist
      IF (do_upd) THEN
         DECLARE
            called_from BOOLEAN := called_from_package;
         BEGIN
            called_from_package := TRUE;

            slct(cg$old_rec);
            validate_domain(cg$rec
                           ,cg$ind);

            IF cg$rec.the_rowid IS NULL THEN
               UPDATE nit_ci_properties
               SET    creation_date     = cg$rec.creation_date
                     ,created_by        = cg$rec.created_by
                     ,last_update_date  = cg$rec.last_update_date
                     ,last_updated_by   = cg$rec.last_updated_by
                     ,cipt_id           = cg$rec.cipt_id
                     ,cit_id            = cg$rec.cit_id
                     ,cip_id_ancient    = cg$rec.cip_id_ancient
                     ,cip_id            = cg$rec.cip_id
                     ,required          = cg$rec.required
                     ,set_like          = cg$rec.set_like
                     ,is_inherited      = cg$rec.is_inherited
                     ,is_importable     = cg$rec.is_importable
                     ,order_in_list     = cg$rec.order_in_list
                     ,description       = cg$rec.description
                     ,comments          = cg$rec.comments
                     ,imp_source_module = cg$rec.imp_source_module
                     ,imp_source_name   = cg$rec.imp_source_name
                     ,imp_auto_cipv     = cg$rec.imp_auto_cipv
                     ,imp_cascade_cip   = cg$rec.imp_cascade_cip
                     ,imp_cascade_cipv  = cg$rec.imp_cascade_cipv
                     ,imp_auto_import   = cg$rec.imp_auto_import
               WHERE  id = cg$rec.id RETURNING id, creation_date, created_by,
                last_update_date, last_updated_by, cipt_id, cit_id,
                cip_id_ancient, cip_id, required, set_like, is_inherited,
                is_importable, order_in_list, description, comments,
                imp_source_module, imp_source_name, imp_auto_cipv,
                imp_cascade_cip, imp_cascade_cipv, imp_auto_import, ROWID

                INTO cg$rec.id, cg$rec.creation_date, cg$rec.created_by,
                cg$rec.last_update_date, cg$rec.last_updated_by,
                cg$rec.cipt_id, cg$rec.cit_id, cg$rec.cip_id_ancient,
                cg$rec.cip_id, cg$rec.required, cg$rec.set_like,
                cg$rec.is_inherited, cg$rec.is_importable,
                cg$rec.order_in_list, cg$rec.description, cg$rec.comments,
                cg$rec.imp_source_module, cg$rec.imp_source_name,
                cg$rec.imp_auto_cipv, cg$rec.imp_cascade_cip,
                cg$rec.imp_cascade_cipv, cg$rec.imp_auto_import,
                cg$rec.the_rowid;


            ELSE
               UPDATE nit_ci_properties
               SET    creation_date     = cg$rec.creation_date
                     ,created_by        = cg$rec.created_by
                     ,last_update_date  = cg$rec.last_update_date
                     ,last_updated_by   = cg$rec.last_updated_by
                     ,cipt_id           = cg$rec.cipt_id
                     ,cit_id            = cg$rec.cit_id
                     ,cip_id_ancient    = cg$rec.cip_id_ancient
                     ,cip_id            = cg$rec.cip_id
                     ,required          = cg$rec.required
                     ,set_like          = cg$rec.set_like
                     ,is_inherited      = cg$rec.is_inherited
                     ,is_importable     = cg$rec.is_importable
                     ,order_in_list     = cg$rec.order_in_list
                     ,description       = cg$rec.description
                     ,comments          = cg$rec.comments
                     ,imp_source_module = cg$rec.imp_source_module
                     ,imp_source_name   = cg$rec.imp_source_name
                     ,imp_auto_cipv     = cg$rec.imp_auto_cipv
                     ,imp_cascade_cip   = cg$rec.imp_cascade_cip
                     ,imp_cascade_cipv  = cg$rec.imp_cascade_cipv
                     ,imp_auto_import   = cg$rec.imp_auto_import
               WHERE  ROWID = cg$rec.the_rowid RETURNING id, creation_date,
                created_by, last_update_date, last_updated_by, cipt_id,
                cit_id, cip_id_ancient, cip_id, required, set_like,
                is_inherited, is_importable, order_in_list, description,
                comments, imp_source_module, imp_source_name,
                imp_auto_cipv, imp_cascade_cip, imp_cascade_cipv,
                imp_auto_import, ROWID

                INTO cg$rec.id, cg$rec.creation_date, cg$rec.created_by,
                cg$rec.last_update_date, cg$rec.last_updated_by,
                cg$rec.cipt_id, cg$rec.cit_id, cg$rec.cip_id_ancient,
                cg$rec.cip_id, cg$rec.required, cg$rec.set_like,
                cg$rec.is_inherited, cg$rec.is_importable,
                cg$rec.order_in_list, cg$rec.description, cg$rec.comments,
                cg$rec.imp_source_module, cg$rec.imp_source_name,
                cg$rec.imp_auto_cipv, cg$rec.imp_cascade_cip,
                cg$rec.imp_cascade_cipv, cg$rec.imp_auto_import,
                cg$rec.the_rowid;

            END IF;

            called_from_package := called_from;
         END;
      END IF;



      IF NOT (do_upd) THEN
         cg$table(idx).id := cg$rec.id;
         cg$tableind(idx).id := cg$ind.id;
         cg$table(idx).creation_date := cg$rec.creation_date;
         cg$tableind(idx).creation_date := cg$ind.creation_date;
         cg$table(idx).created_by := cg$rec.created_by;
         cg$tableind(idx).created_by := cg$ind.created_by;
         cg$table(idx).last_update_date := cg$rec.last_update_date;
         cg$tableind(idx).last_update_date := cg$ind.last_update_date;
         cg$table(idx).last_updated_by := cg$rec.last_updated_by;
         cg$tableind(idx).last_updated_by := cg$ind.last_updated_by;
         cg$table(idx).cipt_id := cg$rec.cipt_id;
         cg$tableind(idx).cipt_id := cg$ind.cipt_id;
         cg$table(idx).cit_id := cg$rec.cit_id;
         cg$tableind(idx).cit_id := cg$ind.cit_id;
         cg$table(idx).cip_id_ancient := cg$rec.cip_id_ancient;
         cg$tableind(idx).cip_id_ancient := cg$ind.cip_id_ancient;
         cg$table(idx).cip_id := cg$rec.cip_id;
         cg$tableind(idx).cip_id := cg$ind.cip_id;
         cg$table(idx).required := cg$rec.required;
         cg$tableind(idx).required := cg$ind.required;
         cg$table(idx).set_like := cg$rec.set_like;
         cg$tableind(idx).set_like := cg$ind.set_like;
         cg$table(idx).is_inherited := cg$rec.is_inherited;
         cg$tableind(idx).is_inherited := cg$ind.is_inherited;
         cg$table(idx).is_importable := cg$rec.is_importable;
         cg$tableind(idx).is_importable := cg$ind.is_importable;
         cg$table(idx).order_in_list := cg$rec.order_in_list;
         cg$tableind(idx).order_in_list := cg$ind.order_in_list;
         cg$table(idx).description := cg$rec.description;
         cg$tableind(idx).description := cg$ind.description;
         cg$table(idx).comments := cg$rec.comments;
         cg$tableind(idx).comments := cg$ind.comments;
         cg$table(idx).imp_source_module := cg$rec.imp_source_module;
         cg$tableind(idx).imp_source_module := cg$ind.imp_source_module;
         cg$table(idx).imp_source_name := cg$rec.imp_source_name;
         cg$tableind(idx).imp_source_name := cg$ind.imp_source_name;
         cg$table(idx).imp_auto_cipv := cg$rec.imp_auto_cipv;
         cg$tableind(idx).imp_auto_cipv := cg$ind.imp_auto_cipv;
         cg$table(idx).imp_cascade_cip := cg$rec.imp_cascade_cip;
         cg$tableind(idx).imp_cascade_cip := cg$ind.imp_cascade_cip;
         cg$table(idx).imp_cascade_cipv := cg$rec.imp_cascade_cipv;
         cg$tableind(idx).imp_cascade_cipv := cg$ind.imp_cascade_cipv;
         cg$table(idx).imp_auto_import := cg$rec.imp_auto_import;
         cg$tableind(idx).imp_auto_import := cg$ind.imp_auto_import;
         idx := idx + 1;
      END IF;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.upd_mandatory_null THEN
         validate_mandatory(cg$rec
                           ,'cg$NIT_CI_PROPERTIES.upd.upd_mandatory_null');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.check_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_check_con
                ,'cg$NIT_CI_PROPERTIES.upd.check_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.fk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_foreign_key
                ,'cg$NIT_CI_PROPERTIES.upd.fk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.uk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_unique_key
                ,'cg$NIT_CI_PROPERTIES.upd.uk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_PROPERTIES.upd.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END upd;

   --------------------------------------------------------------------------------
   -- Name:        del
   --
   -- Description: API delete procedure
   --
   -- Parameters:  cg$pk  Primary key record of row to be deleted
   --------------------------------------------------------------------------------
   PROCEDURE del(cg$pk  IN cg$pk_type
                ,do_del IN BOOLEAN DEFAULT TRUE) IS
   BEGIN
      nit_ci_properties_p.pre_del(cg$pk.id);

      --  Delete the record

      called_from_package := TRUE;

      IF (do_del) THEN
         BEGIN
            IF cg$pk.the_rowid IS NULL THEN
               DELETE nit_ci_properties
               WHERE  id = cg$pk.id;
            ELSE
               DELETE nit_ci_properties
               WHERE  ROWID = cg$pk.the_rowid;
            END IF;

         END;
      END IF;

      called_from_package := FALSE;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.delete_restrict THEN
         err_msg(SQLERRM
                ,cg$errors.err_delete_restrict
                ,'cg$NIT_CI_PROPERTIES.del.delete_restrict');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN no_data_found THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_row_del
                                            ,cg$errors.row_del)
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_PROPERTIES.del.no_data_found');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_PROPERTIES.del.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END del;


   --------------------------------------------------------------------------------
   -- Name:        lck
   --
   -- Description: API lock procedure
   --
   -- Parameters:  cg$old_rec  Calling apps view of record of row to be locked
   --              cg$old_ind  Record of columns to raise error if modified
   --              nowait_flag TRUE lock with NOWAIT, FALSE don't fail if busy
   --------------------------------------------------------------------------------
   PROCEDURE lck(cg$old_rec  IN cg$row_type
                ,cg$old_ind  IN cg$ind_type
                ,nowait_flag IN BOOLEAN DEFAULT TRUE) IS
      cg$tmp_rec   cg$row_type;
      any_modified BOOLEAN := FALSE;

   BEGIN
      --  Application_logic Pre-Lock <<Start>>
      --  Application_logic Pre-Lock << End >>

      --  Do the row lock

      BEGIN
         IF (nowait_flag) THEN
            IF cg$old_rec.the_rowid IS NULL THEN
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,cipt_id
                     ,cit_id
                     ,cip_id_ancient
                     ,cip_id
                     ,required
                     ,set_like
                     ,is_inherited
                     ,is_importable
                     ,order_in_list
                     ,description
                     ,comments
                     ,imp_source_module
                     ,imp_source_name
                     ,imp_auto_cipv
                     ,imp_cascade_cip
                     ,imp_cascade_cipv
                     ,imp_auto_import
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.cipt_id
                     ,cg$tmp_rec.cit_id
                     ,cg$tmp_rec.cip_id_ancient
                     ,cg$tmp_rec.cip_id
                     ,cg$tmp_rec.required
                     ,cg$tmp_rec.set_like
                     ,cg$tmp_rec.is_inherited
                     ,cg$tmp_rec.is_importable
                     ,cg$tmp_rec.order_in_list
                     ,cg$tmp_rec.description
                     ,cg$tmp_rec.comments
                     ,cg$tmp_rec.imp_source_module
                     ,cg$tmp_rec.imp_source_name
                     ,cg$tmp_rec.imp_auto_cipv
                     ,cg$tmp_rec.imp_cascade_cip
                     ,cg$tmp_rec.imp_cascade_cipv
                     ,cg$tmp_rec.imp_auto_import
               FROM   nit_ci_properties
               WHERE  id = cg$old_rec.id
               FOR    UPDATE NOWAIT;
            ELSE
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,cipt_id
                     ,cit_id
                     ,cip_id_ancient
                     ,cip_id
                     ,required
                     ,set_like
                     ,is_inherited
                     ,is_importable
                     ,order_in_list
                     ,description
                     ,comments
                     ,imp_source_module
                     ,imp_source_name
                     ,imp_auto_cipv
                     ,imp_cascade_cip
                     ,imp_cascade_cipv
                     ,imp_auto_import
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.cipt_id
                     ,cg$tmp_rec.cit_id
                     ,cg$tmp_rec.cip_id_ancient
                     ,cg$tmp_rec.cip_id
                     ,cg$tmp_rec.required
                     ,cg$tmp_rec.set_like
                     ,cg$tmp_rec.is_inherited
                     ,cg$tmp_rec.is_importable
                     ,cg$tmp_rec.order_in_list
                     ,cg$tmp_rec.description
                     ,cg$tmp_rec.comments
                     ,cg$tmp_rec.imp_source_module
                     ,cg$tmp_rec.imp_source_name
                     ,cg$tmp_rec.imp_auto_cipv
                     ,cg$tmp_rec.imp_cascade_cip
                     ,cg$tmp_rec.imp_cascade_cipv
                     ,cg$tmp_rec.imp_auto_import
               FROM   nit_ci_properties
               WHERE  ROWID = cg$old_rec.the_rowid
               FOR    UPDATE NOWAIT;
            END IF;
         ELSE
            IF cg$old_rec.the_rowid IS NULL THEN
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,cipt_id
                     ,cit_id
                     ,cip_id_ancient
                     ,cip_id
                     ,required
                     ,set_like
                     ,is_inherited
                     ,is_importable
                     ,order_in_list
                     ,description
                     ,comments
                     ,imp_source_module
                     ,imp_source_name
                     ,imp_auto_cipv
                     ,imp_cascade_cip
                     ,imp_cascade_cipv
                     ,imp_auto_import
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.cipt_id
                     ,cg$tmp_rec.cit_id
                     ,cg$tmp_rec.cip_id_ancient
                     ,cg$tmp_rec.cip_id
                     ,cg$tmp_rec.required
                     ,cg$tmp_rec.set_like
                     ,cg$tmp_rec.is_inherited
                     ,cg$tmp_rec.is_importable
                     ,cg$tmp_rec.order_in_list
                     ,cg$tmp_rec.description
                     ,cg$tmp_rec.comments
                     ,cg$tmp_rec.imp_source_module
                     ,cg$tmp_rec.imp_source_name
                     ,cg$tmp_rec.imp_auto_cipv
                     ,cg$tmp_rec.imp_cascade_cip
                     ,cg$tmp_rec.imp_cascade_cipv
                     ,cg$tmp_rec.imp_auto_import
               FROM   nit_ci_properties
               WHERE  id = cg$old_rec.id
               FOR    UPDATE;
            ELSE
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,cipt_id
                     ,cit_id
                     ,cip_id_ancient
                     ,cip_id
                     ,required
                     ,set_like
                     ,is_inherited
                     ,is_importable
                     ,order_in_list
                     ,description
                     ,comments
                     ,imp_source_module
                     ,imp_source_name
                     ,imp_auto_cipv
                     ,imp_cascade_cip
                     ,imp_cascade_cipv
                     ,imp_auto_import
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.cipt_id
                     ,cg$tmp_rec.cit_id
                     ,cg$tmp_rec.cip_id_ancient
                     ,cg$tmp_rec.cip_id
                     ,cg$tmp_rec.required
                     ,cg$tmp_rec.set_like
                     ,cg$tmp_rec.is_inherited
                     ,cg$tmp_rec.is_importable
                     ,cg$tmp_rec.order_in_list
                     ,cg$tmp_rec.description
                     ,cg$tmp_rec.comments
                     ,cg$tmp_rec.imp_source_module
                     ,cg$tmp_rec.imp_source_name
                     ,cg$tmp_rec.imp_auto_cipv
                     ,cg$tmp_rec.imp_cascade_cip
                     ,cg$tmp_rec.imp_cascade_cipv
                     ,cg$tmp_rec.imp_auto_import
               FROM   nit_ci_properties
               WHERE  ROWID = cg$old_rec.the_rowid
               FOR    UPDATE;
            END IF;
         END IF;

      EXCEPTION
         WHEN cg$errors.cg$error THEN
            cg$errors.raise_failure;
         WHEN cg$errors.resource_busy THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_lck
                                               ,cg$errors.row_lck)
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_CI_PROPERTIES.lck.resource_busy');
            cg$errors.raise_failure;
         WHEN no_data_found THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_del
                                               ,cg$errors.row_del)
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_CI_PROPERTIES.lck.no_data_found');
            cg$errors.raise_failure;
         WHEN OTHERS THEN
            cg$errors.push(SQLERRM
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_CI_PROPERTIES.lck.others');
            cg$errors.raise_failure;
      END;

      -- Optional Columns

      IF (cg$old_ind.cip_id_ancient) THEN
         IF (cg$tmp_rec.cip_id_ancient IS NOT NULL AND
            cg$old_rec.cip_id_ancient IS NOT NULL) THEN
            IF (cg$tmp_rec.cip_id_ancient != cg$old_rec.cip_id_ancient) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p46cip_id_ancient)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_PROPERTIES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.cip_id_ancient IS NOT NULL OR
               cg$old_rec.cip_id_ancient IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p46cip_id_ancient)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTIES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.cip_id) THEN
         IF (cg$tmp_rec.cip_id IS NOT NULL AND cg$old_rec.cip_id IS NOT NULL) THEN
            IF (cg$tmp_rec.cip_id != cg$old_rec.cip_id) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p56cip_id)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_PROPERTIES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.cip_id IS NOT NULL OR cg$old_rec.cip_id IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p56cip_id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTIES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.description) THEN
         IF (cg$tmp_rec.description IS NOT NULL AND
            cg$old_rec.description IS NOT NULL) THEN
            IF (cg$tmp_rec.description != cg$old_rec.description) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p116description)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_PROPERTIES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.description IS NOT NULL OR
               cg$old_rec.description IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p116description)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTIES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.comments) THEN
         IF (cg$tmp_rec.comments IS NOT NULL AND
            cg$old_rec.comments IS NOT NULL) THEN
            IF (cg$tmp_rec.comments != cg$old_rec.comments) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p130comments)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_PROPERTIES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.comments IS NOT NULL OR
               cg$old_rec.comments IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p130comments)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTIES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.imp_source_module) THEN
         IF (cg$tmp_rec.imp_source_module IS NOT NULL AND
            cg$old_rec.imp_source_module IS NOT NULL) THEN
            IF (cg$tmp_rec.imp_source_module != cg$old_rec.imp_source_module) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p140imp_source_module)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_PROPERTIES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.imp_source_module IS NOT NULL OR
               cg$old_rec.imp_source_module IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p140imp_source_module)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTIES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.imp_source_name) THEN
         IF (cg$tmp_rec.imp_source_name IS NOT NULL AND
            cg$old_rec.imp_source_name IS NOT NULL) THEN
            IF (cg$tmp_rec.imp_source_name != cg$old_rec.imp_source_name) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p150imp_source_name)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_PROPERTIES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.imp_source_name IS NOT NULL OR
               cg$old_rec.imp_source_name IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p150imp_source_name)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTIES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.imp_auto_cipv) THEN
         IF (cg$tmp_rec.imp_auto_cipv IS NOT NULL AND
            cg$old_rec.imp_auto_cipv IS NOT NULL) THEN
            IF (cg$tmp_rec.imp_auto_cipv != cg$old_rec.imp_auto_cipv) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p160imp_auto_cipv)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_PROPERTIES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.imp_auto_cipv IS NOT NULL OR
               cg$old_rec.imp_auto_cipv IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p160imp_auto_cipv)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTIES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.imp_cascade_cip) THEN
         IF (cg$tmp_rec.imp_cascade_cip IS NOT NULL AND
            cg$old_rec.imp_cascade_cip IS NOT NULL) THEN
            IF (cg$tmp_rec.imp_cascade_cip != cg$old_rec.imp_cascade_cip) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p170imp_cascade_cip)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_PROPERTIES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.imp_cascade_cip IS NOT NULL OR
               cg$old_rec.imp_cascade_cip IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p170imp_cascade_cip)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTIES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.imp_cascade_cipv) THEN
         IF (cg$tmp_rec.imp_cascade_cipv IS NOT NULL AND
            cg$old_rec.imp_cascade_cipv IS NOT NULL) THEN
            IF (cg$tmp_rec.imp_cascade_cipv != cg$old_rec.imp_cascade_cipv) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p180imp_cascade_cipv)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_PROPERTIES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.imp_cascade_cipv IS NOT NULL OR
               cg$old_rec.imp_cascade_cipv IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p180imp_cascade_cipv)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTIES.lck');
            any_modified := TRUE;
         END IF;
      END IF;

      -- Mandatory Columns

      IF (cg$old_ind.id) THEN
         IF (cg$tmp_rec.id != cg$old_rec.id) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p10id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTIES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.creation_date) THEN
         IF (cg$tmp_rec.creation_date != cg$old_rec.creation_date) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p15creation_date)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTIES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.created_by) THEN
         IF (cg$tmp_rec.created_by != cg$old_rec.created_by) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p16created_by)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTIES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.last_update_date) THEN
         IF (cg$tmp_rec.last_update_date != cg$old_rec.last_update_date) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p19last_update_date)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTIES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.last_updated_by) THEN
         IF (cg$tmp_rec.last_updated_by != cg$old_rec.last_updated_by) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p20last_updated_by)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTIES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.cipt_id) THEN
         IF (cg$tmp_rec.cipt_id != cg$old_rec.cipt_id) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p26cipt_id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTIES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.cit_id) THEN
         IF (cg$tmp_rec.cit_id != cg$old_rec.cit_id) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p36cit_id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTIES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.required) THEN
         IF (cg$tmp_rec.required != cg$old_rec.required) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p76required)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTIES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.set_like) THEN
         IF (cg$tmp_rec.set_like != cg$old_rec.set_like) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p86set_like)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTIES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.is_inherited) THEN
         IF (cg$tmp_rec.is_inherited != cg$old_rec.is_inherited) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p91is_inherited)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTIES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.is_importable) THEN
         IF (cg$tmp_rec.is_importable != cg$old_rec.is_importable) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p96is_importable)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTIES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.order_in_list) THEN
         IF (cg$tmp_rec.order_in_list != cg$old_rec.order_in_list) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p106order_in_list)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTIES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.imp_auto_import) THEN
         IF (cg$tmp_rec.imp_auto_import != cg$old_rec.imp_auto_import) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p190imp_auto_import)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTIES.lck');
            any_modified := TRUE;
         END IF;
      END IF;

      IF (any_modified) THEN
         cg$errors.raise_failure;
      END IF;

   END lck;


BEGIN
   cg$ind_true.id                := TRUE;
   cg$ind_true.creation_date     := TRUE;
   cg$ind_true.created_by        := TRUE;
   cg$ind_true.last_update_date  := TRUE;
   cg$ind_true.last_updated_by   := TRUE;
   cg$ind_true.cipt_id           := TRUE;
   cg$ind_true.cit_id            := TRUE;
   cg$ind_true.cip_id_ancient    := TRUE;
   cg$ind_true.cip_id            := TRUE;
   cg$ind_true.required          := TRUE;
   cg$ind_true.set_like          := TRUE;
   cg$ind_true.is_inherited      := TRUE;
   cg$ind_true.is_importable     := TRUE;
   cg$ind_true.order_in_list     := TRUE;
   cg$ind_true.description       := TRUE;
   cg$ind_true.comments          := TRUE;
   cg$ind_true.imp_source_module := TRUE;
   cg$ind_true.imp_source_name   := TRUE;
   cg$ind_true.imp_auto_cipv     := TRUE;
   cg$ind_true.imp_cascade_cip   := TRUE;
   cg$ind_true.imp_cascade_cipv  := TRUE;
   cg$ind_true.imp_auto_import   := TRUE;


END cg$nit_ci_properties;
/

prompt
prompt Creating package body CG$NIT_CI_PROPERTY_TYPES
prompt ==============================================
prompt
CREATE OR REPLACE PACKAGE BODY cg$nit_ci_property_types IS


   PROCEDURE validate_mandatory(cg$val_rec IN cg$row_type
                               ,loc        IN VARCHAR2 := '');
   PROCEDURE up_autogen_columns(cg$rec    IN OUT cg$row_type
                               ,cg$ind    IN OUT cg$ind_type
                               ,operation IN VARCHAR2 := 'INS'
                               ,do_denorm IN BOOLEAN := TRUE);
   PROCEDURE err_msg(msg  IN VARCHAR2
                    ,TYPE IN INTEGER
                    ,loc  IN VARCHAR2 := '');

   --------------------------------------------------------------------------------
   -- Name:        raise_uk_not_updateable
   --
   -- Description: Raise appropriate error when unique key updated
   --
   -- Parameters:  none
   --------------------------------------------------------------------------------
   PROCEDURE raise_uk_not_updateable(uk IN VARCHAR2) IS
   BEGIN
      cg$errors.push(cg$errors.msggettext(cg$errors.api_unique_key_update
                                         ,cg$errors.err_uk_update
                                         ,uk)
                    ,'E'
                    ,'API'
                    ,cg$errors.api_unique_key_update
                    ,'cg$NIT_CI_PROPERTY_TYPES.raise_uk_not_updateable');
      cg$errors.raise_failure;
   END raise_uk_not_updateable;


   --------------------------------------------------------------------------------
   -- Name:        raise_fk_not_transferable
   --
   -- Description: Raise appropriate error when foreign key updated
   --
   -- Parameters:  none
   --------------------------------------------------------------------------------
   PROCEDURE raise_fk_not_transferable(fk IN VARCHAR2) IS
   BEGIN
      cg$errors.push(cg$errors.msggettext(cg$errors.api_foreign_key_trans
                                         ,cg$errors.err_fk_trans
                                         ,fk)
                    ,'E'
                    ,'API'
                    ,cg$errors.api_foreign_key_trans
                    ,'cg$NIT_CI_PROPERTY_TYPES.raise_fk_not_transferable');
      cg$errors.raise_failure;
   END raise_fk_not_transferable;


   --------------------------------------------------------------------------------
   -- Name:        up_autogen_columns
   --
   -- Description: Specific autogeneration of column values and conversion to
   --              uppercase
   --
   -- Parameters:  cg$rec    Record of row to be manipulated
   --              cg$ind    Indicators for row
   --              operation Procedure where this procedure was called
   --------------------------------------------------------------------------------
   PROCEDURE up_autogen_columns(cg$rec    IN OUT cg$row_type
                               ,cg$ind    IN OUT cg$ind_type
                               ,operation IN VARCHAR2 := 'INS'
                               ,do_denorm IN BOOLEAN := TRUE) IS
   BEGIN
      IF (operation = 'INS') THEN
         BEGIN
            IF (cg$ind.id = FALSE OR cg$rec.id IS NULL) THEN
               SELECT nit_seq.NEXTVAL
               INTO   cg$rec.id
               FROM   dual;
               cg$ind.id := TRUE;
            END IF;
         EXCEPTION
            WHEN OTHERS THEN
               cg$errors.push(SQLERRM
                             ,'E'
                             ,'ORA'
                             ,SQLCODE
                             ,'cg$NIT_CI_PROPERTY_TYPES.up_autogen.ID.OTHERS');
               cg$errors.raise_failure;
         END;
         NULL;
      ELSE
         -- (operation = 'UPD')
         NULL;
      END IF; -- (operation = 'INS') ELSE (operation = 'UPD')

      -- Statements executed for both 'INS' and 'UPD'


   EXCEPTION
      WHEN no_data_found THEN
         NULL;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_PROPERTY_TYPES.up_autogen_columns');
         cg$errors.raise_failure;
   END up_autogen_columns;


   --------------------------------------------------------------------------------
   -- Name:        validate_mandatory
   --
   -- Description: Checks all mandatory columns are not null and raises appropriate
   --              error if not satisfied
   --
   -- Parameters:  cg$val_rec Record of row to be checked
   --              loc        Place where this procedure was called for error
   --                         trapping
   --------------------------------------------------------------------------------
   PROCEDURE validate_mandatory(cg$val_rec IN cg$row_type
                               ,loc        IN VARCHAR2 := '') IS
   BEGIN
      IF (cg$val_rec.id IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p10id)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.creation_date IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p15creation_date)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.created_by IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p16created_by)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.last_update_date IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p19last_update_date)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.last_updated_by IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p20last_updated_by)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.NAME IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p30name)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.type_name IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p51type_name)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      NULL;
   END validate_mandatory;

   --------------------------------------------------------------------------------
   -- Name:        slct
   --
   -- Description: Selects into the given parameter all the attributes for the row
   --              given by the primary key
   --
   -- Parameters:  cg$sel_rec  Record of row to be selected into using its PK
   --------------------------------------------------------------------------------
   PROCEDURE slct(cg$sel_rec IN OUT cg$row_type) IS

   BEGIN

      IF cg$sel_rec.the_rowid IS NULL THEN
         SELECT id
               ,creation_date
               ,created_by
               ,last_update_date
               ,last_updated_by
               ,NAME
               ,type_name
               ,mime_type
               ,description
               ,comments
               ,ROWID
         INTO   cg$sel_rec.id
               ,cg$sel_rec.creation_date
               ,cg$sel_rec.created_by
               ,cg$sel_rec.last_update_date
               ,cg$sel_rec.last_updated_by
               ,cg$sel_rec.NAME
               ,cg$sel_rec.type_name
               ,cg$sel_rec.mime_type
               ,cg$sel_rec.description
               ,cg$sel_rec.comments
               ,cg$sel_rec.the_rowid
         FROM   nit_ci_property_types
         WHERE  id = cg$sel_rec.id;
      ELSE
         SELECT id
               ,creation_date
               ,created_by
               ,last_update_date
               ,last_updated_by
               ,NAME
               ,type_name
               ,mime_type
               ,description
               ,comments
               ,ROWID
         INTO   cg$sel_rec.id
               ,cg$sel_rec.creation_date
               ,cg$sel_rec.created_by
               ,cg$sel_rec.last_update_date
               ,cg$sel_rec.last_updated_by
               ,cg$sel_rec.NAME
               ,cg$sel_rec.type_name
               ,cg$sel_rec.mime_type
               ,cg$sel_rec.description
               ,cg$sel_rec.comments
               ,cg$sel_rec.the_rowid
         FROM   nit_ci_property_types
         WHERE  ROWID = cg$sel_rec.the_rowid;
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_PROPERTY_TYPES.slct.others');
         cg$errors.raise_failure;

   END slct;



   --------------------------------------------------------------------------------
   -- Name:        validate_domain
   --
   -- Description: Checks against reference table for values lying in a domain
   --
   -- Parameters:  cg$rec     Record of NIT_CI_PROPERTY_TYPES current values
   --------------------------------------------------------------------------------
   PROCEDURE validate_domain(cg$rec IN OUT cg$row_type
                            ,cg$ind IN cg$ind_type := cg$ind_true) IS
      FOUND BOOLEAN;
      no_tabview EXCEPTION;
      PRAGMA EXCEPTION_INIT(no_tabview
                           ,-942);
   BEGIN

      FOUND := FALSE;
      IF (cg$ind.type_name AND cg$rec.type_name IS NOT NULL) THEN
         FOR c IN (SELECT rv_low_value
                         ,rv_high_value
                   FROM   cg_ref_codes
                   WHERE  rv_domain = 'TYPE_NAME') LOOP
            IF (c.rv_high_value IS NULL AND cg$rec.type_name = c.rv_low_value) OR
               (c.rv_high_value IS NOT NULL AND
               cg$rec.type_name BETWEEN c.rv_low_value AND c.rv_high_value) THEN
               FOUND := TRUE;
               EXIT;
            END IF;
         END LOOP;

         IF (NOT FOUND) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_rv_lookup_fail
                                               ,cg$errors.apimsg_rv_lookup_fail
                                               ,cg$rec.type_name
                                               ,'NIT_CI_PROPERTY_TYPES'
                                               ,'TYPE_NAME')
                          ,'E'
                          ,'API'
                          ,cg$errors.api_rv_lookup_fail
                          ,'cg$NIT_CI_PROPERTY_TYPES.v_domain.no_data_found');
            cg$errors.raise_failure;
         END IF;
      END IF;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         cg$errors.raise_failure;
      WHEN no_tabview THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_rv_tab_not_found
                                            ,cg$errors.apimsg_rv_tab_not_found
                                            ,'CG_REF_CODES'
                                            ,'NIT_CI_PROPERTY_TYPES')
                       ,'E'
                       ,'API'
                       ,cg$errors.api_rv_tab_not_found
                       ,'cg$NIT_CI_PROPERTY_TYPES.v_domain.no_reftable_found');
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_PROPERTY_TYPES.v_domain.others');
         cg$errors.raise_failure;
   END validate_domain;


   --------------------------------------------------------------------------------
   -- Name:        err_msg
   --
   -- Description: Pushes onto stack appropriate user defined error message
   --              depending on the rule violated
   --
   -- Parameters:  msg     Oracle error message
   --              type    Type of violation e.g. check_constraint: ERR_CHECK_CON
   --              loc     Place where this procedure was called for error
   --                      trapping
   --------------------------------------------------------------------------------
   PROCEDURE err_msg(msg  IN VARCHAR2
                    ,TYPE IN INTEGER
                    ,loc  IN VARCHAR2 := '') IS
      con_name VARCHAR2(240);
   BEGIN
      con_name := cg$errors.parse_constraint(msg
                                            ,TYPE);
      IF (con_name = 'NIT_CPK_CIPT') THEN
         cg$errors.push(NVL(nit_cpk_cipt
                           ,cg$errors.msggettext(cg$errors.api_pk_con_violated
                                                ,cg$errors.apimsg_pk_violat
                                                ,'NIT_CPK_CIPT'
                                                ,'NIT_CI_PROPERTY_TYPES'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_pk_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CUK_CIPT') THEN
         cg$errors.push(NVL(nit_cuk_cipt
                           ,cg$errors.msggettext(cg$errors.api_uq_con_violated
                                                ,cg$errors.apimsg_uk_violat
                                                ,'NIT_CUK_CIPT'
                                                ,'NIT_CI_PROPERTY_TYPES'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_uq_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CFK_CIP_CIPT' AND
            TYPE = cg$errors.err_delete_restrict) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_del_restrict
                                            ,cg$errors.err_del_restrict
                                            ,'Nitil Ci Property Type'
                                            ,'NIT_CI_PROPERTIES')
                       ,'E'
                       ,'API'
                       ,cg$errors.api_del_restrict
                       ,loc);

      ELSE
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,loc);
      END IF;
   END err_msg;

   --------------------------------------------------------------------------------
   -- Name:        ins
   --
   -- Description: API insert procedure
   --
   -- Parameters:  cg$rec  Record of row to be inserted
   --              cg$ind  Record of columns specifically set
   --              do_ins  Whether we want the actual INSERT to occur
   --------------------------------------------------------------------------------
   PROCEDURE ins(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_ins IN BOOLEAN := TRUE) IS

      --  Constant := values

      d51_type_name CONSTANT nit_ci_property_types.type_name%TYPE := 'varchar2';

   BEGIN
      --  Application_logic Pre-Insert <<Start>>
      nit_ci_property_types_p.pre_dml(cg$rec
                                     ,cg$ind
                                     ,'INS');
      --  Application_logic Pre-Insert << End >>

      IF NOT (cg$ind.type_name) THEN
         cg$rec.type_name := d51_type_name;
      END IF;
      --  Auto-generated and uppercased columns

      up_autogen_columns(cg$rec
                        ,cg$ind
                        ,'INS'
                        ,do_ins);

      called_from_package := TRUE;

      IF (do_ins) THEN
         validate_domain(cg$rec);

         INSERT INTO nit_ci_property_types
            (id
            ,creation_date
            ,created_by
            ,last_update_date
            ,last_updated_by
            ,NAME
            ,type_name
            ,mime_type
            ,description
            ,comments)
         VALUES
            (cg$rec.id
            ,cg$rec.creation_date
            ,cg$rec.created_by
            ,cg$rec.last_update_date
            ,cg$rec.last_updated_by
            ,cg$rec.NAME
            ,cg$rec.type_name
            ,cg$rec.mime_type
            ,cg$rec.description
            ,cg$rec.comments)
         RETURNING id, creation_date, created_by, last_update_date, last_updated_by, NAME, type_name, mime_type, description, comments, ROWID INTO cg$rec.id, cg$rec.creation_date, cg$rec.created_by, cg$rec.last_update_date, cg$rec.last_updated_by, cg$rec.NAME, cg$rec.type_name, cg$rec.mime_type, cg$rec.description, cg$rec.comments, cg$rec.the_rowid;
      END IF;

      called_from_package := FALSE;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.mandatory_missing THEN
         validate_mandatory(cg$rec
                           ,'cg$NIT_CI_PROPERTY_TYPES.ins.mandatory_missing');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.check_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_check_con
                ,'cg$NIT_CI_PROPERTY_TYPES.ins.check_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.fk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_foreign_key
                ,'cg$NIT_CI_PROPERTY_TYPES.ins.fk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.uk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_unique_key
                ,'cg$NIT_CI_PROPERTY_TYPES.ins.uk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_PROPERTY_TYPES.ins.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END ins;


   --------------------------------------------------------------------------------
   -- Name:        upd
   --
   -- Description: API update procedure
   --
   -- Parameters:  cg$rec  Record of row to be updated
   --              cg$ind  Record of columns specifically set
   --              do_upd  Whether we want the actual UPDATE to occur
   --------------------------------------------------------------------------------
   PROCEDURE upd(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_upd IN BOOLEAN := TRUE
                ,cg$pk  IN cg$row_type := NULL) IS
      cg$upd_rec cg$row_type;
      cg$old_rec cg$row_type;
   BEGIN
      nit_ci_property_types_p.pre_dml(cg$rec
                                     ,cg$ind
                                     ,'UPD');


      IF (cg$pk.id IS NULL) THEN
         cg$upd_rec.id := cg$rec.id;
      ELSE
         cg$upd_rec.id := cg$pk.id;
      END IF;
      cg$old_rec.id := cg$upd_rec.id;

      IF (cg$pk.the_rowid IS NULL) THEN
         cg$upd_rec.the_rowid := cg$rec.the_rowid;
      ELSE
         cg$upd_rec.the_rowid := cg$pk.the_rowid;
      END IF;
      cg$old_rec.the_rowid := cg$upd_rec.the_rowid;

      IF (do_upd) THEN

         slct(cg$upd_rec);


         --  Report error if attempt to update non updateable Primary Key NIT_CPK_CIPT
         IF (cg$ind.id AND cg$rec.id != cg$upd_rec.id) THEN
            raise_uk_not_updateable('NIT_CPK_CIPT');
         END IF;
         IF NOT (cg$ind.id) THEN
            cg$rec.id := cg$upd_rec.id;
         END IF;
         IF NOT (cg$ind.creation_date) THEN
            cg$rec.creation_date := cg$upd_rec.creation_date;
         END IF;
         IF NOT (cg$ind.created_by) THEN
            cg$rec.created_by := cg$upd_rec.created_by;
         END IF;
         IF NOT (cg$ind.last_update_date) THEN
            cg$rec.last_update_date := cg$upd_rec.last_update_date;
         END IF;
         IF NOT (cg$ind.last_updated_by) THEN
            cg$rec.last_updated_by := cg$upd_rec.last_updated_by;
         END IF;
         IF NOT (cg$ind.NAME) THEN
            cg$rec.NAME := cg$upd_rec.NAME;
         END IF;
         IF NOT (cg$ind.type_name) THEN
            cg$rec.type_name := cg$upd_rec.type_name;
         END IF;
         IF NOT (cg$ind.mime_type) THEN
            cg$rec.mime_type := cg$upd_rec.mime_type;
         END IF;
         IF NOT (cg$ind.description) THEN
            cg$rec.description := cg$upd_rec.description;
         END IF;
         IF NOT (cg$ind.comments) THEN
            cg$rec.comments := cg$upd_rec.comments;
         END IF;
      ELSE
         -- Perform checks if called from a trigger
         -- Indicators are only set on changed values
         --  Report error if attempt to update non updateable Primary Key NIT_CPK_CIPT
         IF (cg$ind.id) THEN
            raise_uk_not_updateable('NIT_CPK_CIPT');
         END IF;
      END IF;

      up_autogen_columns(cg$rec
                        ,cg$ind
                        ,'UPD'
                        ,do_upd); --  Auto-generated and uppercased columns

      --  Now do update if updateable columns exist
      IF (do_upd) THEN
         DECLARE
            called_from BOOLEAN := called_from_package;
         BEGIN
            called_from_package := TRUE;

            slct(cg$old_rec);
            validate_domain(cg$rec
                           ,cg$ind);

            IF cg$rec.the_rowid IS NULL THEN
               UPDATE nit_ci_property_types
               SET    creation_date    = cg$rec.creation_date
                     ,created_by       = cg$rec.created_by
                     ,last_update_date = cg$rec.last_update_date
                     ,last_updated_by  = cg$rec.last_updated_by
                     ,NAME             = cg$rec.NAME
                     ,type_name        = cg$rec.type_name
                     ,mime_type        = cg$rec.mime_type
                     ,description      = cg$rec.description
                     ,comments         = cg$rec.comments
               WHERE  id = cg$rec.id RETURNING id, creation_date, created_by,
                last_update_date, last_updated_by, NAME, type_name,
                mime_type, description, comments, ROWID INTO cg$rec.id,
                cg$rec.creation_date, cg$rec.created_by,
                cg$rec.last_update_date, cg$rec.last_updated_by,
                cg$rec.NAME, cg$rec.type_name, cg$rec.mime_type,
                cg$rec.description, cg$rec.comments, cg$rec.the_rowid;

            ELSE
               UPDATE nit_ci_property_types
               SET    creation_date    = cg$rec.creation_date
                     ,created_by       = cg$rec.created_by
                     ,last_update_date = cg$rec.last_update_date
                     ,last_updated_by  = cg$rec.last_updated_by
                     ,NAME             = cg$rec.NAME
                     ,type_name        = cg$rec.type_name
                     ,mime_type        = cg$rec.mime_type
                     ,description      = cg$rec.description
                     ,comments         = cg$rec.comments
               WHERE  ROWID = cg$rec.the_rowid RETURNING id, creation_date,
                created_by, last_update_date, last_updated_by, NAME,
                type_name, mime_type, description, comments, ROWID INTO
                cg$rec.id, cg$rec.creation_date, cg$rec.created_by,
                cg$rec.last_update_date, cg$rec.last_updated_by,
                cg$rec.NAME, cg$rec.type_name, cg$rec.mime_type,
                cg$rec.description, cg$rec.comments, cg$rec.the_rowid;
            END IF;
            called_from_package := called_from;
         END;
      END IF;

      IF NOT (do_upd) THEN
         cg$table(idx).id := cg$rec.id;
         cg$tableind(idx).id := cg$ind.id;
         cg$table(idx).creation_date := cg$rec.creation_date;
         cg$tableind(idx).creation_date := cg$ind.creation_date;
         cg$table(idx).created_by := cg$rec.created_by;
         cg$tableind(idx).created_by := cg$ind.created_by;
         cg$table(idx).last_update_date := cg$rec.last_update_date;
         cg$tableind(idx).last_update_date := cg$ind.last_update_date;
         cg$table(idx).last_updated_by := cg$rec.last_updated_by;
         cg$tableind(idx).last_updated_by := cg$ind.last_updated_by;
         cg$table(idx).NAME := cg$rec.NAME;
         cg$tableind(idx).NAME := cg$ind.NAME;
         cg$table(idx).type_name := cg$rec.type_name;
         cg$tableind(idx).type_name := cg$ind.type_name;
         cg$table(idx).mime_type := cg$rec.mime_type;
         cg$tableind(idx).mime_type := cg$ind.mime_type;
         cg$table(idx).description := cg$rec.description;
         cg$tableind(idx).description := cg$ind.description;
         cg$table(idx).comments := cg$rec.comments;
         cg$tableind(idx).comments := cg$ind.comments;
         idx := idx + 1;
      END IF;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.upd_mandatory_null THEN
         validate_mandatory(cg$rec
                           ,'cg$NIT_CI_PROPERTY_TYPES.upd.upd_mandatory_null');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.check_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_check_con
                ,'cg$NIT_CI_PROPERTY_TYPES.upd.check_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.fk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_foreign_key
                ,'cg$NIT_CI_PROPERTY_TYPES.upd.fk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.uk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_unique_key
                ,'cg$NIT_CI_PROPERTY_TYPES.upd.uk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_PROPERTY_TYPES.upd.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END upd;
   --------------------------------------------------------------------------------
   -- Name:        del
   --
   -- Description: API delete procedure
   --
   -- Parameters:  cg$pk  Primary key record of row to be deleted
   --------------------------------------------------------------------------------
   PROCEDURE del(cg$pk  IN cg$pk_type
                ,do_del IN BOOLEAN := TRUE) IS
   BEGIN
      nit_ci_property_types_p.pre_del(cg$pk.id);

      --  Delete the record

      called_from_package := TRUE;

      IF (do_del) THEN
         BEGIN

            IF cg$pk.the_rowid IS NULL THEN
               DELETE nit_ci_property_types
               WHERE  id = cg$pk.id;
            ELSE
               DELETE nit_ci_property_types
               WHERE  ROWID = cg$pk.the_rowid;
            END IF;
         END;
      END IF;

      called_from_package := FALSE;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.delete_restrict THEN
         err_msg(SQLERRM
                ,cg$errors.err_delete_restrict
                ,'cg$NIT_CI_PROPERTY_TYPES.del.delete_restrict');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN no_data_found THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_row_del
                                            ,cg$errors.row_del)
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_PROPERTY_TYPES.del.no_data_found');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_PROPERTY_TYPES.del.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END del;


   --------------------------------------------------------------------------------
   -- Name:        lck
   --
   -- Description: API lock procedure
   --
   -- Parameters:  cg$old_rec  Calling apps view of record of row to be locked
   --              cg$old_ind  Record of columns to raise error if modified
   --              nowait_flag TRUE lock with NOWAIT, FALSE don't fail if busy
   --------------------------------------------------------------------------------
   PROCEDURE lck(cg$old_rec  IN cg$row_type
                ,cg$old_ind  IN cg$ind_type
                ,nowait_flag IN BOOLEAN := TRUE) IS
      cg$tmp_rec   cg$row_type;
      any_modified BOOLEAN := FALSE;

   BEGIN
      --  Application_logic Pre-Lock <<Start>>
      --  Application_logic Pre-Lock << End >>

      --  Do the row lock

      BEGIN
         IF (nowait_flag) THEN
            IF cg$old_rec.the_rowid IS NULL THEN
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,NAME
                     ,type_name
                     ,mime_type
                     ,description
                     ,comments
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.NAME
                     ,cg$tmp_rec.type_name
                     ,cg$tmp_rec.mime_type
                     ,cg$tmp_rec.description
                     ,cg$tmp_rec.comments
               FROM   nit_ci_property_types
               WHERE  id = cg$old_rec.id
               FOR    UPDATE NOWAIT;
            ELSE
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,NAME
                     ,type_name
                     ,mime_type
                     ,description
                     ,comments
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.NAME
                     ,cg$tmp_rec.type_name
                     ,cg$tmp_rec.mime_type
                     ,cg$tmp_rec.description
                     ,cg$tmp_rec.comments
               FROM   nit_ci_property_types
               WHERE  ROWID = cg$old_rec.the_rowid
               FOR    UPDATE NOWAIT;
            END IF;
         ELSE
            IF cg$old_rec.the_rowid IS NULL THEN
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,NAME
                     ,type_name
                     ,mime_type
                     ,description
                     ,comments
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.NAME
                     ,cg$tmp_rec.type_name
                     ,cg$tmp_rec.mime_type
                     ,cg$tmp_rec.description
                     ,cg$tmp_rec.comments
               FROM   nit_ci_property_types
               WHERE  id = cg$old_rec.id
               FOR    UPDATE;
            ELSE
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,NAME
                     ,type_name
                     ,mime_type
                     ,description
                     ,comments
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.NAME
                     ,cg$tmp_rec.type_name
                     ,cg$tmp_rec.mime_type
                     ,cg$tmp_rec.description
                     ,cg$tmp_rec.comments
               FROM   nit_ci_property_types
               WHERE  ROWID = cg$old_rec.the_rowid
               FOR    UPDATE;
            END IF;
         END IF;

      EXCEPTION
         WHEN cg$errors.cg$error THEN
            cg$errors.raise_failure;
         WHEN cg$errors.resource_busy THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_lck
                                               ,cg$errors.row_lck)
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_CI_PROPERTY_TYPES.lck.resource_busy');
            cg$errors.raise_failure;
         WHEN no_data_found THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_del
                                               ,cg$errors.row_del)
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_CI_PROPERTY_TYPES.lck.no_data_found');
            cg$errors.raise_failure;
         WHEN OTHERS THEN
            cg$errors.push(SQLERRM
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_CI_PROPERTY_TYPES.lck.others');
            cg$errors.raise_failure;
      END;

      -- Optional Columns

      IF (cg$old_ind.mime_type) THEN
         IF (cg$tmp_rec.mime_type IS NOT NULL AND
            cg$old_rec.mime_type IS NOT NULL) THEN
            IF (cg$tmp_rec.mime_type != cg$old_rec.mime_type) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p61mime_type)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_PROPERTY_TYPES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.mime_type IS NOT NULL OR
               cg$old_rec.mime_type IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p61mime_type)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTY_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.description) THEN
         IF (cg$tmp_rec.description IS NOT NULL AND
            cg$old_rec.description IS NOT NULL) THEN
            IF (cg$tmp_rec.description != cg$old_rec.description) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p66description)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_PROPERTY_TYPES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.description IS NOT NULL OR
               cg$old_rec.description IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p66description)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTY_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.comments) THEN
         IF (cg$tmp_rec.comments IS NOT NULL AND
            cg$old_rec.comments IS NOT NULL) THEN
            IF (cg$tmp_rec.comments != cg$old_rec.comments) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p71comments)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_PROPERTY_TYPES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.comments IS NOT NULL OR
               cg$old_rec.comments IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p71comments)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTY_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;

      -- Mandatory Columns

      IF (cg$old_ind.id) THEN
         IF (cg$tmp_rec.id != cg$old_rec.id) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p10id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTY_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.creation_date) THEN
         IF (cg$tmp_rec.creation_date != cg$old_rec.creation_date) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p15creation_date)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTY_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.created_by) THEN
         IF (cg$tmp_rec.created_by != cg$old_rec.created_by) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p16created_by)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTY_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.last_update_date) THEN
         IF (cg$tmp_rec.last_update_date != cg$old_rec.last_update_date) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p19last_update_date)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTY_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.last_updated_by) THEN
         IF (cg$tmp_rec.last_updated_by != cg$old_rec.last_updated_by) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p20last_updated_by)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTY_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.NAME) THEN
         IF (cg$tmp_rec.NAME != cg$old_rec.NAME) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p30name)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTY_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.type_name) THEN
         IF (cg$tmp_rec.type_name != cg$old_rec.type_name) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p51type_name)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTY_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;

      IF (any_modified) THEN
         cg$errors.raise_failure;
      END IF;

   END lck;


BEGIN
   cg$ind_true.id               := TRUE;
   cg$ind_true.creation_date    := TRUE;
   cg$ind_true.created_by       := TRUE;
   cg$ind_true.last_update_date := TRUE;
   cg$ind_true.last_updated_by  := TRUE;
   cg$ind_true.NAME             := TRUE;
   cg$ind_true.type_name        := TRUE;
   cg$ind_true.mime_type        := TRUE;
   cg$ind_true.description      := TRUE;
   cg$ind_true.comments         := TRUE;


END cg$nit_ci_property_types;
/

prompt
prompt Creating package body CG$NIT_CI_PROPERTY_VALUES
prompt ===============================================
prompt
CREATE OR REPLACE PACKAGE BODY cg$nit_ci_property_values IS

   PROCEDURE validate_mandatory(cg$val_rec IN cg$row_type
                               ,loc        IN VARCHAR2 DEFAULT '');
   PROCEDURE up_autogen_columns(cg$rec    IN OUT cg$row_type
                               ,cg$ind    IN OUT cg$ind_type
                               ,operation IN VARCHAR2 DEFAULT 'INS'
                               ,do_denorm IN BOOLEAN DEFAULT TRUE);
   PROCEDURE err_msg(msg  IN VARCHAR2
                    ,TYPE IN INTEGER
                    ,loc  IN VARCHAR2 DEFAULT '');

   --------------------------------------------------------------------------------
   -- Name:        raise_uk_not_updateable
   --
   -- Description: Raise appropriate error when unique key updated
   --
   -- Parameters:  none
   --------------------------------------------------------------------------------
   PROCEDURE raise_uk_not_updateable(uk IN VARCHAR2) IS
   BEGIN
      cg$errors.push(cg$errors.msggettext(cg$errors.api_unique_key_update
                                         ,cg$errors.err_uk_update
                                         ,uk)
                    ,'E'
                    ,'API'
                    ,cg$errors.api_unique_key_update
                    ,'cg$NIT_CI_PROPERTY_VALUES.raise_uk_not_updateable');
      cg$errors.raise_failure;
   END raise_uk_not_updateable;

   --------------------------------------------------------------------------------
   -- Name:        raise_fk_not_transferable
   --
   -- Description: Raise appropriate error when foreign key updated
   --
   -- Parameters:  none
   --------------------------------------------------------------------------------
   PROCEDURE raise_fk_not_transferable(fk IN VARCHAR2) IS
   BEGIN
      cg$errors.push(cg$errors.msggettext(cg$errors.api_foreign_key_trans
                                         ,cg$errors.err_fk_trans
                                         ,fk)
                    ,'E'
                    ,'API'
                    ,cg$errors.api_foreign_key_trans
                    ,'cg$NIT_CI_PROPERTY_VALUES.raise_fk_not_transferable');
      cg$errors.raise_failure;
   END raise_fk_not_transferable;

   --------------------------------------------------------------------------------
   -- Name:        up_autogen_columns
   --
   -- Description: Specific autogeneration of column values and conversion to
   --              uppercase
   --
   -- Parameters:  cg$rec    Record of row to be manipulated
   --              cg$ind    Indicators for row
   --              operation Procedure where this procedure was called
   --------------------------------------------------------------------------------
   PROCEDURE up_autogen_columns(cg$rec    IN OUT cg$row_type
                               ,cg$ind    IN OUT cg$ind_type
                               ,operation IN VARCHAR2 DEFAULT 'INS'
                               ,do_denorm IN BOOLEAN DEFAULT TRUE) IS
   BEGIN
      IF (operation = 'INS') THEN
         BEGIN
            IF (cg$ind.id = FALSE OR cg$rec.id IS NULL) THEN
               SELECT nit_seq.NEXTVAL
               INTO   cg$rec.id
               FROM   dual;
               cg$ind.id := TRUE;
            END IF;
         EXCEPTION
            WHEN OTHERS THEN
               cg$errors.push(SQLERRM
                             ,'E'
                             ,'ORA'
                             ,SQLCODE
                             ,'cg$NIT_CI_PROPERTY_VALUES.up_autogen.ID.OTHERS');
               cg$errors.raise_failure;
         END;
      ELSE
         -- (operation = 'UPD')
         NULL;
      END IF; -- (operation = 'INS') ELSE (operation = 'UPD')

      -- Statements executed for both 'INS' and 'UPD'

   EXCEPTION
      WHEN no_data_found THEN
         NULL;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_PROPERTY_VALUES.up_autogen_columns');
         cg$errors.raise_failure;
   END up_autogen_columns;

   --------------------------------------------------------------------------------
   -- Name:        validate_mandatory
   --
   -- Description: Checks all mandatory columns are not null and raises appropriate
   --              error if not satisfied
   --
   -- Parameters:  cg$val_rec Record of row to be checked
   --              loc        Place where this procedure was called for error
   --                         trapping
   --------------------------------------------------------------------------------
   PROCEDURE validate_mandatory(cg$val_rec IN cg$row_type
                               ,loc        IN VARCHAR2 DEFAULT '') IS
   BEGIN
      IF (cg$val_rec.id IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p10id)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.creation_date IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p15creation_date)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.created_by IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p16created_by)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.last_update_date IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p19last_update_date)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.last_updated_by IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p24last_updated_by)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.cip_id IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p30cip_id)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.is_default IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p50is_default)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.order_in_list IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p60order_in_list)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.VALUE IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p65value)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      NULL;
   END validate_mandatory;
   --------------------------------------------------------------------------------
   -- Name:        slct
   --
   -- Description: Selects into the given parameter all the attributes for the row
   --              given by the primary key
   --
   -- Parameters:  cg$sel_rec  Record of row to be selected into using its PK
   --------------------------------------------------------------------------------
   PROCEDURE slct(cg$sel_rec IN OUT cg$row_type) IS

   BEGIN

      IF cg$sel_rec.the_rowid IS NULL THEN
         SELECT id
               ,creation_date
               ,created_by
               ,last_update_date
               ,last_updated_by
               ,cip_id
               ,is_default
               ,order_in_list
               ,VALUE
               ,description
               ,comments
               ,ROWID
         INTO   cg$sel_rec.id
               ,cg$sel_rec.creation_date
               ,cg$sel_rec.created_by
               ,cg$sel_rec.last_update_date
               ,cg$sel_rec.last_updated_by
               ,cg$sel_rec.cip_id
               ,cg$sel_rec.is_default
               ,cg$sel_rec.order_in_list
               ,cg$sel_rec.VALUE
               ,cg$sel_rec.description
               ,cg$sel_rec.comments
               ,cg$sel_rec.the_rowid
         FROM   nit_ci_property_values
         WHERE  id = cg$sel_rec.id;
      ELSE
         SELECT id
               ,creation_date
               ,created_by
               ,last_update_date
               ,last_updated_by
               ,cip_id
               ,is_default
               ,order_in_list
               ,VALUE
               ,description
               ,comments
               ,ROWID
         INTO   cg$sel_rec.id
               ,cg$sel_rec.creation_date
               ,cg$sel_rec.created_by
               ,cg$sel_rec.last_update_date
               ,cg$sel_rec.last_updated_by
               ,cg$sel_rec.cip_id
               ,cg$sel_rec.is_default
               ,cg$sel_rec.order_in_list
               ,cg$sel_rec.VALUE
               ,cg$sel_rec.description
               ,cg$sel_rec.comments
               ,cg$sel_rec.the_rowid
         FROM   nit_ci_property_values
         WHERE  ROWID = cg$sel_rec.the_rowid;
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_PROPERTY_VALUES.slct.others');
         cg$errors.raise_failure;

   END slct;

   --------------------------------------------------------------------------------
   -- Name:        err_msg
   --
   -- Description: Pushes onto stack appropriate user defined error message
   --              depending on the rule violated
   --
   -- Parameters:  msg     Oracle error message
   --              type    Type of violation e.g. check_constraint: ERR_CHECK_CON
   --              loc     Place where this procedure was called for error
   --                      trapping
   --------------------------------------------------------------------------------
   PROCEDURE err_msg(msg  IN VARCHAR2
                    ,TYPE IN INTEGER
                    ,loc  IN VARCHAR2 DEFAULT '') IS
      con_name VARCHAR2(240);
   BEGIN
      con_name := cg$errors.parse_constraint(msg
                                            ,TYPE);
      IF (con_name = 'NIT_CPK_CIPV') THEN
         cg$errors.push(nvl(nit_cpk_cipv
                           ,cg$errors.msggettext(cg$errors.api_pk_con_violated
                                                ,cg$errors.apimsg_pk_violat
                                                ,'NIT_CPK_CIPV'
                                                ,'NIT_CI_PROPERTY_VALUES'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_pk_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CUK_CIPV') THEN
         cg$errors.push(nvl(nit_cuk_cipv
                           ,cg$errors.msggettext(cg$errors.api_uq_con_violated
                                                ,cg$errors.apimsg_uk_violat
                                                ,'NIT_CUK_CIPV'
                                                ,'NIT_CI_PROPERTY_VALUES'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_uq_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CFK_CIA_CIV' AND
            TYPE = cg$errors.err_delete_restrict) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_del_restrict
                                            ,cg$errors.err_del_restrict
                                            ,'NIT_CI_PROPERTY_VALUES'
                                            ,'NIT_CI_ATTRIBUTES')
                       ,'E'
                       ,'API'
                       ,cg$errors.api_del_restrict
                       ,loc);

      ELSIF (con_name = 'NITIL_CIPV_CIP_FK') THEN
         cg$errors.push(nvl(nitil_cipv_cip_fk
                           ,cg$errors.msggettext(cg$errors.api_fk_con_violated
                                                ,cg$errors.apimsg_fk_violat
                                                ,'NITIL_CIPV_CIP_FK'
                                                ,'NIT_CI_PROPERTY_VALUES'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_fk_con_violated
                       ,loc);
      ELSE
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,loc);
      END IF;
   END err_msg;

   --------------------------------------------------------------------------------
   -- Name:        ins
   --
   -- Description: API insert procedure
   --
   -- Parameters:  cg$rec  Record of row to be inserted
   --              cg$ind  Record of columns specifically set
   --              do_ins  Whether we want the actual INSERT to occur
   --------------------------------------------------------------------------------
   PROCEDURE ins(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_ins IN BOOLEAN DEFAULT TRUE) IS

      --  Constant default values

      d50_is_default    CONSTANT nit_ci_property_values.is_default%TYPE := 'N';
      d60_order_in_list CONSTANT nit_ci_property_values.order_in_list%TYPE := 0;

   BEGIN
      nit_ci_property_values_p.pre_dml(cg$rec
                                      ,cg$ind
                                      ,'INS');
      nit_ci_property_values_p.pre_ins(cg$rec
                                      ,cg$ind);
      --  Defaulted

      IF NOT (cg$ind.is_default) THEN
         cg$rec.is_default := d50_is_default;
      END IF;
      IF NOT (cg$ind.order_in_list) THEN
         cg$rec.order_in_list := d60_order_in_list;
      END IF;
      --  Auto-generated and uppercased columns

      up_autogen_columns(cg$rec
                        ,cg$ind
                        ,'INS'
                        ,do_ins);

      called_from_package := TRUE;

      IF (do_ins) THEN

         INSERT INTO nit_ci_property_values
            (id
            ,creation_date
            ,created_by
            ,last_update_date
            ,last_updated_by
            ,cip_id
            ,is_default
            ,order_in_list
            ,VALUE
            ,description
            ,comments)
         VALUES
            (cg$rec.id
            ,cg$rec.creation_date
            ,cg$rec.created_by
            ,cg$rec.last_update_date
            ,cg$rec.last_updated_by
            ,cg$rec.cip_id
            ,cg$rec.is_default
            ,cg$rec.order_in_list
            ,cg$rec.VALUE
            ,cg$rec.description
            ,cg$rec.comments)
         RETURNING id, creation_date, created_by, last_update_date, last_updated_by, cip_id, is_default, order_in_list, VALUE, description, comments, ROWID INTO cg$rec.id, cg$rec.creation_date, cg$rec.created_by, cg$rec.last_update_date, cg$rec.last_updated_by, cg$rec.cip_id, cg$rec.is_default, cg$rec.order_in_list, cg$rec.VALUE, cg$rec.description, cg$rec.comments, cg$rec.the_rowid;
      END IF;

      called_from_package := FALSE;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.mandatory_missing THEN
         validate_mandatory(cg$rec
                           ,'cg$NIT_CI_PROPERTY_VALUES.ins.mandatory_missing');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.check_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_check_con
                ,'cg$NIT_CI_PROPERTY_VALUES.ins.check_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.fk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_foreign_key
                ,'cg$NIT_CI_PROPERTY_VALUES.ins.fk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.uk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_unique_key
                ,'cg$NIT_CI_PROPERTY_VALUES.ins.uk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_PROPERTY_VALUES.ins.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END ins;

   --------------------------------------------------------------------------------
   -- Name:        upd
   --
   -- Description: API update procedure
   --
   -- Parameters:  cg$rec  Record of row to be updated
   --              cg$ind  Record of columns specifically set
   --              do_upd  Whether we want the actual UPDATE to occur
   --------------------------------------------------------------------------------
   PROCEDURE upd(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_upd IN BOOLEAN DEFAULT TRUE
                ,cg$pk  IN cg$row_type DEFAULT NULL) IS
      cg$upd_rec cg$row_type;
      cg$old_rec cg$row_type;
   BEGIN
      --  Application_logic Pre-Update <<Start>>
      BEGIN
         nit_ci_property_values_p.pre_dml(cg$rec
                                         ,cg$ind
                                         ,'UPD');
      END;

      --  Application_logic Pre-Update << End >>

      IF (cg$pk.id IS NULL) THEN
         cg$upd_rec.id := cg$rec.id;
      ELSE
         cg$upd_rec.id := cg$pk.id;
      END IF;
      cg$old_rec.id := cg$upd_rec.id;

      IF (cg$pk.the_rowid IS NULL) THEN
         cg$upd_rec.the_rowid := cg$rec.the_rowid;
      ELSE
         cg$upd_rec.the_rowid := cg$pk.the_rowid;
      END IF;
      cg$old_rec.the_rowid := cg$upd_rec.the_rowid;

      IF (do_upd) THEN

         slct(cg$upd_rec);

         --  Report error if attempt to update non transferable Foreign Key NITIL_CIPV_CIP_FK
         IF (cg$ind.cip_id AND cg$rec.cip_id != cg$upd_rec.cip_id) THEN
            raise_fk_not_transferable('NITIL_CIPV_CIP_FK');
         END IF;
         IF (cg$ind.cip_id AND cg$rec.cip_id IS NULL AND
            cg$upd_rec.cip_id IS NOT NULL) THEN
            raise_fk_not_transferable('NITIL_CIPV_CIP_FK');
         END IF;
         IF (cg$ind.cip_id AND cg$rec.cip_id IS NOT NULL AND
            cg$upd_rec.cip_id IS NULL) THEN
            raise_fk_not_transferable('NITIL_CIPV_CIP_FK');
         END IF;

         --  Report error if attempt to update non updateable Primary Key NIT_CPK_CIPV
         IF (cg$ind.id AND cg$rec.id != cg$upd_rec.id) THEN
            raise_uk_not_updateable('NIT_CPK_CIPV');
         END IF;
         IF NOT (cg$ind.id) THEN
            cg$rec.id := cg$upd_rec.id;
         END IF;
         IF NOT (cg$ind.creation_date) THEN
            cg$rec.creation_date := cg$upd_rec.creation_date;
         END IF;
         IF NOT (cg$ind.created_by) THEN
            cg$rec.created_by := cg$upd_rec.created_by;
         END IF;
         IF NOT (cg$ind.last_update_date) THEN
            cg$rec.last_update_date := cg$upd_rec.last_update_date;
         END IF;
         IF NOT (cg$ind.last_updated_by) THEN
            cg$rec.last_updated_by := cg$upd_rec.last_updated_by;
         END IF;
         IF NOT (cg$ind.cip_id) THEN
            cg$rec.cip_id := cg$upd_rec.cip_id;
         END IF;
         IF NOT (cg$ind.is_default) THEN
            cg$rec.is_default := cg$upd_rec.is_default;
         END IF;
         IF NOT (cg$ind.order_in_list) THEN
            cg$rec.order_in_list := cg$upd_rec.order_in_list;
         END IF;
         IF NOT (cg$ind.VALUE) THEN
            cg$rec.VALUE := cg$upd_rec.VALUE;
         END IF;
         IF NOT (cg$ind.description) THEN
            cg$rec.description := cg$upd_rec.description;
         END IF;
         IF NOT (cg$ind.comments) THEN
            cg$rec.comments := cg$upd_rec.comments;
         END IF;
      ELSE
         -- Perform checks if called from a trigger
         -- Indicators are only set on changed values
         --  Report error if attempt to update non transferable Foreign Key NITIL_CIPV_CIP_FK
         IF (cg$ind.cip_id) THEN
            raise_fk_not_transferable('NITIL_CIPV_CIP_FK');
         END IF;
         --  Report error if attempt to update non updateable Primary Key NIT_CPK_CIPV
         IF (cg$ind.id) THEN
            raise_uk_not_updateable('NIT_CPK_CIPV');
         END IF;
      END IF;

      up_autogen_columns(cg$rec
                        ,cg$ind
                        ,'UPD'
                        ,do_upd); --  Auto-generated and uppercased columns

      --  Now do update if updateable columns exist
      IF (do_upd) THEN
         DECLARE
            called_from BOOLEAN := called_from_package;
         BEGIN
            called_from_package := TRUE;

            slct(cg$old_rec);

            IF cg$rec.the_rowid IS NULL THEN
               UPDATE nit_ci_property_values
               SET    creation_date    = cg$rec.creation_date
                     ,created_by       = cg$rec.created_by
                     ,last_update_date = cg$rec.last_update_date
                     ,last_updated_by  = cg$rec.last_updated_by
                     ,cip_id           = cg$rec.cip_id
                     ,is_default       = cg$rec.is_default
                     ,order_in_list    = cg$rec.order_in_list
                     ,VALUE            = cg$rec.VALUE
                     ,description      = cg$rec.description
                     ,comments         = cg$rec.comments
               WHERE  id = cg$rec.id RETURNING id, creation_date, created_by,
                last_update_date, last_updated_by, cip_id, is_default,
                order_in_list, VALUE, description, comments, ROWID INTO
                cg$rec.id, cg$rec.creation_date, cg$rec.created_by,
                cg$rec.last_update_date, cg$rec.last_updated_by,
                cg$rec.cip_id, cg$rec.is_default, cg$rec.order_in_list,
                cg$rec.VALUE, cg$rec.description, cg$rec.comments,
                cg$rec.the_rowid;
            ELSE
               UPDATE nit_ci_property_values
               SET    creation_date    = cg$rec.creation_date
                     ,created_by       = cg$rec.created_by
                     ,last_update_date = cg$rec.last_update_date
                     ,last_updated_by  = cg$rec.last_updated_by
                     ,cip_id           = cg$rec.cip_id
                     ,is_default       = cg$rec.is_default
                     ,order_in_list    = cg$rec.order_in_list
                     ,VALUE            = cg$rec.VALUE
                     ,description      = cg$rec.description
                     ,comments         = cg$rec.comments
               WHERE  ROWID = cg$rec.the_rowid RETURNING id, creation_date,
                created_by, last_update_date, last_updated_by, cip_id,
                is_default, order_in_list, VALUE, description, comments,
                ROWID INTO cg$rec.id, cg$rec.creation_date,
                cg$rec.created_by, cg$rec.last_update_date,
                cg$rec.last_updated_by, cg$rec.cip_id, cg$rec.is_default,
                cg$rec.order_in_list, cg$rec.VALUE, cg$rec.description,
                cg$rec.comments, cg$rec.the_rowid;
            END IF;
            called_from_package := called_from;
         END;
      END IF;

      IF NOT (do_upd) THEN
         cg$table(idx).id := cg$rec.id;
         cg$tableind(idx).id := cg$ind.id;
         cg$table(idx).creation_date := cg$rec.creation_date;
         cg$tableind(idx).creation_date := cg$ind.creation_date;
         cg$table(idx).created_by := cg$rec.created_by;
         cg$tableind(idx).created_by := cg$ind.created_by;
         cg$table(idx).last_update_date := cg$rec.last_update_date;
         cg$tableind(idx).last_update_date := cg$ind.last_update_date;
         cg$table(idx).last_updated_by := cg$rec.last_updated_by;
         cg$tableind(idx).last_updated_by := cg$ind.last_updated_by;
         cg$table(idx).cip_id := cg$rec.cip_id;
         cg$tableind(idx).cip_id := cg$ind.cip_id;
         cg$table(idx).is_default := cg$rec.is_default;
         cg$tableind(idx).is_default := cg$ind.is_default;
         cg$table(idx).order_in_list := cg$rec.order_in_list;
         cg$tableind(idx).order_in_list := cg$ind.order_in_list;
         cg$table(idx).VALUE := cg$rec.VALUE;
         cg$tableind(idx).VALUE := cg$ind.VALUE;
         cg$table(idx).description := cg$rec.description;
         cg$tableind(idx).description := cg$ind.description;
         cg$table(idx).comments := cg$rec.comments;
         cg$tableind(idx).comments := cg$ind.comments;
         idx := idx + 1;
      END IF;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.upd_mandatory_null THEN
         validate_mandatory(cg$rec
                           ,'cg$NIT_CI_PROPERTY_VALUES.upd.upd_mandatory_null');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.check_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_check_con
                ,'cg$NIT_CI_PROPERTY_VALUES.upd.check_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.fk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_foreign_key
                ,'cg$NIT_CI_PROPERTY_VALUES.upd.fk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.uk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_unique_key
                ,'cg$NIT_CI_PROPERTY_VALUES.upd.uk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_PROPERTY_VALUES.upd.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END upd;

   --------------------------------------------------------------------------------
   -- Name:        del
   --
   -- Description: API delete procedure
   --
   -- Parameters:  cg$pk  Primary key record of row to be deleted
   --------------------------------------------------------------------------------
   PROCEDURE del(cg$pk  IN cg$pk_type
                ,do_del IN BOOLEAN DEFAULT TRUE) IS
   BEGIN
      --  Application_logic Pre-Delete <<Start>>
      --  Application_logic Pre-Delete << End >>

      --  Delete the record

      called_from_package := TRUE;

      IF (do_del) THEN
         BEGIN
            IF cg$pk.the_rowid IS NULL THEN
               DELETE nit_ci_property_values
               WHERE  id = cg$pk.id;
            ELSE
               DELETE nit_ci_property_values
               WHERE  ROWID = cg$pk.the_rowid;
            END IF;

         END;
      END IF;

      called_from_package := FALSE;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.delete_restrict THEN
         err_msg(SQLERRM
                ,cg$errors.err_delete_restrict
                ,'cg$NIT_CI_PROPERTY_VALUES.del.delete_restrict');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN no_data_found THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_row_del
                                            ,cg$errors.row_del)
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_PROPERTY_VALUES.del.no_data_found');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_PROPERTY_VALUES.del.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END del;

   --------------------------------------------------------------------------------
   -- Name:        lck
   --
   -- Description: API lock procedure
   --
   -- Parameters:  cg$old_rec  Calling apps view of record of row to be locked
   --              cg$old_ind  Record of columns to raise error if modified
   --              nowait_flag TRUE lock with NOWAIT, FALSE don't fail if busy
   --------------------------------------------------------------------------------
   PROCEDURE lck(cg$old_rec  IN cg$row_type
                ,cg$old_ind  IN cg$ind_type
                ,nowait_flag IN BOOLEAN DEFAULT TRUE) IS
      cg$tmp_rec   cg$row_type;
      any_modified BOOLEAN := FALSE;

   BEGIN
      --  Application_logic Pre-Lock <<Start>>
      --  Application_logic Pre-Lock << End >>

      --  Do the row lock

      BEGIN
         IF (nowait_flag) THEN
            IF cg$old_rec.the_rowid IS NULL THEN
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,cip_id
                     ,is_default
                     ,order_in_list
                     ,VALUE
                     ,description
                     ,comments
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.cip_id
                     ,cg$tmp_rec.is_default
                     ,cg$tmp_rec.order_in_list
                     ,cg$tmp_rec.VALUE
                     ,cg$tmp_rec.description
                     ,cg$tmp_rec.comments
               FROM   nit_ci_property_values
               WHERE  id = cg$old_rec.id
               FOR    UPDATE NOWAIT;
            ELSE
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,cip_id
                     ,is_default
                     ,order_in_list
                     ,VALUE
                     ,description
                     ,comments
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.cip_id
                     ,cg$tmp_rec.is_default
                     ,cg$tmp_rec.order_in_list
                     ,cg$tmp_rec.VALUE
                     ,cg$tmp_rec.description
                     ,cg$tmp_rec.comments
               FROM   nit_ci_property_values
               WHERE  ROWID = cg$old_rec.the_rowid
               FOR    UPDATE NOWAIT;
            END IF;
         ELSE
            IF cg$old_rec.the_rowid IS NULL THEN
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,cip_id
                     ,is_default
                     ,order_in_list
                     ,VALUE
                     ,description
                     ,comments
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.cip_id
                     ,cg$tmp_rec.is_default
                     ,cg$tmp_rec.order_in_list
                     ,cg$tmp_rec.VALUE
                     ,cg$tmp_rec.description
                     ,cg$tmp_rec.comments
               FROM   nit_ci_property_values
               WHERE  id = cg$old_rec.id
               FOR    UPDATE;
            ELSE
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,cip_id
                     ,is_default
                     ,order_in_list
                     ,VALUE
                     ,description
                     ,comments
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.cip_id
                     ,cg$tmp_rec.is_default
                     ,cg$tmp_rec.order_in_list
                     ,cg$tmp_rec.VALUE
                     ,cg$tmp_rec.description
                     ,cg$tmp_rec.comments
               FROM   nit_ci_property_values
               WHERE  ROWID = cg$old_rec.the_rowid
               FOR    UPDATE;
            END IF;
         END IF;

      EXCEPTION
         WHEN cg$errors.cg$error THEN
            cg$errors.raise_failure;
         WHEN cg$errors.resource_busy THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_lck
                                               ,cg$errors.row_lck)
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_CI_PROPERTY_VALUES.lck.resource_busy');
            cg$errors.raise_failure;
         WHEN no_data_found THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_del
                                               ,cg$errors.row_del)
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_CI_PROPERTY_VALUES.lck.no_data_found');
            cg$errors.raise_failure;
         WHEN OTHERS THEN
            cg$errors.push(SQLERRM
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_CI_PROPERTY_VALUES.lck.others');
            cg$errors.raise_failure;
      END;

      -- Optional Columns

      IF (cg$old_ind.description) THEN
         IF (cg$tmp_rec.description IS NOT NULL AND
            cg$old_rec.description IS NOT NULL) THEN
            IF (cg$tmp_rec.description != cg$old_rec.description) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p70description)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_PROPERTY_VALUES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.description IS NOT NULL OR
               cg$old_rec.description IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p70description)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTY_VALUES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.comments) THEN
         IF (cg$tmp_rec.comments IS NOT NULL AND
            cg$old_rec.comments IS NOT NULL) THEN
            IF (cg$tmp_rec.comments != cg$old_rec.comments) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p80comments)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_PROPERTY_VALUES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.comments IS NOT NULL OR
               cg$old_rec.comments IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p80comments)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTY_VALUES.lck');
            any_modified := TRUE;
         END IF;
      END IF;

      -- Mandatory Columns

      IF (cg$old_ind.id) THEN
         IF (cg$tmp_rec.id != cg$old_rec.id) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p10id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTY_VALUES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.creation_date) THEN
         IF (cg$tmp_rec.creation_date != cg$old_rec.creation_date) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p15creation_date)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTY_VALUES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.created_by) THEN
         IF (cg$tmp_rec.created_by != cg$old_rec.created_by) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p16created_by)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTY_VALUES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.last_update_date) THEN
         IF (cg$tmp_rec.last_update_date != cg$old_rec.last_update_date) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p19last_update_date)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTY_VALUES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.last_updated_by) THEN
         IF (cg$tmp_rec.last_updated_by != cg$old_rec.last_updated_by) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p24last_updated_by)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTY_VALUES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.cip_id) THEN
         IF (cg$tmp_rec.cip_id != cg$old_rec.cip_id) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p30cip_id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTY_VALUES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.is_default) THEN
         IF (cg$tmp_rec.is_default != cg$old_rec.is_default) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p50is_default)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTY_VALUES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.order_in_list) THEN
         IF (cg$tmp_rec.order_in_list != cg$old_rec.order_in_list) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p60order_in_list)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTY_VALUES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.VALUE) THEN
         IF (cg$tmp_rec.VALUE != cg$old_rec.VALUE) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p65value)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_PROPERTY_VALUES.lck');
            any_modified := TRUE;
         END IF;
      END IF;

      IF (any_modified) THEN
         cg$errors.raise_failure;
      END IF;

   END lck;

BEGIN
   cg$ind_true.id               := TRUE;
   cg$ind_true.creation_date    := TRUE;
   cg$ind_true.created_by       := TRUE;
   cg$ind_true.last_update_date := TRUE;
   cg$ind_true.last_updated_by  := TRUE;
   cg$ind_true.cip_id           := TRUE;
   cg$ind_true.is_default       := TRUE;
   cg$ind_true.order_in_list    := TRUE;
   cg$ind_true.VALUE            := TRUE;
   cg$ind_true.description      := TRUE;
   cg$ind_true.comments         := TRUE;

END cg$nit_ci_property_values;
/

prompt
prompt Creating package body CG$NIT_CI_RELATIONS
prompt =========================================
prompt
CREATE OR REPLACE PACKAGE BODY cg$nit_ci_relations IS


   PROCEDURE validate_mandatory(cg$val_rec IN cg$row_type
                               ,loc        IN VARCHAR2 DEFAULT '');
   PROCEDURE up_autogen_columns(cg$rec    IN OUT cg$row_type
                               ,cg$ind    IN OUT cg$ind_type
                               ,operation IN VARCHAR2 DEFAULT 'INS'
                               ,do_denorm IN BOOLEAN DEFAULT TRUE);
   PROCEDURE err_msg(msg  IN VARCHAR2
                    ,TYPE IN INTEGER
                    ,loc  IN VARCHAR2 DEFAULT '');

   --------------------------------------------------------------------------------
   -- Name:        raise_uk_not_updateable
   --
   -- Description: Raise appropriate error when unique key updated
   --
   -- Parameters:  none
   --------------------------------------------------------------------------------
   PROCEDURE raise_uk_not_updateable(uk IN VARCHAR2) IS
   BEGIN
      cg$errors.push(cg$errors.msggettext(cg$errors.api_unique_key_update
                                         ,cg$errors.err_uk_update
                                         ,uk)
                    ,'E'
                    ,'API'
                    ,cg$errors.api_unique_key_update
                    ,'cg$NIT_CI_RELATIONS.raise_uk_not_updateable');
      cg$errors.raise_failure;
   END raise_uk_not_updateable;


   --------------------------------------------------------------------------------
   -- Name:        raise_fk_not_transferable
   --
   -- Description: Raise appropriate error when foreign key updated
   --
   -- Parameters:  none
   --------------------------------------------------------------------------------
   PROCEDURE raise_fk_not_transferable(fk IN VARCHAR2) IS
   BEGIN
      cg$errors.push(cg$errors.msggettext(cg$errors.api_foreign_key_trans
                                         ,cg$errors.err_fk_trans
                                         ,fk)
                    ,'E'
                    ,'API'
                    ,cg$errors.api_foreign_key_trans
                    ,'cg$NIT_CI_RELATIONS.raise_fk_not_transferable');
      cg$errors.raise_failure;
   END raise_fk_not_transferable;


   --------------------------------------------------------------------------------
   -- Name:        up_autogen_columns
   --
   -- Description: Specific autogeneration of column values and conversion to
   --              uppercase
   --
   -- Parameters:  cg$rec    Record of row to be manipulated
   --              cg$ind    Indicators for row
   --              operation Procedure where this procedure was called
   --------------------------------------------------------------------------------
   PROCEDURE up_autogen_columns(cg$rec    IN OUT cg$row_type
                               ,cg$ind    IN OUT cg$ind_type
                               ,operation IN VARCHAR2 DEFAULT 'INS'
                               ,do_denorm IN BOOLEAN DEFAULT TRUE) IS
   BEGIN
      IF (operation = 'INS') THEN
         BEGIN
            IF (cg$ind.id = FALSE OR cg$rec.id IS NULL) THEN
               SELECT nit_seq.NEXTVAL
               INTO   cg$rec.id
               FROM   dual;
               cg$ind.id := TRUE;
            END IF;
         EXCEPTION
            WHEN OTHERS THEN
               cg$errors.push(SQLERRM
                             ,'E'
                             ,'ORA'
                             ,SQLCODE
                             ,'cg$NIT_CI_RELATIONS.up_autogen.ID.OTHERS');
               cg$errors.raise_failure;
         END;
      ELSE
         -- (operation = 'UPD')
         NULL;
      END IF; -- (operation = 'INS') ELSE (operation = 'UPD')

      -- Statements executed for both 'INS' and 'UPD'


   EXCEPTION
      WHEN no_data_found THEN
         NULL;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_RELATIONS.up_autogen_columns');
         cg$errors.raise_failure;
   END up_autogen_columns;


   --------------------------------------------------------------------------------
   -- Name:        validate_mandatory
   --
   -- Description: Checks all mandatory columns are not null and raises appropriate
   --              error if not satisfied
   --
   -- Parameters:  cg$val_rec Record of row to be checked
   --              loc        Place where this procedure was called for error
   --                         trapping
   --------------------------------------------------------------------------------
   PROCEDURE validate_mandatory(cg$val_rec IN cg$row_type
                               ,loc        IN VARCHAR2 DEFAULT '') IS
   BEGIN
      IF (cg$val_rec.id IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p10id)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.creation_date IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p15creation_date)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.created_by IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p16created_by)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.last_update_date IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p19last_update_date)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.last_updated_by IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p24last_updated_by)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.ci_id_from IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p27ci_id_from)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.ci_id_to IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p28ci_id_to)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.citr_id IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p30citr_id)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.opn_id IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p40opn_id)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.status IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p70status)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.obsolete IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p110obsolete)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.valid_from IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p120valid_from)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.valid_until IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p130valid_until)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
   END validate_mandatory;

   --------------------------------------------------------------------------------
   -- Name:        slct
   --
   -- Description: Selects into the given parameter all the attributes for the row
   --              given by the primary key
   --
   -- Parameters:  cg$sel_rec  Record of row to be selected into using its PK
   --------------------------------------------------------------------------------
   PROCEDURE slct(cg$sel_rec IN OUT cg$row_type) IS

   BEGIN

      IF cg$sel_rec.the_rowid IS NULL THEN
         SELECT id
               ,creation_date
               ,created_by
               ,last_update_date
               ,last_updated_by
               ,ci_id_from
               ,ci_id_to
               ,citr_id
               ,opn_id
               ,status
               ,obsolete
               ,valid_from
               ,valid_until
               ,comments
               ,ROWID
         INTO   cg$sel_rec.id
               ,cg$sel_rec.creation_date
               ,cg$sel_rec.created_by
               ,cg$sel_rec.last_update_date
               ,cg$sel_rec.last_updated_by
               ,cg$sel_rec.ci_id_from
               ,cg$sel_rec.ci_id_to
               ,cg$sel_rec.citr_id
               ,cg$sel_rec.opn_id
               ,cg$sel_rec.status
               ,cg$sel_rec.obsolete
               ,cg$sel_rec.valid_from
               ,cg$sel_rec.valid_until
               ,cg$sel_rec.comments
               ,cg$sel_rec.the_rowid
         FROM   nit_ci_relations
         WHERE  id = cg$sel_rec.id;
      ELSE
         SELECT id
               ,creation_date
               ,created_by
               ,last_update_date
               ,last_updated_by
               ,ci_id_from
               ,ci_id_to
               ,citr_id
               ,opn_id
               ,status
               ,obsolete
               ,valid_from
               ,valid_until
               ,comments
               ,ROWID
         INTO   cg$sel_rec.id
               ,cg$sel_rec.creation_date
               ,cg$sel_rec.created_by
               ,cg$sel_rec.last_update_date
               ,cg$sel_rec.last_updated_by
               ,cg$sel_rec.ci_id_from
               ,cg$sel_rec.ci_id_to
               ,cg$sel_rec.citr_id
               ,cg$sel_rec.opn_id
               ,cg$sel_rec.status
               ,cg$sel_rec.obsolete
               ,cg$sel_rec.valid_from
               ,cg$sel_rec.valid_until
               ,cg$sel_rec.comments
               ,cg$sel_rec.the_rowid
         FROM   nit_ci_relations
         WHERE  ROWID = cg$sel_rec.the_rowid;
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_RELATIONS.slct.others');
         cg$errors.raise_failure;

   END slct;

   --------------------------------------------------------------------------------
   -- Name:        validate_domain
   --
   -- Description: Checks against reference table for values lying in a domain
   --
   -- Parameters:  cg$rec     Record of NIT_CI_RELATIONS current values
   --------------------------------------------------------------------------------
   PROCEDURE validate_domain(cg$rec IN OUT cg$row_type
                            ,cg$ind IN cg$ind_type DEFAULT cg$ind_true) IS
      FOUND BOOLEAN;
      no_tabview EXCEPTION;
      PRAGMA EXCEPTION_INIT(no_tabview
                           ,-942);
   BEGIN

      FOUND := FALSE;
      IF (cg$ind.status AND cg$rec.status IS NOT NULL) THEN
         FOR c IN (SELECT rv_low_value
                         ,rv_high_value
                   FROM   cg_ref_codes
                   WHERE  rv_domain = 'OPERATABLE_STATUS') LOOP
            IF (c.rv_high_value IS NULL AND cg$rec.status = c.rv_low_value) OR
               (c.rv_high_value IS NOT NULL AND
               cg$rec.status BETWEEN c.rv_low_value AND c.rv_high_value) THEN
               FOUND := TRUE;
               EXIT;
            END IF;
         END LOOP;

         IF (NOT FOUND) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_rv_lookup_fail
                                               ,cg$errors.apimsg_rv_lookup_fail
                                               ,cg$rec.status
                                               ,'NIT_CI_RELATIONS'
                                               ,'STATUS')
                          ,'E'
                          ,'API'
                          ,cg$errors.api_rv_lookup_fail
                          ,'cg$NIT_CI_RELATIONS.v_domain.no_data_found');
            cg$errors.raise_failure;
         END IF;
      END IF;

      FOUND := FALSE;
      IF (cg$ind.obsolete AND cg$rec.obsolete IS NOT NULL) THEN
         FOR c IN (SELECT rv_low_value
                         ,rv_high_value
                   FROM   cg_ref_codes
                   WHERE  rv_domain = 'OBSOLETE') LOOP
            IF (c.rv_high_value IS NULL AND cg$rec.obsolete = c.rv_low_value) OR
               (c.rv_high_value IS NOT NULL AND
               cg$rec.obsolete BETWEEN c.rv_low_value AND c.rv_high_value) THEN
               FOUND := TRUE;
               EXIT;
            END IF;
         END LOOP;

         IF (NOT FOUND) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_rv_lookup_fail
                                               ,cg$errors.apimsg_rv_lookup_fail
                                               ,cg$rec.obsolete
                                               ,'NIT_CI_RELATIONS'
                                               ,'OBSOLETE')
                          ,'E'
                          ,'API'
                          ,cg$errors.api_rv_lookup_fail
                          ,'cg$NIT_CI_RELATIONS.v_domain.no_data_found');
            cg$errors.raise_failure;
         END IF;
      END IF;





      NULL;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         cg$errors.raise_failure;
      WHEN no_tabview THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_rv_tab_not_found
                                            ,cg$errors.apimsg_rv_tab_not_found
                                            ,'CG_REF_CODES'
                                            ,'NIT_CI_RELATIONS')
                       ,'E'
                       ,'API'
                       ,cg$errors.api_rv_tab_not_found
                       ,'cg$NIT_CI_RELATIONS.v_domain.no_reftable_found');
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_RELATIONS.v_domain.others');
         cg$errors.raise_failure;
   END validate_domain;

   --------------------------------------------------------------------------------
   -- Name:        err_msg
   --
   -- Description: Pushes onto stack appropriate user defined error message
   --              depending on the rule violated
   --
   -- Parameters:  msg     Oracle error message
   --              type    Type of violation e.g. check_constraint: ERR_CHECK_CON
   --              loc     Place where this procedure was called for error
   --                      trapping
   --------------------------------------------------------------------------------
   PROCEDURE err_msg(msg  IN VARCHAR2
                    ,TYPE IN INTEGER
                    ,loc  IN VARCHAR2 DEFAULT '') IS
      con_name VARCHAR2(240);
   BEGIN
      con_name := cg$errors.parse_constraint(msg
                                            ,TYPE);
      IF (con_name = 'NIT_CPK_CIR') THEN
         cg$errors.push(NVL(nit_cpk_cir
                           ,cg$errors.msggettext(cg$errors.api_pk_con_violated
                                                ,cg$errors.apimsg_pk_violat
                                                ,'NIT_CPK_CIR'
                                                ,'NIT_CI_RELATIONS'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_pk_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CTC_CIR_SELF_REF_DENY' AND
            nit_ctc_cir_self_ref_deny IS NOT NULL) THEN
         cg$errors.push(''
                       ,'E'
                       ,'API'
                       ,cg$errors.api_ck_con_violated
                       ,loc);

      ELSIF (con_name = 'NIT_CFK_CIR_CI_TO') THEN
         cg$errors.push(NVL(nit_cfk_cir_ci_to
                           ,cg$errors.msggettext(cg$errors.api_fk_con_violated
                                                ,cg$errors.apimsg_fk_violat
                                                ,'NIT_CFK_CIR_CI_TO'
                                                ,'NIT_CI_RELATIONS'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_fk_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CFK_CIR_CI_FROM') THEN
         cg$errors.push(NVL(nit_cfk_cir_ci_from
                           ,cg$errors.msggettext(cg$errors.api_fk_con_violated
                                                ,cg$errors.apimsg_fk_violat
                                                ,'NIT_CFK_CIR_CI_FROM'
                                                ,'NIT_CI_RELATIONS'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_fk_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CFK_CIR_CITR') THEN
         cg$errors.push(NVL(nit_cfk_cir_citr
                           ,cg$errors.msggettext(cg$errors.api_fk_con_violated
                                                ,cg$errors.apimsg_fk_violat
                                                ,'NIT_CFK_CIR_CITR'
                                                ,'NIT_CI_RELATIONS'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_fk_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CFK_CIR_OPN') THEN
         cg$errors.push(NVL(nit_cfk_cir_opn
                           ,cg$errors.msggettext(cg$errors.api_fk_con_violated
                                                ,cg$errors.apimsg_fk_violat
                                                ,'NIT_CFK_CIR_OPN'
                                                ,'NIT_CI_RELATIONS'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_fk_con_violated
                       ,loc);
      ELSE
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,loc);
      END IF;
   END err_msg;

   --------------------------------------------------------------------------------
   -- Name:        ins
   --
   -- Description: API insert procedure
   --
   -- Parameters:  cg$rec  Record of row to be inserted
   --              cg$ind  Record of columns specifically set
   --              do_ins  Whether we want the actual INSERT to occur
   --------------------------------------------------------------------------------
   PROCEDURE ins(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_ins IN BOOLEAN DEFAULT TRUE) IS

      --  Constant default values

      d110_obsolete CONSTANT nit_ci_relations.obsolete%TYPE := 'L';

   BEGIN
      nit_ci_relations_p.pre_dml(cg$rec
                                ,cg$ind
                                ,'INS');

      --  Defaulted

      IF NOT (cg$ind.obsolete) THEN
         cg$rec.obsolete := d110_obsolete;
      END IF;
      --  Auto-generated and uppercased columns

      up_autogen_columns(cg$rec
                        ,cg$ind
                        ,'INS'
                        ,do_ins);

      called_from_package := TRUE;

      IF (do_ins) THEN
         validate_domain(cg$rec);

         INSERT INTO nit_ci_relations
            (id
            ,creation_date
            ,created_by
            ,last_update_date
            ,last_updated_by
            ,ci_id_from
            ,ci_id_to
            ,citr_id
            ,opn_id
            ,status
            ,obsolete
            ,valid_from
            ,valid_until
            ,comments)
         VALUES
            (cg$rec.id
            ,cg$rec.creation_date
            ,cg$rec.created_by
            ,cg$rec.last_update_date
            ,cg$rec.last_updated_by
            ,cg$rec.ci_id_from
            ,cg$rec.ci_id_to
            ,cg$rec.citr_id
            ,cg$rec.opn_id
            ,cg$rec.status
            ,cg$rec.obsolete
            ,cg$rec.valid_from
            ,cg$rec.valid_until
            ,cg$rec.comments)
         RETURNING id, creation_date, created_by, last_update_date, last_updated_by, ci_id_from, ci_id_to, citr_id, opn_id, status, obsolete, valid_from, valid_until, comments, ROWID INTO cg$rec.id, cg$rec.creation_date, cg$rec.created_by, cg$rec.last_update_date, cg$rec.last_updated_by, cg$rec.ci_id_from, cg$rec.ci_id_to, cg$rec.citr_id, cg$rec.opn_id, cg$rec.status, cg$rec.obsolete, cg$rec.valid_from, cg$rec.valid_until, cg$rec.comments, cg$rec.the_rowid;
      END IF;

      called_from_package := FALSE;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.mandatory_missing THEN
         validate_mandatory(cg$rec
                           ,'cg$NIT_CI_RELATIONS.ins.mandatory_missing');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.check_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_check_con
                ,'cg$NIT_CI_RELATIONS.ins.check_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.fk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_foreign_key
                ,'cg$NIT_CI_RELATIONS.ins.fk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.uk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_unique_key
                ,'cg$NIT_CI_RELATIONS.ins.uk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_RELATIONS.ins.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END ins;


   --------------------------------------------------------------------------------
   -- Name:        upd
   --
   -- Description: API update procedure
   --
   -- Parameters:  cg$rec  Record of row to be updated
   --              cg$ind  Record of columns specifically set
   --              do_upd  Whether we want the actual UPDATE to occur
   --------------------------------------------------------------------------------
   PROCEDURE upd(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_upd IN BOOLEAN DEFAULT TRUE
                ,cg$pk  IN cg$row_type DEFAULT NULL) IS
      cg$upd_rec cg$row_type;
      cg$old_rec cg$row_type;
   BEGIN
      nit_ci_relations_p.pre_dml(cg$rec
                                ,cg$ind
                                ,'UPD');
      nit_ci_relations_p.pre_upd(cg$rec
                                ,cg$ind);


      IF (cg$pk.id IS NULL) THEN
         cg$upd_rec.id := cg$rec.id;
      ELSE
         cg$upd_rec.id := cg$pk.id;
      END IF;
      cg$old_rec.id := cg$upd_rec.id;

      IF (cg$pk.the_rowid IS NULL) THEN
         cg$upd_rec.the_rowid := cg$rec.the_rowid;
      ELSE
         cg$upd_rec.the_rowid := cg$pk.the_rowid;
      END IF;
      cg$old_rec.the_rowid := cg$upd_rec.the_rowid;

      IF (do_upd) THEN

         slct(cg$upd_rec);

         --  Report error if attempt to update non transferable Foreign Key NIT_CFK_CIR_CITR
         IF (cg$ind.citr_id AND cg$rec.citr_id != cg$upd_rec.citr_id) THEN
            raise_fk_not_transferable('NIT_CFK_CIR_CITR');
         END IF;
         IF (cg$ind.citr_id AND cg$rec.citr_id IS NULL AND
            cg$upd_rec.citr_id IS NOT NULL) THEN
            raise_fk_not_transferable('NIT_CFK_CIR_CITR');
         END IF;
         IF (cg$ind.citr_id AND cg$rec.citr_id IS NOT NULL AND
            cg$upd_rec.citr_id IS NULL) THEN
            raise_fk_not_transferable('NIT_CFK_CIR_CITR');
         END IF;
         --  Report error if attempt to update non transferable Foreign Key NIT_CFK_CIR_OPN
         IF (cg$ind.opn_id AND cg$rec.opn_id != cg$upd_rec.opn_id) THEN
            raise_fk_not_transferable('NIT_CFK_CIR_OPN');
         END IF;
         IF (cg$ind.opn_id AND cg$rec.opn_id IS NULL AND
            cg$upd_rec.opn_id IS NOT NULL) THEN
            raise_fk_not_transferable('NIT_CFK_CIR_OPN');
         END IF;
         IF (cg$ind.opn_id AND cg$rec.opn_id IS NOT NULL AND
            cg$upd_rec.opn_id IS NULL) THEN
            raise_fk_not_transferable('NIT_CFK_CIR_OPN');
         END IF;

         --  Report error if attempt to update non updateable Primary Key NIT_CPK_CIR
         IF (cg$ind.id AND cg$rec.id != cg$upd_rec.id) THEN
            raise_uk_not_updateable('NIT_CPK_CIR');
         END IF;
         IF NOT (cg$ind.id) THEN
            cg$rec.id := cg$upd_rec.id;
         END IF;
         IF NOT (cg$ind.creation_date) THEN
            cg$rec.creation_date := cg$upd_rec.creation_date;
         END IF;
         IF NOT (cg$ind.created_by) THEN
            cg$rec.created_by := cg$upd_rec.created_by;
         END IF;
         IF NOT (cg$ind.last_update_date) THEN
            cg$rec.last_update_date := cg$upd_rec.last_update_date;
         END IF;
         IF NOT (cg$ind.last_updated_by) THEN
            cg$rec.last_updated_by := cg$upd_rec.last_updated_by;
         END IF;
         IF NOT (cg$ind.ci_id_from) THEN
            cg$rec.ci_id_from := cg$upd_rec.ci_id_from;
         END IF;
         IF NOT (cg$ind.ci_id_to) THEN
            cg$rec.ci_id_to := cg$upd_rec.ci_id_to;
         END IF;
         IF NOT (cg$ind.citr_id) THEN
            cg$rec.citr_id := cg$upd_rec.citr_id;
         END IF;
         IF NOT (cg$ind.opn_id) THEN
            cg$rec.opn_id := cg$upd_rec.opn_id;
         END IF;
         IF NOT (cg$ind.status) THEN
            cg$rec.status := cg$upd_rec.status;
         END IF;
         IF NOT (cg$ind.obsolete) THEN
            cg$rec.obsolete := cg$upd_rec.obsolete;
         END IF;
         IF NOT (cg$ind.valid_from) THEN
            cg$rec.valid_from := cg$upd_rec.valid_from;
         END IF;
         IF NOT (cg$ind.valid_until) THEN
            cg$rec.valid_until := cg$upd_rec.valid_until;
         END IF;
         IF NOT (cg$ind.comments) THEN
            cg$rec.comments := cg$upd_rec.comments;
         END IF;
      ELSE
         --  Report error if attempt to update non transferable Foreign Key NIT_CFK_CIR_CITR
         IF (cg$ind.citr_id) THEN
            raise_fk_not_transferable('NIT_CFK_CIR_CITR');
         END IF;
         --  Report error if attempt to update non transferable Foreign Key NIT_CFK_CIR_OPN
         IF (cg$ind.opn_id) THEN
            raise_fk_not_transferable('NIT_CFK_CIR_OPN');
         END IF;
         --  Report error if attempt to update non updateable Primary Key NIT_CPK_CIR
         IF (cg$ind.id) THEN
            raise_uk_not_updateable('NIT_CPK_CIR');
         END IF;
      END IF;

      up_autogen_columns(cg$rec
                        ,cg$ind
                        ,'UPD'
                        ,do_upd); --  Auto-generated and uppercased columns

      --  Now do update if updateable columns exist
      IF (do_upd) THEN
         DECLARE
            called_from BOOLEAN := called_from_package;
         BEGIN
            called_from_package := TRUE;

            slct(cg$old_rec);
            validate_domain(cg$rec
                           ,cg$ind);

            IF cg$rec.the_rowid IS NULL THEN
               UPDATE nit_ci_relations
               SET    creation_date    = cg$rec.creation_date
                     ,created_by       = cg$rec.created_by
                     ,last_update_date = cg$rec.last_update_date
                     ,last_updated_by  = cg$rec.last_updated_by
                     ,ci_id_from       = cg$rec.ci_id_from
                     ,ci_id_to         = cg$rec.ci_id_to
                     ,citr_id          = cg$rec.citr_id
                     ,opn_id           = cg$rec.opn_id
                     ,status           = cg$rec.status
                     ,obsolete         = cg$rec.obsolete
                     ,valid_from       = cg$rec.valid_from
                     ,valid_until      = cg$rec.valid_until
                     ,comments         = cg$rec.comments
               WHERE  id = cg$rec.id RETURNING id, creation_date, created_by,
                last_update_date, last_updated_by, ci_id_from, ci_id_to,
                citr_id, opn_id, status, obsolete, valid_from,
                valid_until, comments, ROWID INTO cg$rec.id,
                cg$rec.creation_date, cg$rec.created_by,
                cg$rec.last_update_date, cg$rec.last_updated_by,
                cg$rec.ci_id_from, cg$rec.ci_id_to, cg$rec.citr_id,
                cg$rec.opn_id, cg$rec.status, cg$rec.obsolete,
                cg$rec.valid_from, cg$rec.valid_until, cg$rec.comments,
                cg$rec.the_rowid;
            ELSE
               UPDATE nit_ci_relations
               SET    creation_date    = cg$rec.creation_date
                     ,created_by       = cg$rec.created_by
                     ,last_update_date = cg$rec.last_update_date
                     ,last_updated_by  = cg$rec.last_updated_by
                     ,ci_id_from       = cg$rec.ci_id_from
                     ,ci_id_to         = cg$rec.ci_id_to
                     ,citr_id          = cg$rec.citr_id
                     ,opn_id           = cg$rec.opn_id
                     ,status           = cg$rec.status
                     ,obsolete         = cg$rec.obsolete
                     ,valid_from       = cg$rec.valid_from
                     ,valid_until      = cg$rec.valid_until
                     ,comments         = cg$rec.comments
               WHERE  ROWID = cg$rec.the_rowid RETURNING id, creation_date,
                created_by, last_update_date, last_updated_by, ci_id_from,
                ci_id_to, citr_id, opn_id, status, obsolete, valid_from,
                valid_until, comments, ROWID INTO cg$rec.id,
                cg$rec.creation_date, cg$rec.created_by,
                cg$rec.last_update_date, cg$rec.last_updated_by,
                cg$rec.ci_id_from, cg$rec.ci_id_to, cg$rec.citr_id,
                cg$rec.opn_id, cg$rec.status, cg$rec.obsolete,
                cg$rec.valid_from, cg$rec.valid_until, cg$rec.comments,
                cg$rec.the_rowid;

            END IF;
            called_from_package := called_from;
         END;
      END IF;



      IF NOT (do_upd) THEN
         cg$table(idx).id := cg$rec.id;
         cg$tableind(idx).id := cg$ind.id;
         cg$table(idx).creation_date := cg$rec.creation_date;
         cg$tableind(idx).creation_date := cg$ind.creation_date;
         cg$table(idx).created_by := cg$rec.created_by;
         cg$tableind(idx).created_by := cg$ind.created_by;
         cg$table(idx).last_update_date := cg$rec.last_update_date;
         cg$tableind(idx).last_update_date := cg$ind.last_update_date;
         cg$table(idx).last_updated_by := cg$rec.last_updated_by;
         cg$tableind(idx).last_updated_by := cg$ind.last_updated_by;
         cg$table(idx).ci_id_from := cg$rec.ci_id_from;
         cg$tableind(idx).ci_id_from := cg$ind.ci_id_from;
         cg$table(idx).ci_id_to := cg$rec.ci_id_to;
         cg$tableind(idx).ci_id_to := cg$ind.ci_id_to;
         cg$table(idx).citr_id := cg$rec.citr_id;
         cg$tableind(idx).citr_id := cg$ind.citr_id;
         cg$table(idx).opn_id := cg$rec.opn_id;
         cg$tableind(idx).opn_id := cg$ind.opn_id;
         cg$table(idx).status := cg$rec.status;
         cg$tableind(idx).status := cg$ind.status;
         cg$table(idx).obsolete := cg$rec.obsolete;
         cg$tableind(idx).obsolete := cg$ind.obsolete;
         cg$table(idx).valid_from := cg$rec.valid_from;
         cg$tableind(idx).valid_from := cg$ind.valid_from;
         cg$table(idx).valid_until := cg$rec.valid_until;
         cg$tableind(idx).valid_until := cg$ind.valid_until;
         cg$table(idx).comments := cg$rec.comments;
         cg$tableind(idx).comments := cg$ind.comments;
         idx := idx + 1;
      END IF;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.upd_mandatory_null THEN
         validate_mandatory(cg$rec
                           ,'cg$NIT_CI_RELATIONS.upd.upd_mandatory_null');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.check_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_check_con
                ,'cg$NIT_CI_RELATIONS.upd.check_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.fk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_foreign_key
                ,'cg$NIT_CI_RELATIONS.upd.fk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.uk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_unique_key
                ,'cg$NIT_CI_RELATIONS.upd.uk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_RELATIONS.upd.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END upd;

   --------------------------------------------------------------------------------
   -- Name:        del
   --
   -- Description: API delete procedure
   --
   -- Parameters:  cg$pk  Primary key record of row to be deleted
   --------------------------------------------------------------------------------
   PROCEDURE del(cg$pk  IN cg$pk_type
                ,do_del IN BOOLEAN DEFAULT TRUE) IS
   BEGIN
      --  Application_logic Pre-Delete <<Start>>
      raise_application_error(-20001
                             ,'A t?rl?s ?gy nem megengedett');
      --  Application_logic Pre-Delete << End >>

      --  Delete the record

      called_from_package := TRUE;

      IF (do_del) THEN
         BEGIN
            IF cg$pk.the_rowid IS NULL THEN
               DELETE nit_ci_relations
               WHERE  id = cg$pk.id;
            ELSE
               DELETE nit_ci_relations
               WHERE  ROWID = cg$pk.the_rowid;
            END IF;
         END;
      END IF;

      called_from_package := FALSE;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.delete_restrict THEN
         err_msg(SQLERRM
                ,cg$errors.err_delete_restrict
                ,'cg$NIT_CI_RELATIONS.del.delete_restrict');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN no_data_found THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_row_del
                                            ,cg$errors.row_del)
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_RELATIONS.del.no_data_found');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_RELATIONS.del.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END del;


   --------------------------------------------------------------------------------
   -- Name:        lck
   --
   -- Description: API lock procedure
   --
   -- Parameters:  cg$old_rec  Calling apps view of record of row to be locked
   --              cg$old_ind  Record of columns to raise error if modified
   --              nowait_flag TRUE lock with NOWAIT, FALSE don't fail if busy
   --------------------------------------------------------------------------------
   PROCEDURE lck(cg$old_rec  IN cg$row_type
                ,cg$old_ind  IN cg$ind_type
                ,nowait_flag IN BOOLEAN DEFAULT TRUE) IS
      cg$tmp_rec   cg$row_type;
      any_modified BOOLEAN := FALSE;

   BEGIN
      --  Do the row lock

      BEGIN
         IF (nowait_flag) THEN
            IF cg$old_rec.the_rowid IS NULL THEN
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,ci_id_from
                     ,ci_id_to
                     ,citr_id
                     ,opn_id
                     ,status
                     ,obsolete
                     ,valid_from
                     ,valid_until
                     ,comments
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.ci_id_from
                     ,cg$tmp_rec.ci_id_to
                     ,cg$tmp_rec.citr_id
                     ,cg$tmp_rec.opn_id
                     ,cg$tmp_rec.status
                     ,cg$tmp_rec.obsolete
                     ,cg$tmp_rec.valid_from
                     ,cg$tmp_rec.valid_until
                     ,cg$tmp_rec.comments
               FROM   nit_ci_relations
               WHERE  id = cg$old_rec.id
               FOR    UPDATE NOWAIT;
            ELSE
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,ci_id_from
                     ,ci_id_to
                     ,citr_id
                     ,opn_id
                     ,status
                     ,obsolete
                     ,valid_from
                     ,valid_until
                     ,comments
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.ci_id_from
                     ,cg$tmp_rec.ci_id_to
                     ,cg$tmp_rec.citr_id
                     ,cg$tmp_rec.opn_id
                     ,cg$tmp_rec.status
                     ,cg$tmp_rec.obsolete
                     ,cg$tmp_rec.valid_from
                     ,cg$tmp_rec.valid_until
                     ,cg$tmp_rec.comments
               FROM   nit_ci_relations
               WHERE  ROWID = cg$old_rec.the_rowid
               FOR    UPDATE NOWAIT;
            END IF;
         ELSE
            IF cg$old_rec.the_rowid IS NULL THEN
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,ci_id_from
                     ,ci_id_to
                     ,citr_id
                     ,opn_id
                     ,status
                     ,obsolete
                     ,valid_from
                     ,valid_until
                     ,comments
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.ci_id_from
                     ,cg$tmp_rec.ci_id_to
                     ,cg$tmp_rec.citr_id
                     ,cg$tmp_rec.opn_id
                     ,cg$tmp_rec.status
                     ,cg$tmp_rec.obsolete
                     ,cg$tmp_rec.valid_from
                     ,cg$tmp_rec.valid_until
                     ,cg$tmp_rec.comments
               FROM   nit_ci_relations
               WHERE  id = cg$old_rec.id
               FOR    UPDATE;
            ELSE
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,ci_id_from
                     ,ci_id_to
                     ,citr_id
                     ,opn_id
                     ,status
                     ,obsolete
                     ,valid_from
                     ,valid_until
                     ,comments
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.ci_id_from
                     ,cg$tmp_rec.ci_id_to
                     ,cg$tmp_rec.citr_id
                     ,cg$tmp_rec.opn_id
                     ,cg$tmp_rec.status
                     ,cg$tmp_rec.obsolete
                     ,cg$tmp_rec.valid_from
                     ,cg$tmp_rec.valid_until
                     ,cg$tmp_rec.comments
               FROM   nit_ci_relations
               WHERE  ROWID = cg$old_rec.the_rowid
               FOR    UPDATE;
            END IF;
         END IF;

      EXCEPTION
         WHEN cg$errors.cg$error THEN
            cg$errors.raise_failure;
         WHEN cg$errors.resource_busy THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_lck
                                               ,cg$errors.row_lck)
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_CI_RELATIONS.lck.resource_busy');
            cg$errors.raise_failure;
         WHEN no_data_found THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_del
                                               ,cg$errors.row_del)
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_CI_RELATIONS.lck.no_data_found');
            cg$errors.raise_failure;
         WHEN OTHERS THEN
            cg$errors.push(SQLERRM
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_CI_RELATIONS.lck.others');
            cg$errors.raise_failure;
      END;

      -- Optional Columns

      IF (cg$old_ind.comments) THEN
         IF (cg$tmp_rec.comments IS NOT NULL AND
            cg$old_rec.comments IS NOT NULL) THEN
            IF (cg$tmp_rec.comments != cg$old_rec.comments) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p140comments)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_RELATIONS.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.comments IS NOT NULL OR
               cg$old_rec.comments IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p140comments)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_RELATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;

      -- Mandatory Columns

      IF (cg$old_ind.id) THEN
         IF (cg$tmp_rec.id != cg$old_rec.id) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p10id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_RELATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.creation_date) THEN
         IF (cg$tmp_rec.creation_date != cg$old_rec.creation_date) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p15creation_date)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_RELATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.created_by) THEN
         IF (cg$tmp_rec.created_by != cg$old_rec.created_by) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p16created_by)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_RELATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.last_update_date) THEN
         IF (cg$tmp_rec.last_update_date != cg$old_rec.last_update_date) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p19last_update_date)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_RELATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.last_updated_by) THEN
         IF (cg$tmp_rec.last_updated_by != cg$old_rec.last_updated_by) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p24last_updated_by)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_RELATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.ci_id_from) THEN
         IF (cg$tmp_rec.ci_id_from != cg$old_rec.ci_id_from) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p27ci_id_from)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_RELATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.ci_id_to) THEN
         IF (cg$tmp_rec.ci_id_to != cg$old_rec.ci_id_to) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p28ci_id_to)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_RELATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.citr_id) THEN
         IF (cg$tmp_rec.citr_id != cg$old_rec.citr_id) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p30citr_id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_RELATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.opn_id) THEN
         IF (cg$tmp_rec.opn_id != cg$old_rec.opn_id) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p40opn_id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_RELATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.status) THEN
         IF (cg$tmp_rec.status != cg$old_rec.status) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p70status)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_RELATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.obsolete) THEN
         IF (cg$tmp_rec.obsolete != cg$old_rec.obsolete) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p110obsolete)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_RELATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.valid_from) THEN
         IF (cg$tmp_rec.valid_from != cg$old_rec.valid_from) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p120valid_from)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_RELATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.valid_until) THEN
         IF (cg$tmp_rec.valid_until != cg$old_rec.valid_until) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p130valid_until)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_RELATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;

      IF (any_modified) THEN
         cg$errors.raise_failure;
      END IF;

   END lck;


BEGIN
   cg$ind_true.id               := TRUE;
   cg$ind_true.creation_date    := TRUE;
   cg$ind_true.created_by       := TRUE;
   cg$ind_true.last_update_date := TRUE;
   cg$ind_true.last_updated_by  := TRUE;
   cg$ind_true.ci_id_from       := TRUE;
   cg$ind_true.ci_id_to         := TRUE;
   cg$ind_true.citr_id          := TRUE;
   cg$ind_true.opn_id           := TRUE;
   cg$ind_true.status           := TRUE;
   cg$ind_true.obsolete         := TRUE;
   cg$ind_true.valid_from       := TRUE;
   cg$ind_true.valid_until      := TRUE;
   cg$ind_true.comments         := TRUE;

END cg$nit_ci_relations;
/

prompt
prompt Creating package body CG$NIT_CIT_RELATION_TYPES
prompt ===============================================
prompt
CREATE OR REPLACE PACKAGE BODY cg$nit_cit_relation_types IS


   PROCEDURE validate_mandatory(cg$val_rec IN cg$row_type
                               ,loc        IN VARCHAR2 DEFAULT '');
   PROCEDURE up_autogen_columns(cg$rec    IN OUT cg$row_type
                               ,cg$ind    IN OUT cg$ind_type
                               ,operation IN VARCHAR2 DEFAULT 'INS'
                               ,do_denorm IN BOOLEAN DEFAULT TRUE);
   PROCEDURE err_msg(msg  IN VARCHAR2
                    ,TYPE IN INTEGER
                    ,loc  IN VARCHAR2 DEFAULT '');

   --------------------------------------------------------------------------------
   -- Name:        raise_uk_not_updateable
   --
   -- Description: Raise appropriate error when unique key updated
   --
   -- Parameters:  none
   --------------------------------------------------------------------------------
   PROCEDURE raise_uk_not_updateable(uk IN VARCHAR2) IS
   BEGIN
      cg$errors.push(cg$errors.msggettext(cg$errors.api_unique_key_update
                                         ,cg$errors.err_uk_update
                                         ,uk)
                    ,'E'
                    ,'API'
                    ,cg$errors.api_unique_key_update
                    ,'cg$NIT_CIT_RELATION_TYPES.raise_uk_not_updateable');
      cg$errors.raise_failure;
   END raise_uk_not_updateable;


   --------------------------------------------------------------------------------
   -- Name:        raise_fk_not_transferable
   --
   -- Description: Raise appropriate error when foreign key updated
   --
   -- Parameters:  none
   --------------------------------------------------------------------------------
   PROCEDURE raise_fk_not_transferable(fk IN VARCHAR2) IS
   BEGIN
      cg$errors.push(cg$errors.msggettext(cg$errors.api_foreign_key_trans
                                         ,cg$errors.err_fk_trans
                                         ,fk)
                    ,'E'
                    ,'API'
                    ,cg$errors.api_foreign_key_trans
                    ,'cg$NIT_CIT_RELATION_TYPES.raise_fk_not_transferable');
      cg$errors.raise_failure;
   END raise_fk_not_transferable;


   --------------------------------------------------------------------------------
   -- Name:        up_autogen_columns
   --
   -- Description: Specific autogeneration of column values and conversion to
   --              uppercase
   --
   -- Parameters:  cg$rec    Record of row to be manipulated
   --              cg$ind    Indicators for row
   --              operation Procedure where this procedure was called
   --------------------------------------------------------------------------------
   PROCEDURE up_autogen_columns(cg$rec    IN OUT cg$row_type
                               ,cg$ind    IN OUT cg$ind_type
                               ,operation IN VARCHAR2 DEFAULT 'INS'
                               ,do_denorm IN BOOLEAN DEFAULT TRUE) IS
   BEGIN
      IF (operation = 'INS') THEN
         BEGIN
            IF (cg$ind.id = FALSE OR cg$rec.id IS NULL) THEN
               SELECT nit_seq.NEXTVAL
               INTO   cg$rec.id
               FROM   dual;
               cg$ind.id := TRUE;
            END IF;
         EXCEPTION
            WHEN OTHERS THEN
               cg$errors.push(SQLERRM
                             ,'E'
                             ,'ORA'
                             ,SQLCODE
                             ,'cg$NIT_CIT_RELATION_TYPES.up_autogen.ID.OTHERS');
               cg$errors.raise_failure;
         END;
      ELSE
         NULL;
      END IF; -- (operation = 'INS') ELSE (operation = 'UPD')

      -- Statements executed for both 'INS' and 'UPD'


   EXCEPTION
      WHEN no_data_found THEN
         NULL;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CIT_RELATION_TYPES.up_autogen_columns');
         cg$errors.raise_failure;
   END up_autogen_columns;


   --------------------------------------------------------------------------------
   -- Name:        validate_mandatory
   --
   -- Description: Checks all mandatory columns are not null and raises appropriate
   --              error if not satisfied
   --
   -- Parameters:  cg$val_rec Record of row to be checked
   --              loc        Place where this procedure was called for error
   --                         trapping
   --------------------------------------------------------------------------------
   PROCEDURE validate_mandatory(cg$val_rec IN cg$row_type
                               ,loc        IN VARCHAR2 DEFAULT '') IS
   BEGIN
      IF (cg$val_rec.id IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p5id)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.creation_date IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p10creation_date)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.created_by IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p15created_by)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.last_update_date IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p18last_update_date)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.last_updated_by IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p19last_updated_by)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.NAME IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p36name)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      NULL;
   END validate_mandatory;

   --------------------------------------------------------------------------------
   -- Name:        slct
   --
   -- Description: Selects into the given parameter all the attributes for the row
   --              given by the primary key
   --
   -- Parameters:  cg$sel_rec  Record of row to be selected into using its PK
   --------------------------------------------------------------------------------
   PROCEDURE slct(cg$sel_rec IN OUT cg$row_type) IS

   BEGIN

      IF cg$sel_rec.the_rowid IS NULL THEN
         SELECT id
               ,creation_date
               ,created_by
               ,last_update_date
               ,last_updated_by
               ,NAME
               ,description
               ,comments
               ,ROWID
         INTO   cg$sel_rec.id
               ,cg$sel_rec.creation_date
               ,cg$sel_rec.created_by
               ,cg$sel_rec.last_update_date
               ,cg$sel_rec.last_updated_by
               ,cg$sel_rec.NAME
               ,cg$sel_rec.description
               ,cg$sel_rec.comments
               ,cg$sel_rec.the_rowid
         FROM   nit_cit_relation_types
         WHERE  id = cg$sel_rec.id;
      ELSE
         SELECT id
               ,creation_date
               ,created_by
               ,last_update_date
               ,last_updated_by
               ,NAME
               ,description
               ,comments
               ,ROWID
         INTO   cg$sel_rec.id
               ,cg$sel_rec.creation_date
               ,cg$sel_rec.created_by
               ,cg$sel_rec.last_update_date
               ,cg$sel_rec.last_updated_by
               ,cg$sel_rec.NAME
               ,cg$sel_rec.description
               ,cg$sel_rec.comments
               ,cg$sel_rec.the_rowid
         FROM   nit_cit_relation_types
         WHERE  ROWID = cg$sel_rec.the_rowid;
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CIT_RELATION_TYPES.slct.others');
         cg$errors.raise_failure;

   END slct;

   --------------------------------------------------------------------------------
   -- Name:        err_msg
   --
   -- Description: Pushes onto stack appropriate user defined error message
   --              depending on the rule violated
   --
   -- Parameters:  msg     Oracle error message
   --              type    Type of violation e.g. check_constraint: ERR_CHECK_CON
   --              loc     Place where this procedure was called for error
   --                      trapping
   --------------------------------------------------------------------------------
   PROCEDURE err_msg(msg  IN VARCHAR2
                    ,TYPE IN INTEGER
                    ,loc  IN VARCHAR2 DEFAULT '') IS
      con_name VARCHAR2(240);
   BEGIN
      con_name := cg$errors.parse_constraint(msg
                                            ,TYPE);
      IF (con_name = 'NIT_CPK_CITRT') THEN
         cg$errors.push(NVL(nit_cpk_citrt
                           ,cg$errors.msggettext(cg$errors.api_pk_con_violated
                                                ,cg$errors.apimsg_pk_violat
                                                ,'NIT_CPK_CITRT'
                                                ,'NIT_CIT_RELATION_TYPES'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_pk_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CUK_CITRT') THEN
         cg$errors.push(NVL(nit_cuk_citrt
                           ,cg$errors.msggettext(cg$errors.api_uq_con_violated
                                                ,cg$errors.apimsg_uk_violat
                                                ,'NIT_CUK_CITRT'
                                                ,'NIT_CIT_RELATION_TYPES'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_uq_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CFK_CITR_CITRT' AND
            TYPE = cg$errors.err_delete_restrict) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_del_restrict
                                            ,cg$errors.err_del_restrict
                                            ,'NIT_CIT_RELATION_TYPES'
                                            ,'NIT_CI_TYPE_RELATIONS')
                       ,'E'
                       ,'API'
                       ,cg$errors.api_del_restrict
                       ,loc);

      ELSE
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,loc);
      END IF;
   END err_msg;

   --------------------------------------------------------------------------------
   -- Name:        ins
   --
   -- Description: API insert procedure
   --
   -- Parameters:  cg$rec  Record of row to be inserted
   --              cg$ind  Record of columns specifically set
   --              do_ins  Whether we want the actual INSERT to occur
   --------------------------------------------------------------------------------
   PROCEDURE ins(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_ins IN BOOLEAN DEFAULT TRUE) IS

   BEGIN
      nit_cit_relation_types_p.pre_dml(cg$rec
                                      ,cg$ind
                                      ,'INS');

      --  Auto-generated and uppercased columns

      up_autogen_columns(cg$rec
                        ,cg$ind
                        ,'INS'
                        ,do_ins);

      called_from_package := TRUE;

      IF (do_ins) THEN

         INSERT INTO nit_cit_relation_types
            (id
            ,creation_date
            ,created_by
            ,last_update_date
            ,last_updated_by
            ,NAME
            ,description
            ,comments)
         VALUES
            (cg$rec.id
            ,cg$rec.creation_date
            ,cg$rec.created_by
            ,cg$rec.last_update_date
            ,cg$rec.last_updated_by
            ,cg$rec.NAME
            ,cg$rec.description
            ,cg$rec.comments)
         RETURNING id, creation_date, created_by, last_update_date, last_updated_by, NAME, description, comments, ROWID INTO cg$rec.id, cg$rec.creation_date, cg$rec.created_by, cg$rec.last_update_date, cg$rec.last_updated_by, cg$rec.NAME, cg$rec.description, cg$rec.comments, cg$rec.the_rowid;
      END IF;

      called_from_package := FALSE;


   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.mandatory_missing THEN
         validate_mandatory(cg$rec
                           ,'cg$NIT_CIT_RELATION_TYPES.ins.mandatory_missing');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.check_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_check_con
                ,'cg$NIT_CIT_RELATION_TYPES.ins.check_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.fk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_foreign_key
                ,'cg$NIT_CIT_RELATION_TYPES.ins.fk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.uk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_unique_key
                ,'cg$NIT_CIT_RELATION_TYPES.ins.uk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CIT_RELATION_TYPES.ins.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END ins;


   --------------------------------------------------------------------------------
   -- Name:        upd
   --
   -- Description: API update procedure
   --
   -- Parameters:  cg$rec  Record of row to be updated
   --              cg$ind  Record of columns specifically set
   --              do_upd  Whether we want the actual UPDATE to occur
   --------------------------------------------------------------------------------
   PROCEDURE upd(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_upd IN BOOLEAN DEFAULT TRUE
                ,cg$pk  IN cg$row_type DEFAULT NULL) IS
      cg$upd_rec cg$row_type;
      cg$old_rec cg$row_type;
   BEGIN
      nit_cit_relation_types_p.pre_dml(cg$rec
                                      ,cg$ind
                                      ,'UPD');

      IF (cg$pk.id IS NULL) THEN
         cg$upd_rec.id := cg$rec.id;
      ELSE
         cg$upd_rec.id := cg$pk.id;
      END IF;
      cg$old_rec.id := cg$upd_rec.id;

      IF (cg$pk.the_rowid IS NULL) THEN
         cg$upd_rec.the_rowid := cg$rec.the_rowid;
      ELSE
         cg$upd_rec.the_rowid := cg$pk.the_rowid;
      END IF;
      cg$old_rec.the_rowid := cg$upd_rec.the_rowid;

      IF (do_upd) THEN

         slct(cg$upd_rec);

         --  Report error if attempt to update non updateable Primary Key NIT_CPK_CITRT
         IF (cg$ind.id AND cg$rec.id != cg$upd_rec.id) THEN
            raise_uk_not_updateable('NIT_CPK_CITRT');
         END IF;
         IF NOT (cg$ind.id) THEN
            cg$rec.id := cg$upd_rec.id;
         END IF;
         IF NOT (cg$ind.creation_date) THEN
            cg$rec.creation_date := cg$upd_rec.creation_date;
         END IF;
         IF NOT (cg$ind.created_by) THEN
            cg$rec.created_by := cg$upd_rec.created_by;
         END IF;
         IF NOT (cg$ind.last_update_date) THEN
            cg$rec.last_update_date := cg$upd_rec.last_update_date;
         END IF;
         IF NOT (cg$ind.last_updated_by) THEN
            cg$rec.last_updated_by := cg$upd_rec.last_updated_by;
         END IF;
         IF NOT (cg$ind.NAME) THEN
            cg$rec.NAME := cg$upd_rec.NAME;
         END IF;
         IF NOT (cg$ind.description) THEN
            cg$rec.description := cg$upd_rec.description;
         END IF;
         IF NOT (cg$ind.comments) THEN
            cg$rec.comments := cg$upd_rec.comments;
         END IF;
      ELSE
         --  Report error if attempt to update non updateable Primary Key NIT_CPK_CITRT
         IF (cg$ind.id) THEN
            raise_uk_not_updateable('NIT_CPK_CITRT');
         END IF;
      END IF;

      up_autogen_columns(cg$rec
                        ,cg$ind
                        ,'UPD'
                        ,do_upd); --  Auto-generated and uppercased columns

      --  Now do update if updateable columns exist
      IF (do_upd) THEN
         DECLARE
            called_from BOOLEAN := called_from_package;
         BEGIN
            called_from_package := TRUE;

            slct(cg$old_rec);

            IF cg$rec.the_rowid IS NULL THEN
               UPDATE nit_cit_relation_types
               SET    creation_date    = cg$rec.creation_date
                     ,created_by       = cg$rec.created_by
                     ,last_update_date = cg$rec.last_update_date
                     ,last_updated_by  = cg$rec.last_updated_by
                     ,NAME             = cg$rec.NAME
                     ,description      = cg$rec.description
                     ,comments         = cg$rec.comments
               WHERE  id = cg$rec.id RETURNING id, creation_date, created_by,
                last_update_date, last_updated_by, NAME, description,
                comments, ROWID INTO cg$rec.id, cg$rec.creation_date,
                cg$rec.created_by, cg$rec.last_update_date,
                cg$rec.last_updated_by, cg$rec.NAME, cg$rec.description,
                cg$rec.comments, cg$rec.the_rowid;
            ELSE
               UPDATE nit_cit_relation_types
               SET    creation_date    = cg$rec.creation_date
                     ,created_by       = cg$rec.created_by
                     ,last_update_date = cg$rec.last_update_date
                     ,last_updated_by  = cg$rec.last_updated_by
                     ,NAME             = cg$rec.NAME
                     ,description      = cg$rec.description
                     ,comments         = cg$rec.comments
               WHERE  ROWID = cg$rec.the_rowid RETURNING id, creation_date,
                created_by, last_update_date, last_updated_by, NAME,
                description, comments, ROWID INTO cg$rec.id,
                cg$rec.creation_date, cg$rec.created_by,
                cg$rec.last_update_date, cg$rec.last_updated_by,
                cg$rec.NAME, cg$rec.description, cg$rec.comments,
                cg$rec.the_rowid;

            END IF;

            called_from_package := called_from;
         END;
      END IF;



      IF NOT (do_upd) THEN
         cg$table(idx).id := cg$rec.id;
         cg$tableind(idx).id := cg$ind.id;
         cg$table(idx).creation_date := cg$rec.creation_date;
         cg$tableind(idx).creation_date := cg$ind.creation_date;
         cg$table(idx).created_by := cg$rec.created_by;
         cg$tableind(idx).created_by := cg$ind.created_by;
         cg$table(idx).last_update_date := cg$rec.last_update_date;
         cg$tableind(idx).last_update_date := cg$ind.last_update_date;
         cg$table(idx).last_updated_by := cg$rec.last_updated_by;
         cg$tableind(idx).last_updated_by := cg$ind.last_updated_by;
         cg$table(idx).NAME := cg$rec.NAME;
         cg$tableind(idx).NAME := cg$ind.NAME;
         cg$table(idx).description := cg$rec.description;
         cg$tableind(idx).description := cg$ind.description;
         cg$table(idx).comments := cg$rec.comments;
         cg$tableind(idx).comments := cg$ind.comments;
         idx := idx + 1;
      END IF;

      --  Application_logic Post-Update <<Start>>
      --  Application_logic Post-Update << End >>

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.upd_mandatory_null THEN
         validate_mandatory(cg$rec
                           ,'cg$NIT_CIT_RELATION_TYPES.upd.upd_mandatory_null');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.check_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_check_con
                ,'cg$NIT_CIT_RELATION_TYPES.upd.check_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.fk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_foreign_key
                ,'cg$NIT_CIT_RELATION_TYPES.upd.fk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.uk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_unique_key
                ,'cg$NIT_CIT_RELATION_TYPES.upd.uk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CIT_RELATION_TYPES.upd.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END upd;

   --------------------------------------------------------------------------------
   -- Name:        del
   --
   -- Description: API delete procedure
   --
   -- Parameters:  cg$pk  Primary key record of row to be deleted
   --------------------------------------------------------------------------------
   PROCEDURE del(cg$pk  IN cg$pk_type
                ,do_del IN BOOLEAN DEFAULT TRUE) IS
   BEGIN
      nit_cit_relation_types_p.pre_del(cg$pk.id);

      called_from_package := TRUE;

      IF (do_del) THEN
         IF cg$pk.the_rowid IS NULL THEN
            DELETE nit_cit_relation_types
            WHERE  id = cg$pk.id;
         ELSE
            DELETE nit_cit_relation_types
            WHERE  ROWID = cg$pk.the_rowid;
         END IF;
      END IF;

      called_from_package := FALSE;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.delete_restrict THEN
         err_msg(SQLERRM
                ,cg$errors.err_delete_restrict
                ,'cg$NIT_CIT_RELATION_TYPES.del.delete_restrict');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN no_data_found THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_row_del
                                            ,cg$errors.row_del)
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CIT_RELATION_TYPES.del.no_data_found');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CIT_RELATION_TYPES.del.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END del;


   --------------------------------------------------------------------------------
   -- Name:        lck
   --
   -- Description: API lock procedure
   --
   -- Parameters:  cg$old_rec  Calling apps view of record of row to be locked
   --              cg$old_ind  Record of columns to raise error if modified
   --              nowait_flag TRUE lock with NOWAIT, FALSE don't fail if busy
   --------------------------------------------------------------------------------
   PROCEDURE lck(cg$old_rec  IN cg$row_type
                ,cg$old_ind  IN cg$ind_type
                ,nowait_flag IN BOOLEAN DEFAULT TRUE) IS
      cg$tmp_rec   cg$row_type;
      any_modified BOOLEAN := FALSE;

   BEGIN

      BEGIN
         IF (nowait_flag) THEN
            IF cg$old_rec.the_rowid IS NULL THEN
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,NAME
                     ,description
                     ,comments
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.NAME
                     ,cg$tmp_rec.description
                     ,cg$tmp_rec.comments
               FROM   nit_cit_relation_types
               WHERE  id = cg$old_rec.id
               FOR    UPDATE NOWAIT;
            ELSE
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,NAME
                     ,description
                     ,comments
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.NAME
                     ,cg$tmp_rec.description
                     ,cg$tmp_rec.comments
               FROM   nit_cit_relation_types
               WHERE  ROWID = cg$old_rec.the_rowid
               FOR    UPDATE NOWAIT;
            END IF;
         ELSE
            IF cg$old_rec.the_rowid IS NULL THEN
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,NAME
                     ,description
                     ,comments
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.NAME
                     ,cg$tmp_rec.description
                     ,cg$tmp_rec.comments
               FROM   nit_cit_relation_types
               WHERE  id = cg$old_rec.id
               FOR    UPDATE;
            ELSE
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,NAME
                     ,description
                     ,comments
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.NAME
                     ,cg$tmp_rec.description
                     ,cg$tmp_rec.comments
               FROM   nit_cit_relation_types
               WHERE  ROWID = cg$old_rec.the_rowid
               FOR    UPDATE;
            END IF;
         END IF;

      EXCEPTION
         WHEN cg$errors.cg$error THEN
            cg$errors.raise_failure;
         WHEN cg$errors.resource_busy THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_lck
                                               ,cg$errors.row_lck)
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_CIT_RELATION_TYPES.lck.resource_busy');
            cg$errors.raise_failure;
         WHEN no_data_found THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_del
                                               ,cg$errors.row_del)
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_CIT_RELATION_TYPES.lck.no_data_found');
            cg$errors.raise_failure;
         WHEN OTHERS THEN
            cg$errors.push(SQLERRM
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_CIT_RELATION_TYPES.lck.others');
            cg$errors.raise_failure;
      END;

      -- Optional Columns

      IF (cg$old_ind.description) THEN
         IF (cg$tmp_rec.description IS NOT NULL AND
            cg$old_rec.description IS NOT NULL) THEN
            IF (cg$tmp_rec.description != cg$old_rec.description) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p66description)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CIT_RELATION_TYPES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.description IS NOT NULL OR
               cg$old_rec.description IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p66description)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CIT_RELATION_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.comments) THEN
         IF (cg$tmp_rec.comments IS NOT NULL AND
            cg$old_rec.comments IS NOT NULL) THEN
            IF (cg$tmp_rec.comments != cg$old_rec.comments) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p76comments)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CIT_RELATION_TYPES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.comments IS NOT NULL OR
               cg$old_rec.comments IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p76comments)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CIT_RELATION_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;

      -- Mandatory Columns

      IF (cg$old_ind.id) THEN
         IF (cg$tmp_rec.id != cg$old_rec.id) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p5id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CIT_RELATION_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.creation_date) THEN
         IF (cg$tmp_rec.creation_date != cg$old_rec.creation_date) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p10creation_date)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CIT_RELATION_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.created_by) THEN
         IF (cg$tmp_rec.created_by != cg$old_rec.created_by) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p15created_by)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CIT_RELATION_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.last_update_date) THEN
         IF (cg$tmp_rec.last_update_date != cg$old_rec.last_update_date) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p18last_update_date)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CIT_RELATION_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.last_updated_by) THEN
         IF (cg$tmp_rec.last_updated_by != cg$old_rec.last_updated_by) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p19last_updated_by)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CIT_RELATION_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.NAME) THEN
         IF (cg$tmp_rec.NAME != cg$old_rec.NAME) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p36name)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CIT_RELATION_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;

      IF (any_modified) THEN
         cg$errors.raise_failure;
      END IF;

   END lck;


BEGIN
   cg$ind_true.id               := TRUE;
   cg$ind_true.creation_date    := TRUE;
   cg$ind_true.created_by       := TRUE;
   cg$ind_true.last_update_date := TRUE;
   cg$ind_true.last_updated_by  := TRUE;
   cg$ind_true.NAME             := TRUE;
   cg$ind_true.description      := TRUE;
   cg$ind_true.comments         := TRUE;


END cg$nit_cit_relation_types;
/

prompt
prompt Creating package body CG$NIT_CI_TYPE_RELATIONS
prompt ==============================================
prompt
CREATE OR REPLACE PACKAGE BODY cg$nit_ci_type_relations IS


   PROCEDURE validate_mandatory(cg$val_rec IN cg$row_type
                               ,loc        IN VARCHAR2 DEFAULT '');
   PROCEDURE up_autogen_columns(cg$rec    IN OUT cg$row_type
                               ,cg$ind    IN OUT cg$ind_type
                               ,operation IN VARCHAR2 DEFAULT 'INS'
                               ,do_denorm IN BOOLEAN DEFAULT TRUE);
   PROCEDURE err_msg(msg  IN VARCHAR2
                    ,TYPE IN INTEGER
                    ,loc  IN VARCHAR2 DEFAULT '');

   --------------------------------------------------------------------------------
   -- Name:        raise_uk_not_updateable
   --
   -- Description: Raise appropriate error when unique key updated
   --
   -- Parameters:  none
   --------------------------------------------------------------------------------
   PROCEDURE raise_uk_not_updateable(uk IN VARCHAR2) IS
   BEGIN
      cg$errors.push(cg$errors.msggettext(cg$errors.api_unique_key_update
                                         ,cg$errors.err_uk_update
                                         ,uk)
                    ,'E'
                    ,'API'
                    ,cg$errors.api_unique_key_update
                    ,'cg$NIT_CI_TYPE_RELATIONS.raise_uk_not_updateable');
      cg$errors.raise_failure;
   END raise_uk_not_updateable;


   --------------------------------------------------------------------------------
   -- Name:        raise_fk_not_transferable
   --
   -- Description: Raise appropriate error when foreign key updated
   --
   -- Parameters:  none
   --------------------------------------------------------------------------------
   PROCEDURE raise_fk_not_transferable(fk IN VARCHAR2) IS
   BEGIN
      cg$errors.push(cg$errors.msggettext(cg$errors.api_foreign_key_trans
                                         ,cg$errors.err_fk_trans
                                         ,fk)
                    ,'E'
                    ,'API'
                    ,cg$errors.api_foreign_key_trans
                    ,'cg$NIT_CI_TYPE_RELATIONS.raise_fk_not_transferable');
      cg$errors.raise_failure;
   END raise_fk_not_transferable;


   --------------------------------------------------------------------------------
   -- Name:        up_autogen_columns
   --
   -- Description: Specific autogeneration of column values and conversion to
   --              uppercase
   --
   -- Parameters:  cg$rec    Record of row to be manipulated
   --              cg$ind    Indicators for row
   --              operation Procedure where this procedure was called
   --------------------------------------------------------------------------------
   PROCEDURE up_autogen_columns(cg$rec    IN OUT cg$row_type
                               ,cg$ind    IN OUT cg$ind_type
                               ,operation IN VARCHAR2 DEFAULT 'INS'
                               ,do_denorm IN BOOLEAN DEFAULT TRUE) IS
   BEGIN
      IF (operation = 'INS') THEN
         BEGIN
            IF (cg$ind.id = FALSE OR cg$rec.id IS NULL) THEN
               SELECT nit_seq.NEXTVAL
               INTO   cg$rec.id
               FROM   dual;
               cg$ind.id := TRUE;
            END IF;
         EXCEPTION
            WHEN OTHERS THEN
               cg$errors.push(SQLERRM
                             ,'E'
                             ,'ORA'
                             ,SQLCODE
                             ,'cg$NIT_CI_TYPE_RELATIONS.up_autogen.ID.OTHERS');
               cg$errors.raise_failure;
         END;
      ELSE
         NULL;
      END IF; -- (operation = 'INS') ELSE (operation = 'UPD')

      -- Statements executed for both 'INS' and 'UPD'


   EXCEPTION
      WHEN no_data_found THEN
         NULL;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_TYPE_RELATIONS.up_autogen_columns');
         cg$errors.raise_failure;
   END up_autogen_columns;


   --------------------------------------------------------------------------------
   -- Name:        validate_mandatory
   --
   -- Description: Checks all mandatory columns are not null and raises appropriate
   --              error if not satisfied
   --
   -- Parameters:  cg$val_rec Record of row to be checked
   --              loc        Place where this procedure was called for error
   --                         trapping
   --------------------------------------------------------------------------------
   PROCEDURE validate_mandatory(cg$val_rec IN cg$row_type
                               ,loc        IN VARCHAR2 DEFAULT '') IS
   BEGIN
      IF (cg$val_rec.id IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p10id)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.creation_date IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p15creation_date)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.created_by IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p16created_by)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.last_update_date IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p19last_update_date)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.last_updated_by IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p24last_updated_by)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.cit_id_from IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p27cit_id_from)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.cit_id_to IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p28cit_id_to)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.citrt_id IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p30citrt_id)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.order_in_list IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p60order_in_list)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
   END validate_mandatory;

   --------------------------------------------------------------------------------
   -- Name:        slct
   --
   -- Description: Selects into the given parameter all the attributes for the row
   --              given by the primary key
   --
   -- Parameters:  cg$sel_rec  Record of row to be selected into using its PK
   --------------------------------------------------------------------------------
   PROCEDURE slct(cg$sel_rec IN OUT cg$row_type) IS

   BEGIN

      IF cg$sel_rec.the_rowid IS NULL THEN
         SELECT id
               ,creation_date
               ,created_by
               ,last_update_date
               ,last_updated_by
               ,cit_id_from
               ,cit_id_to
               ,citrt_id
               ,order_in_list
               ,description
               ,comments
               ,ROWID
         INTO   cg$sel_rec.id
               ,cg$sel_rec.creation_date
               ,cg$sel_rec.created_by
               ,cg$sel_rec.last_update_date
               ,cg$sel_rec.last_updated_by
               ,cg$sel_rec.cit_id_from
               ,cg$sel_rec.cit_id_to
               ,cg$sel_rec.citrt_id
               ,cg$sel_rec.order_in_list
               ,cg$sel_rec.description
               ,cg$sel_rec.comments
               ,cg$sel_rec.the_rowid
         FROM   nit_ci_type_relations
         WHERE  id = cg$sel_rec.id;
      ELSE
         SELECT id
               ,creation_date
               ,created_by
               ,last_update_date
               ,last_updated_by
               ,cit_id_from
               ,cit_id_to
               ,citrt_id
               ,order_in_list
               ,description
               ,comments
               ,ROWID
         INTO   cg$sel_rec.id
               ,cg$sel_rec.creation_date
               ,cg$sel_rec.created_by
               ,cg$sel_rec.last_update_date
               ,cg$sel_rec.last_updated_by
               ,cg$sel_rec.cit_id_from
               ,cg$sel_rec.cit_id_to
               ,cg$sel_rec.citrt_id
               ,cg$sel_rec.order_in_list
               ,cg$sel_rec.description
               ,cg$sel_rec.comments
               ,cg$sel_rec.the_rowid
         FROM   nit_ci_type_relations
         WHERE  ROWID = cg$sel_rec.the_rowid;
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_TYPE_RELATIONS.slct.others');
         cg$errors.raise_failure;

   END slct;

   --------------------------------------------------------------------------------
   -- Name:        err_msg
   --
   -- Description: Pushes onto stack appropriate user defined error message
   --              depending on the rule violated
   --
   -- Parameters:  msg     Oracle error message
   --              type    Type of violation e.g. check_constraint: ERR_CHECK_CON
   --              loc     Place where this procedure was called for error
   --                      trapping
   --------------------------------------------------------------------------------
   PROCEDURE err_msg(msg  IN VARCHAR2
                    ,TYPE IN INTEGER
                    ,loc  IN VARCHAR2 DEFAULT '') IS
      con_name VARCHAR2(240);
   BEGIN
      con_name := cg$errors.parse_constraint(msg
                                            ,TYPE);
      IF (con_name = 'NIT_CPK_CITR') THEN
         cg$errors.push(NVL(nit_cpk_citr
                           ,cg$errors.msggettext(cg$errors.api_pk_con_violated
                                                ,cg$errors.apimsg_pk_violat
                                                ,'NIT_CPK_CITR'
                                                ,'NIT_CI_TYPE_RELATIONS'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_pk_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CUK_CITR') THEN
         cg$errors.push(NVL(nit_cuk_citr
                           ,cg$errors.msggettext(cg$errors.api_uq_con_violated
                                                ,cg$errors.apimsg_uk_violat
                                                ,'NIT_CUK_CITR'
                                                ,'NIT_CI_TYPE_RELATIONS'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_uq_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CFK_CIR_CITR' AND
            TYPE = cg$errors.err_delete_restrict) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_del_restrict
                                            ,cg$errors.err_del_restrict
                                            ,'NIT_CI_TYPE_RELATIONS'
                                            ,'NIT_CI_RELATIONS')
                       ,'E'
                       ,'API'
                       ,cg$errors.api_del_restrict
                       ,loc);

      ELSIF (con_name = 'NIT_CFK_CITR_CITRT') THEN
         cg$errors.push(NVL(nit_cfk_citr_citrt
                           ,cg$errors.msggettext(cg$errors.api_fk_con_violated
                                                ,cg$errors.apimsg_fk_violat
                                                ,'NIT_CFK_CITR_CITRT'
                                                ,'NIT_CI_TYPE_RELATIONS'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_fk_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CFK_CITR_CIT_FROM') THEN
         cg$errors.push(NVL(nit_cfk_citr_cit_from
                           ,cg$errors.msggettext(cg$errors.api_fk_con_violated
                                                ,cg$errors.apimsg_fk_violat
                                                ,'NIT_CFK_CITR_CIT_FROM'
                                                ,'NIT_CI_TYPE_RELATIONS'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_fk_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CFK_CITR_CIT_TO') THEN
         cg$errors.push(NVL(nit_cfk_citr_cit_to
                           ,cg$errors.msggettext(cg$errors.api_fk_con_violated
                                                ,cg$errors.apimsg_fk_violat
                                                ,'NIT_CFK_CITR_CIT_TO'
                                                ,'NIT_CI_TYPE_RELATIONS'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_fk_con_violated
                       ,loc);
      ELSE
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,loc);
      END IF;
   END err_msg;

   --------------------------------------------------------------------------------
   -- Name:        ins
   --
   -- Description: API insert procedure
   --
   -- Parameters:  cg$rec  Record of row to be inserted
   --              cg$ind  Record of columns specifically set
   --              do_ins  Whether we want the actual INSERT to occur
   --------------------------------------------------------------------------------
   PROCEDURE ins(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_ins IN BOOLEAN DEFAULT TRUE) IS

      --  Constant default values

      d60_order_in_list CONSTANT nit_ci_type_relations.order_in_list%TYPE := 0;

   BEGIN
      nit_ci_type_relations_p.pre_dml(cg$rec
                                     ,cg$ind
                                     ,'INS');

      --  Defaulted

      IF NOT (cg$ind.order_in_list) THEN
         cg$rec.order_in_list := d60_order_in_list;
      END IF;
      --  Auto-generated and uppercased columns

      up_autogen_columns(cg$rec
                        ,cg$ind
                        ,'INS'
                        ,do_ins);

      called_from_package := TRUE;

      IF (do_ins) THEN

         INSERT INTO nit_ci_type_relations
            (id
            ,creation_date
            ,created_by
            ,last_update_date
            ,last_updated_by
            ,cit_id_from
            ,cit_id_to
            ,citrt_id
            ,order_in_list
            ,description
            ,comments)
         VALUES
            (cg$rec.id
            ,cg$rec.creation_date
            ,cg$rec.created_by
            ,cg$rec.last_update_date
            ,cg$rec.last_updated_by
            ,cg$rec.cit_id_from
            ,cg$rec.cit_id_to
            ,cg$rec.citrt_id
            ,cg$rec.order_in_list
            ,cg$rec.description
            ,cg$rec.comments)
         RETURNING id, creation_date, created_by, last_update_date, last_updated_by, cit_id_from, cit_id_to, citrt_id, order_in_list, description, comments, ROWID INTO cg$rec.id, cg$rec.creation_date, cg$rec.created_by, cg$rec.last_update_date, cg$rec.last_updated_by, cg$rec.cit_id_from, cg$rec.cit_id_to, cg$rec.citrt_id, cg$rec.order_in_list, cg$rec.description, cg$rec.comments, cg$rec.the_rowid;

      END IF;

      called_from_package := FALSE;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.mandatory_missing THEN
         validate_mandatory(cg$rec
                           ,'cg$NIT_CI_TYPE_RELATIONS.ins.mandatory_missing');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.check_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_check_con
                ,'cg$NIT_CI_TYPE_RELATIONS.ins.check_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.fk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_foreign_key
                ,'cg$NIT_CI_TYPE_RELATIONS.ins.fk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.uk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_unique_key
                ,'cg$NIT_CI_TYPE_RELATIONS.ins.uk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_TYPE_RELATIONS.ins.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END ins;


   --------------------------------------------------------------------------------
   -- Name:        upd
   --
   -- Description: API update procedure
   --
   -- Parameters:  cg$rec  Record of row to be updated
   --              cg$ind  Record of columns specifically set
   --              do_upd  Whether we want the actual UPDATE to occur
   --------------------------------------------------------------------------------
   PROCEDURE upd(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_upd IN BOOLEAN DEFAULT TRUE
                ,cg$pk  IN cg$row_type DEFAULT NULL) IS
      cg$upd_rec cg$row_type;
      cg$old_rec cg$row_type;
   BEGIN
      nit_ci_type_relations_p.pre_dml(cg$rec
                                     ,cg$ind
                                     ,'UPD');


      IF (cg$pk.id IS NULL) THEN
         cg$upd_rec.id := cg$rec.id;
      ELSE
         cg$upd_rec.id := cg$pk.id;
      END IF;
      cg$old_rec.id := cg$upd_rec.id;

      IF (cg$pk.the_rowid IS NULL) THEN
         cg$upd_rec.the_rowid := cg$rec.the_rowid;
      ELSE
         cg$upd_rec.the_rowid := cg$pk.the_rowid;
      END IF;
      cg$old_rec.the_rowid := cg$upd_rec.the_rowid;

      IF (do_upd) THEN

         slct(cg$upd_rec);

         --  Report error if attempt to update non transferable Foreign Key NIT_CFK_CITR_CITRT
         IF (cg$ind.citrt_id AND cg$rec.citrt_id != cg$upd_rec.citrt_id) THEN
            raise_fk_not_transferable('NIT_CFK_CITR_CITRT');
         END IF;
         IF (cg$ind.citrt_id AND cg$rec.citrt_id IS NULL AND
            cg$upd_rec.citrt_id IS NOT NULL) THEN
            raise_fk_not_transferable('NIT_CFK_CITR_CITRT');
         END IF;
         IF (cg$ind.citrt_id AND cg$rec.citrt_id IS NOT NULL AND
            cg$upd_rec.citrt_id IS NULL) THEN
            raise_fk_not_transferable('NIT_CFK_CITR_CITRT');
         END IF;
         --  Report error if attempt to update non transferable Foreign Key NIT_CFK_CITR_CIT_FROM
         IF (cg$ind.cit_id_from AND
            cg$rec.cit_id_from != cg$upd_rec.cit_id_from) THEN
            raise_fk_not_transferable('NIT_CFK_CITR_CIT_FROM');
         END IF;
         IF (cg$ind.cit_id_from AND cg$rec.cit_id_from IS NULL AND
            cg$upd_rec.cit_id_from IS NOT NULL) THEN
            raise_fk_not_transferable('NIT_CFK_CITR_CIT_FROM');
         END IF;
         IF (cg$ind.cit_id_from AND cg$rec.cit_id_from IS NOT NULL AND
            cg$upd_rec.cit_id_from IS NULL) THEN
            raise_fk_not_transferable('NIT_CFK_CITR_CIT_FROM');
         END IF;
         --  Report error if attempt to update non transferable Foreign Key NIT_CFK_CITR_CIT_TO
         IF (cg$ind.cit_id_to AND cg$rec.cit_id_to != cg$upd_rec.cit_id_to) THEN
            raise_fk_not_transferable('NIT_CFK_CITR_CIT_TO');
         END IF;
         IF (cg$ind.cit_id_to AND cg$rec.cit_id_to IS NULL AND
            cg$upd_rec.cit_id_to IS NOT NULL) THEN
            raise_fk_not_transferable('NIT_CFK_CITR_CIT_TO');
         END IF;
         IF (cg$ind.cit_id_to AND cg$rec.cit_id_to IS NOT NULL AND
            cg$upd_rec.cit_id_to IS NULL) THEN
            raise_fk_not_transferable('NIT_CFK_CITR_CIT_TO');
         END IF;

         --  Report error if attempt to update non updateable Primary Key NIT_CPK_CITR
         IF (cg$ind.id AND cg$rec.id != cg$upd_rec.id) THEN
            raise_uk_not_updateable('NIT_CPK_CITR');
         END IF;
         IF NOT (cg$ind.id) THEN
            cg$rec.id := cg$upd_rec.id;
         END IF;
         IF NOT (cg$ind.creation_date) THEN
            cg$rec.creation_date := cg$upd_rec.creation_date;
         END IF;
         IF NOT (cg$ind.created_by) THEN
            cg$rec.created_by := cg$upd_rec.created_by;
         END IF;
         IF NOT (cg$ind.last_update_date) THEN
            cg$rec.last_update_date := cg$upd_rec.last_update_date;
         END IF;
         IF NOT (cg$ind.last_updated_by) THEN
            cg$rec.last_updated_by := cg$upd_rec.last_updated_by;
         END IF;
         IF NOT (cg$ind.cit_id_from) THEN
            cg$rec.cit_id_from := cg$upd_rec.cit_id_from;
         END IF;
         IF NOT (cg$ind.cit_id_to) THEN
            cg$rec.cit_id_to := cg$upd_rec.cit_id_to;
         END IF;
         IF NOT (cg$ind.citrt_id) THEN
            cg$rec.citrt_id := cg$upd_rec.citrt_id;
         END IF;
         IF NOT (cg$ind.order_in_list) THEN
            cg$rec.order_in_list := cg$upd_rec.order_in_list;
         END IF;
         IF NOT (cg$ind.description) THEN
            cg$rec.description := cg$upd_rec.description;
         END IF;
         IF NOT (cg$ind.comments) THEN
            cg$rec.comments := cg$upd_rec.comments;
         END IF;
      ELSE
         --  Report error if attempt to update non transferable Foreign Key NIT_CFK_CITR_CITRT
         IF (cg$ind.citrt_id) THEN
            raise_fk_not_transferable('NIT_CFK_CITR_CITRT');
         END IF;
         --  Report error if attempt to update non transferable Foreign Key NIT_CFK_CITR_CIT_FROM
         IF (cg$ind.cit_id_from) THEN
            raise_fk_not_transferable('NIT_CFK_CITR_CIT_FROM');
         END IF;
         --  Report error if attempt to update non transferable Foreign Key NIT_CFK_CITR_CIT_TO
         IF (cg$ind.cit_id_to) THEN
            raise_fk_not_transferable('NIT_CFK_CITR_CIT_TO');
         END IF;
         --  Report error if attempt to update non updateable Primary Key NIT_CPK_CITR
         IF (cg$ind.id) THEN
            raise_uk_not_updateable('NIT_CPK_CITR');
         END IF;
      END IF;

      up_autogen_columns(cg$rec
                        ,cg$ind
                        ,'UPD'
                        ,do_upd); --  Auto-generated and uppercased columns

      --  Now do update if updateable columns exist
      IF (do_upd) THEN
         DECLARE
            called_from BOOLEAN := called_from_package;
         BEGIN
            called_from_package := TRUE;

            slct(cg$old_rec);

            IF cg$rec.the_rowid IS NULL THEN
               UPDATE nit_ci_type_relations
               SET    creation_date    = cg$rec.creation_date
                     ,created_by       = cg$rec.created_by
                     ,last_update_date = cg$rec.last_update_date
                     ,last_updated_by  = cg$rec.last_updated_by
                     ,cit_id_from      = cg$rec.cit_id_from
                     ,cit_id_to        = cg$rec.cit_id_to
                     ,citrt_id         = cg$rec.citrt_id
                     ,order_in_list    = cg$rec.order_in_list
                     ,description      = cg$rec.description
                     ,comments         = cg$rec.comments
               WHERE  id = cg$rec.id RETURNING id, creation_date, created_by,
                last_update_date, last_updated_by, cit_id_from, cit_id_to,
                citrt_id, order_in_list, description, comments, ROWID INTO
                cg$rec.id, cg$rec.creation_date, cg$rec.created_by,
                cg$rec.last_update_date, cg$rec.last_updated_by,
                cg$rec.cit_id_from, cg$rec.cit_id_to, cg$rec.citrt_id,
                cg$rec.order_in_list, cg$rec.description, cg$rec.comments,
                cg$rec.the_rowid;
            ELSE
               UPDATE nit_ci_type_relations
               SET    creation_date    = cg$rec.creation_date
                     ,created_by       = cg$rec.created_by
                     ,last_update_date = cg$rec.last_update_date
                     ,last_updated_by  = cg$rec.last_updated_by
                     ,cit_id_from      = cg$rec.cit_id_from
                     ,cit_id_to        = cg$rec.cit_id_to
                     ,citrt_id         = cg$rec.citrt_id
                     ,order_in_list    = cg$rec.order_in_list
                     ,description      = cg$rec.description
                     ,comments         = cg$rec.comments
               WHERE  ROWID = cg$rec.the_rowid RETURNING id, creation_date,
                created_by, last_update_date, last_updated_by,
                cit_id_from, cit_id_to, citrt_id, order_in_list,
                description, comments, ROWID INTO cg$rec.id,
                cg$rec.creation_date, cg$rec.created_by,
                cg$rec.last_update_date, cg$rec.last_updated_by,
                cg$rec.cit_id_from, cg$rec.cit_id_to, cg$rec.citrt_id,
                cg$rec.order_in_list, cg$rec.description, cg$rec.comments,
                cg$rec.the_rowid;

            END IF;

            called_from_package := called_from;
         END;
      END IF;



      IF NOT (do_upd) THEN
         cg$table(idx).id := cg$rec.id;
         cg$tableind(idx).id := cg$ind.id;
         cg$table(idx).creation_date := cg$rec.creation_date;
         cg$tableind(idx).creation_date := cg$ind.creation_date;
         cg$table(idx).created_by := cg$rec.created_by;
         cg$tableind(idx).created_by := cg$ind.created_by;
         cg$table(idx).last_update_date := cg$rec.last_update_date;
         cg$tableind(idx).last_update_date := cg$ind.last_update_date;
         cg$table(idx).last_updated_by := cg$rec.last_updated_by;
         cg$tableind(idx).last_updated_by := cg$ind.last_updated_by;
         cg$table(idx).cit_id_from := cg$rec.cit_id_from;
         cg$tableind(idx).cit_id_from := cg$ind.cit_id_from;
         cg$table(idx).cit_id_to := cg$rec.cit_id_to;
         cg$tableind(idx).cit_id_to := cg$ind.cit_id_to;
         cg$table(idx).citrt_id := cg$rec.citrt_id;
         cg$tableind(idx).citrt_id := cg$ind.citrt_id;
         cg$table(idx).order_in_list := cg$rec.order_in_list;
         cg$tableind(idx).order_in_list := cg$ind.order_in_list;
         cg$table(idx).description := cg$rec.description;
         cg$tableind(idx).description := cg$ind.description;
         cg$table(idx).comments := cg$rec.comments;
         cg$tableind(idx).comments := cg$ind.comments;
         idx := idx + 1;
      END IF;

      --  Application_logic Post-Update <<Start>>
      --  Application_logic Post-Update << End >>

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.upd_mandatory_null THEN
         validate_mandatory(cg$rec
                           ,'cg$NIT_CI_TYPE_RELATIONS.upd.upd_mandatory_null');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.check_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_check_con
                ,'cg$NIT_CI_TYPE_RELATIONS.upd.check_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.fk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_foreign_key
                ,'cg$NIT_CI_TYPE_RELATIONS.upd.fk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.uk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_unique_key
                ,'cg$NIT_CI_TYPE_RELATIONS.upd.uk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_TYPE_RELATIONS.upd.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END upd;

   --------------------------------------------------------------------------------
   -- Name:        del
   --
   -- Description: API delete procedure
   --
   -- Parameters:  cg$pk  Primary key record of row to be deleted
   --------------------------------------------------------------------------------
   PROCEDURE del(cg$pk  IN cg$pk_type
                ,do_del IN BOOLEAN DEFAULT TRUE) IS
   BEGIN
      called_from_package := TRUE;

      IF (do_del) THEN
         IF cg$pk.the_rowid IS NULL THEN
            DELETE nit_ci_type_relations
            WHERE  id = cg$pk.id;
         ELSE
            DELETE nit_ci_type_relations
            WHERE  ROWID = cg$pk.the_rowid;
         END IF;
      END IF;

      called_from_package := FALSE;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.delete_restrict THEN
         err_msg(SQLERRM
                ,cg$errors.err_delete_restrict
                ,'cg$NIT_CI_TYPE_RELATIONS.del.delete_restrict');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN no_data_found THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_row_del
                                            ,cg$errors.row_del)
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_TYPE_RELATIONS.del.no_data_found');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_TYPE_RELATIONS.del.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END del;


   --------------------------------------------------------------------------------
   -- Name:        lck
   --
   -- Description: API lock procedure
   --
   -- Parameters:  cg$old_rec  Calling apps view of record of row to be locked
   --              cg$old_ind  Record of columns to raise error if modified
   --              nowait_flag TRUE lock with NOWAIT, FALSE don't fail if busy
   --------------------------------------------------------------------------------
   PROCEDURE lck(cg$old_rec  IN cg$row_type
                ,cg$old_ind  IN cg$ind_type
                ,nowait_flag IN BOOLEAN DEFAULT TRUE) IS
      cg$tmp_rec   cg$row_type;
      any_modified BOOLEAN := FALSE;

   BEGIN
      BEGIN
         IF (nowait_flag) THEN
            IF cg$old_rec.the_rowid IS NULL THEN
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,cit_id_from
                     ,cit_id_to
                     ,citrt_id
                     ,order_in_list
                     ,description
                     ,comments
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.cit_id_from
                     ,cg$tmp_rec.cit_id_to
                     ,cg$tmp_rec.citrt_id
                     ,cg$tmp_rec.order_in_list
                     ,cg$tmp_rec.description
                     ,cg$tmp_rec.comments
               FROM   nit_ci_type_relations
               WHERE  id = cg$old_rec.id
               FOR    UPDATE NOWAIT;
            ELSE
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,cit_id_from
                     ,cit_id_to
                     ,citrt_id
                     ,order_in_list
                     ,description
                     ,comments
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.cit_id_from
                     ,cg$tmp_rec.cit_id_to
                     ,cg$tmp_rec.citrt_id
                     ,cg$tmp_rec.order_in_list
                     ,cg$tmp_rec.description
                     ,cg$tmp_rec.comments
               FROM   nit_ci_type_relations
               WHERE  ROWID = cg$old_rec.the_rowid
               FOR    UPDATE NOWAIT;
            END IF;
         ELSE
            IF cg$old_rec.the_rowid IS NULL THEN
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,cit_id_from
                     ,cit_id_to
                     ,citrt_id
                     ,order_in_list
                     ,description
                     ,comments
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.cit_id_from
                     ,cg$tmp_rec.cit_id_to
                     ,cg$tmp_rec.citrt_id
                     ,cg$tmp_rec.order_in_list
                     ,cg$tmp_rec.description
                     ,cg$tmp_rec.comments
               FROM   nit_ci_type_relations
               WHERE  id = cg$old_rec.id
               FOR    UPDATE;
            ELSE
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,cit_id_from
                     ,cit_id_to
                     ,citrt_id
                     ,order_in_list
                     ,description
                     ,comments
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.cit_id_from
                     ,cg$tmp_rec.cit_id_to
                     ,cg$tmp_rec.citrt_id
                     ,cg$tmp_rec.order_in_list
                     ,cg$tmp_rec.description
                     ,cg$tmp_rec.comments
               FROM   nit_ci_type_relations
               WHERE  ROWID = cg$old_rec.the_rowid
               FOR    UPDATE;
            END IF;
         END IF;

      EXCEPTION
         WHEN cg$errors.cg$error THEN
            cg$errors.raise_failure;
         WHEN cg$errors.resource_busy THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_lck
                                               ,cg$errors.row_lck)
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_CI_TYPE_RELATIONS.lck.resource_busy');
            cg$errors.raise_failure;
         WHEN no_data_found THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_del
                                               ,cg$errors.row_del)
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_CI_TYPE_RELATIONS.lck.no_data_found');
            cg$errors.raise_failure;
         WHEN OTHERS THEN
            cg$errors.push(SQLERRM
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_CI_TYPE_RELATIONS.lck.others');
            cg$errors.raise_failure;
      END;

      -- Optional Columns

      IF (cg$old_ind.description) THEN
         IF (cg$tmp_rec.description IS NOT NULL AND
            cg$old_rec.description IS NOT NULL) THEN
            IF (cg$tmp_rec.description != cg$old_rec.description) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p100description)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_TYPE_RELATIONS.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.description IS NOT NULL OR
               cg$old_rec.description IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p100description)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPE_RELATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.comments) THEN
         IF (cg$tmp_rec.comments IS NOT NULL AND
            cg$old_rec.comments IS NOT NULL) THEN
            IF (cg$tmp_rec.comments != cg$old_rec.comments) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p110comments)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_TYPE_RELATIONS.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.comments IS NOT NULL OR
               cg$old_rec.comments IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p110comments)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPE_RELATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;

      -- Mandatory Columns

      IF (cg$old_ind.id) THEN
         IF (cg$tmp_rec.id != cg$old_rec.id) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p10id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPE_RELATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.creation_date) THEN
         IF (cg$tmp_rec.creation_date != cg$old_rec.creation_date) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p15creation_date)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPE_RELATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.created_by) THEN
         IF (cg$tmp_rec.created_by != cg$old_rec.created_by) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p16created_by)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPE_RELATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.last_update_date) THEN
         IF (cg$tmp_rec.last_update_date != cg$old_rec.last_update_date) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p19last_update_date)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPE_RELATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.last_updated_by) THEN
         IF (cg$tmp_rec.last_updated_by != cg$old_rec.last_updated_by) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p24last_updated_by)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPE_RELATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.cit_id_from) THEN
         IF (cg$tmp_rec.cit_id_from != cg$old_rec.cit_id_from) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p27cit_id_from)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPE_RELATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.cit_id_to) THEN
         IF (cg$tmp_rec.cit_id_to != cg$old_rec.cit_id_to) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p28cit_id_to)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPE_RELATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.citrt_id) THEN
         IF (cg$tmp_rec.citrt_id != cg$old_rec.citrt_id) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p30citrt_id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPE_RELATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.order_in_list) THEN
         IF (cg$tmp_rec.order_in_list != cg$old_rec.order_in_list) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p60order_in_list)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPE_RELATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;

      IF (any_modified) THEN
         cg$errors.raise_failure;
      END IF;

   END lck;


BEGIN
   cg$ind_true.id               := TRUE;
   cg$ind_true.creation_date    := TRUE;
   cg$ind_true.created_by       := TRUE;
   cg$ind_true.last_update_date := TRUE;
   cg$ind_true.last_updated_by  := TRUE;
   cg$ind_true.cit_id_from      := TRUE;
   cg$ind_true.cit_id_to        := TRUE;
   cg$ind_true.citrt_id         := TRUE;
   cg$ind_true.order_in_list    := TRUE;
   cg$ind_true.description      := TRUE;
   cg$ind_true.comments         := TRUE;


END cg$nit_ci_type_relations;
/

prompt
prompt Creating package body CG$NIT_CI_TYPES
prompt =====================================
prompt
CREATE OR REPLACE PACKAGE BODY cg$nit_ci_types IS


   PROCEDURE validate_mandatory(cg$val_rec IN cg$row_type
                               ,loc        IN VARCHAR2 DEFAULT '');
   PROCEDURE up_autogen_columns(cg$rec    IN OUT cg$row_type
                               ,cg$ind    IN OUT cg$ind_type
                               ,operation IN VARCHAR2 DEFAULT 'INS'
                               ,do_denorm IN BOOLEAN DEFAULT TRUE);
   PROCEDURE err_msg(msg  IN VARCHAR2
                    ,TYPE IN INTEGER
                    ,loc  IN VARCHAR2 DEFAULT '');

   --------------------------------------------------------------------------------
   -- Name:        raise_uk_not_updateable
   --
   -- Description: Raise appropriate error when unique key updated
   --
   -- Parameters:  none
   --------------------------------------------------------------------------------
   PROCEDURE raise_uk_not_updateable(uk IN VARCHAR2) IS
   BEGIN
      cg$errors.push(cg$errors.msggettext(cg$errors.api_unique_key_update
                                         ,cg$errors.err_uk_update
                                         ,uk)
                    ,'E'
                    ,'API'
                    ,cg$errors.api_unique_key_update
                    ,'cg$NIT_CI_TYPES.raise_uk_not_updateable');
      cg$errors.raise_failure;
   END raise_uk_not_updateable;


   --------------------------------------------------------------------------------
   -- Name:        raise_fk_not_transferable
   --
   -- Description: Raise appropriate error when foreign key updated
   --
   -- Parameters:  none
   --------------------------------------------------------------------------------
   PROCEDURE raise_fk_not_transferable(fk IN VARCHAR2) IS
   BEGIN
      cg$errors.push(cg$errors.msggettext(cg$errors.api_foreign_key_trans
                                         ,cg$errors.err_fk_trans
                                         ,fk)
                    ,'E'
                    ,'API'
                    ,cg$errors.api_foreign_key_trans
                    ,'cg$NIT_CI_TYPES.raise_fk_not_transferable');
      cg$errors.raise_failure;
   END raise_fk_not_transferable;


   --------------------------------------------------------------------------------
   -- Name:        up_autogen_columns
   --
   -- Description: Specific autogeneration of column values and conversion to
   --              uppercase
   --
   -- Parameters:  cg$rec    Record of row to be manipulated
   --              cg$ind    Indicators for row
   --              operation Procedure where this procedure was called
   --------------------------------------------------------------------------------
   PROCEDURE up_autogen_columns(cg$rec    IN OUT cg$row_type
                               ,cg$ind    IN OUT cg$ind_type
                               ,operation IN VARCHAR2 DEFAULT 'INS'
                               ,do_denorm IN BOOLEAN DEFAULT TRUE) IS
   BEGIN
      IF (operation = 'INS') THEN
         BEGIN
            IF (cg$ind.id = FALSE OR cg$rec.id IS NULL) THEN
               SELECT nit_seq.NEXTVAL
               INTO   cg$rec.id
               FROM   dual;
               cg$ind.id := TRUE;
            END IF;
         EXCEPTION
            WHEN OTHERS THEN
               cg$errors.push(SQLERRM
                             ,'E'
                             ,'ORA'
                             ,SQLCODE
                             ,'cg$NIT_CI_TYPES.up_autogen.ID.OTHERS');
               cg$errors.raise_failure;
         END;
      ELSE
         -- (operation = 'UPD')
         NULL;
      END IF; -- (operation = 'INS') ELSE (operation = 'UPD')

      -- Statements executed for both 'INS' and 'UPD'

      cg$rec.need_po        := upper(cg$rec.need_po);
      cg$rec.could_in_stock := upper(cg$rec.could_in_stock);

   EXCEPTION
      WHEN no_data_found THEN
         NULL;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_TYPES.up_autogen_columns');
         cg$errors.raise_failure;
   END up_autogen_columns;


   --------------------------------------------------------------------------------
   -- Name:        validate_mandatory
   --
   -- Description: Checks all mandatory columns are not null and raises appropriate
   --              error if not satisfied
   --
   -- Parameters:  cg$val_rec Record of row to be checked
   --              loc        Place where this procedure was called for error
   --                         trapping
   --------------------------------------------------------------------------------
   PROCEDURE validate_mandatory(cg$val_rec IN cg$row_type
                               ,loc        IN VARCHAR2 DEFAULT '') IS
   BEGIN
      IF (cg$val_rec.id IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p10id)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.creation_date IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p15creation_date)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.created_by IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p16created_by)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.last_update_date IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p19last_update_date)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.last_updated_by IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p24last_updated_by)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.NAME IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p40name)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.need_po IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p50need_po)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.could_in_stock IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p60could_in_stock)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.could_in_inventory IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p70could_in_inventory)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.order_in_list IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p80order_in_list)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.is_importable IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p140is_importable)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.imp_auto_import IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p200imp_auto_import)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      NULL;
   END validate_mandatory;

   --------------------------------------------------------------------------------
   -- Name:        slct
   --
   -- Description: Selects into the given parameter all the attributes for the row
   --              given by the primary key
   --
   -- Parameters:  cg$sel_rec  Record of row to be selected into using its PK
   --------------------------------------------------------------------------------
   PROCEDURE slct(cg$sel_rec IN OUT cg$row_type) IS

   BEGIN

      IF cg$sel_rec.the_rowid IS NULL THEN
         SELECT id
               ,creation_date
               ,created_by
               ,last_update_date
               ,last_updated_by
               ,cit_id
               ,NAME
               ,need_po
               ,could_in_stock
               ,could_in_inventory
               ,order_in_list
               ,abbreviation
               ,naming_pattern
               ,description
               ,comments
               ,icon_name
               ,is_importable
               ,imp_source_module
               ,imp_source_name
               ,imp_where_clause
               ,imp_name_attrib
               ,imp_auto_import
               ,ROWID
         INTO   cg$sel_rec.id
               ,cg$sel_rec.creation_date
               ,cg$sel_rec.created_by
               ,cg$sel_rec.last_update_date
               ,cg$sel_rec.last_updated_by
               ,cg$sel_rec.cit_id
               ,cg$sel_rec.NAME
               ,cg$sel_rec.need_po
               ,cg$sel_rec.could_in_stock
               ,cg$sel_rec.could_in_inventory
               ,cg$sel_rec.order_in_list
               ,cg$sel_rec.abbreviation
               ,cg$sel_rec.naming_pattern
               ,cg$sel_rec.description
               ,cg$sel_rec.comments
               ,cg$sel_rec.icon_name
               ,cg$sel_rec.is_importable
               ,cg$sel_rec.imp_source_module
               ,cg$sel_rec.imp_source_name
               ,cg$sel_rec.imp_where_clause
               ,cg$sel_rec.imp_name_attrib
               ,cg$sel_rec.imp_auto_import
               ,cg$sel_rec.the_rowid
         FROM   nit_ci_types
         WHERE  id = cg$sel_rec.id;
      ELSE
         SELECT id
               ,creation_date
               ,created_by
               ,last_update_date
               ,last_updated_by
               ,cit_id
               ,NAME
               ,need_po
               ,could_in_stock
               ,could_in_inventory
               ,order_in_list
               ,abbreviation
               ,naming_pattern
               ,description
               ,comments
               ,icon_name
               ,is_importable
               ,imp_source_module
               ,imp_source_name
               ,imp_where_clause
               ,imp_name_attrib
               ,imp_auto_import
               ,ROWID
         INTO   cg$sel_rec.id
               ,cg$sel_rec.creation_date
               ,cg$sel_rec.created_by
               ,cg$sel_rec.last_update_date
               ,cg$sel_rec.last_updated_by
               ,cg$sel_rec.cit_id
               ,cg$sel_rec.NAME
               ,cg$sel_rec.need_po
               ,cg$sel_rec.could_in_stock
               ,cg$sel_rec.could_in_inventory
               ,cg$sel_rec.order_in_list
               ,cg$sel_rec.abbreviation
               ,cg$sel_rec.naming_pattern
               ,cg$sel_rec.description
               ,cg$sel_rec.comments
               ,cg$sel_rec.icon_name
               ,cg$sel_rec.is_importable
               ,cg$sel_rec.imp_source_module
               ,cg$sel_rec.imp_source_name
               ,cg$sel_rec.imp_where_clause
               ,cg$sel_rec.imp_name_attrib
               ,cg$sel_rec.imp_auto_import
               ,cg$sel_rec.the_rowid
         FROM   nit_ci_types
         WHERE  ROWID = cg$sel_rec.the_rowid;
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_TYPES.slct.others');
         cg$errors.raise_failure;

   END slct;

   --------------------------------------------------------------------------------
   -- Name:        validate_domain
   --
   -- Description: Checks against reference table for values lying in a domain
   --
   -- Parameters:  cg$rec     Record of NIT_CI_TYPES current values
   --------------------------------------------------------------------------------
   PROCEDURE validate_domain(cg$rec IN OUT cg$row_type
                            ,cg$ind IN cg$ind_type DEFAULT cg$ind_true) IS
      FOUND BOOLEAN;
      no_tabview EXCEPTION;
      PRAGMA EXCEPTION_INIT(no_tabview
                           ,-942);
   BEGIN

      FOUND := FALSE;
      IF (cg$ind.imp_source_module AND cg$rec.imp_source_module IS NOT NULL) THEN
         FOR c IN (SELECT rv_low_value
                         ,rv_high_value
                   FROM   cg_ref_codes
                   WHERE  rv_domain = 'IMP_SOURCE_MODULE_DOMAIN') LOOP
            IF (c.rv_high_value IS NULL AND
               cg$rec.imp_source_module = c.rv_low_value) OR
               (c.rv_high_value IS NOT NULL AND
               cg$rec.imp_source_module BETWEEN c.rv_low_value AND
               c.rv_high_value) THEN
               FOUND := TRUE;
               EXIT;
            END IF;
         END LOOP;

         IF (NOT FOUND) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_rv_lookup_fail
                                               ,cg$errors.apimsg_rv_lookup_fail
                                               ,cg$rec.imp_source_module
                                               ,'NIT_CI_TYPES'
                                               ,'IMP_SOURCE_MODULE')
                          ,'E'
                          ,'API'
                          ,cg$errors.api_rv_lookup_fail
                          ,'cg$NIT_CI_TYPES.v_domain.no_data_found');
            cg$errors.raise_failure;
         END IF;
      END IF;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         cg$errors.raise_failure;
      WHEN no_tabview THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_rv_tab_not_found
                                            ,cg$errors.apimsg_rv_tab_not_found
                                            ,'CG_REF_CODES'
                                            ,'NIT_CI_TYPES')
                       ,'E'
                       ,'API'
                       ,cg$errors.api_rv_tab_not_found
                       ,'cg$NIT_CI_TYPES.v_domain.no_reftable_found');
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_TYPES.v_domain.others');
         cg$errors.raise_failure;
   END validate_domain;


   --------------------------------------------------------------------------------
   -- Name:        err_msg
   --
   -- Description: Pushes onto stack appropriate user defined error message
   --              depending on the rule violated
   --
   -- Parameters:  msg     Oracle error message
   --              type    Type of violation e.g. check_constraint: ERR_CHECK_CON
   --              loc     Place where this procedure was called for error
   --                      trapping
   --------------------------------------------------------------------------------
   PROCEDURE err_msg(msg  IN VARCHAR2
                    ,TYPE IN INTEGER
                    ,loc  IN VARCHAR2 DEFAULT '') IS
      con_name VARCHAR2(240);
   BEGIN
      con_name := cg$errors.parse_constraint(msg
                                            ,TYPE);
      IF (con_name = 'NIT_CPK_CIT') THEN
         cg$errors.push(NVL(nit_cpk_cit
                           ,cg$errors.msggettext(cg$errors.api_pk_con_violated
                                                ,cg$errors.apimsg_pk_violat
                                                ,'NIT_CPK_CIT'
                                                ,'NIT_CI_TYPES'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_pk_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CUK_CIT') THEN
         cg$errors.push(NVL(nit_cuk_cit
                           ,cg$errors.msggettext(cg$errors.api_uq_con_violated
                                                ,cg$errors.apimsg_uk_violat
                                                ,'NIT_CUK_CIT'
                                                ,'NIT_CI_TYPES'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_uq_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CFK_CIT_CIT' AND
            TYPE = cg$errors.err_delete_restrict) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_del_restrict
                                            ,cg$errors.err_del_restrict
                                            ,'NIT_CI_TYPES'
                                            ,'NIT_CI_TYPES')
                       ,'E'
                       ,'API'
                       ,cg$errors.api_del_restrict
                       ,loc);

      ELSIF (con_name = 'NIT_CFK_CIT_CIT') THEN
         cg$errors.push(NVL(nit_cfk_cit_cit
                           ,cg$errors.msggettext(cg$errors.api_fk_con_violated
                                                ,cg$errors.apimsg_fk_violat
                                                ,'NIT_CFK_CIT_CIT'
                                                ,'NIT_CI_TYPES'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_fk_con_violated
                       ,loc);
      ELSE
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,loc);
      END IF;
   END err_msg;

   --------------------------------------------------------------------------------
   -- Name:        ins
   --
   -- Description: API insert procedure
   --
   -- Parameters:  cg$rec  Record of row to be inserted
   --              cg$ind  Record of columns specifically set
   --              do_ins  Whether we want the actual INSERT to occur
   --------------------------------------------------------------------------------
   PROCEDURE ins(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_ins IN BOOLEAN DEFAULT TRUE) IS

      --  Constant default values

      d50_need_po            CONSTANT nit_ci_types.need_po%TYPE := 'N';
      d60_could_in_stock     CONSTANT nit_ci_types.could_in_stock%TYPE := 'Y';
      d70_could_in_inventory CONSTANT nit_ci_types.could_in_inventory%TYPE := 'N';
      d80_order_in_list      CONSTANT nit_ci_types.order_in_list%TYPE := 0;
      d140_is_importable     CONSTANT nit_ci_types.is_importable%TYPE := 'N';
      d150_imp_source_module CONSTANT nit_ci_types.imp_source_module%TYPE := 'SMS';
      d170_imp_where_clause  CONSTANT nit_ci_types.imp_where_clause%TYPE := '1=1';
      d200_imp_auto_import   CONSTANT nit_ci_types.imp_auto_import%TYPE := 'N';

   BEGIN
      nit_ci_types_p.pre_dml(cg$rec
                            ,cg$ind
                            ,'INS');

      --  Defaulted

      IF NOT (cg$ind.need_po) THEN
         cg$rec.need_po := d50_need_po;
      END IF;
      IF NOT (cg$ind.could_in_stock) THEN
         cg$rec.could_in_stock := d60_could_in_stock;
      END IF;
      IF NOT (cg$ind.could_in_inventory) THEN
         cg$rec.could_in_inventory := d70_could_in_inventory;
      END IF;
      IF NOT (cg$ind.order_in_list) THEN
         cg$rec.order_in_list := d80_order_in_list;
      END IF;
      IF NOT (cg$ind.is_importable) THEN
         cg$rec.is_importable := d140_is_importable;
      END IF;
      IF NOT (cg$ind.imp_source_module) THEN
         cg$rec.imp_source_module := d150_imp_source_module;
      END IF;
      IF NOT (cg$ind.imp_where_clause) THEN
         cg$rec.imp_where_clause := d170_imp_where_clause;
      END IF;
      IF NOT (cg$ind.imp_auto_import) THEN
         cg$rec.imp_auto_import := d200_imp_auto_import;
      END IF;
      --  Auto-generated and uppercased columns

      up_autogen_columns(cg$rec
                        ,cg$ind
                        ,'INS'
                        ,do_ins);

      called_from_package := TRUE;

      IF (do_ins) THEN
         validate_domain(cg$rec);

         INSERT INTO nit_ci_types
            (id
            ,creation_date
            ,created_by
            ,last_update_date
            ,last_updated_by
            ,cit_id
            ,NAME
            ,need_po
            ,could_in_stock
            ,could_in_inventory
            ,order_in_list
            ,abbreviation
            ,naming_pattern
            ,description
            ,comments
            ,icon_name
            ,is_importable
            ,imp_source_module
            ,imp_source_name
            ,imp_where_clause
            ,imp_name_attrib
            ,imp_auto_import)
         VALUES
            (cg$rec.id
            ,cg$rec.creation_date
            ,cg$rec.created_by
            ,cg$rec.last_update_date
            ,cg$rec.last_updated_by
            ,cg$rec.cit_id
            ,cg$rec.NAME
            ,cg$rec.need_po
            ,cg$rec.could_in_stock
            ,cg$rec.could_in_inventory
            ,cg$rec.order_in_list
            ,cg$rec.abbreviation
            ,cg$rec.naming_pattern
            ,cg$rec.description
            ,cg$rec.comments
            ,cg$rec.icon_name
            ,cg$rec.is_importable
            ,cg$rec.imp_source_module
            ,cg$rec.imp_source_name
            ,cg$rec.imp_where_clause
            ,cg$rec.imp_name_attrib
            ,cg$rec.imp_auto_import)
         RETURNING id, creation_date, created_by, last_update_date, last_updated_by, cit_id, NAME, need_po, could_in_stock, could_in_inventory, order_in_list, abbreviation, naming_pattern, description, comments, icon_name, is_importable, imp_source_module, imp_source_name, imp_where_clause, imp_name_attrib, imp_auto_import, ROWID INTO cg$rec.id, cg$rec.creation_date, cg$rec.created_by, cg$rec.last_update_date, cg$rec.last_updated_by, cg$rec.cit_id, cg$rec.NAME, cg$rec.need_po, cg$rec.could_in_stock, cg$rec.could_in_inventory, cg$rec.order_in_list, cg$rec.abbreviation, cg$rec.naming_pattern, cg$rec.description, cg$rec.comments, cg$rec.icon_name, cg$rec.is_importable, cg$rec.imp_source_module, cg$rec.imp_source_name, cg$rec.imp_where_clause, cg$rec.imp_name_attrib, cg$rec.imp_auto_import, cg$rec.the_rowid;

      END IF;

      called_from_package := FALSE;

      nit_ci_types_p.cascade_ins(cg$rec);

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.mandatory_missing THEN
         validate_mandatory(cg$rec
                           ,'cg$NIT_CI_TYPES.ins.mandatory_missing');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.check_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_check_con
                ,'cg$NIT_CI_TYPES.ins.check_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.fk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_foreign_key
                ,'cg$NIT_CI_TYPES.ins.fk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.uk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_unique_key
                ,'cg$NIT_CI_TYPES.ins.uk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_TYPES.ins.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END ins;


   --------------------------------------------------------------------------------
   -- Name:        upd
   --
   -- Description: API update procedure
   --
   -- Parameters:  cg$rec  Record of row to be updated
   --              cg$ind  Record of columns specifically set
   --              do_upd  Whether we want the actual UPDATE to occur
   --------------------------------------------------------------------------------
   PROCEDURE upd(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_upd IN BOOLEAN DEFAULT TRUE
                ,cg$pk  IN cg$row_type DEFAULT NULL) IS
      cg$upd_rec cg$row_type;
      cg$old_rec cg$row_type;
   BEGIN
      nit_ci_types_p.pre_dml(cg$rec
                            ,cg$ind
                            ,'UPD');

      IF (cg$pk.id IS NULL) THEN
         cg$upd_rec.id := cg$rec.id;
      ELSE
         cg$upd_rec.id := cg$pk.id;
      END IF;
      cg$old_rec.id := cg$upd_rec.id;

      IF (cg$pk.the_rowid IS NULL) THEN
         cg$upd_rec.the_rowid := cg$rec.the_rowid;
      ELSE
         cg$upd_rec.the_rowid := cg$pk.the_rowid;
      END IF;
      cg$old_rec.the_rowid := cg$upd_rec.the_rowid;

      IF (do_upd) THEN

         slct(cg$upd_rec);

         --  Report error if attempt to update non transferable Foreign Key NIT_CFK_CIT_CIT
         IF (cg$ind.cit_id AND cg$rec.cit_id != cg$upd_rec.cit_id) THEN
            raise_fk_not_transferable('NIT_CFK_CIT_CIT');
         END IF;
         IF (cg$ind.cit_id AND cg$rec.cit_id IS NULL AND
            cg$upd_rec.cit_id IS NOT NULL) THEN
            raise_fk_not_transferable('NIT_CFK_CIT_CIT');
         END IF;
         IF (cg$ind.cit_id AND cg$rec.cit_id IS NOT NULL AND
            cg$upd_rec.cit_id IS NULL) THEN
            raise_fk_not_transferable('NIT_CFK_CIT_CIT');
         END IF;

         --  Report error if attempt to update non updateable Primary Key NIT_CPK_CIT
         IF (cg$ind.id AND cg$rec.id != cg$upd_rec.id) THEN
            raise_uk_not_updateable('NIT_CPK_CIT');
         END IF;
         IF NOT (cg$ind.id) THEN
            cg$rec.id := cg$upd_rec.id;
         END IF;
         IF NOT (cg$ind.creation_date) THEN
            cg$rec.creation_date := cg$upd_rec.creation_date;
         END IF;
         IF NOT (cg$ind.created_by) THEN
            cg$rec.created_by := cg$upd_rec.created_by;
         END IF;
         IF NOT (cg$ind.last_update_date) THEN
            cg$rec.last_update_date := cg$upd_rec.last_update_date;
         END IF;
         IF NOT (cg$ind.last_updated_by) THEN
            cg$rec.last_updated_by := cg$upd_rec.last_updated_by;
         END IF;
         IF NOT (cg$ind.cit_id) THEN
            cg$rec.cit_id := cg$upd_rec.cit_id;
         END IF;
         IF NOT (cg$ind.NAME) THEN
            cg$rec.NAME := cg$upd_rec.NAME;
         END IF;
         IF NOT (cg$ind.need_po) THEN
            cg$rec.need_po := cg$upd_rec.need_po;
         END IF;
         IF NOT (cg$ind.could_in_stock) THEN
            cg$rec.could_in_stock := cg$upd_rec.could_in_stock;
         END IF;
         IF NOT (cg$ind.could_in_inventory) THEN
            cg$rec.could_in_inventory := cg$upd_rec.could_in_inventory;
         END IF;
         IF NOT (cg$ind.order_in_list) THEN
            cg$rec.order_in_list := cg$upd_rec.order_in_list;
         END IF;
         IF NOT (cg$ind.abbreviation) THEN
            cg$rec.abbreviation := cg$upd_rec.abbreviation;
         END IF;
         IF NOT (cg$ind.naming_pattern) THEN
            cg$rec.naming_pattern := cg$upd_rec.naming_pattern;
         END IF;
         IF NOT (cg$ind.description) THEN
            cg$rec.description := cg$upd_rec.description;
         END IF;
         IF NOT (cg$ind.comments) THEN
            cg$rec.comments := cg$upd_rec.comments;
         END IF;
         IF NOT (cg$ind.icon_name) THEN
            cg$rec.icon_name := cg$upd_rec.icon_name;
         END IF;
         IF NOT (cg$ind.is_importable) THEN
            cg$rec.is_importable := cg$upd_rec.is_importable;
         END IF;
         IF NOT (cg$ind.imp_source_module) THEN
            cg$rec.imp_source_module := cg$upd_rec.imp_source_module;
         END IF;
         IF NOT (cg$ind.imp_source_name) THEN
            cg$rec.imp_source_name := cg$upd_rec.imp_source_name;
         END IF;
         IF NOT (cg$ind.imp_where_clause) THEN
            cg$rec.imp_where_clause := cg$upd_rec.imp_where_clause;
         END IF;
         IF NOT (cg$ind.imp_name_attrib) THEN
            cg$rec.imp_name_attrib := cg$upd_rec.imp_name_attrib;
         END IF;
         IF NOT (cg$ind.imp_auto_import) THEN
            cg$rec.imp_auto_import := cg$upd_rec.imp_auto_import;
         END IF;
      ELSE
         -- Perform checks if called from a trigger
         -- Indicators are only set on changed values
         NULL;
         --  Report error if attempt to update non transferable Foreign Key NIT_CFK_CIT_CIT
         IF (cg$ind.cit_id) THEN
            raise_fk_not_transferable('NIT_CFK_CIT_CIT');
         END IF;
         --  Report error if attempt to update non updateable Primary Key NIT_CPK_CIT
         IF (cg$ind.id) THEN
            raise_uk_not_updateable('NIT_CPK_CIT');
         END IF;
      END IF;

      up_autogen_columns(cg$rec
                        ,cg$ind
                        ,'UPD'
                        ,do_upd); --  Auto-generated and uppercased columns

      --  Now do update if updateable columns exist
      IF (do_upd) THEN
         DECLARE
            called_from BOOLEAN := called_from_package;
         BEGIN
            called_from_package := TRUE;

            slct(cg$old_rec);
            validate_domain(cg$rec
                           ,cg$ind);

            IF cg$rec.the_rowid IS NULL THEN
               UPDATE nit_ci_types
               SET    creation_date      = cg$rec.creation_date
                     ,created_by         = cg$rec.created_by
                     ,last_update_date   = cg$rec.last_update_date
                     ,last_updated_by    = cg$rec.last_updated_by
                     ,cit_id             = cg$rec.cit_id
                     ,NAME               = cg$rec.NAME
                     ,need_po            = cg$rec.need_po
                     ,could_in_stock     = cg$rec.could_in_stock
                     ,could_in_inventory = cg$rec.could_in_inventory
                     ,order_in_list      = cg$rec.order_in_list
                     ,abbreviation       = cg$rec.abbreviation
                     ,naming_pattern     = cg$rec.naming_pattern
                     ,description        = cg$rec.description
                     ,comments           = cg$rec.comments
                     ,icon_name          = cg$rec.icon_name
                     ,is_importable      = cg$rec.is_importable
                     ,imp_source_module  = cg$rec.imp_source_module
                     ,imp_source_name    = cg$rec.imp_source_name
                     ,imp_where_clause   = cg$rec.imp_where_clause
                     ,imp_name_attrib    = cg$rec.imp_name_attrib
                     ,imp_auto_import    = cg$rec.imp_auto_import
               WHERE  id = cg$rec.id RETURNING id, creation_date, created_by,
                last_update_date, last_updated_by, cit_id, NAME, need_po,
                could_in_stock, could_in_inventory, order_in_list,
                abbreviation, naming_pattern, description, comments,
                icon_name, is_importable, imp_source_module,
                imp_source_name, imp_where_clause, imp_name_attrib,
                imp_auto_import, ROWID INTO cg$rec.id,
                cg$rec.creation_date, cg$rec.created_by,
                cg$rec.last_update_date, cg$rec.last_updated_by,
                cg$rec.cit_id, cg$rec.NAME, cg$rec.need_po,
                cg$rec.could_in_stock, cg$rec.could_in_inventory,
                cg$rec.order_in_list, cg$rec.abbreviation,
                cg$rec.naming_pattern, cg$rec.description,
                cg$rec.comments, cg$rec.icon_name, cg$rec.is_importable,
                cg$rec.imp_source_module, cg$rec.imp_source_name,
                cg$rec.imp_where_clause, cg$rec.imp_name_attrib,
                cg$rec.imp_auto_import, cg$rec.the_rowid;
            ELSE
               UPDATE nit_ci_types
               SET    creation_date      = cg$rec.creation_date
                     ,created_by         = cg$rec.created_by
                     ,last_update_date   = cg$rec.last_update_date
                     ,last_updated_by    = cg$rec.last_updated_by
                     ,cit_id             = cg$rec.cit_id
                     ,NAME               = cg$rec.NAME
                     ,need_po            = cg$rec.need_po
                     ,could_in_stock     = cg$rec.could_in_stock
                     ,could_in_inventory = cg$rec.could_in_inventory
                     ,order_in_list      = cg$rec.order_in_list
                     ,abbreviation       = cg$rec.abbreviation
                     ,naming_pattern     = cg$rec.naming_pattern
                     ,description        = cg$rec.description
                     ,comments           = cg$rec.comments
                     ,icon_name          = cg$rec.icon_name
                     ,is_importable      = cg$rec.is_importable
                     ,imp_source_module  = cg$rec.imp_source_module
                     ,imp_source_name    = cg$rec.imp_source_name
                     ,imp_where_clause   = cg$rec.imp_where_clause
                     ,imp_name_attrib    = cg$rec.imp_name_attrib
                     ,imp_auto_import    = cg$rec.imp_auto_import
               WHERE  ROWID = cg$rec.the_rowid RETURNING id, creation_date,
                created_by, last_update_date, last_updated_by, cit_id, NAME,
                need_po, could_in_stock, could_in_inventory,
                order_in_list, abbreviation, naming_pattern, description,
                comments, icon_name, is_importable, imp_source_module,
                imp_source_name, imp_where_clause, imp_name_attrib,
                imp_auto_import, ROWID INTO cg$rec.id,
                cg$rec.creation_date, cg$rec.created_by,
                cg$rec.last_update_date, cg$rec.last_updated_by,
                cg$rec.cit_id, cg$rec.NAME, cg$rec.need_po,
                cg$rec.could_in_stock, cg$rec.could_in_inventory,
                cg$rec.order_in_list, cg$rec.abbreviation,
                cg$rec.naming_pattern, cg$rec.description,
                cg$rec.comments, cg$rec.icon_name, cg$rec.is_importable,
                cg$rec.imp_source_module, cg$rec.imp_source_name,
                cg$rec.imp_where_clause, cg$rec.imp_name_attrib,
                cg$rec.imp_auto_import, cg$rec.the_rowid;
            END IF;

            called_from_package := called_from;
         END;
      END IF;



      IF NOT (do_upd) THEN
         cg$table(idx).id := cg$rec.id;
         cg$tableind(idx).id := cg$ind.id;
         cg$table(idx).creation_date := cg$rec.creation_date;
         cg$tableind(idx).creation_date := cg$ind.creation_date;
         cg$table(idx).created_by := cg$rec.created_by;
         cg$tableind(idx).created_by := cg$ind.created_by;
         cg$table(idx).last_update_date := cg$rec.last_update_date;
         cg$tableind(idx).last_update_date := cg$ind.last_update_date;
         cg$table(idx).last_updated_by := cg$rec.last_updated_by;
         cg$tableind(idx).last_updated_by := cg$ind.last_updated_by;
         cg$table(idx).cit_id := cg$rec.cit_id;
         cg$tableind(idx).cit_id := cg$ind.cit_id;
         cg$table(idx).NAME := cg$rec.NAME;
         cg$tableind(idx).NAME := cg$ind.NAME;
         cg$table(idx).need_po := cg$rec.need_po;
         cg$tableind(idx).need_po := cg$ind.need_po;
         cg$table(idx).could_in_stock := cg$rec.could_in_stock;
         cg$tableind(idx).could_in_stock := cg$ind.could_in_stock;
         cg$table(idx).could_in_inventory := cg$rec.could_in_inventory;
         cg$tableind(idx).could_in_inventory := cg$ind.could_in_inventory;
         cg$table(idx).order_in_list := cg$rec.order_in_list;
         cg$tableind(idx).order_in_list := cg$ind.order_in_list;
         cg$table(idx).abbreviation := cg$rec.abbreviation;
         cg$tableind(idx).abbreviation := cg$ind.abbreviation;
         cg$table(idx).naming_pattern := cg$rec.naming_pattern;
         cg$tableind(idx).naming_pattern := cg$ind.naming_pattern;
         cg$table(idx).description := cg$rec.description;
         cg$tableind(idx).description := cg$ind.description;
         cg$table(idx).comments := cg$rec.comments;
         cg$tableind(idx).comments := cg$ind.comments;
         cg$table(idx).icon_name := cg$rec.icon_name;
         cg$tableind(idx).icon_name := cg$ind.icon_name;
         cg$table(idx).is_importable := cg$rec.is_importable;
         cg$tableind(idx).is_importable := cg$ind.is_importable;
         cg$table(idx).imp_source_module := cg$rec.imp_source_module;
         cg$tableind(idx).imp_source_module := cg$ind.imp_source_module;
         cg$table(idx).imp_source_name := cg$rec.imp_source_name;
         cg$tableind(idx).imp_source_name := cg$ind.imp_source_name;
         cg$table(idx).imp_where_clause := cg$rec.imp_where_clause;
         cg$tableind(idx).imp_where_clause := cg$ind.imp_where_clause;
         cg$table(idx).imp_name_attrib := cg$rec.imp_name_attrib;
         cg$tableind(idx).imp_name_attrib := cg$ind.imp_name_attrib;
         cg$table(idx).imp_auto_import := cg$rec.imp_auto_import;
         cg$tableind(idx).imp_auto_import := cg$ind.imp_auto_import;
         idx := idx + 1;
      END IF;

      --  Application_logic Post-Update <<Start>>
      --  Application_logic Post-Update << End >>

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.upd_mandatory_null THEN
         validate_mandatory(cg$rec
                           ,'cg$NIT_CI_TYPES.upd.upd_mandatory_null');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.check_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_check_con
                ,'cg$NIT_CI_TYPES.upd.check_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.fk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_foreign_key
                ,'cg$NIT_CI_TYPES.upd.fk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.uk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_unique_key
                ,'cg$NIT_CI_TYPES.upd.uk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_TYPES.upd.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END upd;

   --------------------------------------------------------------------------------
   -- Name:        del
   --
   -- Description: API delete procedure
   --
   -- Parameters:  cg$pk  Primary key record of row to be deleted
   --------------------------------------------------------------------------------
   PROCEDURE del(cg$pk  IN cg$pk_type
                ,do_del IN BOOLEAN DEFAULT TRUE) IS
   BEGIN
      nit_ci_types_p.pre_del(cg$pk.id);

      --  Delete the record

      called_from_package := TRUE;

      IF (do_del) THEN

         IF cg$pk.the_rowid IS NULL THEN
            DELETE nit_ci_types
            WHERE  id = cg$pk.id;
         ELSE
            DELETE nit_ci_types
            WHERE  ROWID = cg$pk.the_rowid;
         END IF;

      END IF;

      called_from_package := FALSE;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.delete_restrict THEN
         err_msg(SQLERRM
                ,cg$errors.err_delete_restrict
                ,'cg$NIT_CI_TYPES.del.delete_restrict');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN no_data_found THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_row_del
                                            ,cg$errors.row_del)
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_TYPES.del.no_data_found');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CI_TYPES.del.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END del;


   --------------------------------------------------------------------------------
   -- Name:        lck
   --
   -- Description: API lock procedure
   --
   -- Parameters:  cg$old_rec  Calling apps view of record of row to be locked
   --              cg$old_ind  Record of columns to raise error if modified
   --              nowait_flag TRUE lock with NOWAIT, FALSE don't fail if busy
   --------------------------------------------------------------------------------
   PROCEDURE lck(cg$old_rec  IN cg$row_type
                ,cg$old_ind  IN cg$ind_type
                ,nowait_flag IN BOOLEAN DEFAULT TRUE) IS
      cg$tmp_rec   cg$row_type;
      any_modified BOOLEAN := FALSE;

   BEGIN

      BEGIN
         IF (nowait_flag) THEN
            IF cg$old_rec.the_rowid IS NULL THEN
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,cit_id
                     ,NAME
                     ,need_po
                     ,could_in_stock
                     ,could_in_inventory
                     ,order_in_list
                     ,abbreviation
                     ,naming_pattern
                     ,description
                     ,comments
                     ,icon_name
                     ,is_importable
                     ,imp_source_module
                     ,imp_source_name
                     ,imp_where_clause
                     ,imp_name_attrib
                     ,imp_auto_import
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.cit_id
                     ,cg$tmp_rec.NAME
                     ,cg$tmp_rec.need_po
                     ,cg$tmp_rec.could_in_stock
                     ,cg$tmp_rec.could_in_inventory
                     ,cg$tmp_rec.order_in_list
                     ,cg$tmp_rec.abbreviation
                     ,cg$tmp_rec.naming_pattern
                     ,cg$tmp_rec.description
                     ,cg$tmp_rec.comments
                     ,cg$tmp_rec.icon_name
                     ,cg$tmp_rec.is_importable
                     ,cg$tmp_rec.imp_source_module
                     ,cg$tmp_rec.imp_source_name
                     ,cg$tmp_rec.imp_where_clause
                     ,cg$tmp_rec.imp_name_attrib
                     ,cg$tmp_rec.imp_auto_import
               FROM   nit_ci_types
               WHERE  id = cg$old_rec.id
               FOR    UPDATE NOWAIT;
            ELSE
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,cit_id
                     ,NAME
                     ,need_po
                     ,could_in_stock
                     ,could_in_inventory
                     ,order_in_list
                     ,abbreviation
                     ,naming_pattern
                     ,description
                     ,comments
                     ,icon_name
                     ,is_importable
                     ,imp_source_module
                     ,imp_source_name
                     ,imp_where_clause
                     ,imp_name_attrib
                     ,imp_auto_import
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.cit_id
                     ,cg$tmp_rec.NAME
                     ,cg$tmp_rec.need_po
                     ,cg$tmp_rec.could_in_stock
                     ,cg$tmp_rec.could_in_inventory
                     ,cg$tmp_rec.order_in_list
                     ,cg$tmp_rec.abbreviation
                     ,cg$tmp_rec.naming_pattern
                     ,cg$tmp_rec.description
                     ,cg$tmp_rec.comments
                     ,cg$tmp_rec.icon_name
                     ,cg$tmp_rec.is_importable
                     ,cg$tmp_rec.imp_source_module
                     ,cg$tmp_rec.imp_source_name
                     ,cg$tmp_rec.imp_where_clause
                     ,cg$tmp_rec.imp_name_attrib
                     ,cg$tmp_rec.imp_auto_import
               FROM   nit_ci_types
               WHERE  ROWID = cg$old_rec.the_rowid
               FOR    UPDATE NOWAIT;
            END IF;
         ELSE
            IF cg$old_rec.the_rowid IS NULL THEN
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,cit_id
                     ,NAME
                     ,need_po
                     ,could_in_stock
                     ,could_in_inventory
                     ,order_in_list
                     ,abbreviation
                     ,naming_pattern
                     ,description
                     ,comments
                     ,icon_name
                     ,is_importable
                     ,imp_source_module
                     ,imp_source_name
                     ,imp_where_clause
                     ,imp_name_attrib
                     ,imp_auto_import
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.cit_id
                     ,cg$tmp_rec.NAME
                     ,cg$tmp_rec.need_po
                     ,cg$tmp_rec.could_in_stock
                     ,cg$tmp_rec.could_in_inventory
                     ,cg$tmp_rec.order_in_list
                     ,cg$tmp_rec.abbreviation
                     ,cg$tmp_rec.naming_pattern
                     ,cg$tmp_rec.description
                     ,cg$tmp_rec.comments
                     ,cg$tmp_rec.icon_name
                     ,cg$tmp_rec.is_importable
                     ,cg$tmp_rec.imp_source_module
                     ,cg$tmp_rec.imp_source_name
                     ,cg$tmp_rec.imp_where_clause
                     ,cg$tmp_rec.imp_name_attrib
                     ,cg$tmp_rec.imp_auto_import
               FROM   nit_ci_types
               WHERE  id = cg$old_rec.id
               FOR    UPDATE;
            ELSE
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,cit_id
                     ,NAME
                     ,need_po
                     ,could_in_stock
                     ,could_in_inventory
                     ,order_in_list
                     ,abbreviation
                     ,naming_pattern
                     ,description
                     ,comments
                     ,icon_name
                     ,is_importable
                     ,imp_source_module
                     ,imp_source_name
                     ,imp_where_clause
                     ,imp_name_attrib
                     ,imp_auto_import
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.cit_id
                     ,cg$tmp_rec.NAME
                     ,cg$tmp_rec.need_po
                     ,cg$tmp_rec.could_in_stock
                     ,cg$tmp_rec.could_in_inventory
                     ,cg$tmp_rec.order_in_list
                     ,cg$tmp_rec.abbreviation
                     ,cg$tmp_rec.naming_pattern
                     ,cg$tmp_rec.description
                     ,cg$tmp_rec.comments
                     ,cg$tmp_rec.icon_name
                     ,cg$tmp_rec.is_importable
                     ,cg$tmp_rec.imp_source_module
                     ,cg$tmp_rec.imp_source_name
                     ,cg$tmp_rec.imp_where_clause
                     ,cg$tmp_rec.imp_name_attrib
                     ,cg$tmp_rec.imp_auto_import
               FROM   nit_ci_types
               WHERE  ROWID = cg$old_rec.the_rowid
               FOR    UPDATE;
            END IF;
         END IF;

      EXCEPTION
         WHEN cg$errors.cg$error THEN
            cg$errors.raise_failure;
         WHEN cg$errors.resource_busy THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_lck
                                               ,cg$errors.row_lck)
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_CI_TYPES.lck.resource_busy');
            cg$errors.raise_failure;
         WHEN no_data_found THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_del
                                               ,cg$errors.row_del)
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_CI_TYPES.lck.no_data_found');
            cg$errors.raise_failure;
         WHEN OTHERS THEN
            cg$errors.push(SQLERRM
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_CI_TYPES.lck.others');
            cg$errors.raise_failure;
      END;

      -- Optional Columns

      IF (cg$old_ind.cit_id) THEN
         IF (cg$tmp_rec.cit_id IS NOT NULL AND cg$old_rec.cit_id IS NOT NULL) THEN
            IF (cg$tmp_rec.cit_id != cg$old_rec.cit_id) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p30cit_id)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_TYPES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.cit_id IS NOT NULL OR cg$old_rec.cit_id IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p30cit_id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.abbreviation) THEN
         IF (cg$tmp_rec.abbreviation IS NOT NULL AND
            cg$old_rec.abbreviation IS NOT NULL) THEN
            IF (cg$tmp_rec.abbreviation != cg$old_rec.abbreviation) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p90abbreviation)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_TYPES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.abbreviation IS NOT NULL OR
               cg$old_rec.abbreviation IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p90abbreviation)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.naming_pattern) THEN
         IF (cg$tmp_rec.naming_pattern IS NOT NULL AND
            cg$old_rec.naming_pattern IS NOT NULL) THEN
            IF (cg$tmp_rec.naming_pattern != cg$old_rec.naming_pattern) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p100naming_pattern)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_TYPES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.naming_pattern IS NOT NULL OR
               cg$old_rec.naming_pattern IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p100naming_pattern)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.description) THEN
         IF (cg$tmp_rec.description IS NOT NULL AND
            cg$old_rec.description IS NOT NULL) THEN
            IF (cg$tmp_rec.description != cg$old_rec.description) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p110description)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_TYPES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.description IS NOT NULL OR
               cg$old_rec.description IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p110description)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.comments) THEN
         IF (cg$tmp_rec.comments IS NOT NULL AND
            cg$old_rec.comments IS NOT NULL) THEN
            IF (cg$tmp_rec.comments != cg$old_rec.comments) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p120comments)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_TYPES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.comments IS NOT NULL OR
               cg$old_rec.comments IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p120comments)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.icon_name) THEN
         IF (cg$tmp_rec.icon_name IS NOT NULL AND
            cg$old_rec.icon_name IS NOT NULL) THEN
            IF (cg$tmp_rec.icon_name != cg$old_rec.icon_name) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p130icon_name)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_TYPES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.icon_name IS NOT NULL OR
               cg$old_rec.icon_name IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p130icon_name)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.imp_source_module) THEN
         IF (cg$tmp_rec.imp_source_module IS NOT NULL AND
            cg$old_rec.imp_source_module IS NOT NULL) THEN
            IF (cg$tmp_rec.imp_source_module != cg$old_rec.imp_source_module) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p150imp_source_module)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_TYPES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.imp_source_module IS NOT NULL OR
               cg$old_rec.imp_source_module IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p150imp_source_module)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.imp_source_name) THEN
         IF (cg$tmp_rec.imp_source_name IS NOT NULL AND
            cg$old_rec.imp_source_name IS NOT NULL) THEN
            IF (cg$tmp_rec.imp_source_name != cg$old_rec.imp_source_name) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p150imp_source_name)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_TYPES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.imp_source_name IS NOT NULL OR
               cg$old_rec.imp_source_name IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p150imp_source_name)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.imp_where_clause) THEN
         IF (cg$tmp_rec.imp_where_clause IS NOT NULL AND
            cg$old_rec.imp_where_clause IS NOT NULL) THEN
            IF (cg$tmp_rec.imp_where_clause != cg$old_rec.imp_where_clause) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p170imp_where_clause)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_TYPES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.imp_where_clause IS NOT NULL OR
               cg$old_rec.imp_where_clause IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p170imp_where_clause)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.imp_name_attrib) THEN
         IF (cg$tmp_rec.imp_name_attrib IS NOT NULL AND
            cg$old_rec.imp_name_attrib IS NOT NULL) THEN
            IF (cg$tmp_rec.imp_name_attrib != cg$old_rec.imp_name_attrib) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p190imp_name_attrib)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CI_TYPES.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.imp_name_attrib IS NOT NULL OR
               cg$old_rec.imp_name_attrib IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p190imp_name_attrib)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;

      -- Mandatory Columns

      IF (cg$old_ind.id) THEN
         IF (cg$tmp_rec.id != cg$old_rec.id) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p10id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.creation_date) THEN
         IF (cg$tmp_rec.creation_date != cg$old_rec.creation_date) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p15creation_date)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.created_by) THEN
         IF (cg$tmp_rec.created_by != cg$old_rec.created_by) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p16created_by)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.last_update_date) THEN
         IF (cg$tmp_rec.last_update_date != cg$old_rec.last_update_date) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p19last_update_date)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.last_updated_by) THEN
         IF (cg$tmp_rec.last_updated_by != cg$old_rec.last_updated_by) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p24last_updated_by)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.NAME) THEN
         IF (cg$tmp_rec.NAME != cg$old_rec.NAME) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p40name)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.need_po) THEN
         IF (cg$tmp_rec.need_po != cg$old_rec.need_po) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p50need_po)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.could_in_stock) THEN
         IF (cg$tmp_rec.could_in_stock != cg$old_rec.could_in_stock) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p60could_in_stock)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.could_in_inventory) THEN
         IF (cg$tmp_rec.could_in_inventory != cg$old_rec.could_in_inventory) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p70could_in_inventory)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.order_in_list) THEN
         IF (cg$tmp_rec.order_in_list != cg$old_rec.order_in_list) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p80order_in_list)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.is_importable) THEN
         IF (cg$tmp_rec.is_importable != cg$old_rec.is_importable) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p140is_importable)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.imp_auto_import) THEN
         IF (cg$tmp_rec.imp_auto_import != cg$old_rec.imp_auto_import) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p200imp_auto_import)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CI_TYPES.lck');
            any_modified := TRUE;
         END IF;
      END IF;

      IF (any_modified) THEN
         cg$errors.raise_failure;
      END IF;

   END lck;


BEGIN
   cg$ind_true.id                 := TRUE;
   cg$ind_true.creation_date      := TRUE;
   cg$ind_true.created_by         := TRUE;
   cg$ind_true.last_update_date   := TRUE;
   cg$ind_true.last_updated_by    := TRUE;
   cg$ind_true.cit_id             := TRUE;
   cg$ind_true.NAME               := TRUE;
   cg$ind_true.need_po            := TRUE;
   cg$ind_true.could_in_stock     := TRUE;
   cg$ind_true.could_in_inventory := TRUE;
   cg$ind_true.order_in_list      := TRUE;
   cg$ind_true.abbreviation       := TRUE;
   cg$ind_true.naming_pattern     := TRUE;
   cg$ind_true.description        := TRUE;
   cg$ind_true.comments           := TRUE;
   cg$ind_true.icon_name          := TRUE;
   cg$ind_true.is_importable      := TRUE;
   cg$ind_true.imp_source_module  := TRUE;
   cg$ind_true.imp_source_name    := TRUE;
   cg$ind_true.imp_where_clause   := TRUE;
   cg$ind_true.imp_name_attrib    := TRUE;
   cg$ind_true.imp_auto_import    := TRUE;


END cg$nit_ci_types;
/

prompt
prompt Creating package body CG$NIT_CONFIG_ITEMS
prompt =========================================
prompt
CREATE OR REPLACE PACKAGE BODY cg$nit_config_items IS


   PROCEDURE validate_mandatory(cg$val_rec IN cg$row_type
                               ,loc        IN VARCHAR2 DEFAULT '');
   PROCEDURE up_autogen_columns(cg$rec    IN OUT cg$row_type
                               ,cg$ind    IN OUT cg$ind_type
                               ,operation IN VARCHAR2 DEFAULT 'INS'
                               ,do_denorm IN BOOLEAN DEFAULT TRUE);
   PROCEDURE err_msg(msg  IN VARCHAR2
                    ,TYPE IN INTEGER
                    ,loc  IN VARCHAR2 DEFAULT '');

   --------------------------------------------------------------------------------
   -- Name:        raise_uk_not_updateable
   --
   -- Description: Raise appropriate error when unique key updated
   --
   -- Parameters:  none
   --------------------------------------------------------------------------------
   PROCEDURE raise_uk_not_updateable(uk IN VARCHAR2) IS
   BEGIN
      cg$errors.push(cg$errors.msggettext(cg$errors.api_unique_key_update
                                         ,cg$errors.err_uk_update
                                         ,uk)
                    ,'E'
                    ,'API'
                    ,cg$errors.api_unique_key_update
                    ,'cg$NIT_CONFIG_ITEMS.raise_uk_not_updateable');
      cg$errors.raise_failure;
   END raise_uk_not_updateable;


   --------------------------------------------------------------------------------
   -- Name:        raise_fk_not_transferable
   --
   -- Description: Raise appropriate error when foreign key updated
   --
   -- Parameters:  none
   --------------------------------------------------------------------------------
   PROCEDURE raise_fk_not_transferable(fk IN VARCHAR2) IS
   BEGIN
      cg$errors.push(cg$errors.msggettext(cg$errors.api_foreign_key_trans
                                         ,cg$errors.err_fk_trans
                                         ,fk)
                    ,'E'
                    ,'API'
                    ,cg$errors.api_foreign_key_trans
                    ,'cg$NIT_CONFIG_ITEMS.raise_fk_not_transferable');
      cg$errors.raise_failure;
   END raise_fk_not_transferable;


   --------------------------------------------------------------------------------
   -- Name:        up_autogen_columns
   --
   -- Description: Specific autogeneration of column values and conversion to
   --              uppercase
   --
   -- Parameters:  cg$rec    Record of row to be manipulated
   --              cg$ind    Indicators for row
   --              operation Procedure where this procedure was called
   --------------------------------------------------------------------------------
   PROCEDURE up_autogen_columns(cg$rec    IN OUT cg$row_type
                               ,cg$ind    IN OUT cg$ind_type
                               ,operation IN VARCHAR2 DEFAULT 'INS'
                               ,do_denorm IN BOOLEAN DEFAULT TRUE) IS
   BEGIN
      IF (operation = 'INS') THEN
         BEGIN
            IF (cg$ind.id = FALSE OR cg$rec.id IS NULL) THEN
               SELECT nit_seq.NEXTVAL
               INTO   cg$rec.id
               FROM   dual;
               cg$ind.id := TRUE;
            END IF;
         EXCEPTION
            WHEN OTHERS THEN
               cg$errors.push(SQLERRM
                             ,'E'
                             ,'ORA'
                             ,SQLCODE
                             ,'cg$NIT_CONFIG_ITEMS.up_autogen.ID.OTHERS');
               cg$errors.raise_failure;
         END;
      ELSE
         -- (operation = 'UPD')
         NULL;
      END IF; -- (operation = 'INS') ELSE (operation = 'UPD')

      -- Statements executed for both 'INS' and 'UPD'


   EXCEPTION
      WHEN no_data_found THEN
         NULL;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CONFIG_ITEMS.up_autogen_columns');
         cg$errors.raise_failure;
   END up_autogen_columns;


   --------------------------------------------------------------------------------
   -- Name:        validate_mandatory
   --
   -- Description: Checks all mandatory columns are not null and raises appropriate
   --              error if not satisfied
   --
   -- Parameters:  cg$val_rec Record of row to be checked
   --              loc        Place where this procedure was called for error
   --                         trapping
   --------------------------------------------------------------------------------
   PROCEDURE validate_mandatory(cg$val_rec IN cg$row_type
                               ,loc        IN VARCHAR2 DEFAULT '') IS
   BEGIN
      IF (cg$val_rec.id IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p10id)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.creation_date IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p15creation_date)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.created_by IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p16created_by)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.last_update_date IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p19last_update_date)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.last_updated_by IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p24last_updated_by)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.cit_id IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p30cit_id)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.opn_id IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p40opn_id)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.NAME IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p45name)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.status IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p50status)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.obsolete IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p80obsolete)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.valid_from IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p90valid_from)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.valid_until IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p100valid_until)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      NULL;
   END validate_mandatory;

   --------------------------------------------------------------------------------
   -- Name:        slct
   --
   -- Description: Selects into the given parameter all the attributes for the row
   --              given by the primary key
   --
   -- Parameters:  cg$sel_rec  Record of row to be selected into using its PK
   --------------------------------------------------------------------------------
   PROCEDURE slct(cg$sel_rec IN OUT cg$row_type) IS

   BEGIN

      IF cg$sel_rec.the_rowid IS NULL THEN
         SELECT id
               ,creation_date
               ,created_by
               ,last_update_date
               ,last_updated_by
               ,cit_id
               ,opn_id
               ,sms_id
               ,NAME
               ,status
               ,obsolete
               ,valid_from
               ,valid_until
               ,comments
               ,last_refresh_date
               ,ROWID
         INTO   cg$sel_rec.id
               ,cg$sel_rec.creation_date
               ,cg$sel_rec.created_by
               ,cg$sel_rec.last_update_date
               ,cg$sel_rec.last_updated_by
               ,cg$sel_rec.cit_id
               ,cg$sel_rec.opn_id
               ,cg$sel_rec.sms_id
               ,cg$sel_rec.NAME
               ,cg$sel_rec.status
               ,cg$sel_rec.obsolete
               ,cg$sel_rec.valid_from
               ,cg$sel_rec.valid_until
               ,cg$sel_rec.comments
               ,cg$sel_rec.last_refresh_date
               ,cg$sel_rec.the_rowid
         FROM   nit_config_items
         WHERE  id = cg$sel_rec.id;
      ELSE
         SELECT id
               ,creation_date
               ,created_by
               ,last_update_date
               ,last_updated_by
               ,cit_id
               ,opn_id
               ,sms_id
               ,NAME
               ,status
               ,obsolete
               ,valid_from
               ,valid_until
               ,comments
               ,last_refresh_date
               ,ROWID
         INTO   cg$sel_rec.id
               ,cg$sel_rec.creation_date
               ,cg$sel_rec.created_by
               ,cg$sel_rec.last_update_date
               ,cg$sel_rec.last_updated_by
               ,cg$sel_rec.cit_id
               ,cg$sel_rec.opn_id
               ,cg$sel_rec.sms_id
               ,cg$sel_rec.NAME
               ,cg$sel_rec.status
               ,cg$sel_rec.obsolete
               ,cg$sel_rec.valid_from
               ,cg$sel_rec.valid_until
               ,cg$sel_rec.comments
               ,cg$sel_rec.last_refresh_date
               ,cg$sel_rec.the_rowid
         FROM   nit_config_items
         WHERE  ROWID = cg$sel_rec.the_rowid;
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CONFIG_ITEMS.slct.others');
         cg$errors.raise_failure;

   END slct;

   --------------------------------------------------------------------------------
   -- Name:        validate_domain
   --
   -- Description: Checks against reference table for values lying in a domain
   --
   -- Parameters:  cg$rec     Record of NIT_CONFIG_ITEMS current values
   --------------------------------------------------------------------------------
   PROCEDURE validate_domain(cg$rec IN OUT cg$row_type
                            ,cg$ind IN cg$ind_type DEFAULT cg$ind_true) IS
      FOUND BOOLEAN;
      no_tabview EXCEPTION;
      PRAGMA EXCEPTION_INIT(no_tabview
                           ,-942);
   BEGIN

      FOUND := FALSE;
      IF (cg$ind.status AND cg$rec.status IS NOT NULL) THEN
         FOR c IN (SELECT rv_low_value
                         ,rv_high_value
                   FROM   cg_ref_codes
                   WHERE  rv_domain = 'CI_STATUS') LOOP
            IF (c.rv_high_value IS NULL AND cg$rec.status = c.rv_low_value) OR
               (c.rv_high_value IS NOT NULL AND
               cg$rec.status BETWEEN c.rv_low_value AND c.rv_high_value) THEN
               FOUND := TRUE;
               EXIT;
            END IF;
         END LOOP;

         IF (NOT FOUND) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_rv_lookup_fail
                                               ,cg$errors.apimsg_rv_lookup_fail
                                               ,cg$rec.status
                                               ,'NIT_CONFIG_ITEMS'
                                               ,'STATUS')
                          ,'E'
                          ,'API'
                          ,cg$errors.api_rv_lookup_fail
                          ,'cg$NIT_CONFIG_ITEMS.v_domain.no_data_found');
            cg$errors.raise_failure;
         END IF;
      END IF;

      FOUND := FALSE;
      IF (cg$ind.obsolete AND cg$rec.obsolete IS NOT NULL) THEN
         FOR c IN (SELECT rv_low_value
                         ,rv_high_value
                   FROM   cg_ref_codes
                   WHERE  rv_domain = 'OBSOLETE') LOOP
            IF (c.rv_high_value IS NULL AND cg$rec.obsolete = c.rv_low_value) OR
               (c.rv_high_value IS NOT NULL AND
               cg$rec.obsolete BETWEEN c.rv_low_value AND c.rv_high_value) THEN
               FOUND := TRUE;
               EXIT;
            END IF;
         END LOOP;

         IF (NOT FOUND) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_rv_lookup_fail
                                               ,cg$errors.apimsg_rv_lookup_fail
                                               ,cg$rec.obsolete
                                               ,'NIT_CONFIG_ITEMS'
                                               ,'OBSOLETE')
                          ,'E'
                          ,'API'
                          ,cg$errors.api_rv_lookup_fail
                          ,'cg$NIT_CONFIG_ITEMS.v_domain.no_data_found');
            cg$errors.raise_failure;
         END IF;
      END IF;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         cg$errors.raise_failure;
      WHEN no_tabview THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_rv_tab_not_found
                                            ,cg$errors.apimsg_rv_tab_not_found
                                            ,'CG_REF_CODES'
                                            ,'NIT_CONFIG_ITEMS')
                       ,'E'
                       ,'API'
                       ,cg$errors.api_rv_tab_not_found
                       ,'cg$NIT_CONFIG_ITEMS.v_domain.no_reftable_found');
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CONFIG_ITEMS.v_domain.others');
         cg$errors.raise_failure;
   END validate_domain;


   --------------------------------------------------------------------------------
   -- Name:        err_msg
   --
   -- Description: Pushes onto stack appropriate user defined error message
   --              depending on the rule violated
   --
   -- Parameters:  msg     Oracle error message
   --              type    Type of violation e.g. check_constraint: ERR_CHECK_CON
   --              loc     Place where this procedure was called for error
   --                      trapping
   --------------------------------------------------------------------------------
   PROCEDURE err_msg(msg  IN VARCHAR2
                    ,TYPE IN INTEGER
                    ,loc  IN VARCHAR2 DEFAULT '') IS
      con_name VARCHAR2(240);
   BEGIN
      con_name := cg$errors.parse_constraint(msg
                                            ,TYPE);
      IF (con_name = 'NIT_CPK_CI') THEN
         cg$errors.push(NVL(nit_cpk_ci
                           ,cg$errors.msggettext(cg$errors.api_pk_con_violated
                                                ,cg$errors.apimsg_pk_violat
                                                ,'NIT_CPK_CI'
                                                ,'NIT_CONFIG_ITEMS'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_pk_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CFK_CIR_CI_FROM' AND
            TYPE = cg$errors.err_delete_restrict) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_del_restrict
                                            ,cg$errors.err_del_restrict
                                            ,'NIT_CONFIG_ITEMS'
                                            ,'NIT_CI_RELATIONS')
                       ,'E'
                       ,'API'
                       ,cg$errors.api_del_restrict
                       ,loc);
      ELSIF (con_name = 'NIT_CFK_PSN_CI' AND
            TYPE = cg$errors.err_delete_restrict) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_del_restrict
                                            ,cg$errors.err_del_restrict
                                            ,'NIT_CONFIG_ITEMS'
                                            ,'NIT_POSITIONS')
                       ,'E'
                       ,'API'
                       ,cg$errors.api_del_restrict
                       ,loc);
      ELSIF (con_name = 'NITIL_CFK_CIA_CI' AND
            TYPE = cg$errors.err_delete_restrict) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_del_restrict
                                            ,cg$errors.err_del_restrict
                                            ,'NIT_CONFIG_ITEMS'
                                            ,'NIT_CI_ATTRIBUTES')
                       ,'E'
                       ,'API'
                       ,cg$errors.api_del_restrict
                       ,loc);
      ELSIF (con_name = 'NIT_CFK_CIR_CI_TO' AND
            TYPE = cg$errors.err_delete_restrict) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_del_restrict
                                            ,cg$errors.err_del_restrict
                                            ,'NIT_CONFIG_ITEMS'
                                            ,'NIT_CI_RELATIONS')
                       ,'E'
                       ,'API'
                       ,cg$errors.api_del_restrict
                       ,loc);

      ELSIF (con_name = 'NIT_CFK_CI_CIT') THEN
         cg$errors.push(NVL(nit_cfk_ci_cit
                           ,cg$errors.msggettext(cg$errors.api_fk_con_violated
                                                ,cg$errors.apimsg_fk_violat
                                                ,'NIT_CFK_CI_CIT'
                                                ,'NIT_CONFIG_ITEMS'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_fk_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CFK_CI_OPN') THEN
         cg$errors.push(NVL(nit_cfk_ci_opn
                           ,cg$errors.msggettext(cg$errors.api_fk_con_violated
                                                ,cg$errors.apimsg_fk_violat
                                                ,'NIT_CFK_CI_OPN'
                                                ,'NIT_CONFIG_ITEMS'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_fk_con_violated
                       ,loc);
      ELSE
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,loc);
      END IF;
   END err_msg;

   --------------------------------------------------------------------------------
   -- Name:        ins
   --
   -- Description: API insert procedure
   --
   -- Parameters:  cg$rec  Record of row to be inserted
   --              cg$ind  Record of columns specifically set
   --              do_ins  Whether we want the actual INSERT to occur
   --------------------------------------------------------------------------------
   PROCEDURE ins(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_ins IN BOOLEAN DEFAULT TRUE) IS

      --  Constant default values

      d80_obsolete CONSTANT nit_config_items.obsolete%TYPE := 'L';

   BEGIN
      nit_config_items_p.pre_dml(cg$rec
                                ,cg$ind
                                ,'INS');
      nit_config_items_p.pre_ins(cg$rec
                                ,cg$ind);

      IF NOT (cg$ind.obsolete) THEN
         cg$rec.obsolete := d80_obsolete;
      END IF;
      --  Auto-generated and uppercased columns

      up_autogen_columns(cg$rec
                        ,cg$ind
                        ,'INS'
                        ,do_ins);

      called_from_package := TRUE;

      IF (do_ins) THEN
         validate_domain(cg$rec);

         INSERT INTO nit_config_items
            (id
            ,creation_date
            ,created_by
            ,last_update_date
            ,last_updated_by
            ,cit_id
            ,opn_id
            ,sms_id
            ,NAME
            ,status
            ,obsolete
            ,valid_from
            ,valid_until
            ,comments
            ,last_refresh_date)
         VALUES
            (cg$rec.id
            ,cg$rec.creation_date
            ,cg$rec.created_by
            ,cg$rec.last_update_date
            ,cg$rec.last_updated_by
            ,cg$rec.cit_id
            ,cg$rec.opn_id
            ,cg$rec.sms_id
            ,cg$rec.NAME
            ,cg$rec.status
            ,cg$rec.obsolete
            ,cg$rec.valid_from
            ,cg$rec.valid_until
            ,cg$rec.comments
            ,cg$rec.last_refresh_date)
         RETURNING id, creation_date, created_by, last_update_date, last_updated_by, cit_id, opn_id, sms_id, NAME, status, obsolete, valid_from, valid_until, comments, last_refresh_date, ROWID INTO cg$rec.id, cg$rec.creation_date, cg$rec.created_by, cg$rec.last_update_date, cg$rec.last_updated_by, cg$rec.cit_id, cg$rec.opn_id, cg$rec.sms_id, cg$rec.NAME, cg$rec.status, cg$rec.obsolete, cg$rec.valid_from, cg$rec.valid_until, cg$rec.comments, cg$rec.last_refresh_date, cg$rec.the_rowid;
      END IF;

      nit_config_items_p.post_ins(cg$rec
                                 ,cg$ind);

      called_from_package := FALSE;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.mandatory_missing THEN
         validate_mandatory(cg$rec
                           ,'cg$NIT_CONFIG_ITEMS.ins.mandatory_missing');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.check_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_check_con
                ,'cg$NIT_CONFIG_ITEMS.ins.check_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.fk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_foreign_key
                ,'cg$NIT_CONFIG_ITEMS.ins.fk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.uk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_unique_key
                ,'cg$NIT_CONFIG_ITEMS.ins.uk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CONFIG_ITEMS.ins.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END ins;


   --------------------------------------------------------------------------------
   -- Name:        upd
   --
   -- Description: API update procedure
   --
   -- Parameters:  cg$rec  Record of row to be updated
   --              cg$ind  Record of columns specifically set
   --              do_upd  Whether we want the actual UPDATE to occur
   --------------------------------------------------------------------------------
   PROCEDURE upd(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_upd IN BOOLEAN DEFAULT TRUE
                ,cg$pk  IN cg$row_type DEFAULT NULL) IS
      cg$upd_rec cg$row_type;
      cg$old_rec cg$row_type;
   BEGIN
      nit_config_items_p.pre_dml(cg$rec
                                ,cg$ind
                                ,'UPD');
      nit_config_items_p.pre_upd(cg$rec
                                ,cg$ind);

      IF (cg$pk.id IS NULL) THEN
         cg$upd_rec.id := cg$rec.id;
      ELSE
         cg$upd_rec.id := cg$pk.id;
      END IF;
      cg$old_rec.id := cg$upd_rec.id;

      IF (cg$pk.the_rowid IS NULL) THEN
         cg$upd_rec.the_rowid := cg$rec.the_rowid;
      ELSE
         cg$upd_rec.the_rowid := cg$pk.the_rowid;
      END IF;
      cg$old_rec.the_rowid := cg$upd_rec.the_rowid;

      IF (do_upd) THEN

         slct(cg$upd_rec);

         --  Report error if attempt to update non transferable Foreign Key NIT_CFK_CI_CIT
         IF (cg$ind.cit_id AND cg$rec.cit_id != cg$upd_rec.cit_id) THEN
            raise_fk_not_transferable('NIT_CFK_CI_CIT');
         END IF;
         IF (cg$ind.cit_id AND cg$rec.cit_id IS NULL AND
            cg$upd_rec.cit_id IS NOT NULL) THEN
            raise_fk_not_transferable('NIT_CFK_CI_CIT');
         END IF;
         IF (cg$ind.cit_id AND cg$rec.cit_id IS NOT NULL AND
            cg$upd_rec.cit_id IS NULL) THEN
            raise_fk_not_transferable('NIT_CFK_CI_CIT');
         END IF;
         --  Report error if attempt to update non transferable Foreign Key NIT_CFK_CI_OPN
         IF (cg$ind.opn_id AND cg$rec.opn_id != cg$upd_rec.opn_id) THEN
            raise_fk_not_transferable('NIT_CFK_CI_OPN');
         END IF;
         IF (cg$ind.opn_id AND cg$rec.opn_id IS NULL AND
            cg$upd_rec.opn_id IS NOT NULL) THEN
            raise_fk_not_transferable('NIT_CFK_CI_OPN');
         END IF;
         IF (cg$ind.opn_id AND cg$rec.opn_id IS NOT NULL AND
            cg$upd_rec.opn_id IS NULL) THEN
            raise_fk_not_transferable('NIT_CFK_CI_OPN');
         END IF;

         --  Report error if attempt to update non updateable Primary Key NIT_CPK_CI
         IF (cg$ind.id AND cg$rec.id != cg$upd_rec.id) THEN
            raise_uk_not_updateable('NIT_CPK_CI');
         END IF;
         IF NOT (cg$ind.id) THEN
            cg$rec.id := cg$upd_rec.id;
         END IF;
         IF NOT (cg$ind.creation_date) THEN
            cg$rec.creation_date := cg$upd_rec.creation_date;
         END IF;
         IF NOT (cg$ind.created_by) THEN
            cg$rec.created_by := cg$upd_rec.created_by;
         END IF;
         IF NOT (cg$ind.last_update_date) THEN
            cg$rec.last_update_date := cg$upd_rec.last_update_date;
         END IF;
         IF NOT (cg$ind.last_updated_by) THEN
            cg$rec.last_updated_by := cg$upd_rec.last_updated_by;
         END IF;
         IF NOT (cg$ind.cit_id) THEN
            cg$rec.cit_id := cg$upd_rec.cit_id;
         END IF;
         IF NOT (cg$ind.opn_id) THEN
            cg$rec.opn_id := cg$upd_rec.opn_id;
         END IF;
         IF NOT (cg$ind.sms_id) THEN
            cg$rec.sms_id := cg$upd_rec.sms_id;
         END IF;
         IF NOT (cg$ind.NAME) THEN
            cg$rec.NAME := cg$upd_rec.NAME;
         END IF;
         IF NOT (cg$ind.status) THEN
            cg$rec.status := cg$upd_rec.status;
         END IF;
         IF NOT (cg$ind.obsolete) THEN
            cg$rec.obsolete := cg$upd_rec.obsolete;
         END IF;
         IF NOT (cg$ind.valid_from) THEN
            cg$rec.valid_from := cg$upd_rec.valid_from;
         END IF;
         IF NOT (cg$ind.valid_until) THEN
            cg$rec.valid_until := cg$upd_rec.valid_until;
         END IF;
         IF NOT (cg$ind.comments) THEN
            cg$rec.comments := cg$upd_rec.comments;
         END IF;
         IF NOT (cg$ind.last_refresh_date) THEN
            cg$rec.last_refresh_date := cg$upd_rec.last_refresh_date;
         END IF;
      ELSE
         --  Report error if attempt to update non transferable Foreign Key NIT_CFK_CI_CIT
         IF (cg$ind.cit_id) THEN
            raise_fk_not_transferable('NIT_CFK_CI_CIT');
         END IF;
         --  Report error if attempt to update non transferable Foreign Key NIT_CFK_CI_OPN
         IF (cg$ind.opn_id) THEN
            raise_fk_not_transferable('NIT_CFK_CI_OPN');
         END IF;
         --  Report error if attempt to update non updateable Primary Key NIT_CPK_CI
         IF (cg$ind.id) THEN
            raise_uk_not_updateable('NIT_CPK_CI');
         END IF;
      END IF;

      up_autogen_columns(cg$rec
                        ,cg$ind
                        ,'UPD'
                        ,do_upd); --  Auto-generated and uppercased columns

      --  Now do update if updateable columns exist
      IF (do_upd) THEN
         DECLARE
            called_from BOOLEAN := called_from_package;
         BEGIN
            called_from_package := TRUE;

            slct(cg$old_rec);
            validate_domain(cg$rec
                           ,cg$ind);

            IF cg$rec.the_rowid IS NULL THEN
               UPDATE nit_config_items
               SET    creation_date     = cg$rec.creation_date
                     ,created_by        = cg$rec.created_by
                     ,last_update_date  = cg$rec.last_update_date
                     ,last_updated_by   = cg$rec.last_updated_by
                     ,cit_id            = cg$rec.cit_id
                     ,opn_id            = cg$rec.opn_id
                     ,sms_id            = cg$rec.sms_id
                     ,NAME              = cg$rec.NAME
                     ,status            = cg$rec.status
                     ,obsolete          = cg$rec.obsolete
                     ,valid_from        = cg$rec.valid_from
                     ,valid_until       = cg$rec.valid_until
                     ,comments          = cg$rec.comments
                     ,last_refresh_date = cg$rec.last_refresh_date
               WHERE  id = cg$rec.id RETURNING id, creation_date, created_by,
                last_update_date, last_updated_by, cit_id, opn_id, sms_id, NAME,
                status, obsolete, valid_from, valid_until, comments,
                last_refresh_date, ROWID INTO cg$rec.id,
                cg$rec.creation_date, cg$rec.created_by,
                cg$rec.last_update_date, cg$rec.last_updated_by,
                cg$rec.cit_id, cg$rec.opn_id, cg$rec.sms_id, cg$rec.NAME,
                cg$rec.status, cg$rec.obsolete, cg$rec.valid_from,
                cg$rec.valid_until, cg$rec.comments,
                cg$rec.last_refresh_date, cg$rec.the_rowid;
            ELSE
               UPDATE nit_config_items
               SET    creation_date     = cg$rec.creation_date
                     ,created_by        = cg$rec.created_by
                     ,last_update_date  = cg$rec.last_update_date
                     ,last_updated_by   = cg$rec.last_updated_by
                     ,cit_id            = cg$rec.cit_id
                     ,opn_id            = cg$rec.opn_id
                     ,sms_id            = cg$rec.sms_id
                     ,NAME              = cg$rec.NAME
                     ,status            = cg$rec.status
                     ,obsolete          = cg$rec.obsolete
                     ,valid_from        = cg$rec.valid_from
                     ,valid_until       = cg$rec.valid_until
                     ,comments          = cg$rec.comments
                     ,last_refresh_date = cg$rec.last_refresh_date
               WHERE  ROWID = cg$rec.the_rowid RETURNING id, creation_date,
                created_by, last_update_date, last_updated_by, cit_id,
                opn_id, sms_id, NAME, status, obsolete, valid_from,
                valid_until, comments, last_refresh_date, ROWID INTO
                cg$rec.id, cg$rec.creation_date, cg$rec.created_by,
                cg$rec.last_update_date, cg$rec.last_updated_by,
                cg$rec.cit_id, cg$rec.opn_id, cg$rec.sms_id, cg$rec.NAME,
                cg$rec.status, cg$rec.obsolete, cg$rec.valid_from,
                cg$rec.valid_until, cg$rec.comments,
                cg$rec.last_refresh_date, cg$rec.the_rowid;
            END IF;

            called_from_package := called_from;
         END;
      END IF;



      IF NOT (do_upd) THEN
         cg$table(idx).id := cg$rec.id;
         cg$tableind(idx).id := cg$ind.id;
         cg$table(idx).creation_date := cg$rec.creation_date;
         cg$tableind(idx).creation_date := cg$ind.creation_date;
         cg$table(idx).created_by := cg$rec.created_by;
         cg$tableind(idx).created_by := cg$ind.created_by;
         cg$table(idx).last_update_date := cg$rec.last_update_date;
         cg$tableind(idx).last_update_date := cg$ind.last_update_date;
         cg$table(idx).last_updated_by := cg$rec.last_updated_by;
         cg$tableind(idx).last_updated_by := cg$ind.last_updated_by;
         cg$table(idx).cit_id := cg$rec.cit_id;
         cg$tableind(idx).cit_id := cg$ind.cit_id;
         cg$table(idx).opn_id := cg$rec.opn_id;
         cg$tableind(idx).opn_id := cg$ind.opn_id;
         cg$table(idx).sms_id := cg$rec.sms_id;
         cg$tableind(idx).sms_id := cg$ind.sms_id;
         cg$table(idx).NAME := cg$rec.NAME;
         cg$tableind(idx).NAME := cg$ind.NAME;
         cg$table(idx).status := cg$rec.status;
         cg$tableind(idx).status := cg$ind.status;
         cg$table(idx).obsolete := cg$rec.obsolete;
         cg$tableind(idx).obsolete := cg$ind.obsolete;
         cg$table(idx).valid_from := cg$rec.valid_from;
         cg$tableind(idx).valid_from := cg$ind.valid_from;
         cg$table(idx).valid_until := cg$rec.valid_until;
         cg$tableind(idx).valid_until := cg$ind.valid_until;
         cg$table(idx).comments := cg$rec.comments;
         cg$tableind(idx).comments := cg$ind.comments;
         cg$table(idx).last_refresh_date := cg$rec.last_refresh_date;
         cg$tableind(idx).last_refresh_date := cg$ind.last_refresh_date;
         idx := idx + 1;
      END IF;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.upd_mandatory_null THEN
         validate_mandatory(cg$rec
                           ,'cg$NIT_CONFIG_ITEMS.upd.upd_mandatory_null');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.check_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_check_con
                ,'cg$NIT_CONFIG_ITEMS.upd.check_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.fk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_foreign_key
                ,'cg$NIT_CONFIG_ITEMS.upd.fk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.uk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_unique_key
                ,'cg$NIT_CONFIG_ITEMS.upd.uk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CONFIG_ITEMS.upd.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END upd;

   --------------------------------------------------------------------------------
   -- Name:        del
   --
   -- Description: API delete procedure
   --
   -- Parameters:  cg$pk  Primary key record of row to be deleted
   --------------------------------------------------------------------------------
   PROCEDURE del(cg$pk  IN cg$pk_type
                ,do_del IN BOOLEAN DEFAULT TRUE) IS
   BEGIN
      raise_application_error(-20001
                             ,'FIXME:?gy nem t?rl?nk.. ?rd ?t a k?dod.. Ezt az ?zenetet ki kell szedni ha ?les lesz a rendszer');

      --  Delete the record

      called_from_package := TRUE;

      IF (do_del) THEN
         IF cg$pk.the_rowid IS NULL THEN
            DELETE nit_config_items
            WHERE  id = cg$pk.id;
         ELSE
            DELETE nit_config_items
            WHERE  ROWID = cg$pk.the_rowid;
         END IF;
      END IF;

      called_from_package := FALSE;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.delete_restrict THEN
         err_msg(SQLERRM
                ,cg$errors.err_delete_restrict
                ,'cg$NIT_CONFIG_ITEMS.del.delete_restrict');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN no_data_found THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_row_del
                                            ,cg$errors.row_del)
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CONFIG_ITEMS.del.no_data_found');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_CONFIG_ITEMS.del.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END del;


   --------------------------------------------------------------------------------
   -- Name:        lck
   --
   -- Description: API lock procedure
   --
   -- Parameters:  cg$old_rec  Calling apps view of record of row to be locked
   --              cg$old_ind  Record of columns to raise error if modified
   --              nowait_flag TRUE lock with NOWAIT, FALSE don't fail if busy
   --------------------------------------------------------------------------------
   PROCEDURE lck(cg$old_rec  IN cg$row_type
                ,cg$old_ind  IN cg$ind_type
                ,nowait_flag IN BOOLEAN DEFAULT TRUE) IS
      cg$tmp_rec   cg$row_type;
      any_modified BOOLEAN := FALSE;

   BEGIN

      BEGIN
         IF (nowait_flag) THEN
            IF cg$old_rec.the_rowid IS NULL THEN
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,cit_id
                     ,opn_id
                     ,sms_id
                     ,NAME
                     ,status
                     ,obsolete
                     ,valid_from
                     ,valid_until
                     ,comments
                     ,last_refresh_date
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.cit_id
                     ,cg$tmp_rec.opn_id
                     ,cg$tmp_rec.sms_id
                     ,cg$tmp_rec.NAME
                     ,cg$tmp_rec.status
                     ,cg$tmp_rec.obsolete
                     ,cg$tmp_rec.valid_from
                     ,cg$tmp_rec.valid_until
                     ,cg$tmp_rec.comments
                     ,cg$tmp_rec.last_refresh_date
               FROM   nit_config_items
               WHERE  id = cg$old_rec.id
               FOR    UPDATE NOWAIT;
            ELSE
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,cit_id
                     ,opn_id
                     ,sms_id
                     ,NAME
                     ,status
                     ,obsolete
                     ,valid_from
                     ,valid_until
                     ,comments
                     ,last_refresh_date
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.cit_id
                     ,cg$tmp_rec.opn_id
                     ,cg$tmp_rec.sms_id
                     ,cg$tmp_rec.NAME
                     ,cg$tmp_rec.status
                     ,cg$tmp_rec.obsolete
                     ,cg$tmp_rec.valid_from
                     ,cg$tmp_rec.valid_until
                     ,cg$tmp_rec.comments
                     ,cg$tmp_rec.last_refresh_date
               FROM   nit_config_items
               WHERE  ROWID = cg$old_rec.the_rowid
               FOR    UPDATE NOWAIT;
            END IF;
         ELSE
            IF cg$old_rec.the_rowid IS NULL THEN
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,cit_id
                     ,opn_id
                     ,sms_id
                     ,NAME
                     ,status
                     ,obsolete
                     ,valid_from
                     ,valid_until
                     ,comments
                     ,last_refresh_date
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.cit_id
                     ,cg$tmp_rec.opn_id
                     ,cg$tmp_rec.sms_id
                     ,cg$tmp_rec.NAME
                     ,cg$tmp_rec.status
                     ,cg$tmp_rec.obsolete
                     ,cg$tmp_rec.valid_from
                     ,cg$tmp_rec.valid_until
                     ,cg$tmp_rec.comments
                     ,cg$tmp_rec.last_refresh_date
               FROM   nit_config_items
               WHERE  id = cg$old_rec.id
               FOR    UPDATE;
            ELSE
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,cit_id
                     ,opn_id
                     ,sms_id
                     ,NAME
                     ,status
                     ,obsolete
                     ,valid_from
                     ,valid_until
                     ,comments
                     ,last_refresh_date
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.cit_id
                     ,cg$tmp_rec.opn_id
                     ,cg$tmp_rec.sms_id
                     ,cg$tmp_rec.NAME
                     ,cg$tmp_rec.status
                     ,cg$tmp_rec.obsolete
                     ,cg$tmp_rec.valid_from
                     ,cg$tmp_rec.valid_until
                     ,cg$tmp_rec.comments
                     ,cg$tmp_rec.last_refresh_date
               FROM   nit_config_items
               WHERE  ROWID = cg$old_rec.the_rowid
               FOR    UPDATE;
            END IF;
         END IF;

      EXCEPTION
         WHEN cg$errors.cg$error THEN
            cg$errors.raise_failure;
         WHEN cg$errors.resource_busy THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_lck
                                               ,cg$errors.row_lck)
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_CONFIG_ITEMS.lck.resource_busy');
            cg$errors.raise_failure;
         WHEN no_data_found THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_del
                                               ,cg$errors.row_del)
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_CONFIG_ITEMS.lck.no_data_found');
            cg$errors.raise_failure;
         WHEN OTHERS THEN
            cg$errors.push(SQLERRM
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_CONFIG_ITEMS.lck.others');
            cg$errors.raise_failure;
      END;

      -- Optional Columns

      IF (cg$old_ind.sms_id) THEN
         IF (cg$tmp_rec.sms_id IS NOT NULL AND cg$old_rec.sms_id IS NOT NULL) THEN
            IF (cg$tmp_rec.sms_id != cg$old_rec.sms_id) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p42sms_id)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CONFIG_ITEMS.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.sms_id IS NOT NULL OR cg$old_rec.sms_id IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p42sms_id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CONFIG_ITEMS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.comments) THEN
         IF (cg$tmp_rec.comments IS NOT NULL AND
            cg$old_rec.comments IS NOT NULL) THEN
            IF (cg$tmp_rec.comments != cg$old_rec.comments) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p110comments)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CONFIG_ITEMS.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.comments IS NOT NULL OR
               cg$old_rec.comments IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p110comments)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CONFIG_ITEMS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.last_refresh_date) THEN
         IF (cg$tmp_rec.last_refresh_date IS NOT NULL AND
            cg$old_rec.last_refresh_date IS NOT NULL) THEN
            IF (cg$tmp_rec.last_refresh_date != cg$old_rec.last_refresh_date) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p155last_refresh_date)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_CONFIG_ITEMS.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.last_refresh_date IS NOT NULL OR
               cg$old_rec.last_refresh_date IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p155last_refresh_date)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CONFIG_ITEMS.lck');
            any_modified := TRUE;
         END IF;
      END IF;

      -- Mandatory Columns

      IF (cg$old_ind.id) THEN
         IF (cg$tmp_rec.id != cg$old_rec.id) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p10id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CONFIG_ITEMS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.creation_date) THEN
         IF (cg$tmp_rec.creation_date != cg$old_rec.creation_date) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p15creation_date)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CONFIG_ITEMS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.created_by) THEN
         IF (cg$tmp_rec.created_by != cg$old_rec.created_by) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p16created_by)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CONFIG_ITEMS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.last_update_date) THEN
         IF (cg$tmp_rec.last_update_date != cg$old_rec.last_update_date) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p19last_update_date)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CONFIG_ITEMS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.last_updated_by) THEN
         IF (cg$tmp_rec.last_updated_by != cg$old_rec.last_updated_by) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p24last_updated_by)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CONFIG_ITEMS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.cit_id) THEN
         IF (cg$tmp_rec.cit_id != cg$old_rec.cit_id) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p30cit_id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CONFIG_ITEMS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.opn_id) THEN
         IF (cg$tmp_rec.opn_id != cg$old_rec.opn_id) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p40opn_id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CONFIG_ITEMS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.NAME) THEN
         IF (cg$tmp_rec.NAME != cg$old_rec.NAME) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p45name)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CONFIG_ITEMS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.status) THEN
         IF (cg$tmp_rec.status != cg$old_rec.status) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p50status)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CONFIG_ITEMS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.obsolete) THEN
         IF (cg$tmp_rec.obsolete != cg$old_rec.obsolete) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p80obsolete)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CONFIG_ITEMS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.valid_from) THEN
         IF (cg$tmp_rec.valid_from != cg$old_rec.valid_from) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p90valid_from)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CONFIG_ITEMS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.valid_until) THEN
         IF (cg$tmp_rec.valid_until != cg$old_rec.valid_until) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p100valid_until)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_CONFIG_ITEMS.lck');
            any_modified := TRUE;
         END IF;
      END IF;

      IF (any_modified) THEN
         cg$errors.raise_failure;
      END IF;

   END lck;


BEGIN
   cg$ind_true.id                := TRUE;
   cg$ind_true.creation_date     := TRUE;
   cg$ind_true.created_by        := TRUE;
   cg$ind_true.last_update_date  := TRUE;
   cg$ind_true.last_updated_by   := TRUE;
   cg$ind_true.cit_id            := TRUE;
   cg$ind_true.opn_id            := TRUE;
   cg$ind_true.sms_id            := TRUE;
   cg$ind_true.NAME              := TRUE;
   cg$ind_true.status            := TRUE;
   cg$ind_true.obsolete          := TRUE;
   cg$ind_true.valid_from        := TRUE;
   cg$ind_true.valid_until       := TRUE;
   cg$ind_true.comments          := TRUE;
   cg$ind_true.last_refresh_date := TRUE;


END cg$nit_config_items;
/

prompt
prompt Creating package body CG$NIT_LOCATIONS
prompt ======================================
prompt
CREATE OR REPLACE PACKAGE BODY cg$nit_locations IS


   PROCEDURE validate_mandatory(cg$val_rec IN cg$row_type
                               ,loc        IN VARCHAR2 DEFAULT '');
   PROCEDURE up_autogen_columns(cg$rec    IN OUT cg$row_type
                               ,cg$ind    IN OUT cg$ind_type
                               ,operation IN VARCHAR2 DEFAULT 'INS'
                               ,do_denorm IN BOOLEAN DEFAULT TRUE);
   PROCEDURE err_msg(msg  IN VARCHAR2
                    ,TYPE IN INTEGER
                    ,loc  IN VARCHAR2 DEFAULT '');

   --------------------------------------------------------------------------------
   -- Name:        raise_uk_not_updateable
   --
   -- Description: Raise appropriate error when unique key updated
   --
   -- Parameters:  none
   --------------------------------------------------------------------------------
   PROCEDURE raise_uk_not_updateable(uk IN VARCHAR2) IS
   BEGIN
      cg$errors.push(cg$errors.msggettext(cg$errors.api_unique_key_update
                                         ,cg$errors.err_uk_update
                                         ,uk)
                    ,'E'
                    ,'API'
                    ,cg$errors.api_unique_key_update
                    ,'cg$NIT_LOCATIONS.raise_uk_not_updateable');
      cg$errors.raise_failure;
   END raise_uk_not_updateable;


   --------------------------------------------------------------------------------
   -- Name:        raise_fk_not_transferable
   --
   -- Description: Raise appropriate error when foreign key updated
   --
   -- Parameters:  none
   --------------------------------------------------------------------------------
   PROCEDURE raise_fk_not_transferable(fk IN VARCHAR2) IS
   BEGIN
      cg$errors.push(cg$errors.msggettext(cg$errors.api_foreign_key_trans
                                         ,cg$errors.err_fk_trans
                                         ,fk)
                    ,'E'
                    ,'API'
                    ,cg$errors.api_foreign_key_trans
                    ,'cg$NIT_LOCATIONS.raise_fk_not_transferable');
      cg$errors.raise_failure;
   END raise_fk_not_transferable;


   --------------------------------------------------------------------------------
   -- Name:        up_autogen_columns
   --
   -- Description: Specific autogeneration of column values and conversion to
   --              uppercase
   --
   -- Parameters:  cg$rec    Record of row to be manipulated
   --              cg$ind    Indicators for row
   --              operation Procedure where this procedure was called
   --------------------------------------------------------------------------------
   PROCEDURE up_autogen_columns(cg$rec    IN OUT cg$row_type
                               ,cg$ind    IN OUT cg$ind_type
                               ,operation IN VARCHAR2 DEFAULT 'INS'
                               ,do_denorm IN BOOLEAN DEFAULT TRUE) IS
   BEGIN
      IF (operation = 'INS') THEN
         BEGIN
            IF (cg$ind.id = FALSE OR cg$rec.id IS NULL) THEN
               SELECT nit_seq.NEXTVAL
               INTO   cg$rec.id
               FROM   dual;
               cg$ind.id := TRUE;
            END IF;
         EXCEPTION
            WHEN OTHERS THEN
               cg$errors.push(SQLERRM
                             ,'E'
                             ,'ORA'
                             ,SQLCODE
                             ,'cg$NIT_LOCATIONS.up_autogen.ID.OTHERS');
               cg$errors.raise_failure;
         END;
      ELSE
         -- (operation = 'UPD')
         NULL;
      END IF; -- (operation = 'INS') ELSE (operation = 'UPD')

      -- Statements executed for both 'INS' and 'UPD'


   EXCEPTION
      WHEN no_data_found THEN
         NULL;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_LOCATIONS.up_autogen_columns');
         cg$errors.raise_failure;
   END up_autogen_columns;


   --------------------------------------------------------------------------------
   -- Name:        validate_mandatory
   --
   -- Description: Checks all mandatory columns are not null and raises appropriate
   --              error if not satisfied
   --
   -- Parameters:  cg$val_rec Record of row to be checked
   --              loc        Place where this procedure was called for error
   --                         trapping
   --------------------------------------------------------------------------------
   PROCEDURE validate_mandatory(cg$val_rec IN cg$row_type
                               ,loc        IN VARCHAR2 DEFAULT '') IS
   BEGIN
      IF (cg$val_rec.id IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p10id)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.creation_date IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p15creation_date)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.created_by IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p16created_by)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.last_update_date IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p19last_update_date)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.last_updated_by IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p24last_updated_by)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.NAME IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p40name)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
   END validate_mandatory;

   --------------------------------------------------------------------------------
   -- Name:        slct
   --
   -- Description: Selects into the given parameter all the attributes for the row
   --              given by the primary key
   --
   -- Parameters:  cg$sel_rec  Record of row to be selected into using its PK
   --------------------------------------------------------------------------------
   PROCEDURE slct(cg$sel_rec IN OUT cg$row_type) IS

   BEGIN

      IF cg$sel_rec.the_rowid IS NULL THEN
         SELECT id
               ,creation_date
               ,created_by
               ,last_update_date
               ,last_updated_by
               ,lcn_id
               ,NAME
               ,abbreviation
               ,naming_pattern
               ,description
               ,comments
               ,icon_name
               ,MAP
               ,ROWID
         INTO   cg$sel_rec.id
               ,cg$sel_rec.creation_date
               ,cg$sel_rec.created_by
               ,cg$sel_rec.last_update_date
               ,cg$sel_rec.last_updated_by
               ,cg$sel_rec.lcn_id
               ,cg$sel_rec.NAME
               ,cg$sel_rec.abbreviation
               ,cg$sel_rec.naming_pattern
               ,cg$sel_rec.description
               ,cg$sel_rec.comments
               ,cg$sel_rec.icon_name
               ,cg$sel_rec.MAP
               ,cg$sel_rec.the_rowid
         FROM   nit_locations
         WHERE  id = cg$sel_rec.id;
      ELSE
         SELECT id
               ,creation_date
               ,created_by
               ,last_update_date
               ,last_updated_by
               ,lcn_id
               ,NAME
               ,abbreviation
               ,naming_pattern
               ,description
               ,comments
               ,icon_name
               ,MAP
               ,ROWID
         INTO   cg$sel_rec.id
               ,cg$sel_rec.creation_date
               ,cg$sel_rec.created_by
               ,cg$sel_rec.last_update_date
               ,cg$sel_rec.last_updated_by
               ,cg$sel_rec.lcn_id
               ,cg$sel_rec.NAME
               ,cg$sel_rec.abbreviation
               ,cg$sel_rec.naming_pattern
               ,cg$sel_rec.description
               ,cg$sel_rec.comments
               ,cg$sel_rec.icon_name
               ,cg$sel_rec.MAP
               ,cg$sel_rec.the_rowid
         FROM   nit_locations
         WHERE  ROWID = cg$sel_rec.the_rowid;
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_LOCATIONS.slct.others');
         cg$errors.raise_failure;

   END slct;

   --------------------------------------------------------------------------------
   -- Name:        err_msg
   --
   -- Description: Pushes onto stack appropriate user defined error message
   --              depending on the rule violated
   --
   -- Parameters:  msg     Oracle error message
   --              type    Type of violation e.g. check_constraint: ERR_CHECK_CON
   --              loc     Place where this procedure was called for error
   --                      trapping
   --------------------------------------------------------------------------------
   PROCEDURE err_msg(msg  IN VARCHAR2
                    ,TYPE IN INTEGER
                    ,loc  IN VARCHAR2 DEFAULT '') IS
      con_name VARCHAR2(240);
   BEGIN
      con_name := cg$errors.parse_constraint(msg
                                            ,TYPE);
      IF (con_name = 'NIT_CPK_LCN') THEN
         cg$errors.push(NVL(nit_cpk_lcn
                           ,cg$errors.msggettext(cg$errors.api_pk_con_violated
                                                ,cg$errors.apimsg_pk_violat
                                                ,'NIT_CPK_LCN'
                                                ,'NIT_LOCATIONS'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_pk_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CUK_LCN') THEN
         cg$errors.push(NVL(nit_cuk_lcn
                           ,cg$errors.msggettext(cg$errors.api_uq_con_violated
                                                ,cg$errors.apimsg_uk_violat
                                                ,'NIT_CUK_LCN'
                                                ,'NIT_LOCATIONS'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_uq_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CFK_LCN_LCN' AND
            TYPE = cg$errors.err_delete_restrict) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_del_restrict
                                            ,cg$errors.err_del_restrict
                                            ,'NIT_LOCATIONS'
                                            ,'NIT_LOCATIONS')
                       ,'E'
                       ,'API'
                       ,cg$errors.api_del_restrict
                       ,loc);

      ELSIF (con_name = 'NIT_CFK_LCN_LCN') THEN
         cg$errors.push(NVL(nit_cfk_lcn_lcn
                           ,cg$errors.msggettext(cg$errors.api_fk_con_violated
                                                ,cg$errors.apimsg_fk_violat
                                                ,'NIT_CFK_LCN_LCN'
                                                ,'NIT_LOCATIONS'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_fk_con_violated
                       ,loc);
      ELSE
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,loc);
      END IF;
   END err_msg;

   --------------------------------------------------------------------------------
   -- Name:        ins
   --
   -- Description: API insert procedure
   --
   -- Parameters:  cg$rec  Record of row to be inserted
   --              cg$ind  Record of columns specifically set
   --              do_ins  Whether we want the actual INSERT to occur
   --------------------------------------------------------------------------------
   PROCEDURE ins(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_ins IN BOOLEAN DEFAULT TRUE) IS

      --  Constant default values


   BEGIN
      nit_locations_p.pre_dml(cg$rec
                             ,cg$ind
                             ,'INS');

      --  Defaulted

      --  Auto-generated and uppercased columns

      up_autogen_columns(cg$rec
                        ,cg$ind
                        ,'INS'
                        ,do_ins);

      called_from_package := TRUE;

      IF (do_ins) THEN

         INSERT INTO nit_locations
            (id
            ,creation_date
            ,created_by
            ,last_update_date
            ,last_updated_by
            ,lcn_id
            ,NAME
            ,abbreviation
            ,naming_pattern
            ,description
            ,comments
            ,icon_name
            ,MAP)
         VALUES
            (cg$rec.id
            ,cg$rec.creation_date
            ,cg$rec.created_by
            ,cg$rec.last_update_date
            ,cg$rec.last_updated_by
            ,cg$rec.lcn_id
            ,cg$rec.NAME
            ,cg$rec.abbreviation
            ,cg$rec.naming_pattern
            ,cg$rec.description
            ,cg$rec.comments
            ,cg$rec.icon_name
            ,cg$rec.MAP)
         RETURNING id, creation_date, created_by, last_update_date, last_updated_by, lcn_id, NAME, abbreviation, naming_pattern, description, comments, icon_name, MAP, ROWID INTO cg$rec.id, cg$rec.creation_date, cg$rec.created_by, cg$rec.last_update_date, cg$rec.last_updated_by, cg$rec.lcn_id, cg$rec.NAME, cg$rec.abbreviation, cg$rec.naming_pattern, cg$rec.description, cg$rec.comments, cg$rec.icon_name, cg$rec.MAP, cg$rec.the_rowid;
      END IF;

      called_from_package := FALSE;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.mandatory_missing THEN
         validate_mandatory(cg$rec
                           ,'cg$NIT_LOCATIONS.ins.mandatory_missing');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.check_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_check_con
                ,'cg$NIT_LOCATIONS.ins.check_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.fk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_foreign_key
                ,'cg$NIT_LOCATIONS.ins.fk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.uk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_unique_key
                ,'cg$NIT_LOCATIONS.ins.uk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_LOCATIONS.ins.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END ins;


   --------------------------------------------------------------------------------
   -- Name:        upd
   --
   -- Description: API update procedure
   --
   -- Parameters:  cg$rec  Record of row to be updated
   --              cg$ind  Record of columns specifically set
   --              do_upd  Whether we want the actual UPDATE to occur
   --------------------------------------------------------------------------------
   PROCEDURE upd(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_upd IN BOOLEAN DEFAULT TRUE
                ,cg$pk  IN cg$row_type DEFAULT NULL) IS
      cg$upd_rec cg$row_type;
      cg$old_rec cg$row_type;
   BEGIN
      nit_locations_p.pre_dml(cg$rec
                             ,cg$ind
                             ,'UPD');

      IF (cg$pk.id IS NULL) THEN
         cg$upd_rec.id := cg$rec.id;
      ELSE
         cg$upd_rec.id := cg$pk.id;
      END IF;
      cg$old_rec.id := cg$upd_rec.id;

      IF (cg$pk.the_rowid IS NULL) THEN
         cg$upd_rec.the_rowid := cg$rec.the_rowid;
      ELSE
         cg$upd_rec.the_rowid := cg$pk.the_rowid;
      END IF;
      cg$old_rec.the_rowid := cg$upd_rec.the_rowid;

      IF (do_upd) THEN

         slct(cg$upd_rec);


         --  Report error if attempt to update non updateable Primary Key NIT_CPK_LCN
         IF (cg$ind.id AND cg$rec.id != cg$upd_rec.id) THEN
            raise_uk_not_updateable('NIT_CPK_LCN');
         END IF;
         IF NOT (cg$ind.id) THEN
            cg$rec.id := cg$upd_rec.id;
         END IF;
         IF NOT (cg$ind.creation_date) THEN
            cg$rec.creation_date := cg$upd_rec.creation_date;
         END IF;
         IF NOT (cg$ind.created_by) THEN
            cg$rec.created_by := cg$upd_rec.created_by;
         END IF;
         IF NOT (cg$ind.last_update_date) THEN
            cg$rec.last_update_date := cg$upd_rec.last_update_date;
         END IF;
         IF NOT (cg$ind.last_updated_by) THEN
            cg$rec.last_updated_by := cg$upd_rec.last_updated_by;
         END IF;
         IF NOT (cg$ind.lcn_id) THEN
            cg$rec.lcn_id := cg$upd_rec.lcn_id;
         END IF;
         IF NOT (cg$ind.NAME) THEN
            cg$rec.NAME := cg$upd_rec.NAME;
         END IF;
         IF NOT (cg$ind.abbreviation) THEN
            cg$rec.abbreviation := cg$upd_rec.abbreviation;
         END IF;
         IF NOT (cg$ind.naming_pattern) THEN
            cg$rec.naming_pattern := cg$upd_rec.naming_pattern;
         END IF;
         IF NOT (cg$ind.description) THEN
            cg$rec.description := cg$upd_rec.description;
         END IF;
         IF NOT (cg$ind.comments) THEN
            cg$rec.comments := cg$upd_rec.comments;
         END IF;
         IF NOT (cg$ind.icon_name) THEN
            cg$rec.icon_name := cg$upd_rec.icon_name;
         END IF;
         IF NOT (cg$ind.MAP) THEN
            cg$rec.MAP := cg$upd_rec.MAP;
         END IF;
      ELSE
         IF (cg$ind.id) THEN
            raise_uk_not_updateable('NIT_CPK_LCN');
         END IF;
      END IF;

      up_autogen_columns(cg$rec
                        ,cg$ind
                        ,'UPD'
                        ,do_upd); --  Auto-generated and uppercased columns

      --  Now do update if updateable columns exist
      IF (do_upd) THEN
         DECLARE
            called_from BOOLEAN := called_from_package;
         BEGIN
            called_from_package := TRUE;

            slct(cg$old_rec);

            IF cg$rec.the_rowid IS NULL THEN
               UPDATE nit_locations
               SET    creation_date    = cg$rec.creation_date
                     ,created_by       = cg$rec.created_by
                     ,last_update_date = cg$rec.last_update_date
                     ,last_updated_by  = cg$rec.last_updated_by
                     ,lcn_id           = cg$rec.lcn_id
                     ,NAME             = cg$rec.NAME
                     ,abbreviation     = cg$rec.abbreviation
                     ,naming_pattern   = cg$rec.naming_pattern
                     ,description      = cg$rec.description
                     ,comments         = cg$rec.comments
                     ,icon_name        = cg$rec.icon_name
                     ,MAP              = cg$rec.MAP
               WHERE  id = cg$rec.id RETURNING id, creation_date, created_by,
                last_update_date, last_updated_by, lcn_id, NAME,
                abbreviation, naming_pattern, description, comments,
                icon_name, MAP, ROWID INTO cg$rec.id,
                cg$rec.creation_date, cg$rec.created_by,
                cg$rec.last_update_date, cg$rec.last_updated_by,
                cg$rec.lcn_id, cg$rec.NAME, cg$rec.abbreviation,
                cg$rec.naming_pattern, cg$rec.description,
                cg$rec.comments, cg$rec.icon_name, cg$rec.MAP,
                cg$rec.the_rowid;
            ELSE
               UPDATE nit_locations
               SET    creation_date    = cg$rec.creation_date
                     ,created_by       = cg$rec.created_by
                     ,last_update_date = cg$rec.last_update_date
                     ,last_updated_by  = cg$rec.last_updated_by
                     ,lcn_id           = cg$rec.lcn_id
                     ,NAME             = cg$rec.NAME
                     ,abbreviation     = cg$rec.abbreviation
                     ,naming_pattern   = cg$rec.naming_pattern
                     ,description      = cg$rec.description
                     ,comments         = cg$rec.comments
                     ,icon_name        = cg$rec.icon_name
                     ,MAP              = cg$rec.MAP
               WHERE  ROWID = cg$rec.the_rowid RETURNING id, creation_date,
                created_by, last_update_date, last_updated_by, lcn_id, NAME,
                abbreviation, naming_pattern, description, comments,
                icon_name, MAP, ROWID INTO cg$rec.id,
                cg$rec.creation_date, cg$rec.created_by,
                cg$rec.last_update_date, cg$rec.last_updated_by,
                cg$rec.lcn_id, cg$rec.NAME, cg$rec.abbreviation,
                cg$rec.naming_pattern, cg$rec.description,
                cg$rec.comments, cg$rec.icon_name, cg$rec.MAP,
                cg$rec.the_rowid;
            END IF;

            called_from_package := called_from;
         END;
      END IF;



      IF NOT (do_upd) THEN
         cg$table(idx).id := cg$rec.id;
         cg$tableind(idx).id := cg$ind.id;
         cg$table(idx).creation_date := cg$rec.creation_date;
         cg$tableind(idx).creation_date := cg$ind.creation_date;
         cg$table(idx).created_by := cg$rec.created_by;
         cg$tableind(idx).created_by := cg$ind.created_by;
         cg$table(idx).last_update_date := cg$rec.last_update_date;
         cg$tableind(idx).last_update_date := cg$ind.last_update_date;
         cg$table(idx).last_updated_by := cg$rec.last_updated_by;
         cg$tableind(idx).last_updated_by := cg$ind.last_updated_by;
         cg$table(idx).lcn_id := cg$rec.lcn_id;
         cg$tableind(idx).lcn_id := cg$ind.lcn_id;
         cg$table(idx).NAME := cg$rec.NAME;
         cg$tableind(idx).NAME := cg$ind.NAME;
         cg$table(idx).abbreviation := cg$rec.abbreviation;
         cg$tableind(idx).abbreviation := cg$ind.abbreviation;
         cg$table(idx).naming_pattern := cg$rec.naming_pattern;
         cg$tableind(idx).naming_pattern := cg$ind.naming_pattern;
         cg$table(idx).description := cg$rec.description;
         cg$tableind(idx).description := cg$ind.description;
         cg$table(idx).comments := cg$rec.comments;
         cg$tableind(idx).comments := cg$ind.comments;
         cg$table(idx).icon_name := cg$rec.icon_name;
         cg$tableind(idx).icon_name := cg$ind.icon_name;
         cg$table(idx).MAP := cg$rec.MAP;
         cg$tableind(idx).MAP := cg$ind.MAP;
         idx := idx + 1;
      END IF;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.upd_mandatory_null THEN
         validate_mandatory(cg$rec
                           ,'cg$NIT_LOCATIONS.upd.upd_mandatory_null');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.check_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_check_con
                ,'cg$NIT_LOCATIONS.upd.check_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.fk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_foreign_key
                ,'cg$NIT_LOCATIONS.upd.fk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.uk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_unique_key
                ,'cg$NIT_LOCATIONS.upd.uk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_LOCATIONS.upd.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END upd;

   --------------------------------------------------------------------------------
   -- Name:        del
   --
   -- Description: API delete procedure
   --
   -- Parameters:  cg$pk  Primary key record of row to be deleted
   --------------------------------------------------------------------------------
   PROCEDURE del(cg$pk  IN cg$pk_type
                ,do_del IN BOOLEAN DEFAULT TRUE) IS
   BEGIN
      nit_locations_p.pre_del(cg$pk.id);

      --  Delete the record

      called_from_package := TRUE;

      IF (do_del) THEN
         IF cg$pk.the_rowid IS NULL THEN
            DELETE nit_locations
            WHERE  id = cg$pk.id;
         ELSE
            DELETE nit_locations
            WHERE  ROWID = cg$pk.the_rowid;
         END IF;
      END IF;

      called_from_package := FALSE;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.delete_restrict THEN
         err_msg(SQLERRM
                ,cg$errors.err_delete_restrict
                ,'cg$NIT_LOCATIONS.del.delete_restrict');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN no_data_found THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_row_del
                                            ,cg$errors.row_del)
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_LOCATIONS.del.no_data_found');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_LOCATIONS.del.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END del;


   --------------------------------------------------------------------------------
   -- Name:        lck
   --
   -- Description: API lock procedure
   --
   -- Parameters:  cg$old_rec  Calling apps view of record of row to be locked
   --              cg$old_ind  Record of columns to raise error if modified
   --              nowait_flag TRUE lock with NOWAIT, FALSE don't fail if busy
   --------------------------------------------------------------------------------
   PROCEDURE lck(cg$old_rec  IN cg$row_type
                ,cg$old_ind  IN cg$ind_type
                ,nowait_flag IN BOOLEAN DEFAULT TRUE) IS
      cg$tmp_rec   cg$row_type;
      any_modified BOOLEAN := FALSE;

   BEGIN

      BEGIN
         IF (nowait_flag) THEN
            IF cg$old_rec.the_rowid IS NULL THEN
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,lcn_id
                     ,NAME
                     ,abbreviation
                     ,naming_pattern
                     ,description
                     ,comments
                     ,icon_name
                     ,MAP
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.lcn_id
                     ,cg$tmp_rec.NAME
                     ,cg$tmp_rec.abbreviation
                     ,cg$tmp_rec.naming_pattern
                     ,cg$tmp_rec.description
                     ,cg$tmp_rec.comments
                     ,cg$tmp_rec.icon_name
                     ,cg$tmp_rec.MAP
               FROM   nit_locations
               WHERE  id = cg$old_rec.id
               FOR    UPDATE NOWAIT;
            ELSE
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,lcn_id
                     ,NAME
                     ,abbreviation
                     ,naming_pattern
                     ,description
                     ,comments
                     ,icon_name
                     ,MAP
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.lcn_id
                     ,cg$tmp_rec.NAME
                     ,cg$tmp_rec.abbreviation
                     ,cg$tmp_rec.naming_pattern
                     ,cg$tmp_rec.description
                     ,cg$tmp_rec.comments
                     ,cg$tmp_rec.icon_name
                     ,cg$tmp_rec.MAP
               FROM   nit_locations
               WHERE  ROWID = cg$old_rec.the_rowid
               FOR    UPDATE NOWAIT;
            END IF;
         ELSE
            IF cg$old_rec.the_rowid IS NULL THEN
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,lcn_id
                     ,NAME
                     ,abbreviation
                     ,naming_pattern
                     ,description
                     ,comments
                     ,icon_name
                     ,MAP
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.lcn_id
                     ,cg$tmp_rec.NAME
                     ,cg$tmp_rec.abbreviation
                     ,cg$tmp_rec.naming_pattern
                     ,cg$tmp_rec.description
                     ,cg$tmp_rec.comments
                     ,cg$tmp_rec.icon_name
                     ,cg$tmp_rec.MAP
               FROM   nit_locations
               WHERE  id = cg$old_rec.id
               FOR    UPDATE;
            ELSE
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,lcn_id
                     ,NAME
                     ,abbreviation
                     ,naming_pattern
                     ,description
                     ,comments
                     ,icon_name
                     ,MAP
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.lcn_id
                     ,cg$tmp_rec.NAME
                     ,cg$tmp_rec.abbreviation
                     ,cg$tmp_rec.naming_pattern
                     ,cg$tmp_rec.description
                     ,cg$tmp_rec.comments
                     ,cg$tmp_rec.icon_name
                     ,cg$tmp_rec.MAP
               FROM   nit_locations
               WHERE  ROWID = cg$old_rec.the_rowid
               FOR    UPDATE;
            END IF;
         END IF;

      EXCEPTION
         WHEN cg$errors.cg$error THEN
            cg$errors.raise_failure;
         WHEN cg$errors.resource_busy THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_lck
                                               ,cg$errors.row_lck)
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_LOCATIONS.lck.resource_busy');
            cg$errors.raise_failure;
         WHEN no_data_found THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_del
                                               ,cg$errors.row_del)
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_LOCATIONS.lck.no_data_found');
            cg$errors.raise_failure;
         WHEN OTHERS THEN
            cg$errors.push(SQLERRM
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_LOCATIONS.lck.others');
            cg$errors.raise_failure;
      END;

      -- Optional Columns

      IF (cg$old_ind.lcn_id) THEN
         IF (cg$tmp_rec.lcn_id IS NOT NULL AND cg$old_rec.lcn_id IS NOT NULL) THEN
            IF (cg$tmp_rec.lcn_id != cg$old_rec.lcn_id) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p30lcn_id)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_LOCATIONS.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.lcn_id IS NOT NULL OR cg$old_rec.lcn_id IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p30lcn_id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_LOCATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.abbreviation) THEN
         IF (cg$tmp_rec.abbreviation IS NOT NULL AND
            cg$old_rec.abbreviation IS NOT NULL) THEN
            IF (cg$tmp_rec.abbreviation != cg$old_rec.abbreviation) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p60abbreviation)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_LOCATIONS.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.abbreviation IS NOT NULL OR
               cg$old_rec.abbreviation IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p60abbreviation)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_LOCATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.naming_pattern) THEN
         IF (cg$tmp_rec.naming_pattern IS NOT NULL AND
            cg$old_rec.naming_pattern IS NOT NULL) THEN
            IF (cg$tmp_rec.naming_pattern != cg$old_rec.naming_pattern) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p70naming_pattern)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_LOCATIONS.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.naming_pattern IS NOT NULL OR
               cg$old_rec.naming_pattern IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p70naming_pattern)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_LOCATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.description) THEN
         IF (cg$tmp_rec.description IS NOT NULL AND
            cg$old_rec.description IS NOT NULL) THEN
            IF (cg$tmp_rec.description != cg$old_rec.description) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p80description)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_LOCATIONS.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.description IS NOT NULL OR
               cg$old_rec.description IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p80description)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_LOCATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.comments) THEN
         IF (cg$tmp_rec.comments IS NOT NULL AND
            cg$old_rec.comments IS NOT NULL) THEN
            IF (cg$tmp_rec.comments != cg$old_rec.comments) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p90comments)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_LOCATIONS.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.comments IS NOT NULL OR
               cg$old_rec.comments IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p90comments)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_LOCATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.icon_name) THEN
         IF (cg$tmp_rec.icon_name IS NOT NULL AND
            cg$old_rec.icon_name IS NOT NULL) THEN
            IF (cg$tmp_rec.icon_name != cg$old_rec.icon_name) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p100icon_name)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_LOCATIONS.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.icon_name IS NOT NULL OR
               cg$old_rec.icon_name IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p100icon_name)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_LOCATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.MAP) THEN
         IF (cg$tmp_rec.MAP IS NOT NULL AND cg$old_rec.MAP IS NOT NULL) THEN
            IF (cg$tmp_rec.MAP != cg$old_rec.MAP) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p110map)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_LOCATIONS.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.MAP IS NOT NULL OR cg$old_rec.MAP IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p110map)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_LOCATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;

      -- Mandatory Columns

      IF (cg$old_ind.id) THEN
         IF (cg$tmp_rec.id != cg$old_rec.id) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p10id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_LOCATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.creation_date) THEN
         IF (cg$tmp_rec.creation_date != cg$old_rec.creation_date) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p15creation_date)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_LOCATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.created_by) THEN
         IF (cg$tmp_rec.created_by != cg$old_rec.created_by) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p16created_by)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_LOCATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.last_update_date) THEN
         IF (cg$tmp_rec.last_update_date != cg$old_rec.last_update_date) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p19last_update_date)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_LOCATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.last_updated_by) THEN
         IF (cg$tmp_rec.last_updated_by != cg$old_rec.last_updated_by) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p24last_updated_by)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_LOCATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.NAME) THEN
         IF (cg$tmp_rec.NAME != cg$old_rec.NAME) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p40name)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_LOCATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;

      IF (any_modified) THEN
         cg$errors.raise_failure;
      END IF;

   END lck;


BEGIN
   cg$ind_true.id               := TRUE;
   cg$ind_true.creation_date    := TRUE;
   cg$ind_true.created_by       := TRUE;
   cg$ind_true.last_update_date := TRUE;
   cg$ind_true.last_updated_by  := TRUE;
   cg$ind_true.lcn_id           := TRUE;
   cg$ind_true.NAME             := TRUE;
   cg$ind_true.abbreviation     := TRUE;
   cg$ind_true.naming_pattern   := TRUE;
   cg$ind_true.description      := TRUE;
   cg$ind_true.comments         := TRUE;
   cg$ind_true.icon_name        := TRUE;
   cg$ind_true.MAP              := TRUE;


END cg$nit_locations;
/

prompt
prompt Creating package body CG$NIT_OPERATIONS
prompt =======================================
prompt
CREATE OR REPLACE PACKAGE BODY cg$nit_operations IS

   PROCEDURE validate_mandatory(cg$val_rec IN cg$row_type
                               ,loc        IN VARCHAR2 DEFAULT '');
   PROCEDURE up_autogen_columns(cg$rec    IN OUT cg$row_type
                               ,cg$ind    IN OUT cg$ind_type
                               ,operation IN VARCHAR2 DEFAULT 'INS'
                               ,do_denorm IN BOOLEAN DEFAULT TRUE);
   PROCEDURE err_msg(msg  IN VARCHAR2
                    ,TYPE IN INTEGER
                    ,loc  IN VARCHAR2 DEFAULT '');

   --------------------------------------------------------------------------------
   -- Name:        raise_uk_not_updateable
   --
   -- Description: Raise appropriate error when unique key updated
   --
   -- Parameters:  none
   --------------------------------------------------------------------------------
   PROCEDURE raise_uk_not_updateable(uk IN VARCHAR2) IS
   BEGIN
      cg$errors.push(cg$errors.msggettext(cg$errors.api_unique_key_update
                                         ,cg$errors.err_uk_update
                                         ,uk)
                    ,'E'
                    ,'API'
                    ,cg$errors.api_unique_key_update
                    ,'cg$NIT_OPERATIONS.raise_uk_not_updateable');
      cg$errors.raise_failure;
   END raise_uk_not_updateable;


   --------------------------------------------------------------------------------
   -- Name:        raise_fk_not_transferable
   --
   -- Description: Raise appropriate error when foreign key updated
   --
   -- Parameters:  none
   --------------------------------------------------------------------------------
   PROCEDURE raise_fk_not_transferable(fk IN VARCHAR2) IS
   BEGIN
      cg$errors.push(cg$errors.msggettext(cg$errors.api_foreign_key_trans
                                         ,cg$errors.err_fk_trans
                                         ,fk)
                    ,'E'
                    ,'API'
                    ,cg$errors.api_foreign_key_trans
                    ,'cg$NIT_OPERATIONS.raise_fk_not_transferable');
      cg$errors.raise_failure;
   END raise_fk_not_transferable;


   --------------------------------------------------------------------------------
   -- Name:        up_autogen_columns
   --
   -- Description: Specific autogeneration of column values and conversion to
   --              uppercase
   --
   -- Parameters:  cg$rec    Record of row to be manipulated
   --              cg$ind    Indicators for row
   --              operation Procedure where this procedure was called
   --------------------------------------------------------------------------------
   PROCEDURE up_autogen_columns(cg$rec    IN OUT cg$row_type
                               ,cg$ind    IN OUT cg$ind_type
                               ,operation IN VARCHAR2 DEFAULT 'INS'
                               ,do_denorm IN BOOLEAN DEFAULT TRUE) IS
   BEGIN
      IF (operation = 'INS') THEN
         BEGIN
            IF (cg$ind.id = FALSE OR cg$rec.id IS NULL) THEN
               SELECT cc_next_value
               INTO   cg$rec.id
               FROM   cg_code_controls
               WHERE  cc_domain = 'NIT_OPN_SEQ'
               FOR    UPDATE;


               UPDATE cg_code_controls
               SET    cc_next_value = cc_next_value + cc_increment
               WHERE  cc_domain = 'NIT_OPN_SEQ';
            END IF;
         EXCEPTION
            WHEN cg$errors.cg$error THEN
               cg$errors.raise_failure;
            WHEN cg$errors.resource_busy THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_code_ctl_locked
                                                  ,cg$errors.apimsg_code_ctl_locked
                                                  ,'NIT_OPN_SEQ')
                             ,'E'
                             ,'API'
                             ,cg$errors.api_code_ctl_locked
                             ,'cg$NIT_OPERATIONS.up_autogen.seq_resource_busy');
               cg$errors.raise_failure;
            WHEN OTHERS THEN
               cg$errors.push(SQLERRM
                             ,'E'
                             ,'ORA'
                             ,SQLCODE
                             ,'cg$NIT_OPERATIONS.up_autogen.seq.OTHERS');
               cg$errors.raise_failure;
         END;
      ELSE
         -- (operation = 'UPD')
         NULL;
      END IF; -- (operation = 'INS') ELSE (operation = 'UPD')

      -- Statements executed for both 'INS' and 'UPD'


   EXCEPTION
      WHEN no_data_found THEN
         NULL;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_OPERATIONS.up_autogen_columns');
         cg$errors.raise_failure;
   END up_autogen_columns;


   --------------------------------------------------------------------------------
   -- Name:        validate_mandatory
   --
   -- Description: Checks all mandatory columns are not null and raises appropriate
   --              error if not satisfied
   --
   -- Parameters:  cg$val_rec Record of row to be checked
   --              loc        Place where this procedure was called for error
   --                         trapping
   --------------------------------------------------------------------------------
   PROCEDURE validate_mandatory(cg$val_rec IN cg$row_type
                               ,loc        IN VARCHAR2 DEFAULT '') IS
   BEGIN
      IF (cg$val_rec.id IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p10id)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.creation_date IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p15creation_date)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.created_by IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p16created_by)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.last_update_date IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p19last_update_date)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.last_updated_by IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p24last_updated_by)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.usr_id IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p30usr_id)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.type_name IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p40type_name)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.status IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p50status)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.op_time IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p60op_time)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      NULL;
   END validate_mandatory;

   --------------------------------------------------------------------------------
   -- Name:        slct
   --
   -- Description: Selects into the given parameter all the attributes for the row
   --              given by the primary key
   --
   -- Parameters:  cg$sel_rec  Record of row to be selected into using its PK
   --------------------------------------------------------------------------------
   PROCEDURE slct(cg$sel_rec IN OUT cg$row_type) IS

   BEGIN

      IF cg$sel_rec.the_rowid IS NULL THEN
         SELECT id
               ,creation_date
               ,created_by
               ,last_update_date
               ,last_updated_by
               ,usr_id
               ,type_name
               ,status
               ,op_time
               ,users
               ,comments
               ,ROWID
         INTO   cg$sel_rec.id
               ,cg$sel_rec.creation_date
               ,cg$sel_rec.created_by
               ,cg$sel_rec.last_update_date
               ,cg$sel_rec.last_updated_by
               ,cg$sel_rec.usr_id
               ,cg$sel_rec.type_name
               ,cg$sel_rec.status
               ,cg$sel_rec.op_time
               ,cg$sel_rec.users
               ,cg$sel_rec.comments
               ,cg$sel_rec.the_rowid
         FROM   nit_operations
         WHERE  id = cg$sel_rec.id;
      ELSE
         SELECT id
               ,creation_date
               ,created_by
               ,last_update_date
               ,last_updated_by
               ,usr_id
               ,type_name
               ,status
               ,op_time
               ,users
               ,comments
               ,ROWID
         INTO   cg$sel_rec.id
               ,cg$sel_rec.creation_date
               ,cg$sel_rec.created_by
               ,cg$sel_rec.last_update_date
               ,cg$sel_rec.last_updated_by
               ,cg$sel_rec.usr_id
               ,cg$sel_rec.type_name
               ,cg$sel_rec.status
               ,cg$sel_rec.op_time
               ,cg$sel_rec.users
               ,cg$sel_rec.comments
               ,cg$sel_rec.the_rowid
         FROM   nit_operations
         WHERE  ROWID = cg$sel_rec.the_rowid;
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_OPERATIONS.slct.others');
         cg$errors.raise_failure;

   END slct;

   --------------------------------------------------------------------------------
   -- Name:        validate_domain
   --
   -- Description: Checks against reference table for values lying in a domain
   --
   -- Parameters:  cg$rec     Record of NIT_OPERATIONS current values
   --------------------------------------------------------------------------------
   PROCEDURE validate_domain(cg$rec IN OUT cg$row_type
                            ,cg$ind IN cg$ind_type DEFAULT cg$ind_true) IS
      FOUND BOOLEAN;
      no_tabview EXCEPTION;
      PRAGMA EXCEPTION_INIT(no_tabview
                           ,-942);
   BEGIN

      FOUND := FALSE;
      IF (cg$ind.type_name AND cg$rec.type_name IS NOT NULL) THEN
         FOR c IN (SELECT rv_low_value
                         ,rv_high_value
                   FROM   cg_ref_codes
                   WHERE  rv_domain = 'OP_TYPES') LOOP
            IF (c.rv_high_value IS NULL AND cg$rec.type_name = c.rv_low_value) OR
               (c.rv_high_value IS NOT NULL AND
               cg$rec.type_name BETWEEN c.rv_low_value AND c.rv_high_value) THEN
               FOUND := TRUE;
               EXIT;
            END IF;
         END LOOP;

         IF (NOT FOUND) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_rv_lookup_fail
                                               ,cg$errors.apimsg_rv_lookup_fail
                                               ,cg$rec.type_name
                                               ,'NIT_OPERATIONS'
                                               ,'TYPE_NAME')
                          ,'E'
                          ,'API'
                          ,cg$errors.api_rv_lookup_fail
                          ,'cg$NIT_OPERATIONS.v_domain.no_data_found');
            cg$errors.raise_failure;
         END IF;
      END IF;

      FOUND := FALSE;
      IF (cg$ind.status AND cg$rec.status IS NOT NULL) THEN
         FOR c IN (SELECT rv_low_value
                         ,rv_high_value
                   FROM   cg_ref_codes
                   WHERE  rv_domain = 'OP_STATUS') LOOP
            IF (c.rv_high_value IS NULL AND cg$rec.status = c.rv_low_value) OR
               (c.rv_high_value IS NOT NULL AND
               cg$rec.status BETWEEN c.rv_low_value AND c.rv_high_value) THEN
               FOUND := TRUE;
               EXIT;
            END IF;
         END LOOP;

         IF (NOT FOUND) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_rv_lookup_fail
                                               ,cg$errors.apimsg_rv_lookup_fail
                                               ,cg$rec.status
                                               ,'NIT_OPERATIONS'
                                               ,'STATUS')
                          ,'E'
                          ,'API'
                          ,cg$errors.api_rv_lookup_fail
                          ,'cg$NIT_OPERATIONS.v_domain.no_data_found');
            cg$errors.raise_failure;
         END IF;
      END IF;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         cg$errors.raise_failure;
      WHEN no_tabview THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_rv_tab_not_found
                                            ,cg$errors.apimsg_rv_tab_not_found
                                            ,'CG_REF_CODES'
                                            ,'NIT_OPERATIONS')
                       ,'E'
                       ,'API'
                       ,cg$errors.api_rv_tab_not_found
                       ,'cg$NIT_OPERATIONS.v_domain.no_reftable_found');
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_OPERATIONS.v_domain.others');
         cg$errors.raise_failure;
   END validate_domain;


   --------------------------------------------------------------------------------
   -- Name:        err_msg
   --
   -- Description: Pushes onto stack appropriate user defined error message
   --              depending on the rule violated
   --
   -- Parameters:  msg     Oracle error message
   --              type    Type of violation e.g. check_constraint: ERR_CHECK_CON
   --              loc     Place where this procedure was called for error
   --                      trapping
   --------------------------------------------------------------------------------
   PROCEDURE err_msg(msg  IN VARCHAR2
                    ,TYPE IN INTEGER
                    ,loc  IN VARCHAR2 DEFAULT '') IS
      con_name VARCHAR2(240);
   BEGIN
      con_name := cg$errors.parse_constraint(msg
                                            ,TYPE);
      IF (con_name = 'NIT_CPK_OPN') THEN
         cg$errors.push(NVL(nit_cpk_opn
                           ,cg$errors.msggettext(cg$errors.api_pk_con_violated
                                                ,cg$errors.apimsg_pk_violat
                                                ,'NIT_CPK_OPN'
                                                ,'NIT_OPERATIONS'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_pk_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CFK_PSN_OPN' AND
            TYPE = cg$errors.err_delete_restrict) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_del_restrict
                                            ,cg$errors.err_del_restrict
                                            ,'NIT_OPERATIONS'
                                            ,'NIT_POSITIONS')
                       ,'E'
                       ,'API'
                       ,cg$errors.api_del_restrict
                       ,loc);
      ELSIF (con_name = 'NIT_CFK_CI_OPN' AND
            TYPE = cg$errors.err_delete_restrict) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_del_restrict
                                            ,cg$errors.err_del_restrict
                                            ,'NIT_OPERATIONS'
                                            ,'NIT_CONFIG_ITEMS')
                       ,'E'
                       ,'API'
                       ,cg$errors.api_del_restrict
                       ,loc);
      ELSIF (con_name = 'NIT_CFK_CIR_OPN' AND
            TYPE = cg$errors.err_delete_restrict) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_del_restrict
                                            ,cg$errors.err_del_restrict
                                            ,'NIT_OPERATIONS'
                                            ,'NIT_CI_RELATIONS')
                       ,'E'
                       ,'API'
                       ,cg$errors.api_del_restrict
                       ,loc);
      ELSIF (con_name = 'NIT_CFK_CIA_OPN' AND
            TYPE = cg$errors.err_delete_restrict) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_del_restrict
                                            ,cg$errors.err_del_restrict
                                            ,'NIT_OPERATIONS'
                                            ,'NIT_CI_ATTRIBUTES')
                       ,'E'
                       ,'API'
                       ,cg$errors.api_del_restrict
                       ,loc);

      ELSIF (con_name = 'NIT_CFK_OPN_USR') THEN
         cg$errors.push(NVL(nit_cfk_opn_usr
                           ,cg$errors.msggettext(cg$errors.api_fk_con_violated
                                                ,cg$errors.apimsg_fk_violat
                                                ,'NIT_CFK_OPN_USR'
                                                ,'NIT_OPERATIONS'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_fk_con_violated
                       ,loc);
      ELSE
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,loc);
      END IF;
   END err_msg;

   --------------------------------------------------------------------------------
   -- Name:        ins
   --
   -- Description: API insert procedure
   --
   -- Parameters:  cg$rec  Record of row to be inserted
   --              cg$ind  Record of columns specifically set
   --              do_ins  Whether we want the actual INSERT to occur
   --------------------------------------------------------------------------------
   PROCEDURE ins(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_ins IN BOOLEAN DEFAULT TRUE) IS

      --  Constant default values

      d40_type_name CONSTANT nit_operations.type_name%TYPE := 'routine';
      d60_op_time   CONSTANT nit_operations.op_time%TYPE := CURRENT_DATE;

   BEGIN

      IF NOT (cg$ind.type_name) THEN
         cg$rec.type_name := d40_type_name;
      END IF;
      IF NOT (cg$ind.op_time) THEN
         cg$rec.op_time := d60_op_time;
      END IF;
      --  Auto-generated and uppercased columns

      up_autogen_columns(cg$rec
                        ,cg$ind
                        ,'INS'
                        ,do_ins);

      called_from_package := TRUE;

      IF (do_ins) THEN
         validate_domain(cg$rec);

         INSERT INTO nit_operations
            (id
            ,creation_date
            ,created_by
            ,last_update_date
            ,last_updated_by
            ,usr_id
            ,type_name
            ,status
            ,op_time
            ,users
            ,comments)
         VALUES
            (cg$rec.id
            ,cg$rec.creation_date
            ,cg$rec.created_by
            ,cg$rec.last_update_date
            ,cg$rec.last_updated_by
            ,cg$rec.usr_id
            ,cg$rec.type_name
            ,cg$rec.status
            ,cg$rec.op_time
            ,cg$rec.users
            ,cg$rec.comments)
         RETURNING id, creation_date, created_by, last_update_date, last_updated_by, usr_id, type_name, status, op_time, users, comments, ROWID INTO cg$rec.id, cg$rec.creation_date, cg$rec.created_by, cg$rec.last_update_date, cg$rec.last_updated_by, cg$rec.usr_id, cg$rec.type_name, cg$rec.status, cg$rec.op_time, cg$rec.users, cg$rec.comments, cg$rec.the_rowid;

      END IF;

      called_from_package := FALSE;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.mandatory_missing THEN
         validate_mandatory(cg$rec
                           ,'cg$NIT_OPERATIONS.ins.mandatory_missing');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.check_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_check_con
                ,'cg$NIT_OPERATIONS.ins.check_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.fk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_foreign_key
                ,'cg$NIT_OPERATIONS.ins.fk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.uk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_unique_key
                ,'cg$NIT_OPERATIONS.ins.uk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_OPERATIONS.ins.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END ins;


   --------------------------------------------------------------------------------
   -- Name:        upd
   --
   -- Description: API update procedure
   --
   -- Parameters:  cg$rec  Record of row to be updated
   --              cg$ind  Record of columns specifically set
   --              do_upd  Whether we want the actual UPDATE to occur
   --------------------------------------------------------------------------------
   PROCEDURE upd(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_upd IN BOOLEAN DEFAULT TRUE
                ,cg$pk  IN cg$row_type DEFAULT NULL) IS
      cg$upd_rec cg$row_type;
      cg$old_rec cg$row_type;
   BEGIN

      IF (cg$pk.id IS NULL) THEN
         cg$upd_rec.id := cg$rec.id;
      ELSE
         cg$upd_rec.id := cg$pk.id;
      END IF;
      cg$old_rec.id := cg$upd_rec.id;

      IF (cg$pk.the_rowid IS NULL) THEN
         cg$upd_rec.the_rowid := cg$rec.the_rowid;
      ELSE
         cg$upd_rec.the_rowid := cg$pk.the_rowid;
      END IF;
      cg$old_rec.the_rowid := cg$upd_rec.the_rowid;

      IF (do_upd) THEN

         slct(cg$upd_rec);

         --  Report error if attempt to update non transferable Foreign Key NIT_CFK_OPN_USR
         IF (cg$ind.usr_id AND cg$rec.usr_id != cg$upd_rec.usr_id) THEN
            raise_fk_not_transferable('NIT_CFK_OPN_USR');
         END IF;
         IF (cg$ind.usr_id AND cg$rec.usr_id IS NULL AND
            cg$upd_rec.usr_id IS NOT NULL) THEN
            raise_fk_not_transferable('NIT_CFK_OPN_USR');
         END IF;
         IF (cg$ind.usr_id AND cg$rec.usr_id IS NOT NULL AND
            cg$upd_rec.usr_id IS NULL) THEN
            raise_fk_not_transferable('NIT_CFK_OPN_USR');
         END IF;

         --  Report error if attempt to update non updateable Primary Key NIT_CPK_OPN
         IF (cg$ind.id AND cg$rec.id != cg$upd_rec.id) THEN
            raise_uk_not_updateable('NIT_CPK_OPN');
         END IF;
         IF NOT (cg$ind.id) THEN
            cg$rec.id := cg$upd_rec.id;
         END IF;
         IF NOT (cg$ind.creation_date) THEN
            cg$rec.creation_date := cg$upd_rec.creation_date;
         END IF;
         IF NOT (cg$ind.created_by) THEN
            cg$rec.created_by := cg$upd_rec.created_by;
         END IF;
         IF NOT (cg$ind.last_update_date) THEN
            cg$rec.last_update_date := cg$upd_rec.last_update_date;
         END IF;
         IF NOT (cg$ind.last_updated_by) THEN
            cg$rec.last_updated_by := cg$upd_rec.last_updated_by;
         END IF;
         IF NOT (cg$ind.usr_id) THEN
            cg$rec.usr_id := cg$upd_rec.usr_id;
         END IF;
         IF NOT (cg$ind.type_name) THEN
            cg$rec.type_name := cg$upd_rec.type_name;
         END IF;
         IF NOT (cg$ind.status) THEN
            cg$rec.status := cg$upd_rec.status;
         END IF;
         IF NOT (cg$ind.op_time) THEN
            cg$rec.op_time := cg$upd_rec.op_time;
         END IF;
         IF NOT (cg$ind.users) THEN
            cg$rec.users := cg$upd_rec.users;
         END IF;
         IF NOT (cg$ind.comments) THEN
            cg$rec.comments := cg$upd_rec.comments;
         END IF;
      ELSE
         --  Report error if attempt to update non transferable Foreign Key NIT_CFK_OPN_USR
         IF (cg$ind.usr_id) THEN
            raise_fk_not_transferable('NIT_CFK_OPN_USR');
         END IF;
         --  Report error if attempt to update non updateable Primary Key NIT_CPK_OPN
         IF (cg$ind.id) THEN
            raise_uk_not_updateable('NIT_CPK_OPN');
         END IF;
      END IF;

      up_autogen_columns(cg$rec
                        ,cg$ind
                        ,'UPD'
                        ,do_upd); --  Auto-generated and uppercased columns

      --  Now do update if updateable columns exist
      IF (do_upd) THEN
         DECLARE
            called_from BOOLEAN := called_from_package;
         BEGIN
            called_from_package := TRUE;

            slct(cg$old_rec);
            validate_domain(cg$rec
                           ,cg$ind);

            IF cg$rec.the_rowid IS NULL THEN
               UPDATE nit_operations
               SET    creation_date    = cg$rec.creation_date
                     ,created_by       = cg$rec.created_by
                     ,last_update_date = cg$rec.last_update_date
                     ,last_updated_by  = cg$rec.last_updated_by
                     ,usr_id           = cg$rec.usr_id
                     ,type_name        = cg$rec.type_name
                     ,status           = cg$rec.status
                     ,op_time          = cg$rec.op_time
                     ,users            = cg$rec.users
                     ,comments         = cg$rec.comments
               WHERE  id = cg$rec.id RETURNING id, creation_date, created_by,
                last_update_date, last_updated_by, usr_id, type_name,
                status, op_time, users, comments, ROWID INTO cg$rec.id,
                cg$rec.creation_date, cg$rec.created_by,
                cg$rec.last_update_date, cg$rec.last_updated_by,
                cg$rec.usr_id, cg$rec.type_name, cg$rec.status,
                cg$rec.op_time, cg$rec.users, cg$rec.comments,
                cg$rec.the_rowid;
            ELSE
               UPDATE nit_operations
               SET    creation_date    = cg$rec.creation_date
                     ,created_by       = cg$rec.created_by
                     ,last_update_date = cg$rec.last_update_date
                     ,last_updated_by  = cg$rec.last_updated_by
                     ,usr_id           = cg$rec.usr_id
                     ,type_name        = cg$rec.type_name
                     ,status           = cg$rec.status
                     ,op_time          = cg$rec.op_time
                     ,users            = cg$rec.users
                     ,comments         = cg$rec.comments
               WHERE  ROWID = cg$rec.the_rowid RETURNING id, creation_date,
                created_by, last_update_date, last_updated_by, usr_id,
                type_name, status, op_time, users, comments, ROWID INTO
                cg$rec.id, cg$rec.creation_date, cg$rec.created_by,
                cg$rec.last_update_date, cg$rec.last_updated_by,
                cg$rec.usr_id, cg$rec.type_name, cg$rec.status,
                cg$rec.op_time, cg$rec.users, cg$rec.comments,
                cg$rec.the_rowid;
            END IF;

            called_from_package := called_from;
         END;
      END IF;



      IF NOT (do_upd) THEN
         cg$table(idx).id := cg$rec.id;
         cg$tableind(idx).id := cg$ind.id;
         cg$table(idx).creation_date := cg$rec.creation_date;
         cg$tableind(idx).creation_date := cg$ind.creation_date;
         cg$table(idx).created_by := cg$rec.created_by;
         cg$tableind(idx).created_by := cg$ind.created_by;
         cg$table(idx).last_update_date := cg$rec.last_update_date;
         cg$tableind(idx).last_update_date := cg$ind.last_update_date;
         cg$table(idx).last_updated_by := cg$rec.last_updated_by;
         cg$tableind(idx).last_updated_by := cg$ind.last_updated_by;
         cg$table(idx).usr_id := cg$rec.usr_id;
         cg$tableind(idx).usr_id := cg$ind.usr_id;
         cg$table(idx).type_name := cg$rec.type_name;
         cg$tableind(idx).type_name := cg$ind.type_name;
         cg$table(idx).status := cg$rec.status;
         cg$tableind(idx).status := cg$ind.status;
         cg$table(idx).op_time := cg$rec.op_time;
         cg$tableind(idx).op_time := cg$ind.op_time;
         cg$table(idx).users := cg$rec.users;
         cg$tableind(idx).users := cg$ind.users;
         cg$table(idx).comments := cg$rec.comments;
         cg$tableind(idx).comments := cg$ind.comments;
         idx := idx + 1;
      END IF;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.upd_mandatory_null THEN
         validate_mandatory(cg$rec
                           ,'cg$NIT_OPERATIONS.upd.upd_mandatory_null');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.check_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_check_con
                ,'cg$NIT_OPERATIONS.upd.check_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.fk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_foreign_key
                ,'cg$NIT_OPERATIONS.upd.fk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.uk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_unique_key
                ,'cg$NIT_OPERATIONS.upd.uk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_OPERATIONS.upd.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END upd;

   --------------------------------------------------------------------------------
   -- Name:        del
   --
   -- Description: API delete procedure
   --
   -- Parameters:  cg$pk  Primary key record of row to be deleted
   --------------------------------------------------------------------------------
   PROCEDURE del(cg$pk  IN cg$pk_type
                ,do_del IN BOOLEAN DEFAULT TRUE) IS
   BEGIN

      called_from_package := TRUE;

      IF (do_del) THEN

         IF cg$pk.the_rowid IS NULL THEN
            DELETE nit_operations
            WHERE  id = cg$pk.id;
         ELSE
            DELETE nit_operations
            WHERE  ROWID = cg$pk.the_rowid;
         END IF;
      END IF;

      called_from_package := FALSE;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.delete_restrict THEN
         err_msg(SQLERRM
                ,cg$errors.err_delete_restrict
                ,'cg$NIT_OPERATIONS.del.delete_restrict');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN no_data_found THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_row_del
                                            ,cg$errors.row_del)
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_OPERATIONS.del.no_data_found');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_OPERATIONS.del.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END del;


   --------------------------------------------------------------------------------
   -- Name:        lck
   --
   -- Description: API lock procedure
   --
   -- Parameters:  cg$old_rec  Calling apps view of record of row to be locked
   --              cg$old_ind  Record of columns to raise error if modified
   --              nowait_flag TRUE lock with NOWAIT, FALSE don't fail if busy
   --------------------------------------------------------------------------------
   PROCEDURE lck(cg$old_rec  IN cg$row_type
                ,cg$old_ind  IN cg$ind_type
                ,nowait_flag IN BOOLEAN DEFAULT TRUE) IS
      cg$tmp_rec   cg$row_type;
      any_modified BOOLEAN := FALSE;

   BEGIN

      BEGIN
         IF (nowait_flag) THEN
            IF cg$old_rec.the_rowid IS NULL THEN
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,usr_id
                     ,type_name
                     ,status
                     ,op_time
                     ,users
                     ,comments
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.usr_id
                     ,cg$tmp_rec.type_name
                     ,cg$tmp_rec.status
                     ,cg$tmp_rec.op_time
                     ,cg$tmp_rec.users
                     ,cg$tmp_rec.comments
               FROM   nit_operations
               WHERE  id = cg$old_rec.id
               FOR    UPDATE NOWAIT;
            ELSE
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,usr_id
                     ,type_name
                     ,status
                     ,op_time
                     ,users
                     ,comments
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.usr_id
                     ,cg$tmp_rec.type_name
                     ,cg$tmp_rec.status
                     ,cg$tmp_rec.op_time
                     ,cg$tmp_rec.users
                     ,cg$tmp_rec.comments
               FROM   nit_operations
               WHERE  ROWID = cg$old_rec.the_rowid
               FOR    UPDATE NOWAIT;
            END IF;
         ELSE
            IF cg$old_rec.the_rowid IS NULL THEN
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,usr_id
                     ,type_name
                     ,status
                     ,op_time
                     ,users
                     ,comments
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.usr_id
                     ,cg$tmp_rec.type_name
                     ,cg$tmp_rec.status
                     ,cg$tmp_rec.op_time
                     ,cg$tmp_rec.users
                     ,cg$tmp_rec.comments
               FROM   nit_operations
               WHERE  id = cg$old_rec.id
               FOR    UPDATE;
            ELSE
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,usr_id
                     ,type_name
                     ,status
                     ,op_time
                     ,users
                     ,comments
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.usr_id
                     ,cg$tmp_rec.type_name
                     ,cg$tmp_rec.status
                     ,cg$tmp_rec.op_time
                     ,cg$tmp_rec.users
                     ,cg$tmp_rec.comments
               FROM   nit_operations
               WHERE  ROWID = cg$old_rec.the_rowid
               FOR    UPDATE;
            END IF;
         END IF;

      EXCEPTION
         WHEN cg$errors.cg$error THEN
            cg$errors.raise_failure;
         WHEN cg$errors.resource_busy THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_lck
                                               ,cg$errors.row_lck)
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_OPERATIONS.lck.resource_busy');
            cg$errors.raise_failure;
         WHEN no_data_found THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_del
                                               ,cg$errors.row_del)
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_OPERATIONS.lck.no_data_found');
            cg$errors.raise_failure;
         WHEN OTHERS THEN
            cg$errors.push(SQLERRM
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_OPERATIONS.lck.others');
            cg$errors.raise_failure;
      END;

      -- Optional Columns

      IF (cg$old_ind.users) THEN
         IF (cg$tmp_rec.users IS NOT NULL AND cg$old_rec.users IS NOT NULL) THEN
            IF (cg$tmp_rec.users != cg$old_rec.users) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p70users)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_OPERATIONS.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.users IS NOT NULL OR cg$old_rec.users IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p70users)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_OPERATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.comments) THEN
         IF (cg$tmp_rec.comments IS NOT NULL AND
            cg$old_rec.comments IS NOT NULL) THEN
            IF (cg$tmp_rec.comments != cg$old_rec.comments) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p80comments)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_OPERATIONS.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.comments IS NOT NULL OR
               cg$old_rec.comments IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p80comments)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_OPERATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;

      -- Mandatory Columns

      IF (cg$old_ind.id) THEN
         IF (cg$tmp_rec.id != cg$old_rec.id) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p10id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_OPERATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.creation_date) THEN
         IF (cg$tmp_rec.creation_date != cg$old_rec.creation_date) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p15creation_date)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_OPERATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.created_by) THEN
         IF (cg$tmp_rec.created_by != cg$old_rec.created_by) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p16created_by)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_OPERATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.last_update_date) THEN
         IF (cg$tmp_rec.last_update_date != cg$old_rec.last_update_date) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p19last_update_date)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_OPERATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.last_updated_by) THEN
         IF (cg$tmp_rec.last_updated_by != cg$old_rec.last_updated_by) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p24last_updated_by)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_OPERATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.usr_id) THEN
         IF (cg$tmp_rec.usr_id != cg$old_rec.usr_id) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p30usr_id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_OPERATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.type_name) THEN
         IF (cg$tmp_rec.type_name != cg$old_rec.type_name) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p40type_name)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_OPERATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.status) THEN
         IF (cg$tmp_rec.status != cg$old_rec.status) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p50status)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_OPERATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.op_time) THEN
         IF (cg$tmp_rec.op_time != cg$old_rec.op_time) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p60op_time)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_OPERATIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;

      IF (any_modified) THEN
         cg$errors.raise_failure;
      END IF;

   END lck;

BEGIN
   cg$ind_true.id               := TRUE;
   cg$ind_true.creation_date    := TRUE;
   cg$ind_true.created_by       := TRUE;
   cg$ind_true.last_update_date := TRUE;
   cg$ind_true.last_updated_by  := TRUE;
   cg$ind_true.usr_id           := TRUE;
   cg$ind_true.type_name        := TRUE;
   cg$ind_true.status           := TRUE;
   cg$ind_true.op_time          := TRUE;
   cg$ind_true.users            := TRUE;
   cg$ind_true.comments         := TRUE;

END cg$nit_operations;
/

prompt
prompt Creating package body CG$NIT_POSITIONS
prompt ======================================
prompt
CREATE OR REPLACE PACKAGE BODY cg$nit_positions IS


   PROCEDURE validate_mandatory(cg$val_rec IN cg$row_type
                               ,loc        IN VARCHAR2 DEFAULT '');
   PROCEDURE up_autogen_columns(cg$rec    IN OUT cg$row_type
                               ,cg$ind    IN OUT cg$ind_type
                               ,operation IN VARCHAR2 DEFAULT 'INS'
                               ,do_denorm IN BOOLEAN DEFAULT TRUE);
   PROCEDURE err_msg(msg  IN VARCHAR2
                    ,TYPE IN INTEGER
                    ,loc  IN VARCHAR2 DEFAULT '');

   --------------------------------------------------------------------------------
   -- Name:        raise_uk_not_updateable
   --
   -- Description: Raise appropriate error when unique key updated
   --
   -- Parameters:  none
   --------------------------------------------------------------------------------
   PROCEDURE raise_uk_not_updateable(uk IN VARCHAR2) IS
   BEGIN
      cg$errors.push(cg$errors.msggettext(cg$errors.api_unique_key_update
                                         ,cg$errors.err_uk_update
                                         ,uk)
                    ,'E'
                    ,'API'
                    ,cg$errors.api_unique_key_update
                    ,'cg$NIT_POSITIONS.raise_uk_not_updateable');
      cg$errors.raise_failure;
   END raise_uk_not_updateable;


   --------------------------------------------------------------------------------
   -- Name:        raise_fk_not_transferable
   --
   -- Description: Raise appropriate error when foreign key updated
   --
   -- Parameters:  none
   --------------------------------------------------------------------------------
   PROCEDURE raise_fk_not_transferable(fk IN VARCHAR2) IS
   BEGIN
      cg$errors.push(cg$errors.msggettext(cg$errors.api_foreign_key_trans
                                         ,cg$errors.err_fk_trans
                                         ,fk)
                    ,'E'
                    ,'API'
                    ,cg$errors.api_foreign_key_trans
                    ,'cg$NIT_POSITIONS.raise_fk_not_transferable');
      cg$errors.raise_failure;
   END raise_fk_not_transferable;


   --------------------------------------------------------------------------------
   -- Name:        up_autogen_columns
   --
   -- Description: Specific autogeneration of column values and conversion to
   --              uppercase
   --
   -- Parameters:  cg$rec    Record of row to be manipulated
   --              cg$ind    Indicators for row
   --              operation Procedure where this procedure was called
   --------------------------------------------------------------------------------
   PROCEDURE up_autogen_columns(cg$rec    IN OUT cg$row_type
                               ,cg$ind    IN OUT cg$ind_type
                               ,operation IN VARCHAR2 DEFAULT 'INS'
                               ,do_denorm IN BOOLEAN DEFAULT TRUE) IS
   BEGIN
      IF (operation = 'INS') THEN
         BEGIN
            IF (cg$ind.id = FALSE OR cg$rec.id IS NULL) THEN
               SELECT nit_seq.NEXTVAL
               INTO   cg$rec.id
               FROM   dual;
               cg$ind.id := TRUE;
            END IF;
         EXCEPTION
            WHEN OTHERS THEN
               cg$errors.push(SQLERRM
                             ,'E'
                             ,'ORA'
                             ,SQLCODE
                             ,'cg$NIT_POSITIONS.up_autogen.ID.OTHERS');
               cg$errors.raise_failure;
         END;
      ELSE
         -- (operation = 'UPD')
         NULL;
      END IF; -- (operation = 'INS') ELSE (operation = 'UPD')

      -- Statements executed for both 'INS' and 'UPD'


   EXCEPTION
      WHEN no_data_found THEN
         NULL;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_POSITIONS.up_autogen_columns');
         cg$errors.raise_failure;
   END up_autogen_columns;


   --------------------------------------------------------------------------------
   -- Name:        validate_mandatory
   --
   -- Description: Checks all mandatory columns are not null and raises appropriate
   --              error if not satisfied
   --
   -- Parameters:  cg$val_rec Record of row to be checked
   --              loc        Place where this procedure was called for error
   --                         trapping
   --------------------------------------------------------------------------------
   PROCEDURE validate_mandatory(cg$val_rec IN cg$row_type
                               ,loc        IN VARCHAR2 DEFAULT '') IS
   BEGIN
      IF (cg$val_rec.id IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p10id)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.creation_date IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p15creation_date)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.created_by IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p16created_by)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.last_update_date IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p19last_update_date)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.last_updated_by IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p24last_updated_by)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.ci_id IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p26ci_id)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.lcn_id IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p34lcn_id)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.opn_id IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p50opn_id)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.status IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p60status)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.obsolete IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p80obsolete)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.valid_from IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p90valid_from)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.valid_until IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p100valid_until)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
   END validate_mandatory;

   --------------------------------------------------------------------------------
   -- Name:        slct
   --
   -- Description: Selects into the given parameter all the attributes for the row
   --              given by the primary key
   --
   -- Parameters:  cg$sel_rec  Record of row to be selected into using its PK
   --------------------------------------------------------------------------------
   PROCEDURE slct(cg$sel_rec IN OUT cg$row_type) IS

   BEGIN

      IF cg$sel_rec.the_rowid IS NULL THEN
         SELECT id
               ,creation_date
               ,created_by
               ,last_update_date
               ,last_updated_by
               ,ci_id
               ,lcn_id
               ,opn_id
               ,status
               ,obsolete
               ,valid_from
               ,valid_until
               ,comments
               ,ROWID
         INTO   cg$sel_rec.id
               ,cg$sel_rec.creation_date
               ,cg$sel_rec.created_by
               ,cg$sel_rec.last_update_date
               ,cg$sel_rec.last_updated_by
               ,cg$sel_rec.ci_id
               ,cg$sel_rec.lcn_id
               ,cg$sel_rec.opn_id
               ,cg$sel_rec.status
               ,cg$sel_rec.obsolete
               ,cg$sel_rec.valid_from
               ,cg$sel_rec.valid_until
               ,cg$sel_rec.comments
               ,cg$sel_rec.the_rowid
         FROM   nit_positions
         WHERE  id = cg$sel_rec.id;
      ELSE
         SELECT id
               ,creation_date
               ,created_by
               ,last_update_date
               ,last_updated_by
               ,ci_id
               ,lcn_id
               ,opn_id
               ,status
               ,obsolete
               ,valid_from
               ,valid_until
               ,comments
               ,ROWID
         INTO   cg$sel_rec.id
               ,cg$sel_rec.creation_date
               ,cg$sel_rec.created_by
               ,cg$sel_rec.last_update_date
               ,cg$sel_rec.last_updated_by
               ,cg$sel_rec.ci_id
               ,cg$sel_rec.lcn_id
               ,cg$sel_rec.opn_id
               ,cg$sel_rec.status
               ,cg$sel_rec.obsolete
               ,cg$sel_rec.valid_from
               ,cg$sel_rec.valid_until
               ,cg$sel_rec.comments
               ,cg$sel_rec.the_rowid
         FROM   nit_positions
         WHERE  ROWID = cg$sel_rec.the_rowid;
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_POSITIONS.slct.others');
         cg$errors.raise_failure;

   END slct;

   --------------------------------------------------------------------------------
   -- Name:        validate_domain
   --
   -- Description: Checks against reference table for values lying in a domain
   --
   -- Parameters:  cg$rec     Record of NIT_POSITIONS current values
   --------------------------------------------------------------------------------
   PROCEDURE validate_domain(cg$rec IN OUT cg$row_type
                            ,cg$ind IN cg$ind_type DEFAULT cg$ind_true) IS
      FOUND BOOLEAN;
      no_tabview EXCEPTION;
      PRAGMA EXCEPTION_INIT(no_tabview
                           ,-942);
   BEGIN

      FOUND := FALSE;
      IF (cg$ind.status AND cg$rec.status IS NOT NULL) THEN
         FOR c IN (SELECT rv_low_value
                         ,rv_high_value
                   FROM   cg_ref_codes
                   WHERE  rv_domain = 'OPERATABLE_STATUS') LOOP
            IF (c.rv_high_value IS NULL AND cg$rec.status = c.rv_low_value) OR
               (c.rv_high_value IS NOT NULL AND
               cg$rec.status BETWEEN c.rv_low_value AND c.rv_high_value) THEN
               FOUND := TRUE;
               EXIT;
            END IF;
         END LOOP;

         IF (NOT FOUND) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_rv_lookup_fail
                                               ,cg$errors.apimsg_rv_lookup_fail
                                               ,cg$rec.status
                                               ,'NIT_POSITIONS'
                                               ,'STATUS')
                          ,'E'
                          ,'API'
                          ,cg$errors.api_rv_lookup_fail
                          ,'cg$NIT_POSITIONS.v_domain.no_data_found');
            cg$errors.raise_failure;
         END IF;
      END IF;

      FOUND := FALSE;
      IF (cg$ind.obsolete AND cg$rec.obsolete IS NOT NULL) THEN
         FOR c IN (SELECT rv_low_value
                         ,rv_high_value
                   FROM   cg_ref_codes
                   WHERE  rv_domain = 'OBSOLETE') LOOP
            IF (c.rv_high_value IS NULL AND cg$rec.obsolete = c.rv_low_value) OR
               (c.rv_high_value IS NOT NULL AND
               cg$rec.obsolete BETWEEN c.rv_low_value AND c.rv_high_value) THEN
               FOUND := TRUE;
               EXIT;
            END IF;
         END LOOP;

         IF (NOT FOUND) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_rv_lookup_fail
                                               ,cg$errors.apimsg_rv_lookup_fail
                                               ,cg$rec.obsolete
                                               ,'NIT_POSITIONS'
                                               ,'OBSOLETE')
                          ,'E'
                          ,'API'
                          ,cg$errors.api_rv_lookup_fail
                          ,'cg$NIT_POSITIONS.v_domain.no_data_found');
            cg$errors.raise_failure;
         END IF;
      END IF;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         cg$errors.raise_failure;
      WHEN no_tabview THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_rv_tab_not_found
                                            ,cg$errors.apimsg_rv_tab_not_found
                                            ,'CG_REF_CODES'
                                            ,'NIT_POSITIONS')
                       ,'E'
                       ,'API'
                       ,cg$errors.api_rv_tab_not_found
                       ,'cg$NIT_POSITIONS.v_domain.no_reftable_found');
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_POSITIONS.v_domain.others');
         cg$errors.raise_failure;
   END validate_domain;


   --------------------------------------------------------------------------------
   -- Name:        err_msg
   --
   -- Description: Pushes onto stack appropriate user defined error message
   --              depending on the rule violated
   --
   -- Parameters:  msg     Oracle error message
   --              type    Type of violation e.g. check_constraint: ERR_CHECK_CON
   --              loc     Place where this procedure was called for error
   --                      trapping
   --------------------------------------------------------------------------------
   PROCEDURE err_msg(msg  IN VARCHAR2
                    ,TYPE IN INTEGER
                    ,loc  IN VARCHAR2 DEFAULT '') IS
      con_name VARCHAR2(240);
   BEGIN
      con_name := cg$errors.parse_constraint(msg
                                            ,TYPE);
      IF (con_name = 'NIT_CPK_PSN') THEN
         cg$errors.push(NVL(nit_cpk_psn
                           ,cg$errors.msggettext(cg$errors.api_pk_con_violated
                                                ,cg$errors.apimsg_pk_violat
                                                ,'NIT_CPK_PSN'
                                                ,'NIT_POSITIONS'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_pk_con_violated
                       ,loc);

      ELSIF (con_name = 'NIT_CFK_PSN_OPN') THEN
         cg$errors.push(NVL(nit_cfk_psn_opn
                           ,cg$errors.msggettext(cg$errors.api_fk_con_violated
                                                ,cg$errors.apimsg_fk_violat
                                                ,'NIT_CFK_PSN_OPN'
                                                ,'NIT_POSITIONS'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_fk_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CFK_PSN_CI') THEN
         cg$errors.push(NVL(nit_cfk_psn_ci
                           ,cg$errors.msggettext(cg$errors.api_fk_con_violated
                                                ,cg$errors.apimsg_fk_violat
                                                ,'NIT_CFK_PSN_CI'
                                                ,'NIT_POSITIONS'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_fk_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CFK_PSN_LCN') THEN
         cg$errors.push(NVL(nit_cfk_psn_lcn
                           ,cg$errors.msggettext(cg$errors.api_fk_con_violated
                                                ,cg$errors.apimsg_fk_violat
                                                ,'NIT_CFK_PSN_LCN'
                                                ,'NIT_POSITIONS'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_fk_con_violated
                       ,loc);
      ELSE
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,loc);
      END IF;
   END err_msg;

   --------------------------------------------------------------------------------
   -- Name:        ins
   --
   -- Description: API insert procedure
   --
   -- Parameters:  cg$rec  Record of row to be inserted
   --              cg$ind  Record of columns specifically set
   --              do_ins  Whether we want the actual INSERT to occur
   --------------------------------------------------------------------------------
   PROCEDURE ins(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_ins IN BOOLEAN DEFAULT TRUE) IS

      --  Constant default values

      d80_obsolete CONSTANT nit_positions.obsolete%TYPE := 'L';

   BEGIN
      nit_positions_p.pre_dml(cg$rec
                             ,cg$ind
                             ,'INS');

      --  Defaulted

      IF NOT (cg$ind.obsolete) THEN
         cg$rec.obsolete := d80_obsolete;
      END IF;
      --  Auto-generated and uppercased columns

      up_autogen_columns(cg$rec
                        ,cg$ind
                        ,'INS'
                        ,do_ins);

      called_from_package := TRUE;

      IF (do_ins) THEN
         validate_domain(cg$rec);

         INSERT INTO nit_positions
            (id
            ,creation_date
            ,created_by
            ,last_update_date
            ,last_updated_by
            ,ci_id
            ,lcn_id
            ,opn_id
            ,status
            ,obsolete
            ,valid_from
            ,valid_until
            ,comments)
         VALUES
            (cg$rec.id
            ,cg$rec.creation_date
            ,cg$rec.created_by
            ,cg$rec.last_update_date
            ,cg$rec.last_updated_by
            ,cg$rec.ci_id
            ,cg$rec.lcn_id
            ,cg$rec.opn_id
            ,cg$rec.status
            ,cg$rec.obsolete
            ,cg$rec.valid_from
            ,cg$rec.valid_until
            ,cg$rec.comments)
         RETURNING id, creation_date, created_by, last_update_date, last_updated_by, ci_id, lcn_id, opn_id, status, obsolete, valid_from, valid_until, comments, ROWID INTO cg$rec.id, cg$rec.creation_date, cg$rec.created_by, cg$rec.last_update_date, cg$rec.last_updated_by, cg$rec.ci_id, cg$rec.lcn_id, cg$rec.opn_id, cg$rec.status, cg$rec.obsolete, cg$rec.valid_from, cg$rec.valid_until, cg$rec.comments, cg$rec.the_rowid;
      END IF;

      called_from_package := FALSE;



      --  Application logic Post-Insert <<Start>>
      --  Application logic Post-Insert << End >>

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.mandatory_missing THEN
         validate_mandatory(cg$rec
                           ,'cg$NIT_POSITIONS.ins.mandatory_missing');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.check_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_check_con
                ,'cg$NIT_POSITIONS.ins.check_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.fk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_foreign_key
                ,'cg$NIT_POSITIONS.ins.fk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.uk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_unique_key
                ,'cg$NIT_POSITIONS.ins.uk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_POSITIONS.ins.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END ins;


   --------------------------------------------------------------------------------
   -- Name:        upd
   --
   -- Description: API update procedure
   --
   -- Parameters:  cg$rec  Record of row to be updated
   --              cg$ind  Record of columns specifically set
   --              do_upd  Whether we want the actual UPDATE to occur
   --------------------------------------------------------------------------------
   PROCEDURE upd(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_upd IN BOOLEAN DEFAULT TRUE
                ,cg$pk  IN cg$row_type DEFAULT NULL) IS
      cg$upd_rec cg$row_type;
      cg$old_rec cg$row_type;
   BEGIN
      nit_positions_p.pre_dml(cg$rec
                             ,cg$ind
                             ,'UPD');
      nit_positions_p.pre_upd(cg$rec
                             ,cg$ind);

      IF (cg$pk.id IS NULL) THEN
         cg$upd_rec.id := cg$rec.id;
      ELSE
         cg$upd_rec.id := cg$pk.id;
      END IF;
      cg$old_rec.id := cg$upd_rec.id;

      IF (cg$pk.the_rowid IS NULL) THEN
         cg$upd_rec.the_rowid := cg$rec.the_rowid;
      ELSE
         cg$upd_rec.the_rowid := cg$pk.the_rowid;
      END IF;
      cg$old_rec.the_rowid := cg$upd_rec.the_rowid;

      IF (do_upd) THEN

         slct(cg$upd_rec);

         --  Report error if attempt to update non transferable Foreign Key NIT_CFK_PSN_OPN
         IF (cg$ind.opn_id AND cg$rec.opn_id != cg$upd_rec.opn_id) THEN
            raise_fk_not_transferable('NIT_CFK_PSN_OPN');
         END IF;
         IF (cg$ind.opn_id AND cg$rec.opn_id IS NULL AND
            cg$upd_rec.opn_id IS NOT NULL) THEN
            raise_fk_not_transferable('NIT_CFK_PSN_OPN');
         END IF;
         IF (cg$ind.opn_id AND cg$rec.opn_id IS NOT NULL AND
            cg$upd_rec.opn_id IS NULL) THEN
            raise_fk_not_transferable('NIT_CFK_PSN_OPN');
         END IF;

         --  Report error if attempt to update non updateable Primary Key NIT_CPK_PSN
         IF (cg$ind.id AND cg$rec.id != cg$upd_rec.id) THEN
            raise_uk_not_updateable('NIT_CPK_PSN');
         END IF;
         IF NOT (cg$ind.id) THEN
            cg$rec.id := cg$upd_rec.id;
         END IF;
         IF NOT (cg$ind.creation_date) THEN
            cg$rec.creation_date := cg$upd_rec.creation_date;
         END IF;
         IF NOT (cg$ind.created_by) THEN
            cg$rec.created_by := cg$upd_rec.created_by;
         END IF;
         IF NOT (cg$ind.last_update_date) THEN
            cg$rec.last_update_date := cg$upd_rec.last_update_date;
         END IF;
         IF NOT (cg$ind.last_updated_by) THEN
            cg$rec.last_updated_by := cg$upd_rec.last_updated_by;
         END IF;
         IF NOT (cg$ind.ci_id) THEN
            cg$rec.ci_id := cg$upd_rec.ci_id;
         END IF;
         IF NOT (cg$ind.lcn_id) THEN
            cg$rec.lcn_id := cg$upd_rec.lcn_id;
         END IF;
         IF NOT (cg$ind.opn_id) THEN
            cg$rec.opn_id := cg$upd_rec.opn_id;
         END IF;
         IF NOT (cg$ind.status) THEN
            cg$rec.status := cg$upd_rec.status;
         END IF;
         IF NOT (cg$ind.obsolete) THEN
            cg$rec.obsolete := cg$upd_rec.obsolete;
         END IF;
         IF NOT (cg$ind.valid_from) THEN
            cg$rec.valid_from := cg$upd_rec.valid_from;
         END IF;
         IF NOT (cg$ind.valid_until) THEN
            cg$rec.valid_until := cg$upd_rec.valid_until;
         END IF;
         IF NOT (cg$ind.comments) THEN
            cg$rec.comments := cg$upd_rec.comments;
         END IF;
      ELSE
         --  Report error if attempt to update non transferable Foreign Key NIT_CFK_PSN_OPN
         IF (cg$ind.opn_id) THEN
            raise_fk_not_transferable('NIT_CFK_PSN_OPN');
         END IF;
         --  Report error if attempt to update non updateable Primary Key NIT_CPK_PSN
         IF (cg$ind.id) THEN
            raise_uk_not_updateable('NIT_CPK_PSN');
         END IF;
      END IF;

      up_autogen_columns(cg$rec
                        ,cg$ind
                        ,'UPD'
                        ,do_upd); --  Auto-generated and uppercased columns

      --  Now do update if updateable columns exist
      IF (do_upd) THEN
         DECLARE
            called_from BOOLEAN := called_from_package;
         BEGIN
            called_from_package := TRUE;

            slct(cg$old_rec);
            validate_domain(cg$rec
                           ,cg$ind);

            IF cg$rec.the_rowid IS NULL THEN
               UPDATE nit_positions
               SET    creation_date    = cg$rec.creation_date
                     ,created_by       = cg$rec.created_by
                     ,last_update_date = cg$rec.last_update_date
                     ,last_updated_by  = cg$rec.last_updated_by
                     ,ci_id            = cg$rec.ci_id
                     ,lcn_id           = cg$rec.lcn_id
                     ,opn_id           = cg$rec.opn_id
                     ,status           = cg$rec.status
                     ,obsolete         = cg$rec.obsolete
                     ,valid_from       = cg$rec.valid_from
                     ,valid_until      = cg$rec.valid_until
                     ,comments         = cg$rec.comments
               WHERE  id = cg$rec.id RETURNING id, creation_date, created_by,
                last_update_date, last_updated_by, ci_id, lcn_id, opn_id,
                status, obsolete, valid_from, valid_until, comments,
                ROWID INTO cg$rec.id, cg$rec.creation_date,
                cg$rec.created_by, cg$rec.last_update_date,
                cg$rec.last_updated_by, cg$rec.ci_id, cg$rec.lcn_id,
                cg$rec.opn_id, cg$rec.status, cg$rec.obsolete,
                cg$rec.valid_from, cg$rec.valid_until, cg$rec.comments,
                cg$rec.the_rowid;
            ELSE
               UPDATE nit_positions
               SET    creation_date    = cg$rec.creation_date
                     ,created_by       = cg$rec.created_by
                     ,last_update_date = cg$rec.last_update_date
                     ,last_updated_by  = cg$rec.last_updated_by
                     ,ci_id            = cg$rec.ci_id
                     ,lcn_id           = cg$rec.lcn_id
                     ,opn_id           = cg$rec.opn_id
                     ,status           = cg$rec.status
                     ,obsolete         = cg$rec.obsolete
                     ,valid_from       = cg$rec.valid_from
                     ,valid_until      = cg$rec.valid_until
                     ,comments         = cg$rec.comments
               WHERE  ROWID = cg$rec.the_rowid RETURNING id, creation_date,
                created_by, last_update_date, last_updated_by, ci_id,
                lcn_id, opn_id, status, obsolete, valid_from, valid_until,
                comments, ROWID INTO cg$rec.id, cg$rec.creation_date,
                cg$rec.created_by, cg$rec.last_update_date,
                cg$rec.last_updated_by, cg$rec.ci_id, cg$rec.lcn_id,
                cg$rec.opn_id, cg$rec.status, cg$rec.obsolete,
                cg$rec.valid_from, cg$rec.valid_until, cg$rec.comments,
                cg$rec.the_rowid;
            END IF;

            called_from_package := called_from;
         END;
      END IF;



      IF NOT (do_upd) THEN
         cg$table(idx).id := cg$rec.id;
         cg$tableind(idx).id := cg$ind.id;
         cg$table(idx).creation_date := cg$rec.creation_date;
         cg$tableind(idx).creation_date := cg$ind.creation_date;
         cg$table(idx).created_by := cg$rec.created_by;
         cg$tableind(idx).created_by := cg$ind.created_by;
         cg$table(idx).last_update_date := cg$rec.last_update_date;
         cg$tableind(idx).last_update_date := cg$ind.last_update_date;
         cg$table(idx).last_updated_by := cg$rec.last_updated_by;
         cg$tableind(idx).last_updated_by := cg$ind.last_updated_by;
         cg$table(idx).ci_id := cg$rec.ci_id;
         cg$tableind(idx).ci_id := cg$ind.ci_id;
         cg$table(idx).lcn_id := cg$rec.lcn_id;
         cg$tableind(idx).lcn_id := cg$ind.lcn_id;
         cg$table(idx).opn_id := cg$rec.opn_id;
         cg$tableind(idx).opn_id := cg$ind.opn_id;
         cg$table(idx).status := cg$rec.status;
         cg$tableind(idx).status := cg$ind.status;
         cg$table(idx).obsolete := cg$rec.obsolete;
         cg$tableind(idx).obsolete := cg$ind.obsolete;
         cg$table(idx).valid_from := cg$rec.valid_from;
         cg$tableind(idx).valid_from := cg$ind.valid_from;
         cg$table(idx).valid_until := cg$rec.valid_until;
         cg$tableind(idx).valid_until := cg$ind.valid_until;
         cg$table(idx).comments := cg$rec.comments;
         cg$tableind(idx).comments := cg$ind.comments;
         idx := idx + 1;
      END IF;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.upd_mandatory_null THEN
         validate_mandatory(cg$rec
                           ,'cg$NIT_POSITIONS.upd.upd_mandatory_null');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.check_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_check_con
                ,'cg$NIT_POSITIONS.upd.check_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.fk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_foreign_key
                ,'cg$NIT_POSITIONS.upd.fk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.uk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_unique_key
                ,'cg$NIT_POSITIONS.upd.uk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_POSITIONS.upd.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END upd;

   --------------------------------------------------------------------------------
   -- Name:        del
   --
   -- Description: API delete procedure
   --
   -- Parameters:  cg$pk  Primary key record of row to be deleted
   --------------------------------------------------------------------------------
   PROCEDURE del(cg$pk  IN cg$pk_type
                ,do_del IN BOOLEAN DEFAULT TRUE) IS
   BEGIN
      --  Application_logic Pre-Delete <<Start>>
      BEGIN
         raise_application_error(-20001
                                ,'Deletions are not allowed such way.');
      END;
      --  Application_logic Pre-Delete << End >>

      --  Delete the record

      called_from_package := TRUE;

      IF (do_del) THEN

         IF cg$pk.the_rowid IS NULL THEN
            DELETE nit_positions
            WHERE  id = cg$pk.id;
         ELSE
            DELETE nit_positions
            WHERE  ROWID = cg$pk.the_rowid;
         END IF;

      END IF;

      called_from_package := FALSE;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.delete_restrict THEN
         err_msg(SQLERRM
                ,cg$errors.err_delete_restrict
                ,'cg$NIT_POSITIONS.del.delete_restrict');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN no_data_found THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_row_del
                                            ,cg$errors.row_del)
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_POSITIONS.del.no_data_found');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_POSITIONS.del.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END del;


   --------------------------------------------------------------------------------
   -- Name:        lck
   --
   -- Description: API lock procedure
   --
   -- Parameters:  cg$old_rec  Calling apps view of record of row to be locked
   --              cg$old_ind  Record of columns to raise error if modified
   --              nowait_flag TRUE lock with NOWAIT, FALSE don't fail if busy
   --------------------------------------------------------------------------------
   PROCEDURE lck(cg$old_rec  IN cg$row_type
                ,cg$old_ind  IN cg$ind_type
                ,nowait_flag IN BOOLEAN DEFAULT TRUE) IS
      cg$tmp_rec   cg$row_type;
      any_modified BOOLEAN := FALSE;

   BEGIN

      --  Do the row lock
      BEGIN
         IF (nowait_flag) THEN
            IF cg$old_rec.the_rowid IS NULL THEN
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,ci_id
                     ,lcn_id
                     ,opn_id
                     ,status
                     ,obsolete
                     ,valid_from
                     ,valid_until
                     ,comments
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.ci_id
                     ,cg$tmp_rec.lcn_id
                     ,cg$tmp_rec.opn_id
                     ,cg$tmp_rec.status
                     ,cg$tmp_rec.obsolete
                     ,cg$tmp_rec.valid_from
                     ,cg$tmp_rec.valid_until
                     ,cg$tmp_rec.comments
               FROM   nit_positions
               WHERE  id = cg$old_rec.id
               FOR    UPDATE NOWAIT;
            ELSE
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,ci_id
                     ,lcn_id
                     ,opn_id
                     ,status
                     ,obsolete
                     ,valid_from
                     ,valid_until
                     ,comments
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.ci_id
                     ,cg$tmp_rec.lcn_id
                     ,cg$tmp_rec.opn_id
                     ,cg$tmp_rec.status
                     ,cg$tmp_rec.obsolete
                     ,cg$tmp_rec.valid_from
                     ,cg$tmp_rec.valid_until
                     ,cg$tmp_rec.comments
               FROM   nit_positions
               WHERE  ROWID = cg$old_rec.the_rowid
               FOR    UPDATE NOWAIT;
            END IF;
         ELSE
            IF cg$old_rec.the_rowid IS NULL THEN
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,ci_id
                     ,lcn_id
                     ,opn_id
                     ,status
                     ,obsolete
                     ,valid_from
                     ,valid_until
                     ,comments
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.ci_id
                     ,cg$tmp_rec.lcn_id
                     ,cg$tmp_rec.opn_id
                     ,cg$tmp_rec.status
                     ,cg$tmp_rec.obsolete
                     ,cg$tmp_rec.valid_from
                     ,cg$tmp_rec.valid_until
                     ,cg$tmp_rec.comments
               FROM   nit_positions
               WHERE  id = cg$old_rec.id
               FOR    UPDATE;
            ELSE
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,ci_id
                     ,lcn_id
                     ,opn_id
                     ,status
                     ,obsolete
                     ,valid_from
                     ,valid_until
                     ,comments
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.ci_id
                     ,cg$tmp_rec.lcn_id
                     ,cg$tmp_rec.opn_id
                     ,cg$tmp_rec.status
                     ,cg$tmp_rec.obsolete
                     ,cg$tmp_rec.valid_from
                     ,cg$tmp_rec.valid_until
                     ,cg$tmp_rec.comments
               FROM   nit_positions
               WHERE  ROWID = cg$old_rec.the_rowid
               FOR    UPDATE;
            END IF;
         END IF;

      EXCEPTION
         WHEN cg$errors.cg$error THEN
            cg$errors.raise_failure;
         WHEN cg$errors.resource_busy THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_lck
                                               ,cg$errors.row_lck)
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_POSITIONS.lck.resource_busy');
            cg$errors.raise_failure;
         WHEN no_data_found THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_del
                                               ,cg$errors.row_del)
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_POSITIONS.lck.no_data_found');
            cg$errors.raise_failure;
         WHEN OTHERS THEN
            cg$errors.push(SQLERRM
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_POSITIONS.lck.others');
            cg$errors.raise_failure;
      END;

      -- Optional Columns

      IF (cg$old_ind.comments) THEN
         IF (cg$tmp_rec.comments IS NOT NULL AND
            cg$old_rec.comments IS NOT NULL) THEN
            IF (cg$tmp_rec.comments != cg$old_rec.comments) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p110comments)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_POSITIONS.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.comments IS NOT NULL OR
               cg$old_rec.comments IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p110comments)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_POSITIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;

      -- Mandatory Columns

      IF (cg$old_ind.id) THEN
         IF (cg$tmp_rec.id != cg$old_rec.id) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p10id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_POSITIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.creation_date) THEN
         IF (cg$tmp_rec.creation_date != cg$old_rec.creation_date) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p15creation_date)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_POSITIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.created_by) THEN
         IF (cg$tmp_rec.created_by != cg$old_rec.created_by) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p16created_by)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_POSITIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.last_update_date) THEN
         IF (cg$tmp_rec.last_update_date != cg$old_rec.last_update_date) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p19last_update_date)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_POSITIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.last_updated_by) THEN
         IF (cg$tmp_rec.last_updated_by != cg$old_rec.last_updated_by) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p24last_updated_by)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_POSITIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.ci_id) THEN
         IF (cg$tmp_rec.ci_id != cg$old_rec.ci_id) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p26ci_id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_POSITIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.lcn_id) THEN
         IF (cg$tmp_rec.lcn_id != cg$old_rec.lcn_id) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p34lcn_id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_POSITIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.opn_id) THEN
         IF (cg$tmp_rec.opn_id != cg$old_rec.opn_id) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p50opn_id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_POSITIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.status) THEN
         IF (cg$tmp_rec.status != cg$old_rec.status) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p60status)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_POSITIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.obsolete) THEN
         IF (cg$tmp_rec.obsolete != cg$old_rec.obsolete) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p80obsolete)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_POSITIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.valid_from) THEN
         IF (cg$tmp_rec.valid_from != cg$old_rec.valid_from) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p90valid_from)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_POSITIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.valid_until) THEN
         IF (cg$tmp_rec.valid_until != cg$old_rec.valid_until) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p100valid_until)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_POSITIONS.lck');
            any_modified := TRUE;
         END IF;
      END IF;

      IF (any_modified) THEN
         cg$errors.raise_failure;
      END IF;

   END lck;


BEGIN
   cg$ind_true.id               := TRUE;
   cg$ind_true.creation_date    := TRUE;
   cg$ind_true.created_by       := TRUE;
   cg$ind_true.last_update_date := TRUE;
   cg$ind_true.last_updated_by  := TRUE;
   cg$ind_true.ci_id            := TRUE;
   cg$ind_true.lcn_id           := TRUE;
   cg$ind_true.opn_id           := TRUE;
   cg$ind_true.status           := TRUE;
   cg$ind_true.obsolete         := TRUE;
   cg$ind_true.valid_from       := TRUE;
   cg$ind_true.valid_until      := TRUE;
   cg$ind_true.comments         := TRUE;


END cg$nit_positions;
/

prompt
prompt Creating package body CG$NIT_USERS
prompt ==================================
prompt
CREATE OR REPLACE PACKAGE BODY cg$nit_users IS


   PROCEDURE validate_mandatory(cg$val_rec IN cg$row_type
                               ,loc        IN VARCHAR2 DEFAULT '');
   PROCEDURE up_autogen_columns(cg$rec    IN OUT cg$row_type
                               ,cg$ind    IN OUT cg$ind_type
                               ,operation IN VARCHAR2 DEFAULT 'INS'
                               ,do_denorm IN BOOLEAN DEFAULT TRUE);
   PROCEDURE err_msg(msg  IN VARCHAR2
                    ,TYPE IN INTEGER
                    ,loc  IN VARCHAR2 DEFAULT '');

   --------------------------------------------------------------------------------
   -- Name:        raise_uk_not_updateable
   --
   -- Description: Raise appropriate error when unique key updated
   --
   -- Parameters:  none
   --------------------------------------------------------------------------------
   PROCEDURE raise_uk_not_updateable(uk IN VARCHAR2) IS
   BEGIN
      cg$errors.push(cg$errors.msggettext(cg$errors.api_unique_key_update
                                         ,cg$errors.err_uk_update
                                         ,uk)
                    ,'E'
                    ,'API'
                    ,cg$errors.api_unique_key_update
                    ,'cg$NIT_USERS.raise_uk_not_updateable');
      cg$errors.raise_failure;
   END raise_uk_not_updateable;


   --------------------------------------------------------------------------------
   -- Name:        raise_fk_not_transferable
   --
   -- Description: Raise appropriate error when foreign key updated
   --
   -- Parameters:  none
   --------------------------------------------------------------------------------
   PROCEDURE raise_fk_not_transferable(fk IN VARCHAR2) IS
   BEGIN
      cg$errors.push(cg$errors.msggettext(cg$errors.api_foreign_key_trans
                                         ,cg$errors.err_fk_trans
                                         ,fk)
                    ,'E'
                    ,'API'
                    ,cg$errors.api_foreign_key_trans
                    ,'cg$NIT_USERS.raise_fk_not_transferable');
      cg$errors.raise_failure;
   END raise_fk_not_transferable;


   --------------------------------------------------------------------------------
   -- Name:        up_autogen_columns
   --
   -- Description: Specific autogeneration of column values and conversion to
   --              uppercase
   --
   -- Parameters:  cg$rec    Record of row to be manipulated
   --              cg$ind    Indicators for row
   --              operation Procedure where this procedure was called
   --------------------------------------------------------------------------------
   PROCEDURE up_autogen_columns(cg$rec    IN OUT cg$row_type
                               ,cg$ind    IN OUT cg$ind_type
                               ,operation IN VARCHAR2 DEFAULT 'INS'
                               ,do_denorm IN BOOLEAN DEFAULT TRUE) IS
   BEGIN
      IF (operation = 'INS') THEN
         BEGIN
            IF (cg$ind.id = FALSE OR cg$rec.id IS NULL) THEN
               SELECT nit_seq.NEXTVAL
               INTO   cg$rec.id
               FROM   dual;
               cg$ind.id := TRUE;
            END IF;
         EXCEPTION
            WHEN OTHERS THEN
               cg$errors.push(SQLERRM
                             ,'E'
                             ,'ORA'
                             ,SQLCODE
                             ,'cg$NIT_USERS.up_autogen.ID.OTHERS');
               cg$errors.raise_failure;
         END;
      ELSE
         -- (operation = 'UPD')
         NULL;
      END IF; -- (operation = 'INS') ELSE (operation = 'UPD')

      -- Statements executed for both 'INS' and 'UPD'


   EXCEPTION
      WHEN no_data_found THEN
         NULL;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_USERS.up_autogen_columns');
         cg$errors.raise_failure;
   END up_autogen_columns;


   --------------------------------------------------------------------------------
   -- Name:        validate_mandatory
   --
   -- Description: Checks all mandatory columns are not null and raises appropriate
   --              error if not satisfied
   --
   -- Parameters:  cg$val_rec Record of row to be checked
   --              loc        Place where this procedure was called for error
   --                         trapping
   --------------------------------------------------------------------------------
   PROCEDURE validate_mandatory(cg$val_rec IN cg$row_type
                               ,loc        IN VARCHAR2 DEFAULT '') IS
   BEGIN
      IF (cg$val_rec.id IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p10id)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.creation_date IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p15creation_date)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.created_by IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p16created_by)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.last_update_date IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p19last_update_date)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.last_updated_by IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p24last_updated_by)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.username IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p30username)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.email IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p50email)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      IF (cg$val_rec.LANGUAGE IS NULL) THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_mand_column_isnull
                                            ,cg$errors.val_mand
                                            ,p55language)
                       ,'E'
                       ,'API'
                       ,cg$errors.api_mand_column_isnull
                       ,loc);
      END IF;
      NULL;
   END validate_mandatory;

   --------------------------------------------------------------------------------
   -- Name:        slct
   --
   -- Description: Selects into the given parameter all the attributes for the row
   --              given by the primary key
   --
   -- Parameters:  cg$sel_rec  Record of row to be selected into using its PK
   --------------------------------------------------------------------------------
   PROCEDURE slct(cg$sel_rec IN OUT cg$row_type) IS

   BEGIN

      IF cg$sel_rec.the_rowid IS NULL THEN
         SELECT id
               ,creation_date
               ,created_by
               ,last_update_date
               ,last_updated_by
               ,username
               ,realname
               ,email
               ,LANGUAGE
               ,comments
               ,role
               ,ROWID
         INTO   cg$sel_rec.id
               ,cg$sel_rec.creation_date
               ,cg$sel_rec.created_by
               ,cg$sel_rec.last_update_date
               ,cg$sel_rec.last_updated_by
               ,cg$sel_rec.username
               ,cg$sel_rec.realname
               ,cg$sel_rec.email
               ,cg$sel_rec.LANGUAGE
               ,cg$sel_rec.comments
               ,cg$sel_rec.role
               ,cg$sel_rec.the_rowid
         FROM   nit_users
         WHERE  id = cg$sel_rec.id;
      ELSE
         SELECT id
               ,creation_date
               ,created_by
               ,last_update_date
               ,last_updated_by
               ,username
               ,realname
               ,email
               ,LANGUAGE
               ,comments
               ,role
               ,ROWID
         INTO   cg$sel_rec.id
               ,cg$sel_rec.creation_date
               ,cg$sel_rec.created_by
               ,cg$sel_rec.last_update_date
               ,cg$sel_rec.last_updated_by
               ,cg$sel_rec.username
               ,cg$sel_rec.realname
               ,cg$sel_rec.email
               ,cg$sel_rec.LANGUAGE
               ,cg$sel_rec.comments
               ,cg$sel_rec.role
               ,cg$sel_rec.the_rowid
         FROM   nit_users
         WHERE  ROWID = cg$sel_rec.the_rowid;
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_USERS.slct.others');
         cg$errors.raise_failure;

   END slct;

   --------------------------------------------------------------------------------
   -- Name:        err_msg
   --
   -- Description: Pushes onto stack appropriate user defined error message
   --              depending on the rule violated
   --
   -- Parameters:  msg     Oracle error message
   --              type    Type of violation e.g. check_constraint: ERR_CHECK_CON
   --              loc     Place where this procedure was called for error
   --                      trapping
   --------------------------------------------------------------------------------
   PROCEDURE err_msg(msg  IN VARCHAR2
                    ,TYPE IN INTEGER
                    ,loc  IN VARCHAR2 DEFAULT '') IS
      con_name VARCHAR2(240);
   BEGIN
      con_name := cg$errors.parse_constraint(msg
                                            ,TYPE);
      IF (con_name = 'NIT_CPK_USR') THEN
         cg$errors.push(NVL(nit_cpk_usr
                           ,cg$errors.msggettext(cg$errors.api_pk_con_violated
                                                ,cg$errors.apimsg_pk_violat
                                                ,'NIT_CPK_USR'
                                                ,'NIT_USERS'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_pk_con_violated
                       ,loc);
      ELSIF (con_name = 'NIT_CUK_USR') THEN
         cg$errors.push(NVL(nit_cuk_usr
                           ,cg$errors.msggettext(cg$errors.api_uq_con_violated
                                                ,cg$errors.apimsg_uk_violat
                                                ,'NIT_CUK_USR'
                                                ,'NIT_USERS'))
                       ,'E'
                       ,'API'
                       ,cg$errors.api_uq_con_violated
                       ,loc);

      ELSE
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,loc);
      END IF;
   END err_msg;


   --------------------------------------------------------------------------------
   -- Name:        ins
   --
   -- Description: API insert procedure
   --
   -- Parameters:  cg$rec  Record of row to be inserted
   --              cg$ind  Record of columns specifically set
   --              do_ins  Whether we want the actual INSERT to occur
   --------------------------------------------------------------------------------
   PROCEDURE ins(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_ins IN BOOLEAN DEFAULT TRUE) IS

      --  Constant default values

      d55_language CONSTANT nit_users.LANGUAGE%TYPE := 'US';

   BEGIN
      nit_users_p.pre_dml(cg$rec
                         ,cg$ind
                         ,'INS');

      --  Defaulted

      IF NOT (cg$ind.LANGUAGE) THEN
         cg$rec.LANGUAGE := d55_language;
      END IF;
      --  Auto-generated and uppercased columns

      up_autogen_columns(cg$rec
                        ,cg$ind
                        ,'INS'
                        ,do_ins);

      called_from_package := TRUE;

      IF (do_ins) THEN

         INSERT INTO nit_users
            (id
            ,creation_date
            ,created_by
            ,last_update_date
            ,last_updated_by
            ,username
            ,realname
            ,email
            ,LANGUAGE
            ,comments
            ,role)
         VALUES
            (cg$rec.id
            ,cg$rec.creation_date
            ,cg$rec.created_by
            ,cg$rec.last_update_date
            ,cg$rec.last_updated_by
            ,cg$rec.username
            ,cg$rec.realname
            ,cg$rec.email
            ,cg$rec.LANGUAGE
            ,cg$rec.comments
            ,cg$rec.role)
         RETURNING id, creation_date, created_by, last_update_date, last_updated_by, username, realname, email, LANGUAGE, comments, role, ROWID INTO cg$rec.id, cg$rec.creation_date, cg$rec.created_by, cg$rec.last_update_date, cg$rec.last_updated_by, cg$rec.username, cg$rec.realname, cg$rec.email, cg$rec.LANGUAGE, cg$rec.comments, cg$rec.role, cg$rec.the_rowid;

      END IF;

      called_from_package := FALSE;

      nit_users_p.post_ins(cg$rec
                          ,cg$ind);

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.mandatory_missing THEN
         validate_mandatory(cg$rec
                           ,'cg$NIT_USERS.ins.mandatory_missing');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.check_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_check_con
                ,'cg$NIT_USERS.ins.check_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.fk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_foreign_key
                ,'cg$NIT_USERS.ins.fk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.uk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_unique_key
                ,'cg$NIT_USERS.ins.uk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_USERS.ins.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END ins;


   --------------------------------------------------------------------------------
   -- Name:        upd
   --
   -- Description: API update procedure
   --
   -- Parameters:  cg$rec  Record of row to be updated
   --              cg$ind  Record of columns specifically set
   --              do_upd  Whether we want the actual UPDATE to occur
   --------------------------------------------------------------------------------
   PROCEDURE upd(cg$rec IN OUT cg$row_type
                ,cg$ind IN OUT cg$ind_type
                ,do_upd IN BOOLEAN DEFAULT TRUE
                ,cg$pk  IN cg$row_type DEFAULT NULL) IS
      cg$upd_rec cg$row_type;
      cg$old_rec cg$row_type;
   BEGIN
      nit_users_p.pre_dml(cg$rec
                         ,cg$ind
                         ,'INS');

      IF (cg$pk.id IS NULL) THEN
         cg$upd_rec.id := cg$rec.id;
      ELSE
         cg$upd_rec.id := cg$pk.id;
      END IF;
      cg$old_rec.id := cg$upd_rec.id;

      IF (cg$pk.the_rowid IS NULL) THEN
         cg$upd_rec.the_rowid := cg$rec.the_rowid;
      ELSE
         cg$upd_rec.the_rowid := cg$pk.the_rowid;
      END IF;
      cg$old_rec.the_rowid := cg$upd_rec.the_rowid;

      IF (do_upd) THEN

         slct(cg$upd_rec);


         --  Report error if attempt to update non updateable Primary Key NIT_CPK_USR
         IF (cg$ind.id AND cg$rec.id != cg$upd_rec.id) THEN
            raise_uk_not_updateable('NIT_CPK_USR');
         END IF;
         IF NOT (cg$ind.id) THEN
            cg$rec.id := cg$upd_rec.id;
         END IF;
         IF NOT (cg$ind.creation_date) THEN
            cg$rec.creation_date := cg$upd_rec.creation_date;
         END IF;
         IF NOT (cg$ind.created_by) THEN
            cg$rec.created_by := cg$upd_rec.created_by;
         END IF;
         IF NOT (cg$ind.last_update_date) THEN
            cg$rec.last_update_date := cg$upd_rec.last_update_date;
         END IF;
         IF NOT (cg$ind.last_updated_by) THEN
            cg$rec.last_updated_by := cg$upd_rec.last_updated_by;
         END IF;
         IF NOT (cg$ind.username) THEN
            cg$rec.username := cg$upd_rec.username;
         END IF;
         IF NOT (cg$ind.realname) THEN
            cg$rec.realname := cg$upd_rec.realname;
         END IF;
         IF NOT (cg$ind.email) THEN
            cg$rec.email := cg$upd_rec.email;
         END IF;
         IF NOT (cg$ind.LANGUAGE) THEN
            cg$rec.LANGUAGE := cg$upd_rec.LANGUAGE;
         END IF;
         IF NOT (cg$ind.comments) THEN
            cg$rec.comments := cg$upd_rec.comments;
         END IF;
         IF NOT (cg$ind.role) THEN
            cg$rec.role := cg$upd_rec.role;
         END IF;
      ELSE
         --  Report error if attempt to update non updateable Primary Key NIT_CPK_USR
         IF (cg$ind.id) THEN
            raise_uk_not_updateable('NIT_CPK_USR');
         END IF;
      END IF;

      up_autogen_columns(cg$rec
                        ,cg$ind
                        ,'UPD'
                        ,do_upd); --  Auto-generated and uppercased columns

      --  Now do update if updateable columns exist
      IF (do_upd) THEN
         DECLARE
            called_from BOOLEAN := called_from_package;
         BEGIN
            called_from_package := TRUE;

            slct(cg$old_rec);

            IF cg$rec.the_rowid IS NULL THEN
               UPDATE nit_users
               SET    creation_date    = cg$rec.creation_date
                     ,created_by       = cg$rec.created_by
                     ,last_update_date = cg$rec.last_update_date
                     ,last_updated_by  = cg$rec.last_updated_by
                     ,username         = cg$rec.username
                     ,realname         = cg$rec.realname
                     ,email            = cg$rec.email
                     ,LANGUAGE         = cg$rec.LANGUAGE
                     ,comments         = cg$rec.comments
                     ,role             = cg$rec.role
               WHERE  id = cg$rec.id RETURNING id, creation_date, created_by,
                last_update_date, last_updated_by, username, realname,
                email, LANGUAGE, comments, role, ROWID INTO cg$rec.id,
                cg$rec.creation_date, cg$rec.created_by,
                cg$rec.last_update_date, cg$rec.last_updated_by,
                cg$rec.username, cg$rec.realname, cg$rec.email,
                cg$rec.LANGUAGE, cg$rec.comments, cg$rec.role,
                cg$rec.the_rowid;

            ELSE
               UPDATE nit_users
               SET    creation_date    = cg$rec.creation_date
                     ,created_by       = cg$rec.created_by
                     ,last_update_date = cg$rec.last_update_date
                     ,last_updated_by  = cg$rec.last_updated_by
                     ,username         = cg$rec.username
                     ,realname         = cg$rec.realname
                     ,email            = cg$rec.email
                     ,LANGUAGE         = cg$rec.LANGUAGE
                     ,comments         = cg$rec.comments
                     ,role             = cg$rec.role
               WHERE  ROWID = cg$rec.the_rowid RETURNING id, creation_date,
                created_by, last_update_date, last_updated_by, username,
                realname, email, LANGUAGE, comments, role, ROWID INTO
                cg$rec.id, cg$rec.creation_date, cg$rec.created_by,
                cg$rec.last_update_date, cg$rec.last_updated_by,
                cg$rec.username, cg$rec.realname, cg$rec.email,
                cg$rec.LANGUAGE, cg$rec.comments, cg$rec.role,
                cg$rec.the_rowid;

            END IF;
            called_from_package := called_from;
         END;
      END IF;



      IF NOT (do_upd) THEN
         cg$table(idx).id := cg$rec.id;
         cg$tableind(idx).id := cg$ind.id;
         cg$table(idx).creation_date := cg$rec.creation_date;
         cg$tableind(idx).creation_date := cg$ind.creation_date;
         cg$table(idx).created_by := cg$rec.created_by;
         cg$tableind(idx).created_by := cg$ind.created_by;
         cg$table(idx).last_update_date := cg$rec.last_update_date;
         cg$tableind(idx).last_update_date := cg$ind.last_update_date;
         cg$table(idx).last_updated_by := cg$rec.last_updated_by;
         cg$tableind(idx).last_updated_by := cg$ind.last_updated_by;
         cg$table(idx).username := cg$rec.username;
         cg$tableind(idx).username := cg$ind.username;
         cg$table(idx).realname := cg$rec.realname;
         cg$tableind(idx).realname := cg$ind.realname;
         cg$table(idx).email := cg$rec.email;
         cg$tableind(idx).email := cg$ind.email;
         cg$table(idx).LANGUAGE := cg$rec.LANGUAGE;
         cg$tableind(idx).LANGUAGE := cg$ind.LANGUAGE;
         cg$table(idx).comments := cg$rec.comments;
         cg$tableind(idx).comments := cg$ind.comments;
         cg$table(idx).role := cg$rec.role;
         cg$tableind(idx).role := cg$ind.role;
         idx := idx + 1;
      END IF;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.upd_mandatory_null THEN
         validate_mandatory(cg$rec
                           ,'cg$NIT_USERS.upd.upd_mandatory_null');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.check_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_check_con
                ,'cg$NIT_USERS.upd.check_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.fk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_foreign_key
                ,'cg$NIT_USERS.upd.fk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.uk_violation THEN
         err_msg(SQLERRM
                ,cg$errors.err_unique_key
                ,'cg$NIT_USERS.upd.uk_violation');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_USERS.upd.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END upd;

   --------------------------------------------------------------------------------
   -- Name:        del
   --
   -- Description: API delete procedure
   --
   -- Parameters:  cg$pk  Primary key record of row to be deleted
   --------------------------------------------------------------------------------
   PROCEDURE del(cg$pk  IN cg$pk_type
                ,do_del IN BOOLEAN DEFAULT TRUE) IS
   BEGIN
      nit_users_p.pre_del(cg$pk.id);

      --  Delete the record

      called_from_package := TRUE;

      IF (do_del) THEN
         IF cg$pk.the_rowid IS NULL THEN
            DELETE nit_users
            WHERE  id = cg$pk.id;
         ELSE
            DELETE nit_users
            WHERE  ROWID = cg$pk.the_rowid;
         END IF;
      END IF;

      called_from_package := FALSE;

   EXCEPTION
      WHEN cg$errors.cg$error THEN
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN cg$errors.delete_restrict THEN
         err_msg(SQLERRM
                ,cg$errors.err_delete_restrict
                ,'cg$NIT_USERS.del.delete_restrict');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN no_data_found THEN
         cg$errors.push(cg$errors.msggettext(cg$errors.api_row_del
                                            ,cg$errors.row_del)
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_USERS.del.no_data_found');
         called_from_package := FALSE;
         cg$errors.raise_failure;
      WHEN OTHERS THEN
         cg$errors.push(SQLERRM
                       ,'E'
                       ,'ORA'
                       ,SQLCODE
                       ,'cg$NIT_USERS.del.others');
         called_from_package := FALSE;
         cg$errors.raise_failure;
   END del;


   --------------------------------------------------------------------------------
   -- Name:        lck
   --
   -- Description: API lock procedure
   --
   -- Parameters:  cg$old_rec  Calling apps view of record of row to be locked
   --              cg$old_ind  Record of columns to raise error if modified
   --              nowait_flag TRUE lock with NOWAIT, FALSE don't fail if busy
   --------------------------------------------------------------------------------
   PROCEDURE lck(cg$old_rec  IN cg$row_type
                ,cg$old_ind  IN cg$ind_type
                ,nowait_flag IN BOOLEAN DEFAULT TRUE) IS
      cg$tmp_rec   cg$row_type;
      any_modified BOOLEAN := FALSE;

   BEGIN

      BEGIN
         IF (nowait_flag) THEN
            IF cg$old_rec.the_rowid IS NULL THEN
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,username
                     ,realname
                     ,email
                     ,LANGUAGE
                     ,comments
                     ,role
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.username
                     ,cg$tmp_rec.realname
                     ,cg$tmp_rec.email
                     ,cg$tmp_rec.LANGUAGE
                     ,cg$tmp_rec.comments
                     ,cg$tmp_rec.role
               FROM   nit_users
               WHERE  id = cg$old_rec.id
               FOR    UPDATE NOWAIT;
            ELSE
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,username
                     ,realname
                     ,email
                     ,LANGUAGE
                     ,comments
                     ,role
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.username
                     ,cg$tmp_rec.realname
                     ,cg$tmp_rec.email
                     ,cg$tmp_rec.LANGUAGE
                     ,cg$tmp_rec.comments
                     ,cg$tmp_rec.role
               FROM   nit_users
               WHERE  ROWID = cg$old_rec.the_rowid
               FOR    UPDATE NOWAIT;
            END IF;
         ELSE
            IF cg$old_rec.the_rowid IS NULL THEN
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,username
                     ,realname
                     ,email
                     ,LANGUAGE
                     ,comments
                     ,role
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.username
                     ,cg$tmp_rec.realname
                     ,cg$tmp_rec.email
                     ,cg$tmp_rec.LANGUAGE
                     ,cg$tmp_rec.comments
                     ,cg$tmp_rec.role
               FROM   nit_users
               WHERE  id = cg$old_rec.id
               FOR    UPDATE;
            ELSE
               SELECT id
                     ,creation_date
                     ,created_by
                     ,last_update_date
                     ,last_updated_by
                     ,username
                     ,realname
                     ,email
                     ,LANGUAGE
                     ,comments
                     ,role
               INTO   cg$tmp_rec.id
                     ,cg$tmp_rec.creation_date
                     ,cg$tmp_rec.created_by
                     ,cg$tmp_rec.last_update_date
                     ,cg$tmp_rec.last_updated_by
                     ,cg$tmp_rec.username
                     ,cg$tmp_rec.realname
                     ,cg$tmp_rec.email
                     ,cg$tmp_rec.LANGUAGE
                     ,cg$tmp_rec.comments
                     ,cg$tmp_rec.role
               FROM   nit_users
               WHERE  ROWID = cg$old_rec.the_rowid
               FOR    UPDATE;
            END IF;
         END IF;

      EXCEPTION
         WHEN cg$errors.cg$error THEN
            cg$errors.raise_failure;
         WHEN cg$errors.resource_busy THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_lck
                                               ,cg$errors.row_lck)
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_USERS.lck.resource_busy');
            cg$errors.raise_failure;
         WHEN no_data_found THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_del
                                               ,cg$errors.row_del)
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_USERS.lck.no_data_found');
            cg$errors.raise_failure;
         WHEN OTHERS THEN
            cg$errors.push(SQLERRM
                          ,'E'
                          ,'ORA'
                          ,SQLCODE
                          ,'cg$NIT_USERS.lck.others');
            cg$errors.raise_failure;
      END;

      -- Optional Columns

      IF (cg$old_ind.realname) THEN
         IF (cg$tmp_rec.realname IS NOT NULL AND
            cg$old_rec.realname IS NOT NULL) THEN
            IF (cg$tmp_rec.realname != cg$old_rec.realname) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p40realname)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_USERS.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.realname IS NOT NULL OR
               cg$old_rec.realname IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p40realname)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_USERS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.comments) THEN
         IF (cg$tmp_rec.comments IS NOT NULL AND
            cg$old_rec.comments IS NOT NULL) THEN
            IF (cg$tmp_rec.comments != cg$old_rec.comments) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p60comments)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_USERS.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.comments IS NOT NULL OR
               cg$old_rec.comments IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p60comments)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_USERS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.role) THEN
         IF (cg$tmp_rec.role IS NOT NULL AND cg$old_rec.role IS NOT NULL) THEN
            IF (cg$tmp_rec.role != cg$old_rec.role) THEN
               cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                                  ,cg$errors.row_mod
                                                  ,p70role)
                             ,'E'
                             ,'API'
                             ,cg$errors.api_modified
                             ,'cg$NIT_USERS.lck');
               any_modified := TRUE;
            END IF;
         ELSIF (cg$tmp_rec.role IS NOT NULL OR cg$old_rec.role IS NOT NULL) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p70role)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_USERS.lck');
            any_modified := TRUE;
         END IF;
      END IF;

      -- Mandatory Columns

      IF (cg$old_ind.id) THEN
         IF (cg$tmp_rec.id != cg$old_rec.id) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p10id)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_USERS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.creation_date) THEN
         IF (cg$tmp_rec.creation_date != cg$old_rec.creation_date) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p15creation_date)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_USERS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.created_by) THEN
         IF (cg$tmp_rec.created_by != cg$old_rec.created_by) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p16created_by)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_USERS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.last_update_date) THEN
         IF (cg$tmp_rec.last_update_date != cg$old_rec.last_update_date) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p19last_update_date)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_USERS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.last_updated_by) THEN
         IF (cg$tmp_rec.last_updated_by != cg$old_rec.last_updated_by) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p24last_updated_by)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_USERS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.username) THEN
         IF (cg$tmp_rec.username != cg$old_rec.username) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p30username)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_USERS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.email) THEN
         IF (cg$tmp_rec.email != cg$old_rec.email) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p50email)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_USERS.lck');
            any_modified := TRUE;
         END IF;
      END IF;
      IF (cg$old_ind.LANGUAGE) THEN
         IF (cg$tmp_rec.LANGUAGE != cg$old_rec.LANGUAGE) THEN
            cg$errors.push(cg$errors.msggettext(cg$errors.api_row_mod
                                               ,cg$errors.row_mod
                                               ,p55language)
                          ,'E'
                          ,'API'
                          ,cg$errors.api_modified
                          ,'cg$NIT_USERS.lck');
            any_modified := TRUE;
         END IF;
      END IF;

      IF (any_modified) THEN
         cg$errors.raise_failure;
      END IF;

   END lck;

BEGIN
   cg$ind_true.id               := TRUE;
   cg$ind_true.creation_date    := TRUE;
   cg$ind_true.created_by       := TRUE;
   cg$ind_true.last_update_date := TRUE;
   cg$ind_true.last_updated_by  := TRUE;
   cg$ind_true.username         := TRUE;
   cg$ind_true.realname         := TRUE;
   cg$ind_true.email            := TRUE;
   cg$ind_true.LANGUAGE         := TRUE;
   cg$ind_true.comments         := TRUE;
   cg$ind_true.role             := TRUE;


END cg$nit_users;
/

prompt
prompt Creating package body NIT_CARD_P
prompt ================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_card_p IS
   pl_version CONSTANT VARCHAR2(12) := '1.0.0';
   pl_module  CONSTANT VARCHAR2(30) := 'NIT_CARD_P';

   g_rs nit_card_ct;

   /*
   1.0.0 Ill?s
   */

   -----------------------------------------------------------------------

   FUNCTION package_version RETURN VARCHAR2 IS
   BEGIN
      RETURN pl_version;
   END package_version;

   -----------------------------------------------------------------------

   PROCEDURE log(p_module  VARCHAR2
                ,p_version VARCHAR2) IS
      i BINARY_INTEGER;
   BEGIN
      IF p_module IS NULL THEN
         RETURN;
      END IF;
      i := module_tab.FIRST;
      WHILE i IS NOT NULL LOOP
         IF module_tab(i) = p_module THEN
            IF (version_tab(i) IS NULL AND p_version IS NOT NULL) OR
               (version_tab(i) IS NOT NULL AND p_version IS NULL) OR
               (version_tab(i) <> p_version) THEN
               version_tab(i) := SUBSTR(p_version
                                       ,1
                                       ,g_max_version_len - 1) || '*';
            END IF;
            RETURN;
         END IF;
         i := module_tab.NEXT(i);
      END LOOP;
      i := module_tab.COUNT + 1;
      module_tab(i) := SUBSTR(p_module
                             ,1
                             ,g_max_module_len);
      version_tab(i) := SUBSTR(p_version
                              ,1
                              ,g_max_version_len);
   END log;

   -----------------------------------------------------------------------

   FUNCTION get_log RETURN VARCHAR2 IS
      l_retval VARCHAR2(2000);
      i        BINARY_INTEGER;
   BEGIN
      i := module_tab.FIRST;
      WHILE i IS NOT NULL LOOP
         IF l_retval IS NOT NULL THEN
            l_retval := l_retval || CHR(10);
         END IF;
         l_retval := SUBSTR(l_retval || module_tab(i) || ' -- ' ||
                            NVL(version_tab(i)
                               ,'{null}')
                           ,1
                           ,1999);
         i        := module_tab.NEXT(i);
      END LOOP;
      RETURN l_retval;
   END get_log;

   -----------------------------------------------------------------------

   /* Ez a funkci? adja vissza a n?zetnek a t?bla-objektumot */

   FUNCTION get_log_recordset RETURN nit_card_ct IS
      i BINARY_INTEGER;
   BEGIN

      g_rs := nit_card_ct(); /* Kezdetben ?res a t?bla */

      i := module_tab.FIRST;
      WHILE i IS NOT NULL LOOP
         g_rs.EXTEND;
         g_rs(g_rs.LAST) := nit_card_ot(RPAD(module_tab(i)
                                            ,31)
                                       ,NVL(version_tab(i)
                                           ,'{null}'));
         i := module_tab.NEXT(i);
      END LOOP;

      RETURN g_rs;

   END get_log_recordset;

-----------------------------------------------------------------------
BEGIN
   nit_card_p.log(pl_module
                 ,pl_version);
END nit_card_p;
/

prompt
prompt Creating package body NIT_CI_ATTRIBUTES_P
prompt =========================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_ci_attributes_p IS
   pl_version CONSTANT VARCHAR2(12) := '0.0.2.3';
   pl_module  CONSTANT VARCHAR2(30) := 'nit_ci_attributes_p';

   FUNCTION package_version RETURN VARCHAR2 IS
   BEGIN
      RETURN pl_module || ' ' || pl_version;
   END;

   PROCEDURE archiving(p_rec     IN OUT cg$nit_ci_attributes.cg$row_type
                      ,p_old_rec IN OUT cg$nit_ci_attributes.cg$row_type) IS
      pl_subprg_name VARCHAR2(30) := 'archiving';
      l_opn_rec      cg$nit_operations.cg$row_type;
      l_need_op_fail BOOLEAN := TRUE;
      l_need_op_stop BOOLEAN := FALSE;
      l_old_ind      cg$nit_ci_attributes.cg$ind_type;
   BEGIN
      IF (p_old_rec.obsolete <> 'L') THEN
         RETURN;
      END IF;

      <<check_op>>
      BEGIN
         l_opn_rec.id := p_rec.opn_id;
         cg$nit_operations.slct(l_opn_rec);
      EXCEPTION
         WHEN no_data_found THEN
            p_rec.opn_id   := nit_operations_p.start_inner_operation;
            l_need_op_stop := TRUE;
            l_opn_rec.id   := p_rec.opn_id;
            cg$nit_operations.slct(l_opn_rec);
         WHEN OTHERS THEN
            IF (l_need_op_fail) THEN
               nit_operations_p.fail_operation(l_opn_rec.id);
            END IF;

            nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                     ,dbms_utility.format_call_stack
                                     ,dbms_utility.format_error_stack
                                     ,'Y'
                                     ,pl_module
                                     ,pl_version
                                     ,pl_subprg_name
                                     ,'#' || p_rec.id);
            RAISE;
      END check_op;

      p_old_rec.valid_until := nit_core_p.push_back(NVL(p_rec.valid_from
                                                       ,l_opn_rec.op_time));
      p_old_rec.obsolete    := 'A';
      p_old_rec.opn_id      := p_rec.opn_id;
      p_old_rec.ci_id       := p_rec.ci_id;

      l_old_ind.obsolete := TRUE;

      p_rec.valid_from := NVL(p_rec.valid_from
                             ,l_opn_rec.op_time);

      SELECT nit_seq.NEXTVAL
      INTO   p_old_rec.id
      FROM   dual;

      cg$nit_ci_attributes.ins(p_old_rec
                              ,l_old_ind);

      IF (l_need_op_stop) THEN
         nit_operations_p.stop_operation(l_opn_rec.id);
      END IF;
   EXCEPTION
      WHEN OTHERS THEN
         IF (l_need_op_fail) THEN
            nit_operations_p.fail_operation(l_opn_rec.id);
         END IF;

         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;

   PROCEDURE pre_dml(p_rec IN OUT cg$nit_ci_attributes.cg$row_type
                    ,p_ind IN OUT cg$nit_ci_attributes.cg$ind_type
                    ,p_op  IN VARCHAR2) IS
      ci_rec          cg$nit_config_items.cg$row_type;
      cip_rec         cg$nit_ci_properties.cg$row_type;
      v_cip_id_name   nit_ci_properties.id%TYPE;
      v_cip_id_status nit_ci_properties.id%TYPE;
      v_has_attribute CHAR;
      pl_subprg_name  VARCHAR2(30) := 'pre_dml';
      CURSOR c_attribute IS
         SELECT 'X'
         FROM   nit_ci_attributes cia
         WHERE  cia.cip_id = p_rec.cip_id AND
                cia.ci_id = p_rec.ci_id;
      CURSOR c_attribute_live IS
         SELECT 'X'
         FROM   nit_ci_attributes cia
         WHERE  cia.cip_id = p_rec.cip_id AND
                cia.ci_id = p_rec.ci_id AND
                cia.obsolete = p_rec.obsolete AND
                cia.obsolete = 'L';
      CURSOR c_cip_id_lookup(p_cipt_name IN VARCHAR2) IS
         SELECT cip.id
         FROM   nit_ci_properties     cip
               ,nit_ci_property_types cipt
         WHERE  cip.cipt_id = cipt.id AND
                cipt.NAME = p_cipt_name AND
                cip.cit_id = ci_rec.cit_id;

   BEGIN
      IF (p_op <> 'INS' AND p_op <> 'UPD') THEN
         RETURN;
      END IF;

      IF (p_op = 'INS') THEN
         nit_core_p.set_validity(p_rec.valid_from
                                ,p_rec.valid_until
                                ,p_rec.opn_id);

         p_ind.id            := TRUE;
         p_ind.creation_date := TRUE;
         p_ind.created_by    := TRUE;

         v_has_attribute := NULL;
         OPEN c_attribute_live;
         FETCH c_attribute_live
            INTO v_has_attribute;
         CLOSE c_attribute_live;

         IF (v_has_attribute IS NOT NULL) THEN
            nit_error_p.error('NIT-00035'
                             ,'E'
                             ,TRUE
                             ,ci_rec.NAME
                             ,NULL
                             ,NULL
                             ,NULL);
         END IF;
      END IF;

      p_ind.last_update_date := TRUE;
      p_ind.last_updated_by  := TRUE;
      p_ind.status           := TRUE;
      p_ind.obsolete         := TRUE;
      p_ind.valid_from       := TRUE;
      p_ind.valid_until      := TRUE;

      ci_rec.id := p_rec.ci_id;
      cg$nit_config_items.slct(ci_rec);
      cip_rec.id := p_rec.cip_id;
      cg$nit_ci_properties.slct(cip_rec);

      IF (ci_rec.status = nit_core_p.ci_statuses(nit_core_p.ci_eol_idx)) THEN
         nit_error_p.error('NIT-00046'
                          ,'E'
                          ,TRUE
                          ,ci_rec.NAME
                          ,ci_rec.status
                          ,NULL
                          ,NULL);

      ELSIF (ci_rec.status = nit_core_p.ci_statuses(nit_core_p.ci_in_stock_idx)) THEN
         v_cip_id_name   := NULL;
         v_cip_id_status := NULL;
         v_has_attribute := NULL;

         OPEN c_cip_id_lookup(nit_ci_property_types_p.get_name_cipt_name);
         FETCH c_cip_id_lookup
            INTO v_cip_id_name;
         CLOSE c_cip_id_lookup;
         OPEN c_cip_id_lookup(nit_ci_property_types_p.get_status_cipt_name);
         FETCH c_cip_id_lookup
            INTO v_cip_id_status;
         CLOSE c_cip_id_lookup;
         OPEN c_attribute;
         FETCH c_attribute
            INTO v_has_attribute;
         CLOSE c_attribute;

         IF (p_rec.cip_id <> v_cip_id_name AND p_rec.cip_id <> v_cip_id_status AND
            v_has_attribute = 'X') THEN
            nit_error_p.error('NIT-00046'
                             ,'E'
                             ,TRUE
                             ,ci_rec.NAME
                             ,ci_rec.status
                             ,NULL
                             ,NULL);
         END IF;
      END IF;

      IF (p_rec.cipv_id IS NULL AND cip_rec.set_like = 'Y') THEN
         nit_error_p.error('NIT-00040'
                          ,'E'
                          ,TRUE
                          ,ci_rec.NAME
                          ,NULL
                          ,NULL
                          ,NULL);
      END IF;

      IF (p_rec.cipv_id IS NOT NULL AND cip_rec.set_like = 'N') THEN
         nit_error_p.error('NIT-00039'
                          ,'E'
                          ,TRUE
                          ,ci_rec.NAME
                          ,NULL
                          ,NULL
                          ,NULL);
      END IF;

      nit_core_p.set_audit(p_rec.creation_date
                          ,p_rec.created_by
                          ,p_rec.last_update_date
                          ,p_rec.last_updated_by
                          ,p_op);

      IF (p_op = 'UPD') THEN
         IF (ci_rec.obsolete <> 'L') THEN
            nit_error_p.error('NIT-00036'
                             ,'E'
                             ,TRUE
                             ,ci_rec.NAME
                             ,NULL
                             ,ci_rec.obsolete
                             ,p_rec.obsolete);
         END IF;
      END IF;


      -- Set the DATA column's value from the set if set-like
      IF (cip_rec.set_like = 'Y') THEN
         SELECT cipv.VALUE
         INTO   p_rec.data
         FROM   nit_ci_property_values cipv
         WHERE  cipv.id = p_rec.cipv_id;
      ELSE
         p_rec.cipv_id := NULL;
      END IF;

      IF (p_rec.obsolete = 'D') THEN
         IF (cip_rec.required = 'Y') THEN
            nit_error_p.error('NIT-00041'
                             ,'E'
                             ,TRUE
                             ,NULL
                             ,NULL
                             ,NULL
                             ,NULL);
         END IF;
      END IF;
   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;



   PROCEDURE pre_upd(p_rec IN OUT cg$nit_ci_attributes.cg$row_type
                    ,p_ind IN OUT cg$nit_ci_attributes.cg$ind_type) IS
      l_old_rec      cg$nit_ci_attributes.cg$row_type;
      opn_rec        cg$nit_operations.cg$row_type;
      pl_subprg_name VARCHAR2(30) := 'pre_upd';
   BEGIN
      l_old_rec.id := p_rec.id;
      cg$nit_ci_attributes.slct(l_old_rec);

      opn_rec.id := p_rec.opn_id;
      cg$nit_operations.slct(opn_rec);

      IF (l_old_rec.obsolete <> 'L') THEN
         nit_error_p.error('NIT-00032'
                          ,'E'
                          ,TRUE
                          ,NULL
                          ,NULL
                          ,NULL
                          ,p_rec.id);
      END IF;

      IF (nit_core_p.is_allowed_obsolete_chg(l_old_rec.obsolete
                                            ,p_rec.obsolete) = 'N') THEN
         nit_error_p.error('NIT-00037'
                          ,'E'
                          ,TRUE
                          ,l_old_rec.obsolete
                          ,p_rec.obsolete
                          ,NULL
                          ,p_rec.id);
      END IF;

      IF (opn_rec.type_name =
         nit_operations_p.operation_types(nit_operations_p.requested_idx) AND
         nit_core_p.is_allowed_ci_props_status_chg(l_old_rec.status
                                                   ,p_rec.status) = 'N') THEN
         nit_error_p.error('NIT-00038'
                          ,'E'
                          ,TRUE
                          ,l_old_rec.status
                          ,p_rec.status
                          ,NULL
                          ,p_rec.id);
      END IF;

      IF (p_ind.cip_id OR p_ind.cipv_id OR p_ind.status OR p_ind.obsolete OR
         p_ind.valid_from OR p_ind.valid_until OR p_ind.data) THEN
         archiving(p_rec
                  ,l_old_rec);
      END IF;

      p_ind.opn_id     := FALSE;
      p_ind.valid_from := TRUE;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;

BEGIN
   nit_card_p.log(pl_module
                 ,pl_version);
END nit_ci_attributes_p;
/

prompt
prompt Creating package body NIT_CI_PROPERTIES_P
prompt =========================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_ci_properties_p IS

   pl_version CONSTANT VARCHAR2(12) := '0.0.2.13';
   pl_module  CONSTANT VARCHAR2(30) := 'nit_ci_properties_p';

   FUNCTION is_child_of(p_parent IN nit_ci_properties.id%TYPE
                       ,p_child  IN nit_ci_properties.id%TYPE) RETURN CHAR IS
      pl_subprg_name VARCHAR2(30) := 'IS_CHILD_OF';
      coll           nit_ci_properties_ct := get_parents_by_rev_inherit(p_child);
      i              PLS_INTEGER;
   BEGIN
      IF (coll IS NOT NULL) THEN
         IF (coll.COUNT > 0) THEN
            i := coll.FIRST;
         ELSE
            RETURN 'N';
         END IF;
         WHILE (i IS NOT NULL) LOOP
            IF (coll(i).id = p_parent) THEN
               RETURN 'Y';
            END IF;
            i := coll.NEXT(i);
         END LOOP;
      END IF;

      RETURN 'N';

   EXCEPTION

      WHEN no_data_found THEN
         RETURN 'N';

      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_parent || '#' || p_child);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION is_direct_child_of(p_parent IN nit_ci_properties.id%TYPE
                              ,p_child  IN nit_ci_properties.id%TYPE) RETURN CHAR IS
      par_id         nit_ci_properties.id%TYPE;
      pl_subprg_name VARCHAR2(30) := 'IS_DIRECT_CHILD_OF';
   BEGIN
      SELECT cip.id
      INTO   par_id
      FROM   nit_ci_properties cip
      WHERE  cip.cip_id = p_parent AND
             cip.id = p_child;

      RETURN 'Y';

   EXCEPTION

      WHEN no_data_found THEN
         RETURN 'N';

      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_parent || '#' || p_child);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION is_parent_of(p_parent IN nit_ci_properties.id%TYPE
                        ,p_child  IN nit_ci_properties.id%TYPE) RETURN CHAR IS
      pl_subprg_name VARCHAR2(30) := 'IS_PARENT_OF';
   BEGIN
      RETURN is_child_of(p_parent
                        ,p_child);

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_parent || '#' || p_child);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION is_direct_parent_of(p_parent IN nit_ci_properties.id%TYPE
                               ,p_child  IN nit_ci_properties.id%TYPE) RETURN CHAR IS
      pl_subprg_name VARCHAR2(30) := 'IS_DIRECT_PARENT_OF';
   BEGIN
      RETURN is_direct_child_of(p_parent
                               ,p_child);

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_parent || '#' || p_child);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   -- A child2-nek gyereke-e a child1
   FUNCTION is_brother_of(p_child1 IN nit_ci_properties.id%TYPE
                         ,p_child2 IN nit_ci_properties.id%TYPE) RETURN CHAR IS
      pl_subprg_name VARCHAR2(30) := 'IS_BROTHER_OF';
   BEGIN
      IF (get_direct_parent(p_child1).id = get_direct_parent(p_child2).id) THEN
         RETURN 'Y';
      END IF;
      RETURN 'N';

   EXCEPTION

      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_child1 || '#' || p_child2);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION get_children(p_id IN nit_ci_properties.id%TYPE)
      RETURN nit_ci_properties_ct IS
      coll           nit_ci_properties_ct;
      pl_subprg_name VARCHAR2(30) := 'GET_CHILDREN';
   BEGIN
      -- Egy kis m?gia :) ?gy kb 200x gyorsabb, mint a hagyom?nyos megold?s :))
      SELECT nit_ci_properties_ot(cip.id
                                 ,cip.creation_date
                                 ,cip.created_by
                                 ,cip.last_update_date
                                 ,cip.last_updated_by
                                 ,cip.cipt_id
                                 ,cip.cit_id
                                 ,cip.cip_id_ancient
                                 ,cip.cip_id
                                 ,cip.required
                                 ,cip.set_like
                                 ,cip.is_inherited
                                 ,cip.order_in_list
                                 ,cip.description
                                 ,cip.comments) BULK COLLECT
      INTO   coll
      FROM   nit_ci_properties cip
      WHERE  id <> p_id
      START  WITH cip.id = p_id
      CONNECT BY PRIOR cip.id = cip.cip_id;
      RETURN coll;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN collection_is_null THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION get_parents_by_rev_inherit(p_id IN nit_ci_properties.id%TYPE)
      RETURN nit_ci_properties_ct IS
      coll           nit_ci_properties_ct;
      cip_parent_id  nit_ci_properties.cip_id%TYPE;
      pl_subprg_name VARCHAR2(30) := 'GET_PARENTS_BY_REV_INHERIT';
   BEGIN
      SELECT cip_id
      INTO   cip_parent_id
      FROM   nit_ci_properties
      WHERE  id = p_id;

      SELECT nit_ci_properties_ot(cip.id
                                 ,cip.creation_date
                                 ,cip.created_by
                                 ,cip.last_update_date
                                 ,cip.last_updated_by
                                 ,cip.cipt_id
                                 ,cip.cit_id
                                 ,cip.cip_id_ancient
                                 ,cip.cip_id
                                 ,cip.required
                                 ,cip.set_like
                                 ,cip.is_inherited
                                 ,cip.order_in_list
                                 ,cip.description
                                 ,cip.comments) BULK COLLECT
      INTO   coll
      FROM   nit_ci_properties cip
      START  WITH id = p_id
      CONNECT BY PRIOR cip.cip_id = cip.id;
      RETURN coll;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN collection_is_null THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION get_parents_by_inherit(p_id IN nit_ci_properties.id%TYPE)
      RETURN nit_ci_properties_ct IS
      coll           nit_ci_properties_ct;
      cip_parent_id  nit_ci_properties.cip_id%TYPE;
      pl_subprg_name VARCHAR2(30) := 'GET_PARENTS_BY_INHERIT';
   BEGIN
      SELECT cip_id
      INTO   cip_parent_id
      FROM   nit_ci_properties
      WHERE  id = p_id;

      SELECT nit_ci_properties_ot(cip.id
                                 ,cip.creation_date
                                 ,cip.created_by
                                 ,cip.last_update_date
                                 ,cip.last_updated_by
                                 ,cip.cipt_id
                                 ,cip.cit_id
                                 ,cip.cip_id_ancient
                                 ,cip.cip_id
                                 ,cip.required
                                 ,cip.set_like
                                 ,cip.is_inherited
                                 ,cip.order_in_list
                                 ,cip.description
                                 ,cip.comments) BULK COLLECT
      INTO   coll
      FROM   nit_ci_properties cip
      START  WITH id = cip_parent_id
      CONNECT BY PRIOR cip_id = id
      ORDER  BY rownum DESC;
      RETURN coll;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN collection_is_null THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION get_brothers(p_id IN nit_ci_properties.id%TYPE)
      RETURN nit_ci_properties_ct IS
      cip_parent_id  nit_ci_properties.cip_id%TYPE;
      coll           nit_ci_properties_ct;
      pl_subprg_name VARCHAR2(30) := 'GET_BROTHERS';
   BEGIN
      SELECT cip_id
      INTO   cip_parent_id
      FROM   nit_ci_properties
      WHERE  id = p_id;

      SELECT nit_ci_properties_ot(cip.id
                                 ,cip.creation_date
                                 ,cip.created_by
                                 ,cip.last_update_date
                                 ,cip.last_updated_by
                                 ,cip.cipt_id
                                 ,cip.cit_id
                                 ,cip.cip_id_ancient
                                 ,cip.cip_id
                                 ,cip.required
                                 ,cip.set_like
                                 ,cip.is_inherited
                                 ,cip.order_in_list
                                 ,cip.description
                                 ,cip.comments) BULK COLLECT
      INTO   coll
      FROM   nit_ci_properties cip
      WHERE  cip.cip_id = cip_parent_id AND
             id <> p_id;

      RETURN coll;

   EXCEPTION
      WHEN collection_is_null THEN
         RETURN NULL;
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION get_direct_children(p_id IN nit_ci_properties.id%TYPE)
      RETURN nit_ci_properties_ct IS
      coll           nit_ci_properties_ct;
      pl_subprg_name VARCHAR2(30) := 'GET_DIRECT_CHILDREN';

   BEGIN
      SELECT nit_ci_properties_ot(cip.id
                                 ,cip.creation_date
                                 ,cip.created_by
                                 ,cip.last_update_date
                                 ,cip.last_updated_by
                                 ,cip.cipt_id
                                 ,cip.cit_id
                                 ,cip.cip_id_ancient
                                 ,cip.cip_id
                                 ,cip.required
                                 ,cip.set_like
                                 ,cip.is_inherited
                                 ,cip.order_in_list
                                 ,cip.description
                                 ,cip.comments) BULK COLLECT
      INTO   coll
      FROM   nit_ci_properties cip
      WHERE  cip.cip_id = p_id;

      RETURN coll;

   EXCEPTION
      WHEN collection_is_null THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION get_direct_parent(p_id IN nit_ci_properties.id%TYPE)
      RETURN nit_ci_properties%ROWTYPE IS
      my_parent      nit_ci_properties%ROWTYPE;
      my_parent_id   nit_ci_properties.cip_id%TYPE;
      pl_subprg_name VARCHAR2(30) := 'GET_DIRECT_PARENT';

   BEGIN
      <<existance_check>>
      BEGIN
         SELECT cip_id
         INTO   my_parent_id
         FROM   nit_ci_properties cip
         WHERE  cip.id = p_id;
      EXCEPTION
         WHEN no_data_found THEN
            RETURN NULL;
      END existance_check;

      SELECT *
      INTO   my_parent
      FROM   nit_ci_properties cip
      WHERE  id = my_parent_id;

      RETURN my_parent;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION is_root(p_id IN nit_ci_properties.id%TYPE) RETURN CHAR IS
      par            nit_ci_properties%ROWTYPE;
      pl_subprg_name VARCHAR2(30) := 'IS_ROOT';
   BEGIN
      SELECT *
      INTO   par
      FROM   nit_ci_properties
      WHERE  id = p_id AND
             cip_id IS NULL; -- az?rt a 'par'-ba mert ?gyis fel?l?rjuk mindj?rt..optimaliz?ci?..

      RETURN 'Y';

   EXCEPTION
      WHEN no_data_found THEN
         RETURN 'N';

      WHEN too_many_rows THEN
         RETURN NULL;

      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION is_leaf(p_id IN nit_ci_properties.id%TYPE) RETURN CHAR IS
      l_rec          nit_ci_properties.id%TYPE;
      pl_subprg_name VARCHAR2(30) := 'IS_LEAF';
   BEGIN
      SELECT id
      INTO   l_rec
      FROM   nit_ci_properties
      WHERE  cip_id = p_id;

      RETURN 'N';

   EXCEPTION
      WHEN no_data_found THEN
         RETURN 'Y';
      WHEN too_many_rows THEN
         RETURN 'N';
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;

   PROCEDURE set_inherited(p_rec IN OUT cg$nit_ci_properties.cg$row_type
                          ,p_ind IN OUT cg$nit_ci_properties.cg$ind_type) IS
      id_coll        nit_num_ct;
      pl_subprg_name VARCHAR2(30) := 'SET_INHERITED';
   BEGIN
      SELECT cip.id BULK COLLECT
      INTO   id_coll
      FROM   nit_ci_properties cip
            ,TABLE(nit_ci_types_p.get_parents_by_rev_inherit(p_rec.cit_id)) cit
      WHERE  (cip.cit_id = cit.id AND cip.cipt_id = p_rec.cipt_id);

      IF (id_coll IS NOT NULL) THEN
         IF (id_coll.COUNT > 0) THEN
            p_rec.is_inherited := 'Y';
         ELSE
            p_rec.is_inherited := 'N';
         END IF;

         IF (id_coll.EXISTS(id_coll.FIRST)) THEN
            p_rec.cip_id := id_coll(id_coll.FIRST);
         ELSE
            p_rec.cip_id := NULL;
         END IF;

         IF (id_coll.EXISTS(id_coll.LAST)) THEN
            p_rec.cip_id_ancient := id_coll(id_coll.LAST);
         ELSE
            p_rec.cip_id_ancient := NULL;
         END IF;

      ELSE
         p_rec.is_inherited   := 'N';
         p_rec.cip_id         := NULL;
         p_rec.cip_id_ancient := NULL;
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;

   FUNCTION package_version RETURN VARCHAR2 IS
   BEGIN
      RETURN pl_module || ' ' || pl_version;
   END;

   PROCEDURE set_order(p_rec   IN OUT cg$nit_ci_properties.cg$row_type
                      ,p_order IN nit_ci_properties.order_in_list%TYPE) IS
      dependant      nit_ci_properties.id%TYPE;
      pl_subprg_name VARCHAR2(30) := 'SET_ORDER';
   BEGIN
      IF (p_rec.order_in_list IS NULL AND p_order IS NOT NULL) THEN
         p_rec.order_in_list := p_order;
      ELSIF (p_rec.order_in_list IS NULL AND p_order IS NULL) THEN
         <<order_set>>
         BEGIN
            SELECT NVL(MAX(order_in_list)
                      ,0) + 1
            INTO   p_rec.order_in_list
            FROM   nit_ci_properties cip
            WHERE  cip.cit_id = p_rec.cit_id;
         EXCEPTION
            WHEN no_data_found THEN
               p_rec.order_in_list := 1;
               RETURN;
            WHEN OTHERS THEN
               nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                        ,dbms_utility.format_call_stack
                                        ,dbms_utility.format_error_stack
                                        ,'Y'
                                        ,pl_module
                                        ,pl_version
                                        ,pl_subprg_name
                                        ,'#' || p_rec.id || '#' || p_order);
               RAISE;
         END;
      END IF;

      -- Ha nincs az adott sorrendi helyen semmi, akkor odarakjuk magunkat..
      -- Ha van, akkor update...
      -- T?bb nem lehet, csak 1...azaz a TOO_MANY_ROWS-t nem fogja kiv?ltani...

      SELECT id
      INTO   dependant
      FROM   nit_ci_properties cip
      WHERE  cip.order_in_list = p_rec.order_in_list AND
             cip.cit_id = p_rec.cit_id AND
             rownum = 1
      FOR    UPDATE;

      -- Szerintem felesleges m?st for-update-elni mert ?gyis azonnal update-?nk, amikor ez lefut..1-2 msec a difi..
      -- ?s nem ID alapon, csak CIT_ID alapon kellene am?gy is z?rolni...
      IF (p_rec.id IS NOT NULL) THEN

         UPDATE nit_ci_properties cip
         SET    cip.order_in_list = cip.order_in_list + 1
         WHERE  cip.id <> p_rec.id AND
                cip.order_in_list >= p_rec.order_in_list AND
                cip.cit_id = p_rec.cit_id;
      END IF;

      IF (p_rec.id IS NULL) THEN

         UPDATE nit_ci_properties cip
         SET    cip.order_in_list = cip.order_in_list + 1
         WHERE  cip.order_in_list >= p_rec.order_in_list AND
                cip.cit_id = p_rec.cit_id;
      END IF;

   EXCEPTION
      WHEN no_data_found THEN
         p_rec.order_in_list := NVL(NVL(p_order
                                       ,p_rec.order_in_list)
                                   ,1);
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id || '#' || p_order);
         RAISE;

   END;

   FUNCTION is_deletable(p_id IN nit_ci_properties.id%TYPE) RETURN CHAR IS
      l_cip_rec cg$nit_ci_properties.cg$row_type;
      l_cit_rec cg$nit_ci_types.cg$row_type;
      l_exists  CHAR;
      l_match   CHAR;
      CURSOR c_match(p_cipt_id IN nit_ci_property_types.id%TYPE, p_cipt_name IN nit_ci_property_types.NAME%TYPE) IS
         SELECT 'X'
         FROM   nit_ci_property_types cipt
         WHERE  cipt.id = p_cipt_id AND
                cipt.NAME = p_cipt_name;
   BEGIN
      IF (p_id IS NULL) THEN
         RETURN 'N';
      ELSIF (nit_ci_types_p.is_deleting = 'N') THEN
         l_cip_rec.id := p_id;
         cg$nit_ci_properties.slct(l_cip_rec);

         l_cit_rec.id := l_cip_rec.cit_id;
         cg$nit_ci_types.slct(l_cit_rec);

         -- name
         OPEN c_match(l_cip_rec.cipt_id
                     ,nit_ci_property_types_p.get_name_cipt_name);
         FETCH c_match
            INTO l_match;
         CLOSE c_match;

         -- status
         OPEN c_match(l_cip_rec.cipt_id
                     ,nit_ci_property_types_p.get_status_cipt_name);
         FETCH c_match
            INTO l_match;
         CLOSE c_match;

         -- purchase order
         OPEN c_match(l_cip_rec.cipt_id
                     ,nit_ci_property_types_p.get_po_cipt_name);
         FETCH c_match
            INTO l_exists;
         CLOSE c_match;

         IF (l_cit_rec.need_po = 'Y' AND l_exists IS NOT NULL) THEN
            l_match := 'X';
         END IF;

         l_exists := NULL;
         -- inventory number
         OPEN c_match(l_cip_rec.cipt_id
                     ,nit_ci_property_types_p.get_inventory_num_cipt_name);
         FETCH c_match
            INTO l_exists;
         CLOSE c_match;

         IF (l_cit_rec.could_in_inventory = 'Y' AND l_exists IS NOT NULL) THEN
            l_match := 'X';
         END IF;
      END IF;

      IF (l_match IS NULL) THEN
         RETURN 'Y';
      ELSE
         RETURN 'N';
      END IF;
   END;

   PROCEDURE set_order_before(p_rec IN OUT cg$nit_ci_properties.cg$row_type
                             ,p_id  IN nit_ci_properties.id%TYPE) IS
      ord            nit_ci_properties.order_in_list%TYPE;
      pl_subprg_name VARCHAR2(30) := 'SET_ORDER_BEFORE';
   BEGIN
      SELECT order_in_list
      INTO   ord
      FROM   nit_ci_properties
      WHERE  id = p_id
      FOR    UPDATE;
      set_order(p_rec
               ,ord);

   EXCEPTION
      WHEN no_data_found THEN
         set_order(p_rec
                  ,1);
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id || '#' || p_id);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   PROCEDURE set_order_after(p_rec IN OUT cg$nit_ci_properties.cg$row_type
                            ,p_id  IN nit_ci_properties.id%TYPE) IS
      ord            nit_ci_properties.order_in_list%TYPE;
      pl_subprg_name VARCHAR2(30) := 'SET_ORDER_BEFORE';
   BEGIN
      SELECT order_in_list
      INTO   ord
      FROM   nit_ci_properties
      WHERE  id = p_id
      FOR    UPDATE;
      set_order(p_rec
               ,ord);
   EXCEPTION
      WHEN no_data_found THEN
         set_order(p_rec
                  ,1);
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;

   /*
      PROCEDURE special_cip_ins(p_cit_id    IN nit_ci_types.id%TYPE
                               ,p_cipt_name IN nit_ci_property_types.NAME%TYPE) IS
         pl_subprg_name VARCHAR2(30) := 'special_cip_ins';
         l_rec          cg$nit_ci_properties.cg$row_type;
         l_ind          cg$nit_ci_properties.cg$ind_type;
         l_cipt_id      nit_ci_property_types.id%TYPE;
         temp           nit_ci_property_types.id%TYPE;

         CURSOR c_cipt_id(p_cipt_name IN nit_ci_property_types.NAME%TYPE) IS
            SELECT cipt.id
            FROM   nit_ci_property_types cipt
            WHERE  cipt.NAME = p_cipt_name;
      BEGIN
         OPEN c_cipt_id(p_cipt_name);
         FETCH c_cipt_id
            INTO l_cipt_id;
         CLOSE c_cipt_id;

         l_rec.required      := 'Y';
         l_rec.set_like      := 'N';
         l_rec.is_importable := 'N';
         l_rec.order_in_list := 1;
         l_rec.cipt_id       := l_cipt_id;
         l_rec.cit_id        := p_cit_id;

         l_ind.id            := TRUE;
         l_ind.cit_id        := TRUE;
         l_ind.cipt_id       := TRUE;
         l_ind.required      := TRUE;
         l_ind.set_like      := TRUE;
         l_ind.order_in_list := TRUE;
         l_ind.is_inherited  := TRUE;
         l_ind.is_importable := TRUE;

         cg$nit_ci_properties.called_from_package := FALSE;
         cg$nit_ci_properties.ins(l_rec
                                 ,l_ind);
         nit_ci_properties_p.cascade_ins(l_rec
                                        ,l_ind);
      EXCEPTION
         WHEN OTHERS THEN
            nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                     ,dbms_utility.format_call_stack
                                     ,dbms_utility.format_error_stack
                                     ,'Y'
                                     ,pl_module
                                     ,pl_version
                                     ,pl_subprg_name
                                     ,'#' || p_cit_id);
            RAISE;
      END;
   */
   PROCEDURE pre_dml(p_rec IN OUT cg$nit_ci_properties.cg$row_type
                    ,p_ind IN OUT cg$nit_ci_properties.cg$ind_type
                    ,p_op  IN VARCHAR2) IS

      pl_subprg_name VARCHAR2(30) := 'pre_dml';
      CURSOR cur(p_cipt_id IN nit_ci_property_types.id%TYPE) IS
         SELECT id
         FROM   nit_ci_property_types cipt
         WHERE  NAME LIKE 'installation%manual%step%' AND
                id = p_cipt_id;
   BEGIN
      IF (p_op <> 'INS' AND p_op <> 'UPD') THEN
         RETURN;
      END IF;

      IF (p_op = 'INS') THEN
         p_ind.creation_date := TRUE;
         p_ind.created_by    := TRUE;
      END IF;

      IF (p_op = 'INS') THEN
         p_ind.id := TRUE;
      END IF;

      p_ind.last_update_date := TRUE;
      p_ind.last_updated_by  := TRUE;
      p_ind.cip_id_ancient   := TRUE;
      p_ind.cip_id           := TRUE;
      p_ind.required         := TRUE;
      p_ind.set_like         := TRUE;
      p_ind.is_inherited     := TRUE;
      p_ind.is_importable    := TRUE;
      p_ind.order_in_list    := TRUE;

      nit_core_p.set_audit(p_rec.creation_date
                          ,p_rec.created_by
                          ,p_rec.last_update_date
                          ,p_rec.last_updated_by
                          ,p_op);

      set_order(p_rec
               ,p_rec.order_in_list);

      set_inherited(p_rec
                   ,p_ind);

      FOR l_rec IN cur(p_rec.cipt_id) LOOP
         p_rec.set_like := 'Y';
      END LOOP;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;

   PROCEDURE pre_upd(p_rec IN OUT cg$nit_ci_properties.cg$row_type
                    ,p_ind IN OUT cg$nit_ci_properties.cg$ind_type) IS
      pl_subprg_name VARCHAR2(30) := 'PRE_UPD';
      old_rec        nit_ci_properties%ROWTYPE;
      cipv_pk_rec    cg$nit_ci_property_values.cg$pk_type;

      CURSOR c_cipv(p_cip_id IN nit_ci_property_values.cip_id%TYPE) IS
         SELECT cipv.id
         FROM   nit_ci_property_values cipv
         WHERE  cipv.cip_id = p_cip_id;
   BEGIN

      SELECT *
      INTO   old_rec
      FROM   nit_ci_properties cip
      WHERE  cip.id = p_rec.id;

      -- Ha halmazos CIP-b?l nme halmazos lesz, akkor kaszk?doltan t?rl?nk minden CIPV-j?t...
      IF (old_rec.set_like = 'Y' AND p_rec.set_like = 'N') THEN
         FOR cipv_rec IN c_cipv(p_rec.id) LOOP
            cipv_pk_rec.the_rowid := NULL;
            cipv_pk_rec.id        := cipv_rec.id;
            cg$nit_ci_property_values.del(cipv_pk_rec);
         END LOOP;
         /*
                  nit_error_p.error('NIT-00014'
                                   ,'E'
                                   ,TRUE
                                   ,NULL
                                   ,NULL
                                   ,NULL
                                   ,p_rec.id);
         */
      END IF;
   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;



   PROCEDURE pre_del(p_id IN nit_ci_properties.id%TYPE) IS
      pl_subprg_name VARCHAR2(30) := 'PRE_DEL';
      l_cipv_pk      cg$nit_ci_property_values.cg$pk_type;
      l_cip_pk       cg$nit_ci_properties.cg$pk_type;
      l_cip_rec      cg$nit_ci_properties.cg$row_type;

      CURSOR cur_cipv IS
         SELECT cipv.id
         FROM   nit_ci_property_values cipv
         WHERE  cipv.cip_id = p_id;

      CURSOR cur_cip IS
         SELECT id
         FROM   nit_ci_properties cip
         WHERE  cip.cip_id = p_id;

   BEGIN
      IF (is_deletable(p_id) = 'N') THEN
         nit_error_p.error('NIT-00015'
                          ,'E'
                          ,TRUE
                          ,NULL
                          ,NULL
                          ,NULL
                          ,NULL);

      END IF;

      -- Ez itt gyakorlatilag CASCADE_DEL. Nem lehetne azt h?vni e helyett?
      -- Lehet, de lassabb lenne szerintem ?s lehet v?gtelen ciklus...
      -- FIXME: ez egy nagyon ?j megjegyz?s.. ?rdemes ?tgondolni...
      FOR rec IN cur_cipv LOOP
         l_cipv_pk.id        := rec.id;
         l_cipv_pk.the_rowid := NULL;
         cg$nit_ci_property_values.del(l_cipv_pk);
      END LOOP;

      FOR rec IN cur_cip LOOP
         l_cip_pk.id        := rec.id;
         l_cip_pk.the_rowid := NULL;

         IF (is_deletable(rec.id) = 'Y') THEN
            cg$nit_ci_properties.del(l_cip_pk);

         ELSE
            l_cip_rec.id        := rec.id;
            l_cip_rec.the_rowid := NULL;
            cg$nit_ci_properties.slct(l_cip_rec);
            l_cip_rec.cip_id := get_direct_parent(p_id).id;
            cg$nit_ci_properties.upd(l_cip_rec
                                    ,cg$nit_ci_properties.cg$ind_true
                                    ,TRUE);
         END IF;


      END LOOP;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);

         RAISE;
   END;




   -- Post insert Table API ?gb?l h?v?dik
   PROCEDURE cascade_ins(p_rec IN OUT cg$nit_ci_properties.cg$row_type
                        ,p_ind IN OUT cg$nit_ci_properties.cg$ind_type) IS
      pl_subprg_name VARCHAR2(30) := 'CASCADE_INS';
      cit_coll       nit_ci_types_ct := nit_ci_types_p.get_children(p_rec.cit_id);
      c_cip_rec      cg$nit_ci_properties.cg$row_type;
      c_cip_ind      cg$nit_ci_properties.cg$ind_type;
      c_cipv_rec     cg$nit_ci_property_values.cg$row_type;
      c_cipv_ind     cg$nit_ci_property_values.cg$ind_type;
      i              PLS_INTEGER;
      temp           nit_ci_properties.id%TYPE;

      -- Ha nem halmazos a CIP, akkor a kollekci? ?res lesz, a bels? ciklus nem fut le, szal nincs gond..
      CURSOR cur IS
         SELECT id
         FROM   nit_ci_property_values cipv
         WHERE  cipv.cip_id = p_rec.id;

   BEGIN
      -- ez sz?rva be az ?r?kl?d? cip-eket
      IF (cit_coll IS NOT NULL) THEN
         IF (cit_coll.COUNT > 0) THEN
            i := cit_coll.FIRST;
         ELSE
            RETURN;

         END IF;
         WHILE (i IS NOT NULL) LOOP
            c_cip_rec := p_rec;

            SELECT id
            INTO   temp
            FROM   nit_ci_properties
            WHERE  cit_id = p_rec.cit_id AND
                   cipt_id = p_rec.cipt_id;
            SELECT nit_seq.NEXTVAL
            INTO   c_cip_rec.id
            FROM   dual;

            c_cip_rec.cit_id := cit_coll(i).id;

            c_cip_ind := p_ind;
            cg$nit_ci_properties.ins(c_cip_rec
                                    ,c_cip_ind);


            FOR cur_rec IN cur LOOP
               c_cipv_rec.id        := cur_rec.id;
               c_cipv_rec.the_rowid := NULL;
               cg$nit_ci_property_values.slct(c_cipv_rec);
               SELECT nit_seq.NEXTVAL
               INTO   c_cipv_rec.id
               FROM   dual;

               c_cipv_ind.cip_id        := TRUE;
               c_cipv_ind.is_default    := TRUE;
               c_cipv_ind.order_in_list := TRUE;
               c_cipv_ind.VALUE         := TRUE;
               c_cipv_ind.description   := TRUE;
               c_cipv_ind.comments      := TRUE;

               cg$nit_ci_property_values.ins(c_cipv_rec
                                            ,c_cipv_ind);
            END LOOP;

            i := cit_coll.NEXT(i);
         END LOOP;
      END IF; -- COLL_EXISTS

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;

   PROCEDURE cascade_upd(p_rec IN OUT cg$nit_ci_properties.cg$row_type
                        ,p_ind IN OUT cg$nit_ci_properties.cg$ind_type) IS
      pl_subprg_name VARCHAR2(30) := 'CASCADE_UPD';
      cip_coll       nit_ci_properties_ct := get_direct_children(p_rec.id);
      i              PLS_INTEGER;
      c_cip_rec      cg$nit_ci_properties.cg$row_type;
      c_cip_ind      cg$nit_ci_properties.cg$ind_type;
   BEGIN
      IF (cip_coll IS NOT NULL) THEN
         IF (cip_coll.COUNT > 0) THEN
            i := cip_coll.FIRST;
         ELSE
            RETURN;
         END IF;

         c_cip_ind               := p_ind;
         c_cip_ind.cit_id        := FALSE;
         c_cip_ind.cipt_id       := FALSE;
         c_cip_ind.required      := TRUE;
         c_cip_ind.set_like      := TRUE;
         c_cip_ind.order_in_list := TRUE;

         WHILE (i IS NOT NULL) LOOP
            c_cip_rec.the_rowid := NULL;
            c_cip_rec.id        := cip_coll(i).id;
            cg$nit_ci_properties.slct(c_cip_rec);
            c_cip_rec.required      := p_rec.required;
            c_cip_rec.set_like      := p_rec.set_like;
            c_cip_rec.order_in_list := p_rec.order_in_list;
            cg$nit_ci_properties.upd(c_cip_rec
                                    ,c_cip_ind
                                    ,TRUE);

            i := cip_coll.NEXT(i);
         END LOOP;
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;

BEGIN
   nit_card_p.log(pl_module
                 ,pl_version);
END nit_ci_properties_p;
/

prompt
prompt Creating package body NIT_CI_PROPERTY_TYPES_P
prompt =============================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_ci_property_types_p IS
   pl_module  CONSTANT VARCHAR2(30) := 'nit_ci_property_types_p';
   pl_version CONSTANT VARCHAR2(12) := '0.0.2.6';

   FUNCTION package_version RETURN VARCHAR2 IS
   BEGIN
      RETURN '' || pl_module || ' ' || pl_version;
   END;

   ----------------------------------------------------------------------------------------------------------------------------------

   -- FIXME: Ezt lehetne gyors?tani OR-okkal a sok CASE ?g helyett, de ?gy szebb
   FUNCTION get_type_pairs(p_mime_type VARCHAR2)
      RETURN nit_ci_property_types.type_name%TYPE IS
      pl_subprg_name VARCHAR2(30) := 'GET_TYPE_PAIRS';
   BEGIN
      IF (p_mime_type IN
         ('text/plain', 'application/octet-stream', 'graphics/jpeg')) THEN
         RETURN 'CLOB';
      END IF;

      RETURN NULL;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_mime_type);
         RAISE;
   END;

   ----------------------------------------------------------------------------------------------------------------------------------

   FUNCTION get_po_cipt_name RETURN VARCHAR2 IS
   BEGIN
      RETURN nit_core_p.getp('purchase order');
   END;

   FUNCTION get_name_cipt_name RETURN VARCHAR2 IS
   BEGIN
      RETURN nit_core_p.getp('name');
   END;

   FUNCTION get_status_cipt_name RETURN VARCHAR2 IS
   BEGIN
      RETURN nit_core_p.getp('status');
   END;

   FUNCTION get_inventory_num_cipt_name RETURN VARCHAR2 IS
   BEGIN
      RETURN nit_core_p.getp('inventory number');
   END;

   FUNCTION get_ed_cipt_name RETURN VARCHAR2 IS
   BEGIN
      RETURN nit_core_p.getp('expected date of purchase');
   END;

   PROCEDURE pre_del(p_id IN nit_ci_property_types.id%TYPE) IS
      rec_name       nit_ci_property_types.NAME%TYPE;
      pl_subprg_name VARCHAR2(30) := 'pre_del';
   BEGIN
      IF (p_id IS NULL) THEN
         nit_error_p.error('NIT-00002'
                          ,'E'
                          ,TRUE
                          ,NULL
                          ,NULL
                          ,NULL
                          ,p_id);
      END IF;

      SELECT NAME
      INTO   rec_name
      FROM   nit_ci_property_types cipt
      WHERE  cipt.id = p_id AND
             cipt.NAME = get_po_cipt_name
      FOR    UPDATE;

      nit_error_p.error('NIT-00002'
                       ,'E'
                       ,TRUE
                       ,rec_name
                       ,NULL
                       ,NULL
                       ,p_id);

   EXCEPTION
      WHEN no_data_found THEN
         NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;


   PROCEDURE pre_dml(p_rec IN OUT cg$nit_ci_property_types.cg$row_type
                    ,p_ind IN OUT cg$nit_ci_property_types.cg$ind_type
                    ,p_op  IN VARCHAR2) IS
      pl_subprg_name VARCHAR2(30) := 'PRE_DML';
   BEGIN
      IF (p_op = 'INS') THEN
         p_ind.id            := TRUE;
         p_ind.creation_date := TRUE;
         p_ind.created_by    := TRUE;
         p_ind.NAME          := TRUE;
      END IF;

      IF (p_op = 'INS' OR p_op = 'UPD') THEN
         p_ind.last_update_date := TRUE;
         p_ind.last_updated_by  := TRUE;
         nit_core_p.caseconv(p_rec.NAME);
         nit_core_p.caseconv(p_rec.type_name);
         nit_core_p.caseconv(p_rec.mime_type);

         nit_core_p.set_audit(p_rec.creation_date
                             ,p_rec.created_by
                             ,p_rec.last_update_date
                             ,p_rec.last_updated_by
                             ,p_op);


         IF (p_rec.type_name IS NULL AND p_rec.mime_type IS NULL) THEN
            nit_error_p.error('NIT-00003'
                             ,'E'
                             ,FALSE
                             ,p_rec.NAME
                             ,p_rec.type_name
                             ,NULL
                             ,p_rec.id);

         ELSIF (p_rec.type_name IS NULL AND p_rec.mime_type IS NOT NULL) THEN
            p_rec.type_name := get_type_pairs(p_rec.mime_type);
         END IF;

         IF (p_rec.type_name = 'integer' OR p_rec.type_name = 'number' OR
            p_rec.type_name = 'varchar2' OR p_rec.type_name = 'date' OR
            p_rec.type_name = 'time') THEN
            NULL; -- Ekkor OK
         ELSE
            nit_error_p.error('NIT-00003'
                             ,'E'
                             ,FALSE
                             ,p_rec.NAME
                             ,p_rec.type_name
                             ,NULL
                             ,p_rec.id);
         END IF;

      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;

   END;

----------------------------------------------------------------------------------------------------------------------------------


----------------------------------------------------------------------------------------------------------------------------------
BEGIN
   nit_card_p.log(pl_module
                 ,pl_version);
END nit_ci_property_types_p;
/

prompt
prompt Creating package body NIT_CI_PROPERTY_VALUES_P
prompt ==============================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_ci_property_values_p IS
   pl_version CONSTANT VARCHAR2(12) := '0.0.2.2';
   pl_module  CONSTANT VARCHAR2(30) := 'nit_ci_property_values_p';

   PROCEDURE set_order(p_rec   IN OUT cg$nit_ci_property_values.cg$row_type
                      ,p_order IN nit_ci_property_values.order_in_list%TYPE) IS
      dependant      nit_ci_properties.id%TYPE;
      pl_subprg_name VARCHAR2(30) := 'SET_ORDER';
   BEGIN

      -- Orb?n Tam?s: probl?m?k ad?dtak vele
      IF (p_rec.is_default = 'Y') THEN
         p_rec.order_in_list := 1;
      END IF;

      IF (p_rec.order_in_list IS NULL AND p_order IS NOT NULL) THEN
         p_rec.order_in_list := p_order;
      ELSIF (p_rec.order_in_list IS NULL AND p_order IS NULL) THEN
         <<order_set>>
         BEGIN
            SELECT nvl(MAX(order_in_list)
                      ,0) + 1
            INTO   p_rec.order_in_list
            FROM   nit_ci_property_values cipv
            WHERE  cipv.cip_id = p_rec.cip_id;
         EXCEPTION
            WHEN no_data_found THEN
               p_rec.order_in_list := 1;
               RETURN;
            WHEN OTHERS THEN
               nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                        ,dbms_utility.format_call_stack
                                        ,dbms_utility.format_error_stack
                                        ,'Y'
                                        ,pl_module
                                        ,pl_version
                                        ,pl_subprg_name
                                        ,'#' || p_rec.id || '#' || p_order);
               RAISE;
         END;


      END IF;

      -- Ha nincs az adott sorrendi helyen semmi, akkor odarakjuk magunkat..
      -- Ha van, akkor update...
      -- T?bb nem lehet, csak 1...azaz a TOO_MANY_ROWS-t nem fogja kiv?ltani...
      SELECT id
      INTO   dependant
      FROM   nit_ci_property_values cipv
      WHERE  cipv.order_in_list = p_order AND
             cipv.cip_id = p_rec.cip_id
      FOR    UPDATE;

      -- Szerintem felesleges m?st for-update-elni mert ?gyis azonnal update-?nk, amikor ez lefut..1-2 msec a difi..
      -- ?s nem ID alapon, csak CIT_ID alapon kellene am?gy is z?rolni...
      IF (p_rec.id IS NOT NULL) THEN
         UPDATE nit_ci_property_values cipv
         SET    cipv.order_in_list = cipv.order_in_list + 1
         WHERE  cipv.id <> p_rec.id AND
                cipv.order_in_list >= p_rec.order_in_list AND
                cipv.cip_id = p_rec.cip_id;
      END IF;

      IF (p_rec.id IS NULL) THEN
         UPDATE nit_ci_property_values cipv
         SET    cipv.order_in_list = cipv.order_in_list + 2
         WHERE  cipv.order_in_list >= p_rec.order_in_list AND
                cipv.cip_id = p_rec.cip_id;
      END IF;

   EXCEPTION
      WHEN no_data_found THEN
         p_rec.order_in_list := p_order;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id || '#' || p_order);
         RAISE;

   END;

   PROCEDURE set_order_before(p_rec IN OUT cg$nit_ci_property_values.cg$row_type
                             ,p_id  IN nit_ci_property_values.id%TYPE) IS
      ord            nit_ci_property_values.order_in_list%TYPE;
      pl_subprg_name VARCHAR2(30) := 'SET_ORDER_BEFORE';
   BEGIN
      SELECT order_in_list
      INTO   ord
      FROM   nit_ci_property_values
      WHERE  id = p_id
      FOR    UPDATE;
      set_order(p_rec
               ,ord);

   EXCEPTION
      WHEN no_data_found THEN
         set_order(p_rec
                  ,1);
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id || '#' || p_id);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   PROCEDURE set_order_after(p_rec IN OUT cg$nit_ci_property_values.cg$row_type
                            ,p_id  IN nit_ci_property_values.id%TYPE) IS
      ord            nit_ci_property_values.order_in_list%TYPE;
      pl_subprg_name VARCHAR2(30) := 'SET_ORDER_AFTER';
   BEGIN
      SELECT order_in_list
      INTO   ord
      FROM   nit_ci_property_values
      WHERE  id = p_id
      FOR    UPDATE;
      set_order(p_rec
               ,ord);
   EXCEPTION
      WHEN no_data_found THEN
         set_order(p_rec
                  ,1);
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;

   PROCEDURE pre_dml(p_rec IN OUT cg$nit_ci_property_values.cg$row_type
                    ,p_ind IN OUT cg$nit_ci_property_values.cg$ind_type
                    ,p_op  IN VARCHAR2) IS
      pl_subprg_name VARCHAR2(30) := 'pre_dml';
      cip_rec        nit_ci_properties%ROWTYPE;
   BEGIN
      IF (p_op <> 'INS' AND p_op <> 'UPD') THEN
         RETURN;
      END IF;

      IF (p_op = 'INS') THEN
         p_ind.id            := TRUE;
         p_ind.creation_date := TRUE;
         p_ind.created_by    := TRUE;
         p_ind.cip_id        := TRUE;
         p_ind.VALUE         := TRUE;
      END IF;

      IF (p_op = 'INS' OR p_op = 'UPD') THEN
         p_ind.last_update_date := TRUE;
         p_ind.last_updated_by  := TRUE;
         p_ind.is_default       := TRUE;
         p_ind.order_in_list    := TRUE;
      END IF;

      IF (p_op = 'UPD') THEN
         p_ind.cip_id := FALSE;
      END IF;

      nit_core_p.caseconv(p_rec.VALUE);
      SELECT *
      INTO   cip_rec
      FROM   nit_ci_properties cip
      WHERE  cip.id = p_rec.cip_id;

      -- BL : csak halmazos CIP-hez lehessen halmazt rendelni
      IF (cip_rec.set_like = 'N') THEN
         nit_error_p.error('NIT-00016'
                          ,'E'
                          ,TRUE
                          ,NULL
                          ,NULL
                          ,NULL
                          ,p_rec.id);
      END IF;

      nit_core_p.caseconv(p_rec.VALUE);

      -- 1 flag ?tbillent?s??rt hdd ne ?rjak kurzort, ciklust, rekordkonvert?l?st hogy designeres h?v?s legyen..
      IF (p_rec.is_default = 'Y') THEN
         UPDATE nit_ci_property_values cipv
         SET    is_default = 'N'
         WHERE  cipv.cip_id = p_rec.cip_id AND
                id <> p_rec.id;
      END IF;
      set_order(p_rec
               ,p_rec.order_in_list);

      nit_core_p.set_audit(p_rec.creation_date
                          ,p_rec.created_by
                          ,p_rec.last_update_date
                          ,p_rec.last_updated_by
                          ,p_op);

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;

   FUNCTION is_child_of(p_parent IN nit_ci_property_values.id%TYPE
                       ,p_child  IN nit_ci_property_values.id%TYPE) RETURN CHAR IS
      pl_subprg_name VARCHAR2(30) := 'IS_CHILD_OF';
      coll           nit_ci_property_values_ct := get_parents_by_rev_inherit(p_child);
      i              PLS_INTEGER;
   BEGIN
      IF (coll IS NOT NULL) THEN

         IF (coll.COUNT > 0) THEN
            i := coll.FIRST;
         ELSE
            RETURN 'N';
         END IF;

         WHILE (i IS NOT NULL)
         LOOP
            IF (coll(i).id = p_parent) THEN
               RETURN 'Y';
            END IF;
            i := coll.NEXT(i);
         END LOOP;
      END IF;

      RETURN 'N';

   EXCEPTION

      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_parent || '#' || p_child);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION is_direct_child_of(p_parent IN nit_ci_property_values.id%TYPE
                              ,p_child  IN nit_ci_property_values.id%TYPE)
      RETURN CHAR IS
      par            nit_ci_property_values%ROWTYPE;
      child          nit_ci_property_values%ROWTYPE;
      pl_subprg_name VARCHAR2(30) := 'IS_DIRECT_CHILD_OF';
   BEGIN
      SELECT *
      INTO   par
      FROM   nit_ci_property_values cipv
      WHERE  cipv.id = p_parent;

      SELECT *
      INTO   child
      FROM   nit_ci_property_values cipv
      WHERE  cipv.id = p_child;

      IF (par.VALUE = child.VALUE) THEN
         RETURN nit_ci_properties_p.is_direct_child_of(p_parent
                                                      ,p_child);
      END IF;

      RETURN 'N';

   EXCEPTION

      WHEN no_data_found THEN
         RETURN 'N';

      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_parent || '#' || p_child);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION is_parent_of(p_parent IN nit_ci_property_values.id%TYPE
                        ,p_child  IN nit_ci_property_values.id%TYPE) RETURN CHAR IS
      pl_subprg_name VARCHAR2(30) := 'IS_PARENT_OF';
   BEGIN
      RETURN is_child_of(p_parent
                        ,p_child);

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_parent || '#' || p_child);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION is_direct_parent_of(p_parent IN nit_ci_property_values.id%TYPE
                               ,p_child  IN nit_ci_property_values.id%TYPE)
      RETURN CHAR IS
      pl_subprg_name VARCHAR2(30) := 'IS_DIRECT_PARENT_OF';
   BEGIN
      RETURN is_direct_child_of(p_parent
                               ,p_child);

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_parent || '#' || p_child);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   -- A child2-nek gyereke-e a child1
   FUNCTION is_brother_of(p_child1 IN nit_ci_property_values.id%TYPE
                         ,p_child2 IN nit_ci_property_values.id%TYPE) RETURN CHAR IS
      pl_subprg_name VARCHAR2(30) := 'IS_BROTHER_OF';
   BEGIN
      IF (get_direct_parent(p_child1).id = get_direct_parent(p_child2).id) THEN
         RETURN 'Y';
      END IF;

      RETURN 'N';

   EXCEPTION

      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_child1 || '#' || p_child2);
         RAISE;
   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   /* Orb?n Tam?s: ?tirtam, az eredeti nem m?k?d?tt
   Bej?n egy ?j param?ter: p_value. Ha nem NULL, a WHERE felt?tel erre ?ll?t?dik,
   k?l?nben a p_id -hez tartoz? value-t haszn?lja */

   FUNCTION get_children(p_id    IN nit_ci_property_values.id%TYPE
                        ,p_value IN nit_ci_property_values.VALUE%TYPE DEFAULT NULL)
      RETURN nit_num_ct IS
      cipv_id_coll nit_num_ct;
      cipv_rec     cg$nit_ci_property_values.cg$row_type;

      pl_subprg_name VARCHAR2(30) := 'GET_CHILDREN';
   BEGIN
      cipv_rec.id := p_id;
      cg$nit_ci_property_values.slct(cipv_rec);
      IF (p_value IS NOT NULL) THEN
         cipv_rec.VALUE := p_value;
      END IF;

      SELECT cipv_id BULK COLLECT
      INTO   cipv_id_coll
      FROM   (SELECT cip.id     AS cip_id
                    ,cip.cip_id AS cip_ancient_id
                    ,cipv.id    AS cipv_id
              FROM   nit_ci_properties      cip
                    ,nit_ci_property_values cipv
              WHERE  cipv.cip_id = cip.id AND
                     cipv.VALUE = cipv_rec.VALUE)
      CONNECT BY PRIOR cip_id = cip_ancient_id
      START  WITH cip_ancient_id = cipv_rec.cip_id;

      RETURN cipv_id_coll;
   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;
   END;


   FUNCTION get_parents_by_rev_inherit(p_id IN nit_ci_property_values.id%TYPE)
      RETURN nit_ci_property_values_ct IS
      cipv_coll      nit_ci_property_values_ct;
      cip_coll       nit_ci_properties_ct;
      cipv_rec       nit_ci_property_values%ROWTYPE;
      pl_subprg_name VARCHAR2(30) := 'GET_CHILDREN';
   BEGIN
      SELECT *
      INTO   cipv_rec
      FROM   nit_ci_property_values cipv
      WHERE  cipv.id = p_id;

      SELECT nit_ci_properties_ot(id
                                 ,creation_date
                                 ,created_by
                                 ,last_update_date
                                 ,last_updated_by
                                 ,cipt_id
                                 ,cit_id
                                 ,cip_id_ancient
                                 ,cip_id
                                 ,required
                                 ,set_like
                                 ,is_inherited
                                 ,order_in_list
                                 ,description
                                 ,comments) BULK COLLECT
      INTO   cip_coll
      FROM   nit_ci_properties cip
      WHERE  cip.id <> cipv_rec.cip_id
      START  WITH cip.id = cipv_rec.cip_id
      CONNECT BY PRIOR cip.cip_id = cip.id;

      SELECT nit_ci_property_values_ot(cipv.id
                                      ,cipv.creation_date
                                      ,cipv.created_by
                                      ,cipv.last_update_date
                                      ,cipv.last_updated_by
                                      ,cipv.cip_id
                                      ,cipv.is_default
                                      ,cipv.order_in_list
                                      ,cipv.VALUE
                                      ,cipv.description
                                      ,cipv.comments) BULK COLLECT
      INTO   cipv_coll
      FROM   nit_ci_property_values cipv
            ,TABLE(cip_coll) cips
      WHERE  (cipv.cip_id = cips.id AND cipv.VALUE = cipv_rec.VALUE) AND
             cipv.id <> cipv_rec.id
      START  WITH cipv.cip_id = cipv_rec.cip_id
      CONNECT BY PRIOR cipv.cip_id = cips.cip_id;

      RETURN cipv_coll;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN collection_is_null THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;

   FUNCTION get_parents_by_inherit(p_id IN nit_ci_property_values.id%TYPE)
      RETURN nit_ci_property_values_ct IS
      cipv_coll      nit_ci_property_values_ct;
      cip_coll       nit_ci_properties_ct;
      cipv_rec       nit_ci_property_values%ROWTYPE;
      pl_subprg_name VARCHAR2(30) := 'GET_CHILDREN';
   BEGIN
      SELECT *
      INTO   cipv_rec
      FROM   nit_ci_property_values cipv
      WHERE  cipv.id = p_id;

      SELECT nit_ci_properties_ot(id
                                 ,creation_date
                                 ,created_by
                                 ,last_update_date
                                 ,last_updated_by
                                 ,cipt_id
                                 ,cit_id
                                 ,cip_id_ancient
                                 ,cip_id
                                 ,required
                                 ,set_like
                                 ,is_inherited
                                 ,order_in_list
                                 ,description
                                 ,comments) BULK COLLECT
      INTO   cip_coll
      FROM   nit_ci_properties cip
      WHERE  cip.id <> cipv_rec.cip_id
      START  WITH cip.id = cipv_rec.cip_id
      CONNECT BY PRIOR cip.cip_id = cip.id
      ORDER  BY rownum DESC;

      SELECT nit_ci_property_values_ot(cipv.id
                                      ,cipv.creation_date
                                      ,cipv.created_by
                                      ,cipv.last_update_date
                                      ,cipv.last_updated_by
                                      ,cipv.cip_id
                                      ,cipv.is_default
                                      ,cipv.order_in_list
                                      ,cipv.VALUE
                                      ,cipv.description
                                      ,cipv.comments) BULK COLLECT
      INTO   cipv_coll
      FROM   nit_ci_property_values cipv
            ,TABLE(cip_coll) cips
      WHERE  (cipv.cip_id = cips.id AND cipv.VALUE = cipv_rec.VALUE) AND
             cipv.id <> cipv_rec.id
      START  WITH cipv.cip_id = cipv_rec.cip_id
      CONNECT BY PRIOR cipv.cip_id = cips.cip_id;

      RETURN cipv_coll;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN collection_is_null THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------

   FUNCTION get_brothers(p_id IN nit_ci_property_values.id%TYPE)
      RETURN nit_ci_property_values_ct IS
      cipv_rec       nit_ci_property_values%ROWTYPE;
      cip_coll       nit_ci_properties_ct;
      cipv_coll      nit_ci_property_values_ct;
      pl_subprg_name VARCHAR2(30) := 'GET_BROTHERS';
   BEGIN
      SELECT *
      INTO   cipv_rec
      FROM   nit_ci_property_values
      WHERE  id = p_id;

      cip_coll := nit_ci_properties_p.get_brothers(cipv_rec.cip_id);

      SELECT nit_ci_property_values_ot(cipv.id
                                      ,cipv.creation_date
                                      ,cipv.created_by
                                      ,cipv.last_update_date
                                      ,cipv.last_updated_by
                                      ,cipv.cip_id
                                      ,cipv.is_default
                                      ,cipv.order_in_list
                                      ,cipv.VALUE
                                      ,cipv.description
                                      ,cipv.comments) BULK COLLECT
      INTO   cipv_coll
      FROM   nit_ci_property_values cipv
            ,TABLE(cip_coll) cips
      WHERE  (cipv.cip_id = cips.id AND cipv.VALUE = cipv_rec.VALUE);

      RETURN cipv_coll;

   EXCEPTION
      WHEN collection_is_null THEN
         RETURN NULL;
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION get_direct_children(p_id IN nit_ci_property_values.id%TYPE)
      RETURN nit_ci_property_values_ct IS
      cipv_rec       nit_ci_property_values%ROWTYPE;
      cipv_coll      nit_ci_property_values_ct;
      pl_subprg_name VARCHAR2(30) := 'GET_DIRECT_CHILDREN';

   BEGIN
      SELECT *
      INTO   cipv_rec
      FROM   nit_ci_property_values
      WHERE  id = p_id;

      SELECT nit_ci_property_values_ot(cipv.id
                                      ,cipv.creation_date
                                      ,cipv.created_by
                                      ,cipv.last_update_date
                                      ,cipv.last_updated_by
                                      ,cipv.cip_id
                                      ,cipv.is_default
                                      ,cipv.order_in_list
                                      ,cipv.VALUE
                                      ,cipv.description
                                      ,cipv.comments) BULK COLLECT
      INTO   cipv_coll
      FROM   nit_ci_property_values cipv
            ,TABLE(nit_ci_properties_p.get_direct_children(cipv_rec.cip_id)) cips
      WHERE  (cips.id = cipv.cip_id AND cipv.VALUE = cipv_rec.VALUE);

   EXCEPTION
      WHEN collection_is_null THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION get_direct_parent(p_id IN nit_ci_property_values.id%TYPE)
      RETURN nit_ci_property_values%ROWTYPE IS
      cip_id         nit_ci_properties.id%TYPE;
      cipv_rec       nit_ci_property_values%ROWTYPE;
      cipv_ret       nit_ci_property_values%ROWTYPE;
      pl_subprg_name VARCHAR2(30) := 'GET_DIRECT_CHILDREN';

   BEGIN
      SELECT *
      INTO   cipv_rec
      FROM   nit_ci_property_values
      WHERE  id = p_id;

      SELECT cip_id
      INTO   cip_id
      FROM   nit_ci_properties
      WHERE  id = cipv_rec.cip_id;

      SELECT *
      INTO   cipv_ret
      FROM   nit_ci_property_values cipv
      WHERE  cipv.cip_id = cip_id AND
             cipv.VALUE = cipv_rec.VALUE;

      RETURN cipv_ret;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;
   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION is_root(p_id IN nit_ci_property_values.id%TYPE) RETURN CHAR IS
      r_cip_id       nit_ci_property_values.cip_id%TYPE;
      pl_subprg_name VARCHAR2(30) := 'IS_ROOT';
   BEGIN
      SELECT cip_id
      INTO   r_cip_id
      FROM   nit_ci_property_values
      WHERE  id = p_id;

      RETURN nit_ci_properties_p.is_root(r_cip_id);

   EXCEPTION

      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION is_leaf(p_id IN nit_ci_property_values.id%TYPE) RETURN CHAR IS
      /* Orb?n Tam?s : az ?r?kl?d?sben megengedt?k property value-k t?rl?s?t a
      lesz?rmazottakn?l. A CIP alapj?n t?rt?n? meghat?roz?s nem m?k?dik. */

      r_cip_id    nit_ci_property_values.cip_id%TYPE;
      r_cip_value nit_ci_property_values.VALUE%TYPE;

      CURSOR c_is_leaf(p_cip_id IN nit_ci_property_values.cip_id%TYPE, p_value IN nit_ci_property_values.VALUE%TYPE) IS
         SELECT 'X'
         FROM   nit_ci_property_values cipv
         WHERE  cipv.VALUE = p_value AND
                cipv.cip_id IN
                (SELECT id
                 FROM   nit_ci_properties cip
                 WHERE  cip.is_inherited = 'Y'
                 CONNECT BY PRIOR cip.id = cip.cip_id
                 START  WITH cip.cip_id = p_cip_id) AND
                rownum = 1;
      v_is_leaf CHAR;

      pl_subprg_name VARCHAR2(30) := 'IS_LEAF';
   BEGIN
      SELECT cip_id
            ,VALUE
      INTO   r_cip_id
            ,r_cip_value
      FROM   nit_ci_property_values
      WHERE  id = p_id;

      OPEN c_is_leaf(r_cip_id
                    ,r_cip_value);
      FETCH c_is_leaf
         INTO v_is_leaf;
      CLOSE c_is_leaf;

      SELECT nvl2(v_is_leaf
                 ,'N'
                 ,'Y')
      INTO   v_is_leaf
      FROM   dual;

      RETURN v_is_leaf;
      /*
            RETURN nit_ci_properties_p.is_leaf(r_cip_id);
      */

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;

   -------------------------------------------------------------------------------------------------------------------------------------------
   FUNCTION is_default_value(p_id IN nit_ci_property_values.id%TYPE) RETURN CHAR IS
      cipv_def       nit_ci_property_values.is_default%TYPE;
      pl_subprg_name VARCHAR2(30) := 'IS_DEFAULT_VALUE';
   BEGIN
      SELECT is_default
      INTO   cipv_def
      FROM   nit_ci_property_values cipv
      WHERE  cipv.id = p_id;

      RETURN cipv_def;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;
   END;

   -------------------------------------------------------------------------------------------------------------------------------------------

   FUNCTION is_inherited(p_id IN nit_ci_property_values.id%TYPE) RETURN CHAR IS
      pl_subprg_name VARCHAR2(30) := 'IS_INHERITED';
      cip_rec        nit_ci_properties%ROWTYPE;
      cipv_rec       nit_ci_property_values%ROWTYPE;
      my_id          nit_ci_property_values.id%TYPE;
   BEGIN
      <<cipv_existance_check>>
      BEGIN
         SELECT *
         INTO   cipv_rec
         FROM   nit_ci_property_values cipv
         WHERE  cipv.id = p_id;

      EXCEPTION
         WHEN no_data_found THEN
            RETURN NULL;
         WHEN OTHERS THEN
            nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                     ,dbms_utility.format_call_stack
                                     ,dbms_utility.format_error_stack
                                     ,'Y'
                                     ,pl_module
                                     ,pl_version
                                     ,pl_subprg_name
                                     ,'#' || p_id);
            RAISE;
      END cipv_existance_check;

      <<cip_existance_check>>
      BEGIN
         SELECT *
         INTO   cip_rec
         FROM   nit_ci_properties cip
         WHERE  cip.id = cipv_rec.cip_id;
      EXCEPTION
         WHEN no_data_found THEN
            RETURN NULL;
         WHEN OTHERS THEN
            nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                     ,dbms_utility.format_call_stack
                                     ,dbms_utility.format_error_stack
                                     ,'Y'
                                     ,pl_module
                                     ,pl_version
                                     ,pl_subprg_name
                                     ,'#' || p_id);
            RAISE;
      END cip_existance_check;

      -- Ha a CIP nem ?r?k?lt akkor a CIPV se, ha a CIP ?r?k?lt, akkor a CIPV vagy ?r?k?lt, vagy nem...
      IF (cip_rec.is_inherited = 'N') THEN
         RETURN 'N';
      END IF;

      SELECT cip2.id
      INTO   my_id
      FROM   (SELECT cip_id
              FROM   nit_ci_property_values cipv
              WHERE  cipv.cip_id = cip_rec.cip_id_ancient AND
                     cipv.VALUE = cipv_rec.VALUE) cips
            ,nit_ci_properties cip2
      WHERE  cips.cip_id = cip2.id AND
             cip2.cipt_id = cip_rec.cipt_id;
      -- Ebben a selectben annyi volt a logika, hogyha pont ?n vagyok az ?s, akkor ?n nem vagyok ?r?k?lt..
      RETURN 'Y';

   EXCEPTION
      WHEN no_data_found THEN
         RETURN 'N';
      WHEN too_many_rows THEN
         RETURN 'Y';
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;
   END;

   ----------------------------------------------------------------------------------------------------------------------------------

   PROCEDURE sort_all(p_attr      IN VARCHAR2
                     ,p_direction IN VARCHAR2) IS
      my_num         nit_ci_types.order_in_list%TYPE;
      pl_subprg_name VARCHAR2(30) := 'SORT_ALL';
      CURSOR cur_parents IS
         SELECT DISTINCT cip1.id
         FROM   nit_ci_properties cip1;
      cur_children SYS_REFCURSOR;
      cur_rec_c    nit_ci_property_values%ROWTYPE;
   BEGIN
      FOR cur_rec_p IN cur_parents
      LOOP
         my_num := 1;
         OPEN cur_children FOR 'SELECT * FROM nit_CI_PROPERTY_VALUES CIV WHERE CIV.CIP_ID = :P_CIP_ID ORDER BY :p_attr :p_order FOR UPDATE;'
            USING cur_rec_p.id, p_attr, p_direction;
         LOOP
            FETCH cur_children
               INTO cur_rec_c;
            EXIT WHEN cur_children%NOTFOUND;
            UPDATE nit_ci_property_values civ2
            SET    civ2.order_in_list = my_num
            WHERE  civ2.id = cur_rec_c.id;
            my_num := my_num + 1;
         END LOOP;
         CLOSE cur_children;
      END LOOP;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_attr || '#' || p_direction);
         RAISE;
   END;
   ----------------------------------------------------------------------------------------------------------------------------------

   PROCEDURE sort_current_level(p_attr      IN VARCHAR2
                               ,p_direction IN VARCHAR2
                               ,from_id     IN nit_ci_properties.id%TYPE) IS
      my_num         nit_ci_types.order_in_list%TYPE;
      pl_subprg_name VARCHAR2(30) := 'SORT_CURRENT_LEVEL';
      CURSOR cur_parents IS
         SELECT DISTINCT cip.id
         FROM   nit_ci_properties cip
         WHERE  cip.cip_id_ancient = from_id;
      cur_children SYS_REFCURSOR;
      cur_rec_c    nit_ci_property_values%ROWTYPE;
   BEGIN
      FOR cur_rec_p IN cur_parents
      LOOP
         my_num := 1;
         OPEN cur_children FOR 'SELECT * FROM nit_CI_PROPERTY_VALUES CIV WHERE CIV.CIP_ID = :P_CIP_ID ORDER BY :p_attr :p_order FOR UPDATE;'
            USING cur_rec_p.id, p_attr, p_direction;
         LOOP
            FETCH cur_children
               INTO cur_rec_c;
            EXIT WHEN cur_children%NOTFOUND;
            UPDATE nit_ci_property_values cip
            SET    cip.order_in_list = my_num
            WHERE  cip.id = cur_rec_c.id;
            my_num := my_num + 1;
         END LOOP;
         CLOSE cur_children;
      END LOOP;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_attr || '#' || p_direction);
         RAISE;

   END;

   FUNCTION get_default_value(p_id IN nit_ci_properties.id%TYPE) RETURN VARCHAR2 IS
      pl_subprg_name VARCHAR2(30) := 'GET_DEFAULT_VALUE';
      cipv_value     nit_ci_property_values.VALUE%TYPE;
   BEGIN
      SELECT VALUE
      INTO   cipv_value
      FROM   nit_ci_property_values cipv
      WHERE  cipv.cip_id = p_id AND
             is_default = 'Y'
      FOR    UPDATE;

      RETURN cipv_value; -- Ekkor van default ?s csak 1 db. Azaz minden rendben van

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN too_many_rows THEN
         -- T?bb default ?rt?k van -> tilos, leszedj?k mindr?l...
         UPDATE nit_ci_property_values cipv
         SET    is_default = 'N'
         WHERE  cipv.cip_id = p_id; -- A legels? order-? elem lesz a default
         RETURN get_default_value(p_id); -- Visszat?r?nk az eredeti k?dhoz ?s ?jrapr?b?ljuk...

      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;
   ----------------------------------------------------------------------------------------------------------------------------------

   FUNCTION has_default_value(p_id IN nit_ci_properties.id%TYPE) RETURN CHAR IS
      pl_subprg_name VARCHAR2(30) := 'GET_DEFAULT_VALUE';
      cipv_id        nit_ci_property_values.id%TYPE;
   BEGIN
      SELECT id
      INTO   cipv_id
      FROM   nit_ci_property_values cipv
      WHERE  cipv.cip_id = p_id AND
             is_default = 'Y';

      RETURN 'Y';

   EXCEPTION
      WHEN no_data_found THEN
         RETURN 'N';
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;

   -- ?sszes gyermek?t updateli egy menetben, azaz nem kell, vagy nem szabad rekurz?van h?vatni.
   -- Ne szerepeljen ilyen form?ban automatikus a Designer TableAPI-ban!
   -- Ha m?gis azt szeretn?nk, hogy szintenk?nt menjen, akkor el?g ?t?rtni a get_children h?v?st get_direct_children-re!
   PROCEDURE cascade_ins(p_rec IN cg$nit_ci_property_values.cg$row_type
                        ,p_ind IN cg$nit_ci_property_values.cg$ind_type) IS
      pl_subprg_name VARCHAR2(30) := 'cascade_del';
      c_rec          cg$nit_ci_property_values.cg$row_type;
      c_ind          cg$nit_ci_property_values.cg$ind_type;
      cip_coll       nit_ci_properties_ct := nit_ci_properties_p.get_children(p_rec.cip_id);
      i              PLS_INTEGER;
   BEGIN
      IF (cip_coll IS NOT NULL) THEN
         IF (cip_coll.COUNT > 0) THEN
            i := cip_coll.FIRST;
         ELSE
            RETURN;
         END IF;
         WHILE (i IS NOT NULL)
         LOOP
            c_rec        := p_rec;
            c_ind        := p_ind;
            c_ind.id     := TRUE;
            c_rec.cip_id := cip_coll(i).id;
            SELECT nit_seq.NEXTVAL
            INTO   c_rec.id
            FROM   dual;
            cg$nit_ci_property_values.ins(c_rec
                                         ,c_ind
                                         ,TRUE);
            i := cip_coll.NEXT(i);
         END LOOP;
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;

   PROCEDURE pre_ins(p_rec cg$nit_ci_property_values.cg$row_type
                    ,p_ind cg$nit_ci_property_values.cg$ind_type) IS
      cipt_name      nit_ci_property_types.NAME%TYPE;
      count_cipv     NUMBER;
      pl_subprg_name VARCHAR2(30) := 'pre_ins';

      CURSOR c_cipt_name(p_cip_id IN nit_ci_property_values.cip_id%TYPE) IS
         SELECT cipt.NAME
         FROM   nit_ci_properties     cip
               ,nit_ci_property_types cipt
         WHERE  cip.id = p_cip_id AND
                cip.cipt_id = cipt.id;
      CURSOR c_count_cipv(p_cip_id IN nit_ci_property_values.cip_id%TYPE) IS
         SELECT COUNT(*)
         FROM   nit_ci_property_values cipv
         WHERE  cipv.cip_id = p_cip_id;

   BEGIN
      OPEN c_cipt_name(p_rec.cip_id);
      FETCH c_cipt_name
         INTO cipt_name;
      CLOSE c_cipt_name;

      IF (cipt_name LIKE nit_core_p.getp('installation step') || '%') THEN
         OPEN c_count_cipv(p_rec.cip_id);
         FETCH c_count_cipv
            INTO count_cipv;
         CLOSE c_count_cipv;

         IF (count_cipv > 0) THEN
            nit_error_p.error('NIT-00072'
                             ,'E'
                             ,TRUE
                             ,NULL
                             ,NULL
                             ,NULL
                             ,p_rec.id);
         END IF;
      END IF;
   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;

   PROCEDURE pre_del(p_pk_rec cg$nit_ci_property_values.cg$pk_type) IS
      pl_subprg_name VARCHAR2(30) := 'pre_del';
      cipt_name      nit_ci_property_types.NAME%TYPE;
      old_rec        cg$nit_ci_property_values.cg$row_type;
      cia_pk_rec     cg$nit_ci_attributes.cg$pk_type;

      CURSOR c_cipt_name(p_cip_id IN nit_ci_property_values.cip_id%TYPE) IS
         SELECT cipt.NAME
         FROM   nit_ci_properties     cip
               ,nit_ci_property_types cipt
         WHERE  cip.id = p_cip_id AND
                cip.cipt_id = cipt.id;
      CURSOR c_cia_id(p_cipv_id IN nit_ci_property_values.id%TYPE) IS
         SELECT cia.id
         FROM   nit_ci_attributes cia
         WHERE  cia.obsolete = 'L' AND
                cia.cipv_id = p_cipv_id;
   BEGIN
      old_rec.id := p_pk_rec.id;
      cg$nit_ci_property_values.slct(old_rec);

      OPEN c_cipt_name(old_rec.cip_id);
      FETCH c_cipt_name
         INTO cipt_name;
      CLOSE c_cipt_name;

      IF (cipt_name LIKE nit_core_p.getp('installation step') || '%') THEN
         FOR cia_id_rec IN c_cia_id(p_pk_rec.id)
         LOOP
            cia_pk_rec.the_rowid := NULL;
            cia_pk_rec.id        := cia_id_rec.id;

            cg$nit_ci_attributes.called_from_package := FALSE;
            cg$nit_ci_attributes.del(cia_pk_rec);
         END LOOP;
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_pk_rec.id);
         RAISE;
   END;

   -- ?sszes gyermek?t updateli egy menetben, azaz nem kell, vagy nem szabad rekurz?van h?vatni.
   -- Ne szerepeljen ilyen form?ban automatikus a Designer TableAPI-ban!
   -- Ha m?gis azt szeretn?nk, hogy szintenk?nt menjen, akkor el?g ?t?rtni a get_children h?v?st get_direct_children-re!

   /* Orb?n Tam?s: felvettem egy param?tert, ez az eredeti value ?rt?k. Ha ezt nem adja ?t,
   a get_children az ?j value alapj?n ?ll?tja ?ssze a cascade update-re sz?nt kollekci?t */
   PROCEDURE cascade_upd(p_rec       IN cg$nit_ci_property_values.cg$row_type
                        ,p_ind       IN cg$nit_ci_property_values.cg$ind_type
                        ,p_old_value IN nit_ci_property_values.VALUE%TYPE) IS
      pl_subprg_name VARCHAR2(30) := 'cascade_del';
      c_rec          cg$nit_ci_property_values.cg$row_type;
      c_ind          cg$nit_ci_property_values.cg$ind_type;
      cipv_id_coll   nit_num_ct;
      i              PLS_INTEGER;
      cipt_name      nit_ci_property_types.NAME%TYPE;
      cia_rec        cg$nit_ci_attributes.cg$row_type;
      cia_ind        cg$nit_ci_attributes.cg$ind_type;

      CURSOR c_cipt_name(p_cip_id IN nit_ci_property_values.cip_id%TYPE) IS
         SELECT cipt.NAME
         FROM   nit_ci_properties     cip
               ,nit_ci_property_types cipt
         WHERE  cip.id = p_cip_id AND
                cip.cipt_id = cipt.id;
      CURSOR c_cia_id(p_cipv_id IN nit_ci_property_values.id%TYPE) IS
         SELECT cia.id
         FROM   nit_ci_attributes cia
         WHERE  cia.obsolete = 'L' AND
                cia.cipv_id = p_cipv_id;
   BEGIN
      cipv_id_coll := get_children(p_rec.id
                                  ,p_old_value);
      IF (cipv_id_coll IS NOT NULL) THEN
         IF (cipv_id_coll.COUNT > 0) THEN
            i := cipv_id_coll.FIRST;
         ELSE
            RETURN;
         END IF;

         c_ind               := p_ind;
         c_ind.order_in_list := FALSE;
         WHILE (i IS NOT NULL)
         LOOP
            c_rec           := p_rec;
            c_rec.id        := cipv_id_coll(i);
            c_rec.the_rowid := NULL;
            cg$nit_ci_property_values.upd(c_rec
                                         ,c_ind
                                         ,TRUE);
            i := cipv_id_coll.NEXT(i);
         END LOOP;
      END IF;

      -- CIA update (installation steps)
      OPEN c_cipt_name(p_rec.cip_id);
      FETCH c_cipt_name
         INTO cipt_name;
      CLOSE c_cipt_name;

      IF (cipt_name LIKE nit_core_p.getp('installation step') || '%') THEN
         FOR cia_id_rec IN c_cia_id(p_rec.id)
         LOOP
            cia_rec.the_rowid := NULL;
            cia_rec.id        := cia_id_rec.id;

            cg$nit_ci_attributes.slct(cia_rec);
            cia_rec.data := p_rec.VALUE;
            cia_ind.data := TRUE;

            cg$nit_ci_attributes.called_from_package := FALSE;
            cg$nit_ci_attributes.upd(cia_rec
                                    ,cia_ind);
         END LOOP;
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;


   -- ?sszes gyermek?t t?rni egy menetben, azaz nem kell, vagy nem szabad rekurz?van h?vatni.
   -- Ne szerepeljen ilyen form?ban automatikus a Designer TableAPI-ban!
   -- Ha m?gis azt szeretn?nk, hogy szintenk?nt menjen, akkor el?g ?t?rtni a get_children h?v?st get_direct_children-re!
   PROCEDURE cascade_del(p_id IN nit_ci_property_values.id%TYPE) IS
      pl_subprg_name VARCHAR2(30) := 'cascade_del';
      c_pk           cg$nit_ci_property_values.cg$pk_type;
      cipv_id_coll   nit_num_ct := get_children(p_id);
      i              PLS_INTEGER;
   BEGIN
      IF (cipv_id_coll IS NOT NULL) THEN
         IF (cipv_id_coll.COUNT > 0) THEN
            i := cipv_id_coll.FIRST;
         ELSE
            RETURN;
         END IF;

         WHILE (i IS NOT NULL)
         LOOP
            c_pk.id := cipv_id_coll(i);
            cg$nit_ci_property_values.del(c_pk
                                         ,TRUE);
            i := cipv_id_coll.NEXT(i);
         END LOOP;
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;
   END;
BEGIN
   nit_card_p.log(pl_module
                 ,pl_version);
END nit_ci_property_values_p;
/

prompt
prompt Creating package body NIT_CI_RELATIONS_P
prompt ========================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_ci_relations_p IS
   pl_version CONSTANT VARCHAR2(12) := '0.0.2.19';
   pl_module  CONSTANT VARCHAR2(30) := 'nit_ci_relations_p';

   FUNCTION package_version RETURN VARCHAR2 IS
   BEGIN
      RETURN pl_module || ' ' || pl_version;
   END;

   FUNCTION get_relation_type(p_id IN nit_ci_relations.id%TYPE) RETURN VARCHAR2 IS
      ret nit_cit_relation_types.NAME%TYPE;
   BEGIN
      SELECT citrt.NAME
      INTO   ret
      FROM   nit_cit_relation_types citrt
            ,nit_ci_type_relations  citr
            ,nit_ci_types           cit_from
            ,nit_ci_types           cit_to
            ,nit_config_items       ci_from
            ,nit_config_items       ci_to
            ,nit_ci_relations       cir
      WHERE  cir.id = p_id AND
             cir.ci_id_from = ci_from.id AND
             cir.ci_id_to = ci_to.id AND
             citr.cit_id_from = ci_from.cit_id AND
             citr.cit_id_to = ci_to.cit_id AND
             citr.citrt_id = citrt.id;

      RETURN ret;
   END;

   PROCEDURE archiving(p_rec     IN OUT cg$nit_ci_relations.cg$row_type
                      ,p_old_rec IN OUT cg$nit_ci_relations.cg$row_type) IS
      -- p_rec az ?j rekord..
      -- p_old_rec -et fogjuk archiv?lni
      pl_subprg_name VARCHAR2(30) := 'archiving';
      l_opn_rec      cg$nit_operations.cg$row_type;
      l_need_op_fail BOOLEAN := TRUE;
      l_need_op_stop BOOLEAN := FALSE;
      l_old_ind      cg$nit_ci_relations.cg$ind_type;
   BEGIN
      IF (p_old_rec.obsolete <> 'L') THEN
         RETURN;
      END IF;

      <<check_op>>
      BEGIN
         l_opn_rec.id := p_rec.opn_id;
         -- ezzek az oper?ci?val fogom learchiv?lni a rekordomat
         cg$nit_operations.slct(l_opn_rec);
         -- Ha sikeres, akkor ok nek?nk...
      EXCEPTION
         WHEN no_data_found THEN
            -- Azaz van valami ID a p_rec-ben opn_idk?nt, de az semmi se...
            p_rec.opn_id   := nit_operations_p.start_inner_operation;
            l_need_op_stop := TRUE;
            -- Namost ;)
            l_opn_rec.id := p_rec.opn_id;
            -- ezzek az oper?ci?val fogom learchiv?lni a rekordomat
            cg$nit_operations.slct(l_opn_rec);
         WHEN OTHERS THEN
            IF (l_need_op_fail) THEN
               nit_operations_p.fail_operation(l_opn_rec.id);
            END IF;

            nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                     ,dbms_utility.format_call_stack
                                     ,dbms_utility.format_error_stack
                                     ,'Y'
                                     ,pl_module
                                     ,pl_version
                                     ,pl_subprg_name
                                     ,'#' || p_rec.id);
            RAISE;
      END check_op;

      -- Ok, oper?ci?nk ?gy vagy ?gy, de megvan...
      p_old_rec.valid_until := nit_core_p.push_back(l_opn_rec.op_time);
      -- Beallitjuk a flaget
      p_old_rec.obsolete := 'A';
      p_old_rec.opn_id   := p_rec.opn_id;
      l_old_ind.obsolete := TRUE;

      /* Orb?n Tam?s: az elj?r?s elvileg csak archiv?l, az oper?ci?kezel?s miatt azonban
      ide tartozik az al?bbi: */
      p_rec.valid_from := l_opn_rec.op_time;

      SELECT nit_seq.NEXTVAL
      INTO   p_old_rec.id
      FROM   dual;

      cg$nit_ci_relations.ins(p_old_rec
                             ,l_old_ind);

      -- Ha mi ind?tottuk az oper?ci?t, akkor korrekten le is fogjuk ?ll?tani
      IF (l_need_op_stop) THEN
         nit_operations_p.stop_operation(l_opn_rec.id);
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         IF (l_need_op_fail) THEN
            nit_operations_p.fail_operation(l_opn_rec.id);
         END IF;

         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;

   PROCEDURE pre_dml(p_rec IN OUT cg$nit_ci_relations.cg$row_type
                    ,p_ind IN OUT cg$nit_ci_relations.cg$ind_type
                    ,p_op  IN VARCHAR2) IS
      pl_subprg_name VARCHAR2(30) := 'pre_dml';
      ci_rec_from    cg$nit_config_items.cg$row_type;
      ci_rec_to      cg$nit_config_items.cg$row_type;
      cir_rec        nit_ci_relations%ROWTYPE;
   BEGIN
      IF (p_op <> 'INS' AND p_op <> 'UPD') THEN
         RETURN;
      END IF;

      nit_core_p.set_validity(p_rec.valid_from
                             ,p_rec.valid_until
                             ,p_rec.opn_id);
      ci_rec_from.id := p_rec.ci_id_from;
      ci_rec_to.id   := p_rec.ci_id_to;
      cg$nit_config_items.slct(ci_rec_from);
      cg$nit_config_items.slct(ci_rec_to);

      IF ((p_op = 'UPD') AND
         (ci_rec_from.obsolete <> 'L' OR ci_rec_to.obsolete <> 'L')) THEN
         nit_error_p.error('NIT-00030'
                          ,'E'
                          ,TRUE
                          ,ci_rec_from.NAME
                          ,ci_rec_to.NAME
                          ,NULL
                          ,p_rec.id);
      END IF;

      IF (p_op = 'INS') THEN
         p_ind.id            := TRUE;
         p_ind.creation_date := TRUE;
         p_ind.created_by    := TRUE;

         /* Orb?n Tam?s: az obsolete ellen?rz?se is kell: mi van archiv?l?skor? */
         IF (p_rec.obsolete = 'L') THEN
            DECLARE
               CURSOR c_cir_exists IS
                  SELECT 'X'
                  FROM   nit_ci_relations cir
                  WHERE  cir.ci_id_from = p_rec.ci_id_from AND
                         cir.ci_id_to = p_rec.ci_id_to AND
                         cir.citr_id = p_rec.citr_id AND
                         cir.obsolete = 'L';
               CURSOR c_cipt_name(p_citr_id IN nit_ci_relations.citr_id%TYPE) IS
                  SELECT citrt.NAME
                  FROM   nit_ci_type_relations  citr
                        ,nit_cit_relation_types citrt
                  WHERE  citr.citrt_id = citrt.id AND
                         citr.id = p_citr_id;
               v_exists    CHAR;
               v_citr_name nit_cit_relation_types.NAME%TYPE;
            BEGIN
               -- van m?r ?l? rel?ci?
               OPEN c_cir_exists;
               FETCH c_cir_exists
                  INTO v_exists;
               CLOSE c_cir_exists;

               IF (v_exists IS NOT NULL) THEN
                  nit_error_p.error('NIT-00029'
                                   ,'E'
                                   ,TRUE
                                   ,ci_rec_from.NAME
                                   ,ci_rec_to.NAME
                                   ,NULL
                                   ,p_rec.id);
               END IF;

               -- contains, installed on eset?n a kapcsolt CI pozici?ja m?dosulhat
               OPEN c_cipt_name(p_rec.citr_id);
               FETCH c_cipt_name
                  INTO v_citr_name;
               CLOSE c_cipt_name;

               IF (v_citr_name IS NOT NULL AND
                  (v_citr_name =
                  nit_cit_relation_types_p.get_contains_rel_name OR
                  v_citr_name =
                  nit_cit_relation_types_p.get_installed_on_rel_name)) THEN
                  DECLARE
                     CURSOR c_psn_id(p_ci_id IN nit_positions.ci_id%TYPE) IS
                        SELECT psn.id
                        FROM   nit_positions psn
                        WHERE  psn.ci_id = p_ci_id AND
                               psn.obsolete = 'L';
                     v_psn_from_rec cg$nit_positions.cg$row_type;
                     v_psn_to_rec   cg$nit_positions.cg$row_type;
                     v_psn_ind      cg$nit_positions.cg$ind_type;
                  BEGIN
                     -- CI From lcn_id keres?se
                     OPEN c_psn_id(ci_rec_from.id);
                     FETCH c_psn_id
                        INTO v_psn_from_rec.id;
                     CLOSE c_psn_id;
                     IF (v_psn_from_rec.id IS NOT NULL) THEN
                        cg$nit_positions.slct(v_psn_from_rec);
                     ELSE
                        RAISE no_data_found;
                     END IF;

                     -- CI To lcn_id keres?se
                     OPEN c_psn_id(ci_rec_to.id);
                     FETCH c_psn_id
                        INTO v_psn_to_rec.id;
                     CLOSE c_psn_id;
                     IF (v_psn_to_rec.id IS NOT NULL) THEN
                        cg$nit_positions.slct(v_psn_to_rec);
                     ELSE
                        RAISE no_data_found;
                     END IF;

                     IF (v_psn_from_rec.lcn_id <> v_psn_to_rec.lcn_id) THEN
                        -- update
                        v_psn_ind := cg$nit_positions.cg$ind_true;

                        IF (v_citr_name =
                           nit_cit_relation_types_p.get_contains_rel_name) THEN
                           v_psn_to_rec.lcn_id := v_psn_from_rec.lcn_id;
                           v_psn_to_rec.opn_id := p_rec.opn_id;

                           cg$nit_positions.upd(v_psn_to_rec
                                               ,v_psn_ind);
                        ELSE
                           -- v_citr_name = nit_cit_relation_types_p.installed_on_rel_name
                           v_psn_from_rec.lcn_id := v_psn_to_rec.lcn_id;
                           v_psn_from_rec.opn_id := p_rec.opn_id;

                           cg$nit_positions.upd(v_psn_from_rec
                                               ,v_psn_ind);

                        END IF;
                     END IF;
                  END;
               END IF;

            EXCEPTION
               WHEN OTHERS THEN
                  nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                           ,dbms_utility.format_call_stack
                                           ,dbms_utility.format_error_stack
                                           ,'Y'
                                           ,pl_module
                                           ,pl_version
                                           ,pl_subprg_name
                                           ,'#' || p_rec.id);
                  RAISE;
            END;
         END IF;
      END IF;

      -- A BL szerinti UNIQUE biztos?t?sa, amit SQL-b?l lehetetlen kiadni
      IF (p_op = 'UPD') THEN

         /* Orb?n Tam?s: az obsolete ellen?rz?se is kell: mi van t?rl?skor? */
         IF (p_rec.obsolete = 'L') THEN
            <<is_there_dependants_upd>>
            BEGIN
               SELECT *
               INTO   cir_rec
               FROM   nit_ci_relations cir
               WHERE  cir.ci_id_from = p_rec.ci_id_from AND
                      cir.ci_id_to = p_rec.ci_id_to AND
                      cir.citr_id = p_rec.citr_id AND
                      cir.obsolete = 'L' AND
                      cir.id <> p_rec.id;

               nit_error_p.error('NIT-00029'
                                ,'E'
                                ,TRUE
                                ,ci_rec_from.NAME
                                ,ci_rec_to.NAME
                                ,NULL
                                ,p_rec.id);
            EXCEPTION
               WHEN no_data_found THEN
                  NULL;
               WHEN OTHERS THEN
                  nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                           ,dbms_utility.format_call_stack
                                           ,dbms_utility.format_error_stack
                                           ,'Y'
                                           ,pl_module
                                           ,pl_version
                                           ,pl_subprg_name
                                           ,'#' || p_rec.id);
                  RAISE;
            END;
         END IF;
      END IF;

      p_ind.last_update_date := TRUE;
      p_ind.last_updated_by  := TRUE;
      p_ind.status           := TRUE;
      p_ind.obsolete         := TRUE;
      p_ind.valid_from       := TRUE;
      p_ind.valid_until      := TRUE;
      nit_core_p.set_audit(p_rec.creation_date
                          ,p_rec.created_by
                          ,p_rec.last_update_date
                          ,p_rec.last_updated_by
                          ,p_op);

      /* TODO : rakt?ron lev? CI rel?ci?ja m?dosithat?-e emergency opn. eset?n ??? */

      IF (ci_rec_from.status = nit_core_p.ci_statuses(nit_core_p.ci_eol_idx) OR
         ci_rec_from.status =
         nit_core_p.ci_statuses(nit_core_p.ci_in_stock_idx)) THEN
         nit_error_p.error('NIT-00047'
                          ,'E'
                          ,TRUE
                          ,ci_rec_from.NAME
                          ,ci_rec_from.status
                          ,NULL
                          ,NULL);
      END IF;

      IF (ci_rec_to.status = nit_core_p.ci_statuses(nit_core_p.ci_eol_idx) OR
         ci_rec_to.status = nit_core_p.ci_statuses(nit_core_p.ci_in_stock_idx)) THEN
         nit_error_p.error('NIT-00047'
                          ,'E'
                          ,TRUE
                          ,ci_rec_to.NAME
                          ,ci_rec_to.status
                          ,NULL
                          ,NULL);
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;

   PROCEDURE pre_upd(p_rec IN OUT cg$nit_ci_relations.cg$row_type
                    ,p_ind IN OUT cg$nit_ci_relations.cg$ind_type) IS
      l_old_rec      cg$nit_ci_relations.cg$row_type;
      opn_rec        cg$nit_operations.cg$row_type;
      pl_subprg_name VARCHAR2(30) := 'pre_upd';
   BEGIN
      l_old_rec.id := p_rec.id;
      cg$nit_ci_relations.slct(l_old_rec);

      opn_rec.id := p_rec.opn_id;
      cg$nit_operations.slct(opn_rec);

      IF (l_old_rec.obsolete <> 'L') THEN
         nit_error_p.error('NIT-00031'
                          ,'E'
                          ,TRUE
                          ,NULL
                          ,NULL
                          ,NULL
                          ,p_rec.id);
      END IF;

      IF (nit_core_p.is_allowed_obsolete_chg(l_old_rec.obsolete
                                            ,p_rec.obsolete) = 'N') THEN
         nit_error_p.error('NIT-00027'
                          ,'E'
                          ,TRUE
                          ,l_old_rec.obsolete
                          ,p_rec.obsolete
                          ,NULL
                          ,p_rec.id);
      END IF;

      IF (opn_rec.type_name =
         nit_operations_p.operation_types(nit_operations_p.requested_idx) AND
         nit_core_p.is_allowed_ci_props_status_chg(l_old_rec.status
                                                   ,p_rec.status) = 'N') THEN
         nit_error_p.error('NIT-00028'
                          ,'E'
                          ,TRUE
                          ,l_old_rec.status
                          ,p_rec.status
                          ,NULL
                          ,p_rec.id);
      END IF;

      IF (p_ind.ci_id_from OR p_ind.ci_id_to OR p_ind.citr_id OR p_ind.status OR
         p_ind.obsolete OR p_ind.valid_from OR p_ind.valid_until) THEN
         archiving(p_rec
                  ,l_old_rec);
      END IF;

      p_ind.opn_id     := FALSE;
      p_ind.valid_from := TRUE;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;

   PROCEDURE create_cir(p_ci_id nit_config_items.id%TYPE) IS
      pl_subprg_name VARCHAR2(30) := 'create_cir';
      ci_rec         cg$nit_config_items.cg$row_type;
      cg$cir_rec     cg$nit_ci_relations.cg$row_type;
      cg$cir_ind     cg$nit_ci_relations.cg$ind_type := cg$nit_ci_relations.cg$ind_true;

      CURSOR c_cir(p_ci_id IN nit_config_items.id%TYPE, p_cit_id IN nit_config_items.cit_id%TYPE, p_resource_id IN INTEGER) IS
         SELECT ci_id_from
               ,citr_id
               ,ci_id_to
               ,least(ci_from.valid_from
                     ,ci_to.valid_from) AS valid_from
         FROM   (SELECT *
                 FROM   (SELECT ci_from.id AS ci_id_from
                               ,citr.id    AS citr_id
                               ,p_ci_id    AS ci_id_to
                         FROM   (SELECT id
                                       ,cit_id
                                       ,valid_from
                                 FROM   nit_config_items
                                 WHERE  nit_importer_p.get_resource_id(sms_id) =
                                        p_resource_id AND
                                        obsolete = 'L') ci_from
                               ,(SELECT /*+ PARALLEL_INDEX(ni_ci_types NIT_CPK_CIT DEFAULT) */
                                  id
                                 FROM   nit_ci_types
                                 WHERE  is_importable = 'Y') cit_from
                               ,nit_ci_type_relations citr
                         WHERE  ci_from.cit_id = cit_from.id AND
                                cit_from.id = citr.cit_id_from AND
                                citr.cit_id_to = p_cit_id AND
                                citr.citrt_id IN
                                (SELECT id
                                 FROM   nit_cit_relation_types citrt
                                 WHERE  citrt.NAME = 'connected to' OR
                                        citrt.NAME = 'contains' OR
                                        citrt.NAME = 'installed on' OR
                                        citrt.NAME = 'provides')
                         UNION
                         SELECT p_ci_id
                               ,citr.id
                               ,ci_to.id
                         FROM   nit_ci_type_relations citr
                               ,(SELECT id
                                       ,cit_id
                                       ,valid_from
                                 FROM   nit_config_items
                                 WHERE  nit_importer_p.get_resource_id(sms_id) =
                                        p_resource_id AND
                                        obsolete = 'L') ci_to
                               ,(SELECT /*+ PARALLEL_INDEX(ni_ci_types NIT_CPK_CIT DEFAULT) */
                                  id
                                 FROM   nit_ci_types
                                 WHERE  is_importable = 'Y') cit_to
                         WHERE  citr.cit_id_from = p_cit_id AND
                                ci_to.cit_id = cit_to.id AND
                                cit_to.id = citr.cit_id_to AND
                                citr.citrt_id IN
                                (SELECT id
                                 FROM   nit_cit_relation_types citrt
                                 WHERE  citrt.NAME = 'connected to' OR
                                        citrt.NAME = 'contains' OR
                                        citrt.NAME = 'installed on' OR
                                        citrt.NAME = 'provides'))
                 MINUS (SELECT cir.ci_id_from
                             ,cir.citr_id
                             ,cir.ci_id_to
                       FROM   nit_ci_relations cir
                       WHERE  (cir.ci_id_from = p_ci_id OR
                              cir.ci_id_to = p_ci_id) AND
                              cir.obsolete = 'L'))
               ,nit_config_items ci_from
               ,nit_config_items ci_to
         WHERE  ci_from.id = ci_id_from AND
                ci_to.id = ci_id_to;

   BEGIN
      ci_rec.id := p_ci_id;
      cg$nit_config_items.slct(ci_rec);

      FOR cir_rec IN c_cir(p_ci_id       => ci_rec.id
                          ,p_cit_id      => ci_rec.cit_id
                          ,p_resource_id => nit_importer_p.get_resource_id(ci_rec.sms_id))
      LOOP
         cg$cir_rec.id         := NULL;
         cg$cir_rec.ci_id_from := cir_rec.ci_id_from;
         cg$cir_rec.citr_id    := cir_rec.citr_id;
         cg$cir_rec.ci_id_to   := cir_rec.ci_id_to;
         cg$cir_rec.status     := 'done';
         cg$cir_rec.obsolete   := 'L';
         cg$cir_rec.valid_from := cir_rec.valid_from;

         cg$nit_ci_relations.called_from_package := FALSE;
         cg$nit_ci_relations.ins(cg$cir_rec
                                ,cg$cir_ind);
      END LOOP;
   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_ci_id);
         RAISE;
   END;

   PROCEDURE create_cir IS
      pl_subprg_name VARCHAR2(30) := 'create_cir';
      cg$cir_rec     cg$nit_ci_relations.cg$row_type;
      cg$cir_ind     cg$nit_ci_relations.cg$ind_type := cg$nit_ci_relations.cg$ind_true;

      CURSOR c_cir IS
         SELECT ci_id_from
               ,citr_id
               ,ci_id_to
               ,least(ci_from.valid_from
                     ,ci_to.valid_from) AS valid_from
         FROM   (SELECT *
                 FROM   (SELECT /*+ ALL_ROWS */
                          ci_from.ci_id AS ci_id_from
                         ,citr.id       AS citr_id
                         ,ci_to.ci_id   AS ci_id_to
                         FROM   (SELECT id AS ci_id
                                       ,nit_importer_p.get_resource_id(sms_id) AS resource_id
                                       ,cit_id
                                 FROM   nit_config_items
                                 WHERE  sms_id IS NOT NULL AND
                                        obsolete = 'L') ci_from
                               ,(SELECT id AS ci_id
                                       ,nit_importer_p.get_resource_id(sms_id) AS resource_id
                                       ,cit_id
                                 FROM   nit_config_items
                                 WHERE  sms_id IS NOT NULL AND
                                        obsolete = 'L') ci_to
                               ,(SELECT /*+ PARALLEL_INDEX(ni_ci_types NIT_CPK_CIT DEFAULT) */
                                  id
                                 FROM   nit_ci_types
                                 WHERE  is_importable = 'Y') cit_from
                               ,(SELECT /*+ PARALLEL_INDEX(ni_ci_types NIT_CPK_CIT DEFAULT) */
                                  id
                                 FROM   nit_ci_types
                                 WHERE  is_importable = 'Y') cit_to
                               ,nit_ci_type_relations citr
                         WHERE  ci_from.cit_id = cit_from.id AND
                                cit_from.id = citr.cit_id_from AND
                                ci_to.cit_id = cit_to.id AND
                                cit_to.id = citr.cit_id_to AND
                                ci_from.resource_id = ci_to.resource_id AND
                                citr.citrt_id IN
                                (SELECT citrt.id
                                 FROM   nit_cit_relation_types citrt
                                 WHERE  citrt.NAME = 'connected to' OR
                                        citrt.NAME = 'contains' OR
                                        citrt.NAME = 'installed on' OR
                                        citrt.NAME = 'provides'))
                 MINUS (SELECT /*+ ALL_ROWS */
                        cir.ci_id_from AS ci_from_id
                       ,cir.citr_id    AS citr_id
                       ,cir.ci_id_to   AS ci_to_id
                       FROM   nit_ci_relations cir
                       WHERE  cir.obsolete = 'L'))
               ,nit_config_items ci_from
               ,nit_config_items ci_to
         WHERE  ci_from.id = ci_id_from AND
                ci_to.id = ci_id_to;
   BEGIN
      FOR cir_rec IN c_cir
      LOOP
         cg$cir_rec.id         := NULL;
         cg$cir_rec.ci_id_from := cir_rec.ci_id_from;
         cg$cir_rec.citr_id    := cir_rec.citr_id;
         cg$cir_rec.ci_id_to   := cir_rec.ci_id_to;
         cg$cir_rec.status     := 'done';
         cg$cir_rec.obsolete   := 'L';
         cg$cir_rec.valid_from := cir_rec.valid_from;

         cg$nit_ci_relations.called_from_package := FALSE;
         cg$nit_ci_relations.ins(cg$cir_rec
                                ,cg$cir_ind);
      END LOOP;
   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#');
         RAISE;
   END;

BEGIN
   nit_card_p.log(pl_module
                 ,pl_version);
END nit_ci_relations_p;
/

prompt
prompt Creating package body NIT_CIT_RELATION_TYPES_P
prompt ==============================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_cit_relation_types_p IS

   pl_version CONSTANT VARCHAR2(12) := '0.0.2.4';
   pl_module  CONSTANT VARCHAR2(30) := 'nit_cit_relation_types_p';

   one_directional_relations nit_string_ct := nit_string_ct('contains'
                                                           ,'installed on');
   bidirectional_relations   nit_string_ct := nit_string_ct('connected to'
                                                           ,'compatible with'
                                                           ,'replaces'
                                                           ,'affects'
                                                           ,'works only with'
                                                           ,'similar to');

   FUNCTION package_version RETURN VARCHAR2 IS
   BEGIN
      RETURN pl_module || ' ' || pl_version;
   END;

   -- CSAK A CASCADE DEL MIATT VAN ITT (SELECT-BEN HIVJUK)
   FUNCTION is_deletable(p_id IN nit_cit_relation_types.id%TYPE) RETURN CHAR IS
      pl_subprg_name VARCHAR2(30) := 'IS_DELETABLE';
      rec_name       nit_cit_relation_types.NAME%TYPE;
   BEGIN
      IF (p_id IS NULL) THEN
         RETURN 'N';
      END IF;

      SELECT NAME
      INTO   rec_name
      FROM   nit_cit_relation_types citrt
      WHERE  citrt.id = p_id;

      IF (rec_name = get_contains_rel_name OR
         rec_name = get_installed_on_rel_name) THEN
         RETURN 'N';
      END IF;

      RETURN 'Y';

   EXCEPTION
      WHEN no_data_found THEN
         RETURN 'N';
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;
   END;

   PROCEDURE pre_dml(p_rec IN OUT cg$nit_cit_relation_types.cg$row_type
                    ,p_ind IN OUT cg$nit_cit_relation_types.cg$ind_type
                    ,p_op  IN VARCHAR2) IS
   BEGIN

      IF (p_op = 'INS') THEN
         p_ind.id            := TRUE;
         p_ind.creation_date := TRUE;
         p_ind.created_by    := TRUE;
         p_ind.NAME          := TRUE;
      END IF;

      IF (p_op = 'INS' OR p_op = 'UPD') THEN
         p_ind.last_update_date := TRUE;
         p_ind.last_updated_by  := TRUE;
         nit_core_p.caseconv(p_rec.NAME);

         nit_core_p.set_audit(p_rec.creation_date
                             ,p_rec.created_by
                             ,p_rec.last_update_date
                             ,p_rec.last_updated_by
                             ,p_op);
      END IF;
   END;

   PROCEDURE cascade_del(p_id IN nit_cit_relation_types.id%TYPE) IS
      pl_subprg_name VARCHAR2(30) := 'CASCADE_DEL';
      citr_rec       cg$nit_ci_type_relations.cg$pk_type;
      CURSOR cur IS
         SELECT id
         FROM   nit_ci_type_relations citr
         WHERE  citr.citrt_id = p_id AND
                nit_cit_relation_types_p.is_deletable(p_id) = 'Y'
         FOR    UPDATE;
   BEGIN
      FOR rec IN cur LOOP
         citr_rec.id := rec.id;
         cg$nit_ci_type_relations.del(citr_rec
                                     ,TRUE);
      END LOOP;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;
   END;

   FUNCTION is_one_directional(p_name IN nit_cit_relation_types.NAME%TYPE)
      RETURN CHAR IS
   BEGIN
      -- Ha lehet berakni 10g only dolgokat, akkor ezt ?rdemesebb egy MEMBER OF h?v?sra kicser?lni.. FIXME
      -- Egy?bk?nt maradjon ?gy.
      RETURN nit_core_p.exists_in(one_directional_relations
                                 ,p_name);
   END;

   FUNCTION is_bidirectional(p_name IN nit_cit_relation_types.NAME%TYPE)
      RETURN CHAR IS
   BEGIN
      -- Ha lehet berakni 10g only dolgokat, akkor ezt ?rdemesebb egy MEMBER OF h?v?sra kicser?lni.. FIXME
      -- Egy?bk?nt maradjon ?gy.
      RETURN nit_core_p.exists_in(bidirectional_relations
                                 ,p_name);
   END;

   PROCEDURE pre_del(p_id IN nit_cit_relation_types.id%TYPE) IS
      l_name nit_locations.NAME%TYPE;
   BEGIN
      IF (is_deletable(p_id) = 'N') THEN
         SELECT NAME
         INTO   l_name
         FROM   nit_locations
         WHERE  id = p_id
         FOR    UPDATE;
         nit_error_p.error('NIT-00004'
                          ,'E'
                          ,TRUE
                          ,l_name
                          ,NULL
                          ,NULL
                          ,p_id);
      END IF;
   END;

   FUNCTION get_contains_rel_name RETURN VARCHAR2 IS
   BEGIN
      RETURN nit_core_p.getp('contains');
   END;

   FUNCTION get_installed_on_rel_name RETURN VARCHAR2 IS
   BEGIN
      RETURN nit_core_p.getp('installed on');
   END;

BEGIN
   nit_card_p.log(pl_module
                 ,pl_version);
END nit_cit_relation_types_p;
/

prompt
prompt Creating package body NIT_CI_TYPE_RELATIONS_P
prompt =============================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_ci_type_relations_p IS
   pl_version CONSTANT VARCHAR2(12) := '0.0.2.4';
   pl_module  CONSTANT VARCHAR2(30) := 'nit_ci_type_relations_p';

   FUNCTION package_version RETURN VARCHAR2 IS
   BEGIN
      RETURN pl_module || ' ' || pl_version;
   END;

   FUNCTION could_bidirectional(p_id IN nit_ci_type_relations.id%TYPE) RETURN CHAR IS
      pl_subprg_name VARCHAR2(30) := 'COULD_BIDIRECTIONAL';
      r_name         nit_cit_relation_types.NAME%TYPE;
   BEGIN
      SELECT NAME
      INTO   r_name
      FROM   nit_ci_type_relations  citr
            ,nit_cit_relation_types citrt
      WHERE  citr.id = p_id AND
             citr.citrt_id = citrt.id;

      RETURN nit_cit_relation_types_p.is_bidirectional(r_name);

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;
   END;

   PROCEDURE set_order(p_rec   IN OUT cg$nit_ci_type_relations.cg$row_type
                      ,p_order IN nit_ci_type_relations.order_in_list%TYPE) IS
      dependant      nit_ci_type_relations.id%TYPE;
      pl_subprg_name VARCHAR2(30) := 'SET_ORDER';
   BEGIN

      IF (p_rec.order_in_list IS NULL AND p_order IS NOT NULL) THEN
         p_rec.order_in_list := p_order;
      ELSIF (p_rec.order_in_list IS NULL AND p_order IS NULL) THEN
         <<order_set>>
         BEGIN
            SELECT NVL(MAX(order_in_list)
                      ,0) + 1
            INTO   p_rec.order_in_list
            FROM   nit_ci_type_relations citr
            WHERE  citr.cit_id_from = p_rec.cit_id_from AND
                   citr.cit_id_to = p_rec.cit_id_to;

         EXCEPTION
            WHEN no_data_found THEN
               p_rec.order_in_list := 1;
               RETURN;
            WHEN OTHERS THEN
               nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                        ,dbms_utility.format_call_stack
                                        ,dbms_utility.format_error_stack
                                        ,'Y'
                                        ,pl_module
                                        ,pl_version
                                        ,pl_subprg_name
                                        ,'#' || p_rec.id || '#' || p_order);
               RAISE;
         END;

      END IF;

      -- Ha nincs az adott sorrendi helyen semmi, akkor odarakjuk magunkat..
      -- Ha van, akkor update...
      -- T?bb nem lehet, csak 1...azaz a TOO_MANY_ROWS-t nem fogja kiv?ltani...
      SELECT id
      INTO   dependant
      FROM   nit_ci_type_relations citr
      WHERE  citr.order_in_list = p_order AND
             citr.cit_id_from = p_rec.cit_id_from AND
             citr.cit_id_to = p_rec.cit_id_to
      FOR    UPDATE;

      -- Szerintem felesleges m?st for-update-elni mert ?gyis azonnal update-?nk, amikor ez lefut..1-2 msec a difi..
      -- ?s nem ID alapon, csak CIT_ID alapon kellene am?gy is z?rolni...
      -- FIXME: Most k?zvetlen?l updatel?nk ?s nem az UPD() fv-en kereszt?l, de ez megbocs?that? itt
      IF (p_rec.id IS NOT NULL) THEN
         UPDATE nit_ci_type_relations citr
         SET    citr.order_in_list = citr.order_in_list + 1
         WHERE  citr.id <> p_rec.id AND
                citr.order_in_list >= p_order AND
                citr.cit_id_from = p_rec.cit_id_from AND
                citr.cit_id_to = p_rec.cit_id_to;
      END IF;

      IF (p_rec.id IS NULL) THEN
         UPDATE nit_ci_type_relations citr
         SET    citr.order_in_list = citr.order_in_list + 1
         WHERE  citr.order_in_list >= p_order AND
                citr.cit_id_from = p_rec.cit_id_from AND
                citr.cit_id_to = p_rec.cit_id_to;
      END IF;
   EXCEPTION
      WHEN no_data_found THEN
         IF (p_order IS NOT NULL) THEN
            p_rec.order_in_list := p_order;
         ELSE
            p_rec.order_in_list := 1;
         END IF;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id || '#' || p_order);
         RAISE;

   END;

   PROCEDURE set_order_before(p_rec IN OUT cg$nit_ci_type_relations.cg$row_type
                             ,p_id  IN nit_ci_type_relations.id%TYPE) IS
      ord            nit_ci_type_relations.order_in_list%TYPE;
      pl_subprg_name VARCHAR2(30) := 'SET_ORDER_BEFORE';
   BEGIN
      SELECT order_in_list
      INTO   ord
      FROM   nit_ci_type_relations citr
      WHERE  id = p_id
      FOR    UPDATE;

      set_order(p_rec
               ,ord);

   EXCEPTION
      WHEN no_data_found THEN
         set_order(p_rec
                  ,1);
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id || '#' || p_id);
         RAISE;

   END;

   PROCEDURE set_order_after(p_rec IN OUT cg$nit_ci_type_relations.cg$row_type
                            ,p_id  IN nit_ci_type_relations.id%TYPE) IS
      ord            nit_ci_type_relations.order_in_list%TYPE;
      pl_subprg_name VARCHAR2(30) := 'SET_ORDER_AFTER';
   BEGIN
      SELECT order_in_list
      INTO   ord
      FROM   nit_ci_type_relations citr
      WHERE  id = p_id
      FOR    UPDATE;

      set_order(p_rec
               ,ord + 1);

   EXCEPTION
      WHEN no_data_found THEN
         set_order(p_rec
                  ,1);
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id || '#' || p_id);
         RAISE;

   END;

   PROCEDURE pre_dml(p_rec IN OUT cg$nit_ci_type_relations.cg$row_type
                    ,p_ind IN OUT cg$nit_ci_type_relations.cg$ind_type
                    ,p_op  IN VARCHAR2) IS
      pl_subprg_name VARCHAR2(30) := 'PRE_DML';
   BEGIN
      IF (p_rec.cit_id_from = p_rec.cit_id_to) THEN
         nit_error_p.error('NIT-00056'
                          ,'E'
                          ,TRUE
                          ,NULL
                          ,NULL
                          ,NULL
                          ,p_rec.id);
      END IF;

      IF (p_op = 'INS' OR p_op = 'UPD') THEN
         p_ind.last_update_date := TRUE;
         p_ind.last_updated_by  := TRUE;
         p_ind.order_in_list    := TRUE;
         set_order(p_rec
                  ,p_rec.order_in_list);
         nit_core_p.set_audit(p_rec.creation_date
                             ,p_rec.created_by
                             ,p_rec.last_update_date
                             ,p_rec.last_updated_by
                             ,p_op);

      END IF;

      IF (p_op = 'INS') THEN
         p_ind.id            := TRUE;
         p_ind.creation_date := TRUE;
         p_ind.created_by    := TRUE;
         p_ind.cit_id_from   := TRUE;
         p_ind.cit_id_to     := TRUE;
         p_ind.citrt_id      := TRUE;

         <<bidir>>
         DECLARE
            citrt_rec cg$nit_cit_relation_types.cg$row_type;
            CURSOR c_citrt_id(p_cit_id_from IN nit_ci_type_relations.cit_id_from%TYPE, p_cit_id_to IN nit_ci_type_relations.cit_id_to%TYPE, p_citrt_id IN nit_ci_type_relations.citrt_id%TYPE) IS
               SELECT citr.citrt_id
               FROM   nit_ci_type_relations  citr
                     ,nit_cit_relation_types citrt
               WHERE  citr.cit_id_from = p_cit_id_to AND
                      citr.cit_id_to = p_cit_id_from AND
                      citrt.id = citr.citrt_id AND
                      citrt.id = p_citrt_id AND
                      nit_cit_relation_types_p.is_bidirectional(citrt.NAME) = 'N';
         BEGIN
            OPEN c_citrt_id(p_rec.cit_id_from
                           ,p_rec.cit_id_to
                           ,p_rec.citrt_id);
            FETCH c_citrt_id
               INTO citrt_rec.id;

            -- He van p?rja a mostani rekordnak ?s a typusa nem bidirectional akkor baj van...figyelj?k
            IF (c_citrt_id%FOUND) THEN
               cg$nit_cit_relation_types.slct(citrt_rec);
               nit_error_p.error('NIT-00069'
                                ,'E'
                                ,TRUE
                                ,citrt_rec.NAME
                                ,NULL
                                ,NULL
                                ,NULL);

               CLOSE c_citrt_id;
            END IF;
         END bidir;
      END IF;
   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;

   END;
   -------------------------------------------------------------------------------------------------------------------------------------------

   FUNCTION is_bidirectional(p_id IN nit_ci_type_relations.id%TYPE) RETURN CHAR IS
      rec            nit_ci_type_relations%ROWTYPE;
      pair_rec       nit_ci_type_relations%ROWTYPE;
      pl_subprg_name VARCHAR2(30) := 'IS_BIDIRECTIONAL';
   BEGIN
      <<existance_check>>
      BEGIN
         SELECT *
         INTO   rec
         FROM   nit_ci_type_relations citr
         WHERE  citr.id = p_id;

      EXCEPTION
         WHEN no_data_found THEN
            RETURN NULL;
         WHEN OTHERS THEN
            nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                     ,dbms_utility.format_call_stack
                                     ,dbms_utility.format_error_stack
                                     ,'Y'
                                     ,pl_module
                                     ,pl_version
                                     ,pl_subprg_name
                                     ,'#' || p_id);
            RAISE;

      END existance_check;

      SELECT *
      INTO   pair_rec
      FROM   nit_ci_type_relations citr
      WHERE  citr.cit_id_from = rec.cit_id_to AND
             citr.cit_id_to = rec.cit_id_from AND
             citr.citrt_id = rec.citrt_id;
      RETURN 'Y';

   EXCEPTION
      WHEN no_data_found THEN
         RETURN 'N';
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;

   PROCEDURE make_bidirectional(p_id IN nit_ci_type_relations.id%TYPE) IS
      rec            nit_ci_type_relations%ROWTYPE;
      pair_rec       cg$nit_ci_type_relations.cg$row_type;
      pair_ind       cg$nit_ci_type_relations.cg$ind_type;
      pl_subprg_name VARCHAR2(30) := 'IS_BIDIRECTIONAL';
   BEGIN
      IF (is_bidirectional(p_id) = 'Y') THEN
         RETURN;
      END IF;

      <<existance_check>>
      BEGIN
         SELECT *
         INTO   rec
         FROM   nit_ci_type_relations citr
         WHERE  citr.id = p_id;

      EXCEPTION
         WHEN no_data_found THEN
            RETURN;
         WHEN OTHERS THEN
            nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                     ,dbms_utility.format_call_stack
                                     ,dbms_utility.format_error_stack
                                     ,'Y'
                                     ,pl_module
                                     ,pl_version
                                     ,pl_subprg_name
                                     ,'#' || p_id);
            RAISE;

      END existance_check;

      pair_rec.cit_id_from   := rec.cit_id_to;
      pair_rec.cit_id_to     := rec.cit_id_from;
      pair_rec.citrt_id      := rec.citrt_id;
      pair_rec.order_in_list := rec.order_in_list;
      pair_rec.description   := rec.description;
      pair_rec.comments      := rec.comments;

      pair_ind.cit_id_from   := TRUE;
      pair_ind.cit_id_to     := TRUE;
      pair_ind.citrt_id      := TRUE;
      pair_ind.order_in_list := TRUE;
      pair_ind.description   := TRUE;
      pair_ind.comments      := TRUE;

      cg$nit_ci_type_relations.ins(pair_rec
                                  ,pair_ind
                                  ,TRUE);

   EXCEPTION
      WHEN no_data_found THEN
         RETURN;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;

   FUNCTION is_one_directional(p_id IN nit_cit_relation_types.id%TYPE) RETURN CHAR IS
      pl_subprg_name VARCHAR2(30) := 'IS_ONE_DIRECTIONAL';
      ret            CHAR(1) := is_bidirectional(p_id);
   BEGIN
      IF (ret = 'Y') THEN
         RETURN 'N';
      ELSIF (ret = 'N') THEN
         RETURN 'Y';
      END IF;

      RETURN NULL;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;

BEGIN
   nit_card_p.log(pl_module
                 ,pl_version);
END nit_ci_type_relations_p;
/

prompt
prompt Creating package body NIT_CI_TYPES_P
prompt ====================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_ci_types_p IS
   pl_module  VARCHAR2(30) := 'nit_ci_types_p';
   pl_version VARCHAR2(30) := '0.5.0.0';

   the_root CONSTANT VARCHAR2(20) := 'something';

   FUNCTION package_version RETURN VARCHAR2 IS
   BEGIN
      RETURN pl_module || ' ' || pl_version;
   END;

   -----------------------------------------------------------------------------------------------------------------

   PROCEDURE set_order(p_rec   IN OUT cg$nit_ci_types.cg$row_type
                      ,p_order IN nit_ci_types.order_in_list%TYPE) IS
      dependant      nit_ci_types.id%TYPE;
      pl_subprg_name VARCHAR2(30) := 'SET_ORDER';
   BEGIN

      IF (p_rec.order_in_list IS NULL AND p_order IS NOT NULL) THEN
         p_rec.order_in_list := p_order;
      ELSIF (p_rec.order_in_list IS NULL AND p_order IS NULL) THEN
         <<order_set>>
         BEGIN
            SELECT NVL(MAX(order_in_list)
                      ,0) + 1
            INTO   p_rec.order_in_list
            FROM   nit_ci_types cit
            WHERE  cit.cit_id = p_rec.cit_id;
         EXCEPTION
            WHEN no_data_found THEN
               p_rec.order_in_list := 1;
               RETURN;
            WHEN OTHERS THEN
               nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                        ,dbms_utility.format_call_stack
                                        ,dbms_utility.format_error_stack
                                        ,'Y'
                                        ,pl_module
                                        ,pl_version
                                        ,pl_subprg_name
                                        ,'#' || p_rec.id || '#' || p_order);
               RAISE;
         END;

      END IF;

      -- Ha nincs az adott sorrendi helyen semmi, akkor odarakjuk magunkat..
      -- Ha van, akkor update...
      -- T?bb nem lehet, csak 1...azaz a TOO_MANY_ROWS-t nem fogja kiv?ltani...
      /* Orb?n Tam?s: elofordult, hogy t?bbet fetchelt be egyn?l... */
      SELECT id
      INTO   dependant
      FROM   nit_ci_types cit
      WHERE  cit.order_in_list = p_order AND
             cit.cit_id = p_rec.cit_id AND
             rownum = 1;
      -- Szerintem felesleges m?st for-update-elni mert ?gyis azonnal update-?nk, amikor ez lefut..1-2 msec a difi..
      -- ?s nem ID alapon, csak CIT_ID alapon kellene am?gy is z?rolni...
      -- FIXME: Most k?zvetlen?l updatel?nk ?s nem az UPD() fv-en kereszt?l, de ez megbocs?that? itt
      UPDATE nit_ci_types cit
      SET    cit.order_in_list = cit.order_in_list + 1
      WHERE  cit.NAME <> p_rec.NAME AND
             cit.order_in_list >= p_order AND
             cit.cit_id = p_rec.cit_id;
      -- a cit.name fontos, hogy nem ID, mert a p_rec.id az NULL a pre_dml -n?l m?g!
   EXCEPTION
      WHEN no_data_found THEN
         p_rec.order_in_list := p_order;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id || '#' || p_order);
         RAISE;

   END;

   -----------------------------------------------------------------------------------------------------------------
   PROCEDURE set_order_before(p_rec IN OUT cg$nit_ci_types.cg$row_type
                             ,p_id  IN nit_ci_types.id%TYPE) IS
      ord            nit_ci_types.order_in_list%TYPE;
      pl_subprg_name VARCHAR2(30) := 'SET_ORDER_BEFORE';
   BEGIN
      SELECT order_in_list
      INTO   ord
      FROM   nit_ci_types cit
      WHERE  cit.id = p_id
      FOR    UPDATE;

      set_order(p_rec
               ,ord);

   EXCEPTION
      WHEN no_data_found THEN
         set_order(p_rec
                  ,1);
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id || '#' || p_id);
         RAISE;

   END;

   -----------------------------------------------------------------------------------------------------------------
   PROCEDURE set_order_after(p_rec IN OUT cg$nit_ci_types.cg$row_type
                            ,p_id  IN nit_ci_types.id%TYPE) IS
      ord            nit_ci_types.order_in_list%TYPE;
      pl_subprg_name VARCHAR2(30) := 'SET_ORDER_BEFORE';
   BEGIN
      SELECT order_in_list
      INTO   ord
      FROM   nit_ci_types cit
      WHERE  cit.id = p_id
      FOR    UPDATE;

      set_order(p_rec
               ,ord + 1);

   EXCEPTION
      WHEN no_data_found THEN
         set_order(p_rec
                  ,1);
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id || '#' || p_id);
         RAISE;

   END;

   -----------------------------------------------------------------------------------------------------------------
   PROCEDURE pre_dml(p_rec IN OUT cg$nit_ci_types.cg$row_type
                    ,p_ind IN OUT cg$nit_ci_types.cg$ind_type
                    ,p_op  IN VARCHAR2) IS
      pl_subprg_name VARCHAR2(30) := 'pre_dml';
   BEGIN
      IF (p_op = 'INS') THEN
         p_ind.id                 := TRUE;
         p_ind.creation_date      := TRUE;
         p_ind.created_by         := TRUE;
         p_ind.cit_id             := TRUE;
         p_ind.NAME               := TRUE;
         p_ind.need_po            := TRUE;
         p_ind.could_in_stock     := TRUE;
         p_ind.could_in_inventory := TRUE;
         p_ind.is_importable      := TRUE;

         IF (p_rec.abbreviation IS NULL) THEN
            p_rec.abbreviation := SUBSTR(p_rec.NAME
                                        ,0
                                        ,3);
         END IF;

      END IF;

      IF (p_op = 'INS' OR p_op = 'UPD') THEN
         p_ind.order_in_list := TRUE;

         IF (p_rec.cit_id IS NULL AND p_rec.NAME <> nit_core_p.getp(the_root)) THEN
            nit_error_p.error('NIT-00009'
                             ,'E'
                             ,TRUE
                             ,p_rec.NAME
                             ,NULL
                             ,NULL
                             ,p_rec.id);
         END IF;

         set_order(p_rec
                  ,p_rec.order_in_list);

         IF (p_rec.NAME IS NULL AND p_rec.abbreviation IS NOT NULL) THEN
            p_rec.NAME := p_rec.abbreviation;
         END IF;

         IF (p_rec.NAME IS NOT NULL AND p_rec.abbreviation IS NULL) THEN
            -- Legyen alap r?vid?t?s az n?v els? 3 karaktere.. jobban nem tudok kital?lni...
            p_rec.abbreviation := SUBSTR(p_rec.NAME
                                        ,1
                                        ,3);
         END IF;

         IF (p_rec.naming_pattern IS NULL) THEN
            p_rec.naming_pattern := get_default_naming_pattern(p_rec);
         END IF;

         nit_core_p.caseconv(p_rec.NAME);
         nit_core_p.caseconv(p_rec.abbreviation);
         nit_core_p.caseconv(p_rec.naming_pattern);

         nit_core_p.set_audit(p_rec.creation_date
                             ,p_rec.created_by
                             ,p_rec.last_update_date
                             ,p_rec.last_updated_by
                             ,p_op);
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;

   END;

   PROCEDURE pre_del(p_id IN nit_ci_types.id%TYPE) IS
      l_cip_pk  cg$nit_ci_properties.cg$pk_type;
      l_citr_pk cg$nit_ci_type_relations.cg$pk_type;

      CURSOR cur_affected_cip IS
         SELECT cip.id
         FROM   nit_ci_properties cip
         WHERE  cip.cit_id = p_id;

      CURSOR cur_citr IS
         SELECT citr.id
         FROM   nit_ci_type_relations citr
         WHERE  (citr.cit_id_from = p_id OR citr.cit_id_to = p_id);

      pl_subprg_name VARCHAR2(30) := 'pre_del';
   BEGIN
      is_deleting := 'Y';

      IF (is_root(p_id) = 'Y') THEN
         nit_error_p.error('NIT-00010'
                          ,'E'
                          ,TRUE
                          ,NULL
                          ,NULL
                          ,NULL
                          ,p_id);
      END IF;

      FOR cip_rec IN cur_affected_cip LOOP
         l_cip_pk.id := cip_rec.id;
         cg$nit_ci_properties.del(l_cip_pk);
      END LOOP;

      FOR rec IN cur_citr LOOP
         l_citr_pk.id := rec.id;
         cg$nit_ci_type_relations.del(l_citr_pk);
      END LOOP;

      is_deleting := 'N';

   EXCEPTION
      WHEN OTHERS THEN
         is_deleting := 'N';
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;
   END;

   /* purchase order ill. inventory number property automatikus felv?tele
   PROCEDURE post_ins(p_rec IN OUT cg$nit_ci_types.cg$row_type
                     ,p_ind IN OUT cg$nit_ci_types.cg$ind_type) IS
      l_cip_rec      cg$nit_ci_properties.cg$row_type;
      l_cip_ind      cg$nit_ci_properties.cg$ind_type;
      pl_subprg_name VARCHAR2(30) := 'post_ins';

   BEGIN
      NULL;
      /*      IF (p_rec.need_po = 'Y') THEN
               NULL;
               nit_ci_properties_p.special_cip_ins(p_rec.id
                                                  ,nit_ci_property_types_p.get_po_cipt_name);
            END IF;

            IF (p_rec.could_in_inventory = 'Y') THEN
               nit_ci_properties_p.special_cip_ins(p_rec.id
                                                  ,nit_ci_property_types_p.get_inventory_num_cipt_name);
            END IF;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;
   */

   /* purchase order ?s inventory number k?telez?v? t?tele (required = 'Y') vagy felv?tele.
   Jelenleg nem ker?l meghiv?sra a table API-b?l. Form szinten van megval?s?tva. */
   /*
   PROCEDURE post_upd(p_rec     IN OUT cg$nit_ci_types.cg$row_type
                     ,p_ind     IN OUT cg$nit_ci_types.cg$ind_type
                     ,p_old_rec IN OUT cg$nit_ci_types.cg$row_type) IS
      l_rec                   cg$nit_ci_properties.cg$row_type;
      l_ind                   cg$nit_ci_properties.cg$ind_type;
      l_po_cipt_id            nit_ci_property_types.id%TYPE;
      l_inventory_num_cipt_id nit_ci_property_types.id%TYPE;
      pl_subprg_name          VARCHAR2(30) := 'post_upd';

      CURSOR c_cipt_id(p_cipt_name IN nit_ci_property_types.NAME%TYPE) IS
         SELECT cipt.id
         FROM   nit_ci_property_types cipt
         WHERE  cipt.NAME = p_cipt_name;
      CURSOR c_cip_id(p_cipt_id IN nit_ci_property_types.id%TYPE) IS
         SELECT cip.id
         FROM   nit_ci_properties cip
         WHERE  cip.cipt_id = p_cipt_id AND
                cip.cit_id = p_rec.id;

   BEGIN
      NULL;
      /*      IF (p_rec.need_po = 'Y') THEN
               -- PO CIPT id meghat?roz?sa
               OPEN c_cipt_id(nit_ci_property_types_p.get_po_cipt_name);
               FETCH c_cipt_id
                  INTO l_po_cipt_id;
               CLOSE c_cipt_id;

               -- PO-hoz tartoz? CIP id
               OPEN c_cip_id(l_po_cipt_id);
               FETCH c_cip_id
                  INTO l_rec.id;
               CLOSE c_cip_id;

               IF (l_rec.id IS NOT NULL) THEN
                  cg$nit_ci_properties.slct(l_rec);

                  l_rec.required := 'Y';
                  l_ind.required := TRUE;

                  cg$nit_ci_properties.upd(l_rec
                                          ,l_ind
                                          ,TRUE);
               ELSE
                  nit_ci_properties_p.special_cip_ins(p_rec.id
                                                     ,nit_ci_property_types_p.get_po_cipt_name);
               END IF;
            END IF;

            IF (p_rec.could_in_inventory = 'Y') THEN
               -- Inventory number CIPT id meghat?roz?sa
               OPEN c_cipt_id(nit_ci_property_types_p.get_inventory_num_cipt_name);
               FETCH c_cipt_id
                  INTO l_inventory_num_cipt_id;
               CLOSE c_cipt_id;

               -- Inventory number-h?z tartoz? CIP id
               OPEN c_cip_id(l_inventory_num_cipt_id);
               FETCH c_cip_id
                  INTO l_rec.id;
               CLOSE c_cip_id;

               IF (l_rec.id IS NOT NULL) THEN
                  l_rec.the_rowid := NULL;
                  cg$nit_ci_properties.slct(l_rec);

                  l_rec.required := 'Y';
                  l_ind.required := TRUE;

                  cg$nit_ci_properties.upd(l_rec
                                          ,l_ind
                                          ,TRUE);
               ELSE
                  nit_ci_properties_p.special_cip_ins(p_rec.id
                                                     ,nit_ci_property_types_p.get_inventory_num_cipt_name);
               END IF;
            END IF;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;
   */

   FUNCTION get_default_name(p_rec IN OUT cg$nit_ci_types.cg$row_type)
      RETURN nit_ci_types.NAME%TYPE IS
      pl_subprg_name VARCHAR2(30) := 'GET_DEFAULT_NAME';
      parent_cit     nit_ci_types%ROWTYPE;
      ret            nit_ci_types.NAME%TYPE;
   BEGIN

      SELECT *
      INTO   parent_cit
      FROM   nit_ci_types cit
      WHERE  cit.id = p_rec.cit_id;

      IF (p_rec.naming_pattern IS NULL) THEN
         ret := parent_cit.naming_pattern;
      ELSE
         ret := p_rec.naming_pattern;
      END IF;


      IF (p_rec.naming_pattern = '#recursive#') THEN
         p_rec.naming_pattern := REPLACE(p_rec.naming_pattern
                                        ,'#recursive#'
                                        ,NVL(parent_cit.naming_pattern
                                            ,''));
         RETURN get_default_name(p_rec);
      END IF;

      ret := REPLACE(ret
                    ,'#parent name#'
                    ,parent_cit.NAME);
      ret := REPLACE(ret
                    ,'#parent abbreviation#'
                    ,parent_cit.abbreviation);
      ret := REPLACE(ret
                    ,'#parent pattern#'
                    ,parent_cit.naming_pattern);

      ret := REPLACE(ret
                    ,'#name#'
                    ,p_rec.NAME);
      ret := REPLACE(ret
                    ,'#abbreviation#'
                    ,p_rec.abbreviation);
      ret := REPLACE(ret
                    ,'#pattern#'
                    ,p_rec.naming_pattern);

      -- Na most n?zz?k a rekurz?v kifejt?sbol eredo cs?nyas?gokat: ----valami--akarmi, -valami, -
      owa_pattern.change(ret
                        ,'-+'
                        ,'-');
      -- Kiszedem az elso - jelet. Mert cs?nya...
      IF (SUBSTR(ret
                ,0
                ,1) = '-') THEN
         ret := SUBSTR(ret
                      ,1
                      ,LENGTH(ret));
      END IF;

      RETURN ret;

   EXCEPTION
      WHEN no_data_found THEN
         -- Ha nincs sz?l?, akkor visszaadjuk a saj?t elnevez?si r?vid?t?s?nket alap?rtelmezett n?vnek.. mert mi csin?ljuk?
         RETURN p_rec.abbreviation;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;

   END;
   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION get_root_id RETURN nit_ci_types.id%TYPE IS
      r_id           nit_ci_types.id%TYPE;
      pl_subprg_name VARCHAR2(30) := 'GET_ROOT_ID';
   BEGIN
      SELECT id
      INTO   r_id
      FROM   nit_ci_types
      WHERE  NAME = nit_core_p.getp(the_root);
      RETURN r_id;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || r_id);
         RAISE;
   END;
   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION get_default_naming_pattern(p_rec IN cg$nit_ci_types.cg$row_type)
      RETURN nit_ci_types.naming_pattern%TYPE IS
      pl_subprg_name VARCHAR2(30) := 'GET_DEFAULT_NAMING_PATTERN';
      naming         nit_ci_types.naming_pattern%TYPE;
   BEGIN

      SELECT cit.naming_pattern
      INTO   naming
      FROM   nit_ci_types cit
      WHERE  cit.id = p_rec.cit_id;

      RETURN naming;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;

   END;

   FUNCTION is_child_of(p_parent IN nit_ci_types.id%TYPE
                       ,p_child  IN nit_ci_types.id%TYPE) RETURN CHAR IS
      pl_subprg_name VARCHAR2(30) := 'IS_CHILD_OF';
      coll           nit_ci_types_ct := get_parents_by_rev_inherit(p_child);
      i              PLS_INTEGER;

   BEGIN
      IF (coll IS NOT NULL) THEN
         IF (coll.COUNT > 0) THEN
            i := coll.FIRST;
         ELSE
            RETURN 'N';
         END IF;
      ELSE
         RETURN 'N';
      END IF;

      WHILE (i IS NOT NULL) LOOP
         IF (coll(i).id = p_parent) THEN
            RETURN 'Y';
         END IF;
         i := coll.NEXT(i);
      END LOOP;

      RETURN 'N';

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_parent || '#' || p_child);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION is_direct_child_of(p_parent IN nit_ci_types.id%TYPE
                              ,p_child  IN nit_ci_types.id%TYPE) RETURN CHAR IS
      par_id         nit_ci_types.id%TYPE;
      pl_subprg_name VARCHAR2(30) := 'IS_DIRECT_CHILD_OF';
   BEGIN
      SELECT cit.id
      INTO   par_id
      FROM   nit_ci_types cit
      WHERE  cit.cit_id = p_parent AND
             cit.id = p_child;

      RETURN 'Y';

   EXCEPTION
      WHEN no_data_found THEN
         RETURN 'N';
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_parent || '#' || p_child);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION is_parent_of(p_parent IN nit_ci_types.id%TYPE
                        ,p_child  IN nit_ci_types.id%TYPE) RETURN CHAR IS
      pl_subprg_name VARCHAR2(30) := 'IS_PARENT_OF';
   BEGIN
      RETURN is_child_of(p_parent
                        ,p_child);

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_parent || '#' || p_child);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION is_direct_parent_of(p_parent IN nit_ci_types.id%TYPE
                               ,p_child  IN nit_ci_types.id%TYPE) RETURN CHAR IS
      pl_subprg_name VARCHAR2(30) := 'IS_DIRECT_PARENT_OF';
   BEGIN
      RETURN is_direct_child_of(p_parent
                               ,p_child);

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_parent || '#' || p_child);
         RAISE;
   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   -- A child2-nek gyereke-e a child1
   FUNCTION is_brother_of(p_child1 IN nit_ci_types.id%TYPE
                         ,p_child2 IN nit_ci_types.id%TYPE) RETURN CHAR IS
      pl_subprg_name VARCHAR2(30) := 'IS_BROTHER_OF';

   BEGIN
      IF (get_direct_parent(p_child1).id = get_direct_parent(p_child2).id) THEN
         RETURN 'Y';
      END IF;

      RETURN 'N';

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_child1 || '#' || p_child2);
         RAISE;
   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION get_children(p_id IN nit_ci_types.id%TYPE) RETURN nit_ci_types_ct IS
      coll           nit_ci_types_ct;
      pl_subprg_name VARCHAR2(30) := 'GET_CHILDREN';
   BEGIN
      SELECT nit_ci_types_ot(cit.id
                            ,cit.creation_date
                            ,cit.created_by
                            ,cit.last_update_date
                            ,cit.last_updated_by
                            ,cit.cit_id
                            ,cit.NAME
                            ,cit.need_po
                            ,cit.could_in_stock
                            ,cit.order_in_list
                            ,cit.abbreviation
                            ,cit.naming_pattern
                            ,cit.description
                            ,cit.comments
                            ,cit.icon_name) BULK COLLECT
      INTO   coll
      FROM   nit_ci_types cit
      WHERE  id <> p_id
      START  WITH cit.id = p_id
      CONNECT BY PRIOR cit.id = cit.cit_id;
      RETURN coll;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;
   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   /* Vigy?zat: ?nmag?t is hozz?adja a halmazhoz */

   FUNCTION get_children_ids(p_id IN nit_ci_types.id%TYPE) RETURN nit_num_ct IS
      coll           nit_num_ct;
      pl_subprg_name VARCHAR2(30) := 'GET_CHILDREN_IDS';
   BEGIN
      SELECT cit.id BULK COLLECT
      INTO   coll
      FROM   nit_ci_types cit
      START  WITH id = p_id
      CONNECT BY PRIOR id = cit_id;
      RETURN coll;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;
   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION get_parents_by_rev_inherit(p_id IN nit_ci_types.id%TYPE)
      RETURN nit_ci_types_ct IS
      coll           nit_ci_types_ct;
      cit_parent_id  nit_ci_types.cit_id%TYPE;
      pl_subprg_name VARCHAR2(30) := 'GET_PARENTS_BY_REV_INHERIT';
   BEGIN
      SELECT cit_id
      INTO   cit_parent_id
      FROM   nit_ci_types
      WHERE  id = p_id;

      SELECT nit_ci_types_ot(cit.id
                            ,cit.creation_date
                            ,cit.created_by
                            ,cit.last_update_date
                            ,cit.last_updated_by
                            ,cit.cit_id
                            ,cit.NAME
                            ,cit.need_po
                            ,cit.could_in_stock
                            ,cit.order_in_list
                            ,cit.abbreviation
                            ,cit.naming_pattern
                            ,cit.description
                            ,cit.comments
                            ,cit.icon_name) BULK COLLECT
      INTO   coll
      FROM   nit_ci_types cit
      START  WITH id = cit_parent_id
      CONNECT BY PRIOR cit_id = id;

      RETURN coll;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;
   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION get_parents_by_inherit(p_id IN nit_ci_types.id%TYPE)
      RETURN nit_ci_types_ct IS
      coll           nit_ci_types_ct;
      cit_parent_id  nit_ci_types.cit_id%TYPE;
      pl_subprg_name VARCHAR2(30) := 'GET_PARENTS_BY_INHERIT';

   BEGIN
      SELECT cit_id
      INTO   cit_parent_id
      FROM   nit_ci_types
      WHERE  id = p_id;

      SELECT nit_ci_types_ot(cit.id
                            ,cit.creation_date
                            ,cit.created_by
                            ,cit.last_update_date
                            ,cit.last_updated_by
                            ,cit.cit_id
                            ,cit.NAME
                            ,cit.need_po
                            ,cit.could_in_stock
                            ,cit.order_in_list
                            ,cit.abbreviation
                            ,cit.naming_pattern
                            ,cit.description
                            ,cit.comments
                            ,cit.icon_name) BULK COLLECT
      INTO   coll
      FROM   nit_ci_types cit
      START  WITH id = cit_parent_id
      CONNECT BY PRIOR cit_id = id;
      --      ORDER  BY rownum DESC;
      RETURN coll;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   /* Vigy?zat: ?nmag?t is hozz?adja a halmazhoz */

   FUNCTION get_parent_ids_by_inherit(p_id IN nit_ci_types.id%TYPE)
      RETURN nit_num_ct IS
      coll           nit_num_ct;
      pl_subprg_name VARCHAR2(30) := 'GET_PARENT_IDS_BY_INHERIT';

   BEGIN
      SELECT cit.id BULK COLLECT
      INTO   coll
      FROM   nit_ci_types cit
      START  WITH id = p_id
      CONNECT BY PRIOR cit_id = id;

      RETURN coll;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------

   FUNCTION get_brothers(p_id IN nit_ci_types.id%TYPE) RETURN nit_ci_types_ct IS
      cit_parent_id  nit_ci_types.cit_id%TYPE;
      coll           nit_ci_types_ct;
      pl_subprg_name VARCHAR2(30) := 'GET_BROTHERS';
   BEGIN
      SELECT cit_id
      INTO   cit_parent_id
      FROM   nit_ci_types
      WHERE  id = p_id;

      SELECT nit_ci_types_ot(cit.id
                            ,cit.creation_date
                            ,cit.created_by
                            ,cit.last_update_date
                            ,cit.last_updated_by
                            ,cit.cit_id
                            ,cit.NAME
                            ,cit.need_po
                            ,cit.could_in_stock
                            ,cit.order_in_list
                            ,cit.abbreviation
                            ,cit.naming_pattern
                            ,cit.description
                            ,cit.comments
                            ,cit.icon_name) BULK COLLECT
      INTO   coll
      FROM   nit_ci_types cit
      WHERE  cit.cit_id = cit_parent_id AND
             id <> p_id;

      RETURN coll;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN collection_is_null THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION get_direct_children(p_id IN nit_ci_types.id%TYPE)
      RETURN nit_ci_types_ct IS
      coll           nit_ci_types_ct;
      pl_subprg_name VARCHAR2(30) := 'GET_DIRECT_CHILDREN';
   BEGIN
      SELECT nit_ci_types_ot(cit.id
                            ,cit.creation_date
                            ,cit.created_by
                            ,cit.last_update_date
                            ,cit.last_updated_by
                            ,cit.cit_id
                            ,cit.NAME
                            ,cit.need_po
                            ,cit.could_in_stock
                            ,cit.order_in_list
                            ,cit.abbreviation
                            ,cit.naming_pattern
                            ,cit.description
                            ,cit.comments
                            ,cit.icon_name) BULK COLLECT
      INTO   coll
      FROM   nit_ci_types cit
      WHERE  cit.cit_id = p_id;
      RETURN coll;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN collection_is_null THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;
   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION get_direct_parent(p_id IN nit_ci_types.id%TYPE)
      RETURN nit_ci_types%ROWTYPE IS
      my_parent      nit_ci_types%ROWTYPE;
      my_parent_id   nit_ci_types.cit_id%TYPE;
      pl_subprg_name VARCHAR2(30) := 'GET_DIRECT_PARENT';

   BEGIN
      <<existance_check>>
      BEGIN
         SELECT cit_id
         INTO   my_parent_id
         FROM   nit_ci_types cit
         WHERE  cit.id = p_id;

      EXCEPTION
         WHEN no_data_found THEN
            nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                     ,dbms_utility.format_call_stack
                                     ,dbms_utility.format_error_stack
                                     ,'Y'
                                     ,pl_module
                                     ,pl_version
                                     ,pl_subprg_name
                                     ,'#' || p_id);
            RETURN NULL;
      END;

      SELECT *
      INTO   my_parent
      FROM   nit_ci_types cit
      WHERE  id = my_parent_id;

      RETURN my_parent;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;
   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION is_root(p_id IN nit_ci_types.id%TYPE) RETURN CHAR IS
      par            nit_ci_types%ROWTYPE;
      pl_subprg_name VARCHAR2(30) := 'IS_ROOT';
   BEGIN
      SELECT *
      INTO   par
      FROM   nit_ci_types
      WHERE  id = p_id AND
             cit_id IS NULL; -- az?rt a 'par'-ba mert ?gyis fel?l?rjuk mindj?rt..optimaliz?ci?..

      IF (par.NAME = nit_core_p.getp(the_root)) THEN
         RETURN 'Y';
      ELSE
         RETURN 'N';
      END IF;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN 'N';
      WHEN too_many_rows THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         nit_error_p.error('NIT-00009'
                          ,'E'
                          ,TRUE
                          ,NULL
                          ,NULL
                          ,NULL
                          ,p_id);

      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;
   END;
   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION is_leaf(p_id IN nit_ci_types.id%TYPE) RETURN CHAR IS
      par            nit_ci_types.id%TYPE;
      pl_subprg_name VARCHAR2(30) := 'IS_LEAF';
   BEGIN
      <<existance_check>>
      BEGIN
         SELECT id
         INTO   par
         FROM   nit_ci_types
         WHERE  id = p_id; -- az?rt a 'par'-ba mert ?gyis fel?l?rjuk mindj?rt..optimaliz?ci?..

      EXCEPTION
         WHEN no_data_found THEN
            RETURN NULL;
      END;

      SELECT id
      INTO   par
      FROM   nit_ci_types
      WHERE  cit_id = p_id;

      RETURN 'N';

   EXCEPTION
      WHEN no_data_found THEN
         RETURN 'Y';
      WHEN too_many_rows THEN
         RETURN 'N';
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;
   END;

   PROCEDURE sort_all(p_attr      IN VARCHAR2
                     ,p_direction IN VARCHAR2) IS
      my_num         nit_ci_types.order_in_list%TYPE;
      pl_subprg_name VARCHAR2(30) := 'SORT_ALL';
      CURSOR cur_parents IS
         SELECT DISTINCT cit1.id
         FROM   nit_ci_types cit1;
      cur_children SYS_REFCURSOR;
      cur_rec_c    nit_ci_types%ROWTYPE;
   BEGIN
      FOR cur_rec_p IN cur_parents LOOP
         my_num := 1;
         OPEN cur_children FOR 'SELECT * FROM nit_CI_TYPES CIT2 WHERE CIT2.CIT_ID = :P_CIT_ID ORDER BY :p_attr :p_order for update;'
            USING cur_rec_p.id, p_attr, p_direction;
         LOOP
            FETCH cur_children
               INTO cur_rec_c;
            EXIT WHEN cur_children%NOTFOUND;
            UPDATE nit_ci_types cit3
            SET    cit3.order_in_list = my_num
            WHERE  cit3.id = cur_rec_c.id;
            my_num := my_num + 1;
         END LOOP;
         CLOSE cur_children;
      END LOOP;

   EXCEPTION
      WHEN cursor_already_open THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_attr || '#' || p_direction);
      WHEN invalid_cursor THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_attr || '#' || p_direction);
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_attr || '#' || p_direction);
         --         RAISE;
   END;

   PROCEDURE sort_sublevels(p_attr      IN VARCHAR2
                           ,p_direction IN VARCHAR2
                           ,from_id     IN nit_ci_types.id%TYPE) IS
      my_num         nit_ci_types.order_in_list%TYPE;
      pl_subprg_name VARCHAR2(30) := 'SORT_SUBLEVELS';
      CURSOR cur_parents IS
         SELECT DISTINCT cit1.id
         FROM   TABLE(get_children(from_id)) cit1;
      cur_children SYS_REFCURSOR;
      cur_rec_c    nit_ci_types%ROWTYPE;
   BEGIN
      FOR cur_rec_p IN cur_parents LOOP
         my_num := 1;
         OPEN cur_children FOR 'SELECT * FROM nit_CI_TYPES CIT2 WHERE CIT2.CIT_ID = :P_CIT_ID ORDER BY :p_attr :p_order for update;'
            USING cur_rec_p.id, p_attr, p_direction;
         LOOP
            FETCH cur_children
               INTO cur_rec_c;
            EXIT WHEN cur_children%NOTFOUND;
            UPDATE nit_ci_types cit3
            SET    cit3.order_in_list = my_num
            WHERE  cit3.id = cur_rec_c.id;
            my_num := my_num + 1;
         END LOOP;
         CLOSE cur_children;
      END LOOP;

   EXCEPTION
      WHEN cursor_already_open THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_attr || '#' || p_direction);
      WHEN invalid_cursor THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_attr || '#' || p_direction);
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_attr || '#' || p_direction);
         RAISE;
   END;

   PROCEDURE sort_current_level(p_attr      IN VARCHAR2
                               ,p_direction IN VARCHAR2
                               ,from_id     IN nit_ci_types.id%TYPE) IS
      my_num         nit_ci_types.order_in_list%TYPE;
      pl_subprg_name VARCHAR2(30) := 'SORT_CURRENT_LEVEL';
      CURSOR cur_parents IS
         SELECT DISTINCT cit1.id
         FROM   TABLE(get_direct_children(from_id)) cit1;
      cur_children SYS_REFCURSOR;
      cur_rec_c    nit_ci_types%ROWTYPE;
   BEGIN
      FOR cur_rec_p IN cur_parents LOOP
         my_num := 1;
         OPEN cur_children FOR 'SELECT * FROM nit_CI_TYPES CIT2 WHERE CIT2.CIT_ID = :P_CIT_ID ORDER BY :p_attr :p_order for update'
            USING cur_rec_p.id, p_attr, p_direction;
         LOOP
            FETCH cur_children
               INTO cur_rec_c;
            EXIT WHEN cur_children%NOTFOUND;
            UPDATE nit_ci_types cit3
            SET    cit3.order_in_list = my_num
            WHERE  cit3.id = cur_rec_c.id;
            my_num := my_num + 1;
         END LOOP;
         CLOSE cur_children;
      END LOOP;

   EXCEPTION

      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_attr || '#' || p_direction);
         -- RAISE;
   END;

   -- Ez a sz?l?m ?sszes CIP-j?t ?r?kli, de mag?val h?zza a CIPV-jeit is...
   PROCEDURE cascade_ins(p_rec IN OUT cg$nit_ci_types.cg$row_type) IS
      pl_subprg_name VARCHAR2(30) := 'CASCADE_INS';
      CURSOR cur_cip IS
         SELECT cip.id
         FROM   nit_ci_properties     cip
               ,nit_ci_property_types cipt
         WHERE  cip.cit_id = p_rec.cit_id AND
                cip.cipt_id = cipt.id AND
                cipt.NAME <> nit_ci_property_types_p.get_po_cipt_name AND
                cipt.NAME <>
                nit_ci_property_types_p.get_inventory_num_cipt_name;

      CURSOR cur_cipv(p_cip_id IN nit_ci_property_values.cip_id%TYPE) IS
         SELECT id
         FROM   nit_ci_property_values cipv
         WHERE  cipv.cip_id = p_cip_id; -- Az ?n sz?l?m ?sszes CIPV-je

      l_cip_rec  cg$nit_ci_properties.cg$row_type;
      l_cip_ind  cg$nit_ci_properties.cg$ind_type;
      l_cipv_rec cg$nit_ci_property_values.cg$row_type;
      l_cipv_ind cg$nit_ci_property_values.cg$ind_type;
   BEGIN

      FOR cip_rec IN cur_cip LOOP
         l_cip_rec.id        := cip_rec.id;
         l_cip_rec.the_rowid := NULL;
         cg$nit_ci_properties.slct(l_cip_rec);

         l_cip_rec.cit_id    := p_rec.id;
         l_cip_rec.id        := NULL;
         l_cip_rec.the_rowid := NULL;

         l_cip_ind.cipt_id        := TRUE;
         l_cip_ind.cit_id         := TRUE;
         l_cip_ind.cip_id_ancient := TRUE;
         l_cip_ind.cip_id         := TRUE;
         l_cip_ind.required       := TRUE;
         l_cip_ind.set_like       := TRUE;
         l_cip_ind.is_inherited   := TRUE;
         l_cip_ind.order_in_list  := TRUE;
         l_cip_ind.description    := TRUE;
         l_cip_ind.comments       := TRUE;

         cg$nit_ci_properties.called_from_package := FALSE;
         cg$nit_ci_properties.ins(l_cip_rec
                                 ,l_cip_ind
                                 ,TRUE);

         FOR cipv_rec IN cur_cipv(cip_rec.id) LOOP
            l_cipv_rec.id        := cipv_rec.id;
            l_cipv_rec.the_rowid := NULL;
            cg$nit_ci_property_values.slct(l_cipv_rec);

            l_cipv_rec.id        := NULL;
            l_cipv_rec.the_rowid := NULL;
            l_cipv_rec.cip_id    := l_cip_rec.id;

            l_cipv_ind.id            := TRUE;
            l_cipv_ind.cip_id        := TRUE;
            l_cipv_ind.is_default    := TRUE;
            l_cipv_ind.order_in_list := TRUE;
            l_cipv_ind.VALUE         := TRUE;
            l_cipv_ind.description   := TRUE;
            l_cipv_ind.comments      := TRUE;

            cg$nit_ci_property_values.ins(l_cipv_rec
                                         ,l_cipv_ind
                                         ,TRUE);
         END LOOP;
      END LOOP;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;

   -- gyermekei fel? cascade-ol! (Ez nem ?rinti a CIP-eket ?s a CIPV-ket, mert azok cascade-jai nem itt vannak)
   PROCEDURE cascade_upd(p_rec IN OUT cg$nit_ci_types.cg$row_type) IS
      -- Ha minden szinten kell, akkor annyi, hogy a direct sz?t kiszedj?k
      child_coll     nit_ci_types_ct := get_children(p_rec.id);
      i              PLS_INTEGER;
      l_cit_rec      cg$nit_ci_types.cg$row_type;
      l_cit_ind      cg$nit_ci_types.cg$ind_type;
      pl_subprg_name VARCHAR2(30) := 'cascade_upd';

      CURSOR cur_contained IS
         SELECT citr.cit_id_to
         FROM   nit_ci_types           cit
               ,nit_ci_type_relations  citr
               ,nit_cit_relation_types citrt
         WHERE  citrt.NAME = nit_cit_relation_types_p.get_contains_rel_name AND
                citr.citrt_id = citrt.id AND
                citr.cit_id_from = p_rec.id;
   BEGIN
      l_cit_ind.id                 := FALSE;
      l_cit_ind.creation_date      := FALSE;
      l_cit_ind.created_by         := FALSE;
      l_cit_ind.last_update_date   := FALSE;
      l_cit_ind.last_updated_by    := FALSE;
      l_cit_ind.cit_id             := FALSE;
      l_cit_ind.NAME               := FALSE;
      l_cit_ind.need_po            := FALSE;
      l_cit_ind.could_in_stock     := TRUE;
      l_cit_ind.could_in_inventory := FALSE;
      l_cit_ind.order_in_list      := FALSE;
      l_cit_ind.abbreviation       := FALSE;
      l_cit_ind.naming_pattern     := FALSE;
      l_cit_ind.description        := FALSE;
      l_cit_ind.comments           := FALSE;
      l_cit_ind.icon_name          := FALSE;
      l_cit_ind.is_importable      := FALSE;

      FOR cur_rec IN cur_contained LOOP
         l_cit_rec.id        := cur_rec.cit_id_to;
         l_cit_rec.the_rowid := NULL;
         cg$nit_ci_types.slct(l_cit_rec);
         l_cit_rec.could_in_stock := p_rec.could_in_stock;
         cg$nit_ci_types.upd(l_cit_rec
                            ,l_cit_ind
                            ,TRUE);
      END LOOP;

      l_cit_ind.need_po            := TRUE;
      l_cit_ind.could_in_inventory := TRUE;

      IF (child_coll IS NOT NULL) THEN
         IF (child_coll.COUNT > 0) THEN
            i := child_coll.FIRST;
         ELSE
            RETURN;
         END IF;

         WHILE (i IS NOT NULL) LOOP

            l_cit_rec.id        := child_coll(i).id;
            l_cit_rec.the_rowid := NULL;
            cg$nit_ci_types.slct(l_cit_rec);
            l_cit_rec.need_po            := p_rec.need_po;
            l_cit_rec.could_in_stock     := p_rec.could_in_stock;
            l_cit_rec.could_in_inventory := p_rec.could_in_inventory;
            cg$nit_ci_types.upd(l_cit_rec
                               ,l_cit_ind
                               ,TRUE);
            i := child_coll.NEXT(i);
         END LOOP;
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;

   END;

   PROCEDURE cascade_del(p_id IN OUT nit_ci_types.id%TYPE) IS
      -- Ha minden szinten kell, akkor annyi, hogy a direct sz?t kiszedj?k
      child_coll     nit_ci_types_ct := get_children(p_id);
      i              PLS_INTEGER;
      l_pk           cg$nit_ci_types.cg$pk_type;
      pl_subprg_name VARCHAR2(30) := 'cascade_del';
   BEGIN
      IF (child_coll IS NOT NULL) THEN
         IF (child_coll.COUNT > 0) THEN
            i := child_coll.LAST;
         ELSE
            RETURN;
         END IF;

         WHILE (i IS NOT NULL) LOOP
            l_pk.id := child_coll(i).id;
            cg$nit_ci_types.del(l_pk);
            i := child_coll.PRIOR(i);
         END LOOP;

      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;

   FUNCTION get_could_in_stock_default(p_rec IN cg$nit_ci_types.cg$row_type)
      RETURN CHAR IS
      l_could_in_stock nit_ci_types.could_in_stock%TYPE;
   BEGIN
      IF (p_rec.NAME IS NULL OR p_rec.NAME <> nit_core_p.getp(the_root)) THEN
         SELECT could_in_stock
         INTO   l_could_in_stock
         FROM   nit_ci_types cit
         WHERE  cit.id = p_rec.cit_id;

         RETURN l_could_in_stock;
      END IF;

      RETURN 'N';
   END;

   FUNCTION get_need_po_default(p_rec IN cg$nit_ci_types.cg$row_type) RETURN CHAR IS
      l_need_po nit_ci_types.need_po%TYPE;
   BEGIN
      IF (p_rec.NAME IS NULL OR p_rec.NAME <> nit_core_p.getp(the_root)) THEN
         SELECT need_po
         INTO   l_need_po
         FROM   nit_ci_types cit
         WHERE  cit.id = p_rec.cit_id;
         RETURN l_need_po;
      END IF;

      RETURN 'N';
   END;

BEGIN
   nit_card_p.log(pl_module
                 ,pl_version);
END nit_ci_types_p;
/

prompt
prompt Creating package body NIT_CONFIG_ITEMS_P
prompt ========================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_config_items_p IS

   pl_version CONSTANT VARCHAR2(12) := '0.5.0.5';
   pl_module  CONSTANT VARCHAR2(30) := 'nit_config_items_p';

   --------------------------------------------------------------------------------------------------------
   FUNCTION package_version RETURN VARCHAR2 IS
   BEGIN
      RETURN pl_module || ' ' || pl_version;
   END;
   --------------------------------------------------------------------------------------------------------

   FUNCTION is_allowed_status_change(p_rec     IN cg$nit_config_items.cg$row_type
                                    ,p_old_rec IN cg$nit_config_items.cg$row_type)
      RETURN CHAR IS
      pl_subprg_name VARCHAR2(30) := 'is_allowed_status_change';
      cir_id         nit_ci_relations.id%TYPE;
      cia_id         nit_ci_attributes.id%TYPE;
      psn_id         nit_positions.id%TYPE;
   BEGIN

      IF (nit_core_p.is_allowed_ci_status_chg(p_old_rec.status
                                             ,p_rec.status) = 'N') THEN
         RETURN 'N';
      END IF;

      <<cir_compat_check>>
      BEGIN
         SELECT cir.id
         INTO   cir_id
         FROM   nit_ci_relations cir
         WHERE  (cir.ci_id_from = p_old_rec.id AND cir.obsolete = 'L' AND
                nit_core_p.is_compat_ci_props_ci(cir.status
                                                 ,p_rec.status) = 'N') OR
                (cir.ci_id_to = p_old_rec.id AND cir.obsolete = 'L' AND
                nit_core_p.is_compat_ci_props_ci(cir.status
                                                 ,p_rec.status) = 'N');
         -- Ha van ilyen az a baj, sz?val a too_many_rows nincs rendben, a no_data_found rendben van.
         -- Ha lefut kiv?tel n?lk?l az is hiba!
         RETURN 'N';
      EXCEPTION
         WHEN no_data_found THEN
            NULL;
         WHEN too_many_rows THEN
            RETURN 'N';
         WHEN OTHERS THEN
            nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                     ,dbms_utility.format_call_stack
                                     ,dbms_utility.format_error_stack
                                     ,'Y'
                                     ,pl_module
                                     ,pl_version
                                     ,pl_subprg_name
                                     ,'#');
            RAISE;

      END cir_compat_check;

      <<cia_compat_check>>
      BEGIN
         SELECT cia.id
         INTO   cia_id
         FROM   nit_ci_attributes cia
         WHERE  cia.ci_id = p_old_rec.id AND
                cia.obsolete = 'L' AND
                nit_core_p.is_compat_ci_props_ci(cia.status
                                                ,p_rec.status) = 'N';
         -- Ha van ilyen az a baj, sz?val a too_many_rows nincs rendben, a no_data_found rendben van.
         -- Ha lefut kiv?tel n?lk?l az is hiba!
         RETURN 'N';
      EXCEPTION
         WHEN no_data_found THEN
            NULL;
         WHEN too_many_rows THEN
            RETURN 'N';
         WHEN OTHERS THEN
            nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                     ,dbms_utility.format_call_stack
                                     ,dbms_utility.format_error_stack
                                     ,'Y'
                                     ,pl_module
                                     ,pl_version
                                     ,pl_subprg_name
                                     ,'#');
            RAISE;

      END cia_compat_check;

      <<psn_compat_check>>
      BEGIN
         SELECT psn.id
         INTO   psn_id
         FROM   nit_positions psn
         WHERE  psn.ci_id = p_old_rec.id AND
                psn.obsolete = 'L' AND
                nit_core_p.is_compat_ci_props_ci(psn.status
                                                ,p_rec.status) = 'N';
         -- Ha van ilyen az a baj, sz?val a too_many_rows nincs rendben, a no_data_found rendben van.
         -- Ha lefut kiv?tel n?lk?l az is hiba!
         RETURN 'N';
      EXCEPTION
         WHEN no_data_found THEN
            NULL;
         WHEN too_many_rows THEN
            RETURN 'N';

         WHEN OTHERS THEN
            nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                     ,dbms_utility.format_call_stack
                                     ,dbms_utility.format_error_stack
                                     ,'Y'
                                     ,pl_module
                                     ,pl_version
                                     ,pl_subprg_name
                                     ,'#');
            RAISE;

      END psn_compat_check;
      RETURN 'Y';

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#');
         RAISE;

   END;

   PROCEDURE archive(p_rec     IN OUT cg$nit_config_items.cg$row_type
                    ,p_old_rec IN cg$nit_config_items.cg$row_type
                    ,p_what    IN VARCHAR2) IS
      l_cia_rec   cg$nit_ci_attributes.cg$row_type;
      l_cia_ind   cg$nit_ci_attributes.cg$ind_type;
      l_opn_rec   cg$nit_operations.cg$row_type;
      l_cipt_name nit_ci_property_types.NAME%TYPE;
      l_count     NUMBER;

      pl_subprg_name VARCHAR2(30) := 'archive';
   BEGIN

      l_cia_rec.ci_id := p_rec.id;

      IF (p_what <> 'name' AND p_what <> 'status') THEN
         RETURN;
      END IF;

      IF (p_what = 'name') THEN
         l_cipt_name := nit_ci_property_types_p.get_name_cipt_name;
      ELSE
         -- p_what = status
         l_cipt_name := nit_ci_property_types_p.get_status_cipt_name;
      END IF;

      -- megkeress?k a CIT-hez tartoz? p_what tulajdons?g id-j?t
      <<search_cip_id>>
      BEGIN
         EXECUTE IMMEDIATE 'SELECT cip.id FROM nit_ci_properties cip ' ||
                           ',nit_ci_property_types cipt ' ||
                           'WHERE  cip.cipt_id = cipt.id AND ' ||
                           'cip.cit_id = :CIT_ID AND cipt.name ' ||
                           '= :CIPT_NAME'
            INTO l_cia_rec.cip_id
            USING p_rec.cit_id, l_cipt_name;
      EXCEPTION
         WHEN OTHERS THEN
            nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                     ,dbms_utility.format_call_stack
                                     ,dbms_utility.format_error_stack
                                     ,'Y'
                                     ,pl_module
                                     ,pl_version
                                     ,pl_subprg_name
                                     ,'#' || p_rec.id);
            RAISE;
      END search_cip_id;

      l_opn_rec.id := p_rec.opn_id;
      cg$nit_operations.slct(l_opn_rec);

      l_cia_rec.opn_id   := p_rec.opn_id;
      l_cia_rec.status   := nit_core_p.ci_props_statuses(nit_core_p.done_idx);
      l_cia_rec.obsolete := 'A';

      <<valid_from>>
      BEGIN
         SELECT MAX(cia.valid_until)
               ,COUNT(*)
         INTO   l_cia_rec.valid_from
               ,l_count
         FROM   nit_ci_attributes cia
         WHERE  cia.ci_id = p_rec.id AND
                cia.cip_id = l_cia_rec.cip_id;

         IF (l_count > 0) THEN
            l_cia_rec.valid_from := nit_core_p.push(l_cia_rec.valid_from);
         ELSE
            l_cia_rec.valid_from := p_old_rec.valid_from;
         END IF;
      EXCEPTION
         WHEN OTHERS THEN
            nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                     ,dbms_utility.format_call_stack
                                     ,dbms_utility.format_error_stack
                                     ,'Y'
                                     ,pl_module
                                     ,pl_version
                                     ,pl_subprg_name
                                     ,'#' || p_rec.id);
            RAISE;
      END valid_from;

      l_cia_rec.valid_until := nit_core_p.push_back(p_rec.valid_from);

      IF (p_what = 'name') THEN
         l_cia_rec.data := p_old_rec.NAME;
      ELSE
         -- p_what csak status lehet
         l_cia_rec.data := p_old_rec.status;
      END IF;

      l_cia_ind := cg$nit_ci_attributes.cg$ind_true;

      cg$nit_ci_attributes.called_from_package := FALSE;
      cg$nit_ci_attributes.ins(l_cia_rec
                              ,l_cia_ind);
   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;

   --------------------------------------------------------------------------------------------------------

   PROCEDURE pre_dml(p_rec IN OUT cg$nit_config_items.cg$row_type
                    ,p_ind IN OUT cg$nit_config_items.cg$ind_type
                    ,p_op  IN VARCHAR2) IS
      pl_subprg_name VARCHAR2(30) := 'pre_dml';
      ci_rec         cg$nit_config_items.cg$row_type;
      cit_rec        cg$nit_ci_types.cg$row_type;
   BEGIN
      IF (p_op <> 'INS' AND p_op <> 'UPD') THEN
         RETURN;
      END IF;

      nit_core_p.set_validity(p_rec.valid_from
                             ,p_rec.valid_until
                             ,p_rec.opn_id);

      IF (p_op = 'INS') THEN
         p_ind.id            := TRUE;
         p_ind.creation_date := TRUE;
         p_ind.created_by    := TRUE;
      END IF;

      p_ind.last_update_date := TRUE;
      p_ind.last_updated_by  := TRUE;
      p_ind.valid_from       := TRUE;

      IF (p_op = 'UPD') THEN
         ci_rec.id := p_rec.id;
         cg$nit_config_items.slct(ci_rec);
         IF (ci_rec.obsolete <> 'L') THEN
            nit_error_p.error('NIT-00051'
                             ,'E'
                             ,TRUE
                             ,ci_rec.NAME
                             ,cit_rec.NAME
                             ,ci_rec.obsolete
                             ,p_rec.obsolete);
         END IF;
      END IF;

      cit_rec.id := p_rec.cit_id;
      cg$nit_ci_types.slct(cit_rec);

      IF ((p_rec.status = nit_core_p.ci_statuses(nit_core_p.ci_in_stock_idx)) AND
         (cit_rec.could_in_stock = 'N')) THEN
         nit_error_p.error('NIT-00052'
                          ,'E'
                          ,TRUE
                          ,p_rec.NAME
                          ,NULL
                          ,NULL
                          ,NULL);

      END IF;

      nit_core_p.set_audit(p_rec.creation_date
                          ,p_rec.created_by
                          ,p_rec.last_update_date
                          ,p_rec.last_updated_by
                          ,p_op);

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;

   PROCEDURE pre_ins(p_rec IN OUT cg$nit_config_items.cg$row_type
                    ,p_ind IN OUT cg$nit_config_items.cg$ind_type) IS
      l_cit_rec         cg$nit_ci_types.cg$row_type;
      l_computer_cit_id nit_ci_types.id%TYPE;

      CURSOR c_computer_cit_id IS
         SELECT cit.id
         FROM   nit_ci_types cit
         WHERE  cit.NAME = 'computer'; -- hardcoding

      CURSOR c_sms_id(p_serialnumber nit_sms_system_enclosure.serialnumber%TYPE) IS
         SELECT cs.sms_id
         FROM   nit_sms_computer_system cs
         WHERE  cs.resource_id = (SELECT se.resource_id
                                  FROM   nit_sms_system_enclosure se
                                  WHERE  se.serialnumber = p_serialnumber AND
                                         rownum = 1)
         ORDER  BY cs.TIMESTAMP ASC;

      pl_subprg_name VARCHAR2(30) := 'pre_ins';
   BEGIN
      l_cit_rec.id := p_rec.cit_id;
      cg$nit_ci_types.slct(l_cit_rec);
      -- cit is importable
      IF (l_cit_rec.is_importable = 'Y') THEN
         OPEN c_computer_cit_id;
         FETCH c_computer_cit_id
            INTO l_computer_cit_id;
         CLOSE c_computer_cit_id;

         -- it is a computer descendant
         IF (l_computer_cit_id IS NOT NULL AND
            nit_core_p.exists_in(nit_ci_types_p.get_children_ids(l_computer_cit_id)
                                 ,l_cit_rec.id) = 'Y') THEN
            -- get SMS_ID
            OPEN c_sms_id(p_rec.NAME);
            FETCH c_sms_id
               INTO p_rec.sms_id;
            CLOSE c_sms_id;
         END IF;

      END IF;
   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;

   PROCEDURE pre_upd(p_rec IN OUT cg$nit_config_items.cg$row_type
                    ,p_ind IN OUT cg$nit_config_items.cg$ind_type) IS
      l_old_rec cg$nit_config_items.cg$row_type;
      opn_rec   cg$nit_operations.cg$row_type;

      pl_subprg_name VARCHAR2(30) := 'pre_upd';
   BEGIN
      l_old_rec.id := p_rec.id;
      cg$nit_config_items.slct(l_old_rec);

      opn_rec.id := p_rec.opn_id;
      cg$nit_operations.slct(opn_rec);

      IF (l_old_rec.obsolete <> 'L') THEN
         nit_error_p.error('NIT-00053'
                          ,'E'
                          ,TRUE
                          ,NULL
                          ,NULL
                          ,NULL
                          ,p_rec.id);
      END IF;

      IF (nit_core_p.is_allowed_obsolete_chg(l_old_rec.obsolete
                                            ,p_rec.obsolete) = 'N') THEN
         nit_error_p.error('NIT-00054'
                          ,'E'
                          ,TRUE
                          ,l_old_rec.obsolete
                          ,p_rec.obsolete
                          ,NULL
                          ,p_rec.id);
      END IF;

      IF (opn_rec.type_name =
         nit_operations_p.operation_types(nit_operations_p.requested_idx) AND
         is_allowed_status_change(p_rec
                                  ,l_old_rec) = 'N') THEN
         nit_error_p.error('NIT-00055'
                          ,'E'
                          ,TRUE
                          ,l_old_rec.status
                          ,p_rec.status
                          ,NULL
                          ,p_rec.id);
      END IF;

      IF (p_ind.NAME) THEN
         archive(p_rec
                ,l_old_rec
                ,'name');
      END IF;

      IF (p_ind.status) THEN
         archive(p_rec
                ,l_old_rec
                ,'status');
         IF (p_rec.status = nit_core_p.ci_statuses(nit_core_p.ci_eol_idx)) THEN
            p_ind.obsolete := TRUE;
            p_rec.obsolete := 'D';
         END IF;
      END IF;

      p_ind.opn_id := FALSE;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;

   PROCEDURE post_ins(p_rec IN OUT cg$nit_config_items.cg$row_type
                     ,p_ind IN OUT cg$nit_config_items.cg$ind_type) IS
      pl_subprg_name VARCHAR2(30) := 'post_ins';
   BEGIN
      nit_ci_relations_p.create_cir(p_rec.id);
   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;

   /* Ha a konfigur?ci?s elem egy rel?ci?ban tartalmazott szerepet t?lt be,
   a st?tuszv?lt?s ?rintheti a tartalmaz? elemet. Ez jelenleg EOL st?tuszra nem ?rv?nyes. */

   PROCEDURE cascade_upd(p_rec IN OUT cg$nit_config_items.cg$row_type
                        ,p_ind IN OUT cg$nit_config_items.cg$ind_type) IS
      pl_subprg_name VARCHAR2(30) := 'cascade_upd';

      l_rec                  cg$nit_config_items.cg$row_type;
      l_old_rec              cg$nit_config_items.cg$row_type;
      l_ind                  cg$nit_config_items.cg$ind_type;
      l_has_different_status CHAR;

      CURSOR c_contains(p_id IN nit_config_items.id%TYPE) IS
         SELECT cir.ci_id_from
         FROM   nit_ci_relations       cir
               ,nit_ci_type_relations  citr
               ,nit_cit_relation_types citrt
         WHERE  cir.obsolete = 'L' AND
                cir.ci_id_to = p_id AND
                cir.citr_id = citr.id AND
                citr.citrt_id = citrt.id AND
                (citrt.NAME = nit_cit_relation_types_p.get_contains_rel_name OR
                citrt.NAME =
                nit_cit_relation_types_p.get_installed_on_rel_name);
      CURSOR c_different_status(p_ci_id_from IN nit_config_items.id%TYPE, p_ci_id_to IN nit_config_items.id%TYPE, p_status nit_config_items.status%TYPE) IS
         SELECT 'X'
         FROM   nit_config_items       ci
               ,nit_ci_relations       cir
               ,nit_ci_type_relations  citr
               ,nit_cit_relation_types citrt
         WHERE  cir.obsolete = 'L' AND
                cir.ci_id_from = p_ci_id_from AND
                cir.ci_id_to <> p_ci_id_to AND
                cir.ci_id_to = ci.id AND
                ci.status <> p_status AND
                cir.citr_id = citr.id AND
                citr.citrt_id = citrt.id AND
                (citrt.NAME = nit_cit_relation_types_p.get_contains_rel_name OR
                citrt.NAME =
                nit_cit_relation_types_p.get_installed_on_rel_name);
   BEGIN
      /* EOL-t figyelmen k?v?l hagyjuk */
      IF (p_ind.status AND
         p_rec.status NOT IN (nit_core_p.ci_statuses(nit_core_p.ci_eol_idx))) THEN
         l_ind.status := TRUE;
         FOR v_id_rec IN c_contains(p_rec.id) LOOP
            l_old_rec.id        := v_id_rec.ci_id_from;
            l_old_rec.the_rowid := NULL;
            cg$nit_config_items.slct(l_old_rec);
            l_rec        := l_old_rec;
            l_rec.status := p_rec.status;

            /* Lefel? ir?nyba automatikus a v?lt?s */
            IF (nit_core_p.is_ci_status_chg_downgrade(from_status => l_old_rec.status
                                                     ,to_status   => l_rec.status) = 'Y') THEN
               IF (is_allowed_status_change(p_rec     => l_rec
                                           ,p_old_rec => l_old_rec) = 'Y') THEN
                  cg$nit_config_items.upd(l_rec
                                         ,l_ind);
               END IF;

               /* Norm?l st?tuszv?lt?s, vizsg?ljuk a contains rel?ci?val kapcsol?d? egy?b elemeket is */
            ELSE
               l_has_different_status := NULL;
               OPEN c_different_status(l_rec.id
                                      ,p_rec.id
                                      ,p_rec.status);
               FETCH c_different_status
                  INTO l_has_different_status;
               CLOSE c_different_status;
               /* Minden contains rel?ci?val kapcsol?d? elem st?tusza azonos, v?ltjuk a tartalmaz? st?tusz?t */
               IF (l_has_different_status IS NULL) THEN
                  IF (is_allowed_status_change(p_rec     => l_rec
                                              ,p_old_rec => l_old_rec) = 'Y') THEN
                     cg$nit_config_items.upd(l_rec
                                            ,l_ind);
                  END IF;
               END IF;
            END IF;
         END LOOP;
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;

   FUNCTION get_serial_suffix(s VARCHAR2) RETURN VARCHAR2 IS
      idx            PLS_INTEGER;
      len            PLS_INTEGER;
      pl_subprg_name VARCHAR2(30) := 'get_serial_suffix';

   BEGIN
      len := LENGTH(s);

      FOR i IN REVERSE 1 .. len LOOP
         IF (SUBSTR(s
                   ,i
                   ,1) NOT IN
            ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')) THEN
            idx := i;
            RETURN SUBSTR(s
                         ,idx + 1
                         ,len - idx);
         END IF;
      END LOOP;

      RETURN NULL;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || s);
         RAISE;

   END;

   FUNCTION get_default_name(p_rec IN cg$nit_config_items.cg$row_type)
      RETURN VARCHAR2 IS
      pl_subprg_name VARCHAR2(30) := 'get_default_name';
      next_num       PLS_INTEGER;
      name_part      VARCHAR2(300);
      --    cit_name       VARCHAR(200);
      name_convention_num PLS_INTEGER;
   BEGIN
      IF (p_rec.NAME IS NOT NULL) THEN
         name_part := TRIM(trailing FROM lower(SUBSTR(p_rec.NAME
                                       ,1
                                       ,LENGTH(p_rec.NAME) -
                                        NVL(LENGTH(get_serial_suffix(p_rec.NAME))
                                           ,0))));
      END IF;

      IF (name_part IS NULL) THEN
         SELECT COUNT(DISTINCT(nit_config_items_p.get_serial_suffix(ci.NAME)))
         INTO   name_convention_num
         FROM   nit_config_items ci
         WHERE  ci.cit_id = p_rec.cit_id;

         IF (name_convention_num = 1) THEN
            SELECT TRIM(trailing FROM
                        lower(SUBSTR(ci.NAME
                                    ,1
                                    ,LENGTH(ci.NAME) - NVL(LENGTH(get_serial_suffix(ci.NAME))
                                                          ,0))))
            INTO   name_part
            FROM   nit_config_items ci
            WHERE  ci.cit_id = p_rec.cit_id AND
                   rownum = 1;

         ELSE
            SELECT cit.NAME
            INTO   name_part
            FROM   nit_ci_types cit
            WHERE  cit.id = p_rec.cit_id;
         END IF;

      END IF;


      SELECT MAX(TO_NUMBER(nit_config_items_p.get_serial_suffix(ci.NAME))) + 1
      INTO   next_num
      FROM   nit_config_items ci
      WHERE  (TRIM(trailing FROM
                   lower(SUBSTR(ci.NAME
                               ,1
                               ,LENGTH(ci.NAME) - NVL(LENGTH(get_serial_suffix(ci.NAME))
                                                     ,0)))) = name_part) AND
             ci.cit_id = p_rec.cit_id;

      IF (next_num IS NULL) THEN
         next_num := 0;
      END IF;

      RETURN name_part || TO_CHAR(next_num
                                 ,'0999999');

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;

   FUNCTION get_default_name(p_cit_id IN nit_ci_types.id%TYPE) RETURN VARCHAR2 IS
      l_ci_rec cg$nit_config_items.cg$row_type;
   BEGIN
      l_ci_rec.cit_id := p_cit_id;
      RETURN get_default_name(l_ci_rec);
   END;

BEGIN
   nit_card_p.log(pl_module
                 ,pl_version);
END nit_config_items_p;
/

prompt
prompt Creating package body NIT_CORE_P
prompt ================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_core_p IS
   pl_version CONSTANT VARCHAR2(12) := '0.0.2.6';
   pl_module  CONSTANT VARCHAR2(30) := 'nit_core_p';

   PROCEDURE set_validity(p_valid_from  IN OUT nit_ci_attributes.valid_from%TYPE
                         ,p_valid_until IN OUT nit_ci_attributes.valid_until%TYPE
                         ,p_op          IN nit_ci_attributes.opn_id%TYPE) IS
      pl_subprg_name VARCHAR2(30) := 'set_validity';
   BEGIN
      IF (p_valid_from IS NULL) THEN
         SELECT op_time
         INTO   p_valid_from
         FROM   nit_operations
         WHERE  id = p_op;
      END IF;

      IF (p_valid_until IS NULL) THEN
         SELECT nit_core_p.get_infinite_date
         INTO   p_valid_until
         FROM   dual;
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         --         nit_operations_p.fail_operation(p_op);
         nit_error_p.log_exception(NULL --dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#');
         RAISE;

   END;

   FUNCTION get_session_user_id RETURN nit_users.id%TYPE IS
      ret            nit_users.id%TYPE;
      pl_subprg_name VARCHAR2(30) := 'get_session_user_id';
   BEGIN
      SELECT usr.id
      INTO   ret
      FROM   nit_users usr
      WHERE  upper(usr.username) =
             sys_context('USERENV'
                        ,'SESSION_USER');

      RETURN ret;
   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#KOLLEKCI?');

   END;

   FUNCTION package_version RETURN VARCHAR2 IS
   BEGIN
      RETURN pl_module || ' ' || pl_version;
   END;

   FUNCTION char_to_bool(p_char IN CHAR) RETURN BOOLEAN IS
   BEGIN
      IF (p_char = 'Y' OR p_char = 'T' OR p_char = 'I' OR p_char = 'y' OR
         p_char = 't' OR p_char = 'i') THEN
         RETURN TRUE;
      ELSE
         IF (p_char = 'N' OR p_char = 'F' OR p_char = 'n' OR p_char = 'f') THEN
            RETURN FALSE;
         END IF;
      END IF;

      RETURN NULL;
   END;

   FUNCTION bool_to_char(p_bool IN BOOLEAN) RETURN CHAR IS
   BEGIN
      IF (p_bool) THEN
         RETURN 'Y';
      END IF;
      RETURN 'N';
   END;

   FUNCTION convert(p_coll IN nit_string_ct) RETURN VARCHAR2 IS
      i              PLS_INTEGER;
      ret            VARCHAR2(4000);
      pl_subprg_name VARCHAR2(30) := 'CONVERT';
   BEGIN

      IF (p_coll IS NULL) THEN
         RETURN NULL;
      END IF;

      i   := p_coll.FIRST;
      ret := p_coll(i);

      WHILE (i IS NOT NULL) LOOP
         ret := ret || ',' || p_coll(i);
         i   := p_coll.NEXT(i);
      END LOOP;

   EXCEPTION
      WHEN subscript_beyond_count OR
           subscript_outside_limit THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#KOLLEKCI?');
         RETURN NULL;
      WHEN value_error THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#KOLLEKCI?');
         RETURN NULL;

      WHEN collection_is_null THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#KOLLEKCI?');
         RETURN NULL;

      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#KOLLEKCI?');
         RAISE;
   END;

   -- Tokeniz?l, a delimiter string is lehet, ?s egy?tt ?rtend?ek karakterei,
   -- meg?rti, ha 2 token k?z?tt t?bb delim van, s?t azt is, ha delimmel kezd?dik vagy v?gz?dik
   -- a string. A token m?rete nincs korl?tozva! Ha korlatozn?m, akkor egyszer?bb lenne a k?d.
   -- Mem?riak?m?l?bb de lassabb
   FUNCTION tokenize(p_str   IN VARCHAR2
                    ,p_delim IN VARCHAR2
                    ,p_start IN INTEGER) RETURN nit_string_ct IS
      ret            nit_string_ct := nit_string_ct();
      delim_len      PLS_INTEGER := LENGTH(p_delim);
      str_pos_from   PLS_INTEGER := p_start;
      str_pos_to     PLS_INTEGER;
      pl_subprg_name VARCHAR2(30) := 'TOKENIZE';
   BEGIN
      /* Orb?n Tam?s: gondok voltak... */
      IF (p_str IS NULL) THEN
         RETURN NULL;
      END IF;

      IF (str_pos_from IS NULL) THEN
         str_pos_from := 1;
      END IF;

      str_pos_to := INSTR(p_str
                         ,p_delim
                         ,str_pos_from);

      LOOP
         EXIT WHEN str_pos_from <> str_pos_to;
         str_pos_from := str_pos_to + delim_len;
         str_pos_to   := INSTR(p_str
                              ,p_delim
                              ,str_pos_from);
      END LOOP;

      WHILE (str_pos_from <> 0) LOOP
         str_pos_to := INSTR(p_str
                            ,p_delim
                            ,str_pos_from);
         LOOP
            EXIT WHEN str_pos_from <> str_pos_to;
            str_pos_from := str_pos_to + delim_len;
            str_pos_to   := INSTR(p_str
                                 ,p_delim
                                 ,str_pos_from);
         END LOOP;

         IF (str_pos_to = 0) THEN
            IF (str_pos_from = LENGTH(p_str) + 1) THEN
               RETURN ret;
            END IF;
            ret.EXTEND;
            ret(NVL(ret.LAST, 1)) := SUBSTR(p_str
                                           ,str_pos_from
                                           ,LENGTH(p_str) - str_pos_from + 1);
            EXIT;
         ELSE
            ret.EXTEND;
            ret(NVL(ret.LAST, 1)) := SUBSTR(p_str
                                           ,str_pos_from
                                           ,str_pos_to - str_pos_from);
            str_pos_from := str_pos_to + delim_len;
         END IF;
      END LOOP;

      RETURN ret;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_str || '#' || p_delim || '#' ||
                                   p_start);
         RAISE;
   END;

   FUNCTION convert(p_coll IN VARCHAR2) RETURN nit_string_ct IS
   BEGIN
      RETURN tokenize(p_coll
                     ,','
                     ,NULL);
   END;

   -- Optimize me: lehet gyorsabb lesz v?gigrohanni a kollekci?n ?s exists.re vizsg?lni az elemeit, mint ?gy..
   FUNCTION exists_in(p_coll    IN nit_string_ct
                     ,p_element IN VARCHAR2) RETURN CHAR IS
      i              PLS_INTEGER := p_coll.FIRST;
      pl_subprg_name VARCHAR2(30) := 'EXISTS_IN';
   BEGIN
      -- Majd a kiv?telkezel? megfogja..
      IF (p_coll.COUNT = 0) THEN
         RETURN 'N';
      END IF;

      WHILE (i IS NOT NULL) LOOP
         -- az?rt kell, mert LAST-ra NULL-t ad, ?s ezt kihaszn?lom
         IF (p_coll(i) = p_element) THEN
            RETURN 'Y';
         END IF;
         i := p_coll.NEXT(i);
      END LOOP;
      RETURN 'N';

   EXCEPTION
      -- A Kollekci?k ?ltal esetlegesen kiv?ltott kiv?teleket lenyelj?k, a t?bbi tov?bbengedj?k..
      WHEN subscript_beyond_count OR
           subscript_outside_limit THEN
         RETURN 'N'; -- Sose fog kiv?lt?dni, de biztos ami biztos
      WHEN value_error THEN
         RETURN NULL; -- Sose fog kiv?lt?dni, de biztos ami biztos
      WHEN collection_is_null THEN
         RETURN 'N'; -- Sose fog kiv?lt?dni, de biztos ami biztos
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_element);
         RAISE;

   END;

   FUNCTION exists_in(p_coll    IN nit_num_ct
                     ,p_element IN NUMBER) RETURN CHAR IS
      i              PLS_INTEGER := p_coll.FIRST;
      pl_subprg_name VARCHAR2(30) := 'EXISTS_IN';
   BEGIN
      IF (p_coll.COUNT = 0) THEN
         RETURN 'N';
      END IF;
      WHILE (i IS NOT NULL) LOOP
         -- az?rt kell, mert LAST-ra NULL-t ad, ?s ezt kihaszn?lom
         IF (p_coll(i) = p_element) THEN
            RETURN 'Y';
         END IF;
         i := p_coll.NEXT(i);
      END LOOP;
      RETURN 'N';

   EXCEPTION
      -- A Kollekci?k ?ltal esetlegesen kiv?ltott kiv?teleket lenyelj?k, a t?bbi tov?bbengedj?k..
      WHEN subscript_beyond_count OR
           subscript_outside_limit THEN
         RETURN 'N'; -- Sose fog kiv?lt?dni, de biztos ami biztos
      WHEN value_error THEN
         RETURN NULL; -- Sose fog kiv?lt?dni, de biztos ami biztos
      WHEN collection_is_null THEN
         RETURN 'N'; -- Sose fog kiv?lt?dni, de biztos ami biztos
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_element);
         RAISE;
   END;

   ------------------------------------------------------------------------------------------------------------

   PROCEDURE send_mail(p_mail_addresses IN VARCHAR2
                      ,subject          IN VARCHAR2
                      ,message          IN VARCHAR2) IS
      crlf CONSTANT VARCHAR2(2) := CHR(13) || CHR(10);
      conn           utl_smtp.connection := utl_smtp.open_connection(nit_core_p.getp('mailhost')
                                                                    ,nit_core_p.getpi('mailport'));
      msg            VARCHAR2(10000);
      pl_subprg_name VARCHAR2(30) := 'SEND_MAIL';
   BEGIN
      IF (validate_email_address(p_mail_addresses) = 'N') THEN
         NULL;
         --         RAISE nit_cant_send_mail_ex;
      END IF;

      msg := 'Date: ' || TO_CHAR(SYSDATE
                                ,'dd Mon yy hh24:mi:ss') || crlf || 'From: <' ||
             'NIT@ni.com' || '>' || crlf || 'Subject: ' || subject || crlf ||
             'To: ' || p_mail_addresses || crlf || '' || crlf || message;

      utl_smtp.helo(conn
                   ,nit_core_p.getpts('mailhost'));
      utl_smtp.mail(conn
                   ,'NIT@ni.com');
      utl_smtp.rcpt(conn
                   ,p_mail_addresses);
      utl_smtp.data(conn
                   ,msg);
      utl_smtp.quit(conn);
   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_mail_addresses);
         RAISE;
   END;

   FUNCTION validate_email_address(p_email IN VARCHAR2) RETURN CHAR IS
      conn           utl_smtp.connection := utl_smtp.open_connection(nit_core_p.getp('mailhost')
                                                                    ,nit_core_p.getpi('mailport'));
      my_reply       utl_smtp.reply;
      pl_subprg_name VARCHAR2(30) := 'VALIDATE_EMAIL_ADDRESS';
   BEGIN
      my_reply := utl_smtp.vrfy(conn
                               ,p_email);
      IF (my_reply.code <= 355) THEN
         RETURN 'Y';
      END IF;
      RETURN 'N';
      utl_smtp.quit(conn);

   EXCEPTION

      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_email);
         RAISE;

   END;

   PROCEDURE set_audit(p_creation_date IN OUT DATE
                      ,p_created_by    IN OUT VARCHAR2
                      ,p_last_upd_date IN OUT DATE
                      ,p_last_upd_by   IN OUT VARCHAR2
                      ,p_operation     IN VARCHAR2 DEFAULT 'INS') IS
      pl_subprg_name VARCHAR2(30) := 'SET_AUDIT';
      l_date         DATE := CURRENT_DATE;
   BEGIN

      IF p_operation = 'INS' THEN
         p_creation_date := l_date;
         p_created_by    := sys_context('USERENV'
                                       ,'SESSION_USER');
      END IF;

      IF ((p_operation = 'UPD') OR (p_operation = 'INS')) THEN
         p_last_upd_date := l_date;
         p_last_upd_by   := sys_context('USERENV'
                                       ,'SESSION_USER');
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || TO_CHAR(p_creation_date) || '#' ||
                                   p_created_by || '#' ||
                                   TO_CHAR(p_last_upd_date) || '#' ||
                                   p_last_upd_by);
         RAISE;
   END;

   PROCEDURE caseconv(p_str IN OUT NOCOPY VARCHAR2) IS
   BEGIN
      p_str := lower(p_str);
   END;

   FUNCTION get_allowed_statuses_props(p_status IN nit_ci_relations.status%TYPE)
      RETURN nit_string_ct IS
   BEGIN

      CASE
         WHEN p_status = ci_props_statuses(planned_idx) THEN
            RETURN nit_string_ct(ci_props_statuses(planned_idx)
                                ,ci_props_statuses(approved_idx));
         WHEN p_status = ci_props_statuses(approved_idx) THEN
            RETURN nit_string_ct(ci_props_statuses(approved_idx)
                                ,ci_props_statuses(tested_idx));
         WHEN p_status = ci_props_statuses(tested_idx) THEN
            RETURN nit_string_ct(ci_props_statuses(planned_idx)
                                ,ci_props_statuses(tested_idx)
                                ,ci_props_statuses(done_idx));
         WHEN p_status = ci_props_statuses(done_idx) THEN
            RETURN nit_string_ct(ci_props_statuses(planned_idx)
                                ,ci_props_statuses(done_idx));
         ELSE
            RETURN nit_string_ct(ci_props_statuses(planned_idx));
      END CASE;

   END;

   FUNCTION get_allowed_statuses_ci(p_status IN nit_ci_relations.status%TYPE)
      RETURN nit_string_ct IS
   BEGIN
      CASE
         WHEN p_status = ci_statuses(ci_ordered_idx) THEN
            RETURN nit_string_ct(ci_statuses(ci_ordered_idx)
                                ,ci_statuses(ci_in_stock_idx));
         WHEN p_status = ci_statuses(ci_in_use_idx) THEN
            RETURN nit_string_ct(ci_statuses(ci_in_use_idx)
                                ,ci_statuses(ci_in_stock_idx)
                                ,ci_statuses(ci_eol_idx));
         WHEN p_status = ci_statuses(ci_planned_idx) THEN
            RETURN nit_string_ct(ci_statuses(ci_planned_idx)
                                ,ci_statuses(ci_approved_idx));
         WHEN p_status = ci_statuses(ci_approved_idx) THEN
            RETURN nit_string_ct(ci_statuses(ci_tested_idx));
         WHEN p_status = ci_statuses(ci_tested_idx) THEN
            RETURN nit_string_ct(ci_statuses(ci_planned_idx)
                                ,ci_statuses(ci_in_use_idx));
         WHEN p_status = ci_statuses(ci_eol_idx) THEN
            RETURN nit_string_ct(ci_statuses(ci_eol_idx));
         WHEN p_status = ci_statuses(ci_in_stock_idx) THEN
            RETURN nit_string_ct(ci_statuses(ci_in_stock_idx)
                                ,ci_statuses(ci_in_use_idx));
         ELSE
            RETURN nit_string_ct(ci_statuses(ci_planned_idx)
                                ,ci_statuses(ci_ordered_idx));

      END CASE;
   END;

   FUNCTION get_allowed_obsoletes(p_obsolete IN nit_ci_relations.obsolete%TYPE)
      RETURN nit_string_ct IS
   BEGIN

      CASE
         WHEN p_obsolete = 'L' THEN
            RETURN nit_string_ct('L'
                                ,'A'
                                ,'D');
         WHEN p_obsolete = 'D' THEN
            RETURN nit_string_ct('D');
         WHEN p_obsolete = 'A' THEN
            RETURN nit_string_ct('A');
         ELSE
            RETURN nit_string_ct('L');
      END CASE;

   END;

   FUNCTION get_infinite_date RETURN DATE IS
   BEGIN
      RETURN TO_DATE('01-01-4000'
                    ,'DD-MM-YYYY');
   END;

   FUNCTION get_negative_infinite_date RETURN DATE IS
   BEGIN
      RETURN TO_DATE('0001.01.01. 00:00:00'
                    ,'YYYY.MM.DD. HH24:MI:SS');
   END;

   FUNCTION push(p_time IN DATE) RETURN DATE IS
      /* Orb?n Tam?s: az eredeti '00:01' nem m?k?dik */
      offset CONSTANT INTERVAL DAY TO SECOND := '0 00:0:01.0';
   BEGIN
      RETURN p_time + offset;
   END;

   FUNCTION push_back(p_time IN DATE) RETURN DATE IS
      /* Orb?n Tam?s: az eredeti '00:01' nem m?k?dik */
      offset CONSTANT INTERVAL DAY TO SECOND := '0 00:00:01.0';
   BEGIN
      RETURN p_time - offset;
   END;

   FUNCTION is_allowed_obsolete_chg(from_obs IN nit_ci_relations.obsolete%TYPE
                                   ,to_obs   IN nit_ci_relations.obsolete%TYPE)
      RETURN CHAR IS
   BEGIN
      RETURN exists_in(get_allowed_obsoletes(from_obs)
                      ,to_obs);
   END;

   FUNCTION is_allowed_ci_props_status_chg(from_status IN nit_ci_relations.status%TYPE
                                          ,to_status   IN nit_ci_relations.status%TYPE)
      RETURN CHAR IS
   BEGIN
      RETURN exists_in(get_allowed_statuses_props(from_status)
                      ,to_status);
   END;

   FUNCTION is_allowed_ci_status_chg(from_status IN nit_config_items.status%TYPE
                                    ,to_status   IN nit_config_items.status%TYPE)
      RETURN CHAR IS
   BEGIN
      RETURN exists_in(get_allowed_statuses_ci(from_status)
                      ,to_status);
   END;

   /* Megadja, hogy a st?tuszv?lt?s lefel? ir?nyba t?rt?nik-e. Egyszerubb felsorolni,
   mint a m?sik ir?nyban */
   FUNCTION is_ci_status_chg_downgrade(from_status IN nit_config_items.status%TYPE
                                      ,to_status   IN nit_config_items.status%TYPE)
      RETURN CHAR IS
   BEGIN
      IF (from_status = ci_statuses(ci_tested_idx) AND
         to_status = ci_statuses(ci_planned_idx)) THEN
         RETURN 'Y';
      END IF;

      RETURN 'N';
   END;

   FUNCTION is_compat_ci_props_ci(p_ci_props_status IN VARCHAR2
                                 ,p_ci_status       IN VARCHAR2) RETURN CHAR IS
   BEGIN
      IF (p_ci_status = ci_statuses(ci_ordered_idx) OR
         p_ci_status = ci_statuses(ci_planned_idx)) THEN
         CASE p_ci_props_status
            WHEN ci_props_statuses(planned_idx) THEN
               RETURN 'Y';
            WHEN ci_props_statuses(approved_idx) THEN
               RETURN 'Y';
            WHEN ci_props_statuses(tested_idx) THEN
               RETURN 'Y';
            WHEN ci_props_statuses(done_idx) THEN
               RETURN 'Y';
            ELSE
               RETURN 'N';
         END CASE; END IF;

      IF (p_ci_status = ci_statuses(ci_eol_idx)) THEN
         IF (p_ci_props_status = ci_props_statuses(done_idx)) THEN
            RETURN 'Y';
         ELSE
            RETURN 'N';
         END IF;
      END IF;

      IF (p_ci_status = ci_statuses(ci_in_use_idx)) THEN
         CASE p_ci_props_status
            WHEN ci_props_statuses(tested_idx) THEN
               RETURN 'Y';
            WHEN ci_props_statuses(done_idx) THEN
               RETURN 'Y';
            ELSE
               RETURN 'N';
         END CASE; END IF;

      IF (p_ci_status = ci_statuses(ci_approved_idx)) THEN
         CASE p_ci_props_status
            WHEN ci_props_statuses(approved_idx) THEN
               RETURN 'Y';
            WHEN ci_props_statuses(tested_idx) THEN
               RETURN 'Y';
            WHEN ci_props_statuses(done_idx) THEN
               RETURN 'Y';
            ELSE
               RETURN 'N';
         END CASE; END IF;

      IF (p_ci_status = ci_statuses(ci_tested_idx)) THEN
         CASE p_ci_props_status
            WHEN ci_props_statuses(tested_idx) THEN
               RETURN 'Y';
            WHEN ci_props_statuses(done_idx) THEN
               RETURN 'Y';
            ELSE
               RETURN 'N';
         END CASE; END IF;

      IF (p_ci_status = ci_statuses(ci_in_stock_idx)) THEN
         CASE p_ci_props_status
            WHEN ci_props_statuses(done_idx) THEN
               RETURN 'Y';
            ELSE
               RETURN 'N';
         END CASE; END IF;
      RETURN 'N';
   END;

   FUNCTION get_ci_eol_status_name RETURN VARCHAR2 IS
   BEGIN
      RETURN ci_statuses(ci_eol_idx);
   END;

   FUNCTION get_parameter_value(p_name IN nit_parameters.NAME%TYPE)
      RETURN nit_parameters%ROWTYPE IS
      pl_subprg_name VARCHAR2(30) := 'get_parameter_value';

      CURSOR c_rec(p_name IN nit_parameters.NAME%TYPE) IS
         SELECT p.*
         FROM   nit_parameters p
         WHERE  upper(p.NAME) = upper(p_name);

      v_rec nit_parameters%ROWTYPE;
   BEGIN
      OPEN c_rec(p_name);
      FETCH c_rec
         INTO v_rec;
      CLOSE c_rec;

      RETURN v_rec;
   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_name);
   END;

   FUNCTION getp(p_name IN nit_parameters.NAME%TYPE) RETURN VARCHAR2 IS
   BEGIN
      RETURN get_parameter_value(p_name) .VALUE;
   END;

   FUNCTION getpi(p_name IN nit_parameters.NAME%TYPE) RETURN INTEGER IS
      ret nit_parameters%ROWTYPE;
   BEGIN
      ret := get_parameter_value(p_name);

      IF (upper(ret.data_type) = 'INTEGER') THEN
         RETURN CAST(ret.VALUE AS INTEGER);
      END IF;

      RETURN NULL;
   END;

   FUNCTION getpn(p_name IN nit_parameters.NAME%TYPE) RETURN NUMBER IS
      ret nit_parameters%ROWTYPE;
   BEGIN
      ret := get_parameter_value(p_name);

      IF (upper(ret.data_type) = 'NUMBER') THEN
         RETURN CAST(ret.VALUE AS NUMBER);
      END IF;

      RETURN NULL;
   END;

   FUNCTION getpd(p_name IN nit_parameters.NAME%TYPE) RETURN DATE IS
      ret nit_parameters%ROWTYPE;
   BEGIN
      ret := get_parameter_value(p_name);

      IF (upper(ret.data_type) = 'DATE') THEN
         RETURN TO_DATE(ret.VALUE
                       ,'YYYY.MM.DD. HH24:MI:SS');
      END IF;

      RETURN NULL;
   END;

   FUNCTION getpts(p_name IN nit_parameters.NAME%TYPE) RETURN TIMESTAMP IS
      ret nit_parameters%ROWTYPE;
   BEGIN
      ret := get_parameter_value(p_name);

      IF (upper(ret.data_type) = 'TIMESTAMP') THEN
         RETURN TO_TIMESTAMP(ret.VALUE
                            ,'YYYY.MM.DD. HH24:MI:SS');
      END IF;

      RETURN NULL;
   END;


BEGIN
   nit_card_p.log(pl_module
                 ,pl_version);
END nit_core_p;
/

prompt
prompt Creating package body NIT_ERROR_P
prompt =================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_error_p IS
   g_version CONSTANT VARCHAR2(12) := '0.2.4';
   g_module  CONSTANT VARCHAR2(30) := 'nit_error_p';
   is_ex_logging BOOLEAN := TRUE;

   /*
   1.0.9 Ill?s Sz?ks?gtelen a geterrors visszaadott ?rt?k?t k_msg_size-ra (512) korl?tozni
   1.0.8 Ill?s A convert_to_text f?ggv?ny publikus
   1.0.7 Ill?s K?dtiszt?t?s a convert_to_text f?ggv?ny bevezet?s?vel
   1.0.6 Ill?s Az error elj?r?s hagyja meg a hibak?dot is az ?zenet elej?n
   1.0.5 Ill?s Az error elj?r?s argumentumainak legyenek default ?rt?kei
   1.0.4 Ill?s Az error elj?r?ssal b?v?tve.
   */

   -----------------------------------------------------------------------

   cg$err_msg      cg$err_msg_t;
   cg$err_error    cg$err_error_t;
   cg$err_msg_type cg$err_msg_type_t;
   cg$err_msgid    cg$err_msgid_t;
   cg$err_loc      cg$err_loc_t;

   -----------------------------------------------------------------------

   FUNCTION package_version RETURN VARCHAR2 IS
      -- PL/SQL Block
   BEGIN
      RETURN g_version;
   END package_version;

   -----------------------------------------------------------------------

   PROCEDURE enable_ex_logging IS
   BEGIN
      is_ex_logging := TRUE;
   END;

   PROCEDURE disable_ex_logging IS
   BEGIN
      is_ex_logging := FALSE;
   END;

   FUNCTION get_ex_logging RETURN CHAR IS
   BEGIN
      IF (is_ex_logging) THEN
         RETURN 'Y';
      END IF;
      RETURN 'N';
   END;

   PROCEDURE log_exception_inside(ex_backtrace_str IN VARCHAR2
                                 ,ex_call_str      IN VARCHAR2
                                 ,ex_error_str     IN VARCHAR2
                                 ,ex_in_engine     IN VARCHAR2
                                 ,ex_module        IN VARCHAR2
                                 ,ex_version       IN VARCHAR2
                                 ,ex_sub           IN VARCHAR2
                                 ,ex_params        IN VARCHAR2) IS

      PRAGMA AUTONOMOUS_TRANSACTION;
      ex_rec nit_exceptions%ROWTYPE;
      coll   nit_string_ct;

   BEGIN
      SELECT nit_seq.NEXTVAL
      INTO   ex_rec.id
      FROM   dual;
      ex_rec.in_engine       := ex_in_engine;
      ex_rec.module_name     := ex_module;
      ex_rec.module_version  := ex_version;
      ex_rec.error_stack     := ex_error_str;
      ex_rec.call_stack      := ex_call_str;
      ex_rec.backtrace       := ex_backtrace_str;
      ex_rec.subprogram_name := ex_sub;
      ex_rec.stamp           := CURRENT_DATE;
      ex_rec.hostname        := sys_context('USERENV'
                                           ,'HOST');
      ex_rec.username        := sys_context('USERENV'
                                           ,'SESSION_USER');
      ex_rec.call_parameters := ex_params;

      coll           := nit_core_p.tokenize(ex_rec.error_stack
                                           ,':'
                                           ,0);
      ex_rec.code    := coll(1);
      ex_rec.NAME    := coll(2);
      ex_rec.message := ex_rec.error_stack;
      IF (ex_rec.backtrace IS NOT NULL) THEN
         coll := nit_core_p.tokenize(ex_rec.backtrace
                                    ,':'
                                    ,0);
         coll(2) := REPLACE(coll(2)
                           ,'.'
                           ,'');
         /*                        Ez a k?d csak a tesztel?s sor?n lehetett volna fontos, only 10g, kiszedj?k
               ex_rec.line_no := to_number(regexp_substr(coll(2)
                                                        ,'[0-9]+')
                                          ,'9999');
         */
      ELSE
         ex_rec.line_no := NULL;
      END IF;

      INSERT INTO nit_exceptions
      VALUES ex_rec;
      COMMIT WORK;

      -- Annak ?rdek?ben, hogy nehogy valamif?le k?rk?r?ss?g alakuljon ki egyenl?re elnyelj?k a loggol?ban a kiv?teleket FIXME.
   EXCEPTION
      WHEN OTHERS THEN
         NULL;
   END;

   PROCEDURE log_exception(ex_backtrace_str IN VARCHAR2
                          ,ex_call_str      IN VARCHAR2
                          ,ex_error_str     IN VARCHAR2
                          ,ex_in_engine     IN VARCHAR2
                          ,ex_module        IN VARCHAR2
                          ,ex_version       IN VARCHAR2
                          ,ex_sub           IN VARCHAR2
                          ,ex_params        IN VARCHAR2) IS
   BEGIN
      IF (is_ex_logging) THEN
         log_exception_inside(ex_backtrace_str
                             ,ex_call_str
                             ,ex_error_str
                             ,ex_in_engine
                             ,ex_module
                             ,ex_version
                             ,ex_sub
                             ,ex_params);
      END IF;
   END;

   --------------------------------------------------------------------------------
   -- Name:        parse_constraint
   -- Description: Isolate constraint name from an Oracle error message
   -- Parameters:  msg     The actual Oracle error message
   --              type    type of constraint to find
   --                      (ERR_FOREIGN_KEY     Foreign key,
   --                       ERR_CHECK_CON       Check,
   --                       ERR_UNIQUE_KEY      Unique key,
   --                       ERR_DELETE_RESTRICT Restricted delete)
   -- Returns:     con_name Constraint found (NULL if none found)

   FUNCTION parse_constraint(msg  IN VARCHAR2
                            ,TYPE IN INTEGER) RETURN VARCHAR2 IS
      start_pos NUMBER;
      con_name  VARCHAR2(100) := '';
   BEGIN
      IF (TYPE = err_foreign_key OR TYPE = err_check_con OR
         TYPE = err_unique_key OR TYPE = err_delete_restrict) THEN
         start_pos := INSTR(msg
                           ,'.'
                           ,INSTR(msg
                                 ,'('));

         IF start_pos != 0 THEN
            con_name := SUBSTR(msg
                              ,start_pos + 1
                              ,INSTR(msg
                                    ,')'
                                    ,start_pos) - start_pos - 1);
         END IF;
      END IF;

      RETURN con_name;
   END;

   --------------------------------------------------------------------------------
   -- Name:        MsgGetText
   -- Description: Provides a mechanism for text translation.
   -- Parameters:  p_MsgNo    The Id of the message
   --              p_DfltText The Default Text
   --              p_Subst1 (to 4) Substitution strings
   --              p_LangId   The Language ID
   -- Returns:    Translated message (truncated to k_msg_size bytes)

   FUNCTION msggettext(p_msgno    IN NUMBER
                      ,p_dflttext IN VARCHAR2
                      ,p_subst1   IN VARCHAR2
                      ,p_subst2   IN VARCHAR2
                      ,p_subst3   IN VARCHAR2
                      ,p_subst4   IN VARCHAR2
                      ,p_langid   IN NUMBER) RETURN VARCHAR2 IS
      l_temp VARCHAR2(32000) := p_dflttext;
      l_lang VARCHAR2(2) := 'US'; -- ez a default
      /* El?szedi a p_dflttext (a hiba "k?d"-ja) k?dnak megfelel? sz?veget, azon a nyelven, amin a user bejelentkezett

         (pontosabban ami a nit_users t?bl?ban az illet? sessiont futtat? userhez nyelvk?nt van rendelve a nit_users t?bl?ban,
         azaz minden bel?pni k?pes usernek (bele?rtve a virtu?lis 'nitil'-t is, rendelkeznie kell rekorddal a nitil_users t?bl?ban!)

         Azaz Magyarorsz?gon a hiba?zenetek nyelve magyar lesz, USA-ban meg angol.
         Azaz itt ha amerikai kollega ?l le a g?p el?, akkor is magyar nyelv? hiba?zenetet fog kapni.

         FIXME: Vigy?zat! Ez a megold?si m?d felt?telezi azt, hogy a t?nyleges felhaszn?l?k adatb?zis felhaszn?l?k is ?s
         ugymond az ? nev?kben fut az alkalmaz?s..Ez webes k?rnyezetben nem felt?tlen?l van ?gy, ut?nna kell n?zni...

         Ha azt a megold?st fogjuk v?lasztani, hogy minden a nitil user nev?ben fut ?s csak a kliens szintj?n van felhaszn?l? kezel?s, akkor
         ez a fajta nyelvi megk?l?nb?zet?s nem fog m?k?dni, mert nem tudjuk, hogy ?ppen ki van bent (m?rmint szerver oldalon), azaz
         a hiba?zenet k?rt nyelv?t a kliensnek kell ?ll?tania, most a szerver ezt automatikusan megcsin?lja...

         FIXME: vegy?k ?szre, hogy a p_langid sehol sincs haszn?lva!

         DE: Az?rt csin?ltam meg ?gy, mert az oper?ci? is annak a usernek a nev?ben indul, aki ?ppen a sessiont futtatja, azaz lesz user bejegyz?s
         hozz?
      */

      CURSOR c_msg(p_lang IN VARCHAR2) IS
         SELECT msg.message
         FROM   nit_messages msg
         WHERE  msg.code = p_dflttext AND
                msg.source_lang = p_lang;

      CURSOR c_lang IS
         SELECT usr.LANGUAGE
         FROM   nit_users usr
         WHERE  upper(usr.username) =
                sys_context('USERENV'
                           ,'CURRENT_USER');

   BEGIN
      IF c_msg%ISOPEN THEN
         CLOSE c_msg;
      END IF;

      IF c_lang%ISOPEN THEN
         CLOSE c_lang;
      END IF;

      OPEN c_lang;

      FETCH c_lang
         INTO l_lang;


      OPEN c_msg(l_lang);
      FETCH c_msg
         INTO l_temp;

      IF c_msg%NOTFOUND THEN
         l_temp := p_dflttext;
      END IF;

      CLOSE c_msg;
      l_temp := REPLACE(l_temp
                       ,'<p1>'
                       ,p_subst1);
      l_temp := REPLACE(l_temp
                       ,'<p2>'
                       ,p_subst2);
      l_temp := REPLACE(l_temp
                       ,'<p3>'
                       ,p_subst3);
      l_temp := REPLACE(l_temp
                       ,'<p4>'
                       ,p_subst4);
      RETURN SUBSTR(l_temp
                   ,1
                   ,k_msg_size);
   END msggettext;

   --------------------------------------------------------------------------------
   -- A convert_to_text funkci? megk?s?rli ?tford?tani a hibak?dot hiba?zenett?.
   -- Ha siker?lt, az elej?re teszi a hibak?dot is.

   FUNCTION convert_to_text(p_msg VARCHAR2
                           ,p_p1  VARCHAR2 DEFAULT NULL
                           ,p_p2  VARCHAR2 DEFAULT NULL
                           ,p_p3  VARCHAR2 DEFAULT NULL
                           ,p_p4  VARCHAR2 DEFAULT NULL) RETURN VARCHAR2 IS
      l_temp VARCHAR2(32000); -- k_msg_size kellene, de itt nem lehet konstans
   BEGIN
      --
      -- Egy ?zenet hossza legfeljebb ennyi lehet
      --
      l_temp := SUBSTR(p_msg
                      ,1
                      ,k_msg_size);
      --
      -- Ha p_temp egy hibak?dnak l?tszik, akkor megpr?b?ljuk  "leford?tani" a nyelvi t?bl?b?l
      --
      IF LENGTH(p_msg) = 9 AND
         SUBSTR(p_msg
               ,4
               ,1) = '-' THEN
         l_temp := nit_error_p.msggettext(20000
                                         ,p_msg
                                         ,p_p1
                                         ,p_p2
                                         ,p_p3
                                         ,p_p4);
         --
         -- Ha siker?lt, akkor el??rjuk a hibak?dot is (de ?gy sem lehet hosszabb a maximumn?l)
         --
         IF l_temp <> p_msg THEN
            l_temp := SUBSTR(p_msg || ': ' || l_temp
                            ,1
                            ,k_msg_size);
         END IF;
      END IF;
      --
      -- Visszat?r?nk az (esetleg konvert?lt) hiba?zenettel
      --
      RETURN l_temp;
   END convert_to_text;

   -----------------------------------------------------------------------------
   -- Name:        geterrors
   -- Description: Pops all messages off the stack and returns them in the order
   --              in which they were raised.
   -- Parameters:  none
   -- Returns:     The messages

   FUNCTION geterrors RETURN VARCHAR2 IS
      i_error_mess VARCHAR2(32000) := '';
      i_next_mess  VARCHAR2(32000) := ''; -- El?g lenne k_msg_size, de itt nem lehet konstans
   BEGIN
      WHILE pop(i_next_mess) LOOP
         IF i_error_mess IS NULL THEN
            i_error_mess := i_next_mess;
         ELSE
            --        i_error_mess := substr( i_next_mess || chr( 10 ) || i_error_mess, 1, k_msg_size );
            i_error_mess := SUBSTR(i_next_mess || CHR(10) || i_error_mess
                                  ,1
                                  ,32000);
         END IF;
      END LOOP;

      RETURN(i_error_mess);
   END;

   -----------------------------------------------------------------------------
   -- Name:        LookErrors
   -- Description: Pops all messages off the stack and returns them in the
   --              reverse order in which they were raised.
   -- Parameters:  none
   -- Returns:     The messages
   -----------------------------------------------------------------------------
   /*
      FUNCTION LookErrors RETURN varchar2
      IS
         maxMessageLength  constant integer := 32767;
         agregatedMessage  varchar2(32767);
         nextMessage       varchar2(512);
      BEGIN
        -- B2401878 : Return errors in reverse order like GetErrors
        -- for i in 1..cg$err_tab_i-1 loop
        for i in reverse 1..cg$err_tab_i-1
        loop
          if agregatedMessage IS NULL
          then
            agregatedMessage := 'TAPI-' || to_char(cg$err_msgid(i)) || ':' || cg$err_msg(i);
          else
            if ( (  length(agregatedMessage)
                  + length(cg$err_msg(i))
                  + length(to_char(cg$err_msgid(i))) + 16 ) < maxMessageLength )  -- B2401878 : add length check
            then
              agregatedMessage := agregatedMessage || chr(10) ||
                                  '           TAPI-' || to_char(cg$err_msgid(i)) || ':' || cg$err_msg(i);
             end if;
          end if;
        end loop;

        return agregatedMessage;
      END;
   */

   --------------------------------------------------------------------------------
   -- Name:        raise_failure
   --
   -- Description: To raise the cg$error failure exception handler

   PROCEDURE raise_failure IS
   BEGIN

      RAISE nit_error_p.cg$error;
   END raise_failure;

   /*
      --------------------------------------------------------------------------------
      -- Name:        raise_failure
      --
      -- Description: To raise the cg$error failure exception handler
      --------------------------------------------------------------------------------
      PROCEDURE raise_failure
      IS
      BEGIN
          raise_application_error(-20999, LookErrors);
      END raise_failure;
   */

   --------------------------------------------------------------------------------
   -- Name:        push
   --
   -- Description: Put a message on stack with full info
   --
   -- Parameters:  msg      Text message
   --              error    ERRor or WARNing
   --              msg_type ORA, API or user TLA
   --              msg_id   Id of message
   --              loc      Location where error occured

   PROCEDURE push(msg      IN VARCHAR2
                 ,error    IN VARCHAR2 DEFAULT 'E'
                 ,msg_type IN VARCHAR2 DEFAULT NULL
                 ,msgid    IN INTEGER DEFAULT 0
                 ,loc      IN VARCHAR2 DEFAULT NULL) IS
   BEGIN
      /*
      -- Eredeti k?d:
          if  substr( msg, 4, 1 ) = '-' and length( msg ) = 9 then
            l_temp := msggettext( 20000, msg );

            -- Ha az MsgGetText valamit tal?lt, ?s az nem hibak?d, akkor hozz?rakjuk
            -- a hibak?dot is (esetleg csonkolva a v?g?t)
            if substr( l_temp, 4, 1 ) <> '-' then
              l_temp := substr( msg || ': ' || l_temp, 1, k_msg_size );
            end if;

            cg$err_msg( cg$err_tab_i ) := l_temp;
          else
            cg$err_msg( cg$err_tab_i ) := msg;
          end if;
      -- M?dos?tott k?d (Ill?s 1.0.7):
      */
      cg$err_msg(cg$err_tab_i) := nit_error_p.convert_to_text(msg);
      cg$err_error(cg$err_tab_i) := error;
      cg$err_msg_type(cg$err_tab_i) := msg_type;
      cg$err_msgid(cg$err_tab_i) := msgid;
      cg$err_loc(cg$err_tab_i) := loc;
      cg$err_tab_i := cg$err_tab_i + 1;
   END push;

   --------------------------------------------------------------------------------
   -- Name:        pop
   -- Description: Take a message off stack
   -- Parameters:  msg     Text message
   -- Returns:     TRUE    Message popped successfully
   --              FALSE   Stack was empty

   FUNCTION pop(msg OUT VARCHAR2) RETURN BOOLEAN IS
   BEGIN
      IF (cg$err_tab_i > 1 AND cg$err_msg(cg$err_tab_i - 1) IS NOT NULL) THEN
         cg$err_tab_i := cg$err_tab_i - 1;
         msg := SUBSTR(cg$err_msg(cg$err_tab_i)
                      ,1
                      ,512);
         cg$err_msg(cg$err_tab_i) := '';
         RETURN TRUE;
      ELSE
         RETURN FALSE;
      END IF;
   END pop;

   --------------------------------------------------------------------------------
   -- Name:        pop (overload)
   -- Description: Take a message off stack with full info
   -- Parameters:  msg      Ttext message
   --              error    ERRor or WARNing
   --              msg_type ORA, API or user TLA
   --              msg_id   Id of message
   --              loc      Location where error occured
   -- Returns:     TRUE     Message popped successfully
   --              FALSE    Stack was empty

   FUNCTION pop(msg      OUT VARCHAR2
               ,error    OUT VARCHAR2
               ,msg_type OUT VARCHAR2
               ,msgid    OUT INTEGER
               ,loc      OUT VARCHAR2) RETURN BOOLEAN IS
   BEGIN
      IF (cg$err_tab_i > 1 AND cg$err_msg(cg$err_tab_i - 1) IS NOT NULL) THEN
         cg$err_tab_i := cg$err_tab_i - 1;
         msg := cg$err_msg(cg$err_tab_i);
         cg$err_msg(cg$err_tab_i) := '';
         error := cg$err_error(cg$err_tab_i);
         msg_type := cg$err_msg_type(cg$err_tab_i);
         msgid := cg$err_msgid(cg$err_tab_i);
         loc := cg$err_loc(cg$err_tab_i);
         RETURN TRUE;
      ELSE
         RETURN FALSE;
      END IF;
   END pop;

   --------------------------------------------------------------------------------
   -- Name:        pop_head
   -- Description: Take a message off stack from head
   -- Parameters:  msg     Text message
   -- Returns:     TRUE    Message popped successfully
   --              FALSE   Stack was empty
   --------------------------------------------------------------------------------
   FUNCTION pop_head(msg OUT VARCHAR2) RETURN BOOLEAN IS
   BEGIN

      IF (cg$err_tab_i > 1 AND cg$err_msg(cg$err_tab_i - 1) IS NOT NULL) THEN
         msg := cg$err_msg(1);

         FOR i IN 1 .. cg$err_tab_i - 2 LOOP
            cg$err_msg(i) := cg$err_msg(i + 1);
            cg$err_error(i) := cg$err_error(i + 1);
            cg$err_msg_type(i) := cg$err_msg_type(i + 1);
            cg$err_msgid(i) := cg$err_msgid(i + 1);
            cg$err_loc(i) := cg$err_loc(i + 1);
         END LOOP;

         cg$err_tab_i := cg$err_tab_i - 1;
         cg$err_msg(cg$err_tab_i) := '';
         RETURN TRUE;
      ELSE
         RETURN FALSE;
      END IF;

   END pop_head;


   --------------------------------------------------------------------------------
   -- Name:        pop_head (overload)
   -- Description: Take a message off stack from head with full info
   -- Parameters:  msg      Ttext message
   --              error    ERRor or WARNing
   --              msg_type ORA, API or user TLA
   --              msg_id   Id of message
   --              loc      Location where error occured
   -- Returns:     TRUE     Message popped successfully
   --              FALSE    Stack was empty
   --------------------------------------------------------------------------------
   FUNCTION pop_head(msg      OUT VARCHAR2
                    ,error    OUT VARCHAR2
                    ,msg_type OUT VARCHAR2
                    ,msgid    OUT INTEGER
                    ,loc      OUT VARCHAR2) RETURN BOOLEAN IS
   BEGIN

      IF (cg$err_tab_i > 1 AND cg$err_msg(cg$err_tab_i - 1) IS NOT NULL) THEN
         msg      := cg$err_msg(1);
         error    := cg$err_error(1);
         msg_type := cg$err_msg_type(1);
         msgid    := cg$err_msgid(1);
         loc      := cg$err_loc(1);

         FOR i IN 1 .. cg$err_tab_i - 2 LOOP
            cg$err_msg(i) := cg$err_msg(i + 1);
            cg$err_error(i) := cg$err_error(i + 1);
            cg$err_msg_type(i) := cg$err_msg_type(i + 1);
            cg$err_msgid(i) := cg$err_msgid(i + 1);
            cg$err_loc(i) := cg$err_loc(i + 1);
         END LOOP;

         cg$err_tab_i := cg$err_tab_i - 1;
         cg$err_msg(cg$err_tab_i) := '';

         RETURN TRUE;
      ELSE
         RETURN FALSE;
      END IF;

   END pop_head;

   --------------------------------------------------------------------------------
   -- Name:        clear
   -- Description: Clears the stack
   -- Parameters:  none

   PROCEDURE clear IS
   BEGIN
      cg$err_tab_i := 1;
   END clear;

   --------------------------------------------------------------------------------
   -- Az error elj?r?s le?r?sa a csomagfejben tal?lhat?

   PROCEDURE error(p_msg        VARCHAR2
                  ,p_error      VARCHAR2 DEFAULT 'E'
                  ,p_raise_flag BOOLEAN DEFAULT TRUE
                  ,p_p1         VARCHAR2 DEFAULT NULL
                  ,p_p2         VARCHAR2 DEFAULT NULL
                  ,p_p3         VARCHAR2 DEFAULT NULL
                  ,p_p4         VARCHAR2 DEFAULT NULL) IS
   BEGIN
      --
      -- Benyomjuk az (eredeti vagy leford?tott) ?zenetet a hiba-verembe
      --
      nit_error_p.push(nit_error_p.convert_to_text(p_msg
                                                  ,p_p1
                                                  ,p_p2
                                                  ,p_p3
                                                  ,p_p4)
                      ,p_error);
      --
      -- Ha sz?ks?ges, kiv?telt v?ltunk ki
      --
      IF p_raise_flag THEN
         nit_error_p.raise_failure;
      END IF;
   END error;

   FUNCTION get_hint(p_msg VARCHAR2) RETURN VARCHAR2 IS
      v_hint nit_messages.hint%TYPE;

      CURSOR c_hint(p_msg_code IN nit_messages.code%TYPE) IS
         SELECT hint
         FROM   nit_messages
         WHERE  code = p_msg_code;
   BEGIN
      IF LENGTH(p_msg) = 9 AND
         SUBSTR(p_msg
               ,4
               ,1) = '-' THEN
         OPEN c_hint(p_msg);
         FETCH c_hint
            INTO v_hint;
         CLOSE c_hint;
      END IF;

      RETURN v_hint;
   END;

--------------------------------------------------------------------------------
BEGIN
   nit_card_p.log(g_module
                 ,g_version);
END nit_error_p;
/

prompt
prompt Creating package body NIT_F_CIA_P
prompt =================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_f_cia_p IS

   TYPE cia_refresh_help_rec_t IS RECORD(
       cit_id          nit_ci_types.id%TYPE
      ,cip_id          nit_ci_properties.id%TYPE
      ,imp_source_name nit_ci_types.imp_source_name%TYPE
      ,imp_attrib      nit_ci_properties.imp_source_name%TYPE
      ,imp_where       nit_ci_types.imp_where_clause%TYPE);

   pl_cia_id nit_ci_attributes.id%TYPE;

   pl_module  CONSTANT VARCHAR2(30) := 'NIT_F_CIPT_P';
   pl_version CONSTANT VARCHAR2(12) := '0.2.0';

   FUNCTION package_version RETURN VARCHAR2 IS
   BEGIN
      RETURN pl_version;
   END;

   PROCEDURE convert_for_tapi(p_cia_rec IN rt_cia
                             ,p_cia_ind IN it_cia
                             ,p_cg$rec  OUT cg$nit_ci_attributes.cg$row_type
                             ,p_cg$ind  OUT cg$nit_ci_attributes.cg$ind_type) IS
   BEGIN
      p_cg$rec.id       := p_cia_rec.id;
      p_cg$rec.ci_id    := p_cia_rec.ci_id;
      p_cg$rec.cip_id   := p_cia_rec.cip_id;
      p_cg$rec.opn_id   := p_cia_rec.opn_id;
      p_cg$rec.cipv_id  := p_cia_rec.cipv_id;
      p_cg$rec.sms_id   := p_cia_rec.sms_id;
      p_cg$rec.status   := p_cia_rec.status;
      p_cg$rec.obsolete := p_cia_rec.obsolete;
      --      p_cg$rec.valid_from        := p_cia_rec.valid_from;
      --      p_cg$rec.valid_until       := p_cia_rec.valid_until;
      p_cg$rec.valid_from        := NULL;
      p_cg$rec.valid_until       := NULL;
      p_cg$rec.data              := p_cia_rec.data;
      p_cg$rec.comments          := p_cia_rec.comments;
      p_cg$rec.last_refresh_date := p_cia_rec.last_refresh_date;

      p_cg$ind.id                := nvl(p_cia_ind.id
                                       ,FALSE);
      p_cg$ind.ci_id             := nvl(p_cia_ind.ci_id
                                       ,FALSE);
      p_cg$ind.cip_id            := nvl(p_cia_ind.cip_id
                                       ,FALSE);
      p_cg$ind.cipv_id           := nvl(p_cia_ind.cipv_id
                                       ,FALSE);
      p_cg$ind.sms_id            := nvl(p_cia_ind.sms_id
                                       ,FALSE);
      p_cg$ind.status            := nvl(p_cia_ind.status
                                       ,FALSE);
      p_cg$ind.obsolete          := nvl(p_cia_ind.obsolete
                                       ,FALSE);
      p_cg$ind.valid_from        := nvl(p_cia_ind.valid_from
                                       ,FALSE);
      p_cg$ind.valid_until       := nvl(p_cia_ind.valid_until
                                       ,FALSE);
      p_cg$ind.data              := nvl(p_cia_ind.data
                                       ,FALSE);
      p_cg$ind.comments          := nvl(p_cia_ind.comments
                                       ,FALSE);
      p_cg$ind.last_refresh_date := nvl(p_cia_ind.last_refresh_date
                                       ,FALSE);
   END;

   PROCEDURE convert_for_mapi(p_cg$rec  IN cg$nit_ci_attributes.cg$row_type
                             ,p_cia_rec OUT rt_cia) IS
   BEGIN
      p_cia_rec.id                := p_cg$rec.id;
      p_cia_rec.ci_id             := p_cg$rec.ci_id;
      p_cia_rec.cip_id            := p_cg$rec.cip_id;
      p_cia_rec.cipv_id           := p_cg$rec.cipv_id;
      p_cia_rec.sms_id            := p_cg$rec.sms_id;
      p_cia_rec.status            := p_cg$rec.status;
      p_cia_rec.obsolete          := p_cg$rec.obsolete;
      p_cia_rec.valid_from        := p_cg$rec.valid_from;
      p_cia_rec.valid_until       := p_cg$rec.valid_until;
      p_cia_rec.data              := p_cg$rec.data;
      p_cia_rec.comments          := p_cg$rec.comments;
      p_cia_rec.last_refresh_date := p_cg$rec.last_refresh_date;
   END;

   PROCEDURE cia_ins(p_rec IN OUT rt_cia
                    ,p_ind IN it_cia) IS
      l_rec cg$nit_ci_attributes.cg$row_type;
      l_ind cg$nit_ci_attributes.cg$ind_type;
   BEGIN
      convert_for_tapi(p_cia_rec => p_rec
                      ,p_cia_ind => p_ind
                      ,p_cg$rec  => l_rec
                      ,p_cg$ind  => l_ind);

      -- insert attribute
      cg$nit_ci_attributes.called_from_package := FALSE;
      cg$nit_ci_attributes.ins(l_rec
                              ,l_ind);

      convert_for_mapi(p_cg$rec  => l_rec
                      ,p_cia_rec => p_rec);
   END;

   PROCEDURE cia_upd(p_rec IN OUT rt_cia
                    ,p_ind IN it_cia) IS
      l_rec cg$nit_ci_attributes.cg$row_type;
      l_ind cg$nit_ci_attributes.cg$ind_type;
   BEGIN
      convert_for_tapi(p_cia_rec => p_rec
                      ,p_cia_ind => p_ind
                      ,p_cg$rec  => l_rec
                      ,p_cg$ind  => l_ind);

      -- update attribute
      cg$nit_ci_attributes.called_from_package := FALSE;
      cg$nit_ci_attributes.upd(l_rec
                              ,l_ind);

      convert_for_mapi(p_cg$rec  => l_rec
                      ,p_cia_rec => p_rec);
   END;

   PROCEDURE cia_lck(p_rec IN OUT rt_cia
                    ,p_ind IN it_cia) IS
      l_rec cg$nit_ci_attributes.cg$row_type;
      l_ind cg$nit_ci_attributes.cg$ind_type;
   BEGIN
      convert_for_tapi(p_cia_rec => p_rec
                      ,p_cia_ind => p_ind
                      ,p_cg$rec  => l_rec
                      ,p_cg$ind  => l_ind);

      cg$nit_ci_attributes.called_from_package := FALSE;
      cg$nit_ci_attributes.lck(l_rec
                              ,l_ind);

      convert_for_mapi(p_cg$rec  => l_rec
                      ,p_cia_rec => p_rec);
   END;

   PROCEDURE cia_del(p_rec IN OUT rt_cia) IS
      l_rec cg$nit_ci_attributes.cg$row_type;
      l_ind cg$nit_ci_attributes.cg$ind_type;
   BEGIN
      l_rec.id := p_rec.id;
      -- a felhaszn?l? a t?rl?st megel?z?en m?dos?thatta, ?gy slct marad ...
      cg$nit_ci_attributes.slct(l_rec);
      l_rec.obsolete := 'D';
      l_rec.opn_id   := p_rec.opn_id;

      l_ind.obsolete := TRUE;

      -- delete attribute
      cg$nit_ci_attributes.called_from_package := FALSE;
      cg$nit_ci_attributes.upd(l_rec
                              ,l_ind);

      convert_for_mapi(p_cg$rec  => l_rec
                      ,p_cia_rec => p_rec);
   END;

   PROCEDURE init_cia_id(p_id IN nit_ci_attributes.id%TYPE) IS
   BEGIN
      pl_cia_id := p_id;
   END;

   FUNCTION get_cia_revisions RETURN nit_ci_attributes_ct IS
      l_coll     nit_ci_attributes_ct;
      l_rec      cg$nit_ci_attributes.cg$row_type;
      help_rec   cia_refresh_help_rec_t;
      slct_stmnt VARCHAR2(2000);
      i          PLS_INTEGER;
      tmp        PLS_INTEGER;
   BEGIN
      l_rec.id := pl_cia_id;
      cg$nit_ci_attributes.slct(l_rec);

      SELECT cit.id               cit_id
            ,cip.id               cip_id
            ,cit.imp_source_name  imp_source_name
            ,cip.imp_source_name  imp_attrib
            ,cit.imp_where_clause imp_where
      INTO   help_rec
      FROM   nit_ci_types      cit
            ,nit_ci_properties cip
      WHERE  cit.is_importable = 'Y' AND
             cit.imp_source_module = 'SMS' AND
             cip.is_importable = 'Y' AND
             cip.imp_source_module = 'SMS' AND
             cip.cit_id = cit.id AND
             cip.id = l_rec.cip_id;

      slct_stmnt := 'SELECT nit_ci_attributes_ot(
                               null
                              ,null
                              ,null
                              ,null
                              ,null
                              ,cia.ci_id
                              ,cia.cip_id
                              ,null
                              ,null
                              ,sms.sms_id
                              ,''done''
                              ,''L''
                              ,sms.TIMESTAMP
                              ,NVL(nit_core_p.push_back(LEAD(sms.TIMESTAMP) OVER (ORDER BY sms.revision_id)),nit_core_p.get_infinite_date)
                              ,lower(to_char(sms.' ||
                    help_rec.imp_attrib || '))
                              ,null
                              ,null)
                     FROM ' || help_rec.imp_source_name ||
                    ' sms
                         ,nit_ci_attributes cia
                         ,nit_ci_properties cip
                         ,nit_ci_property_types cipt
                     WHERE cia.id = ' || pl_cia_id ||
                    ' AND
                           cia.cip_id = cip.id AND
                           cip.cipt_id = cipt.id AND
                           nit_importer_p.get_resource_id(cia.sms_id) = sms.resource_id AND
                           nit_importer_p.get_group_id(cia.sms_id) = sms.group_id AND
                           nit_importer_p.get_revision_id(cia.sms_id) < sms.revision_id AND
                           sms.' || help_rec.imp_attrib ||
                    ' IS NOT NULL
                     ORDER  BY sms.revision_id';

      EXECUTE IMMEDIATE slct_stmnt BULK COLLECT
         INTO l_coll;


      IF (l_coll IS NOT NULL) THEN
         l_rec.data := NULL;
         i          := l_coll.FIRST;
         LOOP
            EXIT WHEN i IS NULL;
            IF (l_rec.data IS NOT NULL AND l_rec.data = l_coll(i).data) THEN
               tmp := i;
               i   := l_coll.NEXT(i);
               l_coll.DELETE(tmp);
            ELSE
               l_rec.data := l_coll(i).data;
               i          := l_coll.NEXT(i);
            END IF;
         END LOOP;

         l_rec.valid_until := nit_core_p.get_infinite_date;
         i                 := l_coll.LAST;
         LOOP
            EXIT WHEN i IS NULL;
            l_coll(i).valid_until := l_rec.valid_until;
            l_rec.valid_until := nit_core_p.push_back(l_coll(i).valid_from);
            i := l_coll.PRIOR(i);
         END LOOP;
      END IF;

      RETURN l_coll;
   END;

BEGIN
   nit_card_p.log(pl_module
                 ,pl_version);
END nit_f_cia_p;
/

prompt
prompt Creating package body NIT_F_CI_P
prompt ================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_f_ci_p IS

   pl_module  CONSTANT VARCHAR2(30) := 'NIT_F_CI_P';
   pl_version CONSTANT VARCHAR2(12) := '1.0.0';

   ci_archive_cit_id        nit_ci_types.id%TYPE;
   ci_archive_ci_id         nit_config_items.id%TYPE;
   ci_archive_show_children VARCHAR2(1) := 'N';

   FUNCTION package_version RETURN VARCHAR2 IS
   BEGIN
      RETURN pl_version;
   END;

   PROCEDURE convert_for_tapi(p_ci_rec IN rt_ci
                             ,p_ci_ind IN it_ci
                             ,p_cg$rec OUT cg$nit_config_items.cg$row_type
                             ,p_cg$ind OUT cg$nit_config_items.cg$ind_type) IS
   BEGIN
      p_cg$rec.id       := p_ci_rec.id;
      p_cg$rec.cit_id   := p_ci_rec.cit_id;
      p_cg$rec.opn_id   := p_ci_rec.opn_id;
      p_cg$rec.sms_id   := p_ci_rec.sms_id;
      p_cg$rec.NAME     := p_ci_rec.NAME;
      p_cg$rec.status   := p_ci_rec.status;
      p_cg$rec.obsolete := p_ci_rec.obsolete;
      --      p_cg$rec.valid_from        := p_ci_rec.valid_from;
      --      p_cg$rec.valid_until       := p_ci_rec.valid_until;
      p_cg$rec.valid_from        := NULL;
      p_cg$rec.valid_until       := NULL;
      p_cg$rec.comments          := p_ci_rec.comments;
      p_cg$rec.last_refresh_date := p_ci_rec.last_refresh_date;

      p_cg$ind.id                := NVL(p_ci_ind.id
                                       ,FALSE);
      p_cg$ind.cit_id            := NVL(p_ci_ind.cit_id
                                       ,FALSE);
      p_cg$ind.opn_id            := NVL(p_ci_ind.opn_id
                                       ,FALSE);
      p_cg$ind.sms_id            := NVL(p_ci_ind.sms_id
                                       ,FALSE);
      p_cg$ind.NAME              := NVL(p_ci_ind.NAME
                                       ,FALSE);
      p_cg$ind.status            := NVL(p_ci_ind.status
                                       ,FALSE);
      p_cg$ind.obsolete          := NVL(p_ci_ind.obsolete
                                       ,FALSE);
      p_cg$ind.valid_from        := NVL(p_ci_ind.valid_from
                                       ,FALSE);
      p_cg$ind.valid_until       := NVL(p_ci_ind.valid_until
                                       ,FALSE);
      p_cg$ind.comments          := NVL(p_ci_ind.comments
                                       ,FALSE);
      p_cg$ind.last_refresh_date := NVL(p_ci_ind.last_refresh_date
                                       ,FALSE);
   END;

   PROCEDURE convert_for_mapi(p_cg$rec IN cg$nit_config_items.cg$row_type
                             ,p_ci_rec OUT rt_ci) IS
   BEGIN
      p_ci_rec.id                := p_cg$rec.id;
      p_ci_rec.cit_id            := p_cg$rec.cit_id;
      p_ci_rec.opn_id            := p_cg$rec.opn_id;
      p_ci_rec.sms_id            := p_cg$rec.sms_id;
      p_ci_rec.NAME              := p_cg$rec.NAME;
      p_ci_rec.status            := p_cg$rec.status;
      p_ci_rec.obsolete          := p_cg$rec.obsolete;
      p_ci_rec.valid_from        := p_cg$rec.valid_from;
      p_ci_rec.valid_until       := p_cg$rec.valid_until;
      p_ci_rec.comments          := p_cg$rec.comments;
      p_ci_rec.last_refresh_date := p_cg$rec.last_refresh_date;
   END;

   PROCEDURE ci_ins(p_rec IN OUT rt_ci
                   ,p_ind IN it_ci) IS
      l_rec     cg$nit_config_items.cg$row_type;
      l_ind     cg$nit_config_items.cg$ind_type;
      l_pos_rec cg$nit_positions.cg$row_type;
      l_pos_ind cg$nit_positions.cg$ind_type;

   BEGIN
      convert_for_tapi(p_ci_rec => p_rec
                      ,p_ci_ind => p_ind
                      ,p_cg$rec => l_rec
                      ,p_cg$ind => l_ind);

      -- insert CI
      cg$nit_config_items.called_from_package := FALSE;
      cg$nit_config_items.ins(l_rec
                             ,l_ind);

      -- insert position
      l_pos_rec.ci_id  := l_rec.id;
      l_pos_rec.lcn_id := p_rec.lcn_id;
      l_pos_rec.opn_id := l_rec.opn_id;
      -- ideglenesen mindig done
      -- l_pos_rec.status      := p_rec.pos_status;
      l_pos_rec.status   := 'done';
      l_pos_rec.obsolete := l_rec.obsolete;
      --      ideiglenesen
      --      l_pos_rec.valid_from  := p_rec.pos_valid_from;
      --      l_pos_rec.valid_until := p_rec.pos_valid_until;
      l_pos_rec.valid_from  := NULL;
      l_pos_rec.valid_until := NULL;

      --      l_pos_rec.comments := p_rec.comments;
      l_pos_ind.id          := TRUE;
      l_pos_ind.ci_id       := TRUE;
      l_pos_ind.lcn_id      := TRUE;
      l_pos_ind.opn_id      := TRUE;
      l_pos_ind.status      := TRUE;
      l_pos_ind.obsolete    := TRUE;
      l_pos_ind.valid_from  := TRUE;
      l_pos_ind.valid_until := TRUE;

      --      l_pos_ind.comments := p_ind.comments;
      cg$nit_positions.called_from_package := FALSE;
      cg$nit_positions.ins(l_pos_rec
                          ,l_pos_ind);

      convert_for_mapi(p_cg$rec => l_rec
                      ,p_ci_rec => p_rec);

      p_rec.pos_id := l_pos_rec.id;
      p_rec.lcn_id := l_pos_rec.lcn_id;
      SELECT NAME
      INTO   p_rec.location
      FROM   nit_f_lcn_main_v
      WHERE  id = l_pos_rec.lcn_id;
      p_rec.pos_status      := l_pos_rec.status;
      p_rec.pos_obsolete    := l_pos_rec.obsolete;
      p_rec.pos_valid_from  := l_pos_rec.valid_from;
      p_rec.pos_valid_until := l_pos_rec.valid_until;
   END;

   PROCEDURE ci_upd(p_rec IN OUT rt_ci
                   ,p_ind IN it_ci) IS
      l_rec     cg$nit_config_items.cg$row_type;
      l_ind     cg$nit_config_items.cg$ind_type;
      l_pos_rec cg$nit_positions.cg$row_type;
      l_pos_ind cg$nit_positions.cg$ind_type;
   BEGIN
      convert_for_tapi(p_ci_rec => p_rec
                      ,p_ci_ind => p_ind
                      ,p_cg$rec => l_rec
                      ,p_cg$ind => l_ind);

      -- update position
      IF (p_ind.lcn_id OR p_ind.pos_status OR p_ind.pos_obsolete OR
         p_ind.pos_valid_from OR p_ind.pos_valid_until) THEN
         l_pos_rec.id          := p_rec.pos_id;
         l_pos_rec.ci_id       := l_rec.id;
         l_pos_rec.lcn_id      := p_rec.lcn_id;
         l_pos_rec.opn_id      := p_rec.opn_id;
         l_pos_rec.status      := p_rec.pos_status;
         l_pos_rec.obsolete    := l_rec.obsolete;
         l_pos_rec.valid_from  := p_rec.valid_from;
         l_pos_rec.valid_until := p_rec.valid_until;
         --      l_pos_rec.comments := p_rec.comments

         l_pos_ind.id          := TRUE;
         l_pos_ind.ci_id       := FALSE;
         l_pos_ind.lcn_id      := NVL(p_ind.lcn_id
                                     ,FALSE);
         l_pos_ind.status      := NVL(p_ind.pos_status
                                     ,FALSE);
         l_pos_ind.obsolete    := NVL(p_ind.pos_obsolete
                                     ,FALSE);
         l_pos_ind.valid_from  := NVL(p_ind.pos_valid_from
                                     ,FALSE);
         l_pos_ind.valid_until := NVL(p_ind.pos_valid_until
                                     ,FALSE);
         --      l_pos_ind.comments := p_rec.comments
         cg$nit_positions.called_from_package := FALSE;
         cg$nit_positions.upd(l_pos_rec
                             ,l_pos_ind);

         l_pos_rec.opn_id := p_rec.opn_id;
         nit_positions_p.cascade_upd(l_pos_rec
                                    ,l_pos_ind);
      END IF;

      -- update CI
      IF (l_ind.id OR l_ind.cit_id OR l_ind.opn_id OR l_ind.NAME OR
         l_ind.status OR l_ind.obsolete OR l_ind.valid_from OR
         l_ind.valid_until OR l_ind.comments) THEN
         cg$nit_config_items.called_from_package := FALSE;
         cg$nit_config_items.upd(l_rec
                                ,l_ind);
         IF (l_ind.status) THEN
            nit_config_items_p.cascade_upd(l_rec
                                          ,l_ind);
         END IF;
      ELSE
         -- nincs update
         cg$nit_config_items.slct(l_rec);
      END IF;

      convert_for_mapi(p_cg$rec => l_rec
                      ,p_ci_rec => p_rec);

      IF (p_ind.lcn_id OR p_ind.pos_status OR p_ind.pos_obsolete OR
         p_ind.pos_valid_from OR p_ind.pos_valid_until) THEN
         p_rec.pos_id := l_pos_rec.id;
         p_rec.lcn_id := l_pos_rec.lcn_id;
         SELECT NAME
         INTO   p_rec.location
         FROM   nit_f_lcn_main_v
         WHERE  id = l_pos_rec.lcn_id;
         p_rec.pos_status      := l_pos_rec.status;
         p_rec.pos_obsolete    := l_pos_rec.obsolete;
         p_rec.pos_valid_from  := l_pos_rec.valid_from;
         p_rec.pos_valid_until := l_pos_rec.valid_until;
      END IF;
   END;

   PROCEDURE ci_lck(p_rec IN OUT rt_ci
                   ,p_ind IN it_ci) IS
      l_rec     cg$nit_config_items.cg$row_type;
      l_ind     cg$nit_config_items.cg$ind_type;
      l_pos_rec cg$nit_positions.cg$row_type;
      l_pos_ind cg$nit_positions.cg$ind_type;
   BEGIN
      convert_for_tapi(p_ci_rec => p_rec
                      ,p_ci_ind => p_ind
                      ,p_cg$rec => l_rec
                      ,p_cg$ind => l_ind);

      l_pos_rec.id := p_rec.pos_id;
      cg$nit_positions.slct(l_pos_rec);

      l_pos_ind.id          := TRUE;
      l_pos_ind.ci_id       := TRUE;
      l_pos_ind.lcn_id      := TRUE;
      l_pos_ind.opn_id      := TRUE;
      l_pos_ind.status      := TRUE;
      l_pos_ind.obsolete    := TRUE;
      l_pos_ind.valid_from  := TRUE;
      l_pos_ind.valid_until := TRUE;
      l_pos_ind.comments    := TRUE;

      cg$nit_config_items.called_from_package := FALSE;
      cg$nit_config_items.lck(l_rec
                             ,l_ind);

      cg$nit_positions.called_from_package := FALSE;
      cg$nit_positions.lck(l_pos_rec
                          ,l_pos_ind);


      convert_for_mapi(p_cg$rec => l_rec
                      ,p_ci_rec => p_rec);

      p_rec.pos_id := l_pos_rec.id;
      p_rec.lcn_id := l_pos_rec.lcn_id;
      -- location name-re esetleg Select into
      p_rec.pos_status      := l_pos_rec.status;
      p_rec.pos_obsolete    := l_pos_rec.obsolete;
      p_rec.pos_valid_from  := l_pos_rec.valid_from;
      p_rec.pos_valid_until := l_pos_rec.valid_until;
   END;

   -- T?rl?s csak a status megv?ltoztat?s?n kereszt?l lehets?ges => end-of-life
   /*
      PROCEDURE ci_del(p_rec IN OUT rt_ci) IS
         l_rec cg$nit_config_items.cg$row_type;
         l_ind cg$nit_config_items.cg$ind_type;
      BEGIN
         l_rec.id := p_rec.id;
         -- a felhaszn?l? a t?rl?st megel?z?en m?dos?thatta, ?gy slct marad ...
         cg$nit_config_items.slct(l_rec);
         l_rec.obsolete := 'D';
         l_rec.opn_id   := p_rec.opn_id;

         l_ind.obsolete := TRUE;

         -- delete CI
         cg$nit_config_items.called_from_package := FALSE;
         cg$nit_config_items.upd(l_rec
                                ,l_ind);

         p_rec.id          := l_rec.id;
         p_rec.cit_id      := l_rec.cit_id;
         p_rec.opn_id      := l_rec.opn_id;
         p_rec.NAME        := l_rec.NAME;
         p_rec.status      := l_rec.status;
         p_rec.obsolete    := l_rec.obsolete;
         p_rec.valid_from  := l_rec.valid_from;
         p_rec.valid_until := l_rec.valid_until;
         p_rec.comments    := l_rec.comments;
      END;
   */

   /* p_cit_id - CIT-hez tartoz? arch?v CI rekordok list?z?sa
   p_ci_id  - konkr?t id-hoz tartoz? arch?v CI rekordok list?z?sa
   p_show_children - p_ci_id = NULL eset?n, a kapott CIT-hez ?s annak
                     lesz?rmazottaihoz tartoz? arch?v CI rekordok list?z?sa */
   PROCEDURE init_ci_archive_ids(p_cit_id        IN nit_ci_types.id%TYPE
                                ,p_ci_id         IN nit_config_items.id%TYPE
                                ,p_show_children IN VARCHAR2) IS
   BEGIN
      ci_archive_cit_id        := p_cit_id;
      ci_archive_ci_id         := p_ci_id;
      ci_archive_show_children := p_show_children;
   END;

   FUNCTION get_ci_archive_ci_id RETURN NUMBER IS
   BEGIN
      RETURN ci_archive_ci_id;
   END;

   FUNCTION get_default_name(p_rec IN rt_ci) RETURN VARCHAR2 IS
      v_rec cg$nit_config_items.cg$row_type;
   BEGIN
      v_rec.cit_id := p_rec.cit_id;
      v_rec.NAME   := p_rec.NAME;
      -- t?bb mez?re nincs sz?ks?g jelenleg

      RETURN nit_config_items_p.get_default_name(v_rec);
   END;

   PROCEDURE ci_refresh(p_id IN nit_config_items.id%TYPE) IS
   BEGIN
      nit_importer_p.ci_refresh(p_id);
   END;

   PROCEDURE cia_refresh(p_id IN nit_ci_attributes.id%TYPE) IS
   BEGIN
      nit_importer_p.cia_refresh(p_id);
   END;

BEGIN
   nit_card_p.log(pl_module
                 ,pl_version);
END;
/

prompt
prompt Creating package body NIT_F_CIPT_P
prompt ==================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_f_cipt_p IS

   pl_module  CONSTANT VARCHAR2(30) := 'NIT_F_CIPT_P';
   pl_version CONSTANT VARCHAR2(12) := '0.2.0';

   FUNCTION package_version RETURN VARCHAR2 IS
   BEGIN
      RETURN pl_version;
   END;

   PROCEDURE convert_for_tapi(p_cipt_rec IN rt_cipt
                             ,p_cipt_ind IN it_cipt
                             ,p_cg$rec   OUT cg$nit_ci_property_types.cg$row_type
                             ,p_cg$ind   OUT cg$nit_ci_property_types.cg$ind_type) IS
   BEGIN
      p_cg$rec.id          := p_cipt_rec.id;
      p_cg$rec.NAME        := p_cipt_rec.NAME;
      p_cg$rec.type_name   := p_cipt_rec.type_name;
      p_cg$rec.description := p_cipt_rec.description;
      p_cg$rec.comments    := p_cipt_rec.comments;

      p_cg$ind.id          := NVL(p_cipt_ind.id
                                 ,FALSE);
      p_cg$ind.NAME        := NVL(p_cipt_ind.NAME
                                 ,FALSE);
      p_cg$ind.type_name   := NVL(p_cipt_ind.type_name
                                 ,FALSE);
      p_cg$ind.description := NVL(p_cipt_ind.description
                                 ,FALSE);
      p_cg$ind.comments    := NVL(p_cipt_ind.comments
                                 ,FALSE);
   END;

   PROCEDURE convert_for_mapi(p_cg$rec   IN cg$nit_ci_property_types.cg$row_type
                             ,p_cipt_rec OUT rt_cipt) IS
   BEGIN
      p_cipt_rec.id          := p_cg$rec.id;
      p_cipt_rec.NAME        := p_cg$rec.NAME;
      p_cipt_rec.type_name   := p_cg$rec.type_name;
      p_cipt_rec.description := p_cg$rec.description;
      p_cipt_rec.comments    := p_cg$rec.comments;
   END;

   PROCEDURE cipt_ins(p_rec IN OUT rt_cipt
                     ,p_ind IN it_cipt) IS
      v_rec cg$nit_ci_property_types.cg$row_type;
      v_ind cg$nit_ci_property_types.cg$ind_type;
   BEGIN
      convert_for_tapi(p_cipt_rec => p_rec
                      ,p_cipt_ind => p_ind
                      ,p_cg$rec   => v_rec
                      ,p_cg$ind   => v_ind);

      cg$nit_ci_property_types.called_from_package := FALSE;
      cg$nit_ci_property_types.ins(v_rec
                                  ,v_ind);

      convert_for_mapi(p_cg$rec   => v_rec
                      ,p_cipt_rec => p_rec);
   END;

   PROCEDURE cipt_upd(p_rec IN OUT rt_cipt
                     ,p_ind IN it_cipt) IS
      v_rec cg$nit_ci_property_types.cg$row_type;
      v_ind cg$nit_ci_property_types.cg$ind_type;
   BEGIN
      convert_for_tapi(p_cipt_rec => p_rec
                      ,p_cipt_ind => p_ind
                      ,p_cg$rec   => v_rec
                      ,p_cg$ind   => v_ind);

      cg$nit_ci_property_types.called_from_package := FALSE;
      cg$nit_ci_property_types.upd(v_rec
                                  ,v_ind);
      convert_for_mapi(p_cg$rec   => v_rec
                      ,p_cipt_rec => p_rec);
   END;

   PROCEDURE cipt_lck(p_rec IN OUT rt_cipt
                     ,p_ind IN it_cipt) IS
      v_rec cg$nit_ci_property_types.cg$row_type;
      v_ind cg$nit_ci_property_types.cg$ind_type;
   BEGIN
      convert_for_tapi(p_cipt_rec => p_rec
                      ,p_cipt_ind => p_ind
                      ,p_cg$rec   => v_rec
                      ,p_cg$ind   => v_ind);

      cg$nit_ci_property_types.called_from_package := FALSE;
      cg$nit_ci_property_types.lck(v_rec
                                  ,v_ind);

      convert_for_mapi(p_cg$rec   => v_rec
                      ,p_cipt_rec => p_rec);
   END;

   PROCEDURE cipt_del(p_rec IN OUT rt_cipt) IS
      v_pk_rec cg$nit_ci_property_types.cg$pk_type;
   BEGIN
      v_pk_rec.id                                  := p_rec.id;
      cg$nit_ci_property_types.called_from_package := FALSE;
      cg$nit_ci_property_types.del(v_pk_rec);
   END;

BEGIN
   nit_card_p.log(pl_module
                 ,pl_version);
END;
/

prompt
prompt Creating package body NIT_F_CIR_P
prompt =================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_f_cir_p IS

   pl_module  CONSTANT VARCHAR2(30) := 'NIT_F_CIR_P';
   pl_version CONSTANT VARCHAR2(12) := '1.0.0';

   FUNCTION package_version RETURN VARCHAR2 IS
   BEGIN
      RETURN pl_version;
   END;

   PROCEDURE convert_for_tapi(p_cir_rec IN rt_cir
                             ,p_cir_ind IN it_cir
                             ,p_cg$rec  OUT cg$nit_ci_relations.cg$row_type
                             ,p_cg$ind  OUT cg$nit_ci_relations.cg$ind_type) IS
   BEGIN
      p_cg$rec.id          := p_cir_rec.id;
      p_cg$rec.ci_id_from  := p_cir_rec.ci_id_from;
      p_cg$rec.ci_id_to    := p_cir_rec.ci_id_to;
      p_cg$rec.citr_id     := p_cir_rec.citr_id;
      p_cg$rec.opn_id      := p_cir_rec.opn_id;
      p_cg$rec.status      := p_cir_rec.status;
      p_cg$rec.obsolete    := p_cir_rec.obsolete;
      p_cg$rec.valid_from  := p_cir_rec.valid_from;
      p_cg$rec.valid_until := p_cir_rec.valid_until;
      p_cg$rec.comments    := p_cir_rec.comments;

      p_cg$ind.id          := NVL(p_cir_ind.id
                                 ,FALSE);
      p_cg$ind.ci_id_from  := NVL(p_cir_ind.ci_id_from
                                 ,FALSE);
      p_cg$ind.ci_id_to    := NVL(p_cir_ind.ci_id_to
                                 ,FALSE);
      p_cg$ind.citr_id     := NVL(p_cir_ind.citr_id
                                 ,FALSE);
      p_cg$ind.opn_id      := NVL(p_cir_ind.opn_id
                                 ,FALSE);
      p_cg$ind.status      := NVL(p_cir_ind.status
                                 ,FALSE);
      p_cg$ind.obsolete    := NVL(p_cir_ind.obsolete
                                 ,FALSE);
      p_cg$ind.valid_from  := NVL(p_cir_ind.valid_from
                                 ,FALSE);
      p_cg$ind.valid_until := NVL(p_cir_ind.valid_until
                                 ,FALSE);
      p_cg$ind.comments    := NVL(p_cir_ind.comments
                                 ,FALSE);
   END;

   PROCEDURE convert_for_mapi(p_cg$rec  IN cg$nit_ci_relations.cg$row_type
                             ,p_cir_rec OUT rt_cir) IS
   BEGIN
      p_cir_rec.id          := p_cg$rec.id;
      p_cir_rec.ci_id_from  := p_cg$rec.ci_id_from;
      p_cir_rec.ci_id_to    := p_cg$rec.ci_id_to;
      p_cir_rec.citr_id     := p_cg$rec.citr_id;
      p_cir_rec.opn_id      := p_cg$rec.opn_id;
      p_cir_rec.status      := p_cg$rec.status;
      p_cir_rec.obsolete    := p_cg$rec.obsolete;
      p_cir_rec.valid_from  := p_cg$rec.valid_from;
      p_cir_rec.valid_until := p_cg$rec.valid_until;
      p_cir_rec.comments    := p_cg$rec.comments;
   END;

   PROCEDURE cir_ins(p_rec IN OUT rt_cir
                    ,p_ind IN it_cir) IS
      l_rec cg$nit_ci_relations.cg$row_type;
      l_ind cg$nit_ci_relations.cg$ind_type;
   BEGIN
      convert_for_tapi(p_cir_rec => p_rec
                      ,p_cir_ind => p_ind
                      ,p_cg$rec  => l_rec
                      ,p_cg$ind  => l_ind);

      -- insert relation
      cg$nit_ci_relations.called_from_package := FALSE;
      cg$nit_ci_relations.ins(l_rec
                             ,l_ind);

      convert_for_mapi(p_cg$rec  => l_rec
                      ,p_cir_rec => p_rec);
   END;

   PROCEDURE cir_upd(p_rec IN OUT rt_cir
                    ,p_ind IN it_cir) IS
      l_rec cg$nit_ci_relations.cg$row_type;
      l_ind cg$nit_ci_relations.cg$ind_type;
   BEGIN
      convert_for_tapi(p_cir_rec => p_rec
                      ,p_cir_ind => p_ind
                      ,p_cg$rec  => l_rec
                      ,p_cg$ind  => l_ind);

      -- update relation
      cg$nit_ci_relations.called_from_package := FALSE;
      cg$nit_ci_relations.upd(l_rec
                             ,l_ind);

      convert_for_mapi(p_cg$rec  => l_rec
                      ,p_cir_rec => p_rec);
   END;

   PROCEDURE cir_lck(p_rec IN OUT rt_cir
                    ,p_ind IN it_cir) IS
      l_rec cg$nit_ci_relations.cg$row_type;
      l_ind cg$nit_ci_relations.cg$ind_type;
   BEGIN
      convert_for_tapi(p_cir_rec => p_rec
                      ,p_cir_ind => p_ind
                      ,p_cg$rec  => l_rec
                      ,p_cg$ind  => l_ind);

      cg$nit_ci_relations.called_from_package := FALSE;
      cg$nit_ci_relations.lck(l_rec
                             ,l_ind);

      convert_for_mapi(p_cg$rec  => l_rec
                      ,p_cir_rec => p_rec);
   END;

   PROCEDURE cir_del(p_rec IN OUT rt_cir) IS
      l_rec cg$nit_ci_relations.cg$row_type;
      l_ind cg$nit_ci_relations.cg$ind_type;
   BEGIN
      l_rec.id := p_rec.id;
      -- a felhaszn?l? a t?rl?st megel?z?en m?dos?thatta, ?gy slct marad ...
      cg$nit_ci_relations.slct(l_rec);
      l_rec.obsolete := 'D';
      l_rec.opn_id   := p_rec.opn_id;

      l_ind.obsolete := TRUE;

      -- delete relation
      cg$nit_ci_relations.called_from_package := FALSE;
      cg$nit_ci_relations.upd(l_rec
                             ,l_ind);

      convert_for_mapi(p_cg$rec  => l_rec
                      ,p_cir_rec => p_rec);
   END;

BEGIN
   nit_card_p.log(pl_module
                 ,pl_version);
END nit_f_cir_p;
/

prompt
prompt Creating package body NIT_F_CIT_CIP_P
prompt =====================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_f_cit_cip_p IS

   pl_module  CONSTANT VARCHAR2(30) := 'NIT_F_CIT_CIP_P';
   pl_version CONSTANT VARCHAR2(12) := '1.0.0';

   FUNCTION package_version RETURN VARCHAR2 IS
   BEGIN
      RETURN pl_version;
   END;

   PROCEDURE convert_for_tapi(p_cit_cip_rec IN rt_cit_cip
                             ,p_cit_cip_ind IN it_cit_cip
                             ,p_cg$rec      OUT cg$nit_ci_properties.cg$row_type
                             ,p_cg$ind      OUT cg$nit_ci_properties.cg$ind_type) IS
   BEGIN
      p_cg$rec.id              := p_cit_cip_rec.id;
      p_cg$rec.cit_id          := p_cit_cip_rec.cit_id;
      p_cg$rec.cipt_id         := p_cit_cip_rec.cipt_id;
      p_cg$rec.cip_id          := p_cit_cip_rec.cip_id;
      p_cg$rec.order_in_list   := p_cit_cip_rec.cip_order;
      p_cg$rec.is_inherited    := p_cit_cip_rec.is_inherited;
      p_cg$rec.is_importable   := p_cit_cip_rec.is_importable;
      p_cg$rec.imp_auto_import := p_cit_cip_rec.auto_import;
      p_cg$rec.required        := p_cit_cip_rec.required;
      p_cg$rec.set_like        := p_cit_cip_rec.set_like;
      p_cg$rec.description     := p_cit_cip_rec.description;
      p_cg$rec.comments        := p_cit_cip_rec.comments;

      p_cg$ind.id              := NVL(p_cit_cip_ind.id
                                     ,FALSE);
      p_cg$ind.cit_id          := NVL(p_cit_cip_ind.cit_id
                                     ,FALSE);
      p_cg$ind.cipt_id         := NVL(p_cit_cip_ind.cipt_id
                                     ,FALSE);
      p_cg$ind.cip_id          := NVL(p_cit_cip_ind.cip_id
                                     ,FALSE);
      p_cg$ind.order_in_list   := NVL(p_cit_cip_ind.cip_order
                                     ,FALSE);
      p_cg$ind.is_inherited    := NVL(p_cit_cip_ind.is_inherited
                                     ,FALSE);
      p_cg$ind.is_importable   := NVL(p_cit_cip_ind.is_importable
                                     ,FALSE);
      p_cg$ind.imp_auto_import := NVL(p_cit_cip_ind.auto_import
                                     ,FALSE);
      p_cg$ind.required        := NVL(p_cit_cip_ind.required
                                     ,FALSE);
      p_cg$ind.set_like        := NVL(p_cit_cip_ind.set_like
                                     ,FALSE);
      p_cg$ind.description     := NVL(p_cit_cip_ind.description
                                     ,FALSE);
      p_cg$ind.comments        := NVL(p_cit_cip_ind.comments
                                     ,FALSE);
   END;

   PROCEDURE convert_for_mapi(p_cg$rec      IN cg$nit_ci_properties.cg$row_type
                             ,p_cit_cip_rec OUT rt_cit_cip) IS
   BEGIN
      p_cit_cip_rec.id            := p_cg$rec.id;
      p_cit_cip_rec.cit_id        := p_cg$rec.cit_id;
      p_cit_cip_rec.cipt_id       := p_cg$rec.cipt_id;
      p_cit_cip_rec.cip_id        := p_cg$rec.cip_id;
      p_cit_cip_rec.cip_order     := p_cg$rec.order_in_list;
      p_cit_cip_rec.is_inherited  := p_cg$rec.is_inherited;
      p_cit_cip_rec.is_importable := p_cg$rec.is_importable;
      p_cit_cip_rec.auto_import   := p_cg$rec.imp_auto_import;
      p_cit_cip_rec.required      := p_cg$rec.required;
      p_cit_cip_rec.set_like      := p_cg$rec.set_like;
      p_cit_cip_rec.description   := p_cg$rec.description;
      p_cit_cip_rec.comments      := p_cg$rec.comments;
   END;

   PROCEDURE cit_cip_ins(p_rec IN OUT rt_cit_cip
                        ,p_ind IN it_cit_cip) IS
      v_rec cg$nit_ci_properties.cg$row_type;
      v_ind cg$nit_ci_properties.cg$ind_type;
   BEGIN
      convert_for_tapi(p_cit_cip_rec => p_rec
                      ,p_cit_cip_ind => p_ind
                      ,p_cg$rec      => v_rec
                      ,p_cg$ind      => v_ind);

      cg$nit_ci_properties.called_from_package := FALSE;
      cg$nit_ci_properties.ins(v_rec
                              ,v_ind);
      nit_ci_properties_p.cascade_ins(v_rec
                                     ,v_ind);

      convert_for_mapi(p_cg$rec      => v_rec
                      ,p_cit_cip_rec => p_rec);
   END;

   PROCEDURE cit_cip_upd(p_rec     IN OUT rt_cit_cip
                        ,p_ind     IN it_cit_cip
                        ,p_cascade IN BOOLEAN) IS
      v_rec cg$nit_ci_properties.cg$row_type;
      v_ind cg$nit_ci_properties.cg$ind_type;
   BEGIN
      convert_for_tapi(p_cit_cip_rec => p_rec
                      ,p_cit_cip_ind => p_ind
                      ,p_cg$rec      => v_rec
                      ,p_cg$ind      => v_ind);

      cg$nit_ci_properties.called_from_package := FALSE;
      cg$nit_ci_properties.upd(v_rec
                              ,v_ind);
      IF (p_cascade) THEN
         nit_ci_properties_p.cascade_upd(v_rec
                                        ,v_ind);
      END IF;

      convert_for_mapi(p_cg$rec      => v_rec
                      ,p_cit_cip_rec => p_rec);
   END;

   PROCEDURE cit_cip_lck(p_rec IN OUT rt_cit_cip
                        ,p_ind IN it_cit_cip) IS
      v_rec cg$nit_ci_properties.cg$row_type;
      v_ind cg$nit_ci_properties.cg$ind_type;
   BEGIN
      convert_for_tapi(p_cit_cip_rec => p_rec
                      ,p_cit_cip_ind => p_ind
                      ,p_cg$rec      => v_rec
                      ,p_cg$ind      => v_ind);

      cg$nit_ci_properties.called_from_package := FALSE;
      cg$nit_ci_properties.lck(v_rec
                              ,v_ind);

      convert_for_mapi(p_cg$rec      => v_rec
                      ,p_cit_cip_rec => p_rec);
   END;

   PROCEDURE cit_cip_del(p_rec     IN OUT rt_cit_cip
                        ,p_cascade IN BOOLEAN) IS
      v_pk_rec cg$nit_ci_properties.cg$pk_type;
   BEGIN
      v_pk_rec.id                              := p_rec.id;
      cg$nit_ci_properties.called_from_package := FALSE;
      --      IF (p_cascade) THEN
      --         nit_ci_properties_p.cascade_del(p_rec.id);
      --      END IF;
      cg$nit_ci_properties.del(v_pk_rec);
   END;

BEGIN
   nit_card_p.log(pl_module
                 ,pl_version);
END;
/

prompt
prompt Creating package body NIT_F_CIT_CIPV_P
prompt ======================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_f_cit_cipv_p IS

   pl_module  CONSTANT VARCHAR2(30) := 'NIT_F_CIT_CIPV_P';
   pl_version CONSTANT VARCHAR2(12) := '1.0.0';

   FUNCTION package_version RETURN VARCHAR2 IS
   BEGIN
      RETURN pl_version;
   END;

   PROCEDURE convert_for_tapi(p_cit_cipv_rec IN rt_cit_cipv
                             ,p_cit_cipv_ind IN it_cit_cipv
                             ,p_cg$rec       OUT cg$nit_ci_property_values.cg$row_type
                             ,p_cg$ind       OUT cg$nit_ci_property_values.cg$ind_type) IS
   BEGIN
      p_cg$rec.id            := p_cit_cipv_rec.id;
      p_cg$rec.cip_id        := p_cit_cipv_rec.cip_id;
      p_cg$rec.is_default    := p_cit_cipv_rec.is_default;
      p_cg$rec.order_in_list := p_cit_cipv_rec.cipv_order;
      p_cg$rec.VALUE         := p_cit_cipv_rec.VALUE;
      p_cg$rec.description   := p_cit_cipv_rec.description;
      p_cg$rec.comments      := p_cit_cipv_rec.comments;

      p_cg$ind.id            := NVL(p_cit_cipv_ind.id
                                   ,FALSE);
      p_cg$ind.cip_id        := NVL(p_cit_cipv_ind.cip_id
                                   ,FALSE);
      p_cg$ind.is_default    := NVL(p_cit_cipv_ind.is_default
                                   ,FALSE);
      p_cg$ind.order_in_list := NVL(p_cit_cipv_ind.cipv_order
                                   ,FALSE);
      p_cg$ind.VALUE         := NVL(p_cit_cipv_ind.VALUE
                                   ,FALSE);
      p_cg$ind.description   := NVL(p_cit_cipv_ind.description
                                   ,FALSE);
      p_cg$ind.comments      := NVL(p_cit_cipv_ind.comments
                                   ,FALSE);
   END;

   PROCEDURE convert_for_mapi(p_cg$rec       IN cg$nit_ci_property_values.cg$row_type
                             ,p_cit_cipv_rec OUT rt_cit_cipv) IS
   BEGIN
      p_cit_cipv_rec.id          := p_cg$rec.id;
      p_cit_cipv_rec.cip_id      := p_cg$rec.cip_id;
      p_cit_cipv_rec.is_default  := p_cg$rec.is_default;
      p_cit_cipv_rec.cipv_order  := p_cg$rec.order_in_list;
      p_cit_cipv_rec.VALUE       := p_cg$rec.VALUE;
      p_cit_cipv_rec.description := p_cg$rec.description;
      p_cit_cipv_rec.comments    := p_cg$rec.comments;
   END;

   PROCEDURE cit_cipv_ins(p_rec IN OUT rt_cit_cipv
                         ,p_ind IN it_cit_cipv) IS
      v_rec cg$nit_ci_property_values.cg$row_type;
      v_ind cg$nit_ci_property_values.cg$ind_type;
   BEGIN
      convert_for_tapi(p_cit_cipv_rec => p_rec
                      ,p_cit_cipv_ind => p_ind
                      ,p_cg$rec       => v_rec
                      ,p_cg$ind       => v_ind);

      cg$nit_ci_property_values.called_from_package := FALSE;
      cg$nit_ci_property_values.ins(v_rec
                                   ,v_ind);
      nit_ci_property_values_p.cascade_ins(v_rec
                                          ,v_ind);

      convert_for_mapi(p_cg$rec       => v_rec
                      ,p_cit_cipv_rec => p_rec);
   END;

   PROCEDURE cit_cipv_upd(p_rec     IN OUT rt_cit_cipv
                         ,p_ind     IN it_cit_cipv
                         ,p_cascade IN BOOLEAN) IS
      v_rec          cg$nit_ci_property_values.cg$row_type;
      v_ind          cg$nit_ci_property_values.cg$ind_type;
      v_old_value    nit_ci_property_values.VALUE%TYPE;
      pl_subprg_name VARCHAR2(30) := 'cit_cipv_upd';
   BEGIN
      convert_for_tapi(p_cit_cipv_rec => p_rec
                      ,p_cit_cipv_ind => p_ind
                      ,p_cg$rec       => v_rec
                      ,p_cg$ind       => v_ind);

      SELECT VALUE
      INTO   v_old_value
      FROM   nit_f_cit_cipv_v cipv
      WHERE  cipv.id = v_rec.id;

      cg$nit_ci_property_values.called_from_package := FALSE;
      cg$nit_ci_property_values.upd(v_rec
                                   ,v_ind);
      IF (p_cascade) THEN
         nit_ci_property_values_p.cascade_upd(v_rec
                                             ,v_ind
                                             ,v_old_value);
      END IF;

      convert_for_mapi(p_cg$rec       => v_rec
                      ,p_cit_cipv_rec => p_rec);

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);

   END;

   PROCEDURE cit_cipv_lck(p_rec IN OUT rt_cit_cipv
                         ,p_ind IN it_cit_cipv) IS
      v_rec cg$nit_ci_property_values.cg$row_type;
      v_ind cg$nit_ci_property_values.cg$ind_type;
   BEGIN
      convert_for_tapi(p_cit_cipv_rec => p_rec
                      ,p_cit_cipv_ind => p_ind
                      ,p_cg$rec       => v_rec
                      ,p_cg$ind       => v_ind);

      cg$nit_ci_property_values.called_from_package := FALSE;
      cg$nit_ci_property_values.lck(v_rec
                                   ,v_ind);

      convert_for_mapi(p_cg$rec       => v_rec
                      ,p_cit_cipv_rec => p_rec);

   END;

   PROCEDURE cit_cipv_del(p_rec     IN OUT rt_cit_cipv
                         ,p_cascade IN BOOLEAN) IS
      v_pk_rec cg$nit_ci_property_values.cg$pk_type;
   BEGIN
      v_pk_rec.id                                   := p_rec.id;
      cg$nit_ci_property_values.called_from_package := FALSE;

      IF (p_cascade) THEN
         nit_ci_property_values_p.cascade_del(p_rec.id);
      END IF;
      cg$nit_ci_property_values.del(v_pk_rec);
   END;
BEGIN
   nit_card_p.log(pl_module
                 ,pl_version);
END;
/

prompt
prompt Creating package body NIT_F_CIT_CITR_P
prompt ======================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_f_cit_citr_p IS

   pl_module  CONSTANT VARCHAR2(30) := 'NIT_F_CIT_CITR_P';
   pl_version CONSTANT VARCHAR2(12) := '1.0.0';

   FUNCTION package_version RETURN VARCHAR2 IS
   BEGIN
      RETURN pl_version;
   END;

   PROCEDURE convert_for_tapi(p_cit_citr_rec IN rt_cit_citr
                             ,p_cit_citr_ind IN it_cit_citr
                             ,p_cg$rec       OUT cg$nit_ci_type_relations.cg$row_type
                             ,p_cg$ind       OUT cg$nit_ci_type_relations.cg$ind_type) IS
   BEGIN
      p_cg$rec.id            := p_cit_citr_rec.id;
      p_cg$rec.cit_id_from   := p_cit_citr_rec.cit_id_from;
      p_cg$rec.cit_id_to     := p_cit_citr_rec.cit_id_to;
      p_cg$rec.citrt_id      := p_cit_citr_rec.citrt_id;
      p_cg$rec.order_in_list := p_cit_citr_rec.citr_order;
      p_cg$rec.description   := p_cit_citr_rec.description;
      p_cg$rec.comments      := p_cit_citr_rec.comments;

      p_cg$ind.id            := NVL(p_cit_citr_ind.id
                                   ,FALSE);
      p_cg$ind.cit_id_from   := NVL(p_cit_citr_ind.cit_id_from
                                   ,FALSE);
      p_cg$ind.cit_id_to     := NVL(p_cit_citr_ind.cit_id_to
                                   ,FALSE);
      p_cg$ind.citrt_id      := NVL(p_cit_citr_ind.citrt_id
                                   ,FALSE);
      p_cg$ind.order_in_list := NVL(p_cit_citr_ind.citr_order
                                   ,FALSE);
      p_cg$ind.description   := NVL(p_cit_citr_ind.description
                                   ,FALSE);
      p_cg$ind.comments      := NVL(p_cit_citr_ind.comments
                                   ,FALSE);
   END;

   PROCEDURE convert_for_mapi(p_cg$rec       IN cg$nit_ci_type_relations.cg$row_type
                             ,p_cit_citr_rec OUT rt_cit_citr) IS
   BEGIN
      p_cit_citr_rec.id          := p_cg$rec.id;
      p_cit_citr_rec.cit_id_from := p_cg$rec.cit_id_from;
      p_cit_citr_rec.cit_id_to   := p_cg$rec.cit_id_to;
      p_cit_citr_rec.citrt_id    := p_cg$rec.citrt_id;
      p_cit_citr_rec.citr_order  := p_cg$rec.order_in_list;
      p_cit_citr_rec.description := p_cg$rec.description;
      p_cit_citr_rec.comments    := p_cg$rec.comments;
   END;

   PROCEDURE cit_citr_ins(p_rec IN OUT rt_cit_citr
                         ,p_ind IN it_cit_citr) IS
      v_rec cg$nit_ci_type_relations.cg$row_type;
      v_ind cg$nit_ci_type_relations.cg$ind_type;
   BEGIN
      convert_for_tapi(p_cit_citr_rec => p_rec
                      ,p_cit_citr_ind => p_ind
                      ,p_cg$rec       => v_rec
                      ,p_cg$ind       => v_ind);

      cg$nit_ci_type_relations.called_from_package := FALSE;
      cg$nit_ci_type_relations.ins(v_rec
                                  ,v_ind);

      convert_for_mapi(p_cg$rec       => v_rec
                      ,p_cit_citr_rec => p_rec);
   END;

   PROCEDURE cit_citr_upd(p_rec IN OUT rt_cit_citr
                         ,p_ind IN it_cit_citr) IS
      v_rec cg$nit_ci_type_relations.cg$row_type;
      v_ind cg$nit_ci_type_relations.cg$ind_type;
   BEGIN
      convert_for_tapi(p_cit_citr_rec => p_rec
                      ,p_cit_citr_ind => p_ind
                      ,p_cg$rec       => v_rec
                      ,p_cg$ind       => v_ind);

      cg$nit_ci_type_relations.called_from_package := FALSE;
      cg$nit_ci_type_relations.upd(v_rec
                                  ,v_ind);

      convert_for_mapi(p_cg$rec       => v_rec
                      ,p_cit_citr_rec => p_rec);
   END;

   PROCEDURE cit_citr_lck(p_rec IN OUT rt_cit_citr
                         ,p_ind IN it_cit_citr) IS
      v_rec cg$nit_ci_type_relations.cg$row_type;
      v_ind cg$nit_ci_type_relations.cg$ind_type;
   BEGIN
      convert_for_tapi(p_cit_citr_rec => p_rec
                      ,p_cit_citr_ind => p_ind
                      ,p_cg$rec       => v_rec
                      ,p_cg$ind       => v_ind);

      cg$nit_ci_type_relations.called_from_package := FALSE;
      cg$nit_ci_type_relations.lck(v_rec
                                  ,v_ind);

      convert_for_mapi(p_cg$rec       => v_rec
                      ,p_cit_citr_rec => p_rec);
   END;

   PROCEDURE cit_citr_del(p_rec IN OUT rt_cit_citr) IS
      v_pk_rec cg$nit_ci_type_relations.cg$pk_type;
   BEGIN
      v_pk_rec.id                                  := p_rec.id;
      cg$nit_ci_type_relations.called_from_package := FALSE;
      cg$nit_ci_type_relations.del(v_pk_rec);
   END;

BEGIN
   nit_card_p.log(pl_module
                 ,pl_version);
END;
/

prompt
prompt Creating package body NIT_F_CIT_P
prompt =================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_f_cit_p IS

   pl_module  CONSTANT VARCHAR2(30) := 'NIT_F_CIT_P';
   pl_version CONSTANT VARCHAR2(12) := '1.0.0';

   FUNCTION package_version RETURN VARCHAR2 IS
   BEGIN
      RETURN pl_version;
   END;

   PROCEDURE convert_for_tapi(p_cit_rec IN rt_cit
                             ,p_cg$rec  OUT cg$nit_ci_types.cg$row_type) IS
   BEGIN
      p_cg$rec.id                 := p_cit_rec.id;
      p_cg$rec.cit_id             := p_cit_rec.cit_id;
      p_cg$rec.NAME               := p_cit_rec.NAME;
      p_cg$rec.abbreviation       := p_cit_rec.abbreviation;
      p_cg$rec.naming_pattern     := p_cit_rec.naming_pattern;
      p_cg$rec.need_po            := p_cit_rec.need_po;
      p_cg$rec.could_in_stock     := p_cit_rec.could_in_stock;
      p_cg$rec.could_in_inventory := p_cit_rec.could_in_inventory;
      p_cg$rec.order_in_list      := p_cit_rec.order_in_list;
      p_cg$rec.description        := p_cit_rec.description;
      p_cg$rec.comments           := p_cit_rec.comments;
      p_cg$rec.is_importable      := p_cit_rec.is_importable;
      p_cg$rec.imp_auto_import    := p_cit_rec.auto_import;
   END;

   PROCEDURE convert_for_tapi(p_cit_rec IN rt_cit
                             ,p_cit_ind IN it_cit
                             ,p_cg$rec  OUT cg$nit_ci_types.cg$row_type
                             ,p_cg$ind  OUT cg$nit_ci_types.cg$ind_type) IS
   BEGIN
      convert_for_tapi(p_cit_rec => p_cit_rec
                      ,p_cg$rec  => p_cg$rec);

      p_cg$ind.id                 := NVL(p_cit_ind.id
                                        ,FALSE);
      p_cg$ind.cit_id             := NVL(p_cit_ind.cit_id
                                        ,FALSE);
      p_cg$ind.NAME               := NVL(p_cit_ind.NAME
                                        ,FALSE);
      p_cg$ind.abbreviation       := NVL(p_cit_ind.abbreviation
                                        ,FALSE);
      p_cg$ind.naming_pattern     := NVL(p_cit_ind.naming_pattern
                                        ,FALSE);
      p_cg$ind.need_po            := NVL(p_cit_ind.need_po
                                        ,FALSE);
      p_cg$ind.could_in_stock     := NVL(p_cit_ind.could_in_stock
                                        ,FALSE);
      p_cg$ind.could_in_inventory := NVL(p_cit_ind.could_in_inventory
                                        ,FALSE);
      p_cg$ind.order_in_list      := NVL(p_cit_ind.order_in_list
                                        ,FALSE);
      p_cg$ind.description        := NVL(p_cit_ind.description
                                        ,FALSE);
      p_cg$ind.comments           := NVL(p_cit_ind.comments
                                        ,FALSE);
      p_cg$ind.is_importable      := NVL(p_cit_ind.is_importable
                                        ,FALSE);
      p_cg$ind.imp_auto_import    := NVL(p_cit_ind.auto_import
                                        ,FALSE);
   END;

   PROCEDURE convert_for_mapi(p_cg$rec  IN cg$nit_ci_types.cg$row_type
                             ,p_cit_rec OUT rt_cit) IS
   BEGIN
      p_cit_rec.id                 := p_cg$rec.id;
      p_cit_rec.cit_id             := p_cg$rec.cit_id;
      p_cit_rec.NAME               := p_cg$rec.NAME;
      p_cit_rec.abbreviation       := p_cg$rec.abbreviation;
      p_cit_rec.naming_pattern     := p_cg$rec.naming_pattern;
      p_cit_rec.need_po            := p_cg$rec.need_po;
      p_cit_rec.could_in_stock     := p_cg$rec.could_in_stock;
      p_cit_rec.could_in_inventory := p_cg$rec.could_in_inventory;
      p_cit_rec.order_in_list      := p_cg$rec.order_in_list;
      p_cit_rec.description        := p_cg$rec.description;
      p_cit_rec.comments           := p_cg$rec.comments;
      p_cit_rec.is_importable      := p_cg$rec.is_importable;
      p_cit_rec.auto_import        := p_cg$rec.imp_auto_import;
   END;

   PROCEDURE cit_ins(p_rec IN OUT rt_cit
                    ,p_ind IN it_cit) IS
      v_rec cg$nit_ci_types.cg$row_type;
      v_ind cg$nit_ci_types.cg$ind_type;
   BEGIN
      convert_for_tapi(p_cit_rec => p_rec
                      ,p_cit_ind => p_ind
                      ,p_cg$rec  => v_rec
                      ,p_cg$ind  => v_ind);

      cg$nit_ci_types.called_from_package := FALSE;
      cg$nit_ci_types.ins(v_rec
                         ,v_ind);

      convert_for_mapi(p_cg$rec  => v_rec
                      ,p_cit_rec => p_rec);
   END;

   PROCEDURE cit_upd(p_rec     IN OUT rt_cit
                    ,p_ind     IN it_cit
                    ,p_cascade IN BOOLEAN) IS
      v_rec cg$nit_ci_types.cg$row_type;
      v_ind cg$nit_ci_types.cg$ind_type;
   BEGIN
      convert_for_tapi(p_cit_rec => p_rec
                      ,p_cit_ind => p_ind
                      ,p_cg$rec  => v_rec
                      ,p_cg$ind  => v_ind);

      cg$nit_ci_types.called_from_package := FALSE;
      cg$nit_ci_types.upd(v_rec
                         ,v_ind);

      IF (p_cascade) THEN
         nit_ci_types_p.cascade_upd(v_rec);
      END IF;

      convert_for_mapi(p_cg$rec  => v_rec
                      ,p_cit_rec => p_rec);
   END;

   PROCEDURE cit_lck(p_rec IN OUT rt_cit
                    ,p_ind IN it_cit) IS
      v_rec cg$nit_ci_types.cg$row_type;
      v_ind cg$nit_ci_types.cg$ind_type;
   BEGIN
      convert_for_tapi(p_cit_rec => p_rec
                      ,p_cit_ind => p_ind
                      ,p_cg$rec  => v_rec
                      ,p_cg$ind  => v_ind);

      cg$nit_ci_types.called_from_package := FALSE;
      cg$nit_ci_types.lck(v_rec
                         ,v_ind);

      convert_for_mapi(p_cg$rec  => v_rec
                      ,p_cit_rec => p_rec);
   END;

   PROCEDURE cit_del(p_rec IN OUT rt_cit) IS
      v_pk_rec cg$nit_ci_types.cg$pk_type;
   BEGIN
      v_pk_rec.id                         := p_rec.id;
      cg$nit_ci_types.called_from_package := FALSE;

      nit_ci_types_p.cascade_del(p_rec.id);
      cg$nit_ci_types.del(v_pk_rec);
   END;

   PROCEDURE set_default_name(p_rec IN OUT rt_cit) IS
      v_rec cg$nit_ci_types.cg$row_type;
   BEGIN
      v_rec.id             := p_rec.id;
      v_rec.cit_id         := p_rec.cit_id;
      v_rec.NAME           := p_rec.NAME;
      v_rec.abbreviation   := p_rec.abbreviation;
      v_rec.naming_pattern := p_rec.naming_pattern;
      v_rec.need_po        := p_rec.need_po;
      v_rec.could_in_stock := p_rec.could_in_stock;
      v_rec.order_in_list  := p_rec.order_in_list;
      v_rec.description    := p_rec.description;
      v_rec.comments       := p_rec.comments;
      p_rec.NAME           := nit_ci_types_p.get_default_name(v_rec);
   END;

   PROCEDURE set_default_naming_pattern(p_rec IN OUT rt_cit) IS
      v_rec cg$nit_ci_types.cg$row_type;
   BEGIN
      convert_for_tapi(p_cit_rec => p_rec
                      ,p_cg$rec  => v_rec);
      p_rec.naming_pattern := nit_ci_types_p.get_default_naming_pattern(v_rec);
   END;

   PROCEDURE set_could_in_stock_default(p_rec IN OUT rt_cit) IS
      v_rec cg$nit_ci_types.cg$row_type;
   BEGIN
      convert_for_tapi(p_cit_rec => p_rec
                      ,p_cg$rec  => v_rec);
      p_rec.could_in_stock := nit_ci_types_p.get_could_in_stock_default(v_rec);
   END;

   PROCEDURE set_need_po_default(p_rec IN OUT rt_cit) IS
      v_rec cg$nit_ci_types.cg$row_type;
   BEGIN
      convert_for_tapi(p_cit_rec => p_rec
                      ,p_cg$rec  => v_rec);
      p_rec.need_po := nit_ci_types_p.get_need_po_default(v_rec);
   END;

BEGIN
   nit_card_p.log(pl_module
                 ,pl_version);
END;
/

prompt
prompt Creating package body NIT_F_CITRT_P
prompt ===================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_f_citrt_p IS

   pl_module  CONSTANT VARCHAR2(30) := 'NIT_F_CITRT_P';
   pl_version CONSTANT VARCHAR2(12) := '1.0.2';

   FUNCTION package_version RETURN VARCHAR2 IS
   BEGIN
      RETURN pl_version;
   END;

   PROCEDURE convert_for_tapi(p_citrt_rec IN rt_citrt
                             ,p_citrt_ind IN it_citrt
                             ,p_cg$rec    OUT cg$nit_cit_relation_types.cg$row_type
                             ,p_cg$ind    OUT cg$nit_cit_relation_types.cg$ind_type) IS
   BEGIN
      p_cg$rec.id          := p_citrt_rec.id;
      p_cg$rec.NAME        := p_citrt_rec.NAME;
      p_cg$rec.description := p_citrt_rec.description;
      p_cg$rec.comments    := p_citrt_rec.comments;

      p_cg$ind.id          := NVL(p_citrt_ind.id
                                 ,FALSE);
      p_cg$ind.NAME        := NVL(p_citrt_ind.NAME
                                 ,FALSE);
      p_cg$ind.description := NVL(p_citrt_ind.description
                                 ,FALSE);
      p_cg$ind.comments    := NVL(p_citrt_ind.comments
                                 ,FALSE);
   END;

   PROCEDURE convert_for_mapi(p_cg$rec    IN cg$nit_cit_relation_types.cg$row_type
                             ,p_citrt_rec OUT rt_citrt) IS
   BEGIN
      p_citrt_rec.id          := p_cg$rec.id;
      p_citrt_rec.NAME        := p_cg$rec.NAME;
      p_citrt_rec.description := p_cg$rec.description;
      p_citrt_rec.comments    := p_cg$rec.comments;
   END;

   PROCEDURE citrt_ins(p_rec IN OUT rt_citrt
                      ,p_ind IN it_citrt) IS
      v_rec cg$nit_cit_relation_types.cg$row_type;
      v_ind cg$nit_cit_relation_types.cg$ind_type;
   BEGIN
      convert_for_tapi(p_citrt_rec => p_rec
                      ,p_citrt_ind => p_ind
                      ,p_cg$rec    => v_rec
                      ,p_cg$ind    => v_ind);

      cg$nit_cit_relation_types.called_from_package := FALSE;
      cg$nit_cit_relation_types.ins(v_rec
                                   ,v_ind);

      convert_for_mapi(p_cg$rec    => v_rec
                      ,p_citrt_rec => p_rec);
   END;

   PROCEDURE citrt_upd(p_rec IN OUT rt_citrt
                      ,p_ind IN it_citrt) IS
      v_rec cg$nit_cit_relation_types.cg$row_type;
      v_ind cg$nit_cit_relation_types.cg$ind_type;
   BEGIN
      convert_for_tapi(p_citrt_rec => p_rec
                      ,p_citrt_ind => p_ind
                      ,p_cg$rec    => v_rec
                      ,p_cg$ind    => v_ind);

      cg$nit_cit_relation_types.called_from_package := FALSE;
      cg$nit_cit_relation_types.upd(v_rec
                                   ,v_ind);

      convert_for_mapi(p_cg$rec    => v_rec
                      ,p_citrt_rec => p_rec);
   END;
   PROCEDURE citrt_lck(p_rec IN OUT rt_citrt
                      ,p_ind IN it_citrt) IS
      v_rec cg$nit_cit_relation_types.cg$row_type;
      v_ind cg$nit_cit_relation_types.cg$ind_type;
   BEGIN
      convert_for_tapi(p_citrt_rec => p_rec
                      ,p_citrt_ind => p_ind
                      ,p_cg$rec    => v_rec
                      ,p_cg$ind    => v_ind);

      cg$nit_cit_relation_types.called_from_package := FALSE;
      cg$nit_cit_relation_types.lck(v_rec
                                   ,v_ind);

      convert_for_mapi(p_cg$rec    => v_rec
                      ,p_citrt_rec => p_rec);
   END;

   PROCEDURE citrt_del(p_rec     IN OUT rt_citrt
                      ,p_cascade IN BOOLEAN) IS
      l_pk_rec cg$nit_cit_relation_types.cg$pk_type;
   BEGIN
      IF (p_cascade) THEN
         nit_cit_relation_types_p.cascade_del(p_rec.id);
      END IF;
      l_pk_rec.id                                   := p_rec.id;
      cg$nit_cit_relation_types.called_from_package := FALSE;
      cg$nit_cit_relation_types.del(l_pk_rec);
   END;

BEGIN
   nit_card_p.log(pl_module
                 ,pl_version);
END;
/

prompt
prompt Creating package body NIT_F_LCN_P
prompt =================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_f_lcn_p IS

   pl_module  CONSTANT VARCHAR2(30) := 'NIT_F_LCN_P';
   pl_version CONSTANT VARCHAR2(12) := '1.0.0';

   FUNCTION package_version RETURN VARCHAR2 IS
   BEGIN
      RETURN pl_version;
   END;

   PROCEDURE convert_for_tapi(p_lcn_rec IN rt_lcn
                             ,p_cg$rec  OUT cg$nit_locations.cg$row_type) IS
   BEGIN
      p_cg$rec.id             := p_lcn_rec.id;
      p_cg$rec.lcn_id         := p_lcn_rec.lcn_id;
      p_cg$rec.NAME           := p_lcn_rec.NAME;
      p_cg$rec.abbreviation   := p_lcn_rec.abbreviation;
      p_cg$rec.naming_pattern := p_lcn_rec.naming_pattern;
      p_cg$rec.description    := p_lcn_rec.description;
      p_cg$rec.comments       := p_lcn_rec.comments;
   END;

   PROCEDURE convert_for_tapi(p_lcn_rec IN rt_lcn
                             ,p_lcn_ind IN it_lcn
                             ,p_cg$rec  OUT cg$nit_locations.cg$row_type
                             ,p_cg$ind  OUT cg$nit_locations.cg$ind_type) IS
   BEGIN
      convert_for_tapi(p_lcn_rec => p_lcn_rec
                      ,p_cg$rec  => p_cg$rec);

      p_cg$ind.id             := NVL(p_lcn_ind.id
                                    ,FALSE);
      p_cg$ind.lcn_id         := NVL(p_lcn_ind.lcn_id
                                    ,FALSE);
      p_cg$ind.NAME           := NVL(p_lcn_ind.NAME
                                    ,FALSE);
      p_cg$ind.abbreviation   := NVL(p_lcn_ind.abbreviation
                                    ,FALSE);
      p_cg$ind.naming_pattern := NVL(p_lcn_ind.naming_pattern
                                    ,FALSE);
      p_cg$ind.description    := NVL(p_lcn_ind.description
                                    ,FALSE);
      p_cg$ind.comments       := NVL(p_lcn_ind.comments
                                    ,FALSE);
   END;

   PROCEDURE convert_for_mapi(p_cg$rec  IN cg$nit_locations.cg$row_type
                             ,p_lcn_rec OUT rt_lcn) IS
   BEGIN
      p_lcn_rec.id             := p_cg$rec.id;
      p_lcn_rec.lcn_id         := p_cg$rec.lcn_id;
      p_lcn_rec.NAME           := p_cg$rec.NAME;
      p_lcn_rec.abbreviation   := p_cg$rec.abbreviation;
      p_lcn_rec.naming_pattern := p_cg$rec.naming_pattern;
      p_lcn_rec.description    := p_cg$rec.description;
      p_lcn_rec.comments       := p_cg$rec.comments;
   END;

   PROCEDURE lcn_ins(p_rec IN OUT rt_lcn
                    ,p_ind IN it_lcn) IS
      v_rec cg$nit_locations.cg$row_type;
      v_ind cg$nit_locations.cg$ind_type;
   BEGIN
      convert_for_tapi(p_lcn_rec => p_rec
                      ,p_lcn_ind => p_ind
                      ,p_cg$rec  => v_rec
                      ,p_cg$ind  => v_ind);

      cg$nit_locations.called_from_package := FALSE;
      cg$nit_locations.ins(v_rec
                          ,v_ind);

      convert_for_mapi(p_cg$rec  => v_rec
                      ,p_lcn_rec => p_rec);
   END;

   PROCEDURE lcn_upd(p_rec IN OUT rt_lcn
                    ,p_ind IN it_lcn) IS
      v_rec cg$nit_locations.cg$row_type;
      v_ind cg$nit_locations.cg$ind_type;
   BEGIN
      convert_for_tapi(p_lcn_rec => p_rec
                      ,p_lcn_ind => p_ind
                      ,p_cg$rec  => v_rec
                      ,p_cg$ind  => v_ind);

      cg$nit_locations.called_from_package := FALSE;
      cg$nit_locations.upd(v_rec
                          ,v_ind);

      convert_for_mapi(p_cg$rec  => v_rec
                      ,p_lcn_rec => p_rec);
   END;

   PROCEDURE lcn_lck(p_rec IN OUT rt_lcn
                    ,p_ind IN it_lcn) IS
      v_rec cg$nit_locations.cg$row_type;
      v_ind cg$nit_locations.cg$ind_type;
   BEGIN
      convert_for_tapi(p_lcn_rec => p_rec
                      ,p_lcn_ind => p_ind
                      ,p_cg$rec  => v_rec
                      ,p_cg$ind  => v_ind);
      cg$nit_locations.called_from_package := FALSE;
      cg$nit_locations.lck(v_rec
                          ,v_ind);

      convert_for_mapi(p_cg$rec  => v_rec
                      ,p_lcn_rec => p_rec);
   END;

   PROCEDURE lcn_del(p_rec IN OUT rt_lcn) IS
      v_pk_rec cg$nit_locations.cg$pk_type;
   BEGIN
      v_pk_rec.id                          := p_rec.id;
      cg$nit_locations.called_from_package := FALSE;
      cg$nit_locations.del(v_pk_rec);
   END;

   PROCEDURE set_default_name(p_rec IN OUT rt_lcn) IS
      v_rec cg$nit_locations.cg$row_type;
   BEGIN
      convert_for_tapi(p_lcn_rec => p_rec
                      ,p_cg$rec  => v_rec);

      p_rec.NAME := nit_locations_p.get_default_name(v_rec);
   END;

   PROCEDURE set_default_naming_pattern(p_rec IN OUT rt_lcn) IS
      v_rec cg$nit_locations.cg$row_type;
   BEGIN
      convert_for_tapi(p_lcn_rec => p_rec
                      ,p_cg$rec  => v_rec);

      p_rec.naming_pattern := nit_locations_p.get_default_naming_pattern(v_rec);
   END;
BEGIN
   nit_card_p.log(pl_module
                 ,pl_version);
END;
/

prompt
prompt Creating package body NIT_F_MSG_P
prompt =================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_f_msg_p IS

   pl_module  CONSTANT VARCHAR2(30) := 'NIT_F_MSG_P';
   pl_version CONSTANT VARCHAR2(12) := '1.0.0';

   FUNCTION package_version RETURN VARCHAR2 IS
   BEGIN
      RETURN pl_version;
   END;

   PROCEDURE convert_for_tapi(p_msg_rec IN rt_msg
                             ,p_msg_ind IN it_msg
                             ,p_cg$rec  OUT cg$nit_messages.cg$row_type
                             ,p_cg$ind  OUT cg$nit_messages.cg$ind_type) IS
   BEGIN
      p_cg$rec.id       := p_msg_rec.id;
      p_cg$rec.code     := p_msg_rec.code;
      p_cg$rec.message  := p_msg_rec.message;
      p_cg$rec.used_in  := p_msg_rec.used_in;
      p_cg$rec.hint     := p_msg_rec.hint;
      p_cg$rec.comments := p_msg_rec.comments;

      p_cg$ind.id       := NVL(p_msg_ind.id
                              ,FALSE);
      p_cg$ind.code     := NVL(p_msg_ind.code
                              ,FALSE);
      p_cg$ind.message  := NVL(p_msg_ind.message
                              ,FALSE);
      p_cg$ind.used_in  := NVL(p_msg_ind.used_in
                              ,FALSE);
      p_cg$ind.hint     := NVL(p_msg_ind.hint
                              ,FALSE);
      p_cg$ind.comments := NVL(p_msg_ind.comments
                              ,FALSE);
   END;

   PROCEDURE convert_for_mapi(p_cg$rec  IN cg$nit_messages.cg$row_type
                             ,p_msg_rec OUT rt_msg) IS
   BEGIN
      p_msg_rec.id       := p_cg$rec.id;
      p_msg_rec.code     := p_cg$rec.code;
      p_msg_rec.message  := p_cg$rec.message;
      p_msg_rec.hint     := p_cg$rec.hint;
      p_msg_rec.used_in  := p_cg$rec.used_in;
      p_msg_rec.comments := p_cg$rec.comments;
   END;

   PROCEDURE msg_ins(p_rec IN OUT rt_msg
                    ,p_ind IN it_msg) IS
      l_rec cg$nit_messages.cg$row_type;
      l_ind cg$nit_messages.cg$ind_type;
   BEGIN
      convert_for_tapi(p_msg_rec => p_rec
                      ,p_msg_ind => p_ind
                      ,p_cg$rec  => l_rec
                      ,p_cg$ind  => l_ind);

      cg$nit_messages.called_from_package := FALSE;
      cg$nit_messages.ins(l_rec
                         ,l_ind);

      convert_for_mapi(p_cg$rec  => l_rec
                      ,p_msg_rec => p_rec);
   END;

   PROCEDURE msg_upd(p_rec IN OUT rt_msg
                    ,p_ind IN it_msg) IS
      l_rec cg$nit_messages.cg$row_type;
      l_ind cg$nit_messages.cg$ind_type;
   BEGIN
      convert_for_tapi(p_msg_rec => p_rec
                      ,p_msg_ind => p_ind
                      ,p_cg$rec  => l_rec
                      ,p_cg$ind  => l_ind);

      cg$nit_messages.called_from_package := FALSE;
      cg$nit_messages.upd(l_rec
                         ,l_ind);

      convert_for_mapi(p_cg$rec  => l_rec
                      ,p_msg_rec => p_rec);
   END;

   PROCEDURE msg_lck(p_rec IN OUT rt_msg
                    ,p_ind IN it_msg) IS
      l_rec cg$nit_messages.cg$row_type;
      l_ind cg$nit_messages.cg$ind_type;
   BEGIN
      convert_for_tapi(p_msg_rec => p_rec
                      ,p_msg_ind => p_ind
                      ,p_cg$rec  => l_rec
                      ,p_cg$ind  => l_ind);

      cg$nit_messages.called_from_package := FALSE;
      cg$nit_messages.lck(l_rec
                         ,l_ind);

      convert_for_mapi(p_cg$rec  => l_rec
                      ,p_msg_rec => p_rec);
   END;
   PROCEDURE msg_del(p_rec IN OUT rt_msg) IS
      l_pk_rec cg$nit_messages.cg$pk_type;
   BEGIN
      l_pk_rec.id                         := p_rec.id;
      cg$nit_messages.called_from_package := FALSE;
      cg$nit_messages.del(l_pk_rec);
   END;
BEGIN
   nit_card_p.log(pl_module
                 ,pl_version);
END;
/

prompt
prompt Creating package body NIT_F_OPN_P
prompt =================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_f_opn_p IS
   pl_module  CONSTANT VARCHAR2(30) := 'nit_f_opn_p';
   pl_version CONSTANT VARCHAR2(30) := '0.0.2.2';

   -- nit_f_ci_life_ci_lv n?zethez
   ci_life_opn_descr_ci_id nit_config_items.id%TYPE;

   FUNCTION package_version RETURN VARCHAR2 IS
   BEGIN
      RETURN pl_module || ' ' || pl_version;
   END;

   FUNCTION get_opn_created_name RETURN VARCHAR2 IS
   BEGIN
      RETURN nit_f_opn_p.opn_description(nit_f_opn_p.created_idx);
   END;

   FUNCTION get_opn_modified_name RETURN VARCHAR2 IS
   BEGIN
      RETURN nit_f_opn_p.opn_description(nit_f_opn_p.modified_idx);
   END;

   FUNCTION get_opn_deleted_name RETURN VARCHAR2 IS
   BEGIN
      RETURN nit_f_opn_p.opn_description(nit_f_opn_p.deleted_idx);
   END;

   FUNCTION start_operation(p_type_name IN VARCHAR2) RETURN nit_operations.id%TYPE IS
      l_opn_rec cg$nit_operations.cg$row_type;
   BEGIN
      l_opn_rec.type_name := p_type_name;
      RETURN nit_operations_p.start_operation(l_opn_rec);
   END;

   PROCEDURE stop_operation(p_id IN nit_operations.id%TYPE) IS
   BEGIN
      nit_operations_p.stop_operation(p_id);
   END;

   PROCEDURE fail_operation(p_id IN nit_operations.id%TYPE) IS
   BEGIN
      nit_operations_p.fail_operation(p_id);
   END;

   FUNCTION get_ci_life_opn_description(p_id   IN nit_config_items.id%TYPE
                                       ,p_type IN VARCHAR2)
      RETURN nit_ci_life_opn_description_ot IS
      l_opn_description VARCHAR2(10);
      l_psn_id          nit_positions.id%TYPE;
      l_cia_name_id     nit_ci_attributes.id%TYPE;
      l_cia_status_id   nit_ci_attributes.id%TYPE;

      l_name_cipt_name   nit_ci_property_types.NAME%TYPE := nit_ci_property_types_p.get_name_cipt_name;
      l_status_cipt_name nit_ci_property_types.NAME%TYPE := nit_ci_property_types_p.get_status_cipt_name;

      CURSOR c_position(p_ci_id IN nit_config_items.id%TYPE, p_date IN nit_config_items.valid_until%TYPE) IS
         SELECT psn.id
               ,psn.valid_from
               ,psn.valid_until
         FROM   nit_positions psn
         WHERE  psn.ci_id = p_ci_id AND
                psn.valid_from <= p_date AND
                psn.valid_until >= p_date;

      CURSOR c_name(p_ci_id IN nit_config_items.id%TYPE, p_date IN nit_config_items.valid_until%TYPE) IS
         SELECT cia.id
               ,cia.valid_from
               ,cia.valid_until
         FROM   nit_ci_attributes     cia
               ,nit_ci_properties     cip
               ,nit_ci_property_types cipt
         WHERE  cia.ci_id = p_ci_id AND
                cia.cip_id = cip.id AND
                cip.cipt_id = cipt.id AND
                cipt.NAME = l_name_cipt_name AND
                cia.valid_from <= p_date AND
                cia.valid_until >= p_date;

      CURSOR c_status(p_ci_id IN nit_config_items.id%TYPE, p_date IN nit_config_items.valid_until%TYPE) IS
         SELECT cia.id
               ,cia.valid_from
               ,cia.valid_until
         FROM   nit_ci_attributes     cia
               ,nit_ci_properties     cip
               ,nit_ci_property_types cipt
         WHERE  cia.ci_id = p_ci_id AND
                cia.cip_id = cip.id AND
                cip.cipt_id = cipt.id AND
                cipt.NAME = l_status_cipt_name AND
                cia.valid_from <= p_date AND
                cia.valid_until >= p_date;

   BEGIN
      IF (p_type = 'CI') THEN
         DECLARE
            l_ci_rec      cg$nit_config_items.cg$row_type;
            l_valid_from  nit_config_items.valid_from%TYPE;
            l_valid_until nit_config_items.valid_until%TYPE;
         BEGIN
            l_ci_rec.id := p_id;
            cg$nit_config_items.slct(l_ci_rec);

            l_opn_description := opn_description(created_idx);

            -- megkereress?k a l?trehoz?skor ?rv?nyes poz?ci?t
            OPEN c_position(l_ci_rec.id
                           ,l_ci_rec.valid_from);
            FETCH c_position
               INTO l_psn_id, l_valid_from, l_valid_until;
            CLOSE c_position;

            -- megkereress?k a l?trehoz?skor ?rv?nyes nevet
            OPEN c_name(l_ci_rec.id
                       ,l_ci_rec.valid_from);
            FETCH c_name
               INTO l_cia_name_id, l_valid_from, l_valid_until;
            CLOSE c_name;

            -- megkereress?k a l?trehoz?skor ?rv?nyes st?tuszt
            OPEN c_status(l_ci_rec.id
                         ,l_ci_rec.valid_from);
            FETCH c_status
               INTO l_cia_status_id, l_valid_from, l_valid_until;
            CLOSE c_status;

            RETURN nit_ci_life_opn_description_ot(l_ci_rec.opn_id
                                                 ,l_opn_description
                                                 ,p_id
                                                 ,l_psn_id
                                                 ,l_cia_name_id
                                                 ,l_cia_status_id
                                                 ,l_ci_rec.valid_from
                                                 ,l_ci_rec.valid_until);
         END;
      ELSIF (p_type = 'PSN') THEN
         DECLARE
            l_psn_rec                cg$nit_positions.cg$row_type;
            l_psn_valid_until        nit_positions.valid_until%TYPE;
            l_cia_name_valid_from    nit_ci_attributes.valid_from%TYPE;
            l_cia_name_valid_until   nit_ci_attributes.valid_until%TYPE;
            l_cia_status_valid_from  nit_ci_attributes.valid_from%TYPE;
            l_cia_status_valid_until nit_ci_attributes.valid_until%TYPE;
            l_valid_from             nit_ci_attributes.valid_from%TYPE;
         BEGIN
            l_psn_rec.id := p_id;
            cg$nit_positions.slct(l_psn_rec);

            IF (l_psn_rec.obsolete = 'L') THEN
               l_opn_description := opn_description(created_idx);
            ELSE
               l_opn_description := opn_description(modified_idx);
            END IF;

            -- itt felt?telezem, hogy a poz?ci? ?s a CI egyidej?leg j?n l?tre, ?s a poz?ci?ra vonatkoz?
            -- created r?szt nem haszn?ljuk fel

            -- megkereress?k az ekkor ?rv?nyes nevet - ami l_psn_rec.valid_until-kor ?rv?nyes volt
            OPEN c_name(l_psn_rec.ci_id
                       ,l_psn_rec.valid_until);
            FETCH c_name
               INTO l_cia_name_id, l_cia_name_valid_from, l_cia_name_valid_until;
            CLOSE c_name;

            -- ha a nevet maga a CI rekord hordozza, kell az esetleges kor?bbi n?v valid_until-ja
            IF (l_cia_name_valid_from IS NULL) THEN
               BEGIN
                  SELECT nit_core_p.push(MAX(cia.valid_until))
                  INTO   l_cia_name_valid_from
                  FROM   nit_ci_attributes     cia
                        ,nit_ci_properties     cip
                        ,nit_ci_property_types cipt
                  WHERE  cia.ci_id = l_psn_rec.ci_id AND
                         cia.cip_id = cip.id AND
                         cip.cipt_id = cipt.id AND
                         cipt.NAME = l_name_cipt_name AND
                         cia.valid_until <= l_psn_rec.valid_until;
               EXCEPTION
                  WHEN no_data_found THEN
                     NULL;
               END;
            END IF;

            -- megkereress?k az ekkor ?rv?nyes st?tuszt - ami l_psn_rec.valid_until-kor ?rv?nyes volt
            OPEN c_status(l_psn_rec.ci_id
                         ,l_psn_rec.valid_until);
            FETCH c_status
               INTO l_cia_status_id, l_cia_status_valid_from, l_cia_status_valid_until;
            CLOSE c_status;

            -- ha a st?tuszt maga a CI rekord hordozza, kell az esetleges kor?bbi st?tusz valid_until-ja
            IF (l_cia_status_valid_from IS NULL) THEN
               BEGIN
                  SELECT nit_core_p.push(MAX(cia.valid_until))
                  INTO   l_cia_status_valid_from
                  FROM   nit_ci_attributes     cia
                        ,nit_ci_properties     cip
                        ,nit_ci_property_types cipt
                  WHERE  cia.ci_id = l_psn_rec.ci_id AND
                         cia.cip_id = cip.id AND
                         cip.cipt_id = cipt.id AND
                         cipt.NAME = l_status_cipt_name AND
                         cia.valid_until <= l_psn_rec.valid_until;
               EXCEPTION
                  WHEN no_data_found THEN
                     NULL;
               END;
            END IF;

            -- korrekt valid_from meghat?roz?sa
            l_valid_from := l_psn_rec.valid_from;
            IF (l_cia_name_valid_from IS NOT NULL AND
               l_valid_from < l_cia_name_valid_from) THEN
               l_valid_from := l_cia_name_valid_from;
            END IF;
            IF (l_cia_status_valid_from IS NOT NULL AND
               l_valid_from < l_cia_status_valid_from) THEN
               l_valid_from := l_cia_status_valid_from;
            END IF;

            RETURN nit_ci_life_opn_description_ot(l_psn_rec.opn_id
                                                 ,l_opn_description
                                                 ,l_psn_rec.ci_id
                                                 ,p_id
                                                 ,l_cia_name_id
                                                 ,l_cia_status_id
                                                 ,l_valid_from
                                                 ,l_psn_rec.valid_until);
         END;

      ELSIF (p_type = 'CIA') THEN
         DECLARE
            l_cia_rec                cg$nit_ci_attributes.cg$row_type;
            l_psn_valid_from         nit_positions.valid_from%TYPE;
            l_psn_valid_until        nit_positions.valid_until%TYPE;
            l_cia_name_valid_from    nit_ci_attributes.valid_from%TYPE;
            l_cia_name_valid_until   nit_ci_attributes.valid_until%TYPE;
            l_cia_status_valid_from  nit_ci_attributes.valid_from%TYPE;
            l_cia_status_valid_until nit_ci_attributes.valid_until%TYPE;
            l_ci_status              nit_config_items.status%TYPE;
            l_last_status_id         nit_ci_attributes.id%TYPE;
            l_valid_from             nit_ci_attributes.valid_from%TYPE;
         BEGIN
            l_cia_rec.id := p_id;
            cg$nit_ci_attributes.slct(l_cia_rec);

            SELECT ci.status
            INTO   l_ci_status
            FROM   nit_config_items ci
            WHERE  ci.id = l_cia_rec.ci_id;

            IF (l_ci_status = nit_core_p.ci_statuses(nit_core_p.ci_eol_idx)) THEN
               -- a CI t?r?lt, megkeress?k az utols? archiv?lt st?tuszt
               SELECT MAX(valid_until)
               INTO   l_cia_status_valid_until
               FROM   nit_ci_attributes     cia2
                     ,nit_ci_properties     cip2
                     ,nit_ci_property_types cipt2
               WHERE  cia2.ci_id = l_cia_rec.ci_id AND
                      cia2.cip_id = cip2.id AND
                      cip2.cipt_id = cipt2.id AND
                      cipt2.NAME = l_status_cipt_name;

               OPEN c_status(l_cia_rec.ci_id
                            ,l_cia_status_valid_until);
               FETCH c_status
                  INTO l_last_status_id, l_cia_status_valid_from, l_cia_status_valid_until;
               CLOSE c_status;

               IF (l_last_status_id <> l_cia_rec.id) THEN
                  -- nem ez az utolj?ra archiv?lt st?tusz
                  l_opn_description := opn_description(modified_idx);
               ELSE
                  -- utolj?ra archiv?lt st?tusz, azaz ekkor volt a t?rl?s
                  l_opn_description := opn_description(deleted_idx);
               END IF;
            ELSE
               l_opn_description := opn_description(modified_idx);
            END IF;

            -- megkeress?k az ekkor ?rv?nyes poz?ci?t: ami a cia_valid_until id?pillanat?ban ?rv?nyes volt
            OPEN c_position(l_cia_rec.ci_id
                           ,l_cia_rec.valid_until);
            FETCH c_position
               INTO l_psn_id, l_psn_valid_from, l_psn_valid_until;
            CLOSE c_position;

            /* TODO : ez n?v vagy st?tusz, ?gy a m?sik ellen?rz?se sz?ks?gtelen */

            -- megkeress?k az ekkor aktu?lis nevet: ami a cia valid_until id?pillanat?ban ?rv?nyes volt
            OPEN c_name(l_cia_rec.ci_id
                       ,l_cia_rec.valid_until);
            FETCH c_name
               INTO l_cia_name_id, l_cia_name_valid_from, l_cia_name_valid_until;
            CLOSE c_name;

            -- ha a nevet maga a CI rekord hordozza, kell az esetleges kor?bbi n?v valid_until-ja
            IF (l_cia_name_valid_from IS NULL) THEN
               BEGIN
                  SELECT nit_core_p.push(MAX(cia.valid_until))
                  INTO   l_cia_name_valid_from
                  FROM   nit_ci_attributes     cia
                        ,nit_ci_properties     cip
                        ,nit_ci_property_types cipt
                  WHERE  cia.ci_id = l_cia_rec.ci_id AND
                         cia.cip_id = cip.id AND
                         cip.cipt_id = cipt.id AND
                         cipt.NAME = l_name_cipt_name AND
                         cia.valid_until <= l_cia_rec.valid_until;
               EXCEPTION
                  WHEN no_data_found THEN
                     NULL;
               END;
            END IF;

            -- megkeress?k az ekkor aktu?lis st?tuszt: ami a cia valid_until id?pillanat?ban ?rv?nyes volt
            OPEN c_status(l_cia_rec.ci_id
                         ,l_cia_rec.valid_until);
            FETCH c_status
               INTO l_cia_status_id, l_cia_status_valid_from, l_cia_status_valid_until;
            CLOSE c_status;

            -- ha a st?tuszt maga a CI rekord hordozza, kell az esetleges kor?bbi st?tusz valid_until-ja
            IF (l_cia_status_valid_from IS NULL) THEN
               BEGIN
                  SELECT nit_core_p.push(MAX(cia.valid_until))
                  INTO   l_cia_status_valid_from
                  FROM   nit_ci_attributes     cia
                        ,nit_ci_properties     cip
                        ,nit_ci_property_types cipt
                  WHERE  cia.ci_id = l_cia_rec.ci_id AND
                         cia.cip_id = cip.id AND
                         cip.cipt_id = cipt.id AND
                         cipt.NAME = l_status_cipt_name AND
                         cia.valid_until <= l_cia_rec.valid_until;
               EXCEPTION
                  WHEN no_data_found THEN
                     NULL;
               END;
            END IF;

            -- korrekt valid_from meghat?roz?sa
            l_valid_from := l_cia_rec.valid_from;
            IF (l_psn_valid_from IS NOT NULL AND
               l_valid_from < l_psn_valid_from) THEN
               l_valid_from := l_psn_valid_from;
            END IF;
            IF (l_cia_name_valid_from IS NOT NULL AND
               l_valid_from < l_cia_name_valid_from) THEN
               l_valid_from := l_cia_name_valid_from;
            END IF;
            IF (l_cia_status_valid_from IS NOT NULL AND
               l_valid_from < l_cia_status_valid_from) THEN
               l_valid_from := l_cia_status_valid_from;
            END IF;

            RETURN nit_ci_life_opn_description_ot(l_cia_rec.opn_id
                                                 ,l_opn_description
                                                 ,l_cia_rec.ci_id
                                                 ,l_psn_id
                                                 ,l_cia_name_id
                                                 ,l_cia_status_id
                                                 ,l_valid_from
                                                 ,l_cia_rec.valid_until);
         END;
      END IF;
   END;

   PROCEDURE init_ci_life_opn_descr(p_id IN nit_config_items.id%TYPE) IS
   BEGIN
      ci_life_opn_descr_ci_id := p_id;
   END;

   FUNCTION get_ci_life_opn_descr_ci_id RETURN nit_num_ct IS
      coll nit_num_ct;
   BEGIN
      IF (ci_life_opn_descr_ci_id IS NOT NULL) THEN
         coll := nit_num_ct(ci_life_opn_descr_ci_id);
      ELSE
         BEGIN
            SELECT ci.id BULK COLLECT
            INTO   coll
            FROM   nit_config_items ci;
         EXCEPTION
            WHEN no_data_found THEN
               coll := nit_num_ct();
         END;
      END IF;
      RETURN coll;
   END;

END nit_f_opn_p;
/

prompt
prompt Creating package body NIT_F_USR_P
prompt =================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_f_usr_p IS

   pl_module  CONSTANT VARCHAR2(30) := 'NIT_F_USR_P';
   pl_version CONSTANT VARCHAR2(12) := '1.0.0';

   FUNCTION package_version RETURN VARCHAR2 IS
   BEGIN
      RETURN pl_version;
   END;

   PROCEDURE convert_for_tapi(p_usr_rec IN rt_usr
                             ,p_usr_ind IN it_usr
                             ,p_cg$rec  OUT cg$nit_users.cg$row_type
                             ,p_cg$ind  OUT cg$nit_users.cg$ind_type) IS
   BEGIN
      p_cg$rec.id       := p_usr_rec.id;
      p_cg$rec.username := p_usr_rec.username;
      p_cg$rec.realname := p_usr_rec.realname;
      p_cg$rec.LANGUAGE := p_usr_rec.LANGUAGE;
      p_cg$rec.email    := p_usr_rec.email;
      p_cg$rec.comments := p_usr_rec.comments;

      p_cg$ind.id       := NVL(p_usr_ind.id
                              ,FALSE);
      p_cg$ind.username := NVL(p_usr_ind.username
                              ,FALSE);
      p_cg$ind.realname := NVL(p_usr_ind.realname
                              ,FALSE);
      p_cg$ind.LANGUAGE := NVL(p_usr_ind.LANGUAGE
                              ,FALSE);
      p_cg$ind.email    := NVL(p_usr_ind.email
                              ,FALSE);
      p_cg$ind.comments := NVL(p_usr_ind.comments
                              ,FALSE);
   END;

   PROCEDURE convert_for_mapi(p_cg$rec  IN cg$nit_users.cg$row_type
                             ,p_usr_rec OUT rt_usr) IS
   BEGIN
      p_usr_rec.id       := p_cg$rec.id;
      p_usr_rec.username := p_cg$rec.username;
      p_usr_rec.realname := p_cg$rec.realname;
      p_usr_rec.LANGUAGE := p_cg$rec.LANGUAGE;
      p_usr_rec.email    := p_cg$rec.email;
      p_usr_rec.comments := p_cg$rec.comments;
   END;

   PROCEDURE usr_ins(p_rec IN OUT rt_usr
                    ,p_ind IN it_usr) IS
      l_rec cg$nit_users.cg$row_type;
      l_ind cg$nit_users.cg$ind_type;
   BEGIN
      convert_for_tapi(p_usr_rec => p_rec
                      ,p_usr_ind => p_ind
                      ,p_cg$rec  => l_rec
                      ,p_cg$ind  => l_ind);

      cg$nit_users.called_from_package := FALSE;
      cg$nit_users.ins(l_rec
                      ,l_ind);

      convert_for_mapi(p_cg$rec  => l_rec
                      ,p_usr_rec => p_rec);
   END;

   PROCEDURE usr_upd(p_rec IN OUT rt_usr
                    ,p_ind IN it_usr) IS
      l_rec cg$nit_users.cg$row_type;
      l_ind cg$nit_users.cg$ind_type;
   BEGIN
      convert_for_tapi(p_usr_rec => p_rec
                      ,p_usr_ind => p_ind
                      ,p_cg$rec  => l_rec
                      ,p_cg$ind  => l_ind);

      cg$nit_users.called_from_package := FALSE;
      cg$nit_users.upd(l_rec
                      ,l_ind);

      convert_for_mapi(p_cg$rec  => l_rec
                      ,p_usr_rec => p_rec);
   END;

   PROCEDURE usr_lck(p_rec IN OUT rt_usr
                    ,p_ind IN it_usr) IS
      l_rec cg$nit_users.cg$row_type;
      l_ind cg$nit_users.cg$ind_type;
   BEGIN
      convert_for_tapi(p_usr_rec => p_rec
                      ,p_usr_ind => p_ind
                      ,p_cg$rec  => l_rec
                      ,p_cg$ind  => l_ind);

      cg$nit_users.called_from_package := FALSE;
      cg$nit_users.lck(l_rec
                      ,l_ind);

      convert_for_mapi(p_cg$rec  => l_rec
                      ,p_usr_rec => p_rec);
   END;

   PROCEDURE usr_del(p_rec IN OUT rt_usr) IS
      l_pk_rec cg$nit_users.cg$pk_type;
   BEGIN
      l_pk_rec.id                      := p_rec.id;
      cg$nit_users.called_from_package := FALSE;
      cg$nit_users.del(l_pk_rec);
   END;
BEGIN
   nit_card_p.log(pl_module
                 ,pl_version);
END;
/

prompt
prompt Creating package body NIT_IMPORTER_P
prompt ====================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_importer_p AS

   /*****************************************************************************************
      NAME:       nit_importer_p
      PURPOSE:    Importing SMS (MS SQL) Datas to NItil (Oracle)
   
      REVISIONS:
      Ver        Date        Author                      Description
      ---------  ----------  ---------------         ------------------------------------
      0.1.0.1    2007.01.27. Szabolcs Hodosi/DEB/NIC     Created this package body.
      0.1.0.2    2007.02.01. Tamas Orban/DEB/NIC         Completed and optimalized.
      0.1.0.3    2007.02.12. Szabolcs Hodosi/DEB/NIC     Optimalized.
      0.5.0.1    2007.02.27. Szabolcs Hodosi/DEB/NIC     Code cleaned.
      0.1.0.0    2007.02.28. Szabolcs Hodosi/DEB/NIC     Downgrading 0.1.0.0
                                                         TOTALLY REWRITED.
   
   ******************************************************************************************/

   pl_version CONSTANT VARCHAR2(12) := '0.2.0.1';
   pl_module  CONSTANT VARCHAR2(30) := 'nit_importer_p';


   -- Only in-use statused CI-s will be fetched !!!
   -- Reason: Planned or approvied CI-s will be fetched when they are in use, because
   --         SMS is a realtime system, nitil can imagine things about the world like planning, approving...
   --         until a CI not in status 'in use' it's not allowed to use by anybody, so it can not
   --         detected by SMS, if the ServiceDesk workdflow is good !!
   --         The 'tested' will be allowed in order to ServiceDesk can deploy a tested CI

   TYPE cia_refresh_help_rec_t IS RECORD(
       cit_id          nit_ci_types.id%TYPE
      ,cip_id          nit_ci_properties.id%TYPE
      ,imp_source_name nit_ci_types.imp_source_name%TYPE
      ,imp_attrib      nit_ci_properties.imp_source_name%TYPE
      ,imp_where       nit_ci_types.imp_where_clause%TYPE);

   TYPE ci_refresh_coll_t IS TABLE OF nit_config_items%ROWTYPE;
   TYPE cia_refresh_coll_t IS TABLE OF nit_ci_attributes%ROWTYPE;
   TYPE cit_coll_t IS VARRAY(2000) OF nit_ci_types%ROWTYPE;
   TYPE psn_coll_t IS TABLE OF nit_positions%ROWTYPE;
   TYPE cia_refresh_help_coll_t IS TABLE OF cia_refresh_help_rec_t;

   TYPE ci_refresh_by_cit_cur_t IS REF CURSOR;
   TYPE ci_refresh_by_id_cur_t IS REF CURSOR;
   TYPE cia_refresh_by_cit_cur_t IS REF CURSOR;

   FUNCTION get_sms_id(presourceid IN INTEGER
                      ,pgroupid    IN INTEGER
                      ,previsionid IN INTEGER
                      ,pagentid    IN INTEGER) RETURN VARCHAR2 IS
      pl_subprg_name VARCHAR2(30) := 'get_sms_id';
   BEGIN
      RETURN NVL(CAST(presourceid AS VARCHAR2)
                ,'NULL') || '#' || NVL(CAST(pgroupid AS VARCHAR2)
                                      ,'NULL') || '#' || NVL(CAST(previsionid AS
                                                                  VARCHAR2)
                                                            ,'NULL') || '#' || NVL(CAST(pagentid AS
                                                                                        VARCHAR2)
                                                                                  ,'NULL');
   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#');
         RAISE;
   END;

   FUNCTION get_resource_id(psms_id IN VARCHAR2) RETURN INTEGER DETERMINISTIC IS
      pl_subprg_name VARCHAR2(30) := 'get_resource_id';
      l_pos1         BINARY_INTEGER := 1;
      l_pos2         BINARY_INTEGER := INSTR(psms_id
                                            ,'#'
                                            ,1
                                            ,1);
      l_str          VARCHAR2(30);
   BEGIN
      IF (l_pos2 = 0) THEN
         RETURN 0;
      ELSE
         l_str := SUBSTR(psms_id
                        ,l_pos1
                        ,l_pos2 - 1);
         RETURN TO_NUMBER(CASE l_str WHEN 'NULL' THEN NULL ELSE l_str END);
      END IF;
   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#');
         RAISE;
      
   END;

   FUNCTION get_group_id(psms_id IN VARCHAR2) RETURN INTEGER DETERMINISTIC IS
      pl_subprg_name VARCHAR2(30) := 'get_group_id';
      l_pos1         BINARY_INTEGER := INSTR(psms_id
                                            ,'#'
                                            ,1
                                            ,1);
      l_pos2         BINARY_INTEGER := INSTR(psms_id
                                            ,'#'
                                            ,1
                                            ,2);
      l_str          VARCHAR2(30);
   BEGIN
      IF (l_pos1 = 0 OR l_pos2 = 0) THEN
         RETURN NULL;
      ELSE
         l_str := SUBSTR(psms_id
                        ,l_pos1 + 1
                        ,l_pos2 - l_pos1 - 1);
         RETURN TO_NUMBER(CASE l_str WHEN 'NULL' THEN NULL ELSE l_str END);
      END IF;
   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#');
         RAISE;
   END;

   --   FUNCTION get_revision_id(psms_id IN VARCHAR2) RETURN INTEGER IS
   FUNCTION get_revision_id(psms_id IN VARCHAR2) RETURN INTEGER IS
      pl_subprg_name VARCHAR2(30) := 'get_revision_id';
      l_pos1         BINARY_INTEGER := INSTR(psms_id
                                            ,'#'
                                            ,1
                                            ,2);
      l_pos2         BINARY_INTEGER := INSTR(psms_id
                                            ,'#'
                                            ,1
                                            ,3);
      l_str          VARCHAR2(30);
   BEGIN
      IF (l_pos1 = 0 OR l_pos2 = 0) THEN
         RETURN NULL;
      ELSE
         l_str := SUBSTR(psms_id
                        ,l_pos1 + 1
                        ,l_pos2 - l_pos1 - 1);
         RETURN TO_NUMBER(CASE l_str WHEN 'NULL' THEN NULL ELSE l_str END);
      END IF;
   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#');
         RAISE;
   END;

   --   FUNCTION get_agent_id(psms_id IN VARCHAR2) RETURN INTEGER IS
   FUNCTION get_agent_id(psms_id IN VARCHAR2) RETURN INTEGER IS
      pl_subprg_name VARCHAR2(30) := 'get_agent_id';
      l_pos1         BINARY_INTEGER := INSTR(psms_id
                                            ,'#'
                                            ,1
                                            ,3);
      l_str          VARCHAR2(30);
   BEGIN
      IF (l_pos1 = 0) THEN
         RETURN NULL;
      ELSE
         l_str := SUBSTR(psms_id
                        ,l_pos1 + 1);
         RETURN TO_NUMBER(CASE l_str WHEN 'NULL' THEN NULL ELSE l_str END);
      END IF;
   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#');
         RAISE;
   END;

   FUNCTION get_first_revisions(p_imp_source_name IN VARCHAR2) RETURN VARCHAR2 IS
   BEGIN
      RETURN '(SELECT * FROM (
                 SELECT sms.*
                       ,min(sms.revision_id) over (partition by sms.resource_id, sms.group_id) AS min_revision_id
                 FROM ' || p_imp_source_name || ' sms
               )
               WHERE revision_id = min_revision_id)';
   END;

   PROCEDURE ci_refresh(p_id IN nit_config_items.id%TYPE) IS
      pl_subprg_name VARCHAR2(30) := 'ci_refresh';
      l_rec          cg$nit_config_items.cg$row_type;
      l_cit_rec      cg$nit_ci_types.cg$row_type;
      l_ind          cg$nit_config_items.cg$ind_type;
      coll           ci_refresh_coll_t;
      cur            ci_refresh_by_id_cur_t;
      slct_stmt      VARCHAR2(2000);
      idx            PLS_INTEGER;
      l_coll_rec     nit_config_items%ROWTYPE;
      l_opn_rec      cg$nit_operations.cg$row_type;
   BEGIN
      l_ind := cg$nit_config_items.cg$ind_true;
   
      l_rec.id        := p_id;
      l_rec.the_rowid := NULL;
   
      cg$nit_config_items.slct(l_rec);
   
      l_cit_rec.id        := l_rec.cit_id;
      l_cit_rec.the_rowid := NULL;
   
      cg$nit_ci_types.slct(l_cit_rec);
   
      IF (l_cit_rec.is_importable <> 'Y' OR
         l_cit_rec.imp_source_module <> 'SMS' OR
         l_cit_rec.imp_name_attrib IS NULL) THEN
         RETURN;
      END IF;
   
      slct_stmt := 'SELECT ci.id AS id
            ,ci.creation_date AS creation_date
            ,ci.created_by AS created_by
            ,NULL AS last_update_date
            ,NULL AS last_updated_by
            ,' || l_cit_rec.id || ' AS cit_id ' ||
                   ',-1 AS opn_id' || ',lower(sms.' ||
                   l_cit_rec.imp_name_attrib || ') AS name' ||
                   ',''in use'' AS status
            ,''L'' AS obsolete
            ,sms.TIMESTAMP AS valid_from
            ,NULL AS valid_until
            ,ci.comments AS comments
            ,sms.sms_id AS sms_id
            ,NULL AS last_refresh_date
            FROM ' || l_cit_rec.imp_source_name || ' sms ' ||
                   ',nit_config_items ci
      WHERE  ci.id = ' || p_id || ' AND
             nit_importer_p.get_resource_id(ci.sms_id) = sms.resource_id AND
             nit_importer_p.get_group_id(ci.sms_id) = sms.group_id AND
             nit_importer_p.get_revision_id(ci.sms_id) < sms.revision_id AND
             ci.obsolete = ''L'' AND
             (ci.status = ''in use'' OR ci.status = ''tested'') AND
             NVL(lower(sms.' || l_cit_rec.imp_name_attrib ||
                   '),ci.name) <> ci.NAME
      ORDER  BY sms.revision_id';
   
   
   
      OPEN cur FOR slct_stmt;
   
      FETCH cur BULK COLLECT
         INTO coll;
   
      CLOSE cur;
   
      IF (coll IS NOT NULL) THEN
         idx := coll.FIRST;
      END IF;
   
      l_opn_rec.id := nit_operations_p.start_operation(l_opn_rec);
   
      WHILE (idx IS NOT NULL) LOOP
         l_coll_rec := coll(idx);
      
         l_rec.the_rowid         := NULL;
         l_rec.opn_id            := l_opn_rec.id;
         l_rec.sms_id            := l_coll_rec.sms_id;
         l_rec.NAME              := l_coll_rec.NAME;
         l_rec.valid_from        := l_coll_rec.valid_from;
         l_rec.valid_until       := nit_core_p.get_infinite_date;
         l_rec.last_refresh_date := l_opn_rec.op_time;
      
         cg$nit_config_items.upd(l_rec
                                ,l_ind
                                ,TRUE);
      
         idx := coll.NEXT(idx);
      
      
      END LOOP;
   
      nit_operations_p.stop_operation(l_opn_rec.id);
   
   EXCEPTION
      WHEN OTHERS THEN
         nit_operations_p.fail_operation(l_opn_rec.id);
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#');
         RAISE;
      
   END;

   PROCEDURE all_ci_refresh(p_force IN BOOLEAN) IS
      pl_subprg_name VARCHAR2(30) := 'all_ci_refresh';
      l_rec          cg$nit_config_items.cg$row_type;
      l_cit_rec      nit_ci_types%ROWTYPE;
      l_ind          cg$nit_config_items.cg$ind_type := cg$nit_config_items.cg$ind_true;
      coll           ci_refresh_coll_t;
      cur            ci_refresh_by_cit_cur_t;
      slct_stmt      VARCHAR2(2000);
      idx            PLS_INTEGER;
      l_coll_rec     nit_config_items%ROWTYPE;
      l_opn_rec      cg$nit_operations.cg$row_type;
      cit_coll       cit_coll_t;
      cit_idx        PLS_INTEGER;
      l_prev_rec     nit_config_items%ROWTYPE;
   
   BEGIN
      IF (p_force) THEN
         SELECT * BULK COLLECT
         INTO   cit_coll
         FROM   nit_ci_types cit
         WHERE  cit.is_importable = 'Y' AND
                cit.imp_source_module = 'SMS' AND
                cit.imp_name_attrib IS NOT NULL
         ORDER  BY cit.NAME;
      END IF;
   
      IF (NOT p_force) THEN
         SELECT * BULK COLLECT
         INTO   cit_coll
         FROM   nit_ci_types cit
         WHERE  cit.is_importable = 'Y' AND
                cit.imp_source_module = 'SMS' AND
                cit.imp_name_attrib IS NOT NULL AND
                cit.imp_auto_import = 'Y'
         ORDER  BY cit.NAME;
      END IF;
   
      l_ind        := cg$nit_config_items.cg$ind_true;
      l_opn_rec.id := nit_operations_p.start_operation(l_opn_rec);
   
      FOR cit_idx IN cit_coll.FIRST .. cit_coll.LAST LOOP
      
         l_cit_rec := cit_coll(cit_idx);
      
         slct_stmt := 'SELECT ci.id AS id
               ,ci.creation_date AS creation_date
               ,ci.created_by AS created_by
               ,NULL AS last_update_date
               ,NULL AS last_updated_by
               ,ci.cit_id AS cit_id
               ,-1 AS opn_id
               ,lower(sms.' || l_cit_rec.imp_name_attrib ||
                      ') AS NAME ' ||
                      ',''in use'' AS status
               ,''L'' AS obsolete
               ,sms.TIMESTAMP AS valid_from ' ||
                      ',NULL AS valid_until' ||
                     
                      ',ci.comments AS comments
                ,sms.sms_id AS sms_id ' ||
                      ',NULL AS last_refresh_date
                FROM ' || l_cit_rec.imp_source_name ||
                      ' sms ' || ',nit_config_items ci ' ||
                      'WHERE ci.cit_id = ' || l_cit_rec.id || ' AND ' ||
                      l_cit_rec.imp_where_clause || ' AND nit_importer_p.get_resource_id(ci.sms_id) = sms.resource_id AND
                nit_importer_p.get_group_id(ci.sms_id) = sms.group_id AND
                nit_importer_p.get_revision_id(ci.sms_id) < sms.revision_id AND
                ci.obsolete = ''L'' AND
                (ci.status = ''in use'' OR ci.status = ''tested'') AND
                NVL(sms.' || l_cit_rec.imp_name_attrib ||
                      ',ci.name) <> ci.NAME AND
                sms.' || l_cit_rec.imp_name_attrib ||
                      ' IS NOT NULL ' || 'ORDER  BY sms.resource_id
                  ,sms.group_id
                  ,sms.revision_id';
      
         OPEN cur FOR slct_stmt;
      
         FETCH cur BULK COLLECT
            INTO coll;
      
         CLOSE cur;
      
         IF (coll IS NOT NULL) THEN
            idx := coll.FIRST;
            IF (idx IS NOT NULL) THEN
               l_prev_rec := coll(idx);
            END IF;
         END IF;
      
         WHILE (idx IS NOT NULL) LOOP
            l_coll_rec := coll(idx);
         
            IF (l_prev_rec.cit_id = l_coll_rec.cit_id AND
               l_prev_rec.NAME <> l_coll_rec.NAME) THEN
               l_rec.id                := l_coll_rec.id;
               l_rec.the_rowid         := NULL;
               l_rec.opn_id            := l_opn_rec.id;
               l_rec.sms_id            := l_coll_rec.sms_id;
               l_rec.NAME              := l_coll_rec.NAME;
               l_rec.cit_id            := l_coll_rec.cit_id;
               l_rec.valid_from        := l_coll_rec.valid_from;
               l_rec.valid_until       := nit_core_p.get_infinite_date;
               l_rec.last_refresh_date := l_opn_rec.op_time;
               l_rec.comments          := l_coll_rec.comments;
               l_rec.creation_date     := l_coll_rec.creation_date;
               l_rec.created_by        := l_coll_rec.created_by;
               l_rec.status            := l_coll_rec.status;
               l_rec.obsolete          := l_coll_rec.obsolete;
            
               cg$nit_config_items.upd(l_rec
                                      ,l_ind
                                      ,TRUE);
            
               idx        := coll.NEXT(idx);
               l_prev_rec := l_coll_rec;
            END IF;
         
            IF (l_prev_rec.cit_id = l_coll_rec.cit_id AND
               l_prev_rec.NAME = l_coll_rec.NAME) THEN
               l_prev_rec := l_coll_rec;
               idx        := coll.NEXT(idx);
            END IF;
         
            IF (l_prev_rec.cit_id <> l_coll_rec.cit_id) THEN
               l_rec.id                := l_coll_rec.id;
               l_rec.the_rowid         := NULL;
               l_rec.opn_id            := l_opn_rec.id;
               l_rec.sms_id            := l_coll_rec.sms_id;
               l_rec.NAME              := l_coll_rec.NAME;
               l_rec.cit_id            := l_coll_rec.cit_id;
               l_rec.valid_from        := l_coll_rec.valid_from;
               l_rec.valid_until       := nit_core_p.get_infinite_date;
               l_rec.last_refresh_date := l_opn_rec.op_time;
               l_rec.comments          := l_coll_rec.comments;
               l_rec.creation_date     := l_coll_rec.creation_date;
               l_rec.created_by        := l_coll_rec.created_by;
               l_rec.status            := l_coll_rec.status;
               l_rec.obsolete          := l_coll_rec.obsolete;
            
               cg$nit_config_items.upd(l_rec
                                      ,l_ind
                                      ,TRUE);
            
               idx        := coll.NEXT(idx);
               l_prev_rec := l_coll_rec;
            END IF;
         
         END LOOP; -- inner
      END LOOP; --cit
   
      nit_operations_p.stop_operation(l_opn_rec.id);
   
   EXCEPTION
      WHEN OTHERS THEN
      
         FOR out_idx IN 0 .. (LENGTH(slct_stmt) / 250) LOOP
            dbms_output.put_line(SUBSTR(slct_stmt
                                       ,out_idx * 250
                                       ,250));
         END LOOP;
      
         nit_operations_p.fail_operation(l_opn_rec.id);
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#');
         RAISE;
      
   END;

   PROCEDURE all_cia_refresh(p_force IN BOOLEAN) IS
      pl_subprg_name VARCHAR2(30) := 'all_cia_refresh';
      l_rec          cg$nit_ci_attributes.cg$row_type;
      l_ind          cg$nit_ci_attributes.cg$ind_type;
      coll           cia_refresh_coll_t;
      cur            cia_refresh_by_cit_cur_t;
      slct_stmt      VARCHAR2(2000);
      idx            PLS_INTEGER;
      l_coll_rec     nit_ci_attributes%ROWTYPE;
      l_opn_rec      cg$nit_operations.cg$row_type;
      help_coll      cia_refresh_help_coll_t;
      help_rec       cia_refresh_help_rec_t;
      help_coll_idx  PLS_INTEGER;
      l_inf_date     DATE;
      l_need_step    BOOLEAN;
      l_old_rec      cg$nit_ci_attributes.cg$row_type;
   BEGIN
      l_inf_date := nit_core_p.get_infinite_date;
   
      IF (p_force) THEN
         SELECT cit.id               cit_id
               ,cip.id               cip_id
               ,cit.imp_source_name  imp_source_name
               ,cip.imp_source_name  imp_attrib
               ,cit.imp_where_clause imp_where BULK COLLECT
         INTO   help_coll
         FROM   nit_ci_types      cit
               ,nit_ci_properties cip
         WHERE  cit.is_importable = 'Y' AND
                cit.imp_source_module = 'SMS' AND
                cip.is_importable = 'Y' AND
                cip.imp_source_module = 'SMS' AND
                cip.cit_id = cit.id
         ORDER  BY cit_id
                  ,cip_id;
      END IF;
   
      IF (NOT p_force) THEN
         SELECT cit.id               cit_id
               ,cip.id               cip_id
               ,cit.imp_source_name  imp_source_name
               ,cip.imp_source_name  imp_attrib
               ,cit.imp_where_clause imp_where BULK COLLECT
         INTO   help_coll
         FROM   nit_ci_types      cit
               ,nit_ci_properties cip
         WHERE  cit.is_importable = 'Y' AND
                cit.imp_source_module = 'SMS' AND
                cip.is_importable = 'Y' AND
                cip.imp_source_module = 'SMS' AND
                cip.cit_id = cit.id AND
                cip.imp_auto_import = 'Y'
         ORDER  BY cit_id
                  ,cip_id;
      END IF;
   
      l_ind        := cg$nit_ci_attributes.cg$ind_true;
      l_opn_rec.id := nit_operations_p.start_operation(l_opn_rec);
   
      FOR help_coll_idx IN 1 .. help_coll.COUNT
      --      FOR help_coll_idx IN help_coll.FIRST .. help_coll.LAST
       LOOP
         -- for over CIPs
         help_rec := help_coll(help_coll_idx);
      
         slct_stmt := 'SELECT /*+ USE_HASH(cia sms) */ cia.id AS id' ||
                     --slct_stmt := 'SELECT cia.id AS id' ||
                      ',cia.creation_date AS creation_date
               ,cia.created_by AS created_by
               ,NULL AS last_update_date
               ,NULL AS last_updated_by
               ,cia.ci_id AS ci_id
               ,cia.cip_id AS cip_id
               ,-1 AS opn_id
               ,NULL AS cipv_id
               ,''done'' AS status
               ,''L'' AS obsolete
               ,sms.TIMESTAMP AS valid_from' ||
                      ',NULL AS valid_until' || ',lower(TO_CHAR(sms.' ||
                      help_rec.imp_attrib || ')) AS data' ||
                      ',cia.comments AS comments
               ,sms.sms_id AS sms_id
               ,NULL AS last_refresh_date ' || ' FROM ' ||
                      help_rec.imp_source_name || ' sms
               ,nit_ci_attributes cia
         WHERE  cia.obsolete = ''L'' AND
                cia.cip_id = ' || help_rec.cip_id ||
                      ' AND nit_importer_p.get_resource_id(cia.sms_id) = sms.resource_id AND
                nit_importer_p.get_group_id(cia.sms_id) = sms.group_id AND
                nit_importer_p.get_revision_id(cia.sms_id) < sms.revision_id AND
                (cia.status = ''done'' OR cia.status = ''tested'') AND ' ||
                      ' lower(to_char(' || help_rec.imp_attrib ||
                      ')) IS NOT NULL AND ' || help_rec.imp_where ||
                      ' ORDER  BY sms.resource_id
                  ,sms.group_id
                  ,sms.revision_id';
      
      
         OPEN cur FOR slct_stmt;
      
         FETCH cur BULK COLLECT
            INTO coll;
      
         CLOSE cur;
      
         IF (coll IS NOT NULL AND coll.COUNT <> 0) THEN
            idx := coll.FIRST;
         END IF;
      
         WHILE (idx IS NOT NULL) LOOP
            l_coll_rec  := coll(idx);
            l_need_step := TRUE;
            WHILE (idx IS NOT NULL AND l_coll_rec.cip_id = coll(idx)
                  .cip_id AND l_coll_rec.ci_id = coll(idx)
                  .ci_id AND lower(l_coll_rec.data) = lower(coll(idx).data)) LOOP
               idx         := coll.NEXT(idx);
               l_need_step := FALSE;
            END LOOP;
         
            l_rec.the_rowid         := NULL;
            l_rec.opn_id            := l_opn_rec.id;
            l_rec.id                := l_coll_rec.id;
            l_rec.ci_id             := l_coll_rec.ci_id;
            l_rec.cip_id            := l_coll_rec.cip_id;
            l_rec.cipv_id           := l_coll_rec.cipv_id;
            l_rec.obsolete          := l_coll_rec.obsolete;
            l_rec.status            := l_coll_rec.status;
            l_rec.sms_id            := l_coll_rec.sms_id;
            l_rec.data              := l_coll_rec.data;
            l_rec.valid_from        := l_coll_rec.valid_from;
            l_rec.valid_until       := l_inf_date;
            l_rec.last_refresh_date := l_opn_rec.op_time;
            l_rec.comments          := l_coll_rec.comments;
            l_rec.creation_date     := l_coll_rec.creation_date;
            l_rec.created_by        := l_coll_rec.created_by;
         
            l_old_rec.id        := l_rec.id;
            l_old_rec.the_rowid := NULL;
         
            cg$nit_ci_attributes.slct(l_old_rec);
         
            IF (l_old_rec.data <> l_rec.data) THEN
               cg$nit_ci_attributes.upd(l_rec
                                       ,l_ind
                                       ,TRUE);
            END IF;
         
            IF (l_need_step) THEN
               idx := coll.NEXT(idx);
            END IF;
         
            IF (MOD(idx
                   ,1000) = 0) THEN
               COMMIT;
            END IF;
         END LOOP; -- inner
         COMMIT;
      END LOOP; -- helper
   
      nit_operations_p.stop_operation(l_opn_rec.id);
   
   EXCEPTION
      WHEN OTHERS THEN
         dbms_output.put_line(SQLCODE || ' ' || SQLERRM);
         FOR out_idx IN 0 .. (LENGTH(slct_stmt) / 250) LOOP
            dbms_output.put_line(SUBSTR(slct_stmt
                                       ,out_idx * 250
                                       ,250));
         END LOOP;
      
         nit_operations_p.fail_operation(l_opn_rec.id);
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#');
         RAISE;
      
   END;

   PROCEDURE cia_refresh(p_id IN nit_ci_attributes.id%TYPE) IS
      pl_subprg_name VARCHAR2(30) := 'cia_refresh';
      l_old_rec      cg$nit_ci_attributes.cg$row_type;
      l_rec          cg$nit_ci_attributes.cg$row_type;
      l_ind          cg$nit_ci_attributes.cg$ind_type;
      coll           cia_refresh_coll_t;
      cur            cia_refresh_by_cit_cur_t;
      slct_stmt      VARCHAR2(2000);
      idx            PLS_INTEGER;
      l_coll_rec     nit_ci_attributes%ROWTYPE;
      l_opn_rec      cg$nit_operations.cg$row_type;
      help_rec       cia_refresh_help_rec_t;
      l_need_step    BOOLEAN;
   BEGIN
      l_rec.id := p_id;
      cg$nit_ci_attributes.slct(l_rec);
   
      SELECT cit.id               cit_id
            ,cip.id               cip_id
            ,cit.imp_source_name  imp_source_name
            ,cip.imp_source_name  imp_attrib
            ,cit.imp_where_clause imp_where
      INTO   help_rec
      FROM   nit_ci_types      cit
            ,nit_ci_properties cip
      WHERE  cit.is_importable = 'Y' AND
             cit.imp_source_module = 'SMS' AND
             cip.is_importable = 'Y' AND
             cip.imp_source_module = 'SMS' AND
             cip.cit_id = cit.id AND
             cip.id = l_rec.cip_id;
   
      l_ind := cg$nit_ci_attributes.cg$ind_true;
   
      slct_stmt := 'SELECT cia.id AS id
               ,cia.creation_date AS creation_date
               ,cia.created_by AS created_by
               ,NULL AS last_update_date
               ,NULL AS last_updated_by
               ,cia.ci_id AS ci_id
               ,cia.cip_id AS cip_id
               ,-1 AS opn_id
               ,NULL AS cipv_id
               ,''done'' AS status
               ,''L'' AS obsolete
               ,sms.TIMESTAMP AS valid_from' || ',NULL ' ||
                   ',lower(TO_CHAR(sms.' || help_rec.imp_attrib || ')) AS data' ||
                   ',cia.comments AS comments
               ,sms.sms_id AS sms_id
               ,NULL' || ' FROM ' || help_rec.imp_source_name ||
                   ' sms ,nit_config_items  ci
               ,nit_ci_attributes cia
         WHERE  ci.id = cia.ci_id AND
                ci.obsolete = ''L'' AND
                cia.obsolete = ''L'' AND
                cia.id = ' || p_id || ' AND
                nit_importer_p.get_resource_id(cia.sms_id) = sms.resource_id AND
                nit_importer_p.get_group_id(cia.sms_id) = sms.group_id AND
                nit_importer_p.get_revision_id(cia.sms_id) < sms.revision_id AND
                (ci.status = ''in use'' OR ci.status = ''tested'') AND
                (cia.status = ''done'' OR cia.status = ''tested'') AND
                sms.' || help_rec.imp_attrib ||
                   ' IS NOT NULL
         ORDER  BY sms.revision_id';
   
      OPEN cur FOR slct_stmt;
   
      FETCH cur BULK COLLECT
         INTO coll;
   
      CLOSE cur;
   
      IF (coll IS NOT NULL) THEN
         idx := coll.FIRST;
      END IF;
   
      l_opn_rec.id := nit_operations_p.start_operation(l_opn_rec);
   
      WHILE (idx IS NOT NULL) LOOP
         l_coll_rec  := coll(idx);
         l_need_step := TRUE;
         WHILE (idx IS NOT NULL AND l_coll_rec.cip_id = coll(idx)
               .cip_id AND l_coll_rec.ci_id = coll(idx)
               .ci_id AND lower(l_coll_rec.data) = lower(coll(idx).data)) LOOP
            idx         := coll.NEXT(idx);
            l_need_step := FALSE;
         END LOOP;
         l_rec.the_rowid         := NULL;
         l_rec.opn_id            := l_opn_rec.id;
         l_rec.id                := l_coll_rec.id;
         l_rec.ci_id             := l_coll_rec.ci_id;
         l_rec.cip_id            := l_coll_rec.cip_id;
         l_rec.cipv_id           := l_coll_rec.cipv_id;
         l_rec.obsolete          := l_coll_rec.obsolete;
         l_rec.status            := l_coll_rec.status;
         l_rec.sms_id            := l_coll_rec.sms_id;
         l_rec.data              := l_coll_rec.data;
         l_rec.valid_from        := l_coll_rec.valid_from;
         l_rec.valid_until       := nit_core_p.get_infinite_date;
         l_rec.last_refresh_date := l_opn_rec.op_time;
         l_rec.comments          := l_coll_rec.comments;
         l_rec.creation_date     := l_coll_rec.creation_date;
         l_rec.created_by        := l_coll_rec.created_by;
      
         l_old_rec.id        := l_rec.id;
         l_old_rec.the_rowid := NULL;
      
         cg$nit_ci_attributes.slct(l_old_rec);
      
         IF (l_old_rec.data <> l_rec.data) THEN
            cg$nit_ci_attributes.upd(l_rec
                                    ,l_ind
                                    ,TRUE);
         END IF;
      
         IF (l_need_step) THEN
            idx := coll.NEXT(idx);
         END IF;
      END LOOP;
   
      nit_operations_p.stop_operation(l_opn_rec.id);
   
   EXCEPTION
      WHEN OTHERS THEN
         nit_operations_p.fail_operation(l_opn_rec.id);
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#');
         RAISE;
      
   END;


   PROCEDURE migrate_all_new_ci(p_force BOOLEAN) IS
      pl_subprg_name VARCHAR2(30) := 'migrate_all_new_ci';
      l_cit_rec      nit_ci_types%ROWTYPE;
      coll           ci_refresh_coll_t;
      big_coll       ci_refresh_coll_t := ci_refresh_coll_t();
      psn_coll       psn_coll_t := psn_coll_t();
      cur            ci_refresh_by_cit_cur_t;
      slct_stmt      VARCHAR2(4000);
      l_opn_rec      cg$nit_operations.cg$row_type;
      cit_coll       cit_coll_t;
      cit_idx        PLS_INTEGER;
      l_user         VARCHAR2(30);
      name_idx       PLS_INTEGER;
      temp_idx       PLS_INTEGER := 0;
      lcn_id         PLS_INTEGER;
      l_comp_id      PLS_INTEGER;
      l_serial       BOOLEAN;
   BEGIN
   
      l_user := sys_context('USERENV'
                           ,'session_user');
   
      IF (p_force) THEN
         SELECT * BULK COLLECT
         INTO   cit_coll
         FROM   nit_ci_types cit
         WHERE  cit.is_importable = 'Y' AND
                cit.imp_source_module = 'SMS';
      END IF;
   
      IF (NOT p_force) THEN
         SELECT * BULK COLLECT
         INTO   cit_coll
         FROM   nit_ci_types cit
         WHERE  cit.is_importable = 'Y' AND
                cit.imp_source_module = 'SMS' AND
                cit.imp_auto_import = 'Y';
      END IF;
   
      l_opn_rec.id := nit_operations_p.start_operation(l_opn_rec);
   
      SELECT id
      INTO   l_comp_id
      FROM   nit_ci_types
      WHERE  NAME = 'computer';
   
   
      FOR cit_idx IN cit_coll.FIRST .. cit_coll.LAST LOOP
         l_cit_rec := cit_coll(cit_idx);
         l_serial  := nit_ci_types_p.is_child_of(l_comp_id
                                                ,l_cit_rec.id) = 'Y';
      
         slct_stmt := 'SELECT  /*+use_hash(ci sms)*/ NULL AS ID ,TO_DATE(''' ||
                      TO_CHAR(l_opn_rec.op_time
                             ,'YYYY.MM.DD. HH24:MI:SS') || ''',''YYYY.MM.DD. HH24:MI:SS'') AS creation_date
               ,''' || l_user ||
                      ''' AS created_by
               ,TO_DATE(''' ||
                      TO_CHAR(l_opn_rec.op_time
                             ,'YYYY.MM.DD. HH24:MI:SS') || ''',''YYYY. MM.DD. HH24:MI:SS'') AS last_update_date
               ,''' || l_user || ''' AS last_updated_by
               ,' || l_cit_rec.id || ' AS cit_id
               ,' || l_opn_rec.id || ' AS opn_id ' ||
                      ',''temp'' AS NAME ' ||
                      ',''in use'' AS status
               ,''L'' AS obsolete
               ,sms.TIMESTAMP AS valid_from ' ||
                      ',NVL(nit_core_p.push_back(LEAD(sms.timestamp) OVER (PARTITION BY sms.resource_id, sms.group_id ORDER BY sms.revision_id)),nit_core_p.get_infinite_date) valid_until ' ||
                      ', NULL AS comments' || ',sms.sms_id AS sms_id ' ||
                      ',TO_DATE(''' ||
                      TO_CHAR(l_opn_rec.op_time
                             ,'YYYY.MM.DD. HH24:MI:SS') ||
                      ''',''YYYY.MM.DD. HH24:MI:SS'') AS last_refresh_date ' ||
                      ' FROM ' ||
                      get_first_revisions(l_cit_rec.imp_source_name) ||
                     --                      ' sms LEFT OUTER JOIN ' ||
                     --                      ' nit_config_items ci ON (sms.resource_id = nit_importer_p.get_resource_id(ci.sms_id) AND sms.group_id = nit_importer_p.get_group_id(ci.sms_id)) ' ||
                      ' sms ' || ' WHERE ' || l_cit_rec.imp_where_clause ||
                      ' AND sms.resource_id NOT IN (SELECT DISTINCT nit_importer_p.get_resource_id(ci.sms_id) FROM nit_config_items ci WHERE ci.sms_id IS NOT NULL AND ci.obsolete = ''L'' AND ci.cit_id = ' ||
                      l_cit_rec.id || ') ' || ' ORDER  BY sms.resource_id
                  ,sms.group_id';
      
         OPEN cur FOR slct_stmt;
      
         FETCH cur BULK COLLECT
            INTO coll;
         CLOSE cur;
      
         IF (coll IS NOT NULL AND coll.COUNT > 0) THEN
            name_idx := 1;
            FOR r IN coll.FIRST .. coll.LAST LOOP
               SELECT nit_seq.NEXTVAL
               INTO   coll(r) .id
               FROM   dual;
            
               IF (l_serial) THEN
                  BEGIN
                     SELECT NVL(lower(serialnumber)
                               ,'temp')
                     INTO   coll(r) .NAME
                     FROM   nit_sms_system_enclosure
                     WHERE  resource_id =
                            nit_importer_p.get_resource_id(coll(r).sms_id) AND
                            serialnumber IS NOT NULL AND
                            rownum = 1;
                  EXCEPTION
                     WHEN no_data_found THEN
                        NULL;
                  END;
               
               END IF;
            
               IF (coll(r).NAME = 'temp') THEN
                  coll(r).NAME := l_cit_rec.NAME || ' ' ||
                                  TO_CHAR(name_idx
                                         ,'0999999');
                  name_idx := name_idx + 1;
               END IF;
            END LOOP;
         
         END IF;
      
         name_idx := 1;
         /* Tricky-Tricky Way :) */
         temp_idx := big_coll.COUNT;
         FOR i IN (temp_idx + 1) .. (temp_idx + coll.COUNT) LOOP
            big_coll.EXTEND;
            big_coll(i) := coll(i - temp_idx);
         END LOOP;
      END LOOP; --cit
   
      BEGIN
         FORALL i IN big_coll.FIRST .. big_coll.LAST SAVE EXCEPTIONS
            INSERT /* + APPEND */
            INTO nit_config_items
            VALUES big_coll
               (i);
      EXCEPTION
         WHEN OTHERS THEN
            IF SQLCODE = -24381 THEN
               FOR indx IN 1 .. SQL%BULK_EXCEPTIONS.COUNT LOOP
                  dbms_output.put_line(SQL%BULK_EXCEPTIONS(indx).ERROR_CODE);
               END LOOP;
            END IF;
      END;
   
      -- Start do the Positions
      -- Maybe could be better in another procedure, but sincs we need copy large collections
      -- this could be very slow..
   
      SELECT id
      INTO   lcn_id
      FROM   nit_locations
      WHERE  NAME = 'nih';
   
      FOR i IN big_coll.FIRST .. big_coll.LAST LOOP
         psn_coll.EXTEND;
      
         SELECT nit_seq.NEXTVAL
         INTO   psn_coll(i) .id
         FROM   dual;
      
         psn_coll(i).lcn_id := lcn_id;
         psn_coll(i).ci_id := big_coll(i).id;
         psn_coll(i).status := 'done';
         psn_coll(i).obsolete := 'L';
         psn_coll(i).valid_from := big_coll(i).valid_from;
         psn_coll(i).valid_until := big_coll(i).valid_until;
         psn_coll(i).comments := NULL;
         psn_coll(i).opn_id := l_opn_rec.id;
         psn_coll(i).creation_date := big_coll(i).creation_date;
         psn_coll(i).created_by := big_coll(i).created_by;
         psn_coll(i).last_update_date := big_coll(i).last_update_date;
         psn_coll(i).last_updated_by := big_coll(i).last_updated_by;
      END LOOP;
   
      FORALL i IN psn_coll.FIRST .. psn_coll.LAST SAVE EXCEPTIONS
         INSERT /* + APPEND */
         INTO nit_positions
         VALUES psn_coll
            (i);
   
      nit_operations_p.stop_operation(l_opn_rec.id);
   
      COMMIT;
   
   EXCEPTION
      WHEN OTHERS THEN
         FOR out_idx IN 0 .. (LENGTH(slct_stmt) / 250) LOOP
            dbms_output.put_line(SUBSTR(slct_stmt
                                       ,out_idx * 250
                                       ,250));
         END LOOP;
      
         nit_operations_p.fail_operation(l_opn_rec.id);
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#');
         RAISE;
      
   END;

   PROCEDURE migrate_all_new_cia(p_force BOOLEAN) IS
      pl_subprg_name VARCHAR2(30) := 'migrate_all_new_cia';
      coll           cia_refresh_coll_t;
      cur            cia_refresh_by_cit_cur_t;
      slct_stmt      VARCHAR2(5000);
      idx            PLS_INTEGER;
      help_coll      cia_refresh_help_coll_t;
      help_rec       cia_refresh_help_rec_t;
      help_coll_idx  PLS_INTEGER;
      refresh_date   DATE;
      inf_date       DATE;
      out_idx        PLS_INTEGER;
   BEGIN
      inf_date     := nit_core_p.get_infinite_date;
      refresh_date := CURRENT_DATE;
   
      IF (p_force) THEN
         SELECT cit.id               cit_id
               ,cip.id               cip_id
               ,cit.imp_source_name  imp_source_name
               ,cip.imp_source_name  imp_attrib
               ,cit.imp_where_clause imp_where BULK COLLECT
         INTO   help_coll
         FROM   nit_ci_types      cit
               ,nit_ci_properties cip
         WHERE  cit.is_importable = 'Y' AND
                cit.imp_source_module = 'SMS' AND
                cip.is_importable = 'Y' AND
                cip.imp_source_module = 'SMS' AND
                cip.cit_id = cit.id
         ORDER  BY cit.imp_source_name
                  ,cit.id
                  ,cip.id;
      END IF;
   
      IF (NOT p_force) THEN
         SELECT cit.id               cit_id
               ,cip.id               cip_id
               ,cit.imp_source_name  imp_source_name
               ,cip.imp_source_name  imp_attrib
               ,cit.imp_where_clause imp_where BULK COLLECT
         INTO   help_coll
         FROM   nit_ci_types      cit
               ,nit_ci_properties cip
         WHERE  cit.is_importable = 'Y' AND
                cit.imp_source_module = 'SMS' AND
                cip.is_importable = 'Y' AND
                cip.imp_source_module = 'SMS' AND
                cip.cit_id = cit.id AND
                cip.imp_auto_import = 'Y'
         ORDER  BY cit.imp_source_name
                  ,cit.id
                  ,cip.id
         
         ;
      END IF;
   
      IF (help_coll IS NOT NULL AND help_coll.COUNT > 0) THEN
         FOR help_coll_idx IN help_coll.FIRST .. help_coll.LAST LOOP
         
            help_rec := help_coll(help_coll_idx);
         
            -- slct_stmt := 'SELECT NULL AS id
            slct_stmt := 'SELECT  /*+use_hash(ci sms)*/ NULL AS id
               ,ci.creation_date AS creation_date
               ,ci.created_by AS created_by
               ,ci.last_update_date AS last_update_date
               ,ci.last_updated_by AS last_updated_by
               ,ci.id AS ci_id ' || ',' ||
                         help_rec.cip_id || ' AS cip_id ' ||
                         ',ci.opn_id AS opn_id
               ,NULL AS cipv_id
               ,''done'' AS status
               ,''L'' AS obsolete,TO_DATE(sms.TIMESTAMP,''YYYY.MM.DD. HH24:MI:SS'') AS valid_from,TO_DATE(''' ||
                         TO_CHAR(inf_date
                                ,'YYYY.MM.DD. HH24:MI:SS') ||
                         ''',''YYYY.MM.DD. HH24:MI:SS'') AS valid_until' ||
                         ',lower(TO_CHAR(sms.' || help_rec.imp_attrib ||
                         ')) AS data' || ',NULL AS comments
               ,sms.sms_id AS sms_id ' || ',TO_DATE(''' ||
                         TO_CHAR(refresh_date
                                ,'YYYY.MM.DD. HH24:MI:SS') ||
                         ''',''YYYY.MM.DD. HH24:MI:SS'') AS last_refresh_date' ||
                         ' FROM ' ||
                         get_first_revisions(help_rec.imp_source_name) ||
                         ' sms LEFT OUTER JOIN nit_config_items ci ON (ci.cit_id = ' ||
                         help_rec.cit_id ||
                         ' AND sms.sms_id = ci.sms_id AND ci.obsolete = ''L'') WHERE ' ||
                         ' (ci.status = ''in use'' OR ci.status = ''tested'') AND sms.' ||
                         help_rec.imp_attrib ||
                         ' IS NOT NULL AND ci.id IS NOT NULL AND sms.sms_id NOT IN (SELECT DISTINCT sms_id FROM nit_ci_attributes cia WHERE cia.ci_id = ci.id AND cia.cip_id = ' ||
                         help_rec.cip_id || ') AND ' || help_rec.imp_where ||
                         ' ORDER  BY sms.resource_id
                  ,sms.group_id
                  ,sms.revision_id';
         
            OPEN cur FOR slct_stmt;
            /*         
                  FETCH cur BULK COLLECT
                     INTO coll;
               
                  CLOSE cur;
               
                  IF (coll IS NOT NULL AND coll.COUNT > 0) THEN
                     idx := coll.FIRST;
                  
                     WHILE (idx IS NOT NULL) LOOP
                        SELECT nit_seq.NEXTVAL
                        INTO   coll(idx) .id
                        FROM   dual;
                        idx := coll.NEXT(idx);
                     END LOOP; -- inner
                  
                     FORALL i IN coll.FIRST .. coll.LAST
                        INSERT INTO nit_ci_attributes
                        VALUES coll
                           (i);
                     COMMIT;
                  END IF; -- coll_count_check
               
               END LOOP; -- helper
            */
         
            LOOP
               FETCH cur BULK COLLECT
                  INTO coll LIMIT 10000;
               IF (coll IS NOT NULL AND coll.COUNT > 0) THEN
                  --     RAISE no_data_found;
                  idx := coll.FIRST;
               
                  WHILE (idx IS NOT NULL) LOOP
                     SELECT nit_seq.NEXTVAL
                     INTO   coll(idx) .id
                     FROM   dual;
                     idx := coll.NEXT(idx);
                  END LOOP; -- inner
               
                  FORALL i IN coll.FIRST .. coll.LAST
                     INSERT INTO nit_ci_attributes
                     VALUES coll
                        (i);
                  COMMIT;
               END IF; -- coll_count_check
            
               EXIT WHEN cur%NOTFOUND;
            END LOOP;
         
            CLOSE cur;
         END LOOP;
      
      END IF;
   EXCEPTION
      WHEN OTHERS THEN
         dbms_output.put_line(SQLERRM || ' ' || SQLCODE);
         FOR out_idx IN 0 .. (LENGTH(slct_stmt) / 250) LOOP
            dbms_output.put_line(SUBSTR(slct_stmt
                                       ,out_idx * 250
                                       ,250));
         END LOOP;
      
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#');
         RAISE;
      
   END;

   PROCEDURE create_cir IS
      l_cir_rec      cg$nit_ci_relations.cg$row_type;
      l_cir_ind      cg$nit_ci_relations.cg$ind_type;
      l_opn_rec      cg$nit_operations.cg$row_type;
      pl_subprg_name VARCHAR2(30) := 'create_cir';
      l_increment    PLS_INTEGER;
      l_ci_from_rec  cg$nit_config_items.cg$row_type;
      l_ci_to_rec    cg$nit_config_items.cg$row_type;
   
      CURSOR cur IS
         SELECT *
         FROM   (SELECT /*+ ALL_ROWS */
                  ci_to.ci_id   AS ci_to_id
                 ,ci_from.ci_id AS ci_from_id
                 ,citr.id       AS citr_id
                 FROM   (SELECT id AS ci_id
                               ,get_resource_id(sms_id) AS resource_id
                               ,cit_id
                         FROM   nit_config_items
                         WHERE  sms_id IS NOT NULL AND
                                obsolete = 'L') ci_from
                       ,(SELECT id AS ci_id
                               ,get_resource_id(sms_id) AS resource_id
                               ,cit_id
                         FROM   nit_config_items
                         WHERE  sms_id IS NOT NULL AND
                                obsolete = 'L') ci_to
                       ,(SELECT /*+ PARALLEL_INDEX(ni_ci_types NIT_CPK_CIT DEFAULT) */
                          id
                         FROM   nit_ci_types
                         WHERE  is_importable = 'Y') cit_from
                       ,(SELECT /*+ PARALLEL_INDEX(ni_ci_types NIT_CPK_CIT DEFAULT) */
                          id
                         FROM   nit_ci_types
                         WHERE  is_importable = 'Y') cit_to
                       ,(SELECT citrt_id
                               ,id
                               ,cit_id_from
                               ,cit_id_to
                         FROM   nit_ci_type_relations) citr
                       ,nit_cit_relation_types citrt
                 WHERE  ci_to.cit_id = cit_to.id AND
                        ci_from.cit_id = cit_from.id AND
                        citr.cit_id_to = cit_to.id AND
                        citr.cit_id_from = cit_from.id AND
                        ci_to.resource_id = ci_from.resource_id AND
                        citrt.id = citr.citrt_id AND
                        (citrt.NAME = 'provides' OR citrt.NAME = 'installed on' OR
                        citrt.NAME = 'contains' OR citrt.NAME = 'connected to')
                 MINUS (SELECT /*+ ALL_ROWS */
                        ci_id_to   AS ci_to_id
                       ,ci_id_from AS ci_from_id
                       ,citr_id    AS citr_id
                       FROM   nit_ci_relations));
   BEGIN
      l_increment := 0;
   
      l_opn_rec.id := nit_operations_p.start_operation(l_opn_rec);
   
      cg$nit_operations.slct(l_opn_rec);
   
      l_cir_ind := cg$nit_ci_relations.cg$ind_true;
   
      FOR rec IN cur LOOP
         IF (l_increment = 100) THEN
            COMMIT;
            l_increment := 0;
         END IF;
      
         l_ci_from_rec.id        := rec.ci_from_id;
         l_ci_from_rec.the_rowid := NULL;
         l_ci_to_rec.id          := rec.ci_to_id;
         l_ci_to_rec.the_rowid   := NULL;
      
         cg$nit_config_items.slct(l_ci_from_rec);
         cg$nit_config_items.slct(l_ci_to_rec);
      
         IF (l_ci_from_rec.valid_from > l_ci_to_rec.valid_from) THEN
            l_cir_rec.valid_from := l_ci_from_rec.valid_from;
         ELSE
            l_cir_rec.valid_from := l_ci_to_rec.valid_from;
         END IF;
      
         IF (l_ci_from_rec.valid_until < l_ci_to_rec.valid_until) THEN
            l_cir_rec.valid_until := l_ci_from_rec.valid_until;
         ELSE
            l_cir_rec.valid_until := l_ci_to_rec.valid_until;
         END IF;
      
         l_cir_rec.id         := NULL;
         l_cir_rec.the_rowid  := NULL;
         l_cir_rec.ci_id_to   := rec.ci_to_id;
         l_cir_rec.ci_id_from := rec.ci_from_id;
         l_cir_rec.citr_id    := rec.citr_id;
         l_cir_rec.status     := 'done';
         l_cir_rec.obsolete   := 'L';
         l_cir_rec.opn_id     := l_opn_rec.id;
      
         cg$nit_ci_relations.called_from_package := FALSE;
         cg$nit_ci_relations.ins(l_cir_rec
                                ,l_cir_ind);
         l_increment := l_increment + 1;
      END LOOP;
   
      nit_operations_p.stop_operation(p_id => l_opn_rec.id);
   
   EXCEPTION
      WHEN OTHERS THEN
         nit_operations_p.fail_operation(l_opn_rec.id);
         nit_error_p.log_exception(NULL
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#');
         RAISE;
   END;


BEGIN
   nit_card_p.log(pl_module
                 ,pl_version);
END nit_importer_p;
/

prompt
prompt Creating package body NIT_LOCATIONS_P
prompt =====================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_locations_p IS

   pl_version CONSTANT VARCHAR2(12) := '0.0.2.9';
   pl_module  CONSTANT VARCHAR2(30) := 'nit_locations_p';

   the_root_place CONSTANT VARCHAR2(20) := 'earth';
   virtual_place  CONSTANT VARCHAR2(20) := 'na';
   mutable_place  CONSTANT VARCHAR2(20) := 'portable';
   stock_place    CONSTANT VARCHAR2(20) := 'stock';

   PROCEDURE pre_dml(p_rec IN OUT cg$nit_locations.cg$row_type
                    ,p_ind IN OUT cg$nit_locations.cg$ind_type
                    ,p_op  IN VARCHAR2) IS
      r_name         nit_locations.NAME%TYPE;
      pl_subprg_name VARCHAR2(30) := 'pre_dml';
      l_old_rec      cg$nit_locations.cg$row_type;
      CURSOR cur IS
         SELECT id
               ,NAME
         FROM   nit_locations lcn
         WHERE  lcn.NAME = nit_core_p.getp(the_root_place) OR
                lcn.NAME = nit_core_p.getp(virtual_place) OR
                lcn.NAME = nit_core_p.getp(mutable_place) OR
                lcn.NAME = nit_core_p.getp(stock_place);
   BEGIN
      IF (p_op = 'INS') THEN
         p_ind.id            := TRUE;
         p_ind.creation_date := TRUE;
         p_ind.created_by    := TRUE;
         p_ind.lcn_id        := TRUE;
         p_ind.NAME          := TRUE;
         p_ind.abbreviation  := TRUE;

         IF (p_rec.abbreviation IS NULL) THEN
            p_rec.abbreviation := SUBSTR(p_rec.NAME
                                        ,0
                                        ,3);
         END IF;

      END IF;

      IF (p_op = 'INS' OR p_op = 'UPD') THEN
         p_ind.last_update_date := TRUE;
         p_ind.last_updated_by  := TRUE;
      END IF;

      /*
            <<check_names>>
            BEGIN
               SELECT NAME
               INTO   r_name
               FROM   nit_locations lcn
               WHERE  lcn.id = p_rec.id;

            EXCEPTION
               WHEN no_data_found THEN
                  NULL;
               WHEN OTHERS THEN
                  nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                           ,dbms_utility.format_call_stack
                                           ,dbms_utility.format_error_stack
                                           ,'Y'
                                           ,pl_module
                                           ,pl_version
                                           ,pl_subprg_name
                                           ,'#' || p_rec.id);
                  RAISE;
            END;
      */

      IF (p_op = 'INS' AND p_rec.NAME <> the_root_place AND r_name IS NOT NULL) THEN
         nit_error_p.error('NIT-00008'
                          ,'E'
                          ,TRUE
                          ,p_rec.NAME
                          ,NULL
                          ,NULL
                          ,p_rec.id);
      END IF;

      /* Orb?n Tam?s: Unique constraint van a n?ven */
      /*
            IF (p_op = 'UPD') THEN
                        IF ((p_rec.NAME = nit_core_p.get_parameter_value(virtual_place) OR
                           p_rec.NAME = nit_core_p.getp(mutable_place) OR
                           p_rec.NAME = nit_core_p.getp.get_parameter_value(the_root_place) OR
                           p_rec.NAME = nit_core_p.getp(stock_place)) AND
                           (r_name <> p_rec.NAME AND r_name IS NOT NULL)) THEN
                           -- Az R_NAME IS NOT NULL Az itt fontos!!! a select into-s blokk miatt
                           -- Ekkor v?dett nevet szeretn?nk m?dos?tani, ami tilos.
                           nit_error_p.error('NIT-00007'
                                            ,'E'
                                            ,TRUE
                                            ,p_rec.NAME
                                            ,NULL
                                            ,NULL
                                            ,p_rec.id);
                        END IF;
            END IF;
      */

      FOR rec IN cur LOOP

         IF ((rec.id = p_rec.id) AND (p_rec.NAME <> rec.NAME)) THEN
            l_old_rec.id := p_rec.id;
            cg$nit_locations.slct(l_old_rec);
            nit_error_p.error('NIT-00007'
                             ,'E'
                             ,TRUE
                             ,l_old_rec.NAME
                             ,NULL
                             ,NULL
                             ,p_rec.id);
         END IF;

      END LOOP;

      nit_core_p.caseconv(p_rec.NAME);
      nit_core_p.caseconv(p_rec.abbreviation);
      nit_core_p.caseconv(p_rec.naming_pattern);

      IF (p_op = 'INS' OR p_op = 'UPD') THEN
         nit_core_p.set_audit(p_rec.creation_date
                             ,p_rec.created_by
                             ,p_rec.last_update_date
                             ,p_rec.last_updated_by
                             ,p_op);
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;

   PROCEDURE pre_del(p_id IN nit_locations.id%TYPE) IS
      pl_subprg_name VARCHAR2(30) := 'PRE_DEL';
   BEGIN
      IF (is_deletable(p_id) = 'N') THEN
         nit_error_p.error('NIT-00006'
                          ,'E'
                          ,TRUE
                          ,NULL
                          ,NULL
                          ,NULL
                          ,p_id);
      END IF;

      IF is_leaf(p_id) = 'N' THEN
         nit_error_p.error('NIT-00025'
                          ,'E'
                          ,TRUE
                          ,NULL
                          ,NULL
                          ,NULL
                          ,p_id);
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;
   END;

   FUNCTION is_virtual(p_id IN nit_locations.id%TYPE) RETURN CHAR IS
      lcn_name       nit_locations.NAME%TYPE;
      pl_subprg_name VARCHAR2(30) := 'IS_VIRTUAL';
   BEGIN
      SELECT NAME
      INTO   lcn_name
      FROM   nit_locations lcn
      WHERE  lcn.id = p_id AND
             lcn.NAME = nit_core_p.getp(virtual_place);
      RETURN 'Y';

   EXCEPTION
      WHEN no_data_found THEN
         RETURN 'N';

      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;
   END;

   ----------------------------------------------------------------------------------------------------------------------------------

   FUNCTION is_mutable(p_id IN nit_locations.id%TYPE) RETURN CHAR IS
      lcn_name       nit_locations.NAME%TYPE;
      pl_subprg_name VARCHAR2(30) := 'IS_MUTABLE';
   BEGIN

      SELECT NAME
      INTO   lcn_name
      FROM   nit_locations lcn
      WHERE  lcn.id = p_id AND
             lcn.NAME = nit_core_p.getp(mutable_place);
      RETURN 'Y';

   EXCEPTION
      WHEN no_data_found THEN
         RETURN 'N';

      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;
   END;

   ----------------------------------------------------------------------------------------------------------------------------------

   FUNCTION is_stock(p_id IN nit_locations.id%TYPE) RETURN CHAR IS
      lcn_name       nit_locations.NAME%TYPE;
      pl_subprg_name VARCHAR2(30) := 'IS_STOCK';
   BEGIN

      SELECT NAME
      INTO   lcn_name
      FROM   nit_locations lcn
      WHERE  lcn.id = p_id AND
             lcn.NAME = nit_core_p.getp(stock_place);
      RETURN 'Y';

   EXCEPTION
      WHEN no_data_found THEN
         RETURN 'N';

      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;
   END;

   ----------------------------------------------------------------------------------------------------------------------------------

   FUNCTION is_root(p_id IN nit_locations.id%TYPE) RETURN CHAR IS
      par            nit_locations%ROWTYPE;
      pl_subprg_name VARCHAR2(30) := 'IS_ROOT';
   BEGIN
      SELECT *
      INTO   par
      FROM   nit_locations
      WHERE  id = p_id AND
             lcn_id IS NULL; -- az?rt a 'par'-ba mert ?gyis fel?l?rjuk mindj?rt..optimaliz?ci?..

      IF (par.NAME = nit_core_p.getp(the_root_place)) THEN
         RETURN 'Y';
      END IF;

      RETURN 'N';

   EXCEPTION
      WHEN no_data_found THEN
         RETURN 'N';
      WHEN too_many_rows THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         nit_error_p.error('NIT-00008'
                          ,'E'
                          ,TRUE
                          ,NULL
                          ,NULL
                          ,NULL
                          ,p_id);

      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;
   END;

   ----------------------------------------------------------------------------------------------------------------------------------

   FUNCTION is_leaf(p_id IN nit_locations.id%TYPE) RETURN CHAR IS
      par            nit_locations.id%TYPE;
      pl_subprg_name VARCHAR2(30) := 'IS_LEAF';
   BEGIN
      <<existance_check>>
      BEGIN
         SELECT lcn.id
         INTO   par
         FROM   nit_locations lcn
         WHERE  lcn.id = p_id -- az?rt a 'par'-ba mert ?gyis fel?l?rjuk mindj?rt..optimaliz?ci?..
                AND
                rownum = 1;

      EXCEPTION
         WHEN no_data_found THEN
            RETURN NULL;
      END;

      SELECT lcn.id
      INTO   par
      FROM   nit_locations lcn
      WHERE  lcn.lcn_id = p_id AND
             rownum = 1;

      RETURN 'N';

   EXCEPTION
      WHEN no_data_found THEN
         RETURN 'Y';
      WHEN too_many_rows THEN
         RETURN 'N';
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;
   END;

   FUNCTION get_stock_id RETURN nit_locations.id%TYPE IS
      r_id           nit_locations.id%TYPE;
      pl_subprg_name VARCHAR2(30) := 'GET_STOCK_ID';
   BEGIN
      SELECT id
      INTO   r_id
      FROM   nit_locations
      WHERE  NAME = nit_core_p.getp(stock_place);
      RETURN r_id;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || r_id);
         RAISE;
   END;

   FUNCTION get_virtual_id RETURN nit_locations.id%TYPE IS
      r_id           nit_locations.id%TYPE;
      pl_subprg_name VARCHAR2(30) := 'GET_STOCK_ID';
   BEGIN
      SELECT id
      INTO   r_id
      FROM   nit_locations
      WHERE  NAME = nit_core_p.getp(virtual_place);
      RETURN r_id;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || r_id);
         RAISE;
   END;

   FUNCTION get_mutable_id RETURN nit_locations.id%TYPE IS
      r_id           nit_locations.id%TYPE;
      pl_subprg_name VARCHAR2(30) := 'GET_STOCK_ID';
   BEGIN
      SELECT id
      INTO   r_id
      FROM   nit_locations
      WHERE  NAME = nit_core_p.getp(mutable_place);
      RETURN r_id;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || r_id);
         RAISE;
   END;

   FUNCTION get_root_id RETURN nit_locations.id%TYPE IS
      r_id           nit_locations.id%TYPE;
      pl_subprg_name VARCHAR2(30) := 'GET_STOCK_ID';
   BEGIN
      SELECT id
      INTO   r_id
      FROM   nit_locations
      WHERE  NAME = nit_core_p.getp(the_root_place);
      RETURN r_id;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || r_id);
         RAISE;
   END;

   /* Orb?n Tam?s: stock-ot is ellen?rizz?k le */
   FUNCTION is_deletable(p_id IN nit_locations.id%TYPE) RETURN CHAR IS
      pl_subprg_name VARCHAR2(30) := 'IS_DELETABLE';
   BEGIN
      IF (p_id IS NULL) THEN
         RETURN 'N';
      END IF;

      -- Ha gy?k?r akkor nem t?r?lhet?. M?s szab?lyt nem l?tok most, FK a t?bbi esetet szerintem megfogja...FIXME
      IF (is_mutable(p_id) = 'Y' OR is_virtual(p_id) = 'Y' OR
         is_root(p_id) = 'Y' OR is_stock(p_id) = 'Y') THEN
         RETURN 'N';
      END IF;

      RETURN 'Y';

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;

   FUNCTION package_version RETURN VARCHAR2 IS
   BEGIN
      RETURN '' || pl_module || ' ' || pl_version;
   END;

   FUNCTION get_default_name(p_rec IN OUT cg$nit_locations.cg$row_type)
      RETURN nit_locations.NAME%TYPE IS
      pl_subprg_name VARCHAR2(30) := 'GET_DEFAULT_NAME';
      parent_lcn     nit_locations%ROWTYPE;
      ret            nit_locations.NAME%TYPE;
   BEGIN

      SELECT *
      INTO   parent_lcn
      FROM   nit_locations lcn
      WHERE  lcn.id = p_rec.lcn_id;

      IF (p_rec.naming_pattern IS NULL) THEN
         ret := parent_lcn.naming_pattern;
      ELSIF (p_rec.naming_pattern = '#recursive#') THEN
         p_rec.naming_pattern := parent_lcn.naming_pattern || '-';
         RETURN get_default_name(p_rec);
      ELSE
         ret := p_rec.naming_pattern;
      END IF;

      ret := REPLACE(ret
                    ,'#parent name#'
                    ,parent_lcn.NAME);
      ret := REPLACE(ret
                    ,'#parent abbreviation#'
                    ,parent_lcn.abbreviation);
      ret := REPLACE(ret
                    ,'#parent pattern#'
                    ,parent_lcn.naming_pattern);

      RETURN ret;

   EXCEPTION
      WHEN no_data_found THEN
         -- Ha nincs sz?l?, akkor visszaadjuk a saj?t elnevez?si r?vid?t?s?nket alap?rtelmezett n?vnek.. mert mi csin?ljuk?
         RETURN p_rec.abbreviation;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;

   END;
   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION get_default_naming_pattern(p_rec IN cg$nit_locations.cg$row_type)
      RETURN nit_locations.naming_pattern%TYPE IS
      pl_subprg_name VARCHAR2(30) := 'GET_DEFAULT_NAMING_PATTERN';
      naming         nit_locations.naming_pattern%TYPE;
   BEGIN

      SELECT lcn.naming_pattern
      INTO   naming
      FROM   nit_locations lcn
      WHERE  lcn.id = p_rec.lcn_id;

      RETURN naming;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION is_child_of(p_parent IN nit_locations.id%TYPE
                       ,p_child  IN nit_locations.id%TYPE) RETURN CHAR IS
      pl_subprg_name VARCHAR2(30) := 'IS_CHILD_OF';
      coll           nit_locations_ct := get_parents_by_rev_inherit(p_child);
      i              PLS_INTEGER;

   BEGIN
      IF (coll IS NOT NULL) THEN

         IF (coll.COUNT > 0) THEN
            i := coll.FIRST;
         ELSE
            RETURN 'N';
         END IF;
      ELSE
         RETURN 'N';
      END IF;

      WHILE (i IS NOT NULL) LOOP
         IF (coll(i).id = p_parent) THEN
            RETURN 'Y';
         END IF;
         i := coll.NEXT(i);
      END LOOP;

      RETURN 'N';

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_parent || '#' || p_child);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION is_direct_child_of(p_parent IN nit_locations.id%TYPE
                              ,p_child  IN nit_locations.id%TYPE) RETURN CHAR IS
      par_id         nit_locations.id%TYPE;
      pl_subprg_name VARCHAR2(30) := 'IS_DIRECT_CHILD_OF';
   BEGIN
      SELECT lcn.id
      INTO   par_id
      FROM   nit_locations lcn
      WHERE  lcn.lcn_id = p_parent AND
             lcn.id = p_child;

      RETURN 'Y';

   EXCEPTION
      WHEN no_data_found THEN
         RETURN 'N';
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_parent || '#' || p_child);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION is_parent_of(p_parent IN nit_locations.id%TYPE
                        ,p_child  IN nit_locations.id%TYPE) RETURN CHAR IS
      pl_subprg_name VARCHAR2(30) := 'IS_PARENT_OF';
   BEGIN
      RETURN is_child_of(p_parent
                        ,p_child);

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_parent || '#' || p_child);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION is_direct_parent_of(p_parent IN nit_locations.id%TYPE
                               ,p_child  IN nit_locations.id%TYPE) RETURN CHAR IS
      pl_subprg_name VARCHAR2(30) := 'IS_DIRECT_PARENT_OF';
   BEGIN
      RETURN is_direct_child_of(p_parent
                               ,p_child);

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_parent || '#' || p_child);
         RAISE;
   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   -- A child2-nek gyereke-e a child1
   FUNCTION is_brother_of(p_child1 IN nit_locations.id%TYPE
                         ,p_child2 IN nit_locations.id%TYPE) RETURN CHAR IS
      pl_subprg_name VARCHAR2(30) := 'IS_BROTHER_OF';

   BEGIN
      IF (get_direct_parent(p_child1).id = get_direct_parent(p_child2).id) THEN
         RETURN 'Y';
      END IF;

      RETURN 'N';

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_child1 || '#' || p_child2);
         RAISE;
   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION get_children(p_id IN nit_locations.id%TYPE) RETURN nit_locations_ct IS
      coll           nit_locations_ct;
      pl_subprg_name VARCHAR2(30) := 'GET_CHILDREN';
   BEGIN
      SELECT nit_locations_ot(lcn.id
                             ,lcn.creation_date
                             ,lcn.created_by
                             ,lcn.last_update_date
                             ,lcn.last_updated_by
                             ,lcn.lcn_id
                             ,lcn.NAME
                             ,lcn.abbreviation
                             ,lcn.naming_pattern
                             ,lcn.description
                             ,lcn.comments
                             ,lcn.icon_name) BULK COLLECT
      INTO   coll
      FROM   nit_locations lcn
      WHERE  id <> p_id
      START  WITH lcn.id = p_id
      CONNECT BY PRIOR lcn.id = lcn.lcn_id;

      RETURN coll;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN OTHERS THEN
         dbms_output.put_line('hiba: ' || SQLERRM);
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RETURN NULL;
         RAISE;
   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION get_parents_by_rev_inherit(p_id IN nit_locations.id%TYPE)
      RETURN nit_locations_ct IS
      coll           nit_locations_ct;
      lcn_parent_id  nit_locations.lcn_id%TYPE;
      pl_subprg_name VARCHAR2(30) := 'GET_PARENTS_BY_REV_INHERIT';
   BEGIN
      SELECT lcn_id
      INTO   lcn_parent_id
      FROM   nit_locations
      WHERE  id = p_id;

      SELECT nit_locations_ot(lcn.id
                             ,lcn.creation_date
                             ,lcn.created_by
                             ,lcn.last_update_date
                             ,lcn.last_updated_by
                             ,lcn.lcn_id
                             ,lcn.NAME
                             ,lcn.abbreviation
                             ,lcn.naming_pattern
                             ,lcn.description
                             ,lcn.comments
                             ,lcn.icon_name) BULK COLLECT
      INTO   coll
      FROM   nit_locations lcn
      START  WITH id = lcn_parent_id
      CONNECT BY PRIOR lcn_id = id;

      RETURN coll;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;
   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION get_parents_by_inherit(p_id IN nit_locations.id%TYPE)
      RETURN nit_locations_ct IS
      coll           nit_locations_ct;
      lcn_parent_id  nit_locations.lcn_id%TYPE;
      pl_subprg_name VARCHAR2(30) := 'GET_PARENTS_BY_INHERIT';

   BEGIN
      SELECT lcn_id
      INTO   lcn_parent_id
      FROM   nit_locations
      WHERE  id = p_id;

      SELECT nit_locations_ot(lcn.id
                             ,lcn.creation_date
                             ,lcn.created_by
                             ,lcn.last_update_date
                             ,lcn.last_updated_by
                             ,lcn.lcn_id
                             ,lcn.NAME
                             ,lcn.abbreviation
                             ,lcn.naming_pattern
                             ,lcn.description
                             ,lcn.comments
                             ,lcn.icon_name) BULK COLLECT
      INTO   coll
      FROM   nit_locations lcn
      START  WITH id = lcn_parent_id
      CONNECT BY PRIOR lcn_id = id
      ORDER  BY rownum DESC;
      RETURN coll;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION get_brothers(p_id IN nit_locations.id%TYPE) RETURN nit_locations_ct IS
      lcn_parent_id  nit_locations.lcn_id%TYPE;
      coll           nit_locations_ct;
      pl_subprg_name VARCHAR2(30) := 'GET_BROTHERS';
   BEGIN
      SELECT lcn_id
      INTO   lcn_parent_id
      FROM   nit_locations
      WHERE  id = p_id;

      SELECT nit_locations_ot(lcn.id
                             ,lcn.creation_date
                             ,lcn.created_by
                             ,lcn.last_update_date
                             ,lcn.last_updated_by
                             ,lcn.lcn_id
                             ,lcn.NAME
                             ,lcn.abbreviation
                             ,lcn.naming_pattern
                             ,lcn.description
                             ,lcn.comments
                             ,lcn.icon_name) BULK COLLECT
      INTO   coll
      FROM   nit_locations lcn
      WHERE  lcn.lcn_id = lcn_parent_id AND
             id <> p_id;

      RETURN coll;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN collection_is_null THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION get_direct_children(p_id IN nit_locations.id%TYPE)
      RETURN nit_locations_ct IS
      coll           nit_locations_ct;
      pl_subprg_name VARCHAR2(30) := 'GET_DIRECT_CHILDREN';
   BEGIN
      SELECT nit_locations_ot(lcn.id
                             ,lcn.creation_date
                             ,lcn.created_by
                             ,lcn.last_update_date
                             ,lcn.last_updated_by
                             ,lcn.lcn_id
                             ,lcn.NAME
                             ,lcn.abbreviation
                             ,lcn.naming_pattern
                             ,lcn.description
                             ,lcn.comments
                             ,lcn.icon_name) BULK COLLECT
      INTO   coll
      FROM   nit_locations lcn
      WHERE  lcn.lcn_id = p_id;
      RETURN coll;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN collection_is_null THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;
   END;

   ----------------------------------------------------------------------------------------------------------------------------------
   FUNCTION get_direct_parent(p_id IN nit_locations.id%TYPE)
      RETURN nit_locations%ROWTYPE IS
      my_parent      nit_locations%ROWTYPE;
      pl_subprg_name VARCHAR2(30) := 'GET_DIRECT_PARENT';

   BEGIN
      <<existance_check>>
      BEGIN
         SELECT lcn_id
         INTO   my_parent.id
         FROM   nit_locations lcn
         WHERE  lcn.id = p_id;

      EXCEPTION
         WHEN no_data_found THEN
            nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                     ,dbms_utility.format_call_stack
                                     ,dbms_utility.format_error_stack
                                     ,'Y'
                                     ,pl_module
                                     ,pl_version
                                     ,pl_subprg_name
                                     ,'#' || p_id);
            RETURN NULL;
      END;

      SELECT *
      INTO   my_parent
      FROM   nit_locations lcn
      WHERE  lcn.id = my_parent.id;

      RETURN my_parent;

   EXCEPTION
      WHEN no_data_found THEN
         RETURN NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;
   END;

   FUNCTION get_direct_parent_obj(p_id IN nit_locations.id%TYPE)
      RETURN nit_locations_ot IS
      obj nit_locations_ot;
      rec nit_locations%ROWTYPE := get_direct_parent(p_id);
   BEGIN
      obj := nit_locations_ot(rec.id
                             ,rec.creation_date
                             ,rec.created_by
                             ,rec.last_update_date
                             ,rec.last_updated_by
                             ,rec.lcn_id
                             ,rec.NAME
                             ,rec.abbreviation
                             ,rec.naming_pattern
                             ,rec.description
                             ,rec.comments
                             ,rec.icon_name);
      RETURN obj;
   END;

   PROCEDURE cascade_upd(p_rec IN OUT cg$nit_locations.cg$row_type) IS
      -- Ha minden szinten kell, akkor annyi, hogy a direct sz?t kiszedj?k
      child_coll     nit_locations_ct := get_direct_children(p_rec.id);
      i              PLS_INTEGER;
      l_lcn_rec      cg$nit_locations.cg$row_type;
      l_lcn_ind      cg$nit_locations.cg$ind_type;
      pl_subprg_name VARCHAR2(30) := 'cascade_upd';
   BEGIN
      IF (child_coll IS NOT NULL) THEN

         IF (child_coll.COUNT > 0) THEN
            i := child_coll.FIRST;
         ELSE
            RETURN;
         END IF;

         l_lcn_ind.id               := FALSE;
         l_lcn_ind.creation_date    := FALSE;
         l_lcn_ind.created_by       := FALSE;
         l_lcn_ind.last_update_date := FALSE;
         l_lcn_ind.last_updated_by  := FALSE;
         l_lcn_ind.lcn_id           := FALSE;
         l_lcn_ind.NAME             := TRUE;
         l_lcn_ind.abbreviation     := FALSE;
         l_lcn_ind.naming_pattern   := FALSE;
         l_lcn_ind.description      := FALSE;
         l_lcn_ind.comments         := FALSE;
         l_lcn_ind.icon_name        := FALSE;

         WHILE (i IS NOT NULL) LOOP
            l_lcn_rec.id               := child_coll(i).id;
            l_lcn_rec.creation_date    := child_coll(i).creation_date;
            l_lcn_rec.created_by       := child_coll(i).created_by;
            l_lcn_rec.last_update_date := child_coll(i).last_update_date;
            l_lcn_rec.last_updated_by  := child_coll(i).last_updated_by;
            l_lcn_rec.lcn_id           := child_coll(i).lcn_id;
            l_lcn_rec.abbreviation     := child_coll(i).abbreviation;
            l_lcn_rec.naming_pattern   := child_coll(i).naming_pattern;
            l_lcn_rec.description      := child_coll(i).description;
            l_lcn_rec.comments         := child_coll(i).comments;
            l_lcn_rec.icon_name        := child_coll(i).icon_name;

            l_lcn_rec.NAME := get_default_name(l_lcn_rec);

            cg$nit_locations.upd(l_lcn_rec
                                ,l_lcn_ind
                                ,TRUE);
            i := child_coll.NEXT(i);
         END LOOP;
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;

   END;

   PROCEDURE cascade_del(p_id IN OUT nit_locations.id%TYPE) IS
      -- Ha minden szinten kell, akkor annyi, hogy a direct sz?t kiszedj?k
      child_coll     nit_locations_ct := get_direct_children(p_id);
      i              PLS_INTEGER;
      l_pk           cg$nit_locations.cg$pk_type;
      pl_subprg_name VARCHAR2(30) := 'cascade_del';
   BEGIN
      IF (child_coll IS NOT NULL) THEN
         IF (child_coll.COUNT > 0) THEN
            i := child_coll.LAST;
         ELSE
            RETURN;
         END IF;
         WHILE (i IS NOT NULL) LOOP
            cg$nit_locations.del(l_pk
                                ,TRUE);
            i := child_coll.PRIOR(i);
         END LOOP;
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;
BEGIN
   nit_card_p.log(pl_module
                 ,pl_version);
END nit_locations_p;
/

prompt
prompt Creating package body NIT_OPERATIONS_P
prompt ======================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_operations_p IS
   pl_module  CONSTANT VARCHAR2(30) := 'nit_operations_p';
   pl_version CONSTANT VARCHAR2(30) := '0.0.2.2';

   FUNCTION get_opn_failed_name RETURN VARCHAR2 IS
   BEGIN
      RETURN allowed_statuses(failed_idx);
   END;

   FUNCTION get_opn_routine_name RETURN VARCHAR2 IS
   BEGIN
      RETURN operation_types(routine_idx);
   END;

   FUNCTION get_opn_emergency_name RETURN VARCHAR2 IS
   BEGIN
      RETURN operation_types(emergency_idx);
   END;

   FUNCTION get_opn_requested_name RETURN VARCHAR2 IS
   BEGIN
      RETURN operation_types(requested_idx);
   END;

   FUNCTION get_status(p_id nit_operations.id%TYPE) RETURN VARCHAR2 IS
      ret            nit_operations.status%TYPE;
      pl_subprg_name VARCHAR2(30) := 'GET_STATUS';

   BEGIN
      SELECT status
      INTO   ret
      FROM   nit_operations op
      WHERE  op.id = p_id;
      RETURN ret;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;
   END;

   FUNCTION package_version RETURN VARCHAR2 IS
   BEGIN
      RETURN pl_module || ' ' || pl_version;
   END;

   FUNCTION start_operation(p_rec IN OUT cg$nit_operations.cg$row_type)
      RETURN nit_operations.id%TYPE IS
      pl_subprg_name VARCHAR2(30) := 'START_OPERATION';
      l_ind          cg$nit_operations.cg$ind_type;
      PRAGMA AUTONOMOUS_TRANSACTION;
   BEGIN
      nit_core_p.set_audit(p_rec.creation_date
                          ,p_rec.created_by
                          ,p_rec.last_update_date
                          ,p_rec.last_updated_by);

      IF (p_rec.op_time IS NULL) THEN
         p_rec.op_time := CURRENT_DATE;
      END IF;

      IF (p_rec.type_name IS NULL) THEN
         p_rec.type_name := operation_types(routine_idx);
      END IF;

      p_rec.usr_id := nit_core_p.get_session_user_id;

      p_rec.status := allowed_statuses(started_idx);

      nit_core_p.caseconv(p_rec.users);

      cg$nit_operations.called_from_package := FALSE;
      cg$nit_operations.ins(p_rec
                           ,l_ind);

      COMMIT;
      RETURN p_rec.id;

   EXCEPTION
      WHEN OTHERS THEN
         -- Nem v?ltjuk ki ?jra a kiv?telt, mert akkor a fail_op nem tud lefutni...

         -- Orb?n Tam?s: a fail_op. legt?bbsz?r akkor futna le, ha az ins. h?v?s sikertelen
         -- A fail_op. kezdetkor h?v egy slct-t, ami nem fogja megtal?lni a rekordot -> ?jabb kiv?tel
         -- fail_operation(p_rec.id);

         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#');
         RAISE;
   END;

   -- Ez csomagol, tr?kk az annyi, hogy az ?res rekordot a start_op... fv. felt?lti defaulttal ?gy
   -- k?nnyebb kezelni a CI props, CI oldalon az oper?ci?t...
   FUNCTION start_inner_operation RETURN nit_operations.id%TYPE IS
      pl_subprg_name VARCHAR2(30) := 'START_INNER_OPERATION';
      l_rec          cg$nit_operations.cg$row_type;
   BEGIN
      RETURN start_operation(l_rec);
   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#');
         RAISE;
   END;

   PROCEDURE fail_operation(p_id IN nit_operations.id%TYPE) IS
      pl_subprg_name VARCHAR2(30) := 'FAIL_OPERATION';
      PRAGMA AUTONOMOUS_TRANSACTION;
      op_rec cg$nit_operations.cg$row_type;
      op_ind cg$nit_operations.cg$ind_type;

   BEGIN
      op_rec.id := p_id;
      cg$nit_operations.slct(op_rec);

      nit_core_p.set_audit(op_rec.creation_date
                          ,op_rec.created_by
                          ,op_rec.last_update_date
                          ,op_rec.last_updated_by);

      op_rec.status  := allowed_statuses(failed_idx);
      op_rec.op_time := CURRENT_DATE;

      op_ind.status  := TRUE;
      op_ind.op_time := TRUE;

      cg$nit_operations.upd(op_rec
                           ,op_ind);

      COMMIT;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#');
         RAISE;
   END;

   PROCEDURE stop_operation(p_id IN nit_operations.id%TYPE) IS
      pl_subprg_name VARCHAR2(30) := 'STOP_OPERATION';
      op_rec         cg$nit_operations.cg$row_type;
      op_ind         cg$nit_operations.cg$ind_type;
      PRAGMA AUTONOMOUS_TRANSACTION;
   BEGIN
      op_rec.id := p_id;
      cg$nit_operations.slct(op_rec);

      op_rec.status := allowed_statuses(finished_idx);
      -- FIXME: A teljes rendszer m?r tervez?si szinten G?borral egy?tt azt felt?telezt?k, hogy
      -- minden DML m?velet kevesebb mint 1 sec alatt lefut.
      -- !!!!! Egy?bk?nt nem j? az op_time!
      op_rec.op_time := CURRENT_DATE;

      op_ind.status := TRUE;

      nit_core_p.set_audit(op_rec.creation_date
                          ,op_rec.created_by
                          ,op_rec.last_update_date
                          ,op_rec.last_updated_by);
      cg$nit_operations.upd(op_rec
                           ,op_ind);
      COMMIT;
   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#');
         RAISE;
   END;

END nit_operations_p;
/

prompt
prompt Creating package body NIT_POSITIONS_P
prompt =====================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_positions_p IS
   pl_version CONSTANT VARCHAR2(12) := '0.0.2.20';
   pl_module  CONSTANT VARCHAR2(30) := 'nit_positions_p';

   FUNCTION package_version RETURN VARCHAR2 IS
   BEGIN
      RETURN pl_module || ' ' || pl_version;
   END;

   PROCEDURE archiving(p_rec     IN OUT cg$nit_positions.cg$row_type
                      ,p_old_rec IN OUT cg$nit_positions.cg$row_type) IS
      -- p_rec az ?j rekord..
      -- p_old_rec -et fogjuk archiv?lni
      pl_subprg_name VARCHAR2(30) := 'archiving';
      l_opn_rec      cg$nit_operations.cg$row_type;
      l_need_op_fail BOOLEAN := TRUE;
      l_need_op_stop BOOLEAN := FALSE;
      l_old_ind      cg$nit_positions.cg$ind_type;
   BEGIN
      IF (p_old_rec.obsolete <> 'L') THEN
         RETURN;
      END IF;

      <<check_op>>
      BEGIN
         l_opn_rec.id := p_rec.opn_id;
         -- ezzek az oper?ci?val fogom learchiv?lni a rekordomat
         cg$nit_operations.slct(l_opn_rec);
         -- Ha sikeres, akkor ok nek?nk...
      EXCEPTION
         WHEN no_data_found THEN
            -- Azaz van valami ID a p_rec-ben opn_idk?nt, de az semmi se...
            p_rec.opn_id   := nit_operations_p.start_inner_operation;
            l_need_op_stop := TRUE;
            -- Namost ;)
            l_opn_rec.id := p_rec.opn_id;
            -- ezzek az oper?ci?val fogom learchiv?lni a rekordomat
            cg$nit_operations.slct(l_opn_rec);
         WHEN OTHERS THEN
            IF (l_need_op_fail) THEN
               nit_operations_p.fail_operation(l_opn_rec.id);
            END IF;

            nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                     ,dbms_utility.format_call_stack
                                     ,dbms_utility.format_error_stack
                                     ,'Y'
                                     ,pl_module
                                     ,pl_version
                                     ,pl_subprg_name
                                     ,'#' || p_rec.id);
            RAISE;
      END check_op;

      -- Ok, oper?ci?nk ?gy vagy ?gy, de megvan...
      --      p_old_rec.valid_until := nit_core_p.push_back(l_opn_rec.op_time);
      p_old_rec.valid_until := nit_core_p.push_back(NVL(p_rec.valid_from
                                                       ,l_opn_rec.op_time));
      -- Beallitjuk a flaget
      p_old_rec.obsolete := 'A';
      p_old_rec.opn_id   := p_rec.opn_id;
      p_old_rec.ci_id    := p_rec.ci_id;

      -- ha az obsolete indik?tora false, a table API automatikusan 'L'-re ?ll?tja
      l_old_ind.obsolete := TRUE;

      p_rec.valid_from := NVL(p_rec.valid_from
                             ,l_opn_rec.op_time);

      SELECT nit_seq.NEXTVAL
      INTO   p_old_rec.id
      FROM   dual;

      cg$nit_positions.ins(p_old_rec
                          ,l_old_ind);

      -- Ha mi ind?tottuk az oper?ci?t, akkor korrekten le is fogjuk ?ll?tani
      IF (l_need_op_stop) THEN
         nit_operations_p.stop_operation(l_opn_rec.id);
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         IF (l_need_op_fail) THEN
            nit_operations_p.fail_operation(l_opn_rec.id);
         END IF;

         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;

   PROCEDURE pre_dml(p_rec IN OUT cg$nit_positions.cg$row_type
                    ,p_ind IN OUT cg$nit_positions.cg$ind_type
                    ,p_op  IN VARCHAR2) IS
      ci_rec         cg$nit_config_items.cg$row_type;
      pl_subprg_name VARCHAR2(30) := 'pre_dml';
      r_stock_id     nit_locations.id%TYPE := nit_locations_p.get_stock_id;
      r_muta_id      nit_locations.id%TYPE := nit_locations_p.get_mutable_id;
      cit_rec        cg$nit_ci_types.cg$row_type;
      pos_rec        nit_positions%ROWTYPE;
      v_has_position CHAR;
   BEGIN
      IF (p_op <> 'INS' AND p_op <> 'UPD') THEN
         RETURN;
      END IF;

      nit_core_p.set_validity(p_rec.valid_from
                             ,p_rec.valid_until
                             ,p_rec.opn_id);
      ci_rec.id := p_rec.ci_id;
      cg$nit_config_items.slct(ci_rec);

      IF (p_op = 'INS') THEN
         p_ind.id            := TRUE;
         p_ind.creation_date := TRUE;
         p_ind.created_by    := TRUE;

         -- Ha ilyen tal?lunk, akkor az nem j?.. 1 Ci nem lehet 2 helyen egyszerre...
         <<psn_check>>
         BEGIN
            SELECT *
            INTO   pos_rec
            FROM   nit_positions psn
            WHERE  psn.ci_id = p_rec.ci_id AND
                   p_rec.obsolete = psn.obsolete AND
                   psn.obsolete = 'L';

            nit_error_p.error('NIT-00033'
                             ,'E'
                             ,TRUE
                             ,ci_rec.NAME
                             ,NULL
                             ,NULL
                             ,p_rec.id);
         EXCEPTION
            WHEN no_data_found THEN
               NULL;
            WHEN OTHERS THEN
               /* Orb?n Tam?s: ezt ?n majd kezelem */
               --               nit_operations_p.fail_operation(p_rec.opn_id);
               nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                        ,dbms_utility.format_call_stack
                                        ,dbms_utility.format_error_stack
                                        ,'Y'
                                        ,pl_module
                                        ,pl_version
                                        ,pl_subprg_name
                                        ,'#' || p_rec.id);
               RAISE;
         END psn_check;
      END IF;

      p_ind.last_update_date := TRUE;
      p_ind.last_updated_by  := TRUE;
      p_ind.status           := TRUE;
      p_ind.obsolete         := TRUE;
      p_ind.valid_from       := TRUE;
      p_ind.valid_until      := TRUE;


      IF (p_op = 'UPD') THEN
         IF (ci_rec.obsolete <> 'L' OR p_rec.obsolete <> 'L') THEN
            nit_error_p.error('NIT-00017'
                             ,'E'
                             ,TRUE
                             ,ci_rec.NAME
                             ,cit_rec.NAME
                             ,ci_rec.obsolete
                             ,p_rec.obsolete);
         END IF;
      END IF;


      cit_rec.id := ci_rec.cit_id;
      cg$nit_ci_types.slct(cit_rec);
      nit_core_p.set_audit(p_rec.creation_date
                          ,p_rec.created_by
                          ,p_rec.last_update_date
                          ,p_rec.last_updated_by
                          ,p_op);

      -- Ha a CI rakt?ron van..
      IF (ci_rec.status = nit_core_p.ci_statuses(nit_core_p.ci_in_stock_idx) AND
         p_rec.lcn_id <> r_stock_id AND cit_rec.could_in_stock = 'Y') THEN
         p_rec.lcn_id := r_stock_id;
      END IF;

      IF (cit_rec.could_in_stock = 'N' AND p_rec.lcn_id = r_stock_id) THEN
         nit_error_p.error('NIT-00019'
                          ,'E'
                          ,TRUE
                          ,ci_rec.NAME
                          ,cit_rec.NAME
                          ,ci_rec.obsolete
                          ,p_rec.obsolete);
      END IF;

      -- Ha a CI nincs rakt?ron ?s nem is haszn?lj?k, akkor tervezget?nk, tesztelget?nk...?gy a POS az 'virtual'
      -- FIXME: Ez nem biztos, hogy korrekt BL szab?ly, lehet, hogy pont azt akarjuk tesztelni, hogy ott,
      -- azon a POS-on ok-e a CI vagy ilyesmi... egyenl?re nem ?rtam meg...

      -- Egy CI csak akkor lehet mutable helyen, ha haszn?lj?k is.
      IF (p_rec.lcn_id = r_muta_id AND
         ci_rec.status <> nit_core_p.ci_statuses(nit_core_p.ci_in_use_idx)) THEN
         nit_error_p.error('NIT-00020'
                          ,'E'
                          ,TRUE
                          ,NULL
                          ,NULL
                          ,NULL
                          ,p_rec.id);
      END IF;

      /* Orb?n Tam?s: fel lehet-e vinni CI-t eol st?tusszal? Jelenleg igen, ehhez pedig
      fel kell vinnem a poz?ci?t, ha eddig m?g nem volt... */

      IF (ci_rec.status = nit_core_p.ci_statuses(nit_core_p.ci_eol_idx)) THEN
         <<position_lookup>>
         BEGIN
            SELECT 'X'
            INTO   v_has_position
            FROM   nit_positions psn
            WHERE  psn.ci_id = p_rec.ci_id;

         EXCEPTION
            WHEN no_data_found THEN
               NULL;
            WHEN too_many_rows THEN
               v_has_position := 'X';
            WHEN OTHERS THEN
               RAISE;
         END position_lookup;

         IF (v_has_position = 'X') THEN
            nit_error_p.error('NIT-00048'
                             ,'E'
                             ,TRUE
                             ,ci_rec.NAME
                             ,ci_rec.status
                             ,NULL
                             ,NULL);
         END IF;
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         /* Orb?n Tam?s: ezt ?n majd kezelem */
         --         nit_operations_p.fail_operation(p_rec.opn_id);
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;

   END;

   PROCEDURE cascade_upd(p_rec IN OUT cg$nit_positions.cg$row_type
                        ,p_ind IN OUT cg$nit_positions.cg$ind_type) IS
      pl_subprg_name VARCHAR2(30) := 'cascade_upd';
      pos_rec        cg$nit_positions.cg$row_type;
      ci_rec         nit_config_items%ROWTYPE;

      CURSOR cur_contained IS
         SELECT id
         FROM   nit_positions pos
         WHERE  pos.obsolete = 'L' AND
                pos.ci_id IN (SELECT cir.ci_id_to
                              FROM   nit_ci_relations       cir
                                    ,nit_cit_relation_types citrt
                                    ,nit_ci_type_relations  citr
                              WHERE  citrt.id = citr.citrt_id AND
                                     citrt.NAME =
                                     nit_cit_relation_types_p.get_contains_rel_name AND
                                     cir.ci_id_from = p_rec.ci_id AND
                                     cir.obsolete = 'L'
                              -- Ide m?g lehet kell st?tuszra is sz?rni, de nem biztos, v?gig kell m?g gondolni. FIXME
                              );

      CURSOR cur_installed_on IS
         SELECT id
         FROM   nit_positions pos
         WHERE  pos.obsolete = 'L' AND
                pos.ci_id IN (SELECT cir.ci_id_from
                              FROM   nit_ci_relations       cir
                                    ,nit_cit_relation_types citrt
                                    ,nit_ci_type_relations  citr
                              WHERE  citrt.id = citr.citrt_id AND
                                     citrt.NAME =
                                     nit_cit_relation_types_p.get_installed_on_rel_name AND
                                     cir.ci_id_to = p_rec.ci_id AND
                                     cir.obsolete = 'L'
                              -- Ide m?g lehet kell st?tuszra is sz?rni, de nem biztos, v?gig kell m?g gondolni. FIXME
                              );

   BEGIN
      SELECT *
      INTO   ci_rec
      FROM   nit_config_items ci
      WHERE  ci.obsolete = 'L' AND
             ci.id = p_rec.ci_id;

      FOR cur_rec IN cur_contained LOOP
         pos_rec.id        := cur_rec.id;
         pos_rec.the_rowid := NULL;
         cg$nit_positions.slct(pos_rec);
         pos_rec.opn_id := p_rec.opn_id;
         pos_rec.lcn_id := p_rec.lcn_id;
         cg$nit_positions.upd(pos_rec
                             ,p_ind);
      END LOOP;

      FOR cur_rec IN cur_installed_on LOOP
         pos_rec.id        := cur_rec.id;
         pos_rec.the_rowid := NULL;
         cg$nit_positions.slct(pos_rec);
         pos_rec.opn_id := p_rec.opn_id;
         pos_rec.lcn_id := p_rec.lcn_id;
         cg$nit_positions.upd(pos_rec
                             ,p_ind);
      END LOOP;

   EXCEPTION
      WHEN OTHERS THEN
         /* Orb?n Tam?s: ezt ?n majd kezelem */
         --         nit_operations_p.fail_operation(p_rec.opn_id);
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;

   PROCEDURE pre_upd(p_rec IN OUT cg$nit_positions.cg$row_type
                    ,p_ind IN OUT cg$nit_positions.cg$ind_type) IS
      l_old_rec      cg$nit_positions.cg$row_type;
      opn_rec        cg$nit_operations.cg$row_type;
      pl_subprg_name VARCHAR2(30) := 'pre_upd';
   BEGIN
      l_old_rec.id := p_rec.id;
      cg$nit_positions.slct(l_old_rec);

      opn_rec.id := p_rec.opn_id;
      cg$nit_operations.slct(opn_rec);

      IF (l_old_rec.obsolete <> 'L') THEN
         nit_error_p.error('NIT-00032'
                          ,'E'
                          ,TRUE
                          ,NULL
                          ,NULL
                          ,NULL
                          ,p_rec.id);
      END IF;

      IF (nit_core_p.is_allowed_obsolete_chg(l_old_rec.obsolete
                                            ,p_rec.obsolete) = 'N') THEN
         nit_error_p.error('NIT-00022'
                          ,'E'
                          ,TRUE
                          ,l_old_rec.obsolete
                          ,p_rec.obsolete
                          ,NULL
                          ,p_rec.id);
      END IF;

      -- Ideiglenesen kiszedve, mindig done
      /*      IF (opn_rec.type_name =
               nit_operations_p.operation_types(nit_operations_p.requested_idx) AND
               nit_core_p.is_allowed_ci_props_status_chg(l_old_rec.status
                                                         ,p_rec.status) = 'N') THEN
               nit_error_p.error('NIT-00023'
                                ,'E'
                                ,TRUE
                                ,l_old_rec.status
                                ,p_rec.status
                                ,NULL
                                ,p_rec.id);
            END IF;
      */
      IF (p_rec.obsolete = 'D') THEN
         nit_error_p.error('NIT-00021'
                          ,'E'
                          ,TRUE
                          ,NULL
                          ,NULL
                          ,NULL
                          ,p_rec.id);
      END IF;

      archiving(p_rec
               ,l_old_rec);

      p_ind.opn_id     := FALSE;
      p_ind.valid_from := TRUE;
      IF (p_rec.obsolete = 'L') THEN
         p_ind.ci_id := FALSE;
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         /* Orb?n Tam?s: ezt ?n majd kezelem */
         --         nit_operations_p.fail_operation(p_rec.opn_id);
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;
BEGIN
   nit_card_p.log(pl_module
                 ,pl_version);
END nit_positions_p;
/

prompt
prompt Creating package body NIT_USERS_P
prompt =================================
prompt
CREATE OR REPLACE PACKAGE BODY nit_users_p IS
   pl_version CONSTANT VARCHAR2(12) := '0.0.2.4';
   pl_module  CONSTANT VARCHAR2(30) := 'nit_users_p';

   ---------------------------------------------------------------------------------------------------------------------------------------

   PROCEDURE send_mail(p_id      IN nit_users.id%TYPE
                      ,p_subject IN VARCHAR2
                      ,p_message IN VARCHAR2) IS
      usr_email      nit_users.email%TYPE;
      pl_subprg_name VARCHAR2(30) := 'send_mail';
   BEGIN
      SELECT email
      INTO   usr_email
      FROM   nit_users usr
      WHERE  usr.id = p_id;
      nit_core_p.send_mail(usr_email
                          ,p_subject
                          ,p_message);

   EXCEPTION
      WHEN no_data_found THEN
         NULL;
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;
   END;
   ---------------------------------------------------------------------------------------------------------------------------------------

   FUNCTION is_deletable(p_id IN nit_users.id%TYPE) RETURN CHAR IS
   BEGIN
      IF (p_id IS NULL) THEN
         RETURN 'N';
      ELSE
         RETURN 'Y';
      END IF;
   END;

   ---------------------------------------------------------------------------------------------------------------------------------------

   FUNCTION package_version RETURN VARCHAR2 IS
   BEGIN
      RETURN pl_module || ' ' || pl_version;
   END;
   ---------------------------------------------------------------------------------------------------------------------------------------

   PROCEDURE pre_dml(p_rec IN OUT cg$nit_users.cg$row_type
                    ,p_ind IN OUT cg$nit_users.cg$ind_type
                    ,p_op  IN VARCHAR2) IS
      pl_subprg_name VARCHAR2(30) := 'pre_dml';
   BEGIN

      p_rec.username := upper(p_rec.username);
      nit_core_p.caseconv(p_rec.realname);
      nit_core_p.caseconv(p_rec.email);

      IF (p_op = 'INS') THEN
         p_ind.id            := TRUE;
         p_ind.creation_date := TRUE;
         p_ind.created_by    := TRUE;
      END IF;

      IF (p_op = 'INS' OR p_op = 'UPD') THEN
         p_ind.last_update_date := TRUE;
         p_ind.last_updated_by  := TRUE;
         p_ind.LANGUAGE         := TRUE;
         nit_core_p.set_audit(p_rec.creation_date
                             ,p_rec.created_by
                             ,p_rec.last_update_date
                             ,p_rec.last_updated_by
                             ,p_op);
      END IF;

      IF (p_rec.LANGUAGE IS NULL) THEN
         p_rec.LANGUAGE := 'US';
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;

   END;

   ---------------------------------------------------------------------------------------------------------------------------------------
   PROCEDURE post_ins(p_rec IN OUT cg$nit_users.cg$row_type
                     ,p_ind IN OUT cg$nit_users.cg$ind_type) IS
      pl_subprg_name VARCHAR2(30) := 'post_ins';
   BEGIN
      nit_users_p.send_mail(p_rec.id
                           ,'Welcome to NIT'
                           ,'Dear ' || p_rec.realname || '!' || greeting_msg);
   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_rec.id);
         RAISE;
   END;

   PROCEDURE pre_del(p_id IN nit_users.id%TYPE) IS
      pl_subprg_name VARCHAR2(30) := 'pre_del';
   BEGIN
      IF (nit_users_p.is_deletable(p_id) <> 'Y') THEN
         nit_error_p.error('NIT-00001'
                          ,'E'
                          ,TRUE
                          ,NULL
                          ,NULL
                          ,NULL
                          ,p_id);
      END IF;

   EXCEPTION
      WHEN OTHERS THEN
         nit_error_p.log_exception(NULL -- dbms_utility.format_error_backtrace
                                  ,dbms_utility.format_call_stack
                                  ,dbms_utility.format_error_stack
                                  ,'Y'
                                  ,pl_module
                                  ,pl_version
                                  ,pl_subprg_name
                                  ,'#' || p_id);
         RAISE;

   END;


BEGIN
   nit_card_p.log(pl_module
                 ,pl_version);
END nit_users_p;
/

