Print ''
Print '-------------------------------------------------------------------------'
Print ' using Database: #DB_N#'
Print ' Procedures    : [JobMgr_30_ApplProceduresObjects_Import_Object.sql]'
Print ' Autor         : J.Feuerstein'
Print ' Creation Date : 08.08.2014'
Print ' Last Update   : 06.07.2017/J.Fes'
Print '-------------------------------------------------------------------------'

use [#DB_N#]

Print '-- [Object_Import_GetProcStatFromMask_UDF] -------------------------------'
If Exists (select Name
           from sysobjects
            where Name = "Object_Import_GetProcStatFromMask_UDF")
DROP FUNCTION Object_Import_GetProcStatFromMask_UDF
GO

--- Returns from ProcStateMask value of ProcStateColume
CREATE FUNCTION Object_Import_GetProcStatFromMask_UDF(@ProcStateMask_p nvarchar(220) ,@Num int)
RETURNS varchar(32)
AS
BEGIN
   RETURN rtrim(substring(@ProcStateMask_p,  (@Num -1) * 10 + 1 ,10))
END
GO

Print '-- [Object_Import_Get_ProcessStatus_on_X_PLM_ERR_UDF #New:06.07.17] -----'
If Exists (select Name
           from sysobjects
            where Name = 'Object_Import_Get_ProcessStatus_on_X_PLM_ERR_UDF')
DROP FUNCTION Object_Import_Get_ProcessStatus_on_X_PLM_ERR_UDF
GO


-- returs for @ObjectId_p new value for @ProcStateCol if X_PLM_ERR is requested
CREATE FUNCTION Object_Import_Get_ProcessStatus_on_X_PLM_ERR_UDF(@ObjectId_p uniqueidentifier,
                                                                 @ProcStateColVal_p nvarchar(32),
                                                                 @ProcStateCol_p nvarchar(2),
                                                                 @ProcStateMask_p nvarchar(220),
                                                                 @Num int
                                                                 )
RETURNS nvarchar(32)
AS
BEGIN
    -- Returns final ProcSatCol val
    DECLARE @ProcStateColVal_c nvarchar(32),
            @ProcStateColVal_r nvarchar(32)

    -- #Doc: Get status for @ProcStateCol_p from Objects_tbl via @ObjectId_p
    set @ProcStateColVal_c = dbo.Objects_tbl_Object_Get_ProcessStatus_UDF(@ObjectId_p, @ProcStateCol_p)
    if @ProcStateColVal_c = 'X.PLM.ERR'
    BEGIN
     -- #Doc: set @ProcStateColVal_r to value from @ProcStateMask_p
     -- #Doc: -> it sets value to P.Status from ImportMask ('N')
     SET @ProcStateColVal_r = dbo.Object_Import_GetProcStatFromMask_UDF(@ProcStateMask_p,@Num)
    END
    ELSE
    BEGIN
     -- #Doc: set @ProcStateColVal_r to value @ProcStateColVal_p
     -- #Doc: -> because no change on @ProcStateColVal
     SET @ProcStateColVal_r = @ProcStateColVal_p
    END

    RETURN @ProcStateColVal_r
END
GO




Print '-- [Object_Import] ------------------------------------------------------'
If Exists (select Name
           from sysobjects
           where Name = "Object_Import" and type = "P")
Drop Procedure Object_Import
GO





Create Procedure Object_Import @ObjectPuid                    nvarchar(64),         -- 01 change 22.08.2012 a.becker (size from 15 to 32) #LUp:30.11.17 J.Fes (size from 32 to 64)
                               @ObjectName                    nvarchar(128),        -- 02 25.10.2018 S.Gueth (size from 64 to 128)
                               @ObjectName2                   nvarchar(128),        -- 03 25.10.2018 S.Gueth (size from 64 to 128)
                               @ObjectDescription             nvarchar(255),        -- 04

                               @ObjectFromSiteID              nvarchar(32),         -- 05
                               @ObjectCliName                 nvarchar(255),        -- 06
                               @ObjectClass                   nvarchar(10),         -- 07 ITem IR DS

                               @ObjectOwningSiteID            nvarchar(32),         -- 08
                               @ObjectExportRecord            nvarchar(255) = null, -- 09: #New: 16.08.2013/J.Fes
                               @ObjectExportRecordDate        datetime = null,      -- 10: #New 20.08.2013/J.Fes

                               @ObjectType                    nvarchar(32),         -- 11: UGMASTER UGPART ..

                               @ObjectOwner                   nvarchar(32),         -- 12:
                               @ObjectGroup                   nvarchar(255),        -- 13: #Upd: 16.09.2015/J.Fes size enlarged
                               @ObjectCreateDate              datetime = null,      -- 14:
                               @ObjectLastModUser             nvarchar(32),         -- 15:
                               @ObjectLastModDate             datetime = null,      -- 16:

                               @ObjectFs_DPNE                 nvarchar(255)= null,  -- 17:
                               @ObjectFs_Vol                  nvarchar(64) = null,  -- 18:
                               @ObjectFs_NE                   nvarchar(64) = null,  -- 19:
                               @ObjectFs_SizeBytes            bigint = null,        -- 20:new 22.08.2012 a.becker angepasst 09.11.2012 10:50

                               @ObjectFs_HashCode             nvarchar(64),         -- 21:new 22.08.2012 a.becker
                               @ObjectFs_LastModDate          datetime = null,      -- 22:new 25.04.2014 J.Fes

                               @ObjectDs_Ver                  int  = null,          -- 23:#New: 27.05.2016 J.Fes
                               @ObjectDs_VerKeepLimt          int  = null,          -- 25:#New: 27.05.2016 J.Fes
                               @ObjectDs_VersN                int  = null,          -- 25:#New: 27.05.2016 J.Fes

                               @ObjectSaveVersion             nvarchar(64),         -- 26:#New 22.08.2012 a.becker

                               @ObjectUgMaster_PartFamMemName  nvarchar(64) = null, -- 27:
                               @ObjectUgMaster_Type            nvarchar(32),        -- 28: SP AP
                               @ObjectUgMaster_APLevels        int,                 -- 29:
                               @ObjectUgMaster_CompCount       int,                 -- 30:
                               @ObjectUgMaster_CompCountUnique int,                 -- 31: new 22.08.2012 a.becker
                               @ObjectUgMaster_FsHitCount      int,                 -- 32:

                               @ObjectReleaseState            nvarchar(255) = null, -- 33: UPd: 11.01.2019/J.Fes upsize 32 -255
                               @ObjectReleaseDate             datetime = null,      -- 34:

                               @ObjectNote                    nvarchar(255),        -- 35:
                               @ObjectPrjIds                  nvarchar(255),        -- 36: #New: 01.04.2013 J.Fes

                               @ImportObjectNewProcStateMask  nvarchar(220),        -- 37: LUp:01.03.2016 + P.Gr Mc /  Up:08.08.2014 / J.Fes je Pgr = 10
                               @ImportObjectUpdProcStateMask  nvarchar(220),        -- 38: LUp:01.03.2016 + P.Gr Mc / J.Fes je Pgr = 10
                               @ImportObjectErr_p               nvarchar(64),       -- 39

                               -- #New: 07.08.2014 Start -------------------------
                               @ObjectUgMaster_Lev1CompN       int = null ,         -- 40
                               @ObjectUgMaster_Lev1CompUniqueN int = null ,         -- 41
                               @ObjectUgMaster_ApBOM_isPrecise bit = null ,         -- 42

                               @ObjectAttr01                   nvarchar(255) = null , -- 43
                               @ObjectAttr02                   nvarchar(255) = null , -- 44
                               @ObjectAttr03                   nvarchar(255) = null , -- 45
                               @ObjectAttr04                   nvarchar(255) = null , -- 46
                               @ObjectAttr05                   nvarchar(255) = null , -- 47
                               @ObjectAttr06                   nvarchar(255) = null , -- 48
                               @ObjectAttr07                   nvarchar(255) = null , -- 49
                               @ObjectAttr08                   nvarchar(255) = null , -- 50
                               @ObjectAttr09                   nvarchar(255) = null , -- 51
                               @ObjectAttr10                   nvarchar(255) = null , -- 52   
                               
                               -- #New: 21.08.2019 S.Gueth
                               @MultiCadAP                     nvarchar(255) = null , 
                               -- #New: 21.08.2019 S.Gueth
                               @MultiCadItemRevs               nvarchar(max) = null , 

                               -- #New: 29.04.2019
                               @DoUpdateRank                   bit,  -- #New: 29.04.2019/Anton

                               -- #New: 07.08.2014 Ende -------------------------

                               @IrId                          uniqueidentifier,        -- 53
                               @IrPuid                        nvarchar(32),            -- 54: change A.Becker 22.08.2012: Puid Feld von 15 auf 32 Zeichen erweitert
                               @ObjectId                      uniqueidentifier Output  -- 55:


--  Lastet ein Object in die Datenbank ein wichtig: bei Struktur anpassungen ist immer die .. dazugehörigen View auch zu prüfen !!
--  31.12.2008 J.Fes @ImportObjectErr_p
--  12.07.2010 J.Fes Transaction methoden eingefuegt
--  24.02.2011 J.Fes @IrId eingefuegt
--  22.08.2012 A.Becker: @ObjectFs_SizeBytes, @ObjectFs_HashCode, @ObjectSaveVersion und @ObjectUgMaster_CompCountUnique hinzugefügt
--  07.11.2016 J.Fes Update ObjectSyncTrigger = null add
As
BEGIN

 DECLARE @DebugPrintOn bit,
         @MyProcName nvarchar(32),
         @ImportObjectErr_c nvarchar(64),
         @StatusXRemove nvarchar(10)

 set @DebugPrintOn = 0
 set @MyProcName='Object_Import'
 set @ImportObjectErr_c = ""

-- #DOC: Updated removed 30.05.2018 15:36
--   if @ObjectType <> 'UGMASTER' and  @ObjectType <> 'UGPART'
--     and  @ObjectType <> 'PROPRT' and  @ObjectType <> 'PROASM' and  @ObjectType <> 'PRODRW'
--     BEGIN
--        set @ObjectUgMaster_PartFamMemName = ""
--     END
  -- set @ObjectUgMaster_PartFamMemName = "#Debug"


 if @DebugPrintOn = 1
 begin
  -- Clear Debug Table
  -- EXECUTE zzzzzDebugTbl_Empty
  EXECUTE zzzzzDebugTbl_AddDataSet @MyProcName , '###########################' ,    '###################'
  EXECUTE zzzzzDebugTbl_AddDataSet @MyProcName , '01-@ObjectPuid' ,    @ObjectPuid
  EXECUTE zzzzzDebugTbl_AddDataSet @MyProcName , '02-@ObjectCliName' , @ObjectCliName
  EXECUTE zzzzzDebugTbl_AddDataSet @MyProcName , '03-@ObjectType' ,    @ObjectType
  EXECUTE zzzzzDebugTbl_AddDataSet @MyProcName , '04-@ObjectClass' ,   @ObjectClass
 end


 DECLARE @RetryCounter INT
 SET @RetryCounter = 1
 RETRY:             -- Label RETRY
 BEGIN TRY          -- Begin TRY
 BEGIN TRANSACTION  -- BEGIN Transaction 03.09.2010 14:39 Verlegt J.Fes/A.Becker



  EXECUTE JF_DateResetCheck @ObjectReleaseDate Output

  DECLARE @ProcStateCol01Val nvarchar(32),
          @ProcStateCol02Val nvarchar(32),
          @ProcStateCol03Val nvarchar(32),
          @ProcStateCol04Val nvarchar(32),
          @ProcStateCol05Val nvarchar(32),
          @ProcStateCol06Val nvarchar(32),
          @ProcStateCol07Val nvarchar(32),
          @ProcStateCol08Val nvarchar(32),
          @ProcStateCol09Val nvarchar(32),
          @ProcStateCol10Val nvarchar(32),
          @ProcStateCol11Val nvarchar(32),
          @ProcStateCol12Val nvarchar(32),
          @ProcStateCol13Val nvarchar(32),
          @ProcStateCol14Val nvarchar(32),
          @ProcStateCol15Val nvarchar(32),
          @ProcStateCol16Val nvarchar(32),
          @ProcStateCol17Val nvarchar(32),
          @ProcStateCol18Val nvarchar(32),
          @ProcStateCol19Val nvarchar(32),
          @ProcStateCol20Val nvarchar(32),
          @ProcStateColRfVal nvarchar(32),
          @ProcStateColMcVal nvarchar(32)

  -- set @ObjectCliName = @ObjectCliName + 'Debug#:Test'
  -- debug: BgStrukEx-Einzelteil-01_01/A;BgStrukEx-Einzelteil-01_01/B
  -- ermittelt @ObjectId Id der IR in der Objects_tbl
  EXECUTE Objects_tbl_Object_GetId_via_ObjectPuid
          @ObjectPuid, @ObjectCliName, @ObjectFromSiteID,
          @ObjectClass,
          @IrId,
          @IrPuid,
          @ObjectId Output

  if @ObjectId IS NULL
     BEGIN
      SET @ProcStateCol01Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectNewProcStateMask,01)
      SET @ProcStateCol02Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectNewProcStateMask,02)
      SET @ProcStateCol03Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectNewProcStateMask,03)
      SET @ProcStateCol04Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectNewProcStateMask,04)
      SET @ProcStateCol05Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectNewProcStateMask,05)
      SET @ProcStateCol06Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectNewProcStateMask,06)
      SET @ProcStateCol07Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectNewProcStateMask,07)
      SET @ProcStateCol08Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectNewProcStateMask,08)
      SET @ProcStateCol09Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectNewProcStateMask,09)
      SET @ProcStateCol10Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectNewProcStateMask,10)
      SET @ProcStateCol11Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectNewProcStateMask,11)
      SET @ProcStateCol12Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectNewProcStateMask,12)
      SET @ProcStateCol13Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectNewProcStateMask,13)
      SET @ProcStateCol14Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectNewProcStateMask,14)
      SET @ProcStateCol15Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectNewProcStateMask,15)
      SET @ProcStateCol16Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectNewProcStateMask,16)
      SET @ProcStateCol17Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectNewProcStateMask,17)
      SET @ProcStateCol18Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectNewProcStateMask,18)
      SET @ProcStateCol19Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectNewProcStateMask,19)
      SET @ProcStateCol20Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectNewProcStateMask,20)
      SET @ProcStateColMcVal = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectNewProcStateMask,21)
      SET @ProcStateColRfVal = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectNewProcStateMask,22)


      if @DebugPrintOn = 1
      begin
        EXECUTE zzzzzDebugTbl_AddDataSet @MyProcName , '13-@ObjectId IS:' , 'NULL'
        EXECUTE zzzzzDebugTbl_AddDataSet @MyProcName , '14-@ImportObjectNewProcStateMask' , @ImportObjectNewProcStateMask
        EXECUTE zzzzzDebugTbl_AddDataSet @MyProcName , '15-@ProcStateCol01Val' , @ProcStateCol01Val
      end

      -- NEWSEQUENTIALID()
      -- http://sqlpractice.wordpress.com/2010/04/08/sql-server-newid-versus-newsequentialid/ 04.03.2011 21:15 von Alex
      -- last ID get via SCOPE_IDENTITY()
      SET @ObjectId = NEWID()

      if @DebugPrintOn = 1
      begin
        EXECUTE zzzzzDebugTbl_AddDataSet @MyProcName , '21-@ObjectId nf:do add new' , @ObjectId
      end
      INSERT INTO Objects_tbl (ID ,
                               ObjectPuid ,
                               ObjectName ,
                               ObjectName2 ,
                               ObjectDescription ,

                               ObjectFromSiteID ,
                               ObjectCliName ,
                               ObjectClass ,

                               ObjectOwningSiteID ,
                               ObjectExportRecord ,
                               ObjectExportRecordDate ,
                               ObjectType ,

                               ObjectOwner ,
                               ObjectGroup ,
                               ObjectCreateDate ,
                               ObjectLastModUser ,
                               ObjectLastModDate ,
                               ObjectNote , --  21.10.2009 J.Fes eingefuegt
                               ObjectPrjIds , --  01.04.2013 J.Fes eingefuegt

                               ObjectFs_DPNE ,
                               ObjectFs_Vol ,
                               ObjectFs_NE ,
                               ObjectFs_SizeBytes , -- new 22.08.2012 a.becker
                               ObjectFs_HashCode ,  -- new 22.08.2012 a.becker
                               ObjectFs_LastModDate , -- new 25.04.2014 J.Fes

                               ObjectDs_Ver,          -- #New: 27.05.2016 J.Fes
                               ObjectDs_VerKeepLimt,  -- #New: 27.05.2016 J.Fes
                               ObjectDs_VersN,  -- #New: 27.05.2016 J.Fes

                               ObjectSaveVersion ,   -- new 22.08.2012 a.becker

                               ObjectUgMaster_PartFamMemName ,
                               ObjectUgMaster_Type ,
                               ObjectUgMaster_APLevels ,
                               ObjectUgMaster_CompCount ,
                               ObjectUgMaster_CompCountUnique , -- new 22.08.2012 a.becker
                               ObjectUgMaster_FsHitCount ,

                               ObjectReleaseState ,
                               ObjectReleaseDate ,

                               ProcStateCol01,
                               ProcStateCol02,
                               ProcStateCol03,
                               ProcStateCol04,
                               ProcStateCol05,
                               ProcStateCol06,
                               ProcStateCol07,
                               ProcStateCol08,
                               ProcStateCol09,
                               ProcStateCol10,
                               ProcStateCol11, -- #New: 08.08.2014 / J.fes
                               ProcStateCol12,
                               ProcStateCol13,
                               ProcStateCol14,
                               ProcStateCol15,
                               ProcStateCol16,
                               ProcStateCol17,
                               ProcStateCol18,
                               ProcStateCol19,
                               ProcStateCol20,
                               ProcStateColMc, -- #New:02.03.2016/J.Fes
                               ProcStateColRf,

                               ImportObjectErr,

                               ObjectUgMaster_Lev1CompN,
                               ObjectUgMaster_Lev1CompUniqueN,
                               ObjectUgMaster_ApBOM_isPrecise,

                               ObjectAttr01,
                               ObjectAttr02,
                               ObjectAttr03,
                               ObjectAttr04,
                               ObjectAttr05,
                               ObjectAttr06,
                               ObjectAttr07,
                               ObjectAttr08,
                               ObjectAttr09,
                               ObjectAttr10,
                               MultiCadAP,
                               MultiCadItemRevs,

                               ObjectSyncTrigger

                               )
                  VALUES      (@ObjectId ,
                               @ObjectPuid ,
                               @ObjectName ,
                               @ObjectName2 ,
                               @ObjectDescription ,

                               @ObjectFromSiteID ,
                               @ObjectCliName ,
                               @ObjectClass ,

                               @ObjectOwningSiteID ,
                               @ObjectExportRecord ,
                               @ObjectExportRecordDate ,
                               @ObjectType ,
--                                entnommen J.Fes/ 10.01.2012
--                                @ObjectIrType ,

                               @ObjectOwner ,
                               @ObjectGroup ,
                               @ObjectCreateDate ,
                               @ObjectLastModUser ,
                               @ObjectLastModDate ,
                               @ObjectNote ,
                               @ObjectPrjIds ,

                               @ObjectFs_DPNE ,
                               @ObjectFs_Vol ,
                               @ObjectFs_NE ,
                               @ObjectFs_SizeBytes ,   -- new 22.08.2012 a.becker
                               @ObjectFs_HashCode ,    -- new 22.08.2012 a.becker
                               @ObjectFs_LastModDate , -- new 25.04.2014 J.Fes

                               @ObjectDs_Ver ,         -- #New: 27.05.2016/J.Fes
                               @ObjectDs_VerKeepLimt,  -- #New: 27.05.2016/J.Fes
                               @ObjectDs_VersN ,         -- #New: 27.05.2016/J.Fes

                               @ObjectSaveVersion ,    -- new 22.08.2012 a.becker

                               @ObjectUgMaster_PartFamMemName ,
                               @ObjectUgMaster_Type ,
                               @ObjectUgMaster_APLevels ,
                               @ObjectUgMaster_CompCount ,
                               @ObjectUgMaster_CompCountUnique , -- new 22.08.2012 a.becker
                               @ObjectUgMaster_FsHitCount ,

                               @ObjectReleaseState ,
                               @ObjectReleaseDate ,

                               @ProcStateCol01Val ,
                               @ProcStateCol02Val ,
                               @ProcStateCol03Val ,
                               @ProcStateCol04Val ,
                               @ProcStateCol05Val ,
                               @ProcStateCol06Val ,
                               @ProcStateCol07Val ,
                               @ProcStateCol08Val ,
                               @ProcStateCol09Val ,
                               @ProcStateCol10Val ,
                               @ProcStateCol11Val,
                               @ProcStateCol12Val, -- #New: 08.08.2014 / J.fes
                               @ProcStateCol13Val,
                               @ProcStateCol14Val,
                               @ProcStateCol15Val,
                               @ProcStateCol16Val,
                               @ProcStateCol17Val,
                               @ProcStateCol18Val,
                               @ProcStateCol19Val,
                               @ProcStateCol20Val,

                               @ProcStateColMcVal , -- #New:02.03.2016/J.Fes
                               @ProcStateColRfVal ,

                               @ImportObjectErr_p ,

                               @ObjectUgMaster_Lev1CompN,
                               @ObjectUgMaster_Lev1CompUniqueN,
                               @ObjectUgMaster_ApBOM_isPrecise,

                               @ObjectAttr01,
                               @ObjectAttr02,
                               @ObjectAttr03,
                               @ObjectAttr04,
                               @ObjectAttr05,
                               @ObjectAttr06,
                               @ObjectAttr07,
                               @ObjectAttr08,
                               @ObjectAttr09,
                               @ObjectAttr10,
                               @MultiCadAP, 
                               @MultiCadItemRevs,
                               Null
                               )
       -- SET @ReturnValue = @ReturnValue + '/DataSet=Add'
     END
  ELSE
     BEGIN
      -- DS.: Exist Update erforderlich'
      -- Now: Edit Datensatz mit @Id:=' + CONVERT(varchar(100), @Id)
      -- #New: 14.06.2017/J.Fes get current of ImportObjectErr
      select @ImportObjectErr_c=ImportObjectErr FROM Objects_tbl WITH (nolock) WHERE Id = @ObjectId

      if @DebugPrintOn = 1
      begin
       EXECUTE zzzzzDebugTbl_AddDataSet @MyProcName , '21-@ObjectId found YES:do Update' , @ObjectId
       EXECUTE zzzzzDebugTbl_AddDataSet @MyProcName , '22-@ImportObjectErr_c' , @ImportObjectErr_c
       EXECUTE zzzzzDebugTbl_AddDataSet @MyProcName , '23-@ImportObjectErr_p' , @ImportObjectErr_p
      end

      UPDATE Objects_tbl
             SET ObjectPuid         = @ObjectPuid ,
                 ObjectName         = @ObjectName ,
                 ObjectName2        = @ObjectName2 ,
                 ObjectDescription  = @ObjectDescription ,

                 ObjectFromSiteID   = @ObjectFromSiteID ,
                 ObjectCliName      = @ObjectCliName ,
                 ObjectClass        = @ObjectClass ,

                 ObjectOwningSiteID = @ObjectOwningSiteID ,
                 ObjectExportRecord = @ObjectExportRecord ,
                 ObjectExportRecordDate = @ObjectExportRecordDate ,
                 ObjectType         = @ObjectType ,
--                 10.01.2012 J.Fes entnommen
--                 ObjectIrType       = @ObjectIrType , -- 20.12.2011 06:27 eingefuegt

                 ObjectOwner        = @ObjectOwner ,
                 ObjectGroup        = @ObjectGroup ,
                 ObjectCreateDate   = @ObjectCreateDate ,
                 ObjectLastModUser  = @ObjectLastModUser ,
                 ObjectLastModDate  = @ObjectLastModDate ,
                 ObjectNote         = @ObjectNote , -- 21.10.2009 eingefuegt JFes
                 ObjectPrjIds       = @ObjectPrjIds , -- 01.04.2013 eingefuegt JFes

                 ObjectFs_DPNE      = @ObjectFs_DPNE ,
                 ObjectFs_Vol       = @ObjectFs_Vol ,
                 ObjectFs_NE        = @ObjectFs_NE ,
                 ObjectFs_SizeBytes = @ObjectFs_SizeBytes ,  -- new 22.08.2012 a.becker
                 ObjectFs_HashCode  = @ObjectFs_HashCode ,   -- new 22.08.2012 a.becker
                 ObjectFs_LastModDate = @ObjectFs_LastModDate ,

                 ObjectDs_Ver         = @ObjectDs_Ver ,        -- #New: 27.05.2016/J.Fes
                 ObjectDs_VerKeepLimt = @ObjectDs_VerKeepLimt, -- #New: 27.05.2016/J.Fes
                 ObjectDs_VersN       = @ObjectDs_VersN ,      -- #New: 27.05.2016/J.Fes

                 ObjectSaveVersion   = @ObjectSaveVersion ,    -- new 22.08.2012 a.becker / Einkommentiert 19.03.2019 S.Gueth

                 ObjectUgMaster_PartFamMemName  = @ObjectUgMaster_PartFamMemName ,
                 ObjectUgMaster_Type            = @ObjectUgMaster_Type ,
                 ObjectUgMaster_APLevels        = @ObjectUgMaster_APLevels ,
                 ObjectUgMaster_CompCount       = @ObjectUgMaster_CompCount ,
                 ObjectUgMaster_CompCountUnique = @ObjectUgMaster_CompCountUnique , -- new 22.08.2012 a.becker
                 ObjectUgMaster_FsHitCount      = @ObjectUgMaster_FsHitCount ,

                 ObjectReleaseState = @ObjectReleaseState ,
                 ObjectReleaseDate  = @ObjectReleaseDate ,

                 ImportObjectErr = @ImportObjectErr_p ,

                 ObjectUgMaster_Lev1CompN = @ObjectUgMaster_Lev1CompN ,
                 ObjectUgMaster_Lev1CompUniqueN = @ObjectUgMaster_Lev1CompUniqueN ,
                 ObjectUgMaster_ApBOM_isPrecise = @ObjectUgMaster_ApBOM_isPrecise ,

                 -- #LUp: 08.06.2019/J.Fes update Object Attr values only if not NULL
                 ObjectAttr01 = ISNULL(@ObjectAttr01, ObjectAttr01),
                 ObjectAttr02 = ISNULL(@ObjectAttr02, ObjectAttr02),
                 ObjectAttr03 = ISNULL(@ObjectAttr03, ObjectAttr03),
                 ObjectAttr04 = ISNULL(@ObjectAttr04, ObjectAttr04),
                 ObjectAttr05 = ISNULL(@ObjectAttr05, ObjectAttr05),
                 ObjectAttr06 = ISNULL(@ObjectAttr06, ObjectAttr06),
                 ObjectAttr07 = ISNULL(@ObjectAttr07, ObjectAttr07),
                 ObjectAttr08 = ISNULL(@ObjectAttr08, ObjectAttr08),
                 ObjectAttr09 = ISNULL(@ObjectAttr09, ObjectAttr09),
                 ObjectAttr10 = ISNULL(@ObjectAttr10, ObjectAttr10),
                 
                 MultiCadAP = @MultiCadAP,
                 MultiCadItemRevs = @MultiCadItemRevs,

                 ObjectSyncTrigger = null

             Where Id = @ObjectId

             -- Updating ProcState
             SET @ProcStateCol01Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectUpdProcStateMask,01)
             SET @ProcStateCol02Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectUpdProcStateMask,02)
             SET @ProcStateCol03Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectUpdProcStateMask,03)
             SET @ProcStateCol04Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectUpdProcStateMask,04)
             SET @ProcStateCol05Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectUpdProcStateMask,05)
             SET @ProcStateCol06Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectUpdProcStateMask,06)
             SET @ProcStateCol07Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectUpdProcStateMask,07)
             SET @ProcStateCol08Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectUpdProcStateMask,08)
             SET @ProcStateCol09Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectUpdProcStateMask,09)
             SET @ProcStateCol10Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectUpdProcStateMask,10)
             SET @ProcStateCol11Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectUpdProcStateMask,11)
             SET @ProcStateCol12Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectUpdProcStateMask,12)
             SET @ProcStateCol13Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectUpdProcStateMask,13)
             SET @ProcStateCol14Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectUpdProcStateMask,14)
             SET @ProcStateCol15Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectUpdProcStateMask,15)
             SET @ProcStateCol16Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectUpdProcStateMask,16)
             SET @ProcStateCol17Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectUpdProcStateMask,17)
             SET @ProcStateCol18Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectUpdProcStateMask,18)
             SET @ProcStateCol19Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectUpdProcStateMask,19)
             SET @ProcStateCol20Val = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectUpdProcStateMask,20)
             SET @ProcStateColMcVal = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectUpdProcStateMask,21)
             SET @ProcStateColRfVal = dbo.Object_Import_GetProcStatFromMask_UDF(@ImportObjectUpdProcStateMask,22)

             -- #Doc: behandeln von X. via ImportObjectErr  -----------------------------
             -- CASE @ImportObjectErr_p =  "" and @ImportObjectErr_c  = ""  as now set Status=...
             -- CASE @ImportObjectErr_p <> "" and @ImportObjectErr_c  = ""  as now set Status=...
             -- CASE @ImportObjectErr_p <> "" and @ImportObjectErr_c  = <>  as now set Status=...
             -- CASE @ImportObjectErr_p =  "" and @ImportObjectErr_c <> ""  remove Status=X.
             if charindex('ERR',@ImportObjectErr_c) > 0 and charindex('ERR',@ImportObjectErr_p) = 0
              BEGIN
                -- #Doc: Object Err have a value before and now not anymore
                -- #Doc: then replace Status=X.PLM.ERR = value from @ImportObjectNewProcStateMask
                set @ProcStateCol01Val = dbo.Object_Import_Get_ProcessStatus_on_X_PLM_ERR_UDF(@ObjectId, @ProcStateCol01Val,'01',@ImportObjectNewProcStateMask,01)
                set @ProcStateCol02Val = dbo.Object_Import_Get_ProcessStatus_on_X_PLM_ERR_UDF(@ObjectId, @ProcStateCol02Val,'02',@ImportObjectNewProcStateMask,02)
                set @ProcStateCol03Val = dbo.Object_Import_Get_ProcessStatus_on_X_PLM_ERR_UDF(@ObjectId, @ProcStateCol03Val,'03',@ImportObjectNewProcStateMask,03)
                set @ProcStateCol04Val = dbo.Object_Import_Get_ProcessStatus_on_X_PLM_ERR_UDF(@ObjectId, @ProcStateCol04Val,'04',@ImportObjectNewProcStateMask,04)
                set @ProcStateCol05Val = dbo.Object_Import_Get_ProcessStatus_on_X_PLM_ERR_UDF(@ObjectId, @ProcStateCol05Val,'05',@ImportObjectNewProcStateMask,05)
                set @ProcStateCol06Val = dbo.Object_Import_Get_ProcessStatus_on_X_PLM_ERR_UDF(@ObjectId, @ProcStateCol06Val,'06',@ImportObjectNewProcStateMask,06)
                set @ProcStateCol07Val = dbo.Object_Import_Get_ProcessStatus_on_X_PLM_ERR_UDF(@ObjectId, @ProcStateCol07Val,'07',@ImportObjectNewProcStateMask,07)
                set @ProcStateCol08Val = dbo.Object_Import_Get_ProcessStatus_on_X_PLM_ERR_UDF(@ObjectId, @ProcStateCol08Val,'08',@ImportObjectNewProcStateMask,08)
                set @ProcStateCol09Val = dbo.Object_Import_Get_ProcessStatus_on_X_PLM_ERR_UDF(@ObjectId, @ProcStateCol09Val,'09',@ImportObjectNewProcStateMask,09)
                set @ProcStateCol10Val = dbo.Object_Import_Get_ProcessStatus_on_X_PLM_ERR_UDF(@ObjectId, @ProcStateCol10Val,'10',@ImportObjectNewProcStateMask,10)

                set @ProcStateCol11Val = dbo.Object_Import_Get_ProcessStatus_on_X_PLM_ERR_UDF(@ObjectId, @ProcStateCol01Val,'11',@ImportObjectNewProcStateMask,11)
                set @ProcStateCol12Val = dbo.Object_Import_Get_ProcessStatus_on_X_PLM_ERR_UDF(@ObjectId, @ProcStateCol02Val,'12',@ImportObjectNewProcStateMask,12)
                set @ProcStateCol13Val = dbo.Object_Import_Get_ProcessStatus_on_X_PLM_ERR_UDF(@ObjectId, @ProcStateCol03Val,'13',@ImportObjectNewProcStateMask,13)
                set @ProcStateCol14Val = dbo.Object_Import_Get_ProcessStatus_on_X_PLM_ERR_UDF(@ObjectId, @ProcStateCol04Val,'14',@ImportObjectNewProcStateMask,14)
                set @ProcStateCol15Val = dbo.Object_Import_Get_ProcessStatus_on_X_PLM_ERR_UDF(@ObjectId, @ProcStateCol05Val,'15',@ImportObjectNewProcStateMask,15)
                set @ProcStateCol16Val = dbo.Object_Import_Get_ProcessStatus_on_X_PLM_ERR_UDF(@ObjectId, @ProcStateCol06Val,'16',@ImportObjectNewProcStateMask,16)
                set @ProcStateCol17Val = dbo.Object_Import_Get_ProcessStatus_on_X_PLM_ERR_UDF(@ObjectId, @ProcStateCol07Val,'17',@ImportObjectNewProcStateMask,17)
                set @ProcStateCol18Val = dbo.Object_Import_Get_ProcessStatus_on_X_PLM_ERR_UDF(@ObjectId, @ProcStateCol08Val,'18',@ImportObjectNewProcStateMask,18)
                set @ProcStateCol19Val = dbo.Object_Import_Get_ProcessStatus_on_X_PLM_ERR_UDF(@ObjectId, @ProcStateCol09Val,'19',@ImportObjectNewProcStateMask,19)
                set @ProcStateCol20Val = dbo.Object_Import_Get_ProcessStatus_on_X_PLM_ERR_UDF(@ObjectId, @ProcStateCol10Val,'20',@ImportObjectNewProcStateMask,20)
                -- #Doc: not for @ProcStateColMcVal
                -- set @ProcStateColMcVal = dbo.Object_Import_Get_ProcessStatus_on_X_PLM_ERR_UDF(@ObjectId, @ProcStateColMcVal,'Mc',@ImportObjectNewProcStateMask,21)
                -- #LUp: @ProcStateColRfVal changed from: @ProcStateCol10Val to:@ProcStateColRfVal
                set @ProcStateColRfVal = dbo.Object_Import_Get_ProcessStatus_on_X_PLM_ERR_UDF(@ObjectId, @ProcStateColRfVal,'Rf',@ImportObjectNewProcStateMask,22)

              END

             if @DebugPrintOn = 1
             begin
              EXECUTE zzzzzDebugTbl_AddDataSet @MyProcName , '24-@ProcStateCol01Val' , @ProcStateCol01Val
              EXECUTE zzzzzDebugTbl_AddDataSet @MyProcName , '25-@ProcStateCol02Val' , @ProcStateCol02Val
             end

             -- Update der Processspalten wenn <> '-'  ----------------------------------
             if @ProcStateCol01Val <> '-' UPDATE Objects_tbl SET ProcStateCol01 = @ProcStateCol01Val Where ID = @ObjectId
             if @ProcStateCol02Val <> '-' UPDATE Objects_tbl SET ProcStateCol02 = @ProcStateCol02Val Where ID = @ObjectId
             if @ProcStateCol03Val <> '-' UPDATE Objects_tbl SET ProcStateCol03 = @ProcStateCol03Val Where ID = @ObjectId
             if @ProcStateCol04Val <> '-' UPDATE Objects_tbl SET ProcStateCol04 = @ProcStateCol04Val Where ID = @ObjectId
             if @ProcStateCol05Val <> '-' UPDATE Objects_tbl SET ProcStateCol05 = @ProcStateCol05Val Where ID = @ObjectId
             if @ProcStateCol06Val <> '-' UPDATE Objects_tbl SET ProcStateCol06 = @ProcStateCol06Val Where ID = @ObjectId
             if @ProcStateCol07Val <> '-' UPDATE Objects_tbl SET ProcStateCol07 = @ProcStateCol07Val Where ID = @ObjectId
             if @ProcStateCol08Val <> '-' UPDATE Objects_tbl SET ProcStateCol08 = @ProcStateCol08Val Where ID = @ObjectId
             if @ProcStateCol09Val <> '-' UPDATE Objects_tbl SET ProcStateCol09 = @ProcStateCol09Val Where ID = @ObjectId
             if @ProcStateCol10Val <> '-' UPDATE Objects_tbl SET ProcStateCol10 = @ProcStateCol10Val Where ID = @ObjectId

             if @ProcStateCol11Val <> '-' UPDATE Objects_tbl SET ProcStateCol11 = @ProcStateCol11Val Where ID = @ObjectId
             if @ProcStateCol12Val <> '-' UPDATE Objects_tbl SET ProcStateCol12 = @ProcStateCol12Val Where ID = @ObjectId
             if @ProcStateCol13Val <> '-' UPDATE Objects_tbl SET ProcStateCol13 = @ProcStateCol13Val Where ID = @ObjectId
             if @ProcStateCol14Val <> '-' UPDATE Objects_tbl SET ProcStateCol14 = @ProcStateCol14Val Where ID = @ObjectId
             if @ProcStateCol15Val <> '-' UPDATE Objects_tbl SET ProcStateCol15 = @ProcStateCol15Val Where ID = @ObjectId
             if @ProcStateCol16Val <> '-' UPDATE Objects_tbl SET ProcStateCol16 = @ProcStateCol16Val Where ID = @ObjectId
             if @ProcStateCol17Val <> '-' UPDATE Objects_tbl SET ProcStateCol17 = @ProcStateCol17Val Where ID = @ObjectId
             if @ProcStateCol18Val <> '-' UPDATE Objects_tbl SET ProcStateCol18 = @ProcStateCol18Val Where ID = @ObjectId
             if @ProcStateCol19Val <> '-' UPDATE Objects_tbl SET ProcStateCol19 = @ProcStateCol19Val Where ID = @ObjectId
             if @ProcStateCol20Val <> '-' UPDATE Objects_tbl SET ProcStateCol20 = @ProcStateCol20Val Where ID = @ObjectId
             if @ProcStateColRfVal <> '-' UPDATE Objects_tbl SET ProcStateColRf = @ProcStateColRfVal Where ID = @ObjectId
             if @ProcStateColMcVal <> '-' UPDATE Objects_tbl SET ProcStateColMc = @ProcStateColMcVal Where ID = @ObjectId
     END
 -- #doc:29.04.2019 Rank is disabled set RANK to = 0
 if @DoUpdateRank <> 1 UPDATE Objects_tbl SET ObjectIrLatestRank = 0 Where ID = @ObjectId

 COMMIT TRANSACTION   -- *************  Commit Transaction **************
 END TRY              -- *************  End TRY **************

 BEGIN CATCH          -- *************  Begin CATCH ************
 	-- PRINT 'Rollback Transaction'
 	ROLLBACK TRANSACTION
 	DECLARE @DoRetry bit; -- Whether to Retry transaction or not
 	DECLARE @ErrorMessage varchar(500)
 	SET @DoRetry = 0;
 	SET @ErrorMessage = ERROR_MESSAGE()
 	IF ERROR_NUMBER() = 1205 -- Deadlock Error Number
 	BEGIN
 		SET @DoRetry = 1; -- Set @doRetry to 1 only for Deadlock
 	END
 	IF @DoRetry = 1
 	BEGIN
 		SET @RetryCounter = @RetryCounter + 1 -- Increment Retry Counter By one
 		IF (@RetryCounter > 3) -- Check whether Retry Counter reached to 3
 		BEGIN
 			RAISERROR(@ErrorMessage, 18, 1) -- Raise Error Message if still deadlock occurred after three retries
 		END
 		ELSE
 		BEGIN
    WAITFOR DELAY '00:00:00.10' -- 02.08.2010 19:35 Wait=01 sec 23.07.2010 01:30 Wait=01 sec --- Wait for 10 ms
 			GOTO RETRY	-- Go to Label RETRY
 		END
 	END
 	ELSE
 	BEGIN
 		RAISERROR(@ErrorMessage, 18, 1)
 	END
 END CATCH    -- *************  End CATCH ************

END
GO

ende:

-- EXECUTE zzzzzDebugTbl_Empty
Print ''
Print '-------------------------------------------------------------------------'
Print ' Procedures imported to #DB_N#'
Print '-------------------------------------------------------------------------'
GO

