FUNC
:MPRF:6
:VERS:A2LN
:RELE:a7
:CUST:FP7
:FNAM:DateHandling
:DSCA:Date and UTC functions
:LURN:baan
:LDAT:12/3/2013 1:35:48 PM
:FDEF:START
function get.utc(i.utc.field, i.mandatory)
'|
'|FunctionDesciption
'| 	This function can be used to determine the UTC date format for a LN UTC field.
'|	The fucntion takes the type of database into account.
'|	The UTC output is always the UTC value for GMT(0). After loading the system compensates
'|	for the displayed UTC taking the Timezone of the user into account.
'|	When the field is not defined but mandatory needs to be filled the function will default it
'|	with 4 January 1970 (as "1970-01-04 00:00:00").
'|
'|	Below are the zero (empty utc) values per database:
'| 	DB2_ZERO_UTC = "01-01-0001"
'| 	MSSQL_ZERO_UTC = "1753-01-01 00:00:00"
'| 	ORACLE_ZERO_UTC = "-4712-01-01 00:00:00"
'|
'|Input:
'| 	i.utc.field:	The value which needs to be converted into UTC.
'| 	i.mandatory: Indicates if the fiels is set as mandatory in LN Datadictionary  
'|Output:
'|	converted UTC value for the input field
'|EndFunctionDesciption


	  If i.utc.field  =  "" or IsNull(i.utc.field) then  	
	   	If Ucase(i.mandatory) = "YES" then
				var.get.utc  =  DEFAULT_UTC
			else						'Tmp.sn
				'| i.mandatory = "NO"
				'| FUNCTION LOGIC NEEDS TO BE MOVED TO DCA:ClsConvdll
				'| Currentl local.to.utc does not handle db dependent ZERO_UTC string	
				'| If fixed then the Tmp section can be replaced by var.get.utc  =  LocalToUtc(i.utc.field)
				var.get.utc = to_date("0")		'Tmp.en
			end if
	  else  						
			var.get.utc  =  LocalToUtc(i.utc.field)

			if i.utc.field <= "1/1/1970" then
				'| In case the access field is explicitly set to 1970
				var.get.utc = "1970-01-01 00:00:01"
			end if	   	
	  end if 
	  get.utc = var.get.utc
	  
end function

function get.date(i.date.field, i.mandatory)
'|
'| 
'|FunctionDesciption
'| 	This function can be used to handle date fields.
'|	The fucntion takes the type of database into account.
'|	When the field is not defined but mandatory needs to be filled the function will default it
'|	with 4 January 1970 (as "1970-01-01").
'|
'|Input:
'| 	i.date.field:	The value which needs to be converted into date.
'| 	i.mandatory: Indicates if the fiels is set as mandatory in LN Datadictionary  
'|Output:
'|	converted date value for the input field
'|EndFunctionDesciption    
	
	  If i.date.field  =  "" or IsNull(i.date.field) then  
			If Ucase(i.mandatory) = "YES" then
				var.get.date  =  DEFAULT_DATE
		  else
				'| i.mandatory = "NO"
				var.get.date = ("0")
		  end if		  
	  else  
	   	  var.get.date  =  i.date.field 
	  end if  
	  get.date = var.get.date

end function

Function DateHandling_To_Date_Zero()
 

	'' Tempt solution only works for oracle and mssql
	select	GeneralParameters.*
	from	GeneralParameters
	selectdo
		mvarTargetDb = GeneralParameters.ODBCDriver
	endselect


	if mvarTargetDb = "SQL Server" then
		DateHandling_To_Date_Zero 	= "1753-01-01 00:00:00"
	else
		DateHandling_To_Date_Zero 	= "-4712-01-01 00:00:00"
	end if


''	Must be moved to DCA function :ClsConvdll
''        Select Case mvarTargetDb
''        Case Oracle:
''            DateHandling_To_Date_Zero 	= "-4712-01-01 00:00:00"
''        Case MSSQL:
''           DateHandling_To_Date_Zero 	= "1753-01-01 00:00:00"
''        Case Databases.DB2:            
''            DateHandling_To_Date_Zero	= "01-01-0001"    
''        Case Else
''            DateHandling_To_Date_Zero 	= "0001-01-01 00:00:00"
''        End Select

End Function
:FDEF:END
:CURN:
:STAT:M
:COMT:START

:COMT:END
FUNC
:MPRF:7
:VERS:A2LN
:RELE:a7
:CUST:FP7R
:FNAM:ItemHandling
:DSCA:Item Handling Functions
:LURN:baan
:LDAT:11/5/2013 11:12:08 AM
:FDEF:START
Function get.segment.item.code(i.cprj.field, i.item.field)

	'| Remark regards to domain cpitem:
	'| The function 'get.segment.cp.item.code() is not stored in the Function Repository 
	'| as this is only used in conversion object for table cprpd100 and cprpd710.
	'| Therefore this function can be found in the Function section of conversion objects tcibd001 and cprpd710.	
	
	'| Read the segmentation parameters.
	If s.tc.ItemCodeSegmentationParameters.Read <> 2 Then
		'Intitialize default values
		s.tc.StartPosition.project 	= 1
		s.tc.segmentLength.project 	= 9
		s.tc.StartPosition.item 	= 10		
		s.tc.segmentLength.item 	= 38
		s.tc.segmentAlignment.project 	= "left"	
		s.tc.segmentAlignment.item 	= "left"	
		
		s.tc.ItemCodeSegmentationParameters.Read = 2

		Select	ItemCodeSegmentationParameters.*
		From	ItemCodeSegmentationParameters
		Where	ItemCodeSegmentationParameters.cpac = "tc" 
		And 	ItemCodeSegmentationParameters.pdom = "item"
		Selectdo
			If ItemCodeSegmentationParameters.apco = "project" Then
				s.tc.StartPosition.project 	= ItemCodeSegmentationParameters.spos
				s.tc.segmentLength.project 	= ItemCodeSegmentationParameters.leng
				s.tc.segmentAlignment.project	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "item" Then
				s.tc.StartPosition.item 	= ItemCodeSegmentationParameters.spos
				s.tc.segmentLength.item 	= ItemCodeSegmentationParameters.leng
				s.tc.segmentAlignment.item	= ItemCodeSegmentationParameters.adju	
			End If
		Endselect	
	End If	

	'| This section fills the segment field in the item code. 
	'| The segment part is always considered as UpperCase.
	
	ProjectSegment 	= Trim(i.cprj.field)
	ItemSegment 	= Trim(i.item.field)
	ProjectLength	= len(ProjectSegment)	
	ItemLength	= len(ItemSegment)	


	'|* This section formats the segments. 
	'|* For aligment only 'left' or 'right' is possible and remaining positions will be filled with spaces.
	'| Formatting the project segment			
	
	if s.tc.segmentAlignment.project = "left" then
		ProjectSegment = ProjectSegment & Space(s.tc.segmentLength.project - ProjectLength)
	else
		ProjectSegment = Space(s.tc.segmentLength.project - ProjectLength) & ProjectSegment
	end if
	'| Formatting the item segment
	if s.tc.segmentAlignment.item = "left" then
		ItemSegment = ItemSegment & Space(s.tc.segmentLength.item - ItemLength)
	else
		ItemSegment = Space(s.tc.segmentLength.item - ItemLength) & ItemSegment
	end if	

	'| Project segment before Item Segment: Project - Item
	If s.tc.StartPosition.project < s.tc.StartPosition.item then
		CombinedSegments = ProjectSegment & ItemSegment	
	Else
	'|Project segment after Item segment: Item - Project 
		CombinedSegments = ItemSegment & ProjectSegment
	End If
	
	get.segment.item.code = UCase(CombinedSegments)	

End Function





:FDEF:END
:CURN:
:STAT:M
:COMT:START

:COMT:END
FUNC
:MPRF:7
:VERS:A2LN
:RELE:a7
:CUST:FP7R
:FNAM:tfgld0001
:DSCA:GLD functions
:LURN:baan
:LDAT:8/26/2011 11:59:22 AM
:FDEF:START
Function tfgld0001.read.general.parameter( ByRef varstr.TransactionType, ByRef varstr.SourceGLVersion, ByRef varstr.DefaultCountry)

	select GeneralParameters.TransactionType, GeneralParameters.SourceGLVersion, GeneralParameters.DefaultCountry
	from GeneralParameters
	selectdo
		varstr.TransactionType = GeneralParameters.TransactionType
		varstr.SourceGLVersion = GeneralParameters.SourceGLVersion
		varstr.DefaultCountry = GeneralParameters.DefaultCountry
	endselect
	tfgld0001.read.general.parameter = "temp"

End Function

Function tfgld0001.get.target.currency(varstr.CurrencySource)

	tfgld0001.get.target.currency = varstr.CurrencySource
	
	select	CurrencyMapping.*
	from	CurrencyMapping
	where	CurrencyMapping.CurrencySource = varstr.CurrencySource
	selectdo
		tfgld0001.get.target.currency = CurrencyMapping.CurrencyTarget
	endselect

End Function

Function tfgld0001.get.exchange.rate.type(varstr.RateTypeSource)

	tfgld0001.get.exchange.rate.type = varstr.RateTypeSource
	
	select	ExchangeRateTypeMapping.*
	from	ExchangeRateTypeMapping
	where	ExchangeRateTypeMapping.RateTypeSource = varstr.RateTypeSource
	selectdo
		tfgld0001.get.exchange.rate.type = ExchangeRateTypeMapping.ExchangeRateTypeTarget
	endselect

End Function

Function tfgld0001.get.target.dimension(varint.Type, varstr.DimCodeSource)

	tfgld0001.get.target.dimension = varstr.DimCodeSource

	select	DimensionMapping.*
	from	DimensionMapping
	where	DimensionMapping.Type = varint.Type
	and	DimensionMapping.DimCodeSource = varstr.DimCodeSource
	selectdo
		tfgld0001.get.target.dimension = DimensionMapping.DimCodeTarget
	endselect


End Function

Function tfgld0001.get.target.ledger.account(varstr.AccountSource)

	If Trim(varstr.AccountSource) = "" Then Exit Function

	tfgld0001.get.target.ledger.account = varstr.AccountSource

	select	ChartOfAccountsMapping.*
	from	ChartOfAccountsMapping
	where	ChartOfAccountsMapping.AccountSource = varstr.AccountSource
	selectdo
		tfgld0001.get.target.ledger.account = ChartOfAccountsMapping.AccountTarget
	endselect
end function

:FDEF:END
:CURN:
:STAT:M
:COMT:START

:COMT:END
FUNC
:MPRF:8
:VERS:A2LN
:RELE:a8
:CUST:fp8
:FNAM:DateHandling
:DSCA:Date and UTC functions
:LURN:baan
:LDAT:12/3/2013 1:35:48 PM
:FDEF:START
function get.utc(i.utc.field, i.mandatory)
'|
'|FunctionDesciption
'| 	This function can be used to determine the UTC date format for a LN UTC field.
'|	The fucntion takes the type of database into account.
'|	The UTC output is always the UTC value for GMT(0). After loading the system compensates
'|	for the displayed UTC taking the Timezone of the user into account.
'|	When the field is not defined but mandatory needs to be filled the function will default it
'|	with 4 January 1970 (as "1970-01-04 00:00:00").
'|
'|	Below are the zero (empty utc) values per database:
'| 	DB2_ZERO_UTC = "01-01-0001"
'| 	MSSQL_ZERO_UTC = "1753-01-01 00:00:00"
'| 	ORACLE_ZERO_UTC = "-4712-01-01 00:00:00"
'|
'|Input:
'| 	i.utc.field:	The value which needs to be converted into UTC.
'| 	i.mandatory: Indicates if the fiels is set as mandatory in LN Datadictionary  
'|Output:
'|	converted UTC value for the input field
'|EndFunctionDesciption


	  If i.utc.field  =  "" or IsNull(i.utc.field) then  	
	   	If Ucase(i.mandatory) = "YES" then
				var.get.utc  =  DEFAULT_UTC
			else						'Tmp.sn
				'| i.mandatory = "NO"
				'| FUNCTION LOGIC NEEDS TO BE MOVED TO DCA:ClsConvdll
				'| Currentl local.to.utc does not handle db dependent ZERO_UTC string	
				'| If fixed then the Tmp section can be replaced by var.get.utc  =  LocalToUtc(i.utc.field)
				var.get.utc = to_date("0")		'Tmp.en
			end if
	  else  						
			var.get.utc  =  LocalToUtc(i.utc.field)

			if i.utc.field <= "1/1/1970" then
				'| In case the access field is explicitly set to 1970
				var.get.utc = "1970-01-01 00:00:01"
			end if	   	
	  end if 
	  get.utc = var.get.utc
	  
end function

function get.date(i.date.field, i.mandatory)
'|
'| 
'|FunctionDesciption
'| 	This function can be used to handle date fields.
'|	The fucntion takes the type of database into account.
'|	When the field is not defined but mandatory needs to be filled the function will default it
'|	with 4 January 1970 (as "1970-01-01").
'|
'|Input:
'| 	i.date.field:	The value which needs to be converted into date.
'| 	i.mandatory: Indicates if the fiels is set as mandatory in LN Datadictionary  
'|Output:
'|	converted date value for the input field
'|EndFunctionDesciption    
	
	  If i.date.field  =  "" or IsNull(i.date.field) then  
			If Ucase(i.mandatory) = "YES" then
				var.get.date  =  DEFAULT_DATE
		  else
				'| i.mandatory = "NO"
				var.get.date = ("0")
		  end if		  
	  else  
	   	  var.get.date  =  i.date.field 
	  end if  
	  get.date = var.get.date

end function

Function DateHandling_To_Date_Zero()
 

	'' Tempt solution only works for oracle and mssql
	select	GeneralParameters.*
	from	GeneralParameters
	selectdo
		mvarTargetDb = GeneralParameters.ODBCDriver
	endselect


	if mvarTargetDb = "SQL Server" then
		DateHandling_To_Date_Zero 	= "1753-01-01 00:00:00"
	else
		DateHandling_To_Date_Zero 	= "-4712-01-01 00:00:00"
	end if


''	Must be moved to DCA function :ClsConvdll
''        Select Case mvarTargetDb
''        Case Oracle:
''            DateHandling_To_Date_Zero 	= "-4712-01-01 00:00:00"
''        Case MSSQL:
''           DateHandling_To_Date_Zero 	= "1753-01-01 00:00:00"
''        Case Databases.DB2:            
''            DateHandling_To_Date_Zero	= "01-01-0001"    
''        Case Else
''            DateHandling_To_Date_Zero 	= "0001-01-01 00:00:00"
''        End Select

End Function
:FDEF:END
:CURN:
:STAT:M
:COMT:START

:COMT:END
FUNC
:MPRF:9
:VERS:A2LN
:RELE:a9
:CUST:fp9
:FNAM:DateHandling
:DSCA:Date and UTC functions
:LURN:baan
:LDAT:3/27/2014 3:47:01 PM
:FDEF:START
function get.utc(i.utc.field, i.mandatory)
''''''''''''''''|
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|FunctionDesciption
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	This function can be used to determine the UTC date format for a LN UTC field.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|The fucntion takes the type of database into account.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|The UTC output is always the UTC value for GMT(0). After loading the system compensates
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|for the displayed UTC taking the Timezone of the user into account.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|When the field is not defined but mandatory needs to be filled the function will default it
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|with 4 January 1970 (as "1970-01-04 00:00:00").
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|Below are the zero (empty utc) values per database:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	DEFAULT_UTC = "1970-01-04 00:00:00"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	ZERO_UTC =     "1970-01-01 00:00:00"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	DEFAULT_DATE = "1970-01-01 00:00:00"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	ZERO_DATE = "0001-01-01 00:00:00"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	DB2_ZERO_UTC = "01-01-0001"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	MSSQL_ZERO_UTC = "1753-01-01 00:00:00"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	ORACLE_ZERO_UTC = "-4712-01-01 00:00:00"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|Input:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	i.utc.field:	The value which needs to be converted into UTC.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	i.mandatory: Indicates if the fiels is set as mandatory in LN Datadictionary  
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|Output:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	converted UTC value for the input field
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|EndFunctionDesciption

	  If i.utc.field  =  "" or IsNull(i.utc.field) then  	
	   	If Ucase(i.mandatory) = "YES" then
				var.get.utc  =  "1970-01-04 00:00:00" 
			else						''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Tmp.sn
				''''''''''''''''| i.mandatory = "NO"
				''''''''''''''''| FUNCTION LOGIC NEEDS TO BE MOVED TO DCA:ClsConvdll
				''''''''''''''''| Currentl local.to.utc does not handle db dependent ZERO_UTC string	
				''''''''''''''''| If fixed then the Tmp section can be replaced by var.get.utc  =  LocalToUtc(i.utc.field)
				var.get.utc = DateHandling_To_Date_Zero()		''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Tmp.en
			end if
	  else  						
			var.get.utc  =  LocalToUtc(i.utc.field)

			if i.utc.field <= "1/1/1970" then
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''| In case the access field is explicitly set to 1970
				var.get.utc = "1970-01-01 00:01:01"
			end if	   	
	  end if 
	  get.utc = var.get.utc
	  
end function

function get.date(i.date.field, i.mandatory)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''| 
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|FunctionDesciption
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''| 	This function can be used to handle date fields.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	The fucntion takes the type of database into account.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	When the field is not defined but mandatory needs to be filled the function will default it
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	with 4 January 1970 (as "1970-01-01").
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|Input:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''| 	i.date.field:	The value which needs to be converted into date.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''| 	i.mandatory: Indicates if the fiels is set as mandatory in LN Datadictionary  
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|Output:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	converted date value for the input field
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|EndFunctionDesciption    
	
	  If i.date.field  =  "" or IsNull(i.date.field) then  
			If Ucase(i.mandatory) = "YES" then
				var.get.date  =  "1970-01-01 00:00:00"
		  else
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''| i.mandatory = "NO"
				var.get.date = ("0")
		  end if		  
	  else  
	   	  var.get.date  =  i.date.field 
	  end if  
	  get.date = var.get.date

end function

Function DateHandling_To_Date_Zero()
 

	'''''''' Tempt solution only works for oracle and mssql
	select	GeneralParameters.*
	from	GeneralParameters
	selectdo
		mvarTargetDb = GeneralParameters.ODBCDriver
	endselect


	if mvarTargetDb = "SQL Server" then
		DateHandling_To_Date_Zero 	= "1753-01-01 00:00:00"
	else
		DateHandling_To_Date_Zero 	= "-4712-01-01 00:00:00"
	end if


''''''''	Must be moved to DCA function :ClsConvdll
''''''''        Select Case mvarTargetDb
''''''''        Case Oracle:
''''''''            DateHandling_To_Date_Zero 	= "-4712-01-01 00:00:00"
''''''''        Case MSSQL:
''''''''           DateHandling_To_Date_Zero 	= "1753-01-01 00:00:00"
''''''''        Case Databases.DB2:            
''''''''            DateHandling_To_Date_Zero	= "01-01-0001"    
''''''''        Case Else
''''''''            DateHandling_To_Date_Zero 	= "0001-01-01 00:00:00"
''''''''        End Select

End Function



:FDEF:END
:CURN:
:STAT:M
:COMT:START

:COMT:END
FUNC
:MPRF:9
:VERS:A2LN
:RELE:a9
:CUST:fp9
:FNAM:ItemHandling
:DSCA:Item Handling Functions
:LURN:baan
:LDAT:12/2/2013 11:46:20 AM
:FDEF:START
Function get.segment.item.code(i.cprj.field, i.item.field)

	''''| Remark regards to domain cpitem:
	''''| The function ''''get.segment.cp.item.code() is not stored in the Function Repository 
	''''| as this is only used in conversion object for table cprpd100 and cprpd710.
	''''| Therefore this function can be found in the Function section of conversion objects tcibd001 and cprpd710.	
	
	''''| Read the segmentation parameters.
	If s.tc.ItemCodeSegmentationParameters.Read <> 2 Then
		''''Intitialize default values
		s.tc.StartPosition.project 	= 1
		s.tc.segmentLength.project 	= 9
		s.tc.StartPosition.item 	= 10		
		s.tc.segmentLength.item 	= 38
		s.tc.segmentAlignment.project 	= "left"	
		s.tc.segmentAlignment.item 	= "left"	
		
		s.tc.ItemCodeSegmentationParameters.Read = 2

		Select	ItemCodeSegmentationParameters.*
		From	ItemCodeSegmentationParameters
		Where	ItemCodeSegmentationParameters.cpac = "tc" 
		And 	ItemCodeSegmentationParameters.pdom = "item"
		Selectdo
			If ItemCodeSegmentationParameters.apco = "project" Then
				s.tc.StartPosition.project 	= ItemCodeSegmentationParameters.spos
				s.tc.segmentLength.project 	= ItemCodeSegmentationParameters.leng
				s.tc.segmentAlignment.project	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "item" Then
				s.tc.StartPosition.item 	= ItemCodeSegmentationParameters.spos
				s.tc.segmentLength.item 	= ItemCodeSegmentationParameters.leng
				s.tc.segmentAlignment.item	= ItemCodeSegmentationParameters.adju	
			End If
		Endselect	
	End If	

	''''| This section fills the segment field in the item code. 
	''''| The segment part is always considered as UpperCase.
	
	ProjectSegment 	= Trim(i.cprj.field)
	ItemSegment 	= Trim(i.item.field)
	ProjectLength	= len(ProjectSegment)	
	ItemLength	= len(ItemSegment)	


	''''|* This section formats the segments. 
	''''|* For aligment only ''''left'''' or ''''right'''' is possible and remaining positions will be filled with spaces.
	''''| Formatting the project segment			
	
	if s.tc.segmentAlignment.project = "left" then
		ProjectSegment = ProjectSegment & Space(s.tc.segmentLength.project - ProjectLength)
	else
		ProjectSegment = Space(s.tc.segmentLength.project - ProjectLength) & ProjectSegment
	end if
	''''| Formatting the item segment
	if s.tc.segmentAlignment.item = "left" then
		ItemSegment = ItemSegment & Space(s.tc.segmentLength.item - ItemLength)
	else
		ItemSegment = Space(s.tc.segmentLength.item - ItemLength) & ItemSegment
	end if	

	''''| Project segment before Item Segment: Project - Item
	If s.tc.StartPosition.project < s.tc.StartPosition.item then
		CombinedSegments = ProjectSegment & ItemSegment	
	Else
	''''|Project segment after Item segment: Item - Project 
		CombinedSegments = ItemSegment & ProjectSegment
	End If
	
	get.segment.item.code = UCase(CombinedSegments)	

End Function


'''' The below 3 functions are created for the Item Default handling.
Function ItemHandling.GetTypeString(Varstr.Itemdefault, Varstr.Itemfield, Varint.Exception, Varint.DefaultFound)

	if Varint.Exception = 2	then			''''|# Exception = No
		if Varstr.Itemdefault = "" or Varint.DefaultFound = 0 then
			ItemHandling.GetTypeString = Varstr.Itemfield
		else
			ItemHandling.GetTypeString = Varstr.Itemdefault
		end if
	else
		ItemHandling.GetTypeString = Varstr.Itemfield
	end if

End Function

Function ItemHandling.GetTypeEnum(Varint.Itemdefault, Varint.Itemfield, Varint.Exception, Varint.DefaultFound, Varint.DefaultValue)

	if Varint.Exception = 2	then					''''|# Exception = No
		if Varint.DefaultFound = 0 then				''''|# Default not found/present
			if Varint.Itemfield <> "0" and _
			   Varint.Itemfield <> "" then			''''|# If no mapping exist is access, 0 is passed as argument
				ItemHandling.GetTypeEnum = Varint.Itemfield
			else
				ItemHandling.GetTypeEnum = Varint.DefaultValue	''''|# Default value of enum always passed as argument
			end if
		else
			ItemHandling.GetTypeEnum = Varint.Itemdefault
		end if
	else
		if Varint.Itemfield <> "0" and Varint.Itemfield <> "" then
			ItemHandling.GetTypeEnum = Varint.Itemfield
		else
			ItemHandling.GetTypeEnum = Varint.DefaultValue
		end if
	end if

End Function

Function ItemHandling.GetTypeNumber(Varnum.Itemdefault, Varnum.Itemfield, Varint.Exception, Varint.DefaultFound)

	if Varint.Exception = 2	then			''''|# Exception = No
		if Varnum.Itemdefault = "" or Varint.DefaultFound = 0 then
			ItemHandling.GetTypeNumber = Varnum.Itemfield
		else
			ItemHandling.GetTypeNumber = Varnum.Itemdefault
		end if
	else
		ItemHandling.GetTypeNumber = Varnum.Itemfield
	end if

End Function



:FDEF:END
:CURN:
:STAT:M
:COMT:START

:COMT:END
FUNC
:MPRF:11
:VERS:A2LN
:RELE:LN
:CUST:105
:FNAM:DateHandling
:DSCA:Date and UTC functions
:LURN:baan
:LDAT:3/27/2014 3:47:01 PM
:FDEF:START
function get.utc(i.utc.field, i.mandatory)
''''''''''''''''|
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|FunctionDesciption
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	This function can be used to determine the UTC date format for a LN UTC field.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|The fucntion takes the type of database into account.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|The UTC output is always the UTC value for GMT(0). After loading the system compensates
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|for the displayed UTC taking the Timezone of the user into account.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|When the field is not defined but mandatory needs to be filled the function will default it
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|with 4 January 1970 (as "1970-01-04 00:00:00").
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|Below are the zero (empty utc) values per database:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	DEFAULT_UTC = "1970-01-04 00:00:00"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	ZERO_UTC =     "1970-01-01 00:00:00"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	DEFAULT_DATE = "1970-01-01 00:00:00"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	ZERO_DATE = "0001-01-01 00:00:00"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	DB2_ZERO_UTC = "01-01-0001"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	MSSQL_ZERO_UTC = "1753-01-01 00:00:00"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	ORACLE_ZERO_UTC = "-4712-01-01 00:00:00"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|Input:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	i.utc.field:	The value which needs to be converted into UTC.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	i.mandatory: Indicates if the fiels is set as mandatory in LN Datadictionary  
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|Output:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	converted UTC value for the input field
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|EndFunctionDesciption

	  If i.utc.field  =  "" or IsNull(i.utc.field) then  	
	   	If Ucase(i.mandatory) = "YES" then
				var.get.utc  =  "1970-01-04 00:00:00" 
			else						''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Tmp.sn
				''''''''''''''''| i.mandatory = "NO"
				''''''''''''''''| FUNCTION LOGIC NEEDS TO BE MOVED TO DCA:ClsConvdll
				''''''''''''''''| Currentl local.to.utc does not handle db dependent ZERO_UTC string	
				''''''''''''''''| If fixed then the Tmp section can be replaced by var.get.utc  =  LocalToUtc(i.utc.field)
				var.get.utc = DateHandling_To_Date_Zero()		''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Tmp.en
			end if
	  else  						
			var.get.utc  =  LocalToUtc(i.utc.field)

			if i.utc.field <= "1/1/1970" then
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''| In case the access field is explicitly set to 1970
				var.get.utc = "1970-01-01 00:01:01"
			end if	   	
	  end if 
	  get.utc = var.get.utc
	  
end function

function get.date(i.date.field, i.mandatory)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''| 
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|FunctionDesciption
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''| 	This function can be used to handle date fields.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	The fucntion takes the type of database into account.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	When the field is not defined but mandatory needs to be filled the function will default it
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	with 4 January 1970 (as "1970-01-01").
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|Input:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''| 	i.date.field:	The value which needs to be converted into date.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''| 	i.mandatory: Indicates if the fiels is set as mandatory in LN Datadictionary  
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|Output:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|	converted date value for the input field
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''|EndFunctionDesciption    
	
	  If i.date.field  =  "" or IsNull(i.date.field) then  
			If Ucase(i.mandatory) = "YES" then
				var.get.date  =  "1970-01-01 00:00:00"
		  else
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''| i.mandatory = "NO"
				var.get.date = ("0")
		  end if		  
	  else  
	   	  var.get.date  =  i.date.field 
	  end if  
	  get.date = var.get.date

end function

Function DateHandling_To_Date_Zero()
 

	'''''''' Tempt solution only works for oracle and mssql
	select	GeneralParameters.*
	from	GeneralParameters
	selectdo
		mvarTargetDb = GeneralParameters.ODBCDriver
	endselect


	if mvarTargetDb = "SQL Server" then
		DateHandling_To_Date_Zero 	= "1753-01-01 00:00:00"
	else
		DateHandling_To_Date_Zero 	= "-4712-01-01 00:00:00"
	end if


''''''''	Must be moved to DCA function :ClsConvdll
''''''''        Select Case mvarTargetDb
''''''''        Case Oracle:
''''''''            DateHandling_To_Date_Zero 	= "-4712-01-01 00:00:00"
''''''''        Case MSSQL:
''''''''           DateHandling_To_Date_Zero 	= "1753-01-01 00:00:00"
''''''''        Case Databases.DB2:            
''''''''            DateHandling_To_Date_Zero	= "01-01-0001"    
''''''''        Case Else
''''''''            DateHandling_To_Date_Zero 	= "0001-01-01 00:00:00"
''''''''        End Select

End Function



:FDEF:END
:CURN:
:STAT:M
:COMT:START

:COMT:END
FUNC
:MPRF:14
:VERS:A2LN
:RELE:LN
:CUST:1060
:FNAM:DateHandling
:DSCA:Date and UTC functions
:LURN:hermant
:LDAT:1/7/2019 11:25:15 AM
:FDEF:START
''|Global variable declaration										''|LN10605.sn
dim Hold_GeneralParameter_TargetDatabase
dim Hold_GeneralParameter_UTC40DateFormat								''|LN10605.en

function get.utc(i.utc.field, i.mandatory)
''|
''|FunctionDescription
''|	This function can be used to determine the UTC date format for a LN UTC field.
''|The fucntion takes the type of database into account.
''|The UTC output is always the UTC value for GMT(0). After loading the system compensates
''|for the displayed UTC taking the Timezone of the user into account.
''|When the field is not defined but mandatory needs to be filled the function will default it
''|with 4 January 1970 (as "1970-01-04 00:00:00").
''|
''|Below are the zero (empty utc) values per database:
''|	DEFAULT_UTC = "1970-01-04 00:00:00"
''|	ZERO_UTC =     "1970-01-01 00:00:00"
''|	DEFAULT_DATE = "1970-01-01 00:00:00"
''|	ZERO_DATE = "0001-01-01 00:00:00"
''|	DB2_ZERO_UTC = "01-01-0001"
''|	MSSQL_ZERO_UTC = "1753-01-01 00:00:00"
''|	ORACLE_ZERO_UTC = "-4712-01-01 00:00:00"
''|
''|Input:
''|	i.utc.field:	The value which needs to be converted into UTC.
''|	i.mandatory: Indicates if the fiels is set as mandatory in LN Datadictionary  
''|Output:
''|	converted UTC value for the input field
''|EndFunctionDesciption

	  If i.utc.field  =  "" or IsNull(i.utc.field) then  	
	   	If Ucase(i.mandatory) = "YES" then
				var.get.utc  =  "1970-01-04 00:00:00" 
			else						''Tmp.sn
				''| i.mandatory = "NO"
				''| FUNCTION LOGIC NEEDS TO BE MOVED TO DCA:ClsConvdll
				''| Currentl local.to.utc does not handle db dependent ZERO_UTC string	
				''| If fixed then the Tmp section can be replaced by var.get.utc  =  LocalToUtc(i.utc.field)
				var.get.utc = DateHandling_To_Date_Zero()	
									''Tmp.en
			end if
	  else  						
			var.get.utc  =  LocalToUtc(i.utc.field)

''Wrong date formatting			if i.utc.field <= "1/1/1970" then
			if i.utc.field <= #1/1/1970# then					''Date should be enclosed in ##
				''| In case the access field is explicitly set to 1970
				var.get.utc = "1970-01-01 00:01:01"
			end if	   	
	  end if 
	  get.utc = var.get.utc
	  
end function

function get.date(i.date.field, i.mandatory)
''|
''| 
''|FunctionDesciption
''| 	This function can be used to handle date fields.
''|	The fucntion takes the type of database into account.
''|	When the field is not defined but mandatory needs to be filled the function will default it
''|	with 4 January 1970 (as "1970-01-01").
''|
''|Input:
''| 	i.date.field:	The value which needs to be converted into date.
''| 	i.mandatory: Indicates if the fiels is set as mandatory in LN Datadictionary  
''|Output:
''|	converted date value for the input field
''|EndFunctionDesciption    
	
	  If i.date.field  =  "" or IsNull(i.date.field) then  
		If Ucase(i.mandatory) = "YES" then
				var.get.date  =  "1970-01-01 00:00:00"
		  else
				''| i.mandatory = "NO"
				var.get.date = ("0")
		  end if		  
	  else  
	   	  var.get.date  =  i.date.field 
	  end if  
	  get.date = var.get.date

end function


''LN10605.sn
''| Changed function to work with input variable from General parameters Instead of selecting them each time.
''| Introduced global variable set in top of Function Repository
''|LN10605.sn
Function DateHandling_To_Date_Zero()
	''| Temporay solution, possibly move to convdll 

	if Hold_GeneralParameter_TargetDatabase = "" then
		Read.GeneralParameters()
	end if

        Select Case Hold_GeneralParameter_TargetDatabase
        Case "Oracle":
            DateHandling_To_Date_Zero 	= " -4712-01-01 00:00:00"
        Case "SQL Server":
''|LN1061.sc
''|Date empty for MS SQL no longer 1753-01-01 00:00:00 but 1970-01-01 00:00:00
''|           DateHandling_To_Date_Zero 	= "1753-01-01 00:00:00"
           DateHandling_To_Date_Zero 	= "1970-01-01 00:00:00"
''|LN1061.ec
        Case "DB2":            
            DateHandling_To_Date_Zero	= "0001-01-01"    
        Case "Informix":            
            DateHandling_To_Date_Zero	= "0001-01-01 00:00:00"   
        Case "EDB":            
            DateHandling_To_Date_Zero	= "1970-01-01 00:00:00"               
        Case Else
            DateHandling_To_Date_Zero 	= "0001-01-01 00:00:00"
        End Select

End Function

								''|LN10605.sn
Function get.max.date() 

	if Hold_GeneralParameter_UTC40DateFormat = "" then
		''Avoid to many selects on general parameters
		Read.GeneralParameters()
	end if

	if Hold_GeneralParameter_UTC40DateFormat = "Yes" then
		get.max.date = "9999-12-30"
	else
		get.max.date = "2038-01-19"
	end if	

End Function

Function get.max.UTC() 

	if Hold_GeneralParameter_UTC40DateFormat = "" then
		''Avoid to many selects on general parameters
		Read.GeneralParameters()
	end if

	if Hold_GeneralParameter_UTC40DateFormat = "Yes" then
		get.max.UTC = "9999-12-30 00:00:00"
	else
		get.max.UTC = "2038-01-19 03:14:07"
	end if	

End Function
								
Function Read.GeneralParameters()
	''This function reads the general parameters and stores fields in global variables

	Select 	GeneralParameters.TargetDatabase as Hold_GeneralParameter_TargetDatabase,  
		GeneralParameters.UTC40Format as Hold_GeneralParameter_UTC40DateFormat
	from	GeneralParameters
	selectdo
		''Hold_GeneralParameter_UTC40DateFormat = GeneralParameters.UTC40Format
		''Hold_GeneralParameter_TargetDatabase = GeneralParameters.TargetDatabase
	endselect
	
End Function	
								''|LN10605.en							
:FDEF:END
:CURN:
:STAT:M
:COMT:START

:COMT:END
FUNC
:MPRF:14
:VERS:A2LN
:RELE:LN
:CUST:1060
:FNAM:ItemHandling
:DSCA:Item Handling Functions
:LURN:ivgils
:LDAT:11/14/2018 12:06:13 AM
:FDEF:START
''|Define global variables used in the functions specified in this function repository			''|LN10605.sn
dim Hold.tc.ItemCodeSegmentationParameters.Read						
dim Hold.tc.StartPosition.project								
dim Hold.tc.segmentLength.project							
dim Hold.tc.StartPosition.item								
dim Hold.tc.segmentLength.item								
dim Hold.tc.segmentAlignment.project							
dim Hold.tc.segmentAlignment.item							''|LN10605.en

Function get.segment.item.code(i.cprj.field, i.item.field)

	''| Remark regards to domain cpitem:
	''| The function ''get.segment.cp.item.code() is not stored in the Function Repository 
	''| as this is only used in conversion object for table cprpd100 and cprpd710.
	''| Therefore this function can be found in the Function section of conversion objects tcibd001 and cprpd710.	
	
	''| Read the segmentation parameters.
	If Hold.tc.ItemCodeSegmentationParameters.Read <> 2 Then
		''Intitialize default values
		Hold.tc.StartPosition.project 	= 1
		Hold.tc.segmentLength.project 	= 9
		Hold.tc.StartPosition.item 	= 10		
		Hold.tc.segmentLength.item 	= 38
		Hold.tc.segmentAlignment.project 	= "left"	
		Hold.tc.segmentAlignment.item 	= "left"	
		
		Hold.tc.ItemCodeSegmentationParameters.Read = 2

		Select	ItemCodeSegmentationParameters.*
		From	ItemCodeSegmentationParameters
		Where	ItemCodeSegmentationParameters.cpac = "tc" 
		And 	ItemCodeSegmentationParameters.pdom = "item"
		Selectdo
			If ItemCodeSegmentationParameters.apco = "project" Then
				Hold.tc.StartPosition.project 	= ItemCodeSegmentationParameters.spos
				Hold.tc.segmentLength.project 	= ItemCodeSegmentationParameters.leng
				Hold.tc.segmentAlignment.project	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "item" Then
				Hold.tc.StartPosition.item 	= ItemCodeSegmentationParameters.spos
				Hold.tc.segmentLength.item 	= ItemCodeSegmentationParameters.leng
				Hold.tc.segmentAlignment.item	= ItemCodeSegmentationParameters.adju	
			End If
		Endselect	
	End If	

	''| This section fills the segment field in the item code. 
	''| The segment part is always considered as UpperCase.
	
	ProjectSegment 	= Trim(i.cprj.field)
												''|#LN10605.sn			
	''| For templates with Item (project segment/itemsegment) in the primary key it requires the project segement must always have a value.
	''| Therefore the default value vor project segment in the templates is set as "PROJEMPTY", meaning the project segment should be regarded as empty.
	''| The below section is to clear the project segment field when the access field contains the value "PROJEMPTY".
	if ProjectSegment = "PROJEMPTY" then
		ProjectSegment = ""
	end if	
												''|#LN10605.en
	ItemSegment 	= Trim(i.item.field)
	ProjectLength	= len(ProjectSegment)	
	ItemLength	= len(ItemSegment)	


	
	''|* This section formats the segments. 
	''|* For aligment only "left" or "right" is possible and remaining positions will be filled with spaces.
	''| Formatting the project segment			
	
	if Hold.tc.segmentAlignment.project = "left" then
		ProjectSegment = ProjectSegment & Space(Hold.tc.segmentLength.project - ProjectLength)
	else
		ProjectSegment = Space(Hold.tc.segmentLength.project - ProjectLength) & ProjectSegment
	end if
	''| Formatting the item segment
	if Hold.tc.segmentAlignment.item = "left" then
		ItemSegment = ItemSegment & Space(Hold.tc.segmentLength.item - ItemLength)
	else
		ItemSegment = Space(Hold.tc.segmentLength.item - ItemLength) & ItemSegment
	end if	

	''| Project segment before Item Segment: Project - Item
	If Hold.tc.StartPosition.project < Hold.tc.StartPosition.item then
		CombinedSegments = ProjectSegment & ItemSegment	
	Else
	''|Project segment after Item segment: Item - Project 
		CombinedSegments = ItemSegment & ProjectSegment
	End If
	
	get.segment.item.code = UCase(CombinedSegments)	

End Function


'' The below 3 functions are created for the Item Default handling.
Function ItemHandling.GetTypeString(Varstr.Itemdefault, Varstr.Itemfield, Varint.Exception, Varint.DefaultFound)

	if Varint.Exception = 2	then			''|# Exception = No
		if Varstr.Itemdefault = "" or Varint.DefaultFound = 0 then
			ItemHandling.GetTypeString = Varstr.Itemfield
		else
			ItemHandling.GetTypeString = Varstr.Itemdefault
		end if
	else
		ItemHandling.GetTypeString = Varstr.Itemfield
	end if

End Function

Function ItemHandling.GetTypeEnum(Varint.Itemdefault, Varint.Itemfield, Varint.Exception, Varint.DefaultFound, Varint.DefaultValue)

	if Varint.Exception = 2	then					''|# Exception = No
		if Varint.DefaultFound = 0 then				''|# Default not found/present
			if Varint.Itemfield <> "0" and _
			   Varint.Itemfield <> "" then			''|# If no mapping exist is access, 0 is passed as argument
				ItemHandling.GetTypeEnum = Varint.Itemfield
			else
				ItemHandling.GetTypeEnum = Varint.DefaultValue	''|# Default value of enum always passed as argument
			end if
		else
			ItemHandling.GetTypeEnum = Varint.Itemdefault
		end if
	else
		if Varint.Itemfield <> "0" and Varint.Itemfield <> "" then
			ItemHandling.GetTypeEnum = Varint.Itemfield
		else
			ItemHandling.GetTypeEnum = Varint.DefaultValue
		end if
	end if

End Function

Function ItemHandling.GetTypeNumber(Varnum.Itemdefault, Varnum.Itemfield, Varint.Exception, Varint.DefaultFound)

	if Varint.Exception = 2	then			''|# Exception = No
		if Varnum.Itemdefault = "" or Varint.DefaultFound = 0 then
			ItemHandling.GetTypeNumber = Varnum.Itemfield
		else
			ItemHandling.GetTypeNumber = Varnum.Itemdefault
		end if
	else
		ItemHandling.GetTypeNumber = Varnum.Itemfield
	end if

End Function



:FDEF:END
:CURN:
:STAT:M
:COMT:START

:COMT:END
