if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Update_MigCompSummary]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Update_MigCompSummary]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Write_to_file]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Write_to_file]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_CreateDefaultMappings]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_CreateDefaultMappings]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_CreateDefaultMappingsForFineTunedTables]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_CreateDefaultMappingsForFineTunedTables]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_CreateMappingForChangedTables]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_CreateMappingForChangedTables]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_CreateMappingForUnchangedTables]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_CreateMappingForUnchangedTables]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_CreateMappingsForFineTunedChangedTables]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_CreateMappingsForFineTunedChangedTables]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_LegacyCreateDefaultMappings]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_LegacyCreateDefaultMappings]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_LegacyCreateMappingForChangedTables]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_LegacyCreateMappingForChangedTables]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_LegacyCreateMappingForUnchangedTables]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_LegacyCreateMappingForUnchangedTables]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_insert_bcddc000_1]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_insert_bcddc000_1]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_insert_bcmap110_1]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_insert_bcmap110_1]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_insert_bcmap120_1]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_insert_bcmap120_1]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_insert_bcmap125_1]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_insert_bcmap125_1]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_insert_bcmap130_1]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_insert_bcmap130_1]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_insert_bcmap135_1]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_insert_bcmap135_1]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_insert_bcmap140_1]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_insert_bcmap140_1]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_insert_bcmap145_1]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_insert_bcmap145_1]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_update_bcddc000_1]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_update_bcddc000_1]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[testtext]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[testtext]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcddc000]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcddc000]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcddc100]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcddc100]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcddc140]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcddc140]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcddc141]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcddc141]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcddc150]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcddc150]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcddc151]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcddc151]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcddc160]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcddc160]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcddc200]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcddc200]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcddc220]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcddc220]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcddc230]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcddc230]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcddi100]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcddi100]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcddi101]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcddi101]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcddi140]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcddi140]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcddi150]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcddi150]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcddi160]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcddi160]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcddi200]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcddi200]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcddi220]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcddi220]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcddi230]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcddi230]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcdoc100]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcdoc100]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcdoc101]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcdoc101]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcdoc102]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcdoc102]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcldc140]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcldc140]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcldc141]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcldc141]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcldc150]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcldc150]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcldc151]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcldc151]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bclgy115]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bclgy115]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bclgy140]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bclgy140]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bclgy141]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bclgy141]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bclgy150]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bclgy150]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bclgy400]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bclgy400]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bclgy401]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bclgy401]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bclib100]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bclib100]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bclib105]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bclib105]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcmap100]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcmap100]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcmap101]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcmap101]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcmap102]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcmap102]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcmap105]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcmap105]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcmap110]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcmap110]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcmap120]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcmap120]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcmap125]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcmap125]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcmap130]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcmap130]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcmap135]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcmap135]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcmap140]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcmap140]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcmap145]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcmap145]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcmap150]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcmap150]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcmap160]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcmap160]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcmap165]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcmap165]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcmap170]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcmap170]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcmap175]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcmap175]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcmap200]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcmap200]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcmap205]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcmap205]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcmap210]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcmap210]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcmap300]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcmap300]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcmap400]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcmap400]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcmpc100]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcmpc100]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcmpc110]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcmpc110]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcmpc150]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcmpc150]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bctmp000]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bctmp000]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bctmp001]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bctmp001]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcusr100]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcusr100]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bcusr110]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bcusr110]
GO

CREATE TABLE [dbo].[bcddc000] (
	[runn] [numeric](10, 5) NOT NULL ,
	[cpac] [varchar] (2) COLLATE Latin1_General_BIN NULL ,
	[cmod] [varchar] (3) COLLATE Latin1_General_BIN NULL ,
	[flno] [varchar] (60) COLLATE Latin1_General_BIN NULL ,
	[sdat] [datetime] NULL ,
	[tdat] [datetime] NULL ,
	[type] [varchar] (1) COLLATE Latin1_General_BIN NOT NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcddc100] (
	[runn] [numeric](10, 5) NOT NULL ,
	[spln] [varchar] (15) COLLATE Latin1_General_BIN NOT NULL ,
	[tpln] [varchar] (15) COLLATE Latin1_General_BIN NOT NULL ,
	[sdat] [datetime] NOT NULL ,
	[edat] [datetime] NULL ,
	[stat] [varchar] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[fdno] [bit] NULL ,
	[comb] [bit] NULL ,
	[refm] [bit] NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcddc140] (
	[runn] [numeric](10, 5) NOT NULL ,
	[ctyp] [varchar] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[cpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[flno] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcddc141] (
	[runn] [numeric](10, 5) NOT NULL ,
	[spac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[smod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[slno] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[tpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[tmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[tlno] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcddc150] (
	[runn] [numeric](10, 5) NOT NULL ,
	[ctyp] [varchar] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[cpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[flno] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[fdnm] [varchar] (8) COLLATE Latin1_General_BIN NOT NULL ,
	[tpac] [varchar] (2) COLLATE Latin1_General_BIN NULL ,
	[tmod] [varchar] (3) COLLATE Latin1_General_BIN NULL ,
	[tlno] [varchar] (3) COLLATE Latin1_General_BIN NULL ,
	[tdnm] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[sfdn] [int] NULL ,
	[tfdn] [int] NULL ,
	[scom] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[tcom] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[sddo] [varchar] (14) COLLATE Latin1_General_BIN NULL ,
	[tddo] [varchar] (14) COLLATE Latin1_General_BIN NULL ,
	[sdep] [int] NULL ,
	[tdep] [int] NULL ,
	[sman] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[tman] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[sini] [nvarchar] (30) COLLATE Latin1_General_BIN NULL ,
	[tini] [nvarchar] (30) COLLATE Latin1_General_BIN NULL ,
	[srff] [varchar] (17) COLLATE Latin1_General_BIN NULL ,
	[trff] [varchar] (17) COLLATE Latin1_General_BIN NULL ,
	[srem] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[trem] [varchar] (1) COLLATE Latin1_General_BIN NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcddc151] (
	[runn] [numeric](10, 5) NOT NULL ,
	[ctyp] [varchar] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[cpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[flno] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[fdnm] [varchar] (8) COLLATE Latin1_General_BIN NOT NULL ,
	[tpac] [varchar] (2) COLLATE Latin1_General_BIN NULL ,
	[tmod] [varchar] (3) COLLATE Latin1_General_BIN NULL ,
	[tlno] [varchar] (3) COLLATE Latin1_General_BIN NULL ,
	[tdnm] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[sfdn] [int] NULL ,
	[tfdn] [int] NULL ,
	[scom] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[tcom] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[sddo] [varchar] (14) COLLATE Latin1_General_BIN NULL ,
	[tddo] [varchar] (14) COLLATE Latin1_General_BIN NULL ,
	[sdep] [int] NULL ,
	[tdep] [int] NULL ,
	[sman] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[tman] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[sini] [nvarchar] (30) COLLATE Latin1_General_BIN NULL ,
	[tini] [nvarchar] (30) COLLATE Latin1_General_BIN NULL ,
	[srff] [varchar] (17) COLLATE Latin1_General_BIN NULL ,
	[trff] [varchar] (17) COLLATE Latin1_General_BIN NULL ,
	[srem] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[trem] [varchar] (1) COLLATE Latin1_General_BIN NULL
) ON [PRIMARY]
GO


CREATE TABLE [dbo].[bcddc160] (
	[runn] [numeric](10, 5) NOT NULL ,
	[ctyp] [varchar] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[cpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[flno] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[fdnm] [varchar] (8) COLLATE Latin1_General_BIN NOT NULL ,
	[sern] [int] NOT NULL ,
	[schl] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[tchl] [varchar] (8) COLLATE Latin1_General_BIN NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcddc200] (
	[runn] [numeric](10, 5) NOT NULL ,
	[ctyp] [varchar] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[cpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[flno] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[indn] [int] NOT NULL ,
	[sact] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[tact] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[sdup] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[tdup] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[sp01] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[tp01] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[sp02] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[tp02] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[sp03] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[tp03] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[sp04] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[tp04] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[sp05] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[tp05] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[sp06] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[tp06] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[sp07] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[tp07] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[sp08] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[tp08] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[sp09] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[tp09] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[sp10] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[tp10] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[sp11] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[tp11] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[sp12] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[tp12] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[sp13] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[tp13] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[sp14] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[tp14] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[sp15] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[tp15] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[sp16] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[tp16] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[sp17] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[tp17] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[sp18] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[tp18] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[sp19] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[tp19] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[sp20] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[tp20] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[sp21] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[tp21] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[sp22] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[tp22] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[sp23] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[tp23] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[sp24] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[tp24] [varchar] (8) COLLATE Latin1_General_BIN NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcddc220] (
	[runn] [numeric](10, 5) NOT NULL ,
	[ctyp] [varchar] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[cpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cdom] [varchar] (12) COLLATE Latin1_General_BIN NOT NULL ,
	[styp] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[ttyp] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[slng] [int] NULL ,
	[tlng] [int] NULL ,
	[slga] [nvarchar] (30) COLLATE Latin1_General_BIN NULL ,
	[tlga] [nvarchar] (30) COLLATE Latin1_General_BIN NULL ,
	[sill] [nvarchar] (30) COLLATE Latin1_General_BIN NULL ,
	[till] [nvarchar] (30) COLLATE Latin1_General_BIN NULL ,
	[scon] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[tcon] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[sadj] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[tadj] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[srng] [nvarchar] (100) COLLATE Latin1_General_BIN NULL ,
	[trng] [nvarchar] (100) COLLATE Latin1_General_BIN NULL ,
	[sdiv] [int] NULL ,
	[tdiv] [int] NULL ,
	[srnd] [int] NULL ,
	[trnd] [int] NULL ,
	[sdgb] [int] NULL ,
	[tdgb] [int] NULL ,
	[sdga] [int] NULL ,
	[tdga] [int] NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcddc230] (
	[runn] [numeric](10, 5) NOT NULL ,
	[ctyp] [varchar] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[cpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cdom] [varchar] (12) COLLATE Latin1_General_BIN NOT NULL ,
	[ctnm] [varchar] (15) COLLATE Latin1_General_BIN NOT NULL ,
	[scnt] [int] NULL ,
	[tcnt] [int] NULL ,
	[sdes] [nvarchar] (40) COLLATE Latin1_General_BIN NULL ,
	[tdes] [nvarchar] (40) COLLATE Latin1_General_BIN NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcddi100] (
	[appl] [varchar] (15) COLLATE Latin1_General_BIN NOT NULL ,
	[dsca] [varchar] (100) COLLATE Latin1_General_BIN NULL ,
	[idat] [datetime] NULL ,
	[srvr] [varchar] (15) COLLATE Latin1_General_BIN NULL ,
	[rdir] [text] COLLATE Latin1_General_BIN NULL ,
	[extn] [int] NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcddi101] (
	[appl] [varchar] (15) COLLATE Latin1_General_BIN NOT NULL ,
	[sour] [varchar] (200) COLLATE Latin1_General_BIN NULL ,
	[logn] [varchar] (12) COLLATE Latin1_General_BIN NULL ,
	[pswd] [varchar] (30) COLLATE Latin1_General_BIN NULL ,
	[diry] [varchar] (255) COLLATE Latin1_General_BIN NOT NULL ,
	[ftyp] [varchar] (10) COLLATE Latin1_General_BIN NOT NULL ,
	[sepr] [varchar] (10) COLLATE Latin1_General_BIN NULL ,
	[fixd] [int] NOT NULL ,
	[tqul] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[tcol] [int] NOT NULL ,
	[cnul] [int] NOT NULL ,
	[nskp] [int] NOT NULL ,
	[rsep] [varchar] (8) COLLATE Latin1_General_BIN NOT NULL ,
	[dscn] [int] NOT NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcddi140] (
	[appl] [varchar] (15) COLLATE Latin1_General_BIN NOT NULL ,
	[cpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[flno] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcddi150] (
	[appl] [varchar] (15) COLLATE Latin1_General_BIN NOT NULL ,
	[cpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[flno] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[fdnm] [varchar] (8) COLLATE Latin1_General_BIN NOT NULL ,
	[fdno] [int] NOT NULL ,
	[comb] [varchar] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[cdom] [varchar] (14) COLLATE Latin1_General_BIN NULL ,
	[dept] [int] NOT NULL ,
	[mand] [varchar] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[iniv] [nvarchar] (30) COLLATE Latin1_General_BIN NULL ,
	[rffd] [varchar] (17) COLLATE Latin1_General_BIN NULL ,
	[refm] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[dsca] [varchar] (150) COLLATE Latin1_General_BIN NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcddi160] (
	[appl] [varchar] (15) COLLATE Latin1_General_BIN NOT NULL ,
	[cpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[flno] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[fdnm] [varchar] (8) COLLATE Latin1_General_BIN NOT NULL ,
	[sern] [int] NOT NULL ,
	[chld] [varchar] (8) COLLATE Latin1_General_BIN NOT NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcddi200] (
	[appl] [varchar] (15) COLLATE Latin1_General_BIN NOT NULL ,
	[cpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[flno] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[indn] [int] NOT NULL ,
	[acti] [varchar] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[dupl] [varchar] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[pt01] [varchar] (8) COLLATE Latin1_General_BIN NOT NULL ,
	[pt02] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[pt03] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[pt04] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[pt05] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[pt06] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[pt07] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[pt08] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[pt09] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[pt10] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[pt11] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[pt12] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[pt13] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[pt14] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[pt15] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[pt16] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[pt17] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[pt18] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[pt19] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[pt20] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[pt21] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[pt22] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[pt23] [varchar] (8) COLLATE Latin1_General_BIN NULL ,
	[pt24] [varchar] (8) COLLATE Latin1_General_BIN NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcddi220] (
	[appl] [varchar] (15) COLLATE Latin1_General_BIN NOT NULL ,
	[cpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cdom] [varchar] (12) COLLATE Latin1_General_BIN NOT NULL ,
	[type] [varchar] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[leng] [int] NULL ,
	[lene] [int] NULL ,
	[lega] [nvarchar] (30) COLLATE Latin1_General_BIN NULL ,
	[ille] [nvarchar] (30) COLLATE Latin1_General_BIN NULL ,
	[conv] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[adju] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[rang] [nvarchar] (100) COLLATE Latin1_General_BIN NULL ,
	[divf] [int] NULL ,
	[rndm] [int] NULL ,
	[digb] [int] NULL ,
	[diga] [int] NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcddi230] (
	[appl] [varchar] (15) COLLATE Latin1_General_BIN NOT NULL ,
	[cpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cdom] [varchar] (12) COLLATE Latin1_General_BIN NOT NULL ,
	[ctnm] [varchar] (15) COLLATE Latin1_General_BIN NOT NULL ,
	[cnst] [int] NOT NULL ,
	[edes] [nvarchar] (40) COLLATE Latin1_General_BIN NOT NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcdoc100] (
	[tpid] [varchar] (10) COLLATE Latin1_General_BIN NOT NULL ,
	[dsca] [varchar] (50) COLLATE Latin1_General_BIN NULL ,
	[txtn] [varchar] (2000) COLLATE Latin1_General_BIN NULL ,
	[dtcr] [datetime] NOT NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcdoc101] (
	[docid] [numeric](18, 0) NOT NULL ,
	[dsca] [varchar] (1000) COLLATE Latin1_General_BIN NOT NULL ,
	[dnam] [varchar] (255) COLLATE Latin1_General_BIN NULL ,
	[dcfl] [image] NULL ,
	[dtcr] [datetime] NULL ,
	[dtyp] [numeric](18, 0) NULL ,
	[usrn] [varchar] (50) COLLATE Latin1_General_BIN NULL ,
	[dknd] [numeric](18, 0) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcdoc102] (
	[tpid] [varchar] (10) COLLATE Latin1_General_BIN NOT NULL ,
	[mprf] [numeric](18, 0) NOT NULL ,
	[docid] [numeric](18, 0) NOT NULL ,
	[note] [varchar] (2000) COLLATE Latin1_General_BIN NULL ,
	[dtcr] [datetime] NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcldc140] (
	[runn] [numeric](10, 5) NOT NULL ,
	[ctyp] [char] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[cpac] [char] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cmod] [char] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[flno] [varchar] (60) COLLATE Latin1_General_BIN NOT NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcldc141] (
	[runn] [numeric](18, 0) NOT NULL ,
	[ctyp] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[cpac] [char] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cmod] [char] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[flno] [varchar] (60) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[sdsc] [varchar] (60) COLLATE Latin1_General_BIN NULL ,
	[tdsc] [varchar] (60) COLLATE Latin1_General_BIN NULL ,
	[styp] [varchar] (10) COLLATE Latin1_General_BIN NOT NULL ,
	[ttyp] [varchar] (10) COLLATE Latin1_General_BIN NOT NULL ,
	[sspr] [varchar] (10) COLLATE Latin1_General_BIN NULL ,
	[tspr] [varchar] (50) COLLATE Latin1_General_BIN NULL ,
	[sfmt] [bit] NOT NULL ,
	[tfmt] [bit] NOT NULL ,
	[squl] [char] (1) COLLATE Latin1_General_BIN NULL ,
	[tqul] [char] (1) COLLATE Latin1_General_BIN NULL ,
	[scol] [bit] NOT NULL ,
	[tcol] [bit] NOT NULL ,
	[snul] [bit] NOT NULL ,
	[tnul] [bit] NOT NULL ,
	[sskp] [int] NOT NULL ,
	[tskp] [int] NOT NULL ,
	[srsp] [varchar] (8) COLLATE Latin1_General_BIN NOT NULL ,
	[trsp] [varchar] (8) COLLATE Latin1_General_BIN NOT NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcldc150] (
	[runn] [numeric](10, 5) NOT NULL ,
	[ctyp] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[cpac] [char] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cmod] [char] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[flno] [varchar] (60) COLLATE Latin1_General_BIN NOT NULL ,
	[fdnm] [varchar] (60) COLLATE Latin1_General_BIN NOT NULL ,
	[sseq] [int] NULL ,
	[tseq] [int] NULL ,
	[sdsc] [varchar] (60) COLLATE Latin1_General_BIN NULL ,
	[tdsc] [varchar] (60) COLLATE Latin1_General_BIN NULL ,
	[styp] [char] (1) COLLATE Latin1_General_BIN NULL ,
	[ttyp] [char] (1) COLLATE Latin1_General_BIN NULL ,
	[srdl] [int] NULL ,
	[trdl] [int] NULL ,
	[sspn] [int] NULL ,
	[tspn] [int] NULL ,
	[sepn] [int] NULL ,
	[tepn] [int] NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcldc151] (
	[runn] [numeric](10, 5) NOT NULL ,
	[ctyp] [varchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[cpac] [varchar] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[cmod] [varchar] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[flno] [varchar] (60) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[fdnm] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[ssps] [int] NOT NULL ,
	[tsps] [int] NOT NULL ,
	[seps] [int] NOT NULL ,
	[teps] [int] NOT NULL ,
	[sfdn] [int] NULL ,
	[tfdn] [int] NULL ,
	[scom] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[tcom] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[sddo] [varchar] (14) COLLATE Latin1_General_BIN NULL ,
	[tddo] [varchar] (14) COLLATE Latin1_General_BIN NULL ,
	[sdep] [int] NULL ,
	[tdep] [int] NULL ,
	[sman] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[tman] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[sini] [nvarchar] (30) COLLATE Latin1_General_BIN NULL ,
	[tini] [nvarchar] (30) COLLATE Latin1_General_BIN NULL ,
	[srff] [varchar] (17) COLLATE Latin1_General_BIN NULL ,
	[trff] [varchar] (17) COLLATE Latin1_General_BIN NULL ,
	[srem] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[trem] [varchar] (1) COLLATE Latin1_General_BIN NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bclgy115] (
	[code] [varchar] (5) COLLATE Latin1_General_BIN NOT NULL ,
	[dsca] [varchar] (30) COLLATE Latin1_General_BIN NULL ,
	[ival] [varchar] (30) COLLATE Latin1_General_BIN NOT NULL ,
	[oval] [varchar] (30) COLLATE Latin1_General_BIN NOT NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bclgy140] (
	[appl] [varchar] (15) COLLATE Latin1_General_BIN NOT NULL ,
	[cpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[flno] [varchar] (60) COLLATE Latin1_General_BIN NOT NULL ,
	[dsca] [varchar] (120) COLLATE Latin1_General_BIN NULL ,
	[sour] [varchar] (200) COLLATE Latin1_General_BIN NOT NULL ,
	[logn] [varchar] (12) COLLATE Latin1_General_BIN NULL ,
	[pswd] [varchar] (30) COLLATE Latin1_General_BIN NULL ,
	[qury] [text] COLLATE Latin1_General_BIN NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[bclgy141] (
	[appl] [varchar] (15) COLLATE Latin1_General_BIN NOT NULL ,
	[cpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[flno] [varchar] (60) COLLATE Latin1_General_BIN NOT NULL ,
	[dsca] [varchar] (120) COLLATE Latin1_General_BIN NULL ,
	[diry] [varchar] (255) COLLATE Latin1_General_BIN NOT NULL ,
	[ftyp] [varchar] (10) COLLATE Latin1_General_BIN NOT NULL ,
	[sepr] [varchar] (10) COLLATE Latin1_General_BIN NULL ,
	[fixd] [int] NOT NULL ,
	[tqul] [varchar] (1) COLLATE Latin1_General_BIN NULL ,
	[tcol] [int] NOT NULL ,
	[cnul] [int] NOT NULL ,
	[nskp] [int] NOT NULL ,
	[rsep] [varchar] (8) COLLATE Latin1_General_BIN NOT NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bclgy150] (
	[appl] [varchar] (15) COLLATE Latin1_General_BIN NOT NULL ,
	[cpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[flno] [varchar] (60) COLLATE Latin1_General_BIN NOT NULL ,
	[seqn] [int] NOT NULL ,
	[flna] [varchar] (60) COLLATE Latin1_General_BIN NOT NULL ,
	[dsca] [varchar] (120) COLLATE Latin1_General_BIN NULL ,
	[dtyp] [varchar] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[nrdl] [int] NULL ,
	[spos] [int] NULL ,
	[epos] [int] NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bclgy400] (
	[btno] [numeric](18, 0) NOT NULL ,
	[mprf] [int] NOT NULL ,
	[Dtbs] [int] NOT NULL ,
	[cpno] [char] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[cnst] [varchar] (1000) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bclgy401] (
	[btno] [numeric](18, 0) NOT NULL ,
	[tbnm] [varchar] (8) COLLATE Latin1_General_BIN NOT NULL ,
	[stat] [int] NOT NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bclib100] (
	[mprf] [int] NOT NULL ,
	[vers] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[rele] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cust] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[fnam] [varchar] (12) COLLATE Latin1_General_BIN NOT NULL ,
	[dsca] [varchar] (60) COLLATE Latin1_General_BIN NULL ,
	[lurn] [varchar] (12) COLLATE Latin1_General_BIN NOT NULL ,
	[ldat] [datetime] NOT NULL ,
	[fdef] [text] COLLATE Latin1_General_BIN NULL ,
	[curn] [varchar] (12) COLLATE Latin1_General_BIN NULL ,
	[stat] [char] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[comt] [text] COLLATE Latin1_General_BIN NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[bclib105] (
	[mprf] [int] NOT NULL ,
	[vers] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[rele] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cust] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[fnam] [varchar] (12) COLLATE Latin1_General_BIN NOT NULL ,
	[revi] [int] NOT NULL ,
	[rinf] [text] COLLATE Latin1_General_BIN NULL ,
	[isid] [varchar] (50) COLLATE Latin1_General_BIN NOT NULL ,
	[cdat] [datetime] NOT NULL ,
	[pexp] [bit] NOT NULL ,
	[usrn] [varchar] (12) COLLATE Latin1_General_BIN NOT NULL ,
	[fdef] [text] COLLATE Latin1_General_BIN NOT NULL ,
	[comt] [text] COLLATE Latin1_General_BIN NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcmap100] (
	[mprf] [int] NOT NULL ,
	[sapp] [varchar] (15) COLLATE Latin1_General_BIN NOT NULL ,
	[tapp] [varchar] (15) COLLATE Latin1_General_BIN NOT NULL ,
	[vers] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[rele] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cust] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[verf] [varchar] (4) COLLATE Latin1_General_BIN NULL ,
	[relf] [varchar] (2) COLLATE Latin1_General_BIN NULL ,
	[cusf] [varchar] (4) COLLATE Latin1_General_BIN NULL ,
	[dsca] [varchar] (30) COLLATE Latin1_General_BIN NULL ,
	[scme] [varchar] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[deph] [int] NOT NULL ,
	[ownr] [varbinary] (50) NULL ,
	[bsen] [varchar] (50) COLLATE Latin1_General_BIN NULL ,
	[rhos] [varchar] (50) COLLATE Latin1_General_BIN NULL ,
	[busr] [varchar] (20) COLLATE Latin1_General_BIN NULL ,
	[pswd] [varchar] (50) COLLATE Latin1_General_BIN NULL ,
	[apln] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcmap101] (
	[mprf] [int] NOT NULL ,
	[levl] [int] NOT NULL ,
	[vers] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[rele] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cust] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[pprf] [int] NOT NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcmap102] (
	[mprf] [int] NOT NULL ,
	[pprf] [bit] NULL ,
	[drvr] [varchar] (2) COLLATE Latin1_General_BIN NULL ,
	[qopt] [bit] NULL ,
	[tdso] [varchar] (15) COLLATE Latin1_General_BIN NULL ,
	[cxsd] [bit] NULL ,
	[ccvg] [bit] NULL ,
	[becs] [varchar] (2000) COLLATE Latin1_General_BIN NULL ,
	[host] [varchar] (15) COLLATE Latin1_General_BIN NULL ,
	[logn] [varchar] (12) COLLATE Latin1_General_BIN NULL ,
	[pswd] [varchar] (50) COLLATE Latin1_General_BIN NULL ,
	[bsep] [varchar] (50) COLLATE Latin1_General_BIN NULL ,
	[cmpo] [smallint] NULL ,
	[cmpf] [char] (2) COLLATE Latin1_General_BIN NULL ,
	[bseo] [char] (1) COLLATE Latin1_General_BIN NULL ,
	[isis] [bit] NULL ,
	[sdir] [varchar] (50) COLLATE Latin1_General_BIN NULL ,
	[splb] [bit] NULL ,
	[twgb] [bit] NULL ,
	[ismb] [bit] NULL ,
	[epbo] [int] NULL ,
	[esyn] [bit] NULL ,
	[exrb] [bit] NULL ,
	[isrn] [bit] NULL ,
	[rngf] [varchar] (65) COLLATE Latin1_General_BIN NULL ,
	[rngt] [varchar] (65) COLLATE Latin1_General_BIN NULL ,
	[rngs] [varchar] (2000) COLLATE Latin1_General_BIN NULL ,
	[gxml] [bit] NULL ,
	[gsrt] [bit] NULL ,
	[csrt] [bit] NULL ,
	[srty] [char] (1) COLLATE Latin1_General_BIN NULL
) ON [PRIMARY]
GO


CREATE TABLE [dbo].[bcmap105] (
	[mprf] [int] NOT NULL ,
	[vers] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[rele] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cust] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[dver] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[drel] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[dcus] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcmap110] (
	[mprf] [int] NOT NULL ,
	[vers] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[rele] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cust] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[tcpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[tcmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[tflno] [varchar] (60) COLLATE Latin1_General_BIN NOT NULL ,
	[revi] [int] NOT NULL ,
	[rinf] [text] COLLATE Latin1_General_BIN NULL ,
	[isid] [varchar] (50) COLLATE Latin1_General_BIN NOT NULL ,
	[sdat] [datetime] NOT NULL ,
	[pexp] [int] NOT NULL ,
	[logn] [varchar] (12) COLLATE Latin1_General_BIN NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcmap120] (
	[mprf] [int] NOT NULL ,
	[vers] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[rele] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cust] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[tcpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[tcmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[tflno] [varchar] (60) COLLATE Latin1_General_BIN NOT NULL ,
	[prtx] [text] COLLATE Latin1_General_BIN NULL ,
	[logn] [varchar] (12) COLLATE Latin1_General_BIN NULL ,
	[lusr] [varchar] (12) COLLATE Latin1_General_BIN NULL ,
	[ldat] [datetime] NULL ,
	[stat] [varchar] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[vari] [text] COLLATE Latin1_General_BIN NULL ,
	[comt] [text] COLLATE Latin1_General_BIN NULL ,
	[stbl] [varchar] (4000) COLLATE Latin1_General_BIN NULL ,
	[isms] [bit] NOT NULL ,
	[txtn] [text] COLLATE Latin1_General_BIN NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcmap125] (
	[mprf] [int] NOT NULL ,
	[vers] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[rele] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cust] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[tcpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[tcmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[tflno] [varchar] (60) COLLATE Latin1_General_BIN NOT NULL ,
	[revi] [int] NOT NULL ,
	[prtx] [text] COLLATE Latin1_General_BIN NULL ,
	[logn] [varchar] (12) COLLATE Latin1_General_BIN NOT NULL ,
	[csta] [char] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[vari] [text] COLLATE Latin1_General_BIN NULL ,
	[stbl] [varchar] (4000) COLLATE Latin1_General_BIN NULL ,
	[txtn] [text] COLLATE Latin1_General_BIN NULL ,
	[isms] [bit] NOT NULL ,
	[comt] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcmap130] (
	[mprf] [int] NOT NULL ,
	[vers] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[rele] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cust] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[tcpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[tcmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[tflno] [varchar] (60) COLLATE Latin1_General_BIN NOT NULL ,
	[scpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[scmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[sflno] [varchar] (60) COLLATE Latin1_General_BIN NOT NULL ,
	[icod] [varchar] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[qury] [text] COLLATE Latin1_General_BIN NULL ,
	[txtn] [text] COLLATE Latin1_General_BIN NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcmap135] (
	[mprf] [int] NOT NULL ,
	[vers] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[rele] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cust] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[tcpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[tcmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[tflno] [varchar] (60) COLLATE Latin1_General_BIN NOT NULL ,
	[scpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[scmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[sflno] [varchar] (60) COLLATE Latin1_General_BIN NOT NULL ,
	[icod] [varchar] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[revi] [int] NOT NULL ,
	[qury] [text] COLLATE Latin1_General_BIN NULL ,
	[logn] [varchar] (12) COLLATE Latin1_General_BIN NOT NULL ,
	[csta] [char] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[txtn] [text] COLLATE Latin1_General_BIN NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcmap140] (
	[mprf] [int] NOT NULL ,
	[vers] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[rele] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cust] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[tcpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[tcmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[tflno] [varchar] (60) COLLATE Latin1_General_BIN NOT NULL ,
	[dnum] [int] NOT NULL ,
	[fdnm] [varchar] (60) COLLATE Latin1_General_BIN NOT NULL ,
	[mrul] [text] COLLATE Latin1_General_BIN NULL ,
	[type] [int] NOT NULL ,
	[stat] [varchar] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[txtn] [text] COLLATE Latin1_General_BIN NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcmap145] (
	[mprf] [int] NOT NULL ,
	[vers] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[rele] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cust] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[tcpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[tcmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[tflno] [varchar] (60) COLLATE Latin1_General_BIN NOT NULL ,
	[dnum] [int] NOT NULL ,
	[fdnm] [varchar] (60) COLLATE Latin1_General_BIN NOT NULL ,
	[revi] [int] NOT NULL ,
	[mrul] [text] COLLATE Latin1_General_BIN NULL ,
	[type] [int] NOT NULL ,
	[logn] [varchar] (12) COLLATE Latin1_General_BIN NOT NULL ,
	[stat] [varchar] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[csta] [char] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[txtn] [text] COLLATE Latin1_General_BIN NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcmap150] (
	[func] [varchar] (100) COLLATE Latin1_General_BIN NOT NULL ,
	[defn] [varchar] (4000) COLLATE Latin1_General_BIN NOT NULL ,
	[help] [text] COLLATE Latin1_General_BIN NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcmap160] (
	[mprf] [int] NOT NULL ,
	[vers] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[rele] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cust] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[tcpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[tcmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[tflno] [varchar] (60) COLLATE Latin1_General_BIN NOT NULL ,
	[func] [text] COLLATE Latin1_General_BIN NULL ,
	[txtn] [text] COLLATE Latin1_General_BIN NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcmap165] (
	[mprf] [int] NOT NULL ,
	[vers] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[rele] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cust] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[tcpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[tcmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[tflno] [varchar] (60) COLLATE Latin1_General_BIN NOT NULL ,
	[revi] [int] NOT NULL ,
	[func] [text] COLLATE Latin1_General_BIN NULL ,
	[logn] [varchar] (12) COLLATE Latin1_General_BIN NOT NULL ,
	[csta] [char] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[txtn] [text] COLLATE Latin1_General_BIN NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcmap170] (
	[mprf] [int] NOT NULL ,
	[vers] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[rele] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cust] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[bpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[bmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[bflno] [varchar] (60) COLLATE Latin1_General_BIN NOT NULL ,
	[cpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[cflno] [varchar] (60) COLLATE Latin1_General_BIN NOT NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcmap175] (
	[mprf] [int] NOT NULL ,
	[vers] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[rele] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cust] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[bpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[bmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[bflno] [varchar] (60) COLLATE Latin1_General_BIN NOT NULL ,
	[revi] [int] NOT NULL ,
	[cpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[cflno] [varchar] (30) COLLATE Latin1_General_BIN NOT NULL ,
	[csta] [char] (1) COLLATE Latin1_General_BIN NULL ,
	[logn] [varchar] (12) COLLATE Latin1_General_BIN NOT NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcmap200] (
	[mprf] [int] NOT NULL ,
	[vers] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[rele] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cust] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[txtn] [int] NOT NULL ,
	[key1] [varchar] (20) COLLATE Latin1_General_BIN NULL ,
	[key2] [varchar] (20) COLLATE Latin1_General_BIN NULL ,
	[key3] [varchar] (20) COLLATE Latin1_General_BIN NULL ,
	[text] [text] COLLATE Latin1_General_BIN NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcmap205] (
	[mprf] [int] NOT NULL ,
	[vers] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[rele] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cust] [varchar] (4) COLLATE Latin1_General_BIN NOT NULL ,
	[txtn] [int] NOT NULL ,
	[revi] [int] NOT NULL ,
	[key1] [varchar] (20) COLLATE Latin1_General_BIN NULL ,
	[key2] [varchar] (20) COLLATE Latin1_General_BIN NULL ,
	[key3] [varchar] (20) COLLATE Latin1_General_BIN NULL ,
	[text] [text] COLLATE Latin1_General_BIN NULL ,
	[csta] [char] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[logn] [varchar] (12) COLLATE Latin1_General_BIN NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcmap210] (
	[txno] [bigint] NOT NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcmap300] (
	[ttbl] [char] (36) COLLATE Latin1_General_BIN NOT NULL ,
	[stbl] [char] (36) COLLATE Latin1_General_BIN NOT NULL ,
	[flst] [varchar] (4000) COLLATE Latin1_General_BIN NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcmap400] (
	[mprf] [int] NOT NULL ,
	[cpac] [varchar] (2) COLLATE Latin1_General_BIN NULL ,
	[cmod] [varchar] (3) COLLATE Latin1_General_BIN NULL ,
	[flno] [varchar] (60) COLLATE Latin1_General_BIN NULL ,
	[fldn] [varchar] (30) COLLATE Latin1_General_BIN NULL ,
	[text] [text] COLLATE Latin1_General_BIN NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcmpc100] (
	[mpcr] [int] NOT NULL ,
	[sprf] [int] NOT NULL ,
	[spds] [varchar] (30) COLLATE Latin1_General_BIN NULL ,
	[tprf] [int] NOT NULL ,
	[tpds] [varchar] (30) COLLATE Latin1_General_BIN NULL ,
	[sdat] [datetime] NOT NULL ,
	[edat] [datetime] NULL ,
	[stat] [varchar] (1) COLLATE Latin1_General_BIN NOT NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcmpc110] (
	[mpcr] [int] NOT NULL ,
	[ctyp] [varchar] (50) COLLATE Latin1_General_BIN NOT NULL ,
	[cpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[flno] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[actn] [varchar] (100) COLLATE Latin1_General_BIN NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcmpc150] (
	[mpcr] [int] NOT NULL ,
	[ctyp] [varchar] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[cpac] [varchar] (2) COLLATE Latin1_General_BIN NOT NULL ,
	[cmod] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[flno] [varchar] (3) COLLATE Latin1_General_BIN NOT NULL ,
	[fdnm] [varchar] (30) COLLATE Latin1_General_BIN NOT NULL ,
	[actn] [varchar] (50) COLLATE Latin1_General_BIN NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bctmp000] (
	[usrn] [varchar] (50) COLLATE Latin1_General_BIN NOT NULL ,
	[sfob] [varchar] (60) COLLATE Latin1_General_BIN NOT NULL ,
	[bsob] [varchar] (60) COLLATE Latin1_General_BIN NOT NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bctmp001] (
	[usrn] [varchar] (50) COLLATE Latin1_General_BIN NOT NULL ,
	[conv] [text] COLLATE Latin1_General_BIN NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcusr100] (
	[usrn] [varbinary] (50) NOT NULL ,
	[pswd] [varbinary] (50) NOT NULL ,
	[name] [varchar] (30) COLLATE Latin1_General_BIN NOT NULL ,
	[defa] [varbinary] (50) NULL ,
	[shwm] [int] NULL ,
	[cpac] [char] (2) COLLATE Latin1_General_BIN NULL ,
	[cmod] [char] (3) COLLATE Latin1_General_BIN NULL ,
	[edtr] [varchar] (1000) COLLATE Latin1_General_BIN NULL ,
	[simn] [bigint] NULL ,
	[synh] [bit] NULL

) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bcusr110] (
	[usrn] [varbinary] (50) NOT NULL ,
	[mprf] [varbinary] (50) NOT NULL ,
	[busr] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[bpsd] [varbinary] (50) NULL
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcddc000] WITH NOCHECK ADD
	CONSTRAINT [PK_bcddc000] PRIMARY KEY  NONCLUSTERED
	(
		[runn]
	)  ON [PRIMARY] ,
	CONSTRAINT [IX_bcddc000] UNIQUE  CLUSTERED
	(
		[runn]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcddc100] WITH NOCHECK ADD
	CONSTRAINT [DF_bcddc100_fdno] DEFAULT (0) FOR [fdno],
	CONSTRAINT [DF_bcddc100_comb] DEFAULT (0) FOR [comb],
	CONSTRAINT [DF_bcddc100_refm] DEFAULT (0) FOR [refm],
	CONSTRAINT [PK_bcddc100] PRIMARY KEY  NONCLUSTERED
	(
		[runn]
	)  ON [PRIMARY] ,
	CONSTRAINT [IX_bcddc100] UNIQUE  CLUSTERED
	(
		[runn]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcddc140] WITH NOCHECK ADD
	CONSTRAINT [PK_bcddc140] PRIMARY KEY  CLUSTERED
	(
		[runn],
		[ctyp],
		[cpac],
		[cmod],
		[flno]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcddc141] WITH NOCHECK ADD
	CONSTRAINT [PK_bcddc141] PRIMARY KEY  CLUSTERED
	(
		[runn],
		[spac],
		[smod],
		[slno],
		[tpac],
		[tmod],
		[tlno]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcddc150] WITH NOCHECK ADD
	CONSTRAINT [PK_bcddc150] PRIMARY KEY  CLUSTERED
	(
		[runn],
		[ctyp],
		[cpac],
		[cmod],
		[flno],
		[fdnm]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcddc151] WITH NOCHECK ADD
	CONSTRAINT [PK_bcddc151] PRIMARY KEY  CLUSTERED
	(
		[runn],
		[cpac],
		[cmod],
		[flno],
		[fdnm]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcddc160] WITH NOCHECK ADD
	CONSTRAINT [PK_bcddc160] PRIMARY KEY  CLUSTERED
	(
		[runn],
		[ctyp],
		[cpac],
		[cmod],
		[flno],
		[fdnm],
		[sern]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcddc200] WITH NOCHECK ADD
	CONSTRAINT [PK_bcddc200] PRIMARY KEY  CLUSTERED
	(
		[runn],
		[ctyp],
		[cpac],
		[cmod],
		[flno],
		[indn]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcddc220] WITH NOCHECK ADD
	CONSTRAINT [PK_bcddc220] PRIMARY KEY  CLUSTERED
	(
		[runn],
		[ctyp],
		[cpac],
		[cdom]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcddc230] WITH NOCHECK ADD
	CONSTRAINT [PK_bcddc230] PRIMARY KEY  CLUSTERED
	(
		[runn],
		[ctyp],
		[cpac],
		[cdom],
		[ctnm]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcddi100] WITH NOCHECK ADD
	CONSTRAINT [DF_bcddi100_extn] DEFAULT (0) FOR [extn],
	CONSTRAINT [PK_bcddi100] PRIMARY KEY  CLUSTERED
	(
		[appl]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcddi101] WITH NOCHECK ADD
	CONSTRAINT [DF_bcddi101_ftyp] DEFAULT ('ANSI') FOR [ftyp],
	CONSTRAINT [DF_bcddi101_fixed] DEFAULT (0) FOR [fixd],
	CONSTRAINT [DF_bcddi101_tcol] DEFAULT (0) FOR [tcol],
	CONSTRAINT [DF_bcddi101_cnul] DEFAULT (0) FOR [cnul],
	CONSTRAINT [DF_bcddi101_nskp] DEFAULT (0) FOR [nskp],
	CONSTRAINT [DF_bcddi101_rsep] DEFAULT ('{CR}{LF}') FOR [rsep],
	CONSTRAINT [DF_bcddi101_dscn] DEFAULT (1) FOR [dscn],
	CONSTRAINT [PK_bcddi101] PRIMARY KEY  CLUSTERED
	(
		[appl]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcddi140] WITH NOCHECK ADD
	CONSTRAINT [PK_bcddi140] PRIMARY KEY  CLUSTERED
	(
		[appl],
		[cpac],
		[cmod],
		[flno]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcddi150] WITH NOCHECK ADD
	CONSTRAINT [PK_bcddi150] PRIMARY KEY  CLUSTERED
	(
		[appl],
		[cpac],
		[cmod],
		[flno],
		[fdnm]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcddi160] WITH NOCHECK ADD
	CONSTRAINT [PK_bcddi160] PRIMARY KEY  CLUSTERED
	(
		[appl],
		[cpac],
		[cmod],
		[flno],
		[fdnm],
		[sern]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcddi200] WITH NOCHECK ADD
	CONSTRAINT [PK_bcddi200] PRIMARY KEY  CLUSTERED
	(
		[appl],
		[cpac],
		[cmod],
		[flno],
		[indn]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcddi220] WITH NOCHECK ADD
	CONSTRAINT [PK_bcddi220] PRIMARY KEY  CLUSTERED
	(
		[appl],
		[cpac],
		[cdom]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcddi230] WITH NOCHECK ADD
	CONSTRAINT [PK_bcddi230] PRIMARY KEY  CLUSTERED
	(
		[appl],
		[cpac],
		[cdom],
		[ctnm],
		[cnst]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcdoc102] WITH NOCHECK ADD
	CONSTRAINT [PK_bcdoc102] PRIMARY KEY  CLUSTERED
	(
		[tpid],
		[mprf],
		[docid]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcldc140] WITH NOCHECK ADD
	CONSTRAINT [DF_bcldc140_cpac] DEFAULT ('bc') FOR [cpac],
	CONSTRAINT [PK_bcldc140] PRIMARY KEY  CLUSTERED
	(
		[runn],
		[ctyp],
		[cpac],
		[cmod],
		[flno]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcldc141] WITH NOCHECK ADD
	CONSTRAINT [DF_bcldc141_cpac] DEFAULT ('bc') FOR [cpac],
	CONSTRAINT [DF_bcldc141_cmod] DEFAULT ('fil') FOR [cmod],
	CONSTRAINT [DF_bcldc141_scol] DEFAULT (0) FOR [scol],
	CONSTRAINT [DF_bcldc141_tcol] DEFAULT (0) FOR [tcol],
	CONSTRAINT [DF_bcldc141_snul] DEFAULT (0) FOR [snul],
	CONSTRAINT [DF_bcldc141_tnul] DEFAULT (0) FOR [tnul],
	CONSTRAINT [DF_bcldc141_sskp] DEFAULT (0) FOR [sskp],
	CONSTRAINT [DF_bcldc141_tskp] DEFAULT (0) FOR [tskp],
	CONSTRAINT [PK_bcldc141] PRIMARY KEY  CLUSTERED
	(
		[runn],
		[ctyp],
		[cpac],
		[cmod],
		[flno]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcldc150] WITH NOCHECK ADD
	CONSTRAINT [DF_bcldc150_cpac] DEFAULT ('bc') FOR [cpac],
	CONSTRAINT [PK_bcldc150] PRIMARY KEY  CLUSTERED
	(
		[runn],
		[ctyp],
		[cpac],
		[cmod],
		[flno],
		[fdnm]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcldc151] WITH NOCHECK ADD
CONSTRAINT [DF_bcldc151_cpac] DEFAULT ('bc') FOR [cpac],
	CONSTRAINT [DF_bcldc151_cmod] DEFAULT ('fil') FOR [cmod],
	CONSTRAINT [PK_bcldc151] PRIMARY KEY  CLUSTERED
	(
		[runn],
		[ctyp],
		[cpac],
		[cmod],
		[flno],
		[fdnm]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bclgy115] WITH NOCHECK ADD
	CONSTRAINT [PK_bclgy115] PRIMARY KEY  CLUSTERED
	(
		[code],
		[ival]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bclgy140] WITH NOCHECK ADD
	CONSTRAINT [DF_bclgy100_cpac] DEFAULT ('bc') FOR [cpac],
	CONSTRAINT [DF_bclgy100_cmod] DEFAULT ('tbl') FOR [cmod],
	CONSTRAINT [PK_bclgy100] PRIMARY KEY  CLUSTERED
	(
		[appl],
		[cpac],
		[cmod],
		[flno]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bclgy141] WITH NOCHECK ADD
	CONSTRAINT [DF_bclgy101_cpac] DEFAULT ('bc') FOR [cpac],
	CONSTRAINT [DF_bclgy101_cmod] DEFAULT ('fil') FOR [cmod],
	CONSTRAINT [DF_bclgy101_fixed] DEFAULT (0) FOR [fixd],
	CONSTRAINT [DF_bclgy101_tcol] DEFAULT (0) FOR [tcol],
	CONSTRAINT [DF_bclgy101_cnul] DEFAULT (0) FOR [cnul],
	CONSTRAINT [DF_bclgy141_nskp] DEFAULT (0) FOR [nskp],
	CONSTRAINT [PK_bclgy101] PRIMARY KEY  CLUSTERED
	(
		[appl],
		[cpac],
		[cmod],
		[flno]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bclgy150] WITH NOCHECK ADD
	CONSTRAINT [PK_bclgy150] PRIMARY KEY  CLUSTERED
	(
		[appl],
		[cpac],
		[cmod],
		[flno],
		[flna]
	)  ON [PRIMARY]
GO

CREATE  INDEX [IX_bclgy150] ON [dbo].[bclgy150]([appl], [flno], [flna], [dtyp]) ON [PRIMARY]
GO

ALTER TABLE [dbo].[bclgy400] WITH NOCHECK ADD
	CONSTRAINT [PK_bclgy400] PRIMARY KEY  CLUSTERED
	(
		[btno]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bclgy401] WITH NOCHECK ADD
	CONSTRAINT [PK_bclgy401] PRIMARY KEY  CLUSTERED
	(
		[btno],
		[tbnm]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bclib100] WITH NOCHECK ADD
	CONSTRAINT [DF_bclib100_stat] DEFAULT ('N') FOR [stat],
	CONSTRAINT [PK_bclib100] PRIMARY KEY  CLUSTERED
	(
		[mprf],
		[vers],
		[rele],
		[cust],
		[fnam]
	)  ON [PRIMARY]
GO


ALTER TABLE [dbo].[bclib105] WITH NOCHECK ADD
	CONSTRAINT [PK_bclib105] PRIMARY KEY  CLUSTERED
	(
		[mprf],
		[vers],
		[rele],
		[cust],
		[fnam],
		[revi]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcmap100] WITH NOCHECK ADD
	CONSTRAINT [PK_bcmap100] PRIMARY KEY  CLUSTERED
	(
		[mprf]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcmap101] WITH NOCHECK ADD
	CONSTRAINT [PK_bcmap101] PRIMARY KEY  CLUSTERED
	(
		[mprf],
		[levl]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcmap105] WITH NOCHECK ADD
	CONSTRAINT [PK_bcmap105] PRIMARY KEY  CLUSTERED
	(
		[mprf],
		[vers],
		[rele],
		[cust]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcmap110] WITH NOCHECK ADD
	CONSTRAINT [PK_bcmap110] PRIMARY KEY  CLUSTERED
	(
		[mprf],
		[vers],
		[rele],
		[cust],
		[tcpac],
		[tcmod],
		[tflno],
		[revi]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcmap120] WITH NOCHECK ADD
	CONSTRAINT [DF_bcmap120_mscript] DEFAULT (0) FOR [isms],
	CONSTRAINT [PK_bcmap120] PRIMARY KEY  CLUSTERED
	(
		[mprf],
		[vers],
		[rele],
		[cust],
		[tcpac],
		[tcmod],
		[tflno]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcmap125] WITH NOCHECK ADD
	CONSTRAINT [DF_bcmap125_isms] DEFAULT (0) FOR [isms],
	CONSTRAINT [PK_bcmap125] PRIMARY KEY  CLUSTERED
	(
		[mprf],
		[vers],
		[rele],
		[cust],
		[tcpac],
		[tcmod],
		[tflno],
		[revi]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcmap130] WITH NOCHECK ADD
	CONSTRAINT [PK_bcmap130] PRIMARY KEY  CLUSTERED
	(
		[mprf],
		[vers],
		[rele],
		[cust],
		[tcpac],
		[tcmod],
		[tflno],
		[scpac],
		[scmod],
		[sflno],
		[icod]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcmap135] WITH NOCHECK ADD
	CONSTRAINT [PK_bcmap135] PRIMARY KEY  CLUSTERED
	(
		[mprf],
		[vers],
		[rele],
		[cust],
		[tcpac],
		[tcmod],
		[tflno],
		[scpac],
		[scmod],
		[sflno],
		[icod],
		[revi]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcmap140] WITH NOCHECK ADD
	CONSTRAINT [PK_bcmap140] PRIMARY KEY  CLUSTERED
	(
		[mprf],
		[vers],
		[rele],
		[cust],
		[tcpac],
		[tcmod],
		[tflno],
		[dnum],
		[fdnm]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcmap145] WITH NOCHECK ADD
	CONSTRAINT [PK_bcmap145] PRIMARY KEY  CLUSTERED
	(
		[mprf],
		[vers],
		[rele],
		[cust],
		[tcpac],
		[tcmod],
		[tflno],
		[dnum],
		[fdnm],
		[revi]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcmap150] WITH NOCHECK ADD
	CONSTRAINT [PK_bcmap150] PRIMARY KEY  CLUSTERED
	(
		[func]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcmap160] WITH NOCHECK ADD
	CONSTRAINT [PK_bcmap160] PRIMARY KEY  CLUSTERED
	(
		[mprf],
		[vers],
		[rele],
		[cust],
		[tcpac],
		[tcmod],
		[tflno]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcmap165] WITH NOCHECK ADD
	CONSTRAINT [PK_bcmap165] PRIMARY KEY  CLUSTERED
	(
		[mprf],
		[vers],
		[rele],
		[cust],
		[tcpac],
		[tcmod],
		[tflno],
		[revi]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcmap170] WITH NOCHECK ADD
	CONSTRAINT [PK_bcmap180] PRIMARY KEY  CLUSTERED
	(
		[mprf],
		[vers],
		[rele],
		[cust],
		[bpac],
		[bmod],
		[bflno],
		[cpac],
		[cmod],
		[cflno]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcmap175] WITH NOCHECK ADD
	CONSTRAINT [DF_bcmap175_csta] DEFAULT ('C') FOR [csta],
	CONSTRAINT [PK_bcmap175] PRIMARY KEY  CLUSTERED
	(
		[mprf],
		[vers],
		[rele],
		[cust],
		[bpac],
		[bmod],
		[bflno],
		[revi],
		[cpac],
		[cmod],
		[cflno]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcmap200] WITH NOCHECK ADD
	CONSTRAINT [PK_bcmap200] PRIMARY KEY  CLUSTERED
	(
		[mprf],
		[vers],
		[rele],
		[cust],
		[txtn]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcmap205] WITH NOCHECK ADD
	CONSTRAINT [PK_bcmap205] PRIMARY KEY  CLUSTERED
	(
		[mprf],
		[vers],
		[rele],
		[cust],
		[txtn],
		[revi]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcmap210] WITH NOCHECK ADD
	CONSTRAINT [PK_bcmap210] PRIMARY KEY  CLUSTERED
	(
		[txno]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcmap300] WITH NOCHECK ADD
	CONSTRAINT [PK_bcmap300] PRIMARY KEY  CLUSTERED
	(
		[ttbl],
		[stbl]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcmpc100] WITH NOCHECK ADD
	CONSTRAINT [PK_bcmpc100] PRIMARY KEY  CLUSTERED
	(
		[mpcr]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcmpc110] WITH NOCHECK ADD
	CONSTRAINT [PK_bcmpc110] PRIMARY KEY  CLUSTERED
	(
		[mpcr],
		[cpac],
		[cmod],
		[flno]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcmpc150] WITH NOCHECK ADD
	CONSTRAINT [PK_bcmpc150] PRIMARY KEY  CLUSTERED
	(
		[mpcr],
		[cpac],
		[cmod],
		[flno],
		[fdnm]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bctmp000] WITH NOCHECK ADD
	CONSTRAINT [PK_bctmp000] PRIMARY KEY  CLUSTERED
	(
		[usrn],
		[sfob],
		[bsob]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bctmp001] WITH NOCHECK ADD
	CONSTRAINT [PK_bctmp001] PRIMARY KEY  CLUSTERED
	(
		[usrn]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcusr100] WITH NOCHECK ADD
	CONSTRAINT [DF_bcusr100_simn] DEFAULT (100) FOR [simn],
	CONSTRAINT [DF_bcusr100_synh] DEFAULT (1) FOR [synh],
	CONSTRAINT [PK_bcusr100] PRIMARY KEY  NONCLUSTERED
	(
		[usrn]
	)  ON [PRIMARY]
GO

ALTER TABLE [dbo].[bcusr110] WITH NOCHECK ADD
	CONSTRAINT [PK_bcusr110] PRIMARY KEY  NONCLUSTERED
	(
		[usrn],
		[mprf]
	)  ON [PRIMARY]
GO


SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO



CREATE  PROCEDURE Update_MigCompSummary  @MPCNum  [int ], @SrcPrf  [int], @SrcDDC  [int]
AS
DECLARE @intRunMPC 	as int			--RunNumber of Mig Prof Comp Run Number
DECLARE @StrConObj		as varchar(8)		--To Store Conversion Object Name
DECLARE @StrStbl		as varchar(1000)	--To Store all dependent source tables of the Conversion Object Name
DECLARE @StrPackage 	as varchar(2)		--Package
DECLARE @StrModule 		as varchar(3)		--Module
DECLARE @StrTable 		as varchar(3)		--Table
DECLARE @StrCtype 		as varchar(1)		--Ctype -U/C/N/R
DECLARE @IntCount 		as int
DECLARE @StrTempQry	as nvarchar(1024)	--Temporary String
DECLARE @ParmDefinition 	as nvarchar(500)
Create TABLE #TableSrcDDCVar
  	(SrcTbl char(8) PRIMARY KEY)
INSERT INTO #TableSrcDDCVar (SrcTbl)
SELECT cpac+cmod+flno
FROM  bcddc140
WHERE runn= @SrcDDC and  ctyp in ('R', 'C')
--BEGIN TRANSACTION
--ROLLBACK TRANSACTION
--COMMIT TRANSACTION  -- Commit the Transaction
DECLARE MPC110_Cursor CURSOR FOR
SELECT 	[dbo].[bcmpc110].mpcr,
		[dbo].[bcmpc110].cpac,
		[dbo].[bcmpc110].cmod,
		[dbo].[bcmpc110].flno,
		[dbo].[bcmpc110].ctyp
FROM 		[dbo].[bcmpc110]
WHERE	[dbo].[bcmpc110].mpcr = @MPCNum
		AND [dbo].[bcmpc110].ctyp = 'U'
OPEN 	MPC110_Cursor
FETCH NEXT FROM MPC110_Cursor
INTO   @intRunMPC, @StrPackage, @StrModule, @StrTable, @StrCtype
WHILE @@FETCH_STATUS = 0
BEGIN
	SET @StrConObj = ''
	SET @StrStbl = ''
	SELECT 	@StrConObj= [dbo].[bcmap120].tcpac+[dbo].[bcmap120].tcmod +[dbo].[bcmap120].tflno,
			@StrStbl = [dbo].[bcmap120].stbl
	FROM   	[dbo].[bcmap120]
	WHERE  	[dbo].[bcmap120].mprf 	= 	@SrcPrf
		AND  	[dbo].[bcmap120].tcpac 	=	@StrPackage
		AND	[dbo].[bcmap120].tcmod 	=	@StrModule
		AND	[dbo].[bcmap120].tflno 	=	@StrTable

	SET @StrConObj = ISNULL(@StrConObj,'')
	SET @StrStbl = ISNULL(@StrStbl,'')
	IF (@StrStbl <> '' )
	BEGIN

		SET @StrStbl = ('''' + replace(@StrStbl, ',',''',''' )+ '''')
		SET @StrTempQry = 'SELECT  @IntCount = Count(*) '  +  'FROM   #TableSrcDDCVar '  + ' WHERE SrcTbl in  ('   + @StrStbl+  ')'
		SET @ParmDefinition = N'@IntCount integer out'
		exec sp_executesql @StrTempQry,@ParmDefinition,@IntCount out
		IF (@IntCount>0)
		BEGIN
			PRINT  @IntCount
			PRINT  @StrStbl

			UPDATE [dbo].[bcmpc110]
			SET  [mpcr]	 = @MPCNum,
				 [ctyp]	 = 'C',
				 [cpac]	 = @StrPackage,
				 [cmod]	 = @StrModule,
				 [flno]	 = @StrTable,
				 [actn]	 = 'Changed'

			WHERE
				( [mpcr]	 = @MPCNum AND
				 [cpac]	 = @StrPackage AND
				 [cmod]	 = @StrModule AND
				 [flno]	 = @StrTable)
		END

	END
	FETCH NEXT FROM MPC110_Cursor
	INTO   @intRunMPC, @StrPackage, @StrModule, @StrTable, @StrCtype
END
CLOSE MPC110_Cursor
DEALLOCATE MPC110_Cursor
RETURN @@ERROR



GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO



/****** Object:  Stored Procedure dbo.Write_to_file    Script Date: 10/6/2003 2:36:54 PM ******/
/****** Object:  Stored Procedure dbo.Write_to_file    Script Date: 8/29/2003 10:56:08 AM ******/
CREATE PROC Write_to_file
		@msg VARCHAR(1024),
		@file VARCHAR(1024),
		@overwrite BIT = 0
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @execstr VARCHAR(3072)
	SET @execstr = RTRIM('echo ' + COALESCE(LTRIM(@msg),'-') + CASE WHEN (@overwrite = 1) THEN ' > ' ELSE ' >> ' END + RTRIM(@file))
	EXEC master..xp_cmdshell @execstr
	SET NOCOUNT OFF
END



GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO



/****** Object:  Stored Procedure dbo.sp_CreateDefaultMappings    Script Date: 10/6/2003 2:36:55 PM ******/
/****** Object:  Stored Procedure dbo.sp_CreateDefaultMappings    Script Date: 8/29/2003 10:56:08 AM ******/
/********************************************************************************
* 	NAME:		sp_CreateDefaultMappings			      	*
*	DESCRIPTION:	This Strored procedure, generates the Default mappings	*
*			for the tables for which Comparison has already been  	*
*			done.						      	*
*	Inputs:		The Runn Number, the Migration Profile, the Start pack	*
*			module and Table to the target Pack, Mod and Table.   	*
*	Calls:		The Following procedures are called.		      	*
*			1. sp_insert_bcmap120_1					*
*			2. sp_insert_bcmap125_1					*
*			3. sp_insert_bcmap130_1					*
*			4. sp_insert_bcmap135_1					*
*			5. sp_CreateMappingsForFineTunedChangedTables		*
*			6. sp_update_bcddc000_1					*
*	UPDATION 								*
*		- Adding  a Parameter @I_UserName[varchar](12)-31/oct/2001	*
*		- Call to sp_insert_bcmap110_1() is added-31/oct/2001		*
********************************************************************************/
CREATE PROCEDURE [sp_CreateDefaultMappings]
	(

	@I_IntRunn 		[int],
	@I_IntMprf 		[int],
	@I_StrPackFrom 		[varchar](2),
	@I_StrModFrom 		[varchar](3),
	@I_StrTableFrom 	[varchar](3),
	@I_StrPackTo 		[varchar](2),
	@I_StrModTo		[varchar](3),
	@I_StrTableTo		[varchar](3),
	@I_UserName		[varchar](12),
	@I_DMGChangedTables	[int] = 1,
	@I_DMGUnChangedTables	[int] = 1,
	@I_StrLogFileName	[varchar](1024) = "C:\DefaultMapGenLog.txt"
	)
AS
DECLARE @RecCntMAP120 		as int			--Record Count of BCMAP120
DECLARE @IntRetVal		as int			--Return Value
DECLARE	@IntCount		as int			--Counter
DECLARE @IntTableCount		as int			--Table Count
DECLARE @StrPackage 		as varchar(2)		--Package
DECLARE @StrModule 		as varchar(3)		--Module
DECLARE @StrTable 		as varchar(3)		--Table
DECLARE @StrCtype 		as varchar(1)		--Ctype -U/C/N/D
DECLARE @StrTargetAppl		as varchar(15)		--Target Application
DECLARE @StrSourceAppl		as varchar(15)		--Source Application
DECLARE @StrStdVersion		as varchar(4)		--Standard Version
DECLARE @StrStdRelease		as varchar(2)		--Standard Release
DECLARE @StrStdCustomer		as varchar(4)		--Standard Customer
DECLARE	@StrDevVersion		as varchar(4)		--Development Version
DECLARE	@StrDevRelease		as varchar(2)		--Development Release
DECLARE	@StrDevCustomer		as varchar(4)		--Development Customer
DECLARE @StrSCM			as varchar(1)		--SCM enabled for the Mig. Profile
DECLARE @StrText		as varchar(1024)	--Text
DECLARE @StrTableName		as varchar(8)		--To Store Table Name
DECLARE @CurrDateTime		as datetime		--Current Date and Time
DECLARE	@StrComment		as varchar(2000)	--Variable to hold Pretext
DECLARE @StrStatus		as varchar(1)		--Status
DECLARE @StrUnChanged		as varchar(1)		--Status - Unchanged
DECLARE @StrChanged		as varchar(1)		--Status - Changed
DECLARE @StrTemp		as varchar(1024)	--Temporary String
/* STEP 1. Get the Target Application Name & Mprf VRC details.*/
SELECT 	@StrTargetAppl 	= [dbo].[bcmap100].tapp,
	@StrSourceAppl	= [dbo].[bcmap100].sapp,
	@StrStdVersion	= [dbo].[bcmap100].vers,
	@StrStdRelease	= [dbo].[bcmap100].rele,
	@StrStdCustomer	= [dbo].[bcmap100].cust,
	@StrSCM		= [dbo].[bcmap100].scme
FROM 	[dbo].[bcmap100]
WHERE 	[dbo].[bcmap100].mprf = @I_IntMprf
/* STEP 2. Get the Development VRC from BCMAP 105 */
SELECT 	@StrDevVersion	= [dbo].[bcmap105].dver,
	@StrDevRelease	= [dbo].[bcmap105].drel,
	@StrDevCustomer	= [dbo].[bcmap105].dcus
FROM	[dbo].[bcmap105]
WHERE	[dbo].[bcmap105].mprf = @I_IntMprf
AND	[dbo].[bcmap105].vers = @StrStdVersion
AND	[dbo].[bcmap105].rele = @StrStdRelease
AND	[dbo].[bcmap105].cust = @StrStdCustomer

--If there is no Dev. VRC then set the Var to empty
SET @StrDevVersion = ISNULL(@StrDevVersion,'')
SET @StrDevRelease = ISNULL(@StrDevRelease,'')
SET @StrDevCustomer = ISNULL(@StrDevCustomer,'')
--IF Generation is for Changed Tables then Set the Flag.
IF (@I_DMGChangedTables = 1)
BEGIN
	SET @StrChanged ='C'
END
ELSE
BEGIN
	SET @StrChanged =''
END
--IF Generation is for UnChanged Tables then Set the Flag.
IF (@I_DMGUnChangedTables = 1 )
BEGIN
	SET @StrUnChanged ='U'
END
ELSE
BEGIN
	SET @StrUnChanged =''
END
SET @CurrDateTime = GETDATE()
EXEC Write_to_file '***********************************************************************************************************************', @I_StrLogFileName,1
SET @StrTemp=   'START DEFAULT MAPPING GENERATION '  + CHAR(9) + ' START TIME ' + CAST(@CurrDateTime as varchar)
EXEC Write_to_file @StrTemp, @I_StrLogFileName
SET @StrTemp =  'Range FROM ' +	@I_StrPackFrom 	+ @I_StrModFrom + @I_StrTableFrom + '  TO   '  +
						@I_StrPackTo 	+ @I_StrModTo	+ @I_StrTableTo
EXEC Write_to_file @StrTemp, @I_StrLogFileName

SET @StrTemp =  'Migration Profile- '  +  LTRIM(STR(@I_IntMprf))
EXEC Write_to_file @StrTemp, @I_StrLogFileName
SET @StrTemp =   'Run Number- '  +  LTRIM(STR(@I_IntRunn))
EXEC Write_to_file @StrTemp, @I_StrLogFileName
SET @StrTemp =  'User Name- '  + @I_UserName
EXEC Write_to_file @StrTemp, @I_StrLogFileName
EXEC Write_to_file '***********************************************************************************************************************', @I_StrLogFileName
SET @IntTableCount = 0
/*STEP 3. Generate Default Mappings for Unchanged and  Changed  Tables*/
DECLARE DDC140_Cursor CURSOR FOR
SELECT 	[dbo].[bcddc140].cpac,
	[dbo].[bcddc140].cmod,
	[dbo].[bcddc140].flno,
	[dbo].[bcddc140].ctyp
FROM 	[dbo].[bcddc140]
WHERE	[dbo].[bcddc140].runn = @I_IntRunn
AND 	([dbo].[bcddc140].ctyp IN (@StrUnChanged, @StrChanged))
AND  	([dbo].[bcddc140].cpac  BETWEEN @I_StrPackFrom AND @I_StrPackTo )
AND	([dbo].[bcddc140].cmod  BETWEEN @I_StrModFrom  AND @I_StrModTo)
AND	([dbo].[bcddc140].flno  BETWEEN @I_StrTableFrom AND @I_StrTableTo )
OPEN DDC140_Cursor
FETCH NEXT FROM DDC140_Cursor
INTO   @StrPackage, @StrModule, @StrTable,@StrCtype
WHILE @@FETCH_STATUS = 0
BEGIN
	SET @StrComment = ''
	SET @StrStatus = ''


	/* If some mappings are present for the given Range (@RecCntMAP120 <> 0) then check
	   whether mapping present for the Curent Table. If no mappings then Generate */
	SELECT 	@StrComment= [dbo].[bcmap120].comt,
		@StrStatus = [dbo].[bcmap120].stat
	FROM   	[dbo].[bcmap120]
	WHERE  	[dbo].[bcmap120].mprf 	= 	@I_IntMprf
	AND	[dbo].[bcmap120].vers 	= 	@StrStdVersion
	AND	[dbo].[bcmap120].rele 	= 	@StrStdRelease
	AND	[dbo].[bcmap120].cust 	= 	@StrStdCustomer
	AND  	[dbo].[bcmap120].tcpac 	=	@StrPackage
	AND	[dbo].[bcmap120].tcmod 	=	@StrModule
	AND	[dbo].[bcmap120].tflno 	=	@StrTable

	SET @StrComment = ISNULL(@StrComment,'')
	SET @StrStatus = ISNULL(@StrStatus,'')


	IF (@StrStatus ='' OR @StrStatus ='N')
	BEGIN
		--check whether a rec. is there in DVRC.
		--If DVRC is present then Skip.
		SELECT 	@IntCount = Count(*)
		FROM   	[dbo].[bcmap120]
		WHERE  	[dbo].[bcmap120].mprf 	=	@I_IntMprf
		AND  	[dbo].[bcmap120].tcpac 	=	@StrPackage
		AND	[dbo].[bcmap120].tcmod 	=	@StrModule
		AND	[dbo].[bcmap120].tflno 	=	@StrTable
		AND	[dbo].[bcmap120].vers	=	@StrDevVersion
		AND	[dbo].[bcmap120].rele	=	@StrDevRelease
		AND	[dbo].[bcmap120].cust	=	@StrDevCustomer

		IF (@IntCount > 0)
		BEGIN
			--Write in Log file - Mapping Already Exist
			SET @StrTemp = CHAR(9) +'Mapping Exists for the ' +  	@StrPackage      +
										@StrModule       +
										@StrTable 	 +
					       ' In the Development VRC - ' +
										@StrDevVersion +
										@StrDevRelease +
										@StrDevCustomer
			EXEC Write_to_file @StrTemp, @I_StrLogFileName

			FETCH NEXT FROM DDC140_Cursor
			INTO   @StrPackage, @StrModule, @StrTable,@StrCtype
			CONTINUE
		END

	END
	ELSE
	BEGIN
		IF ( @StrStatus <> 'N')
		BEGIN
			SET @StrTemp = CHAR(9)+ 'Mapping Exists for the ' +  	@StrPackage      +
										@StrModule       +
										@StrTable 	 +
					       ' in the Standard VRC - ' +
										@StrStdVersion 	 +
										@StrStdRelease    +
										@StrStdCustomer   +
					       ' with the status - '  +  @StrStatus

			EXEC Write_to_file @StrTemp, @I_StrLogFileName
			FETCH NEXT FROM DDC140_Cursor
			INTO   @StrPackage, @StrModule, @StrTable,@StrCtype
			CONTINUE
		END
	END


	BEGIN TRANSACTION
	-- STEP 4. Insert a New Record in BCMAP120/125,130/135

	/* Insert a Record in BAMAP120*/
	SET @StrTableName =  @StrPackage + @StrModule + @StrTable
	SET @StrText =  'migrate ' + @StrTableName
	EXEC @IntRetVal = sp_insert_bcmap120_1 	@I_IntMprf,		--Migration Profile
						@StrStdVersion,		--Version
						@StrStdRelease,		--Release
						@StrStdCustomer,	--Customer
						@StrPackage,		--Package
						@StrModule,		--Module
						@StrTable,		--Table
						@StrText,		--Precondition Text
						'',			--Check out User
						@I_UserName,		--Last Modified User
						@CurrDateTime,		--Date
						'G',			--Status
						'',			--Variables
						@StrComment,		--Comments
						@StrTableName		--Source Table
	IF @IntRetVal <> 0
	BEGIN
		--ERROR Encountered: ROLLBACK and Continue with the Next Table
		SELECT @StrTemp = [master].[dbo].[sysmessages].description
		FROM   [master].[dbo].[sysmessages]
		WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

		SET @StrTemp = CHAR(9) + 'Error -' + @StrTemp + ' -  while inserting  the record ' +
					 ' MPRF - '   + LTRIM(STR(@I_IntMprf))	+  ' ' +
				         ' VRC  - '   + @StrStdVersion	+  '-' +
			                                @StrStdRelease	+  '-' +
			                                @StrStdCustomer	+
					 ' TABLE - '  +	@StrPackage	+
			                                @StrModule	+
			                                @StrTable	+  ' ' +
			                ' into BCMAP120. '
		EXEC Write_to_file @StrTemp, @I_StrLogFileName

		ROLLBACK TRANSACTION


		FETCH NEXT FROM DDC140_Cursor
		INTO   @StrPackage, @StrModule, @StrTable,@StrCtype

		CONTINUE
	END

	/* STEP 5. Insert 2 Records in BCMAP130
		1. For Select
		2. SelectDo */

	SET @StrText ='Select  ' +  @StrTableName + '.* ' + CHAR(13)  + CHAR(10) + 'From  ' + @StrTableName
	EXEC @IntRetVal = sp_insert_bcmap130_1  @I_IntMprf,		--Migration Profile
						@StrStdVersion,       	--Version
						@StrStdRelease,       	--Release
						@StrStdCustomer,      	--Customer
						@StrPackage,    	--Target Package
						@StrModule,     	--Target Module
						@StrTable,      	--Target Table
						@StrPackage,    	--Source Package
						@StrModule,     	--Source Module
						@StrTable,      	--Source Table
						'S',            	--Code for Text S/D/F/X
						@StrText        	--The Text -Query

	IF @IntRetVal <> 0
	BEGIN
		--ERROR Encountered: ROLLBACK and Continue with the Next Table
		SELECT @StrTemp = [master].[dbo].[sysmessages].description
		FROM   [master].[dbo].[sysmessages]
		WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

		SET @StrTemp = ' Error -' + @StrTemp + ' -  while inserting  the record -' +
					 ' MPRF - '   + LTRIM(STR(@I_IntMprf))	+  ' ' +
				         ' VRC  - '   + @StrStdVersion	+  '-' +
			                                @StrStdRelease	+  '-' +
			                                @StrStdCustomer	+
					 ' TABLE - '  +	@StrPackage	+
			                                @StrModule	+
			                                @StrTable	+  ' ' +
			                 ' CODE  - S ' +
	 		                 ' into BCMAP130. '

		EXEC Write_to_file @StrTemp, @I_StrLogFileName
		ROLLBACK TRANSACTION

		FETCH NEXT FROM DDC140_Cursor
		INTO   @StrPackage, @StrModule, @StrTable,@StrCtype

		CONTINUE
	END
	EXEC @IntRetVal = sp_insert_bcmap130_1 	@I_IntMprf,	--Migration Profile
						@StrStdVersion,	--Version
						@StrStdRelease,        --Release
						@StrStdCustomer,       --Customer
						@StrPackage,    --Target Package
						@StrModule,     --Target Module
						@StrTable,      --Target Table
						@StrPackage,    --Source Package
						@StrModule,     --Source Module
						@StrTable,      --Source Table
						'D',            --Code for Text S/D/F/X
						'dump 1'        --The Text -Query
	IF @IntRetVal <> 0
	BEGIN
		--ERROR Encountered: ROLLBACK and Continue with the Next Table
		SELECT @StrTemp = [master].[dbo].[sysmessages].description
		FROM   [master].[dbo].[sysmessages]
		WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

		SET @StrTemp = ' Error -' + @StrTemp + ' -  while inserting  the record -' +
					 ' MPRF - '   + LTRIM(STR(@I_IntMprf))	+  ' ' +
				         ' VRC  - '   + @StrStdVersion	+  '-' +
			                                @StrStdRelease	+  '-' +
			                                @StrStdCustomer	+
					 ' TABLE - '  +	@StrPackage	+
			                                @StrModule	+
			                                @StrTable	+  ' ' +
			                 ' CODE - D ' +
			                 ' into BCMAP130. '
		ROLLBACK TRANSACTION

		FETCH NEXT FROM DDC140_Cursor
		INTO   @StrPackage, @StrModule, @StrTable,@StrCtype

		CONTINUE
	END
	--STEP 6. If Migration is SCM enabled then insert records into 125 & 135

	IF @StrSCM = 'Y'
	BEGIN
		/* Inser a New Record in BCMAP110*/
		EXEC @IntRetVal = sp_insert_bcmap110_1 		@I_IntMprf,		--Migration Profile
								@StrStdVersion,     	--Version
								@StrStdRelease,     	--Release
								@StrStdCustomer,    	--Customer
								@StrPackage, 		--Package
								@StrModule,  		--Module
								@StrTable,   		--Table
								1,           		--Revision No.
								'Default Generation',   --Revision Info.
								'DEFAULT',		--Issue ID
								@CurrDateTime,		--Date & Time
								0,			--Patch NOT Exported(0)/Exported(1)
								@I_UserName		--User Name

		IF @IntRetVal <> 0
		BEGIN
			--ERROR Encountered: ROLLBACK and Continue with the Next Table
			SELECT @StrTemp = [master].[dbo].[sysmessages].description
			FROM   [master].[dbo].[sysmessages]
			WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

			SET @StrTemp = ' Error -' + @StrTemp + ' -  while inserting  the record -' +
					 ' MPRF - '   + LTRIM(STR(@I_IntMprf))	+  ' ' +
				         ' VRC  - '   + @StrStdVersion	+  '-' +
			                                @StrStdRelease	+  '-' +
			                                @StrStdCustomer	+
					 ' TABLE - '  +	@StrPackage	+
			                                @StrModule	+
			                                @StrTable	+  ' ' +
			                ' into BCMAP110. '

			ROLLBACK TRANSACTION

			FETCH NEXT FROM DDC140_Cursor
			INTO   @StrPackage, @StrModule, @StrTable,@StrCtype

			CONTINUE
		END

		/* Insert a New Record in BCMAP125*/
		SET @StrText =  'migrate ' + @StrTableName
		EXEC	@IntRetVal = sp_insert_bcmap125_1 	@I_IntMprf,	        --Migration Profile
								@StrStdVersion,         --Version
								@StrStdRelease,         --Release
								@StrStdCustomer,        --Customer
								@StrPackage,    	--Package
								@StrModule,     	--Module
								@StrTable,      	--Table
								1,              	--Revision Number
								@StrText,       	--Precondition Text
								@I_UserName,    	--Last Modified User
								'C',            	--Status
								'',             	--Variables
								@StrTableName   	--Source Table

		IF @IntRetVal <> 0
		BEGIN
			--ERROR Encountered: ROLLBACK and Continue with the Next Table
			SELECT @StrTemp = [master].[dbo].[sysmessages].description
			FROM   [master].[dbo].[sysmessages]
			WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

			SET @StrTemp = ' Error -' + @StrTemp + ' -  while inserting  the record -' +
					 ' MPRF - '   + LTRIM(STR(@I_IntMprf))	+  ' ' +
				         ' VRC  - '   + @StrStdVersion	+  '-' +
			                                @StrStdRelease	+  '-' +
			                                @StrStdCustomer	+
					 ' TABLE - '  +	@StrPackage	+
			                                @StrModule	+
			                                @StrTable	+  ' ' +
			                ' into BCMAP125. '

			EXEC Write_to_file @StrTemp, @I_StrLogFileName

			ROLLBACK TRANSACTION

			FETCH NEXT FROM DDC140_Cursor
			INTO   @StrPackage, @StrModule, @StrTable,@StrCtype

			CONTINUE
		END

		/* Insert 2 Records in BCMAP135
			1. For Select
			2. SelectDo */
		SET @StrText =  'Select  ' +  @StrTableName + '.* ' + CHAR(13)  + CHAR(10) + 'From  ' + @StrTableName
		EXEC @IntRetVal = sp_insert_bcmap135_1 	@I_IntMprf,		--Migration Profile
							@StrStdVersion,        --Version
							@StrStdRelease,        --Release
							@StrStdCustomer,       --Customer
							@StrPackage,    	--Target Package
							@StrModule,     	--Target Module
							@StrTable,      	--Target Table
							@StrPackage,    	--Source Package
							@StrModule,     	--Source Module
							@StrTable,      	--Source Table
							'S',            	--Code for Text S/D/F/X
							1,              	-- REvision Code
							@StrText,		--The Text -Query
							@I_UserName,		--User Name
							'C'			--Change Code
		IF @IntRetVal <> 0
		BEGIN
			--ERROR Encountered: ROLLBACK and Continue with the Next Table
			SELECT @StrTemp = [master].[dbo].[sysmessages].description
			FROM   [master].[dbo].[sysmessages]
			WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

			SET @StrTemp = ' Error -' + @StrTemp + ' -  while inserting  the record -' +
					 ' MPRF - '   + LTRIM(STR(@I_IntMprf))	+  ' ' +
				         ' VRC  - '   + @StrStdVersion	+  '-' +
			                                @StrStdRelease	+  '-' +
			                                @StrStdCustomer	+
					 ' TABLE - '  +	@StrPackage	+
			                                @StrModule	+
			                                @StrTable	+  ' ' +
			                ' into BCMAP135. '

			EXEC Write_to_file @StrTemp, @I_StrLogFileName

			ROLLBACK TRANSACTION

			FETCH NEXT FROM DDC140_Cursor
			INTO   @StrPackage, @StrModule, @StrTable,@StrCtype

			CONTINUE
		END
		--STEP Insert Second Record
		EXEC  @IntRetVal = sp_insert_bcmap135_1 	@I_IntMprf,	       	--Migration Profile
								@StrStdVersion,        	--Version
								@StrStdRelease,        	--Release
								@StrStdCustomer,       	--Customer
								@StrPackage,    	--Target Package
								@StrModule,     	--Target Module
								@StrTable,      	--Target Table
								@StrPackage,    	--Source Package
								@StrModule,     	--Source Module
								@StrTable,      	--Source Table
								'D',            	--Code for Text S/D/F/X
								1,              	-- REvision Code
								'dump 1',       	--The Text -Query
								@I_UserName,    	--User Name
								'C'             	--Change Code
		IF @IntRetVal <> 0
		BEGIN
			--ERROR Encountered: ROLLBACK and Continue with the Next Table
			SELECT @StrTemp = [master].[dbo].[sysmessages].description
			FROM   [master].[dbo].[sysmessages]
			WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

			SET @StrTemp = ' Error -' + @StrTemp + ' -  while inserting  the record -' +
					 ' MPRF - '   + LTRIM(STR(@I_IntMprf))	+  ' ' +
				         ' VRC  - '   + @StrStdVersion	+  '-' +
			                                @StrStdRelease	+  '-' +
			                                @StrStdCustomer	+
					 ' TABLE - '  +	@StrPackage	+
			                                @StrModule	+
			                                @StrTable	+  ' ' +
			                ' into BCMAP135. '

			EXEC Write_to_file @StrTemp, @I_StrLogFileName

			ROLLBACK TRANSACTION

			FETCH NEXT FROM DDC140_Cursor
			INTO   @StrPackage, @StrModule, @StrTable,@StrCtype

			CONTINUE
		END
	END


	--STEP 7. If the Table is Unchanged then Call Unchangedtables Procedure

	IF @StrCtype = 'U'
	BEGIN

		EXEC @IntRetVal = sp_CreateMappingForUnchangedTables 	@StrTargetAppl, 	--Target Application
									@StrSourceAppl	,	--Source Application
									@StrStdVersion,		--Version
									@StrStdRelease,		--Release
									@StrStdCustomer,	--Customer
									@StrSCM,		--SCM
									@I_IntRunn, 		--Runn
									@I_IntMprf, 		--Migration Profile
									@StrPackage, 		--Package
									@StrModule, 		--Module
									@StrTable,		--Table
									@I_UserName,		--User Name
									@I_StrLogFileName	--LogFileName
		IF @IntRetVal <> 0
		BEGIN
			--ERROR Encountered: ROLLBACK and Continue with the Next Table
			ROLLBACK TRANSACTION

			FETCH NEXT FROM DDC140_Cursor
			INTO   @StrPackage, @StrModule, @StrTable,@StrCtype

			CONTINUE
		END
	END

	--STEP 8. IF the Table is a changed Table then Call Changed tables Proc.

	IF @StrCtype = 'C'
	BEGIN
		EXEC @IntRetVal = sp_CreateMappingForChangedTables 	@StrTargetAppl, 	--Target Application
									@StrSourceAppl,         --Source Application
									@StrStdVersion,		--Version
									@StrStdRelease,         --Release
									@StrStdCustomer,        --Customer
									@StrSCM,                --SCM
									@I_IntRunn,             --Runn
									@I_IntMprf,             --Migration Profile
									@StrPackage,            --Package
									@StrModule,             --Module
									@StrTable,              --Table
									@I_UserName,            --User Name
									@I_StrLogFileName	--LogFile Name
		IF @IntRetVal <> 0
		BEGIN
			--ERROR Encountered: ROLLBACK and Continue with the Next Table

			ROLLBACK TRANSACTION

			FETCH NEXT FROM DDC140_Cursor
			INTO   @StrPackage, @StrModule, @StrTable,@StrCtype

			CONTINUE
		END
	END
	COMMIT TRANSACTION  -- Commit the Transaction
	SET @IntTableCount = @IntTableCount + 1
	SET @StrTemp = CHAR(9) + 'Successfully completed Default Mapping for - ' + @StrTableName
	EXEC Write_to_file  @StrTemp, @I_StrLogFileName

	FETCH NEXT FROM DDC140_Cursor
	INTO   @StrPackage, @StrModule, @StrTable,@StrCtype
END
CLOSE DDC140_Cursor
DEALLOCATE DDC140_Cursor
IF @IntTableCount = 0
BEGIN
	EXEC Write_to_file '----------------------------------------------------------------------------------------------------------------------',@I_StrLogFileName
	SET @StrTemp = CHAR(9) +  'Default Mapping Generation for Tables Not Done due to any of the following reasons. '
	EXEC Write_to_file @StrTemp,@I_StrLogFileName
	SET @StrTemp = CHAR(9) + CHAR(9) + '1. Mapping Already exists for the tables in the selcted Range.'
	EXEC Write_to_file @StrTemp, @I_StrLogFileName
	SET @StrTemp = CHAR(9) + CHAR(9) + '2. DD Comparison was not done for the Tables in the selected Range.'
	EXEC Write_to_file @StrTemp, @I_StrLogFileName
	EXEC Write_to_file '----------------------------------------------------------------------------------------------------------------------',@I_StrLogFileName
END
ELSE
BEGIN
	EXEC Write_to_file '----------------------------------------------------------------------------------------------------------------------',@I_StrLogFileName
	SET @StrTemp = CHAR(9) + 'Default Mapping Generation is successfully done for = ' + LTRIM(STR(@IntTableCount)) + ' table(s).' + char(9) + 'END TIME   ' + CAST(GETDATE() as varchar)
	EXEC Write_to_file @StrTemp,@I_StrLogFileName
	EXEC Write_to_file '----------------------------------------------------------------------------------------------------------------------',@I_StrLogFileName
END
RETURN @@ERROR



GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO



/****** Object:  Stored Procedure dbo.sp_CreateDefaultMappingsForFineTunedTables    Script Date: 10/6/2003 2:36:55 PM ******/
/****** Object:  Stored Procedure dbo.sp_CreateDefaultMappingsForFineTunedTables    Script Date: 8/29/2003 10:56:08 AM ******/
/********************************************************************************
*	NAME:		sp_CreateDefaultMappingsForFineTunedTables		*
*	DESCRIPTION:	This is the Stroed Procedure that generates the Default *
*			mapping for given range of table.Default Mappings are   *
*			generated only for those table for which mappings are 	*
*			not present in BCMAP120.				*
*	TABLES:		1. BCMAP100						*
*			2. BCMAP120						*
*			3. BCDDC141						*
*	CALLS:		The following are the list of the PROC's CALLED		*
*			1. sp_insert_bcmap120_1					*
*			2. sp_insert_bcmap125_1					*
*			3. sp_insert_bcmap130_1					*
*			4. sp_insert_bcmap135_1					*
*			5. sp_CreateMappingsForFineTunedChangedTables		*
*			6. sp_update_bcddc000_1					*
*	UPDATION:								*
*		- On 31/Oct/2001						*
*			- Add a Parameter @I_UserName[varchar](12)		*
*			- Call sp_insert_bcmap110_1()				*
*			- Replace all "root" by @I_UserName			*
********************************************************************************/
CREATE PROCEDURE [sp_CreateDefaultMappingsForFineTunedTables]
(
	@I_IntRunn 		[int],
	@I_IntMprf 		[int],
	@I_StrPackFrom 		[varchar](2),
	@I_StrModFrom 		[varchar](3),
	@I_StrTableFrom 	[varchar](3),
	@I_StrPackTo 		[varchar](2),
	@I_StrModTo		[varchar](3),
	@I_StrTableTo		[varchar](3),
	@I_UserName		[varchar](12),
	@I_StrLogFileName	[varchar](1024) = "C:\DefaultMapGenLog.txt"
	)
 AS
DECLARE @RecCntMAP120 	as int			--Record Count in BCMAP120 Table
DECLARE @IntCount	as int			--Int Record Count
DECLARE @IntRetVal 	as int			--Return Value
DECLARE @IntTableCount	as int			--Table Count
DECLARE @StrTrgPackage 	as varchar(2)		--Target  Package
DECLARE @StrTrgModule 	as varchar(3)		--Target  Module
DECLARE @StrTrgTable 	as varchar(3)		--Target  Table
DECLARE @StrTableName	as varchar(8)		--To Store Table Name
DECLARE @StrSrcPackage 	as varchar(2)		--Source  Package
DECLARE @StrSrcModule 	as varchar(3)          	--Source  Module
DECLARE @StrSrcTable 	as varchar(3)          	--Source  Table
DECLARE @StrTargetAppl	as varchar(15)		--Target Application
DECLARE @StrSourceAppl	as varchar(15)		--Source Application
DECLARE @StrStdVersion	as varchar(4)		--Standard Version
DECLARE @StrStdRelease	as varchar(2)		--Standard Release
DECLARE @StrStdCustomer	as varchar(4)		--Standard Customer
DECLARE	@StrDevVersion	as varchar(4)		--Development Version
DECLARE	@StrDevRelease	as varchar(2)		--Development Release
DECLARE	@StrDevCustomer	as varchar(4)		--Development Customer
DECLARE @StrSCM		as varchar(1)		--Is SCM enabled?
DECLARE @StrText	as varchar(1024)	--To hold the Text value
DECLARE @CurrDateTime	as DateTime		--Current Date & time
DECLARE @StrTemp	as varchar(1024)	--Temp String to write data into he Log file
DECLARE	@StrComment	as varchar(2000)	--Variable to hold Pretext
DECLARE @StrStatus	as varchar(1)		--Status
/* STEP 1: Get the Target Application Name & mprf VRC details.*/
SELECT 	@StrTargetAppl 	= [dbo].[bcmap100].tapp,
	@StrSourceAppl	= [dbo].[bcmap100].sapp,
	@StrStdVersion	= [dbo].[bcmap100].vers,
	@StrStdRelease	= [dbo].[bcmap100].rele,
	@StrStdCustomer	= [dbo].[bcmap100].cust,
	@StrSCM		= [dbo].[bcmap100].scme
FROM 	[dbo].[bcmap100]
WHERE 	[dbo].[bcmap100].mprf 	= @I_IntMprf
/* STEP 2. Get the Development VRC from BCMAP 105 */
SELECT 	@StrDevVersion	= [dbo].[bcmap105].dver,
	@StrDevRelease	= [dbo].[bcmap105].drel,
	@StrDevCustomer	= [dbo].[bcmap105].dcus
FROM	[dbo].[bcmap105]
WHERE	[dbo].[bcmap105].mprf = @I_IntMprf
AND	[dbo].[bcmap105].vers = @StrStdVersion
AND	[dbo].[bcmap105].rele = @StrStdRelease
AND	[dbo].[bcmap105].cust = @StrStdCustomer

--If there is no Dev. VRC then set the Var to empty
SET @StrDevVersion = ISNULL(@StrDevVersion,'')
SET @StrDevRelease = ISNULL(@StrDevRelease,'')
SET @StrDevCustomer = ISNULL(@StrDevCustomer,'')
SET @CurrDateTime = GETDATE()
EXEC Write_to_file '***********************************************************************************************************************', @I_StrLogFileName
SET @StrTemp=  'START  Default Mapping Generation for FINE TUNED TABLES ' + CHAR(9) + + ' START TIME ' + CAST(@CurrDateTime as varchar)
EXEC Write_to_file @StrTemp, @I_StrLogFileName
SET @StrTemp =  'Range FROM ' +	@I_StrPackFrom 	+ @I_StrModFrom + @I_StrTableFrom + '  TO   '  +
						@I_StrPackTo 	+ @I_StrModTo	+ @I_StrTableTo
EXEC Write_to_file @StrTemp, @I_StrLogFileName

SET @StrTemp = 'Migration Profile- '  +  LTRIM(STR(@I_IntMprf))
EXEC Write_to_file @StrTemp, @I_StrLogFileName
SET @StrTemp =   'Run Number- '  +  LTRIM(STR(@I_IntRunn))
EXEC Write_to_file @StrTemp, @I_StrLogFileName
SET @StrTemp =  'User Name- '  + @I_UserName
EXEC Write_to_file @StrTemp, @I_StrLogFileName
EXEC Write_to_file '***********************************************************************************************************************', @I_StrLogFileName
SET @IntTableCount = 0
/*Generate Default Mappings for Unchanged and  Changed  Tables*/
/* STEP 3: Select all the records from BCDDC141 (Fine Tuned Table) which are within the Range*/
DECLARE DDC141_Cursor CURSOR FOR
SELECT 	[dbo].[bcddc141].spac,
	[dbo].[bcddc141].smod,
	[dbo].[bcddc141].slno,
	[dbo].[bcddc141].tpac,
	[dbo].[bcddc141].tmod,
	[dbo].[bcddc141].tlno
FROM 	[dbo].[bcddc141]
WHERE	[dbo].[bcddc141].runn = @I_IntRunn
AND 	([dbo].[bcddc141].tpac  BETWEEN   @I_StrPackFrom AND  @I_StrPackTo )
AND	([dbo].[bcddc141].tmod  BETWEEN   @I_StrModFrom  AND  @I_StrModTo  )
AND	([dbo].[bcddc141].tlno  BETWEEN	  @I_StrTableFrom AND @I_StrTableTo)
OPEN DDC141_Cursor
FETCH NEXT FROM DDC141_Cursor
INTO   @StrSrcPackage, @StrSrcModule, @StrSrcTable,@StrTrgPackage, @StrTrgModule, @StrTrgTable
WHILE @@FETCH_STATUS = 0
BEGIN
	SET @StrComment = ''
	SET @StrStatus = ''

	/* If some mappings are present for the given Range (@RecCntMAP120 <> 0) then check
	   whether mapping present for the Curent Table. If no mappings then Generate */
	SELECT 	@StrComment= [dbo].[bcmap120].comt,
		@StrStatus = [dbo].[bcmap120].stat
	FROM   	[dbo].[bcmap120]
	WHERE  	[dbo].[bcmap120].mprf 	= 	@I_IntMprf
	AND	[dbo].[bcmap120].vers 	= 	@StrStdVersion
	AND	[dbo].[bcmap120].rele 	= 	@StrStdRelease
	AND	[dbo].[bcmap120].cust 	= 	@StrStdCustomer
	AND  	[dbo].[bcmap120].tcpac 	=	@StrTrgPackage
	AND	[dbo].[bcmap120].tcmod 	=	@StrTrgModule
	AND	[dbo].[bcmap120].tflno 	=	@StrTrgTable

	SET @StrComment = ISNULL(@StrComment,'')
	SET @StrStatus = ISNULL(@StrStatus,'')


	IF (@StrStatus ='' OR @StrStatus ='N')
	BEGIN
		--check whether a rec. is there in DVRC.
		--If DVRC is present then Skip.
		SELECT 	@IntCount = Count(*)
		FROM   	[dbo].[bcmap120]
		WHERE  	[dbo].[bcmap120].mprf 	=	@I_IntMprf
		AND  	[dbo].[bcmap120].tcpac 	=	@StrTrgPackage
		AND	[dbo].[bcmap120].tcmod 	=	@StrTrgModule
		AND	[dbo].[bcmap120].tflno 	=	@StrTrgTable
		AND	[dbo].[bcmap120].vers	=	@StrDevVersion
		AND	[dbo].[bcmap120].rele	=	@StrDevRelease
		AND	[dbo].[bcmap120].cust	=	@StrDevCustomer

		IF (@IntCount > 0)
		BEGIN
			--Write in Log file - Mapping Already Exist
			SET @StrTemp = char(9) +'Mapping Exists for the ' +  	@StrTrgPackage      +
										@StrTrgModule       +
										@StrTrgTable 	 +
					       ' In the Development VRC - ' +
										@StrDevVersion 	 +
										@StrDevRelease   +
										@StrDevCustomer
			EXEC Write_to_file @StrTemp, @I_StrLogFileName

			FETCH NEXT FROM DDC141_Cursor
			INTO   @StrSrcPackage, @StrSrcModule, @StrSrcTable,@StrTrgPackage, @StrTrgModule, @StrTrgTable
			CONTINUE
		END

	END
	ELSE
	BEGIN
		IF ( @StrStatus <> 'N')
		BEGIN
			SET @StrTemp = char(9)+ 'Mapping Exists for the ' +  	@StrTrgPackage   +
										@StrTrgModule    +
										@StrTrgTable 	 +
					       ' in the Standard VRC - ' +
										@StrStdVersion 	 +
										@StrStdRelease    +
										@StrStdCustomer   +
					       ' with the status - '  +  @StrStatus

			EXEC Write_to_file @StrTemp, @I_StrLogFileName
			FETCH NEXT FROM DDC141_Cursor
			INTO   @StrSrcPackage, @StrSrcModule, @StrSrcTable,@StrTrgPackage, @StrTrgModule, @StrTrgTable
			CONTINUE
		END
	END

	--Start Updating the Records
	BEGIN TRANSACTION 	--Start the Transaction for this Table
	SET @StrTableName = @StrSrcPackage + @StrSrcModule + @StrSrcTable
	-- STEP 5: Insert a New Record in BCMAP120 And 130
	/* Insert the "Migrate <TableName> Record in BCMAP120*/

	SET @StrText =  'migrate ' + @StrTableName



	EXEC	@IntRetVal =  sp_insert_bcmap120_1 	@I_IntMprf,		--Migration Profile  				'',			--Variables						'',			--Variables
							@StrStdVersion,         --Version            				@StrComment,		--Comments 						@StrComment,		--Comments
							@StrStdRelease,         --Release            				@StrTableName		--Source Table						@StrTableName		--Source Table
							@StrStdCustomer,        --Customer
							@StrTrgPackage,         --Package
							@StrTrgModule,          --Module
							@StrTrgTable,           --Table
							@StrText,               --Precondition Text
							'',                     --Check out User
							@I_UserName,            --Last Modified User
							@CurrDateTime,          --Date
							'G',                    --Status
							'',			--Variables
							@StrComment,		--Comments
							@StrTableName		--Source Table
	IF @IntRetVal <> 0
	BEGIN
		-- ERROR Encountered ROLLBACK and Continue with the Next Table
		SELECT @StrTemp = [master].[dbo].[sysmessages].description
		FROM   [master].[dbo].[sysmessages]
		WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

		SET @StrTemp = char(9) + 'Error -' + @StrTemp + ' -  while inserting  the record ' +
					 ' MPRF - '   + STR(@I_IntMprf)	+  ' ' +
				         ' VRC  - '   + @StrStdVersion	+  '-' +
			                                @StrStdRelease	+  '-' +
			                                @StrStdCustomer	+
					 ' TABLE - '  +	@StrTrgPackage	+
			                                @StrTrgModule	+
			                                @StrTrgTable	+  ' ' +
			                ' into BCMAP120. '
		EXEC Write_to_file @StrTemp, @I_StrLogFileName

		ROLLBACK TRANSACTION
		FETCH NEXT FROM DDC141_Cursor
		INTO   @StrSrcPackage, @StrSrcModule, @StrSrcTable,@StrTrgPackage, @StrTrgModule, @StrTrgTable
		CONTINUE
	END
	/* Insert 2 Records in BCMAP130
		1. For Select  - Select * from <TableName>
		2. SelectDo    - Dump 1*/

	SET @StrText =  'select  '  + @StrSrcPackage + @StrSrcModule + @StrSrcTable + '.*  from ' + @StrSrcPackage + @StrSrcModule + @StrSrcTable
	EXEC @IntRetVal = sp_insert_bcmap130_1 		@I_IntMprf,		--Migration Profile
							@StrStdVersion,         --Version
							@StrStdRelease,         --Release
							@StrStdCustomer,        --Customer
							@StrTrgPackage,         --Target Package
							@StrTrgModule,          --Target Module
							@StrTrgTable,           --Target Table
							@StrSrcPackage,         --Source Package
							@StrSrcModule,          --Source Module
							@StrSrcTable,           --Source Table
							'S',                    --Code for Text S/D/F/X
							@StrText                --The Text -Query

	IF @IntRetVal <> 0
	BEGIN
		--ERROR Encountered ROLLBACK and Continue with the Next Table
		SELECT @StrTemp = [master].[dbo].[sysmessages].description
		FROM   [master].[dbo].[sysmessages]
		WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

		SET @StrTemp = char(9) + ' Error -' + @StrTemp + ' -  while inserting  the record ' +
					 ' MPRF - '   + STR(@I_IntMprf)	+  ' ' +
				         ' VRC  - '   + @StrStdVersion	+  '-' +
			                                @StrStdRelease	+  '-' +
			                                @StrStdCustomer	+
					 ' TABLE - '  +	@StrTrgPackage	+
			                                @StrTrgModule	+
			                                @StrTrgTable	+  ' ' +
			                 ' CODE - S ' +
			                 ' into BCMAP130. '
		EXEC Write_to_file @StrTemp, @I_StrLogFileName

		ROLLBACK TRANSACTION
		FETCH NEXT FROM DDC141_Cursor
		INTO   @StrSrcPackage, @StrSrcModule, @StrSrcTable,@StrTrgPackage, @StrTrgModule, @StrTrgTable
		CONTINUE
	END
	EXEC @IntRetVal = sp_insert_bcmap130_1 		@I_IntMprf,		--Migration Profile
							@StrStdVersion,         --Version
							@StrStdRelease,         --Release
							@StrStdCustomer,        --Customer
						  	@StrTrgPackage,         --Target Package
						  	@StrTrgModule,          --Target Module
						  	@StrTrgTable,           --Target Table
						  	@StrSrcPackage,         --Source Package
						  	@StrSrcModule,          --Source Module
						  	@StrSrcTable,           --Source Table
						  	'D',                    --Code for Text S/D/F/X
						  	'dump 1'		--The Text -Query
	IF @IntRetVal <> 0
	BEGIN
		--ERROR enocuntered ROLLBACK and Continue with the Next Table
		SELECT @StrTemp = [master].[dbo].[sysmessages].description
		FROM   [master].[dbo].[sysmessages]
		WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

		SET @StrTemp = char(9) + ' Error -'   + @StrTemp + ' -  while inserting  the record ' +
					 ' MPRF - '   + STR(@I_IntMprf)	+  ' ' +
				         ' VRC  - '   + @StrStdVersion	+  '-' +
			                                @StrStdRelease	+  '-' +
			                                @StrStdCustomer	+
					 ' TABLE - '  +	@StrTrgPackage	+
			                                @StrTrgModule	+
			                                @StrTrgTable	+  ' ' +
			                 ' CODE - D ' +
			                 ' into BCMAP130. '
		EXEC Write_to_file @StrTemp, @I_StrLogFileName

		ROLLBACK TRANSACTION
		FETCH NEXT FROM DDC141_Cursor
		INTO   @StrSrcPackage, @StrSrcModule, @StrSrcTable,@StrTrgPackage, @StrTrgModule, @StrTrgTable
		CONTINUE
	END
	--If  Migration Profile is SCM enabled then Fill 125 and 135 also.
	IF @StrSCM = 'Y'
	BEGIN
		/* Inser a New Record in BCMAP110*/
		EXEC @IntRetVal = sp_insert_bcmap110_1 		@I_IntMprf,			--Migration Profile
							  	@StrStdVersion,                 --Version
							  	@StrStdRelease,                 --Release
							  	@StrStdCustomer,                --Customer
								@StrTrgPackage,                 --Package
								@StrTrgModule,                  --Module
								@StrTrgTable,                   --Table
							  	1,                              --Revision No.
							  	' Default Generation ' ,        --Revision Info.
								'DEFAULT',                      --Issue ID
								@CurrDateTime,                  --Date & Time
								0,                              --Patch NOT Exported(0)/Exported(1)
								@I_UserName                     --User Name

		IF @IntRetVal <> 0
		BEGIN
			--ERROR Encountered: ROLLBACK and Continue with the Next Table
			SELECT @StrTemp = [master].[dbo].[sysmessages].description
			FROM   [master].[dbo].[sysmessages]
			WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

			SET @StrTemp = char(9) + ' Error -'   + @StrTemp + ' -  while inserting  the record ' +
						 ' MPRF - '   + STR(@I_IntMprf)	+  ' ' +
					         ' VRC  - '   + @StrStdVersion	+  '-' +
				                                @StrStdRelease	+  '-' +
				                                @StrStdCustomer	+
						 ' TABLE - '  +	@StrTrgPackage	+
				                                @StrTrgModule	+
				                                @StrTrgTable	+  ' ' +
				                 ' into BCMAP110. '

			EXEC Write_to_file @StrTemp, @I_StrLogFileName

			ROLLBACK TRANSACTION

			FETCH NEXT FROM DDC141_Cursor
			INTO   @StrSrcPackage, @StrSrcModule, @StrSrcTable,@StrTrgPackage, @StrTrgModule, @StrTrgTable

			CONTINUE
		END



		/* Insert a New Record in BCMAP125*/
		SET @StrText =  'Migrate ' + @StrSrcPackage + @StrSrcModule + @StrSrcTable
		EXEC	@IntRetVal = sp_insert_bcmap125_1 	@I_IntMprf,		--Migration Profile
								@StrStdVersion,         --Version
								@StrStdRelease,         --Release
								@StrStdCustomer,        --Customer
								@StrTrgPackage,         --Package
								@StrTrgModule,          --Module
								@StrTrgTable,           --Table
								1,                      --Revision Number
								@StrText,               --Precondition Text
								@I_UserName,            --Last Modified User
								'C',                    --Status
								'',                     --Variables
								@StrTableName           --Source Table

		IF @IntRetVal <> 0
		BEGIN
			--ERROR encountered ROLLBACK and Continue with the Next Table
			SELECT @StrTemp = [master].[dbo].[sysmessages].description
			FROM   [master].[dbo].[sysmessages]
			WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

			SET @StrTemp = char(9) + ' Error -'   + @StrTemp + ' -  while inserting  the record ' +
						 ' MPRF - '   + STR(@I_IntMprf)	+  ' ' +
					         ' VRC  - '   + @StrStdVersion	+  '-' +
				                                @StrStdRelease	+  '-' +
				                                @StrStdCustomer	+
						 ' TABLE - '  +	@StrTrgPackage	+
				                                @StrTrgModule	+
				                                @StrTrgTable	+  ' ' +
				                 ' into BCMAP125. '
			EXEC Write_to_file @StrTemp, @I_StrLogFileName

			ROLLBACK TRANSACTION
			FETCH NEXT FROM DDC141_Cursor
			INTO   @StrSrcPackage, @StrSrcModule, @StrSrcTable,@StrTrgPackage, @StrTrgModule, @StrTrgTable
			CONTINUE
		END
		/* Insert 2 Records in BCMAP135
			1. For Select
			2. SelectDo */
		/* Insert  'Select * from  <TableName> in BCMAP135 */

		SET @StrText =  'Select  '  + @StrSrcPackage + @StrSrcModule + @StrSrcTable + '.*  from ' + @StrSrcPackage + @StrSrcModule + @StrSrcTable
		EXEC @IntRetVal = sp_insert_bcmap135_1 		@I_IntMprf,		--Migration Profile
								@StrStdVersion,         --Version
								@StrStdRelease,         --Release
								@StrStdCustomer,        --Customer
								@StrTrgPackage,         --Target Package
								@StrTrgModule,          --Target Module
								@StrTrgTable,           --Target Table
								@StrSrcPackage,         --Source Package
								@StrSrcModule,          --Source Module
								@StrSrcTable,           --Source Table
								'S',                    --Code for Text S/D/F/X
								1,                      --Revision Code
								@StrText,               --The Text -Query
								@I_UserName,            --User Name
								'C'			--Change Code
		IF @IntRetVal <> 0
		BEGIN
			--ERROR encountered ROLLBACK and Continue with the Next Table
			SELECT @StrTemp = [master].[dbo].[sysmessages].description
			FROM   [master].[dbo].[sysmessages]
			WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

			SET @StrTemp = char(9) + ' Error -' + @StrTemp + ' -  while inserting  the record ' +
						 ' MPRF - '   + STR(@I_IntMprf)	+  ' ' +
					         ' VRC  - '   + @StrStdVersion	+  '-' +
				                                @StrStdRelease	+  '-' +
				                                @StrStdCustomer	+
						 ' TABLE - '  +	@StrTrgPackage	+
				                                @StrTrgModule	+
				                                @StrTrgTable	+  ' ' +
				                 ' CODE - S ' +
				                 ' into BCMAP135. '
			EXEC Write_to_file @StrTemp, @I_StrLogFileName

			ROLLBACK TRANSACTION
			FETCH NEXT FROM DDC141_Cursor
			INTO   @StrSrcPackage, @StrSrcModule, @StrSrcTable,@StrTrgPackage, @StrTrgModule, @StrTrgTable
			CONTINUE
		END
		/* Insert 'dump 1'  text into BCMAP135 */
		EXEC @IntRetVal = sp_insert_bcmap135_1 		@I_IntMprf,		--Migration Profile
								@StrStdVersion,         --Version
								@StrStdRelease,         --Release
								@StrStdCustomer,        --Customer
								@StrTrgPackage,         --Target Package
								@StrTrgModule,          --Target Module
								@StrTrgTable,           --Target Table
								@StrSrcPackage,         --Source Package
								@StrSrcModule,          --Source Module
								@StrSrcTable,           --Source Table
								'D',                    --Code for Text S/D/F/X
								1,                      -- Revision Code
								'dump 1	',              --The Text -Query
								@I_UserName,            --User Name
								'C'                     --Change Code
		IF @IntRetVal <> 0
		BEGIN
			--ERROR encountered ROLLBACK and Continue with the Next Table
			SELECT @StrTemp = [master].[dbo].[sysmessages].description
			FROM   [master].[dbo].[sysmessages]
			WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

			SET @StrTemp = char(9) + ' Error -'   + @StrTemp + ' -  while inserting  the record ' +
						 ' MPRF - '   + STR(@I_IntMprf)	+  ' ' +
					         ' VRC  - '   + @StrStdVersion	+  '-' +
				                                @StrStdRelease	+  '-' +
				                                @StrStdCustomer	+
						 ' TABLE - '  +	@StrTrgPackage	+
				                                @StrTrgModule	+
				                                @StrTrgTable	+  ' ' +
				                 ' CODE - D ' +
				                 ' into BCMAP135. '
			EXEC Write_to_file @StrTemp, @I_StrLogFileName

			ROLLBACK TRANSACTION
			FETCH NEXT FROM DDC141_Cursor
			INTO   @StrSrcPackage, @StrSrcModule, @StrSrcTable,@StrTrgPackage, @StrTrgModule, @StrTrgTable
			CONTINUE
		END
	END
	EXEC @IntRetVal = sp_CreateMappingsForFineTunedChangedTables 	@StrTargetAppl,
									@StrSourceAppl,
									@StrStdVersion,
									@StrStdRelease,
									@StrStdCustomer,
									@StrSCM,
									@I_IntRunn,
									@I_IntMprf,
									@StrSrcPackage,
									@StrSrcModule,
									@StrSrcTable,
									@StrTrgPackage,
									@StrTrgModule,
									@StrTrgTable,
									@I_UserName,
									@I_StrLogFileName
	IF @IntRetVal <> 0
	BEGIN
		--ERROR encountered ROLLBACK and Continue with the Next Table


		ROLLBACK TRANSACTION
		FETCH NEXT FROM DDC141_Cursor
		INTO   @StrSrcPackage, @StrSrcModule, @StrSrcTable,@StrTrgPackage, @StrTrgModule, @StrTrgTable
		CONTINUE
	END
	COMMIT TRANSACTION
	SET @IntTableCount = @IntTableCount + 1
	SET @StrTemp = CHAR(9) + 'Successfully completed Default Mapping generation for - ' + @StrTableName
	EXEC Write_to_file  @StrTemp, @I_StrLogFileName
	FETCH NEXT FROM DDC141_Cursor
	INTO   @StrSrcPackage, @StrSrcModule, @StrSrcTable,@StrTrgPackage, @StrTrgModule, @StrTrgTable
END
CLOSE DDC141_Cursor
DEALLOCATE DDC141_Cursor
IF @IntTableCount = 0
BEGIN
	EXEC Write_to_file '----------------------------------------------------------------------------------------------------------------------',@I_StrLogFileName
	SET @StrTemp = CHAR(9) +  'Default Mapping Generation for FINE TUNED Tables Not Done due to any of the following reasons. '
	EXEC Write_to_file @StrTemp,@I_StrLogFileName
	SET @StrTemp = CHAR(9) + CHAR(9) + '1. Mapping Already exists for the tables in the selcted Range.'
	EXEC Write_to_file @StrTemp, @I_StrLogFileName
	SET @StrTemp = CHAR(9) + CHAR(9) + '2. FINE TUNE was not done for the Tables in the selected Range.'
	EXEC Write_to_file @StrTemp, @I_StrLogFileName
	EXEC Write_to_file '----------------------------------------------------------------------------------------------------------------------',@I_StrLogFileName
END
ELSE
BEGIN
	EXEC Write_to_file '----------------------------------------------------------------------------------------------------------------------',@I_StrLogFileName
	SET @StrTemp = 'Default Mapping Generation (FINE TUNED Tables) is successfully done for = ' + LTRIM(STR(@IntTableCount)) + ' table(s).' + char(9) + 'END TIME   ' + CAST(GETDATE() as varchar)
	EXEC Write_to_file @StrTemp,@I_StrLogFileName
	EXEC Write_to_file '----------------------------------------------------------------------------------------------------------------------',@I_StrLogFileName
END
RETURN @@ERROR



GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO



/****** Object:  Stored Procedure dbo.sp_CreateMappingForChangedTables    Script Date: 10/6/2003 2:36:55 PM ******/
/****** Object:  Stored Procedure dbo.sp_CreateMappingForChangedTables    Script Date: 8/29/2003 10:56:08 AM ******/
/********************************************************************************
*	NAME:		sp_CreateMappingForChangedTables			*
*	DESCRIPTION:	This stored procedure creates default mappings for all 	*
*			changed tables.						*
*	INPUTS:	The Source Application 						*
*			The Target Application					*
*			The Version Release and Customer			*
*			The Migration Profile					*
*			Whether the Migration profile is SCM enabled?		*
*			DDC Comparison Run number				*
*			The <Package><Module><Table>				*
*	CALLS:		1. sp_insert_bcmap140_1					*
*			2. sp_insert_bcmap145_1					*
*	RETURNS:	ON SUCCESS - -0						*
*			ON ERROR    Value <> 0					*
*	CREATED BY:	S. Anand Kumar						*
* Updated - On 30 /Oct/2001							*
*	-Adding User Name as the Parameter.	@I_UserName			*
* Updated - On2- Nov - 2002							*
*	-Added the Depth field check so that if the Target and the source	*
*	-fields are depth fields, they are mapped accordingly.			*
*	-Removed applying funcions like Left.Align, Right.Align,ToUpper$,	*
*	-ToLower$ functions							*
********************************************************************************/
CREATE PROCEDURE [sp_CreateMappingForChangedTables]
 (
	  @I_StrTargetappl 	[varchar](15),
	  @I_StrSourceappl 	[varchar](15),
	  @I_StrVer  		[varchar](4),
	  @I_StrRel  		[varchar](2),
	  @I_StrCust  		[varchar](4),
	  @I_StrSCM  		[varchar](1),
	  @I_IntRunn  		[int],
	  @I_IntMprf   		[int],
	  @I_StrPackage  	[varchar](2),
	  @I_StrModule   	[varchar](3),
	  @I_StrTable  		[varchar](3),
	  @I_UserName		[varchar](12),
   	  @I_StrLogFileName	[varchar](1024) = "C:\DefaultMapGenLog.txt"
 )
 AS

	 DECLARE @StrField    		as varchar(20)		--Field Name.
	 DECLARE @StrTempField  	as varchar(20)		--Temporary Var. to hold.
	 DECLARE @StrText    		as varchar(1024)	--Text to hold the Generated rule.
	 DECLARE @StrTempTableName  	as varchar(8)		--Temp Var. to hold Table Name.
	 DECLARE @StrTempTableName1 	as varchar(8)		--Temp Var. to hold Table Name.
	 DECLARE @StrSrcDomain  	as varchar(14)		--Var. to Hold Source Domain.
	 DECLARE @StrTrgDomain  	as varchar(14)		--Var. to Hold Target Domain.
	 DECLARE @StrCType   		as varchar(1)		--Var. to hold the Field Type.
	 DECLARE @IntFieldDumpType  	as int			--Var. to hold the Field dump type. (1/2)
	 DECLARE @IntTrgDepth   	as int			--Field Depth	 - Target
	 DECLARE @IntSrcDepth   	as int			--Field Depth	 - source
	 DECLARE @IntRetVal		as int			--Var. to hold the Return Value.
	 DECLARE @StrTemp   		as varchar(1024)	--Temporary Variable
	 DECLARE @StrVarName  		as varchar(100)	 	--Variable to hold the Type 2 variable name.

	 --VARIABLES TO  HOLD THE DOMAIN ATTRIBUTES
	 DECLARE @StrSrcDType  		as varchar(1)		--Source Domain Type
	 DECLARE @IntSrcDLen   		as int			--Source Domain Length
	 DECLARE @StrSrcDAlign  	as varchar(1)		--Source Domain	Align.
	 DECLARE @StrSrcDCase	  	as varchar(1)		--Source Domain	Case.
	 DECLARE @IntSrcDDigb  		as int			--Source Domain Digit before Decimal.
	 DECLARE @IntSrcDDiga  		as int 			--Source Domain Digit After Decimal.
	 DECLARE @StrSrcMan   		as varchar(1)		--Source Domain - Mandatory or not?
	 DECLARE @StrSrcInitialValue	as nvarchar(60)		--Initial Value of the Target Field


	 DECLARE @StrTrgDType  		as varchar(1)		--Target Domain Type
	 DECLARE @IntTrgDLen   		as int       		--Target Domain Length
	 DECLARE @StrTrgDAlign  	as varchar(1)		--Target Domain	Align.
	 DECLARE @StrTrgDCase	  	as varchar(1)		--Target Domain	Case.
	 DECLARE @IntTrgDDigb  		as int       		--Target Domain Digit before Decimal.
	 DECLARE @IntTrgDDiga  		as int       		--Target Domain Digit After Decimal.
	 DECLARE @StrTrgMan   		as varchar(1)		--Target Domain - Mandatory or not?
	 DECLARE @StrTrgInitialValue	as nvarchar(60)		--Initial Value of the Target Field

	 /*STEP 1. Get all the Unchanged/Changed and New Fields Records from BCDDC150*/

	 DECLARE DDC150_Cursor CURSOR FOR

	 SELECT 	[dbo].[bcddc150].fdnm,
			[dbo].[bcddc150].sddo,
			[dbo].[bcddc150].tddo,
			[dbo].[bcddc150].sdep,
			[dbo].[bcddc150].tdep,
			[dbo].[bcddc150].ctyp,
			[dbo].[bcddc150].sman,
			[dbo].[bcddc150].tman,
  			[dbo].[bcddc150].sini,
  			[dbo].[bcddc150].tini
	 FROM   	[dbo].[bcddc150]
	 WHERE 		[dbo].[bcddc150].runn  = @I_IntRunn AND [dbo].[bcddc150].ctyp <> 'R'
	 AND    	[dbo].[bcddc150].cpac  = @I_StrPackage
	 AND  		[dbo].[bcddc150].cmod  = @I_StrModule
	 AND  		[dbo].[bcddc150].flno  = @I_StrTable
	 AND 		[dbo].[bcddc150].tcom  = 'N'
	 ORDER BY  	[dbo].[bcddc150].fdnm,
	   		[dbo].[bcddc150].ctyp

	 OPEN DDC150_Cursor
	 SET @IntTrgDepth	  = 0
	 SET @IntSrcDepth	  = 0
	 FETCH NEXT FROM DDC150_Cursor
	 INTO    @StrField, @StrSrcDomain, @StrTrgDomain,@IntSrcDepth, @IntTrgDepth,
		 @StrCType,@StrSrcMan, @StrTrgMan,@StrSrcInitialValue, @StrTrgInitialValue

	 WHILE 	  @@FETCH_STATUS = 0
	 BEGIN
		  SET @StrSrcDType  	=''
		  SET @IntSrcDLen 	=0
		  SET @StrSrcDAlign 	=''
		  SET @IntSrcDDigb 	=0
		  SET @IntSrcDDiga      =0
		  SET @StrSrcDCase	=''

		  SET @StrTrgDType  	=''
		  SET @IntTrgDLen 	=0
		  SET @StrTrgDAlign 	=''
		  SET @IntTrgDDigb 	=0
		  SET @IntTrgDDiga 	=0
		  SET @StrTrgDCase	=''

		  SET @StrTempField = @StrField

		  /*Get the Source Domain Information */
	  	  SELECT    @StrSrcDType  	= [dbo].[bcddi220].type,
			    @IntSrcDLen 	= [dbo].[bcddi220].leng,
			    @StrSrcDAlign 	= [dbo].[bcddi220].adju,
			    @IntSrcDDigb 	= [dbo].[bcddi220].digb,
			    @IntSrcDDiga 	= [dbo].[bcddi220].diga,
			    @StrSrcDCase	= [dbo].[bcddi220].conv
		  FROM      [dbo].[bcddi220]
		  WHERE     [dbo].[bcddi220].appl = @I_StrSourceappl
		  AND  	    (([dbo].[bcddi220].cpac + [dbo].[bcddi220].cdom) = @StrSrcDomain)

		  /*Get the TARGET Domain Information */
		  SELECT    @StrTrgDType  	= [dbo].[bcddi220].type,
			    @IntTrgDLen 	= [dbo].[bcddi220].leng,
			    @StrTrgDAlign 	= [dbo].[bcddi220].adju,
			    @IntTrgDDigb 	= [dbo].[bcddi220].digb,
			    @IntTrgDDiga 	= [dbo].[bcddi220].diga,
			    @StrTrgDCase 	= [dbo].[bcddi220].conv
		  FROM      [dbo].[bcddi220]
		  WHERE     [dbo].[bcddi220].appl = @I_StrTargetappl
		  AND       (([dbo].[bcddi220].cpac + [dbo].[bcddi220].cdom) = @StrTrgDomain)

		  WHILE @IntTrgDepth >= 0
		  BEGIN
			SET @StrSrcDType 	= ISNULL(@StrSrcDType,'0')
			SET @IntSrcDLen 	= ISNULL(@IntSrcDLen,0)
			SET @StrSrcDAlign 	= ISNULL(@StrSrcDAlign,'')
			SET @StrSrcDCase 	= ISNULL(@StrSrcDCase,'')
			SET @IntSrcDDigb 	= ISNULL(@IntSrcDDigb,0)
			SET @IntSrcDDiga	= ISNULL(@IntSrcDDiga,0)
			SET @StrSrcInitialValue = ISNULL(@StrSrcInitialValue,'0')
			SET @StrTrgDType 	= ISNULL(@StrTrgDType,'0')
			SET @IntTrgDLen 	= ISNULL(@IntTrgDLen,0)
			SET @StrTrgDAlign 	= ISNULL(@StrTrgDAlign,'')
			SET @StrTrgDCase 	= ISNULL(@StrTrgDCase,'')
			SET @IntTrgDDigb 	= ISNULL(@IntTrgDDigb,0)
			SET @IntTrgDDiga 	= ISNULL(@IntTrgDDiga,0)
			SET @StrTrgInitialValue = ISNULL(@StrTrgInitialValue,'0')


			   /* The Depth of the Field is > 0. So all these Field are assigned Default Values*/
			   IF  @IntTrgDepth > @IntSrcDepth
			   BEGIN
-- Cycle3 .so			IF @StrTrgDType = 'S' OR @StrTrgDType = 'M'
--				BEGIN
--					IF @StrTrgInitialValue = '0'
--					BEGIN
--						SET @StrTrgInitialValue = 'String.Set$("",' + LTRIM(STR(@IntTrgDLen)) + ')'
--					END
--				END
--
--		        	SET @StrText = CASE @StrTrgDType
--						        WHEN 'B' THEN @StrTrgInitialValue
--						        WHEN 'I' THEN @StrTrgInitialValue
--						        WHEN 'L' THEN @StrTrgInitialValue
--						        WHEN 'D' THEN @StrTrgInitialValue
--						        WHEN 'F' THEN @StrTrgInitialValue
--						        WHEN 'S' THEN @StrTrgInitialValue
--						        WHEN 'E' THEN @StrTrgInitialValue
--						        WHEN 'T' THEN 'utc(0,0,2)'
--						        WHEN 'U' THEN @StrTrgInitialValue
--						        WHEN 'M' THEN @StrTrgInitialValue
--						        WHEN 'K' THEN 'utc(0,0)'
--						        ELSE '0'
-- Cycle3 .eo		 		          	  END
				SET @StrText = 'default()' -- Cycle3 .n
			     	SET @IntFieldDumpType = 0
				SET @StrField = @StrTempField + '(' +  LTRIM(STR(@IntTrgDepth)) + ')'
			   END

			   ELSE
			   BEGIN

				     IF @IntTrgDepth >= 1
				     BEGIN
					SET @StrField = @StrTempField + '(' + LTRIM(STR(@IntTrgDepth)) + ')'
					--check whether the Target is a string. If so add "1,1" to the value
					IF @StrTrgDType = 'S' or @StrTrgDType = 'M'
					BEGIN
						SET @StrText= @I_StrPackage + @I_StrModule + @I_StrTable  +  '.'  + @StrTempField + '(1,' + LTRIM(STR(@IntTrgDepth)) + ')'
					END
					ELSE
					BEGIN
						SET @StrText= @I_StrPackage + @I_StrModule + @I_StrTable  +  '.'  + @StrField
					END
				     END
				     /* The Field is a New Field. So Map Default Values for it.*/
				     IF @StrCType = 'N'
				     BEGIN
-- Cycle3 .so					IF @StrTrgDType = 'S' OR @StrTrgDType = 'M'
--						BEGIN
--							IF @StrTrgInitialValue = '0'
--							BEGIN
--								SET @StrTrgInitialValue = 'String.Set$("",' + LTRIM(STR(@IntTrgDLen)) + ')'
--							END
--						END
--					       	SET @StrText = CASE @StrTrgDType
--								WHEN 'B' THEN @StrTrgInitialValue
--							        WHEN 'I' THEN @StrTrgInitialValue
--							        WHEN 'L' THEN @StrTrgInitialValue
--							        WHEN 'D' THEN @StrTrgInitialValue
--							        WHEN 'F' THEN @StrTrgInitialValue
--							        WHEN 'S' THEN @StrTrgInitialValue
--							        WHEN 'E' THEN @StrTrgInitialValue
--							        WHEN 'T' THEN 'utc(0,0,2)'
--							        WHEN 'U' THEN @StrTrgInitialValue
--							        WHEN 'M' THEN @StrTrgInitialValue
--							        WHEN 'K' THEN 'utc(0,0)'
--							        ELSE '0'
-- Cycle3 .eo					END
						SET @StrText = 'default()' -- Cycle3 .n
					       	SET @IntFieldDumpType=0
				     END

				     /* The Field is Changed or Unchanged one*/
				     IF @StrCType = 'U' OR @StrCType = 'C'
				     BEGIN

					       SET @StrText = @I_StrPackage + @I_StrModule + @I_StrTable +  '.'  + @StrField

					       /* 1. Target is ENUM  Dataype  */
					       IF @StrTrgDType  = 'E'
					       BEGIN
						         SET @StrText = CASE  @StrSrcDType
								            WHEN 'E'  THEN  @StrText --Enum Data Type
								            WHEN 'I'  THEN  @StrText --INT Data Type
								            WHEN 'L'  THEN  @StrText --INT Data Type
-- Cycle3 .o								    ELSE @StrTrgInitialValue  --Initial Value
									    ELSE 'default()'  --Initial Value -- Cycle3 .n
								        END
					       END

					       /* 2. Target is STRING DataType
					       IF @StrTrgDType = 'S'
					       BEGIN*/
						         /* Check for the  ALignment */
							 /* Done in XML generation */

						         /* check for the Case */
						         /* done is XML Generation */
					       /*END*/


					       /* 3. Target is UTC Datatype */
					       IF @StrTrgDType = 'K'
					       BEGIN
						         Set @StrText = CASE  	@StrSrcDType
								        WHEN 'T'  THEN  'utc(' + @StrText +',2)'     --Date Data Type
								        WHEN 'K'  THEN  'utc.utc(' + @StrText +')'     --UTC Data Type
-- Cycle3 .o								ELSE 'utc(0,0)'
									ELSE 'empty()' -- Empty value -- Cycle3 .n
							           	END
					       END

					       /* 4. Target is BYTE Datatype */
					       IF @StrTrgDType = 'B'
					       BEGIN
						         --SET @StrText = 'to.byte(' + @StrText + ')'
						         SET @StrText = @StrText
					       END

					       /* 5. Target is INTEGER / LONG Datatype */
					       IF @StrTrgDType = 'I' OR  @StrTrgDType ='L'
			                      	       BEGIN
						               SET @StrText = 	CASE @StrSrcDType
						             		    	WHEN 'I' THEN @StrText
					                           		WHEN 'L' THEN @StrText
-- Cycle3 .o						                        ELSE '0' + '|Source field is of diff. Data types'
										ELSE 'empty()' -- Cycle3 .n
			             				             	END

					       END

		                   	      /* 6. Target is FLOAT /DOUBLE Datatype */
		                   	      IF @StrTrgDType = 'F' OR @StrTrgDType ='D'
		                   	      BEGIN
		                    	       	SET @StrText = CASE @StrSrcDType
						             	     	WHEN 'D' THEN @StrText
		        	                			  	WHEN 'F' THEN @StrText
-- Cycle3 .o		                	         	  		ELSE '0' + '|Source field is of diff. Data types'
										ELSE 'empty()' -- Cycle3 .n
			        	                	  	END

		                   	       END


					       /* 7. Target is DATE Datatype */
					       IF @StrTrgDType = 'T'
					       BEGIN
					       		SET @StrText =   CASE @StrSrcDType
-- Cycle3 .o					                	        WHEN 'T'  THEN 'utc('+ @StrText + '0,2)' --Source is Date
										WHEN 'T'  THEN 'utc('+ @StrText + ',0,2)' --Source is Date -- Cycle3 .n
                        							WHEN 'K'  THEN 'date.utc(' + @StrText + ')' --source is UTC
-- Cycle3 .o			                          			ELSE 'utc(0,0,2)'
										ELSE 'empty()' -- Cycle3 .n
					                         	 END
					       END

					       /* 8. Target is MULTI BYTE DataType */

					       /*IF @StrTrgDType = 'M'
					       BEGIN*/
					       		/* Handled in XML Generation */
					       /*END*/


			                       /* Check for TARGET Mandatory and SOURCE NOT Mandatory */
			                       IF @StrTrgMan = 'M' and @StrSrcMan ='N'
					       BEGIN

			      				SET @StrVarName = 'var.' + @I_StrPackage + @I_StrModule + @I_StrTable +  '.'  + @StrField

				                	SET @StrTemp = CASE @StrTrgDType
								            WHEN 'B' THEN '0'
								            WHEN 'I' THEN '0'
								            WHEN 'L' THEN '0'
								            WHEN 'D' THEN '0'
								            WHEN 'F' THEN '0'
								            WHEN 'S' THEN  'String.Set$("",' + LTRIM(STR(@IntTrgDLen)) + ')'
								            WHEN 'E' THEN  '0'
								            WHEN 'T' THEN  'utc(0,0,2)'
								            WHEN 'U' THEN  '0'
								            WHEN 'M' THEN  'String.Set$("",' + LTRIM(STR(@IntTrgDLen)) + ')'
								            WHEN 'K' THEN  'utc(0,0)'
									    ELSE '0'
								       END

					           	/* WRITE THE TEXT FOR THE FIELD OF TYPE 2
							 if isspace(Field) then
						            	Var.FieldName = Default Value
					              	endif */

				                	SET @StrText = '|* The Target field is a Mandatory Field but the Source is' + char(13) + char(10) +
				            			       '|* Not a Mandatory Field. So  Default Value is Filled here.' + char(13) + char(10) +
				            			       char(9) + 'if isspace(' +  @StrText + ') then' + char(13)  + char(10) +
					           		       char(9) + char(9) + @StrVarName + '=' + @StrTemp + char(13)  + char(10) +
					           		       char(9) + 'endif'

					         	SET @IntFieldDumpType = 1
					        END
					        ELSE
					        BEGIN
						         SET @StrVarName = ''
						         SET @StrTemp = ''
						         SET @IntFieldDumpType=0
					        END
		                     END  --IF @StrCType = 'U' OR @StrCType = 'C'  END

			   END  -- ELSE of @IntTrgDepth > 0 END

			   --Insert the Field values into BCMAP140

			   EXEC @IntRetVal = sp_insert_bcmap140_1 	@I_IntMprf,		--Migration Profile
					   				@I_StrVer,		--Version
					   				@I_StrRel,		--Release
					   				@I_StrCust,		--Customer
				   					@I_StrPackage,		--Package
				   					@I_StrModule,		--Module
				        			 	@I_StrTable,		--Table
							        	1,			--Dump Number
						        		@StrField,		--Field Name
						        		@StrText,		--Field Value - Text
							        	@IntFieldDumpType,	--Type of the Value Type 0/1
							        	'N'			-- N- Not Approved  Rule not Approved

			   IF (@IntRetVal <> 0)
			   BEGIN
				-- Error So BREAK
				SELECT @StrTemp = [master].[dbo].[sysmessages].description
				FROM   [master].[dbo].[sysmessages]
				WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

				SET @StrTemp = ' Error -' + @StrTemp + ' -  while inserting  the record -' +
						 ' MPRF - '   + STR(@I_IntMprf)	+  ' ' +
					         ' VRC  - '   + @I_StrVer	+  '-' +
				                                @I_StrRel	+  '-' +
				                                @I_StrCust	+
						 ' TABLE - '  +	@I_StrPackage	+
				                                @I_StrModule	+
				                                @I_StrTable	+  ' ' +
				                 ' FIELD - '  + @StrField  	+
				                 ' into BCMAP140. '

				EXEC Write_to_file @StrTemp, @I_StrLogFileName
			   	BREAK
			   END

			   --If the Profile is SCM enabled then  Insert another Record in BCMAP145
			   IF @I_StrSCM = 'Y'
			   BEGIN
			    	EXEC @IntRetVal =sp_insert_bcmap145_1 	@I_IntMprf,		--Migration Profile
				    					@I_StrVer,              --Version
				    					@I_StrRel,              --Release
				    					@I_StrCust,             --Customer
			    						@I_StrPackage,          --Package
			    						@I_StrModule,           --Module
						            		@I_StrTable,            --Table
						            		1,                      --Dump Number
				            				@StrField,              --Field Name
			            					1,                      --Revision Info
			            					@StrText,               --Field Value - Text
					            			@IntFieldDumpType,      --Tupe of the Value Type 0/1
					            			@I_UserName,            --User Name
			            					'N' ,			--N- Not Approved  Rule not Approved
									'C'			--Status of the Component C- New/Changed
				IF @IntRetVal <> 0
				BEGIN
					-- ERROR So Break
					SELECT @StrTemp = [master].[dbo].[sysmessages].description
					FROM   [master].[dbo].[sysmessages]
					WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

					SET @StrTemp = ' Error -' + @StrTemp + ' -  while inserting  the record -' +
							 ' MPRF - '   + STR(@I_IntMprf)	+  ' ' +
						         ' VRC  - '   + @I_StrVer	+  '-' +
					                                @I_StrRel	+  '-' +
					                                @I_StrCust	+
							 ' TABLE - '  +	@I_StrPackage	+
					                                @I_StrModule	+
					                                @I_StrTable	+  ' ' +
					                 ' FIELD - '  + @StrField  	+
					                 ' into BCMAP145. '

					EXEC Write_to_file @StrTemp, @I_StrLogFileName
					BREAK
				END
			   END

			   SET @IntTrgDepth = @IntTrgDepth - 1
			   IF @IntTrgDepth = 0 BREAK      /*  This is to Avoid one more looping in case the  *
			   				*  Depth of the Field is more than 0.		  */

	  	END  --WHILE @IntTrgDepth > 0 then

		IF @IntRetVal <> 0
		BEGIN
			 CLOSE DDC150_Cursor
			 DEALLOCATE DDC150_Cursor
 			 RETURN @IntRetVal
		END
		 SET @IntTrgDepth	  = 0
		 SET @IntSrcDepth	  = 0

		FETCH NEXT FROM DDC150_Cursor
		INTO    @StrField, @StrSrcDomain, @StrTrgDomain,@IntSrcDepth, @IntTrgDepth, @StrCType,
			@StrSrcMan, @StrTrgMan,@StrSrcInitialValue, @StrTrgInitialValue

	 END   -- WHILE  @@FETCH_STATUS = 0

	 CLOSE DDC150_Cursor
	 DEALLOCATE DDC150_Cursor
	 RETURN @IntRetVal



GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO



/****** Object:  Stored Procedure dbo.sp_CreateMappingForUnchangedTables    Script Date: 10/6/2003 2:36:55 PM ******/
/****** Object:  Stored Procedure dbo.sp_CreateMappingForUnchangedTables    Script Date: 8/29/2003 10:56:08 AM ******/
/********************************************************************************
*	NAME:		sp_CreateMappingForUnchangedTables			*
*	DESCRPTION:	This Stored procedure generates the default mappings    *
*			for Unchaged Tables.					*
*	CALLS:		1. sp_insert_bcmap140_1()				*
*			2. sp_insert_bcmap145_1()				*
*	CALLED BY:	sp_CreateDefaultMappings()				*
*	UPDATION								*
*			-Add a Parameter @I_UserName [varchar](12)-31/Oct/01    *
*			-Replace "root" by @I_UserName	-31/Oct/01 		*
********************************************************************************/
CREATE PROCEDURE [sp_CreateMappingForUnchangedTables]
(
	  @I_StrTargetappl 	[varchar](15),
	  @I_StrSourceappl 	[varchar](15),
	  @I_StrVer  		[varchar](4),
	  @I_StrRel  		[varchar](2),
	  @I_StrCust  		[varchar](4),
	  @I_StrSCM  		[varchar](1),
	  @I_IntRunn  		[int],
	  @I_IntMprf   		[int],
	  @I_StrPackage  	[varchar](2),
	  @I_StrModule   	[varchar](3),
	  @I_StrTable   	[varchar](3),
	  @I_UserName		[varchar](12),
   	  @I_StrLogFileName	[varchar](1024) = "C:\DefaultMapGenLog.txt"
	   )
 AS
	 DECLARE @StrField   		as varchar(15)
	 DECLARE @StrTempField  	as varchar(15)
	 DECLARE @StrText   		as varchar(1024)
	 DECLARE @StrTrgDomain 		as varchar(14)
	 DECLARE @StrTrgDType 		as varchar(1)
	 DECLARE @IntTrgDLen  		as int
	 DECLARE @IntSrcDepth  		as int
	 DECLARE @IntTrgDepth  		as int
	 DECLARE @IntLoopCount 		as int
	 DECLARE @IntRetVal 		as int
	 DECLARE @StrTemp		as varchar(1024)
	 DECLARE @StrTrgInitialValue	as nvarchar(60)

	 SET @IntRetVal = 0

	 /*Get all the Unchanged Tables Records from BCDDC150*/
	 DECLARE DDC150_Cursor CURSOR FOR

	 SELECT  	[dbo].[bcddc150].fdnm,
	   		[dbo].[bcddc150].tddo,
	   		[dbo].[bcddc150].sdep,
	   		[dbo].[bcddc150].tdep,
	   		[dbo].[bcddc150].tini
	 FROM   	[dbo].[bcddc150]
	 WHERE 		[dbo].[bcddc150].runn  	= @I_IntRunn
	 AND   		[dbo].[bcddc150].ctyp 	= 'U'
	 AND    	[dbo].[bcddc150].cpac  	= @I_StrPackage
	 AND  		[dbo].[bcddc150].cmod  	= @I_StrModule
	 AND  		[dbo].[bcddc150].flno  	= @I_StrTable
	 ORDER BY  	[dbo].[bcddc150].fdnm

	 OPEN 	DDC150_Cursor
	 FETCH	NEXT FROM DDC150_Cursor
	 INTO   @StrField, @StrTrgDomain, @IntSrcDepth, @IntTrgDepth, @StrTrgInitialValue

	 WHILE 	@@FETCH_STATUS = 0
	 BEGIN
		  SET @StrTempField = @StrField
 		  SET @StrTrgInitialValue = ISNULL(@StrTrgInitialValue,'0')
		  /*Get the TARGET Domain Information */
		  SELECT 	@StrTrgDType  = [dbo].[bcddi220].type,
		    		@IntTrgDLen = [dbo].[bcddi220].leng
		  FROM  	[dbo].[bcddi220]
		  WHERE 	[dbo].[bcddi220].appl = @I_StrTargetappl
		  AND  		(([dbo].[bcddi220].cpac + [dbo].[bcddi220].cdom) = @StrTrgDomain)


		  /*Check for the Depth of the Field*/
		  WHILE @IntTrgDepth >= 0
		  BEGIN

		  	SET @StrText= @I_StrPackage + @I_StrModule + @I_StrTable  +  '.'  + @StrField

			IF  @IntTrgDepth > @IntSrcDepth
			BEGIN
				IF @StrTrgDType = 'S' OR @StrTrgDType = 'M'
				BEGIN
					IF @StrTrgInitialValue = '0'
					BEGIN
						SET @StrTrgInitialValue = 'empty.string(1;' + LTRIM(STR(@IntTrgDLen)) + ')'
					END
				END
		        	SET @StrText = CASE @StrTrgDType
						        WHEN 'B' THEN @StrTrgInitialValue
						        WHEN 'I' THEN @StrTrgInitialValue
						        WHEN 'L' THEN @StrTrgInitialValue
						        WHEN 'D' THEN @StrTrgInitialValue
						        WHEN 'F' THEN @StrTrgInitialValue
						        WHEN 'S' THEN @StrTrgInitialValue
						        WHEN 'E' THEN @StrTrgInitialValue
						        WHEN 'T' THEN 'utc(0,0,2)'
						        WHEN 'U' THEN @StrTrgInitialValue
						        WHEN 'M' THEN @StrTrgInitialValue
						        WHEN 'K' THEN 'utc(0,0)'
						        ELSE '0'
 		 		          	  END
			     SET @StrField = @StrTempField + '(' + LTRIM(STR(@IntTrgDepth)) + ')'
		        END

			ELSE
			BEGIN

			     IF @IntTrgDepth >= 1
			     BEGIN
				SET @StrField = @StrTempField + '(' +  LTRIM(STR(@IntTrgDepth)) + ')'

				--check whether the Target is a string. If so add "1,1" to the value
				IF @StrTrgDType = 'S' or @StrTrgDType = 'M'
				BEGIN
					SET @StrText= @I_StrPackage + @I_StrModule + @I_StrTable  +  '.'  + @StrTempField + '(1,' +  LTRIM(STR(@IntTrgDepth)) + ')'
				END
				ELSE
				BEGIN
					SET @StrText= @I_StrPackage + @I_StrModule + @I_StrTable  +  '.'  + @StrField
				END
			     END

			     SET @StrText= @StrText
			     SET @StrText = CASE  @StrTrgDType
					        WHEN  'E' THEN  @StrText	--Enum Data Type
					        WHEN  'B' THEN  @StrText 	--Byte Data Type
					        WHEN  'K' THEN  'utc.utc(' + @StrText +')'   --UTC Data Type
						WHEN  'M' THEN  @StrText 	-- Multi - byte
-- Cycle3 .o					WHEN  'T' THEN  'utc(' + @StrText + '0,2)' -- Date
						WHEN  'T' THEN  'utc(' + @StrText + ',0,2)' -- Date --Cycle3 .n
					        ELSE  @StrText
					       END
			     END

			     EXEC @IntRetVal = sp_insert_bcmap140_1
					      @I_IntMprf,  	-- MPRF
					      @I_StrVer,  	--version
					      @I_StrRel,  	--Release
					      @I_StrCust,  	--Customer
					      @I_StrPackage,  	--Package
					      @I_StrModule,  	--Module
					      @I_StrTable ,  	--Table
					      1,   		--Dump Number
					      @StrField,  	--Field Name
					      @StrText,  	--Field  Value
					      0,   		--Type (Hard coded)
					      'N'   		--Not Approved

			     IF @IntRetVal <> 0
			     BEGIN
				SELECT @StrTemp = [master].[dbo].[sysmessages].description
				FROM   [master].[dbo].[sysmessages]
				WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

				SET @StrTemp = ' Error -' + @StrTemp + ' -  while inserting  the record -' +
						 ' MPRF - '   + STR(@I_IntMprf)	+  ' ' +
					         ' VRC  - '   + @I_StrVer	+  '-' +
				                                @I_StrRel	+  '-' +
				                                @I_StrCust	+
						 ' TABLE - '  +	@I_StrPackage	+
				                                @I_StrModule	+
				                                @I_StrTable	+  ' ' +
				                 ' FIELD - '  + @StrField  	+
				                 ' into BCMAP140. '

				EXEC Write_to_file @StrTemp, @I_StrLogFileName
				RETURN @IntRetVal
			     END

			     -- If the Migration Profile is SCM enabled then Insert a rec. in BCMAP145.
			     IF @I_StrSCM = 'Y'
			     BEGIN
				    EXEC @IntRetVal = sp_insert_bcmap145_1
						       @I_IntMprf,  	--Mprf
						       @I_StrVer,  	--version
						       @I_StrRel,  	--Release
						       @I_StrCust,  	--Customer
						       @I_StrPackage,  	--Package
						       @I_StrModule,  	--Module
						       @I_StrTable ,  	--Table
						       1,   		--Dump No.
						       @StrField,  	--Field Name
						       1,   		--Revision Number
						       @StrText,  	--Field  Value
						       0,   		--Hard coded
						       @I_UserName,  	--Login Id
						      'N',  		--Not Approved
						      'C'		--Changed
				    IF @IntRetVal <> 0
				    BEGIN
					SELECT @StrTemp = [master].[dbo].[sysmessages].description
					FROM   [master].[dbo].[sysmessages]
					WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

					SET @StrTemp = ' Error -' + @StrTemp + ' -  while inserting  the record -' +
							 ' MPRF - '   + STR(@I_IntMprf)	+  ' ' +
						         ' VRC  - '   + @I_StrVer	+  '-' +
					                                @I_StrRel	+  '-' +
					                                @I_StrCust	+
							 ' TABLE - '  +	@I_StrPackage	+
					                                @I_StrModule	+
					                                @I_StrTable	+  ' ' +
					                 ' FIELD - '  + @StrField  	+
					                 ' into BCMAP145. '

					EXEC Write_to_file @StrTemp, @I_StrLogFileName
					RETURN @IntRetVal
				    END
			    END

			    SET @IntTrgDepth = @IntTrgDepth - 1
			    IF @IntTrgDepth = 0 BREAK    -- This is to Avoid one more looping
		  END

		  FETCH NEXT FROM DDC150_Cursor
		  INTO   @StrField, @StrTrgDomain, @IntSrcDepth, @IntTrgDepth, @StrTrgInitialValue
	 END

	 CLOSE DDC150_Cursor

	 DEALLOCATE DDC150_Cursor

	 RETURN @IntRetVal



GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO



/****** Object:  Stored Procedure dbo.sp_CreateMappingsForFineTunedChangedTables    Script Date: 10/6/2003 2:36:55 PM ******/
/****** Object:  Stored Procedure dbo.sp_CreateMappingsForFineTunedChangedTables    Script Date: 8/29/2003 10:56:09 AM ******/
/********************************************************************************
*	NAME:		sp_CreateMappingsForFineTunedChangedTables		*
*	DESCRPTION:	This Stored procedure generates default mappings for 	*
*			all fine tuned CHANGED tables.				*
*	INPUTS:		The Source Application 					*
*			The Target Application					*
*			The Version Release and Customer			*
*			The Migration Profile					*
*			Whether the Migration profile is SCM enabled?		*
*			DDC Comparison Run number				*
*			The Source <Package><Module><Table>			*
*			The Target <Package><Module><Table>			*
*	CALLS:		1.sp_insert_bcmap140_1()				*
*			2.sp_insert_bcmap145_1()				*
*	CALLED BY:	sp_CreateDefaultMappings()				*
*	RETURNS:	ON SUCCESS - -0						*
*			ON ERROR    Value <> 0					*
*	CREATED BY:	S. Anand Kumar						*
*	UPDATION:								*
*		- 31/Oct/2001							*
*			- Parameter @I_UserName	[varchar](12) Added		*
*			- Replace "root" by @I_UserName				*
*		-2/Nov/2001							*
*			- Check for the Depth field				*
********************************************************************************/
CREATE PROCEDURE [sp_CreateMappingsForFineTunedChangedTables]
	(
	 @I_StrTargetappl		[varchar](15),
	 @I_StrSourceappl		[varchar](15),
	 @I_StrVer			[varchar](4),
	 @I_StrRel			[varchar](2),
	 @I_StrCust			[varchar](4),
	 @I_StrSCM			[varchar](1),
	 @I_IntRunn			[int],
	 @I_IntMprf 			[int],
	 @I_StrSrcPackage 		[varchar](2),
	 @I_StrSrcModule 		[varchar](3),
	 @I_StrSrcTable 		[varchar](3),
	 @I_StrTrgPackage 		[varchar](2),
	 @I_StrTrgModule 		[varchar](3),
	 @I_StrTrgTable 		[varchar](3),
	 @I_UserName			[varchar](12),
   	 @I_StrLogFileName		[varchar](1024) = "C:\DefaultMapGenLog.txt"
	 )
 AS
	DECLARE @StrField 		as varchar(15)
	DECLARE @StrTempField		as varchar(15)
	DECLARE @StrText 		as varchar(1024)
	DECLARE @StrTempTableName 	as varchar(8)
	DECLARE @StrTempTableName1	as varchar(8)
	DECLARE @StrSrcDomain		as varchar(14)
	DECLARE @StrTrgDomain		as varchar(14)
	DECLARE @Strctype		as varchar(1)
	DECLARE @IntFieldDumpType	as int
	DECLARE @IntRetVal		as int

	--VARIABLES TO  HOLD THE DOMAIN ATTRIBUTES
	DECLARE @StrSrcDType		as varchar(1)
	DECLARE @IntSrcDLen		as int
	DECLARE @StrSrcDAlign		as varchar(1)
	DECLARE @StrSrcDCase		as varchar(1)
	DECLARE @IntSrcDDigb		as int
	DECLARE @IntSrcDDiga		as int
	DECLARE @IntSrcDepth		as int
	DECLARE @IntTrgDepth		as int
	DECLARE @StrSrcMan		as varchar(1)

	DECLARE @StrTrgDType		as varchar(1)
	DECLARE @IntTrgDLen		as int
	DECLARE @StrTrgDAlign		as varchar(1)
	DECLARE @StrTrgDCase		as varchar(1)
	DECLARE @IntTrgDDigb		as int
	DECLARE @IntTrgDDiga		as int
	DECLARE @StrTrgMan		as varchar(1)
	DECLARE @StrTemp		as varchar(1024)
	DECLARE @StrVarName		as varchar(100)
	DECLARE @StrTrgInitialValue	as nvarchar(60)


	/*Get all the Unchanged Tables Records from BCDDC150*/
	DECLARE DDC150_Cursor CURSOR FOR
	SELECT		[dbo].[bcddc150].fdnm,
			[dbo].[bcddc150].sddo,
			[dbo].[bcddc150].tddo,
			[dbo].[bcddc150].sdep,
			[dbo].[bcddc150].tdep,
			[dbo].[bcddc150].ctyp,
			[dbo].[bcddc150].sman,
			[dbo].[bcddc150].tman,
			[dbo].[bcddc150].tini
	FROM 		[dbo].[bcddc150]
	WHERE		[dbo].[bcddc150].runn  = @I_IntRunn
	AND 		[dbo].[bcddc150].ctyp <> 'R'
	AND 		[dbo].[bcddc150].tcom =  'N'
	AND  		[dbo].[bcddc150].cpac  = @I_StrSrcPackage
	AND		[dbo].[bcddc150].cmod  = @I_StrSrcModule
	AND		[dbo].[bcddc150].flno  = @I_StrSrcTable
	AND  		[dbo].[bcddc150].tpac  = @I_StrTrgPackage
	AND		[dbo].[bcddc150].tmod  = @I_StrTrgModule
	AND		[dbo].[bcddc150].tlno  = @I_StrTrgTable
	ORDER BY	[dbo].[bcddc150].fdnm,
			[dbo].[bcddc150].ctyp

	OPEN DDC150_Cursor

	set @IntTrgDepth = 0
	set @IntSrcDepth = 0

	FETCH NEXT FROM DDC150_Cursor
	INTO   	@StrField, @StrSrcDomain, @StrTrgDomain, @IntSrcDepth,@IntTrgDepth,@Strctype,@StrSrcMan, @StrTrgMan,@StrTrgInitialValue

	WHILE @@FETCH_STATUS = 0
	BEGIN
		SET @StrSrcDType 	=''
	        SET @IntSrcDLen		=0
		SET @StrSrcDAlign	=''
		SET @IntSrcDDigb	=0
		SET @IntSrcDDiga        =0
		SET @StrSrcDCase	=''

		SET @StrTrgDType 	=''
		SET @IntTrgDLen		=0
		SET @StrTrgDAlign	=''
		SET @StrTrgDCase	=''
		SET @IntTrgDDigb	=0
		SET @IntTrgDDiga	=0

		SET @StrTempField = @StrField	-- Store the field Name in a Temporary Variable

		/*Get the Source Domain Information */
		SELECT	@StrSrcDType 	= [dbo].[bcddi220].type,
			@IntSrcDLen	= [dbo].[bcddi220].leng,
			@StrSrcDAlign	= [dbo].[bcddi220].adju,
			@IntSrcDDigb	= [dbo].[bcddi220].digb,
			@IntSrcDDiga	= [dbo].[bcddi220].diga,
			@StrSrcDCase	= [dbo].[bcddi220].conv
		FROM 	[dbo].[bcddi220]
		WHERE	[dbo].[bcddi220].appl = @I_StrSourceappl
		AND	(([dbo].[bcddi220].cpac + [dbo].[bcddi220].cdom) = @StrSrcDomain)

		/*Get the TARGET Domain Information */
		SELECT	@StrTrgDType 	= [dbo].[bcddi220].type,
			@IntTrgDLen	= [dbo].[bcddi220].leng,
			@StrTrgDAlign	= [dbo].[bcddi220].adju,
			@IntTrgDDigb	= [dbo].[bcddi220].digb,
			@IntTrgDDiga	= [dbo].[bcddi220].diga,
			@StrTrgDCase	= [dbo].[bcddi220].conv
		FROM	[dbo].[bcddi220]
		WHERE	[dbo].[bcddi220].appl = @I_StrTargetappl
		AND	(([dbo].[bcddi220].cpac + [dbo].[bcddi220].cdom) = @StrTrgDomain)


		WHILE @IntTrgDepth >= 0
		BEGIN

			SET @StrSrcDType 	= ISNULL(@StrSrcDType,'0')
			SET @IntSrcDLen 	= ISNULL(@IntSrcDLen,0)
			SET @StrSrcDAlign 	= ISNULL(@StrSrcDAlign,'')
			SET @StrSrcDCase 	= ISNULL(@StrSrcDAlign,'')
			SET @IntSrcDDigb 	= ISNULL(@IntSrcDDigb,0)
			SET @IntSrcDDiga	= ISNULL(@IntSrcDDiga,0)
			SET @StrTrgDType 	= ISNULL(@StrTrgDType,'0')
			SET @IntTrgDLen 	= ISNULL(@IntTrgDLen,0)
			SET @StrTrgDAlign 	= ISNULL(@StrTrgDAlign,'')
			SET @StrTrgDCase 	= ISNULL(@StrTrgDAlign,'')
			SET @IntTrgDDigb 	= ISNULL(@IntTrgDDigb,0)
			SET @IntTrgDDiga 	= ISNULL(@IntTrgDDiga,0)
			SET @StrTrgInitialValue	= ISNULL(@StrTrgInitialValue,'0')


			/* The Depth of the Field is > 0. So for all these Field Map Default Values*/
			IF @IntTrgDepth > @IntSrcDepth
				BEGIN
-- Cycle3 .so				IF @StrTrgDType = 'S' OR @StrTrgDType = 'M'
--					BEGIN
--						IF @StrTrgInitialValue = '0'
--						BEGIN
--							SET @StrTrgInitialValue = 'String.Set$("",' + LTRIM(STR(@IntTrgDLen)) + ')'
--						END
--					END
--			        	SET @StrText = CASE @StrTrgDType
--							        WHEN 'B' THEN @StrTrgInitialValue
--							        WHEN 'I' THEN @StrTrgInitialValue
--							        WHEN 'L' THEN @StrTrgInitialValue
--							        WHEN 'D' THEN @StrTrgInitialValue
--							        WHEN 'F' THEN @StrTrgInitialValue
--							        WHEN 'S' THEN @StrTrgInitialValue
--							        WHEN 'E' THEN @StrTrgInitialValue
--							        WHEN 'T' THEN 'utc(0,0,2)'
--							        WHEN 'U' THEN @StrTrgInitialValue
--							        WHEN 'M' THEN @StrTrgInitialValue
--							        WHEN 'K' THEN 'utc(0,0)'
--							        ELSE '0'
-- Cycle3 .eo							END
					SET @StrText = 'default()' -- Cycle3 .n
					SET @IntFieldDumpType = 0
					SET @StrField = @StrTempField + '(' + LTRIM(STR(@IntTrgDepth)) + ')'
				END
			ELSE
				BEGIN
				     IF @IntTrgDepth >= 1
				     BEGIN
					SET @StrField = @StrTempField + '(' + LTRIM(STR(@IntTrgDepth)) + ')'
--					SET @StrText= @I_StrSrcPackage + @I_StrSrcModule + @I_StrSrcTable +  '.'  + @StrField
					--check whether the Target is a string. If so add position no also to the value.
					IF @StrTrgDType = 'S' or @StrTrgDType = 'M'
					BEGIN
						SET @StrText= @I_StrSrcPackage + @I_StrSrcModule + @I_StrSrcTable +  '.'  + @StrTempField + '(1,' + LTRIM(STR(@IntTrgDepth)) + ')'
					END
					ELSE
					BEGIN
						SET @StrText= @I_StrSrcPackage + @I_StrSrcModule + @I_StrSrcTable +  '.'  + @StrField
					END
				     END
					/* The Field is a New Field. So Map Default/Initial Values for it.*/
					IF @Strctype = 'N'
					BEGIN
-- Cycle3 .so					IF @StrTrgDType = 'S' OR @StrTrgDType = 'M'
--						BEGIN
--							IF @StrTrgInitialValue = '0'
--							BEGIN
--								SET @StrTrgInitialValue = 'String.Set$("",' + LTRIM(STR(@IntTrgDLen)) + ')'
--							END
--						END
--				        	SET @StrText = CASE @StrTrgDType
--								        WHEN 'B' THEN @StrTrgInitialValue
--								        WHEN 'I' THEN @StrTrgInitialValue
--								        WHEN 'L' THEN @StrTrgInitialValue
--								        WHEN 'D' THEN @StrTrgInitialValue
--								        WHEN 'F' THEN @StrTrgInitialValue
--								        WHEN 'S' THEN @StrTrgInitialValue
--								        WHEN 'E' THEN @StrTrgInitialValue
--								        WHEN 'T' THEN 'utc(0,0,2)'
--								        WHEN 'U' THEN @StrTrgInitialValue
--								        WHEN 'M' THEN @StrTrgInitialValue
--								        WHEN 'K' THEN 'utc(0,0)'
--								        ELSE '0'
-- Cycle3 .eo								END
						SET @StrText = 'default()' -- Cycle3 .n
						SET @IntFieldDumpType=0
					END
					/* The Field is Changed or Unchanged one*/
					IF @Strctype = 'U' OR @Strctype = 'C'
						BEGIN

							SET @StrText = @I_StrSrcPackage + @I_StrSrcModule + @I_StrSrcTable +  '.'  + @StrField

							/* 1. Target is ENUM  Dataype  */
							IF @StrTrgDType  = 'E'
							BEGIN
								SET @StrText = CASE 	@StrSrcDType
											WHEN 'E'  THEN @StrText	--Enum Data Type
											WHEN 'I'  THEN @StrText	--INT Data Type
											WHEN 'L'  THEN @StrText	--INT Data Type
-- Cycle3 .o										ELSE	'0'
											ELSE	'empty()' -- Cycle3 .n
										END

							END

							/* 2. Target is STRING DataType
							IF @StrTrgDType = 'S'
							BEGIN
								Handled in XML Generation
							END*/


							/* 3. Target is UTC Datatype */
							IF @StrTrgDType = 'K'
								BEGIN
									Set @StrText = CASE 	@StrSrcDType
												WHEN 'T'  THEN	'utc(' + @StrText +',2))'  	  --Date Data Type
												WHEN 'K'  THEN 	'utc.utc(' + @StrText +')'  	  --UTC Data Type
												ELSE	'utc(0,0)'
											END

								END

							/* 4. Target is BYTE Datatype */
							IF @StrTrgDType = 'B'
								BEGIN
									SET @StrText = 'to.byte(' + @StrText + ')'
								END

							/* 5. Target is INTEGER / LONG Datatype */
							IF @StrTrgDType = 'I' OR  @StrTrgDType ='L'
				                		BEGIN
				                			SET @StrText = CASE @StrSrcDType
					                					WHEN 'I' THEN @StrText
				             		   					WHEN 'L' THEN @StrText
-- Cycle3 .o					             					ELSE	'0' + '|Source field is of Different Data type.'
												ELSE	'empty()' -- Cycle3 .o
				             		   				END

					                	END

					                /* 6. Target is FLOAT /DOUBLE Datatype */
					                IF @StrTrgDType = 'F' OR @StrTrgDType ='D'
					                	BEGIN
					                		SET @StrText = CASE @StrSrcDType
					                				WHEN 'D' THEN @StrText
					                				WHEN 'F' THEN @StrText
-- Cycle3 .o					                			ELSE	'0' + '|Source field is of Different Data type.'
											ELSE	'empty()' -- Cycle3 .n
					                				END

					                	END



						       /* 7. Target is DATE Datatype */
						       IF @StrTrgDType = 'T'
						       BEGIN
						       		SET @StrText =   CASE @StrSrcDType
-- Cycle3 .o						                	         WHEN 'T'  THEN 'utc('+ @StrText + '0,2)' --Source is Date
											 WHEN 'T'  THEN 'utc('+ @StrText + ',0,2)' --Source is Date -- Cycle3 .n
	                        							 WHEN 'K'  THEN 'date.utc(' + @StrText + ')' --source is UTC
				                          				 ELSE 'utc(0,0,2)'
						                         	 END
						       END
					                /* 8. Target is MULTI BYTE DataType
					                  --Handled in XML Generation
					                IF @StrTrgDType = 'M'
					                BEGIN
							         IF @StrTrgDAlign = @StrSrcDAlign
							         BEGIN
			  				      	          SET @StrText = @StrText
							         END
							         ELSE
							         BEGIN
								           SET @StrText = CASE @StrTrgDAlign
											        WHEN 'L'  THEN 'Left.Align(' + @StrText + ',' + LTRIM(STR(@IntTrgDLen)) + ')'
										           	WHEN 'R'  THEN 'Right.Align(' + @StrText + ',' + LTRIM(STR(@IntTrgDLen)) + ')'
												ELSE 	 @StrText
								           END

							         END


							        -- check for the Case
							        -- IF @StrTrgDCase = @StrSrcDCase
							         BEGIN
							         	SET @StrText =  @StrText
							         END
							         ELSE
							         BEGIN
							         	SET @StrText  = CASE @StrTrgDCase
							         				WHEN 'U' THEN 'toupper$(' + @StrText + ')'
							         				WHEN 'L' THEN 'tolower$(' + @StrText + ')'
							         				ELSE @StrText
							         			END
							        END

					                	SET @StrText = 'to.native(' + @StrText + ')'
					                END */

					                /* Check for TARGET Mandatory and SOURCE NOT Mandatory */
					                IF @StrTrgMan = 'M' and @StrSrcMan ='N'
					                	BEGIN
						                	SET @StrVarName = 'var.' + @I_StrTrgPackage + @I_StrTrgModule + @I_StrTrgTable +  '.'  + @StrField
									IF @StrTrgDType = 'S' OR @StrTrgDType = 'M'
									BEGIN
										IF @StrTrgInitialValue = '0'
										BEGIN
											SET @StrTrgInitialValue = 'String.Set$("",' + LTRIM(STR(@IntTrgDLen)) + ')'
										END
									END

							        	SET @StrTemp = CASE @StrTrgDType
											        WHEN 'B' THEN @StrTrgInitialValue
											        WHEN 'I' THEN @StrTrgInitialValue
											        WHEN 'L' THEN @StrTrgInitialValue
											        WHEN 'D' THEN @StrTrgInitialValue
											        WHEN 'F' THEN @StrTrgInitialValue
											        WHEN 'S' THEN @StrTrgInitialValue
											        WHEN 'E' THEN @StrTrgInitialValue
											        WHEN 'T' THEN 'utc(0,0,2)'
											        WHEN 'U' THEN @StrTrgInitialValue
											        WHEN 'M' THEN @StrTrgInitialValue
											        WHEN 'K' THEN 'utc(0,0)'
											        ELSE '0'
											END

											/* if isspace(Field) then
												Var.FieldName = Default Value
											   endif */

									SET @StrText = 	'|* The Target field is a Mandatory Field but the Source is' + char(13) + char(10) +
										 	'|* Not a Mandatory Field. So  Default Value is Filled here.' + char(13) + char(10) +
										 	char(9) + 'if isspace(' +  @StrText + ') then' + char(13)  + char(10) +
											char(9) + char(9) + @StrVarName + '=' + @StrTemp + char(13)  + char(10) +
											char(9) + 'endif'
									SET @IntFieldDumpType = 1
								END
							ELSE
								BEGIN
									SET @StrVarName = ''
									SET @StrTemp = ''
									SET @IntFieldDumpType=0
								END
				                END 	--IF @Strctype = 'U' OR @Strctype = 'C'  END
				END 	-- IF @IntTrgDepth > 0 END


			EXEC	@IntRetVal = sp_insert_bcmap140_1 	@I_IntMprf,             --Migration Profile
									@I_StrVer,              --Version
									@I_StrRel,              --Release
									@I_StrCust,             --Customer
									@I_StrTrgPackage,       --Package
									@I_StrTrgModule,        --Module
								  	@I_StrTrgTable,         --Table
								  	1,                      --Dump Number
								  	@StrField,              --Field Name
								  	@StrText,               --Field Value - Text
								  	@IntFieldDumpType,      --Type of the Value Type 0/1
								  	'N'                     -- N- Not Approved  Rule not Approved
			IF  @IntRetVal <> 0
			BEGIN
				-- Error So BREAK
				SELECT @StrTemp = [master].[dbo].[sysmessages].description
				FROM   [master].[dbo].[sysmessages]
				WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

				SET @StrTemp = ' Error -' + @StrTemp + ' -  while inserting  the record -' +
						 ' MPRF - '   + STR(@I_IntMprf)		+  ' ' +
					         ' VRC  - '   + @I_StrVer		+  '-' +
				                                @I_StrRel		+  '-' +
				                                @I_StrCust		+
						 ' TABLE - '  +	@I_StrTrgPackage	+
				                                @I_StrTrgModule		+
				                                @I_StrTrgTable		+  ' ' +
				                 ' FIELD - '  + @StrField  		+
				                 ' into BCMAP140. '

				EXEC Write_to_file @StrTemp, @I_StrLogFileName

				CLOSE DDC150_Cursor
				DEALLOCATE DDC150_Cursor

				RETURN @IntRetVal
			END

			IF @I_StrSCM = 'Y'
			BEGIN
				EXEC	@IntRetVal = sp_insert_bcmap145_1 	@I_IntMprf,            --Migration Profile
										@I_StrVer,             --Version
										@I_StrRel,             --Release
										@I_StrCust,            --Customer
										@I_StrTrgPackage,      --Package
										@I_StrTrgModule,       --Module
									     	@I_StrTrgTable,        --Table
									     	1,                     --Dump Number
									     	@StrField,             --Field Name
									     	1,                     --Revision Info
									     	@StrText,              --Field Value - Text
									     	@IntFieldDumpType,     --Tupe of the Value Type 0/1
									     	@I_UserName,           --User Name
									     	'N',                   --N- Not Approved  Rule not Approved
										'C'		       --Status of the Component C- New/Changed


				IF  @IntRetVal <> 0
				BEGIN
					SELECT @StrTemp = [master].[dbo].[sysmessages].description
					FROM   [master].[dbo].[sysmessages]
					WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

					SET @StrTemp = ' Error -' + @StrTemp + ' -  while inserting  the record -' +
							 ' MPRF - '   + STR(@I_IntMprf)		+  ' ' +
						         ' VRC  - '   + @I_StrVer		+  '-' +
					                                @I_StrRel		+  '-' +
					                                @I_StrCust		+
							 ' TABLE - '  +	@I_StrTrgPackage	+
					                                @I_StrTrgModule		+
					                                @I_StrTrgTable		+  ' ' +
					                 ' FIELD - '  + @StrField  		+
					                 ' into BCMAP145. '

					EXEC Write_to_file @StrTemp, @I_StrLogFileName

					CLOSE DDC150_Cursor
					DEALLOCATE DDC150_Cursor

					RETURN @IntRetVal
				END
			END

			SET @IntTrgDepth = @IntTrgDepth - 1
			IF @IntTrgDepth = 0 BREAK  		-- This is to Avoid one more looping when @IntTrgDepth > 0
		END 	--WHILE END


		FETCH NEXT FROM DDC150_Cursor
		INTO   	@StrField, @StrSrcDomain, @StrTrgDomain, @IntSrcDepth,@IntTrgDepth,@Strctype,@StrSrcMan, @StrTrgMan,@StrTrgInitialValue
	END -- WHILE  @@FETCH_STATUS = 0

	CLOSE DDC150_Cursor
	DEALLOCATE DDC150_Cursor

	RETURN @IntRetVal



GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

/****** Object:  Stored Procedure dbo.sp_LegacyCreateDefaultMappings    Script Date: 10/6/2003 2:36:55 PM ******/
/****** Object:  Stored Procedure dbo.sp_LegacyCreateDefaultMappings    Script Date: 8/29/2003 10:56:08 AM ******/
/********************************************************************************
* 	NAME:		sp_LegacyCreateDefaultMappings			      	*
*	DESCRIPTION:	This Strored procedure, generates the Default mappings	*
*			for the tables for which Comparison has already been  	*
*			done.						      	*
*	Inputs:		The Runn Number, the Migration Profile, the Start pack	*
*			module and Table to the target Pack, Mod and Table.   	*
*	Calls:		The Following procedures are called.		      	*
*			1. sp_insert_bcmap120_1					*
*			2. sp_insert_bcmap125_1					*
*			3. sp_insert_bcmap130_1					*
*			4. sp_insert_bcmap135_1					*
*			5. sp_CreateMappingsForFineTunedChangedTables		*
*			6. sp_update_bcddc000_1					*
*	UPDATION 								*
*		- Adding  a Parameter @I_UserName[varchar](12)-31/oct/2001	*
*		- Call to sp_insert_bcmap110_1() is added-31/oct/2001		*
********************************************************************************/
CREATE PROCEDURE [sp_LegacyCreateDefaultMappings]
	(

	@I_IntRunn 		[int],
	@I_IntMprf 		[int],
	@I_StrPackFrom 		[varchar](2),
	@I_StrModFrom 		[varchar](3),
	@I_StrTableFrom 	[varchar](60),
	@I_StrPackTo 		[varchar](2),
	@I_StrModTo		[varchar](3),
	@I_StrTableTo		[varchar](60),
	@I_UserName		[varchar](12),
	@I_DMGChangedTables	[int] = 1,
	@I_DMGUnChangedTables	[int] = 1,
	@I_StrLogFileName	[varchar](1024) = "C:\DefaultMapGenLog.txt"
	)
AS
DECLARE @RecCntMAP120 		as int			--Record Count of BCMAP120
DECLARE @IntRetVal		as int			--Return Value
DECLARE	@IntCount		as int			--Counter
DECLARE @IntTableCount		as int			--Table Count
DECLARE @StrPackage 		as varchar(2)		--Package
DECLARE @StrModule 		as varchar(3)		--Module
DECLARE @StrTable 		as varchar(60)		--Table
DECLARE @StrCtype 		as varchar(1)		--Ctype -U/C/N/D
DECLARE @StrTargetAppl		as varchar(15)		--Target Application
DECLARE @StrSourceAppl		as varchar(15)		--Source Application
DECLARE @StrStdVersion		as varchar(4)		--Standard Version
DECLARE @StrStdRelease		as varchar(2)		--Standard Release
DECLARE @StrStdCustomer		as varchar(4)		--Standard Customer
DECLARE	@StrDevVersion		as varchar(4)		--Development Version
DECLARE	@StrDevRelease		as varchar(2)		--Development Release
DECLARE	@StrDevCustomer		as varchar(4)		--Development Customer
DECLARE @StrSCM			as varchar(1)		--SCM enabled for the Mig. Profile
DECLARE @StrText		as varchar(1024)	--Text
DECLARE @StrTableName		as varchar(60)		--To Store Table Name
DECLARE @CurrDateTime		as datetime		--Current Date and Time
DECLARE	@StrComment		as varchar(2000)	--Variable to hold Pretext
DECLARE @StrStatus		as varchar(1)		--Status
DECLARE @StrUnChanged		as varchar(1)		--Status - Unchanged
DECLARE @StrChanged		as varchar(1)		--Status - Changed
DECLARE @StrTemp		as varchar(1024)	--Temporary String
/* STEP 1. Get the Target Application Name & Mprf VRC details.*/
SELECT 	@StrTargetAppl 	= [dbo].[bcmap100].tapp,
	@StrSourceAppl	= [dbo].[bcmap100].sapp,
	@StrStdVersion	= [dbo].[bcmap100].vers,
	@StrStdRelease	= [dbo].[bcmap100].rele,
	@StrStdCustomer	= [dbo].[bcmap100].cust,
	@StrSCM		= [dbo].[bcmap100].scme
FROM 	[dbo].[bcmap100]
WHERE 	[dbo].[bcmap100].mprf = @I_IntMprf
/* STEP 2. Get the Development VRC from BCMAP 105 */
SELECT 	@StrDevVersion	= [dbo].[bcmap105].dver,
	@StrDevRelease	= [dbo].[bcmap105].drel,
	@StrDevCustomer	= [dbo].[bcmap105].dcus
FROM	[dbo].[bcmap105]
WHERE	[dbo].[bcmap105].mprf = @I_IntMprf
AND	[dbo].[bcmap105].vers = @StrStdVersion
AND	[dbo].[bcmap105].rele = @StrStdRelease
AND	[dbo].[bcmap105].cust = @StrStdCustomer

--If there is no Dev. VRC then set the Var to empty
SET @StrDevVersion = ISNULL(@StrDevVersion,'')
SET @StrDevRelease = ISNULL(@StrDevRelease,'')
SET @StrDevCustomer = ISNULL(@StrDevCustomer,'')
--IF Generation is for Changed Tables then Set the Flag.
IF (@I_DMGChangedTables = 1)
BEGIN
	SET @StrChanged ='C'
END
ELSE
BEGIN
	SET @StrChanged =''
END
--IF Generation is for UnChanged Tables then Set the Flag.
IF (@I_DMGUnChangedTables = 1 )
BEGIN
	SET @StrUnChanged ='U'
END
ELSE
BEGIN
	SET @StrUnChanged =''
END
SET @CurrDateTime = GETDATE()
EXEC Write_to_file '***********************************************************************************************************************', @I_StrLogFileName,1
SET @StrTemp=   'START DEFAULT MAPPING GENERATION '  + CHAR(9) + ' START TIME ' + CAST(@CurrDateTime as varchar)
EXEC Write_to_file @StrTemp, @I_StrLogFileName
SET @StrTemp =  'Range FROM ' +	@I_StrPackFrom 	+ @I_StrModFrom + @I_StrTableFrom + '  TO   '  +
						@I_StrPackTo 	+ @I_StrModTo	+ @I_StrTableTo
EXEC Write_to_file @StrTemp, @I_StrLogFileName

SET @StrTemp =  'Migration Profile- '  +  LTRIM(STR(@I_IntMprf))
EXEC Write_to_file @StrTemp, @I_StrLogFileName
SET @StrTemp =   'Run Number- '  +  LTRIM(STR(@I_IntRunn))
EXEC Write_to_file @StrTemp, @I_StrLogFileName
SET @StrTemp =  'User Name- '  + @I_UserName
EXEC Write_to_file @StrTemp, @I_StrLogFileName
EXEC Write_to_file '***********************************************************************************************************************', @I_StrLogFileName
SET @IntTableCount = 0
/*STEP 3. Generate Default Mappings for Unchanged and  Changed  Tables*/
DECLARE DDC140_Cursor CURSOR FOR
SELECT 	[dbo].[bcldc140].cpac,
	[dbo].[bcldc140].cmod,
	[dbo].[bcldc140].flno,
	[dbo].[bcldc140].ctyp
FROM 	[dbo].[bcldc140]
WHERE	[dbo].[bcldc140].runn = @I_IntRunn
AND 	([dbo].[bcldc140].ctyp IN (@StrUnChanged, @StrChanged))
AND  	([dbo].[bcldc140].cpac  BETWEEN @I_StrPackFrom AND @I_StrPackTo )
AND	([dbo].[bcldc140].cmod  BETWEEN @I_StrModFrom  AND @I_StrModTo)
AND	([dbo].[bcldc140].flno  BETWEEN @I_StrTableFrom AND @I_StrTableTo )
OPEN DDC140_Cursor
FETCH NEXT FROM DDC140_Cursor
INTO   @StrPackage, @StrModule, @StrTable,@StrCtype
WHILE @@FETCH_STATUS = 0
BEGIN
	SET @StrComment = ''
	SET @StrStatus = ''


	/* If some mappings are present for the given Range (@RecCntMAP120 <> 0) then check
	   whether mapping present for the Curent Table. If no mappings then Generate */
	SELECT 	@StrComment= [dbo].[bcmap120].comt,
		@StrStatus = [dbo].[bcmap120].stat
	FROM   	[dbo].[bcmap120]
	WHERE  	[dbo].[bcmap120].mprf 	= 	@I_IntMprf
	AND	[dbo].[bcmap120].vers 	= 	@StrStdVersion
	AND	[dbo].[bcmap120].rele 	= 	@StrStdRelease
	AND	[dbo].[bcmap120].cust 	= 	@StrStdCustomer
	AND  	[dbo].[bcmap120].tcpac 	=	@StrPackage
	AND	[dbo].[bcmap120].tcmod 	=	@StrModule
	AND	[dbo].[bcmap120].tflno 	=	@StrTable

	SET @StrComment = ISNULL(@StrComment,'')
	SET @StrStatus = ISNULL(@StrStatus,'')


	IF (@StrStatus ='' OR @StrStatus ='N')
	BEGIN
		--check whether a rec. is there in DVRC.
		--If DVRC is present then Skip.
		SELECT 	@IntCount = Count(*)
		FROM   	[dbo].[bcmap120]
		WHERE  	[dbo].[bcmap120].mprf 	=	@I_IntMprf
		AND  	[dbo].[bcmap120].tcpac 	=	@StrPackage
		AND	[dbo].[bcmap120].tcmod 	=	@StrModule
		AND	[dbo].[bcmap120].tflno 	=	@StrTable
		AND	[dbo].[bcmap120].vers	=	@StrDevVersion
		AND	[dbo].[bcmap120].rele	=	@StrDevRelease
		AND	[dbo].[bcmap120].cust	=	@StrDevCustomer

		IF (@IntCount > 0)
		BEGIN
			--Write in Log file - Mapping Already Exist
			SET @StrTemp = CHAR(9) +'Mapping Exists for the ' +  	@StrPackage      +
										@StrModule       +
										@StrTable 	 +
					       ' In the Development VRC - ' +
										@StrDevVersion +
										@StrDevRelease +
										@StrDevCustomer
			EXEC Write_to_file @StrTemp, @I_StrLogFileName

			FETCH NEXT FROM DDC140_Cursor
			INTO   @StrPackage, @StrModule, @StrTable,@StrCtype
			CONTINUE
		END

	END
	ELSE
	BEGIN
		IF ( @StrStatus <> 'N')
		BEGIN
			SET @StrTemp = CHAR(9)+ 'Mapping Exists for the ' +  	@StrPackage      +

										@StrModule       +
										@StrTable 	 +
					       ' in the Standard VRC - ' +
										@StrStdVersion 	 +
										@StrStdRelease    +
										@StrStdCustomer   +
					       ' with the status - '  +  @StrStatus

			EXEC Write_to_file @StrTemp, @I_StrLogFileName
			FETCH NEXT FROM DDC140_Cursor
			INTO   @StrPackage, @StrModule, @StrTable,@StrCtype
			CONTINUE
		END
	END


	BEGIN TRANSACTION
	-- STEP 4. Insert a New Record in BCMAP120/125,130/135

	/* Insert a Record in BAMAP120*/
	SET @StrTableName =  @StrTable
	SET @StrText =  'migrate ' + @StrTableName
	EXEC @IntRetVal = sp_insert_bcmap120_1 	@I_IntMprf,		--Migration Profile
						@StrStdVersion,		--Version
						@StrStdRelease,		--Release
						@StrStdCustomer,	--Customer
						@StrPackage,		--Package
						@StrModule,		--Module
						@StrTable,		--Table
						@StrText,		--Precondition Text
						'',			--Check out User
						@I_UserName,		--Last Modified User
						@CurrDateTime,		--Date
						'G',			--Status
						'',			--Variables
						@StrComment,		--Comments
						@StrTableName		--Source Table
	IF @IntRetVal <> 0
	BEGIN
		--ERROR Encountered: ROLLBACK and Continue with the Next Table
		SELECT @StrTemp = [master].[dbo].[sysmessages].description
		FROM   [master].[dbo].[sysmessages]
		WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

		SET @StrTemp = CHAR(9) + 'Error -' + @StrTemp + ' -  while inserting  the record ' +
					 ' MPRF - '   + LTRIM(STR(@I_IntMprf))	+  ' ' +
				         ' VRC  - '   + @StrStdVersion	+  '-' +
			                                @StrStdRelease	+  '-' +
			                                @StrStdCustomer	+
					 ' TABLE - '  +	@StrPackage	+
			                                @StrModule	+
			                                @StrTable	+  ' ' +
			                ' into BCMAP120. '
		EXEC Write_to_file @StrTemp, @I_StrLogFileName

		ROLLBACK TRANSACTION


		FETCH NEXT FROM DDC140_Cursor
		INTO   @StrPackage, @StrModule, @StrTable,@StrCtype

		CONTINUE
	END

	/* STEP 5. Insert 2 Records in BCMAP130
		1. For Select
		2. SelectDo */

	SET @StrText ='Select  ' +  @StrTableName + '.* ' + CHAR(13)  + CHAR(10) + 'From  ' + @StrTableName
	EXEC @IntRetVal = sp_insert_bcmap130_1  @I_IntMprf,		--Migration Profile
						@StrStdVersion,       	--Version
						@StrStdRelease,       	--Release
						@StrStdCustomer,      	--Customer
						@StrPackage,    	--Target Package
						@StrModule,     	--Target Module
						@StrTable,      	--Target Table
						@StrPackage,    	--Source Package
						@StrModule,     	--Source Module
						@StrTable,      	--Source Table
						'S',            	--Code for Text S/D/F/X
						@StrText        	--The Text -Query

	IF @IntRetVal <> 0
	BEGIN
		--ERROR Encountered: ROLLBACK and Continue with the Next Table
		SELECT @StrTemp = [master].[dbo].[sysmessages].description
		FROM   [master].[dbo].[sysmessages]
		WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

		SET @StrTemp = ' Error -' + @StrTemp + ' -  while inserting  the record -' +
					 ' MPRF - '   + LTRIM(STR(@I_IntMprf))	+  ' ' +
				         ' VRC  - '   + @StrStdVersion	+  '-' +
			                                @StrStdRelease	+  '-' +
			                                @StrStdCustomer	+
					 ' TABLE - '  +	@StrPackage	+
			                                @StrModule	+
			                                @StrTable	+  ' ' +
			                 ' CODE  - S ' +
	 		                 ' into BCMAP130. '

		EXEC Write_to_file @StrTemp, @I_StrLogFileName
		ROLLBACK TRANSACTION

		FETCH NEXT FROM DDC140_Cursor
		INTO   @StrPackage, @StrModule, @StrTable,@StrCtype

		CONTINUE
	END
	EXEC @IntRetVal = sp_insert_bcmap130_1 	@I_IntMprf,	--Migration Profile
						@StrStdVersion,	--Version
						@StrStdRelease,        --Release
						@StrStdCustomer,       --Customer
						@StrPackage,    --Target Package
						@StrModule,     --Target Module
						@StrTable,      --Target Table
						@StrPackage,    --Source Package
						@StrModule,     --Source Module
						@StrTable,      --Source Table
						'D',            --Code for Text S/D/F/X
						'dump 1'        --The Text -Query
	IF @IntRetVal <> 0
	BEGIN
		--ERROR Encountered: ROLLBACK and Continue with the Next Table
		SELECT @StrTemp = [master].[dbo].[sysmessages].description
		FROM   [master].[dbo].[sysmessages]
		WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

		SET @StrTemp = ' Error -' + @StrTemp + ' -  while inserting  the record -' +
					 ' MPRF - '   + LTRIM(STR(@I_IntMprf))	+  ' ' +
				         ' VRC  - '   + @StrStdVersion	+  '-' +
			                                @StrStdRelease	+  '-' +
			                                @StrStdCustomer	+
					 ' TABLE - '  +	@StrPackage	+
			                                @StrModule	+
			                                @StrTable	+  ' ' +
			                 ' CODE - D ' +
			                 ' into BCMAP130. '
		ROLLBACK TRANSACTION

		FETCH NEXT FROM DDC140_Cursor
		INTO   @StrPackage, @StrModule, @StrTable,@StrCtype

		CONTINUE
	END
	--STEP 6. If Migration is SCM enabled then insert records into 125 & 135

	IF @StrSCM = 'Y'
	BEGIN
		/* Inser a New Record in BCMAP110*/
		EXEC @IntRetVal = sp_insert_bcmap110_1 		@I_IntMprf,		--Migration Profile
								@StrStdVersion,     	--Version
								@StrStdRelease,     	--Release
								@StrStdCustomer,    	--Customer
								@StrPackage, 		--Package
								@StrModule,  		--Module
								@StrTable,   		--Table
								1,           		--Revision No.
								'Default Generation',   --Revision Info.
								'DEFAULT',		--Issue ID
								@CurrDateTime,		--Date & Time
								0,			--Patch NOT Exported(0)/Exported(1)
								@I_UserName		--User Name

		IF @IntRetVal <> 0
		BEGIN
			--ERROR Encountered: ROLLBACK and Continue with the Next Table
			SELECT @StrTemp = [master].[dbo].[sysmessages].description
			FROM   [master].[dbo].[sysmessages]
			WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

			SET @StrTemp = ' Error -' + @StrTemp + ' -  while inserting  the record -' +
					 ' MPRF - '   + LTRIM(STR(@I_IntMprf))	+  ' ' +
				         ' VRC  - '   + @StrStdVersion	+  '-' +
			                                @StrStdRelease	+  '-' +
			                                @StrStdCustomer	+
					 ' TABLE - '  +	@StrPackage	+
			                                @StrModule	+
			                                @StrTable	+  ' ' +
			                ' into BCMAP110. '

			ROLLBACK TRANSACTION

			FETCH NEXT FROM DDC140_Cursor
			INTO   @StrPackage, @StrModule, @StrTable,@StrCtype

			CONTINUE
		END

		/* Insert a New Record in BCMAP125*/
		SET @StrText =  'migrate ' + @StrTableName
		EXEC	@IntRetVal = sp_insert_bcmap125_1 	@I_IntMprf,	        --Migration Profile
								@StrStdVersion,         --Version
								@StrStdRelease,         --Release
								@StrStdCustomer,        --Customer
								@StrPackage,    	--Package
								@StrModule,     	--Module
								@StrTable,      	--Table
								1,              	--Revision Number
								@StrText,       	--Precondition Text
								@I_UserName,    	--Last Modified User
								'C',            	--Status
								'',             	--Variables
								@StrTableName   	--Source Table

		IF @IntRetVal <> 0
		BEGIN
			--ERROR Encountered: ROLLBACK and Continue with the Next Table
			SELECT @StrTemp = [master].[dbo].[sysmessages].description
			FROM   [master].[dbo].[sysmessages]
			WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

			SET @StrTemp = ' Error -' + @StrTemp + ' -  while inserting  the record -' +
					 ' MPRF - '   + LTRIM(STR(@I_IntMprf))	+  ' ' +
				         ' VRC  - '   + @StrStdVersion	+  '-' +
			                                @StrStdRelease	+  '-' +
			                                @StrStdCustomer	+
					 ' TABLE - '  +	@StrPackage	+
			                                @StrModule	+
			                                @StrTable	+  ' ' +
			                ' into BCMAP125. '

			EXEC Write_to_file @StrTemp, @I_StrLogFileName

			ROLLBACK TRANSACTION

			FETCH NEXT FROM DDC140_Cursor
			INTO   @StrPackage, @StrModule, @StrTable,@StrCtype

			CONTINUE
		END

		/* Insert 2 Records in BCMAP135
			1. For Select
			2. SelectDo */
		SET @StrText =  'Select  ' +  @StrTableName + '.* ' + CHAR(13)  + CHAR(10) + 'From  ' + @StrTableName
		EXEC @IntRetVal = sp_insert_bcmap135_1 	@I_IntMprf,		--Migration Profile
							@StrStdVersion,        --Version
							@StrStdRelease,        --Release
							@StrStdCustomer,       --Customer
							@StrPackage,    	--Target Package
							@StrModule,     	--Target Module
							@StrTable,      	--Target Table
							@StrPackage,    	--Source Package
							@StrModule,     	--Source Module
							@StrTable,      	--Source Table
							'S',            	--Code for Text S/D/F/X
							1,              	-- REvision Code
							@StrText,		--The Text -Query
							@I_UserName,		--User Name
							'C'			--Change Code
		IF @IntRetVal <> 0
		BEGIN
			--ERROR Encountered: ROLLBACK and Continue with the Next Table
			SELECT @StrTemp = [master].[dbo].[sysmessages].description
			FROM   [master].[dbo].[sysmessages]
			WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

			SET @StrTemp = ' Error -' + @StrTemp + ' -  while inserting  the record -' +
					 ' MPRF - '   + LTRIM(STR(@I_IntMprf))	+  ' ' +
				         ' VRC  - '   + @StrStdVersion	+  '-' +
			                                @StrStdRelease	+  '-' +
			                                @StrStdCustomer	+
					 ' TABLE - '  +	@StrPackage	+
			                                @StrModule	+
			                                @StrTable	+  ' ' +
			                ' into BCMAP135. '

			EXEC Write_to_file @StrTemp, @I_StrLogFileName

			ROLLBACK TRANSACTION

			FETCH NEXT FROM DDC140_Cursor
			INTO   @StrPackage, @StrModule, @StrTable,@StrCtype

			CONTINUE
		END
		--STEP Insert Second Record
		EXEC  @IntRetVal = sp_insert_bcmap135_1 	@I_IntMprf,	       	--Migration Profile
								@StrStdVersion,        	--Version
								@StrStdRelease,        	--Release
								@StrStdCustomer,       	--Customer
								@StrPackage,    	--Target Package
								@StrModule,     	--Target Module
								@StrTable,      	--Target Table
								@StrPackage,    	--Source Package
								@StrModule,     	--Source Module
								@StrTable,      	--Source Table
								'D',            	--Code for Text S/D/F/X
								1,              	-- REvision Code
								'dump 1',       	--The Text -Query
								@I_UserName,    	--User Name
								'C'             	--Change Code
		IF @IntRetVal <> 0
		BEGIN
			--ERROR Encountered: ROLLBACK and Continue with the Next Table
			SELECT @StrTemp = [master].[dbo].[sysmessages].description
			FROM   [master].[dbo].[sysmessages]
			WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

			SET @StrTemp = ' Error -' + @StrTemp + ' -  while inserting  the record -' +
					 ' MPRF - '   + LTRIM(STR(@I_IntMprf))	+  ' ' +
				         ' VRC  - '   + @StrStdVersion	+  '-' +
			                                @StrStdRelease	+  '-' +
			                                @StrStdCustomer	+
					 ' TABLE - '  +	@StrPackage	+
			                                @StrModule	+
			                                @StrTable	+  ' ' +
			                ' into BCMAP135. '

			EXEC Write_to_file @StrTemp, @I_StrLogFileName

			ROLLBACK TRANSACTION

			FETCH NEXT FROM DDC140_Cursor
			INTO   @StrPackage, @StrModule, @StrTable,@StrCtype

			CONTINUE
		END
	END


	--STEP 7. If the Table is Unchanged then Call Unchangedtables Procedure

	IF @StrCtype = 'U'
	BEGIN

		EXEC @IntRetVal = sp_LegacyCreateMappingForUnchangedTables 	@StrTargetAppl, 	--Target Application
									@StrSourceAppl	,	--Source Application
									@StrStdVersion,		--Version
									@StrStdRelease,		--Release
									@StrStdCustomer,	--Customer
									@StrSCM,		--SCM
									@I_IntRunn, 		--Runn
									@I_IntMprf, 		--Migration Profile
									@StrPackage, 		--Package
									@StrModule, 		--Module
									@StrTable,		--Table
									@I_UserName,		--User Name
									@I_StrLogFileName	--LogFileName
		IF @IntRetVal <> 0
		BEGIN
			--ERROR Encountered: ROLLBACK and Continue with the Next Table
			ROLLBACK TRANSACTION

			FETCH NEXT FROM DDC140_Cursor
			INTO   @StrPackage, @StrModule, @StrTable,@StrCtype

			CONTINUE
		END
	END

	--STEP 8. IF the Table is a changed Table then Call Changed tables Proc.

	IF @StrCtype = 'C'
	BEGIN
		EXEC @IntRetVal = sp_LegacyCreateMappingForChangedTables 	@StrTargetAppl, 	--Target Application
									@StrSourceAppl,         --Source Application
									@StrStdVersion,		--Version
									@StrStdRelease,         --Release
									@StrStdCustomer,        --Customer
									@StrSCM,                --SCM
									@I_IntRunn,             --Runn
									@I_IntMprf,             --Migration Profile
									@StrPackage,            --Package
									@StrModule,             --Module
									@StrTable,              --Table
									@I_UserName,            --User Name
									@I_StrLogFileName	--LogFile Name
		IF @IntRetVal <> 0
		BEGIN
			--ERROR Encountered: ROLLBACK and Continue with the Next Table

			ROLLBACK TRANSACTION

			FETCH NEXT FROM DDC140_Cursor
			INTO   @StrPackage, @StrModule, @StrTable,@StrCtype

			CONTINUE
		END
	END
	COMMIT TRANSACTION  -- Commit the Transaction
	SET @IntTableCount = @IntTableCount + 1
	SET @StrTemp = CHAR(9) + 'Successfully completed Default Mapping for - ' + @StrTableName
	EXEC Write_to_file  @StrTemp, @I_StrLogFileName

	FETCH NEXT FROM DDC140_Cursor
	INTO   @StrPackage, @StrModule, @StrTable,@StrCtype
END
CLOSE DDC140_Cursor
DEALLOCATE DDC140_Cursor
IF @IntTableCount = 0
BEGIN
	EXEC Write_to_file '----------------------------------------------------------------------------------------------------------------------',@I_StrLogFileName
	SET @StrTemp = CHAR(9) +  'Default Mapping Generation for Tables Not Done due to any of the following reasons. '
	EXEC Write_to_file @StrTemp,@I_StrLogFileName
	SET @StrTemp = CHAR(9) + CHAR(9) + '1. Mapping Already exists for the tables in the selcted Range.'
	EXEC Write_to_file @StrTemp, @I_StrLogFileName
	SET @StrTemp = CHAR(9) + CHAR(9) + '2. DD Comparison was not done for the Tables in the selected Range.'
	EXEC Write_to_file @StrTemp, @I_StrLogFileName
	EXEC Write_to_file '----------------------------------------------------------------------------------------------------------------------',@I_StrLogFileName
END
ELSE
BEGIN
	EXEC Write_to_file '----------------------------------------------------------------------------------------------------------------------',@I_StrLogFileName
	SET @StrTemp = CHAR(9) + 'Default Mapping Generation is successfully done for = ' + LTRIM(STR(@IntTableCount)) + ' table(s).' + char(9) + 'END TIME   ' + CAST(GETDATE() as varchar)
	EXEC Write_to_file @StrTemp,@I_StrLogFileName
	EXEC Write_to_file '----------------------------------------------------------------------------------------------------------------------',@I_StrLogFileName
END
RETURN @@ERROR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

 CREATE PROCEDURE [sp_LegacyCreateMappingForChangedTables]
 (
	  @I_StrTargetappl 	[varchar](15),
	  @I_StrSourceappl 	[varchar](15),
	  @I_StrVer  		[varchar](4),
	  @I_StrRel  		[varchar](2),
	  @I_StrCust  		[varchar](4),
	  @I_StrSCM  		[varchar](1),
	  @I_IntRunn  		[int],
	  @I_IntMprf   		[int],
	  @I_StrPackage  	[varchar](2),
	  @I_StrModule   	[varchar](3),
	  @I_StrTable  		[varchar](60),
	  @I_UserName		[varchar](12),
   	  @I_StrLogFileName	[varchar](1024) = "C:\DefaultMapGenLog.txt"
 )
 AS

	 DECLARE @StrField    		as varchar(60)		--Field Name.
	 DECLARE @StrTempField  	as varchar(60)		--Temporary Var. to hold.
	 DECLARE @StrText    		as varchar(1024)	--Text to hold the Generated rule.
	 DECLARE @StrTempTableName  	as varchar(60)		--Temp Var. to hold Table Name.
	 DECLARE @StrTempTableName1 	as varchar(60)		--Temp Var. to hold Table Name.
	 DECLARE @StrFType   		as varchar(1)		--Var. to hold the Field Type.
	 DECLARE @IntRetVal		as int			--Var. to hold the Return Value.
	 DECLARE @StrTemp   		as varchar(1024)	--Temporary Variable
	 DECLARE @StrVarName  		as varchar(100)	 	--Variable to hold the Type 2 variable name.


	 /*STEP 1. Get all the Unchanged/Changed and New Fields Records from BCLDC150*/

	 DECLARE LDC150_Cursor CURSOR FOR

	 SELECT 	[dbo].[bcldc150].flno,
			[dbo].[bcldc150].fdnm,
			[dbo].[bcldc150].ttyp
	 FROM   	[dbo].[bcldc150]
	 WHERE 		[dbo].[bcldc150].runn  = @I_IntRunn AND [dbo].[bcldc150].ctyp <> 'R'  AND [dbo].[bcldc150].ctyp <> 'N'
	 AND    	[dbo].[bcldc150].cpac  = @I_StrPackage
	 AND  		[dbo].[bcldc150].cmod  = @I_StrModule
	 AND  		[dbo].[bcldc150].flno  = @I_StrTable
	 ORDER BY  	[dbo].[bcldc150].fdnm,
	   		[dbo].[bcldc150].ctyp

	 OPEN LDC150_Cursor
	 FETCH NEXT FROM LDC150_Cursor
	 INTO    @StrTempTableName1,@StrField,@StrFType

	 WHILE 	  @@FETCH_STATUS = 0
	 BEGIN


			         Set @StrText = CASE  @StrFType
					        WHEN 'T'  THEN  'to_date(' + @StrTempTableName1 + '.' + @StrField + ')'
					        ELSE @StrTempTableName1 + '.' + @StrField
				           	END



		   --Insert the Field values into BCMAP140

			   EXEC @IntRetVal = sp_insert_bcmap140_1 	@I_IntMprf,		--Migration Profile
					   				@I_StrVer,		--Version
					   				@I_StrRel,		--Release
					   				@I_StrCust,		--Customer
				   					@I_StrPackage,		--Package
				   					@I_StrModule,		--Module
				        			 	@I_StrTable,		--Table
							        	1,			--Dump Number
						        		@StrField,		--Field Name
						        		@StrText,		--Field Value - Text
							        	0,			--Type of the Value Type 0/1
							        	'N'			-- N- Not Approved  Rule not Approved

			   IF (@IntRetVal <> 0)
			   BEGIN
				-- Error So BREAK
				SELECT @StrTemp = [master].[dbo].[sysmessages].description
				FROM   [master].[dbo].[sysmessages]
				WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

				SET @StrTemp = ' Error -' + @StrTemp + ' -  while inserting  the record -' +
						 ' MPRF - '   + STR(@I_IntMprf)	+  ' ' +
					         ' VRC  - '   + @I_StrVer	+  '-' +
				                                @I_StrRel	+  '-' +
				                                @I_StrCust	+
						 ' TABLE - '  +	@I_StrPackage	+
				                                @I_StrModule	+
				                                @I_StrTable	+  ' ' +
				                 ' FIELD - '  + @StrField  	+
				                 ' into BCMAP140. '

				EXEC Write_to_file @StrTemp, @I_StrLogFileName
			   	BREAK
			   END

			   --If the Profile is SCM enabled then  Insert another Record in BCMAP145
			   IF @I_StrSCM = 'Y'
			   BEGIN
			    	EXEC @IntRetVal =sp_insert_bcmap145_1 	@I_IntMprf,		--Migration Profile
				    					@I_StrVer,              --Version
				    					@I_StrRel,              --Release
				    					@I_StrCust,             --Customer
			    						@I_StrPackage,          --Package
			    						@I_StrModule,           --Module
						            		@I_StrTable,            --Table
						            		1,                      --Dump Number
				            				@StrField,              --Field Name
			            					1,                      --Revision Info
			            					@StrText,               --Field Value - Text
					            			0,		        --Tupe of the Value Type 0/1
					            			@I_UserName,            --User Name
			            					'N' ,			--N- Not Approved  Rule not Approved
									'C'			--Status of the Component C- New/Changed
				IF @IntRetVal <> 0
				BEGIN
					-- ERROR So Break
					SELECT @StrTemp = [master].[dbo].[sysmessages].description
					FROM   [master].[dbo].[sysmessages]
					WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

					SET @StrTemp = ' Error -' + @StrTemp + ' -  while inserting  the record -' +
							 ' MPRF - '   + STR(@I_IntMprf)	+  ' ' +
						         ' VRC  - '   + @I_StrVer	+  '-' +
					                                @I_StrRel	+  '-' +
					                                @I_StrCust	+
							 ' TABLE - '  +	@I_StrPackage	+
					                                @I_StrModule	+
					                                @I_StrTable	+  ' ' +
					                 ' FIELD - '  + @StrField  	+
					                 ' into BCMAP145. '

					EXEC Write_to_file @StrTemp, @I_StrLogFileName
					BREAK
				END
			   END


		IF @IntRetVal <> 0
		BEGIN
			 CLOSE LDC150_Cursor
			 DEALLOCATE LDC150_Cursor
 			 RETURN @IntRetVal
		END

		FETCH NEXT FROM LDC150_Cursor
		INTO    @StrTempTableName1,@StrField,@StrFType

	 END   -- WHILE  @@FETCH_STATUS = 0

	 CLOSE LDC150_Cursor
	 DEALLOCATE LDC150_Cursor
	 RETURN @IntRetVal
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO


/****** Object:  Stored Procedure dbo.sp_LegacyCreateMappingForUnchangedTables    Script Date: 6th Jun 2005 2:36 PM ******/
/********************************************************************************
*	NAME:		sp_LegacyCreateMappingForUnchangedTables			*
*	DESCRPTION:	This Stored procedure generates the default mappings    *
*			for Unchaged Tables.					*
*	CALLS:		1. sp_insert_bcmap140_1()				*
*			2. sp_insert_bcmap145_1()				*
*	CALLED BY:	sp_LegacyCreateDefaultMappings()				*
********************************************************************************/
CREATE PROCEDURE [sp_LegacyCreateMappingForUnchangedTables]
(
	  @I_StrTargetappl 	[varchar](15),
	  @I_StrSourceappl 	[varchar](15),
	  @I_StrVer  		[varchar](4),
	  @I_StrRel  		[varchar](2),
	  @I_StrCust  		[varchar](4),
	  @I_StrSCM  		[varchar](1),
	  @I_IntRunn  		[int],
	  @I_IntMprf   		[int],
	  @I_StrPackage  	[varchar](2),
	  @I_StrModule   	[varchar](3),
	  @I_StrTable   	[varchar](60),
	  @I_UserName		[varchar](12),
   	  @I_StrLogFileName	[varchar](1024) = "C:\DefaultMapGenLog.txt"
	   )
 AS
	 DECLARE @StrField   		as varchar(60)
	 DECLARE @StrTempField  	as varchar(60)
	DECLARE @StrTempTable  	as varchar(60)
	 DECLARE @StrText   		as varchar(1024)
	 DECLARE @StrTrgFType 		as varchar(1)
	 DECLARE @IntRetVal 		as int
	 DECLARE @StrTemp		as varchar(1024)

	 SET @IntRetVal = 0

	 /*Get all the Unchanged Tables Records from BCLDC150*/
	 DECLARE LDC150_Cursor CURSOR FOR

	 SELECT  	[dbo].[bcldc150].flno , [dbo].[bcldc150].fdnm,[dbo].[bcldc150].ttyp
	 FROM   	[dbo].[bcldc150]
	 WHERE 		[dbo].[bcldc150].runn  	= @I_IntRunn
	 AND   		[dbo].[bcldc150].ctyp 	= 'U'
	 AND    	[dbo].[bcldc150].cpac  	= @I_StrPackage
	 AND  		[dbo].[bcldc150].cmod  	= @I_StrModule
	 AND  		[dbo].[bcldc150].flno  	= @I_StrTable
	 ORDER BY  	[dbo].[bcldc150].fdnm

	 OPEN 	LDC150_Cursor
	 FETCH	NEXT FROM LDC150_Cursor
	 INTO   @StrTempTable,@StrField,@StrTrgFType

	 WHILE 	@@FETCH_STATUS = 0
	 BEGIN
		  SET @StrTempField = @StrField

		        	SET @StrText = CASE @StrTrgFType
					        WHEN 'T' THEN 'to_date(' + @StrTempTable + '.' + @StrField + ')'
					        ELSE @StrTempTable + '.' + @StrField
 	 		          	  	END

			     EXEC @IntRetVal = sp_insert_bcmap140_1
					      @I_IntMprf,  	-- MPRF
					      @I_StrVer,  	--version
					      @I_StrRel,  	--Release
					      @I_StrCust,  	--Customer
					      @I_StrPackage,  	--Package
					      @I_StrModule,  	--Module
					      @I_StrTable ,  	--Table
					      1,   		--Dump Number
					      @StrField,  	--Field Name
					      @StrText,  	--Field  Value
					      0,   		--Type (Hard coded)
					      'N'   		--Not Approved

			     IF @IntRetVal <> 0
			     BEGIN
				SELECT @StrTemp = [master].[dbo].[sysmessages].description
				FROM   [master].[dbo].[sysmessages]
				WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

				SET @StrTemp = ' Error -' + @StrTemp + ' -  while inserting  the record -' +
						 ' MPRF - '   + STR(@I_IntMprf)	+  ' ' +
					         ' VRC  - '   + @I_StrVer	+  '-' +
				                                @I_StrRel	+  '-' +
				                                @I_StrCust	+
						 ' TABLE - '  +	@I_StrPackage	+
				                                @I_StrModule	+
				                                @I_StrTable	+  ' ' +
				                 ' FIELD - '  + @StrField  	+
				                 ' into BCMAP140. '

				EXEC Write_to_file @StrTemp, @I_StrLogFileName
				RETURN @IntRetVal
			     END

			     -- If the Migration Profile is SCM enabled then Insert a rec. in BCMAP145.
			     IF @I_StrSCM = 'Y'
			     BEGIN
				    EXEC @IntRetVal = sp_insert_bcmap145_1
						       @I_IntMprf,  	--Mprf
						       @I_StrVer,  	--version
						       @I_StrRel,  	--Release
						       @I_StrCust,  	--Customer
						       @I_StrPackage,  	--Package
						       @I_StrModule,  	--Module
						       @I_StrTable ,  	--Table
						       1,   		--Dump No.
						       @StrField,  	--Field Name
						       1,   		--Revision Number
						       @StrText,  	--Field  Value
						       0,   		--Hard coded
						       @I_UserName,  	--Login Id
						      'N',  		--Not Approved
						      'C'		--Changed
				    IF @IntRetVal <> 0
				    BEGIN
					SELECT @StrTemp = [master].[dbo].[sysmessages].description
					FROM   [master].[dbo].[sysmessages]
					WHERE  [master].[dbo].[sysmessages].error = @IntRetVal

					SET @StrTemp = ' Error -' + @StrTemp + ' -  while inserting  the record -' +
							 ' MPRF - '   + STR(@I_IntMprf)	+  ' ' +
						         ' VRC  - '   + @I_StrVer	+  '-' +
					                                @I_StrRel	+  '-' +
					                                @I_StrCust	+
							 ' TABLE - '  +	@I_StrPackage	+
					                                @I_StrModule	+
					                                @I_StrTable	+  ' ' +
					                 ' FIELD - '  + @StrField  	+
					                 ' into BCMAP145. '

					EXEC Write_to_file @StrTemp, @I_StrLogFileName
					RETURN @IntRetVal
				    END


		  END

		  FETCH NEXT FROM LDC150_Cursor
		  INTO   @StrTempTable,@StrField,@StrTrgFType
	 END

	 CLOSE LDC150_Cursor

	 DEALLOCATE LDC150_Cursor

	 RETURN @IntRetVal
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


/****** Object:  Stored Procedure dbo.sp_insert_bcddc000_1    Script Date: 10/6/2003 2:36:55 PM ******/
/****** Object:  Stored Procedure dbo.sp_insert_bcddc000_1    Script Date: 8/29/2003 10:56:09 AM ******/
/****************************************************************************************************
* NAME:   sp_insert_bcddc000_1    *
* DESCRIPTION:  This Stored procedure is used to insert a record     *
*    in BCDDC000 table.    *
* CREATED BY:  S.Anand Kumar     *
* RETURNS:  ON SUCCESS - -0    *
*    ON ERROR    Value <> 0   *
***************************************************************************************************/
CREATE PROCEDURE [sp_insert_bcddc000_1]
 (@runn_1  [int],
  @cpac_2  [nvarchar](2),
  @cmod_3  [nvarchar](3),
  @flno_4  [nvarchar](60),
  @sdat_5  [datetime],
  @tdat_6  [datetime],
  @type_7  [char](1))
AS INSERT INTO [dbo].[bcddc000]
  ( [runn],
  [cpac],
  [cmod],
  [flno],
  [sdat],
  [tdat],
  [type])

VALUES
 ( @runn_1,
  @cpac_2,
  @cmod_3,
  @flno_4,
  @sdat_5,
  @tdat_6,
  @type_7)
RETURN @@ERROR



GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO



/****** Object:  Stored Procedure dbo.sp_insert_bcmap110_1    Script Date: 10/6/2003 2:36:55 PM ******/
/****** Object:  Stored Procedure dbo.sp_insert_bcmap110_1    Script Date: 8/29/2003 10:56:09 AM ******/
CREATE PROCEDURE [sp_insert_bcmap110_1]
	(@mprf_1 	[int],
	 @vers_2 	[varchar](4),
	 @rele_3 	[varchar](2),
	 @cust_4 	[varchar](4),
	 @tcpac_5 	[varchar](2),
	 @tcmod_6 	[varchar](3),
	 @tflno_7 	[varchar](60),
	 @revi_8 	[int],
	 @rinf_9 	[text],
	 @isid_10 	[varchar](50),
	 @sdat_11 	[datetime],
	 @pexp_12 	[int],
	 @logn_13 	[varchar](12))
AS INSERT INTO [dbo].[bcmap110]
	 ( [mprf],
	 [vers],
	 [rele],
	 [cust],
	 [tcpac],
	 [tcmod],
	 [tflno],
	 [revi],
	 [rinf],
	 [isid],
	 [sdat],
	 [pexp],
	 [logn])

VALUES
	( @mprf_1,
	 @vers_2,
	 @rele_3,
	 @cust_4,
	 @tcpac_5,
	 @tcmod_6,
	 @tflno_7,
	 @revi_8,
	 @rinf_9,
	 @isid_10,
	 @sdat_11,
	 @pexp_12,
	 @logn_13)
RETURN @@ERROR



GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO



/****** Object:  Stored Procedure dbo.sp_insert_bcmap120_1    Script Date: 10/6/2003 2:36:55 PM ******/
/****** Object:  Stored Procedure dbo.sp_insert_bcmap120_1    Script Date: 8/29/2003 10:56:09 AM ******/
CREATE PROCEDURE [sp_insert_bcmap120_1]
	(@mprf_1 	[int],
	 @vers_2 	[varchar](4),
	 @rele_3 	[varchar](2),
	 @cust_4 	[varchar](4),
	 @tcpac_5 	[varchar](2),
	 @tcmod_6 	[varchar](3),
	 @tflno_7 	[varchar](60),
	 @prtx_8 	[text],
	 @logn_9 	[varchar](12),
	 @lusr_10 	[varchar](12),
	 @ldat_11 	[datetime],
	 @stat_12 	[varchar](1),
	 @vari_13 	[varchar](2000),
	 @comt_14 	[varchar](2000),
	 @stbl_15 	[varchar](200))
AS INSERT INTO [dbo].[bcmap120]
	 ( [mprf],
	 [vers],
	 [rele],
	 [cust],
	 [tcpac],
	 [tcmod],
	 [tflno],
	 [prtx],
	 [logn],
	 [lusr],
	 [ldat],
	 [stat],
	 [vari],
	 [comt],
	 [stbl])

VALUES
	( @mprf_1,
	 @vers_2,
	 @rele_3,
	 @cust_4,
	 @tcpac_5,
	 @tcmod_6,
	 @tflno_7,
	 @prtx_8,
	 @logn_9,
	 @lusr_10,
	 @ldat_11,
	 @stat_12,
	 @vari_13,
	 @comt_14,
	 @stbl_15)
RETURN @@ERROR



GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO



/****** Object:  Stored Procedure dbo.sp_insert_bcmap125_1    Script Date: 10/6/2003 2:36:55 PM ******/
/****** Object:  Stored Procedure dbo.sp_insert_bcmap125_1    Script Date: 8/29/2003 10:56:09 AM ******/
CREATE PROCEDURE [sp_insert_bcmap125_1]
	(@mprf_1 	[int],
	 @vers_2 	[varchar](4),
	 @rele_3 	[varchar](2),
	 @cust_4 	[varchar](4),
	 @tcpac_5 	[varchar](2),
	 @tcmod_6 	[varchar](3),
	 @tflno_7 	[varchar](60),
	 @revi_8 	[int],
	 @prtx_9 	[text],
	 @logn_10 	[varchar](12),
	 @csta_11 	[char](1),
	 @vari_12 	[varchar](2000),
	 @stbl_13 	[varchar](200))
AS INSERT INTO [dbo].[bcmap125]
	 ( [mprf],
	 [vers],
	 [rele],
	 [cust],
	 [tcpac],
	 [tcmod],
	 [tflno],
	 [revi],
	 [prtx],
	 [logn],
	 [csta],
	 [vari],
	 [stbl])

VALUES
	( @mprf_1,
	 @vers_2,
	 @rele_3,
	 @cust_4,
	 @tcpac_5,
	 @tcmod_6,
	 @tflno_7,
	 @revi_8,
	 @prtx_9,
	 @logn_10,
	 @csta_11,
	 @vari_12,
	 @stbl_13)
RETURN @@ERROR



GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO



/****** Object:  Stored Procedure dbo.sp_insert_bcmap130_1    Script Date: 10/6/2003 2:36:55 PM ******/
/****** Object:  Stored Procedure dbo.sp_insert_bcmap130_1    Script Date: 8/29/2003 10:56:09 AM ******/
CREATE PROCEDURE [sp_insert_bcmap130_1]
	(@mprf_1 	[int],
	 @vers_2 	[varchar](4),
	 @rele_3 	[varchar](2),
	 @cust_4 	[varchar](4),
	 @tcpac_5 	[varchar](2),
	 @tcmod_6 	[varchar](3),
	 @tflno_7 	[varchar](60),
	 @scpac_8 	[varchar](2),
	 @scmod_9 	[varchar](3),
	 @sflno_10 	[varchar](60),
	 @icod_11 	[varchar](1),
	 @qury_12 	[text])
AS INSERT INTO [dbo].[bcmap130]
	 ( [mprf],
	 [vers],
	 [rele],
	 [cust],
	 [tcpac],
	 [tcmod],
	 [tflno],
	 [scpac],
	 [scmod],
	 [sflno],
	 [icod],
	 [qury])

VALUES
	( @mprf_1,
	 @vers_2,
	 @rele_3,
	 @cust_4,
	 @tcpac_5,
	 @tcmod_6,
	 @tflno_7,
	 @scpac_8,
	 @scmod_9,
	 @sflno_10,
	 @icod_11,
	 @qury_12)
RETURN @@ERROR



GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO



/****** Object:  Stored Procedure dbo.sp_insert_bcmap135_1    Script Date: 10/6/2003 2:36:55 PM ******/
/****** Object:  Stored Procedure dbo.sp_insert_bcmap135_1    Script Date: 8/29/2003 10:56:09 AM ******/
CREATE PROCEDURE [sp_insert_bcmap135_1]
	(@mprf_1 	[int],
	 @vers_2 	[varchar](4),
	 @rele_3 	[varchar](2),
	 @cust_4 	[varchar](4),
	 @tcpac_5 	[varchar](2),
	 @tcmod_6 	[varchar](3),
	 @tflno_7 	[varchar](60),
	 @scpac_8 	[varchar](2),
	 @scmod_9 	[varchar](3),
	 @sflno_10 	[varchar](60),
	 @icod_11 	[varchar](1),
	 @revi_12 	[int],
	 @qury_13 	[text],
	 @logn_14 	[varchar](12),
	 @csta_15 	[char](1))
AS INSERT INTO [dbo].[bcmap135]
	 ( [mprf],
	 [vers],
	 [rele],
	 [cust],
	 [tcpac],
	 [tcmod],
	 [tflno],
	 [scpac],
	 [scmod],
	 [sflno],
	 [icod],
	 [revi],
	 [qury],
	 [logn],
	 [csta])

VALUES
	( @mprf_1,
	 @vers_2,
	 @rele_3,
	 @cust_4,
	 @tcpac_5,
	 @tcmod_6,
	 @tflno_7,
	 @scpac_8,
	 @scmod_9,
	 @sflno_10,
	 @icod_11,
	 @revi_12,
	 @qury_13,
	 @logn_14,
	 @csta_15)
RETURN @@ERROR



GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO



/****** Object:  Stored Procedure dbo.sp_insert_bcmap140_1    Script Date: 10/6/2003 2:36:55 PM ******/
/****** Object:  Stored Procedure dbo.sp_insert_bcmap140_1    Script Date: 8/29/2003 10:56:09 AM ******/
CREATE PROCEDURE [sp_insert_bcmap140_1]
	(@mprf_1 	[int],
	 @vers_2 	[varchar](4),
	 @rele_3 	[varchar](2),
	 @cust_4 	[varchar](4),
	 @tcpac_5 	[varchar](2),
	 @tcmod_6 	[varchar](3),
	 @tflno_7 	[varchar](60),
	 @dnum_8 	[int],
	 @fdnm_9 	[varchar](60),
	 @mrul_10 	[text],
	 @type_11 	[int],
	 @stat_12 	[varchar](1))
AS INSERT INTO [dbo].[bcmap140]
	 ( [mprf],
	 [vers],
	 [rele],
	 [cust],
	 [tcpac],
	 [tcmod],
	 [tflno],
	 [dnum],
	 [fdnm],
	 [mrul],
	 [type],
	 [stat])

VALUES
	( @mprf_1,
	 @vers_2,
	 @rele_3,
	 @cust_4,
	 @tcpac_5,
	 @tcmod_6,
	 @tflno_7,
	 @dnum_8,
	 @fdnm_9,
	 @mrul_10,
	 @type_11,
	 @stat_12)
RETURN @@ERROR



GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO



/****** Object:  Stored Procedure dbo.sp_insert_bcmap145_1    Script Date: 10/6/2003 2:36:55 PM ******/
/****** Object:  Stored Procedure dbo.sp_insert_bcmap145_1    Script Date: 8/29/2003 10:56:09 AM ******/
CREATE PROCEDURE [sp_insert_bcmap145_1]
	(@mprf_1 	[int],
	 @vers_2 	[varchar](4),
	 @rele_3 	[varchar](2),
	 @cust_4 	[varchar](4),
	 @tcpac_5 	[varchar](2),
	 @tcmod_6 	[varchar](3),
	 @tflno_7 	[varchar](60),
	 @dnum_8 	[int],
	 @fdnm_9 	[varchar](60),
	 @revi_10 	[int],
	 @mrul_11 	[text],
	 @type_12 	[int],
	 @logn_13 	[varchar](12),
	 @stat_14 	[varchar](1),
	 @csta_15 	[char](1))
AS INSERT INTO [dbo].[bcmap145]
	 ( [mprf],
	 [vers],
	 [rele],
	 [cust],
	 [tcpac],
	 [tcmod],
	 [tflno],
	 [dnum],
	 [fdnm],
	 [revi],
	 [mrul],
	 [type],
	 [logn],
	 [stat],
	 [csta])

VALUES
	( @mprf_1,
	 @vers_2,
	 @rele_3,
	 @cust_4,
	 @tcpac_5,
	 @tcmod_6,
	 @tflno_7,
	 @dnum_8,
	 @fdnm_9,
	 @revi_10,
	 @mrul_11,
	 @type_12,
	 @logn_13,
	 @stat_14,
	 @csta_15)
RETURN @@ERROR



GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO



/****** Object:  Stored Procedure dbo.sp_update_bcddc000_1    Script Date: 10/6/2003 2:36:55 PM ******/
/****** Object:  Stored Procedure dbo.sp_update_bcddc000_1    Script Date: 8/29/2003 10:56:09 AM ******/
/* **********************************************************************************************
*	This stored procedure is  used to update the Log table bcddc000	       *
* **********************************************************************************************/
CREATE PROCEDURE [sp_update_bcddc000_1]
(
	@I_IntRunn 	[int],
	@I_IntMprf 	[int],
	@I_StrPackFrom 	[nvarchar](2),
	@I_StrModFrom 	[nvarchar](3),
	@I_StrTableFrom [nvarchar](3),
	@I_StrPackTo 	[nvarchar](2),
	@I_StrModTo	[nvarchar](3),
	@I_StrTableTo	[nvarchar](3),
	@I_IntType	int
)
AS
	DECLARE @StrPackage 	as nvarchar(2)
	DECLARE @StrModule 	as nvarchar(3)
	DECLARE @StrTable 	as nvarchar(3)

	DECLARE BCMAP120_Cursor CURSOR FOR
	SELECT  [dbo].[bcmap120].tcpac,
		[dbo].[bcmap120].tcmod,
		[dbo].[bcmap120].tflno
	FROM	[dbo].[bcmap120]
	WHERE 	[dbo].[bcmap120].mprf = @I_IntMprf
	AND  	[dbo].[bcmap120].tcpac  +  [dbo].[bcmap120].tcmod + [dbo].[bcmap120].tflno
	BETWEEN	(@I_StrPackFrom +  @I_StrModFrom  + @I_StrTableFrom)
	AND  	(@I_StrPackTo + @I_StrModTo +@I_StrTableTo)
	OPEN BCMAP120_Cursor
	FETCH NEXT FROM BCMAP120_Cursor
	INTO   @StrPackage, @StrModule, @StrTable
	WHILE @@FETCH_STATUS = 0
	BEGIN
		EXEC sp_insert_bcddc000_1 @I_IntRunn,@StrPackage, @StrModule, @StrTable,'','','S'

		FETCH NEXT FROM BCMAP120_Cursor
		INTO   @StrPackage, @StrModule, @StrTable
	END
	CLOSE BCMAP120_Cursor
	DEALLOCATE BCMAP120_Cursor
	IF @I_IntType = 1  -- call from Default Mapping Gen Proc
	BEGIN
		DECLARE DDC140_Cursor CURSOR FOR
		SELECT 	[dbo].[bcddc140].cpac,
			[dbo].[bcddc140].cmod,
			[dbo].[bcddc140].flno
		FROM 	[dbo].[bcddc140]
		WHERE	NOT EXISTS(	SELECT  *
					FROM	[dbo].[bcmap120]
					WHERE 	[dbo].[bcmap120].mprf = @I_IntMprf
					AND  	[dbo].[bcmap120].tcpac  +  [dbo].[bcmap120].tcmod + [dbo].[bcmap120].tflno
					BETWEEN	(@I_StrPackFrom +  @I_StrModFrom  + @I_StrTableFrom)
					AND  	(@I_StrPackTo + @I_StrModTo +@I_StrTableTo) )
		AND		[dbo].[bcddc140].runn = @I_IntRunn
		AND		([dbo].[bcddc140].ctyp = 'U'  	OR  	[dbo].[bcddc140].ctyp = 'C')
		AND  		([dbo].[bcddc140].cpac  +  [dbo].[bcddc140].cmod + [dbo].[bcddc140].flno
		BETWEEN 	(@I_StrPackFrom +  @I_StrModFrom  + @I_StrTableFrom)
		AND 		(@I_StrPackTo + @I_StrModTo +@I_StrTableTo) )

		OPEN DDC140_Cursor

		FETCH NEXT FROM DDC140_Cursor
		INTO   @StrPackage, @StrModule, @StrTable


		WHILE @@FETCH_STATUS = 0
		BEGIN
			EXEC sp_insert_bcddc000_1 @I_IntRunn,@StrPackage, @StrModule, @StrTable,'','','F'

			FETCH NEXT FROM DDC140_Cursor
			INTO   @StrPackage, @StrModule, @StrTable

		END

		CLOSE DDC140_Cursor

		DEALLOCATE DDC140_Cursor
	END
	ELSE	--Called from Fine Tune Table
	BEGIN
		DECLARE DDC141_Cursor CURSOR FOR

		SELECT 	[dbo].[bcddc141].spac,
			[dbo].[bcddc141].smod,
			[dbo].[bcddc141].slno
		FROM 	[dbo].[bcddc141]
		WHERE	NOT EXISTS(	SELECT  	*
					FROM		[dbo].[bcmap120]
					WHERE 		[dbo].[bcmap120].mprf = @I_IntMprf
					AND  		[dbo].[bcmap120].tcpac  +  [dbo].[bcmap120].tcmod + [dbo].[bcmap120].tflno
					BETWEEN		(@I_StrPackFrom +  @I_StrModFrom  + @I_StrTableFrom)
					AND  		(@I_StrPackTo + @I_StrModTo +@I_StrTableTo) )
		AND	[dbo].[bcddc141].runn = @I_IntRunn
		AND 	[dbo].[bcddc141].spac +  [dbo].[bcddc141].smod +[dbo].[bcddc141].slno
		BETWEEN	(@I_StrPackFrom +  @I_StrModFrom  + @I_StrTableFrom)  AND  (@I_StrPackTo + @I_StrModTo +@I_StrTableTo)

		OPEN DDC141_Cursor

		FETCH NEXT FROM DDC141_Cursor
		INTO   @StrPackage, @StrModule, @StrTable

		WHILE @@FETCH_STATUS = 0
		BEGIN

			EXEC sp_insert_bcddc000_1 @I_IntRunn,@StrPackage, @StrModule, @StrTable,'','','F'

			FETCH NEXT FROM DDC141_Cursor
			INTO   @StrPackage, @StrModule, @StrTable
		END

		CLOSE DDC141_Cursor
		DEALLOCATE DDC141_Cursor
	END



GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO



CREATE PROCEDURE  testtext  AS
begin
EXEC sp_dboption 'iBCA20', 'select into/bulkcopy', 'true'
DECLARE @textpointer varbinary(16)
SELECT @textpointer = TEXTPTR(prtx)
FROM bcmap120
READTEXT bcmap120.prtx @textpointer 1 0
end



GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_EmptyRulesReport]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_EmptyRulesReport]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_EmptydepthFields]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_EmptydepthFields]
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[sp_EmptyRulesReport]
(
		@I_IntMprf 		[int]=0,			-- From part of Profile Range
		@I_IntMprfTo 		[int]=999,			-- To part of Profile Range
		@I_StrPac		[varchar](65)='' ,	-- Table  Name of From range
		@I_StrPacTo		[varchar](65)='zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz' ,	-- Table  Name of To range
		@I_Strldat		[datetime] ,	-- Table  Name of From range
		@I_StrldatTo		[datetime],	-- Table  Name of To range
		@I_StrUsr		[varchar](12)='',	-- User  Name of From range
		@I_StrUsrTo		[varchar](65)='zzzzzzzzzzzz',	-- User  Name of To range
		@I_IntFlag  		[int]		   -- if 0,find list of tables for which rules are not maintained         -- if 1, Find empty rules for fields of tables for which rules are maintained


)

 AS
DECLARE @strTargetApp		as varchar(30)			--Target Application Name
DECLARE @intMPRF			as int				-- MPRF
DECLARE @intPPRF			as int				-- MPRF
DECLARE @strNoRuleTable		as varchar(65)			--Tables not maintained with Rules
DECLARE @strNoRuleTable_ButM	as varchar(65)			--Tables not maintained with Rules but status as Maintned in bcmap120

DECLARE @strMaintTable		as varchar(65)			--Tables with maintained Rules
DECLARE @intDump			as int				-- Dumps
DECLARE @strTemp			as varchar(2000)		--Storing temporary string
DECLARE @intCNTPPRF		as int				--Storing No of Total profiles
DECLARE @intCNTTab			as int				--Storing No of Total tables not having rules
DECLARE @intCNTTab_M		as int				--Storing No of Total tables not having rules but has got M status
DECLARE @intCNTMaintTab		as int				--Storing No of Total tables having rules
DECLARE @strMissedField		as varchar(60)			--Storing Empty Field Name
DECLARE @intCNTMissedField		as int				--Storing No of Total Fields in a table which missed rule
DECLARE @intCNTDumps		as int				--Storing No of Dumps maintained per table
DECLARE @PrintFlag			as varchar(10)
DECLARE @TargetType			as int 				--Stores 'baan=1' or 'nonbaan=0' value
DECLARE @DateModified		as datetime			--Stores date modified
DECLARE @UserModified		as varchar(12) 			--Stores user name who modified the rule

/* Get Target Application Name for MPRF(@I_IntMprf) 	*/


SET NOCOUNT OFF

IF(@I_IntFlag  =1 )
BEGIN
	Create table ##TempResult (tbln varchar(8000));
END

IF(@I_IntFlag  =0 )
BEGIN
	Create table ##TempNoRules(tbln varchar(8000));
END

DECLARE BCMAP101_CURSOR   CURSOR STATIC FOR
	--select distinct mprf from bcmap101 where (pprf =@I_IntMprf)	SCA2.2
	select distinct pprf from bcmap101 where mprf between @I_IntMprf and @I_IntMprfTo


OPEN BCMAP101_CURSOR;

FETCH NEXT FROM BCMAP101_CURSOR INTO @intPPRF

SET @intCNTPPRF = @@CURSOR_ROWS

WHILE @intCNTPPRF > 0
	BEGIN



		SELECT @strTargetApp=[dbo].[bcmap100].tapp
		FROM [dbo].[bcmap100]
		WHERE [dbo].[bcmap100].mprf =@intPPRF


		/* Check for application type @TargetType */
		SELECT @TargetType=[dbo].[bcddi100].extn
		FROM [dbo].[bcddi100]
		WHERE [dbo].[bcddi100].appl = @strTargetApp

		/* Finding EMpty fields mappings starts here  */
	IF(@I_IntFlag=1)
	BEGIN



			DECLARE MaintainedTable_CURSOR CURSOR STATIC FOR
			select DISTINCT( tcpac+tcmod+tflno ) from bcmap140 where mprf=@intPPRF and (tcpac+tcmod+tflno between  @I_StrPac and @I_StrPacTo ) and  tcpac+tcmod+tflno in (select tcpac+tcmod+tflno from bcmap120 where mprf = @intPPRF and CAST(FLOOR(CAST(ldat AS float)) AS datetime) >= @I_Strldat and CAST(FLOOR(CAST(ldat AS float)) AS datetime) <= @I_StrldatTo and lusr between @I_StrUsr and @I_StrUsrTo ) order by tcpac+tcmod+tflno;


			OPEN MaintainedTable_CURSOR;

			FETCH NEXT FROM MaintainedTable_CURSOR INTO @strMaintTable

			SET @intCNTMaintTab	= @@CURSOR_ROWS

			--IF(@intCNTMaintTab > 0 )
			--BEGIN
				--SET @strTemp = 'Profile : ' + STR(@intPPRF)
				--Insert into ##TempResult values (@strTemp)

				--SET @strTemp='Target Application : ' + @strTargetApp
				--Insert into ##TempResult values (@strTemp)


			--END

			WHILE @intCNTMaintTab > 0
			BEGIN

				/* DECLARE Cursor to find out no of dumps maintained for particular table */
				DECLARE Dumps_CURSOR CURSOR STATIC FOR
				select DISTINCT dnum from bcmap140  where mprf=  @intPPRF and tcpac+tcmod+tflno= @strMaintTable;
				OPEN Dumps_CURSOR ;
				FETCH NEXT FROM Dumps_CURSOR into @intDump
				SET @intCNTDumps = @@CURSOR_ROWS

				SET @PrintFlag='True';
				WHILE @intCNTDumps > 0
				BEGIN


					/* Declare cursor to find out Missed fields in dumps per table */
					/* First find out whether selected table contains any dept  field*/

					IF(@TargetType=1)
						BEGIN
							DECLARE EmptyFields_CURSOR CURSOR STATIC FOR
							select DISTINCT bcddi150.fdnm from bcddi150 where bcddi150.appl = @strTargetApp
							and bcddi150.comb='N'
							and bcddi150.dept = 0
							and bcddi150.cpac+bcddi150.cmod+bcddi150.flno = @strMaintTable
							and bcddi150.fdnm not in (select bcmap140.fdnm from bcmap140 where mprf= @intPPRF and dnum = @intDump and tcpac+tcmod+tflno= @strMaintTable ) ;
						END

					ELSE

						BEGIN
							DECLARE EmptyFields_CURSOR CURSOR STATIC FOR
							select DISTINCT bclgy150.flna from bclgy150 where bclgy150.appl = @strTargetApp
							and bclgy150.cpac+bclgy150.cmod+bclgy150.flno = @strMaintTable
							and bclgy150.flna not in (select bcmap140.fdnm from bcmap140 where mprf= @intPPRF and dnum = @intDump and tcpac+tcmod+tflno= @strMaintTable ) ;

						END

					OPEN EmptyFields_CURSOR ;

					FETCH NEXT FROM EmptyFields_CURSOR into @strMissedField	 ;
					SET @intCNTMissedField = @@CURSOR_ROWS;



						IF (@intCNTMissedField <> 0 )
						BEGIN
							IF (@PrintFlag = 'True')
							BEGIN
								SET @strTemp ='['+'Profile: ' + STR(@intPPRF) +']'+  '    ' +  '[' + @strMaintTable +']'
								Insert into ##TempResult values (@strTemp)
							END

							SET @strTemp = 'Dump= ' + LTRIM(STR(@intDump))
							Insert into ##TempResult values (@strTemp)

							SET @strTemp ='Empty Fields :'
							Insert into ##TempResult values (@strTemp)


						END

					WHILE @intCNTMissedField > 0
					BEGIN

						IF(@strMissedField IS NOT NULL)
						BEGIN
							Insert into ##TempResult values (@strMissedField)
						END
						SET @intCNTMissedField = @intCNTMissedField - 1

						FETCH NEXT FROM EmptyFields_CURSOR into @strMissedField	 ;

						CONTINUE
					END

					CLOSE EmptyFields_CURSOR
					DEALLOCATE EmptyFields_CURSOR

				IF(@TargetType=1)
				BEGIN

					/* [dbo].sp_EmptydepthFields  is called here which will find missed fields which has got depth in bcddi150*/

					EXEC [dbo].sp_EmptydepthFields @strTargetApp=@strTargetApp,@strMaintTable=@strMaintTable,@intPPRF =@intPPRF,@intDump=@intDump

				END


				/*SET @PrintFlag = 'False'; */
				FETCH NEXT FROM Dumps_CURSOR into @intDump
				SET @intCNTDumps = @intCNTDumps -1

				CONTINUE
				END
				CLOSE Dumps_CURSOR;
				DEALLOCATE Dumps_CURSOR;

				FETCH NEXT FROM MaintainedTable_CURSOR into @strMaintTable
				SET @intCNTMaintTab	= @intCNTMaintTab - 1
				CONTINUE

			END

			CLOSE MaintainedTable_CURSOR;
			DEALLOCATE MaintainedTable_CURSOR;

			FETCH NEXT FROM BCMAP101_CURSOR into @intPPRF
			SET @intCNTPPRF = @intCNTPPRF - 1
			Insert into ##TempResult values (' ')
		END
/* Finding EMpty fields mappings ends here  */


/* Finding No rules starts here  */
	ELSE
		BEGIN
			/*  Below cursor finds table which has got M status but actullay no rules prsent i.e. user might have just checked out and in*/
			DECLARE NoRuleButMaintTabl_CURSOR CURSOR STATIC FOR
			select bcmap120.tcpac+bcmap120.tcmod+bcmap120.tflno,ldat,lusr
			from bcmap120 where ( prtx LIKE '' OR prtx IS NULL) and mprf = @intPPRF and stat='M' and
			lusr between @I_StrUsr and @I_StrUsrTo and
 			CAST(FLOOR(CAST(ldat AS float)) AS datetime) >= @I_Strldat and CAST(FLOOR(CAST(ldat AS float)) AS datetime) <= @I_StrldatTo

			IF(@TargetType=0)
				BEGIN
			/*  Below cursor finds table which has got No Rules in case of Non Baan as target */
					DECLARE   NoRuleTables_CURSOR   CURSOR STATIC FOR
					select cpac+cmod+flno from bclgy140 where bclgy140.appl=@strTargetApp
					and cpac+cmod+flno between @I_StrPac and @I_StrPacTo
					and cpac+cmod+flno not in (select bcmap120.tcpac+bcmap120.tcmod+bcmap120.tflno from bcmap120 where mprf=@intPPRF)
					order by cpac+cmod+flno


				END

			ELSE

				BEGIN
			/*  Below cursor finds table which has got No Rules in case of Baan as target */
					DECLARE NoRuleTables_CURSOR   CURSOR STATIC FOR
					select cpac+cmod+flno from bcddi140 where bcddi140.appl=@strTargetApp
					and cpac+cmod+flno between @I_StrPac and @I_StrPacTo
					and cpac+cmod+flno not in (select bcmap120.tcpac+bcmap120.tcmod+bcmap120.tflno from bcmap120 where mprf=@intPPRF)
					order by cpac+cmod+flno

				END

			/*  Retrieve and insert both cursor data into ##TempNoRules  table */

				OPEN NoRuleTables_CURSOR;

				FETCH NEXT FROM NoRuleTables_CURSOR INTO @strNoRuleTable;
				SET @intCNTTab = @@CURSOR_ROWS

				--IF(@intCNTTab>0)
				--BEGIN
					--SET @strTemp = 'Profile : ' + STR(@intPPRF)
					--Insert into ##TempNoRules values (@strTemp + '^' + '' + '^' + '' +'^' + '')
					--Insert into ##TempNoRules values ('---------------' +'^' + '---------------' + '^' + '---------------' + '^'  + '---------------' + '^' )
				--END


				WHILE @intCNTTab > 0
				BEGIN
					Insert into ##TempNoRules values (STR(@intPPRF) + '^' + @strNoRuleTable + '^' + '-' + '^' + '-' +'^' + 'No-Rules')
					FETCH NEXT FROM NoRuleTables_CURSOR INTO @strNoRuleTable;
					SET @intCNTTab = @intCNTTab - 1
					CONTINUE

				END

				--Insert into ##TempNoRules values ('--------------------------')

				CLOSE NoRuleTables_CURSOR;
				DEALLOCATE NoRuleTables_CURSOR;

				/* Now retrieve records from No rules but maintaied cursor  */
				OPEN NoRuleButMaintTabl_CURSOR;


				FETCH NEXT FROM NoRuleButMaintTabl_CURSOR INTO @strNoRuleTable_ButM,@DateModified,@UserModified;
				SET @intCNTTab_M = @@CURSOR_ROWS

				--IF( @intCNTTab_M > 0)
				--BEGIN
					--SET @strTemp = 'Profile : ' + STR(@intPPRF)
					--Insert into ##TempNoRules values (@strTemp + '^' + '' + '^' + '' +'^' + '')
					--Insert into ##TempNoRules values ('---------------' +'^' + '---------------' + '^' + '---------------' + '^'  + '---------------' + '^' )
				--END

				WHILE @intCNTTab_M > 0
				BEGIN
					DECLARE @tempSTR as varchar(8000)
					SET @tempSTR = STR(@intPPRF) +  '^' + @strNoRuleTable_ButM + '^' + CONVERT(varchar,@DateModified,100) + '^' +  @UserModified +'^' + 'Maintained'
					Insert into ##TempNoRules values (@tempSTR)

					FETCH NEXT FROM NoRuleButMaintTabl_CURSOR INTO @strNoRuleTable_ButM,@DateModified,@UserModified;
						SET @intCNTTab_M = @intCNTTab_M - 1
					CONTINUE

				END ;

			--	Insert into ##TempNoRules values ('---------------' +'^' + '---------------' + '^' + '---------------' + '^'  + '---------------' + '^' )

				CLOSE NoRuleButMaintTabl_CURSOR;
				DEALLOCATE NoRuleButMaintTabl_CURSOR;
				Insert into ##TempNoRules values (''+ '^' + '' +'^' + '' + '^' + '' + '^'  + '' + '^' )
				FETCH NEXT FROM BCMAP101_CURSOR into @intPPRF
				SET @intCNTPPRF = @intCNTPPRF - 1



		END
		/* Finding No rules ENds  here  */




	CONTINUE


CLOSE BCMAP101_CURSOR
DEALLOCATE BCMAP101_CURSOR

END


GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

CREATE PROCEDURE [dbo].[sp_EmptydepthFields]
(
	@strTargetApp  varchar(60),
	@strMaintTable  varchar(60),
	@intPPRF [int],
	@intDump [int]
)
AS

DECLARE @cntDept	as integer;
DECLARE @strFdnm	as varchar(60);
DECLARE @intDepth	as integer;
DECLARE @intTempDepth	as integer;
DECLARE @intCNTDepth	as integer;
DECLARE @intCNTMapDep	as integer;
DECLARE @strMapDeptField	as varchar(60);
DECLARE @strTempDepth	as varchar(60);
DECLARE @strMissedDept	as varchar(60);
DECLARE @strTemp		as varchar(2000)		--Storing temporary string

SET NOCOUNT ON
select @cntDept=count(*) from bcddi150 where bcddi150.appl = @strTargetApp
	and bcddi150.comb='N'
	and bcddi150.dept > 0
	and bcddi150.cpac+bcddi150.cmod+bcddi150.flno = @strMaintTable;


IF (@cntDept > 0)
BEGIN

	Create table #DeptTemp (fdnm varchar(60));
	Create table #DeptMap (fdnm varchar(60));

	DECLARE DepthFields_CURSOR CURSOR STATIC FOR
		select fdnm,dept from bcddi150 where appl = @strTargetApp
		and bcddi150.comb='N'
		and bcddi150.dept > 0
		and cpac+cmod+flno = @strMaintTable;

	OPEN DepthFields_CURSOR ;

	FETCH NEXT FROM DepthFields_CURSOR into @strFdnm,@intDepth ;
	SET @intCNTDepth = @@CURSOR_ROWS;

	WHILE @intCNTDepth > 0
		BEGIN
			SET @intTempDepth = @intDepth
			While @intTempDepth > 0
			BEGIN
				SET @strTempDepth = LTRIM(@strFdnm) + '(' + LTRIM(STR(@intTempDepth))+ ')'
				Insert into #DeptTemp values (@strTempDepth)
				SET @intTempDepth = @intTempDepth - 1
				CONTINUE
			END

			SET @strTempDepth = @strFdnm + '(%)'
			DECLARE BCMAP140Depth_CURSOR CURSOR STATIC FOR
				select fdnm from bcmap140 where mprf= @intPPRF
				and dnum = @intDump
				and tcpac+tcmod+tflno= @strMaintTable
				and fdnm LIKE @strTempDepth ;

			OPEN BCMAP140Depth_CURSOR ;
			FETCH NEXT FROM BCMAP140Depth_CURSOR into @strMapDeptField;
			SET @intCNTMapDep = @@CURSOR_ROWS;
			WHILE @intCNTMapDep > 0
				BEGIN
					Insert into #DeptMap values (LTRIM(@strMapDeptField));
					SET @intCNTMapDep =@intCNTMapDep - 1
					FETCH NEXT FROM BCMAP140Depth_CURSOR into @strMapDeptField;
					CONTINUE
				END

			CLOSE BCMAP140Depth_CURSOR
			DEALLOCATE BCMAP140Depth_CURSOR

			/* Write missed depth fields by compairing data in temporary tables  */
				DECLARE MissedDepth_CURSOR CURSOR STATIC FOR
				select #DeptTemp.fdnm from #DeptTemp where #DeptTemp.fdnm not in( select #DeptMap.fdnm from #DeptMap)

				OPEN MissedDepth_CURSOR ;
				FETCH NEXT FROM MissedDepth_CURSOR  into @strMissedDept;
				SET @intCNTMapDep = @@CURSOR_ROWS;

				if(@intCNTMapDep > 0 )
				BEGIN
					SET @strTemp ='['+'Profile: ' + STR(@intPPRF) +']'+  '    ' +  '[' + @strMaintTable +']'
					Insert into ##TempResult values (@strTemp)

					SET @strTemp = 'Dump= ' + LTRIM(STR(@intDump))
					Insert into ##TempResult values (@strTemp)

					SET @strTemp ='Empty Depth Fields :'
					Insert into ##TempResult values (@strTemp)

				END

					WHILE @intCNTMapDep > 0
					BEGIN
						IF(@strMissedDept IS NOT NULL)
						BEGIN
							Insert into ##TempResult values (@strMissedDept)
						END
						SET @intCNTMapDep = @intCNTMapDep - 1;
						FETCH NEXT FROM MissedDepth_CURSOR into @strMissedDept;
						CONTINUE
					END

				CLOSE MissedDepth_CURSOR
				DEALLOCATE MissedDepth_CURSOR
		DELETE FROM #DeptTemp;
		DELETE FROM #DeptMap;

		SET @intCNTDepth = @intCNTDepth - 1
		FETCH NEXT FROM DepthFields_CURSOR into @strFdnm,@intDepth ;

		CONTINUE
		END


	CLOSE DepthFields_CURSOR
	DEALLOCATE DepthFields_CURSOR

END

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

