<#--
   ******************************************************
   *
   *                       NOTICE
   *
   *  THIS SOFTWARE IS THE PROPERTY OF AND CONTAINS
   *  CONFIDENTIAL INFORMATION OF INFOR, AND SHALL NOT BE
   *  COPIED, USED, NOR DISCLOSED WITHOUT EXPRESS WRITTEN
   *  AUTHORIZATION.  ALTHOUGH PUBLICATION IS NOT
   *  INTENDED, IN THE EVENT OF PUBLICATION, THE
   *  FOLLOWING NOTICE IS APPLICABLE:
   *
   *  Copyright © 2009 Infor. All rights reserved.
   *  The word and design marks set forth herein are
   *  trademarks and/or registered trademarks of Infor
   *  and/or related affiliates and subsidiaries.
   *  All rights reserved. All other trademarks listed
   *  herein are the property of their respective owners.
   *  www.infor.com.
   *
   ******************************************************
  -->
<#import "protected.st.afs.ftl" as afs/>

|****************************** Execute Method ********************************
|	boolean	ibl.cancel
<#list protected.listProtectedComponents() as c>
	<#list c.componentImplementation.methodImplementation as methodImplementation>
		<#assign methodName = common.getNameFromMethodImplementation(methodImplementation)>
		<#if !common.isQueryMethod(methodName) && !common.isPublishMethod(methodName) && !common.isEventMethod(methodName) &&
		     methodImplementation.processingOrder != "batch" &&
		     protected.hasMethodAlternativeImplementation(methodName)=="">
function extern 
long <@names.ST_DLLCode/>.before.execute.${c.componentName}.${methodName}(ref	boolean	io.cancel)
{
	DllUsage
	EndDllUsage

			<#if !protected.isFunctionServerComponent(c.componentImplementation)>
	long	hold.context
			</#if><#--if !protected.isFunctionServerComponent(c.componentImplementation)-->

	RETIFNOK( <@names.ST_DLLCode/>.${c.componentName}.${methodName}.set.derived() )

	error.bypass = 1
			<#if !protected.isFunctionServerComponent(c.componentImplementation)>
	hold.context = dal.get.context()
				<#if !common.isSpecificMethod(methodName)>
	dal.set.context(CTX_INTEGRATION)
				<#else><#--if !common.isSpecificMethod(methodName)-->
	dal.set.context(CTX_PROCESS)
				</#if><#--if !common.isSpecificMethod(methodName)-->
			</#if><#--if !protected.isFunctionServerComponent(c.componentImplementation)-->

			<#list protected.listProtectedAttributes(methodName, c.componentName) as pa>
				<#assign scope=common.getScopeFromMethodArgumentImplementation(pa.methodArgumentImplementation)>
				<#if (scope?contains("in") && common.getIsMandatoryFromMethodArgumentImplementation(pa.methodArgumentImplementation))>
	if not bl.${c.componentName}.${common.getAttributeName(pa.attributeImplementation)}.set then
		dal.set.error.message("tlbctst0001",
			"${c.componentName}.${common.getAttributeName(pa.attributeImplementation)}")
		|* Mandatory protected attribute %1$s is not set.
		error.bypass = 0
					<#if !protected.isFunctionServerComponent(c.componentImplementation)>
		dal.set.context(hold.context)
					</#if><#--if !protected.isFunctionServerComponent(c.componentImplementation)-->
		return(DALHOOKERROR)
	endif
				</#if><#--if (scope?contains("in") && common.getIsMandatoryFromMethodArgumentImplementation(pa.methodArgumentImplementation))-->
			</#list><#--list protected.listProtectedAttributes(methodName, c.componentName) as pa-->

			<#if protected.executeMethodHookPresent("before", methodImplementation)>
	|* Before Hook
	<@protected.RETIFNOKINITFIN_COMPONENT iComponent=c iMethod=methodImplementation
		iFun="Hook.BeforeExecute."+c.componentName+"."+methodName
		iCancel=true iHookType="before"
		iRestoreDalContext=!protected.isFunctionServerComponent(c.componentImplementation)/>
			</#if><#--if protected.executeMethodHookPresent("before", methodImplementation)-->
	if io.cancel then
		bl.${c.componentName}.initialize = false
	endif
	error.bypass = 0
			<#if !protected.isFunctionServerComponent(c.componentImplementation)>
	dal.set.context(hold.context)
			</#if><#--if !protected.isFunctionServerComponent(c.componentImplementation)-->
	return(0)
}

function extern 
long <@names.ST_DLLCode/>.execute.${c.componentName}.${methodName}()
{
	DllUsage
	EndDllUsage
			<#if protected.executeMethodHookPresent("on", methodImplementation)>
	boolean	loc.default
			</#if>
			<#if !protected.isFunctionServerComponent(c.componentImplementation)>
	long	hold.context
			</#if><#--if !protected.isFunctionServerComponent(c.componentImplementation)-->
	long	duml

	duml = 0
			<#if (methodName=="Change" || methodName=="Delete") &&
				  !protected.isFunctionServerComponent(c.componentImplementation)>
	${c.componentName}.GetOldValuesBeforeChangeDelete()

			</#if>
	error.bypass = 1
	bl.component.result = 0
			<#if !protected.isFunctionServerComponent(c.componentImplementation)>
	hold.context = dal.get.context()
				<#if !common.isSpecificMethod(methodName)>
	dal.set.context(CTX_INTEGRATION)
				<#else><#--if !common.isSpecificMethod(methodName)-->
	dal.set.context(CTX_PROCESS)
				</#if><#--if !common.isSpecificMethod(methodName)-->
			</#if><#--if !protected.isFunctionServerComponent(c.componentImplementation)-->

			<#if protected.executeMethodHookPresent("before", methodImplementation)>
|	if not ibl.cancel then
			</#if><#--if protected.executeMethodHook("before", methodImplementation)-->
	set.permission.for.readonly.attributes(true)

			<#if methodName == "Create">
				<#list protected.listProtectedAttributes(methodName, c.componentName) as a>
					<#if (a.scope=="in" || a.scope=="inout")>
					<#assign staticDefault=protected.getDefaultValueFromMethodArgumentImplementation(a.methodArgumentImplementation)>
						<#if (a.attributeImplementation.defaultValueHookExpression?exists && a.attributeImplementation.defaultValueHookExpression?has_content) || staticDefault.present ><#-- default hook present-->
	|* Default handling...
	if not bl.${c.componentName}.${a.attributeName}.set then
					    	<#if !common.getMandatoryDatatype(a.attributeImplementation).dimensions?exists>
								<#if staticDefault.present>
		|* Found in ${staticDefault.where}
		bl.${c.componentName}.${a.attributeName} = ${staticDefault.value}
		bl.${c.componentName}.${a.attributeName}.set = true
								</#if>
							</#if>
							<#if a.attributeImplementation.defaultValueHookExpression?exists && a.attributeImplementation.defaultValueHookExpression?has_content>
		duml = Hook.DefaultValue.${c.componentName}.${a.attributeName}(
								<#if a.attributeImplementation.attributeImplementationRelationship?exists>
									<#list a.attributeImplementation.attributeImplementationRelationship?sort_by("position") as air>
				bl.${c.componentName}.${common.getAttributeName(air.attributeImplementation.idref)},
									</#list><#--list attributeImplementation.attributeImplementationRelationship?sort_by("position") as air-->
								</#if>
				bl.${c.componentName}.${a.attributeName},
				bl.${c.componentName}.${a.attributeName}.set)
							</#if><#-- a.attributeImplementation.defaultValueHookExpression?exists && a.attributeImplementation.defaultValueHookExpression?has_content-->
	endif
						</#if>
					</#if><#-- (a.scope=="in" || a.scope=="inout")-->
				</#list><#--list protected.listProtectedAttributes(methodName, c.componentName) as a-->
			</#if>

			<#if methodImplementation.module?exists && methodImplementation.procedure?exists>
				<#assign module=methodImplementation.module.idref>
				<#assign procedure=methodImplementation.procedure.idref>

	#pragma used dll o${module.name}
	bl.result = ${procedure.name}(
				<#assign first=true>
				<#assign isSetList=[]/>
				<#list procedure.procedureArgument?sort_by("position")?sort_by("position") as pa>
					<#list protected.listProtectedAttributes(methodName, c.componentName) as a>
						<#if a.methodArgumentImplementation.procedureArgument?exists>
							<#if a.methodArgumentImplementation.procedureArgument.idref==pa>
								<#if first>
				bl.${a.componentName}.${a.attributeName}
									<#assign first=false>
								<#else>
				, bl.${a.componentName}.${a.attributeName}
								</#if>
								<#if a.methodArgumentImplementation.procedureArgument.idref.scope == "out" ||
								     a.methodArgumentImplementation.procedureArgument.idref.scope == "inout">
									<#assign isSetList=isSetList+[a]/>
								</#if>
							</#if>
						</#if>
					</#list>
				</#list>
	)
	if bl.result <> 0 then
		bl.${c.componentName}.initialize = false
		bl.method.result = bl.result
		bl.component.result = bl.result
		bl.ret = ${names.packageName}${names.moduleName}.bl${names.businessObjectID}st00.finalize.${methodName}(bl.result)
		error.bypass = 0
				<#if !protected.isFunctionServerComponent(c.componentImplementation)>
		dal.set.context(hold.context)
				</#if><#--if !protected.isFunctionServerComponent(c.componentImplementation)-->
		return(bl.result)
	endif
	<#list isSetList as a>
	bl.${a.componentName}.${a.attributeName}.set = true
	</#list><#--list isSetList as a-->
			<#else><#--if methodImplementation.module?exists && methodImplementation.procedure?exists-->

			<#if protected.executeMethodHookPresent("on", methodImplementation)>
	loc.default = false

	<@protected.RETIFNOKINITFIN_COMPONENT iComponent=c iMethod=methodImplementation 
		iFun="Hook.OnExecute."+c.componentName+"."+methodName
		iHookType="on" iNoDefault=!protected.generateIoDefaultInOnExecuteHook(methodName, methodImplementation.processingOrder)
		iRestoreDalContext=!protected.isFunctionServerComponent(c.componentImplementation)/>

	if loc.default then
		|* Default execute.
			</#if><#--if protected.executeMethodHookPresent("on", methodImplementation)-->
<#-- Process tables in bottom-up order (for the Delete method, in top-down order) -->
		<#if methodName=="Delete">
			<#assign isBottomUp=false>
		<#else>
			<#assign isBottomUp=true>
		</#if>
		<#list protected.listOfComponentTables(c, isBottomUp) as theTable>
			<#list c.componentImplementation.componentImplementationTable as componentImplementationTable>
			<#if componentImplementationTable.table.idref.name==theTable>
				<#if protected.isFunctionServerComponent(c.componentImplementation) && componentImplementationTable.isRootTable>
|*	RETIFNOKINITFIN_COMPONENT(${methodName}, ${c.componentName}, ${methodName}.Object.${c.componentName}.${componentImplementationTable.table.idref.name}())
	<@protected.RETIFNOKINITFIN_COMPONENT iComponent=c iMethod=methodImplementation
		iFun=methodName+".Object."+c.componentName+"."+componentImplementationTable.table.idref.name+"_"+componentImplementationTable.position
		iRestoreDalContext=!protected.isFunctionServerComponent(c.componentImplementation)/>
				<#elseif !protected.isFunctionServerComponent(c.componentImplementation)><#--if protected.isFunctionServerComponent(c.componentImplementation) && componentImplementationTable.isRootTable-->
					<#if componentImplementationTable.isRootTable && methodName != "Delete" || 
						!componentImplementationTable.isRootTable && methodName == "Delete">
						<#if common.isStandardMethod(methodName) && protected.handleObject(methodName, componentImplementationTable)>
|*	RETIFNOKINITFIN_COMPONENT(${methodName}, ${c.componentName}, ${methodName}.Object.${c.componentName}.${componentImplementationTable.table.idref.name}())
	<@protected.RETIFNOKINITFIN_COMPONENT iComponent=c iMethod=methodImplementation
		iFun=methodName+".Object."+c.componentName+"."+componentImplementationTable.table.idref.name+"_"+componentImplementationTable.position
		iRestoreDalContext=!protected.isFunctionServerComponent(c.componentImplementation)/>
						</#if><#--if common.isStandardMethod(methodName)-->
					</#if><#--if componentImplementationTable.isRootTable && methodName != "Delete" || !componentImplementationTable.isRootTable && methodName == "Delete"-->
				</#if><#--elseif !protected.isFunctionServerComponent(c.componentImplementation)-->
			</#if><#--if componentImplementationTable.table.idref.name==theTable-->
			</#list><#--list c.componentImplementation.componentImplementationTable as componentImplementationTable-->
			<#list c.componentImplementation.componentImplementationTable as componentImplementationTable>
			<#if componentImplementationTable.table.idref.name==theTable>
				<#if !protected.isFunctionServerComponent(c.componentImplementation)>

					<#if componentImplementationTable.isRootTable && methodName == "Delete" || 
						!componentImplementationTable.isRootTable && methodName != "Delete">
						<#if common.isStandardMethod(methodName) && protected.handleObject(methodName, componentImplementationTable)>
|*	RETIFNOKINITFIN_COMPONENT(${methodName}, ${c.componentName}, ${methodName}.Object.${c.componentName}.${componentImplementationTable.table.idref.name}())
	<@protected.RETIFNOKINITFIN_COMPONENT iComponent=c iMethod=methodImplementation
		iFun=methodName+".Object."+c.componentName+"."+componentImplementationTable.table.idref.name+"_"+componentImplementationTable.position
		iRestoreDalContext=!protected.isFunctionServerComponent(c.componentImplementation)/>
						</#if><#--if common.isStandardMethod(methodName)-->
					</#if><#--if componentImplementationTable.isRootTable && methodName == "Delete" || !componentImplementationTable.isRootTable && methodName != "Delete"-->
				</#if><#--if !protected.isFunctionServerComponent(c.componentImplementation)-->
				</#if><#--if componentImplementationTable.table.idref.name==theTable-->
			</#list><#--list c.componentImplementation.componentImplementationTable as componentImplementationTable-->
		</#list><#--list protected.listOfComponentTables(c, false) as theTable-->

			<#if protected.executeMethodHookPresent("on", methodImplementation)>
	endif
			</#if><#--if protected.executeMethodHookPresent("on", methodImplementation)-->
			</#if><#--if methodImplementation.module?exists && methodImplementation.procedure?exists-->

			<#if protected.executeMethodHookPresent("before", methodImplementation)>
|	endif
			</#if><#--if protected.executeMethodHookPresent("before", methodImplementation)-->
		<#list protected.listProtectedAttributes(methodName, c.componentName) as a>
			<#if !a.attributeImplementation.interactionPoint?exists>
				<#if !a.attributeImplementation.column?exists>
				<#assign defaultVal=protected.getDefaultValueFromMethodArgumentImplementation(a.methodArgumentImplementation)>
				<#if defaultVal.present && defaultVal.dimensions==0><#-- no defaults for arrays-->
	|* Default found in ${defaultVal.where}
	if not bl.${c.componentName}.${a.attributeName}.set then
		bl.${c.componentName}.${a.attributeName} = ${defaultVal.value}
		bl.${c.componentName}.${a.attributeName}.set = true
	endif
				</#if>
				</#if>
			</#if>
		</#list>
	error.bypass = 0
		<#if !protected.isFunctionServerComponent(c.componentImplementation)>
	dal.set.context(hold.context)
		</#if><#--if !protected.isFunctionServerComponent(c.componentImplementation)-->
	return(0)
}

function extern 
long <@names.ST_DLLCode/>.after.execute.${c.componentName}.${methodName}()
{
	DllUsage
	EndDllUsage

			<#if protected.executeMethodHookPresent("before", methodImplementation)>
|	if not ibl.cancel then
			</#if><#--if protected.executeMethodHookPresent("before", methodImplementation)-->

		<#if protected.executeMethodHookPresent("after", methodImplementation)>
				<#assign MArguments="">
		<@protected.RETIFNOKINITFIN_COMPONENT iComponent=c iMethod=methodImplementation 
		iFun="Hook.AfterExecute."+c.componentName+"."+methodName
		iHookType="after" iAfter=false/>
		</#if>
		<#if protected.executeMethodHookPresent("before", methodImplementation)>
|	endif
		</#if><#--if protected.executeMethodHookPresent("before", methodImplementation)-->
	bl.${c.componentName}.initialize = false
	return(0)
}
		</#if><#--if !common.isQueryMethod(methodName)-->
	</#list><#--list c.componentImplementation.methodImplementation as methodImplementation-->
</#list><#--list protected.listProtectedComponents() as c-->

<#list protected.listProtectedComponents() as c>
function extern 
long <@names.ST_DLLCode/>.execute.${c.componentName}.Read()
{
	DllUsage
	EndDllUsage

	long	result
		<#if !protected.isFunctionServerComponent(c.componentImplementation)>
	long	hold.context
	long	retl
	
	retl = 0
		</#if><#--if !protected.isFunctionServerComponent(c.componentImplementation)-->

	result = 0
	bl.component.result = 0
		<#if !protected.isFunctionServerComponent(c.componentImplementation)>
	hold.context = dal.get.context()
	dal.set.context(CTX_INTEGRATION)
		</#if><#--if !protected.isFunctionServerComponent(c.componentImplementation)-->
	<#--set.derived must be called to set calculated index fields -->
	<#if common.methodPresent("Change", c.componentImplementation) >
	RETIFNOK( <@names.ST_DLLCode/>.${c.componentName}.Change.set.derived() )
	</#if><#-- common.methodPresent("Change", c.componentImplementation) -->
	
			<#list protected.listProtectedAttributes("", c.componentName) as pa>
				<#if (common.getIsIdentifier(pa.attributeImplementation))>
	if not bl.${c.componentName}.${common.getAttributeName(pa.attributeImplementation)}.set then
		dal.set.error.message("tlbctst0001",
			"${c.componentName}.${common.getAttributeName(pa.attributeImplementation)}")
		|* Mandatory protected attribute %1$s is not set.
					<#if !protected.isFunctionServerComponent(c.componentImplementation)>
		dal.set.context(hold.context)
					</#if><#--if !protected.isFunctionServerComponent(c.componentImplementation)-->
		return(DALHOOKERROR)
	endif
				</#if><#--if (scope?contains("in") && common.getIsMandatoryFromMethodArgumentImplementation(pa.methodArgumentImplementation))-->
			</#list><#--list protected.listProtectedAttributes(methodName, c.componentName) as pa-->

	set.permission.for.readonly.attributes(true)

		<#if protected.isFunctionServerComponent(c.componentImplementation)>
	RETIFNOK(Read.Object.${c.componentName}.AFS())
		<#else><#--if protected.isFunctionServerComponent(c.componentImplementation)-->
			<#list c.componentImplementation.componentImplementationTable as componentImplementationTable>
	<#--<-No.Reference.Table>> Zit nog niet in model !! todo -->
				<#if !componentImplementationTable.isReferentialIntegrityTable && componentImplementationTable.isRootTable>
	retl = Read.Object.${c.componentName}.${componentImplementationTable.table.idref.name}_${componentImplementationTable.position}()
	if retl <> 0 then
		dal.set.context(hold.context)
		return(retl)
	endif
				</#if><#--if !componentImplementationTable.isReferentialIntegrityTable && componentImplementationTable.isRootTable-->
			</#list><#--list c.componentImplementation.componentImplementationTable as componentImplementationTable-->
	set.current.number.of.DAL.messages()
			<#list c.componentImplementation.componentImplementationTable as componentImplementationTable>
				<#if !componentImplementationTable.isReferentialIntegrityTable && !componentImplementationTable.isRootTable>
	retl = Read.Object.${c.componentName}.${componentImplementationTable.table.idref.name}_${componentImplementationTable.position}()
	if retl <> 0 then
		dal.set.context(hold.context)
		return(retl)
	endif
				</#if><#--if !componentImplementationTable.isReferentialIntegrityTable && !componentImplementationTable.isRootTable-->
			</#list><#--list c.componentImplementation.componentImplementationTable as componentImplementationTable-->
	clear.recent.DAL.error.messages()
		</#if><#--if protected.isFunctionServerComponent(c.componentImplementation)-->

		<#list c.componentImplementation.attributeImplementation as a>
			<#if !a.interactionPoint?exists>
				<#if !a.column?exists && a.defaultValue?exists>
					<#assign defaultVal=protected.getDefaultFromAttributeImplementation(a)>
					<#if defaultVal.dimensions==0 && defaultVal.present> <#-- no defaults for arrays-->
	if not bl.${c.componentName}.${a.name}.set then
		bl.${c.componentName}.${a.name} = ${defaultVal.value}
		bl.${c.componentName}.${a.name}.set = true
	endif
					</#if>
				</#if>
			</#if>
		</#list>

|*	RETIFNOKINITFIN_COMPONENT(Read, ${c.componentName}, "<@names.SF_DLLCode/>.after.Read.${c.componentName}")

	bl.${c.componentName}.initialize = false
	bl.ret = <@names.ST_DLLCode/>.finalize.Read()
		<#if !protected.isFunctionServerComponent(c.componentImplementation)>
	dal.set.context(hold.context)
		</#if><#--if !protected.isFunctionServerComponent(c.componentImplementation)-->

	return(0)
}

function extern 
long <@names.ST_DLLCode/>.execute.${c.componentName}.Read.Only()
{
	DllUsage
	EndDllUsage

	long	result
	<#if !protected.isFunctionServerComponent(c.componentImplementation)>
	long	hold.context
	</#if><#--if !protected.isFunctionServerComponent(c.componentImplementation)-->

	result = 0
	<#if !protected.isFunctionServerComponent(c.componentImplementation)>
	hold.context = dal.get.context()
	dal.set.context(CTX_INTEGRATION)
	</#if><#--if !protected.isFunctionServerComponent(c.componentImplementation)-->
	set.current.number.of.DAL.messages()
	<#--set.derived must be called to set calculated index fields -->
	<#if common.methodPresent("Change", c.componentImplementation) >
	RETIFNOK( <@names.ST_DLLCode/>.${c.componentName}.Change.set.derived() )
	</#if><#-- common.methodPresent("Change", c.componentImplementation) -->
	
	<#list common.listComponentImplementations() as ci>
		<#list c.componentImplementation.componentImplementationTable as componentImplementationTable>
			<#if c.componentImplementation == ci.componentImplementation && componentImplementationTable.isRootTable>
	result = dal.get.object("${componentImplementationTable.table.idref.name}", false
				<#assign table=componentImplementationTable.table.idref>
				<#assign tableName=table.name>
				<#list table.column as tc>
					<#if tc.isPrimaryKey>
						<#list protected.searchattrimpl(c.componentImplementation, componentImplementationTable, tc.name) as an>
		,"${tableName}.${tc.name}", bl.${c.componentName}.${an.attributeName}
						</#list>
					</#if>
				</#list>
		)
	if result <> 0 then
		clear.recent.DAL.error.messages()
				<#if !protected.isFunctionServerComponent(c.componentImplementation)>
		dal.set.context(hold.context)
				</#if><#--if !protected.isFunctionServerComponent(c.componentImplementation)-->
		return(result)
	endif

			</#if>
		</#list>
	</#list>
	clear.recent.DAL.error.messages()
	<#if !protected.isFunctionServerComponent(c.componentImplementation)>
	dal.set.context(hold.context)
	</#if><#--if !protected.isFunctionServerComponent(c.componentImplementation)-->
	return(0)
}

</#list><#--list protected.listProtectedComponents() as c-->
|****************************** Finalize Method *******************************

function set.component.init.vars.to.false()
{
	long	ret

<#list protected.listProtectedComponents() as c>
	bl.${c.componentName}.initialize = false
	<#if protected.isFunctionServerComponent(c.componentImplementation)>
	if not isspace(bl.${c.componentName}.main.session) then
		stpapi.end.session(bl.${c.componentName}.main.session)
<#--#CRM-00000-01607.sn-->
		bl.${c.componentName}.main.session = ""
		bl.${c.componentName}.sync.session = ""
<#--#CRM-00000-01607.en-->
	endif
	</#if><#--if protected.isFunctionServerComponent(c.componentImplementation)-->
</#list><#--list protected.listProtectedMethods() as c-->
	bl.SortingExpressionSet = false
	if bl.Filter <> 0 then
		ret = xmlDelete(bl.Filter)
	endif
	bl.Filter = 0
	if bl.FilteredAttributes <> 0 then
		ret = xmlDelete(bl.FilteredAttributes)
	endif
	bl.FilteredAttributes = 0
	bl.FilterExpression = ""
	bl.PostFilter = false
	set.permission.for.readonly.attributes(false)
}

<#list protected.listProtectedMethods() as m>
		<#if !common.isPublishMethod(m.methodName) && !common.isEventMethod(m.methodName)&&
		     protected.hasMethodAlternativeImplementation(m.methodName)=="">
function extern long <@names.ST_DLLCode/>.finalize.${m.methodName}(...)
{
	DllUsage
	EndDllUsage

	bl.method.result = ( get.argc() > 0 ) ? get.long.arg(1) : 0
	bl.component.result = bl.method.result
		<#if !common.isReferenceMethod(m.methodName)>
	if bl.before.initialize <> 0 then
		bl.before.initialize = 0
|*		Not possible yet... No After hook for method available in model.
|*		if bl.method.result = 0 then
|*			CALL.SPECIFIC.METHOD.NO.RET(
|*				"<@names.ST_DLLCode/>.after.${m.methodName}")
|*			bl.method.result = retval
|*		else
|*			CALL.SPECIFIC.METHOD.NO.RET(
|*				"<@names.ST_DLLCode/>.after.${m.methodName}")
|*		endif
	endif
		</#if><#--if !common.isReferenceMethod(m.methodName)-->

	set.component.init.vars.to.false()

	return(bl.method.result)
}
	</#if><#-- if !common.isPublishMethod(methodName) && !common.isEventMethod(methodName)-->
</#list><#--list object.methodImplementation as m-->

function extern long <@names.ST_DLLCode/>.before.initialized()
{
	DllUsage
	EndDllUsage

	return( (bl.before.initialize = 0) ? 0 : 1)
}

function extern long <@names.ST_DLLCode/>.get.method.result()
{
	DllUsage
	EndDllUsage

	return(bl.method.result)
}

function extern long <@names.ST_DLLCode/>.get.component.result()
{
	DllUsage
	EndDllUsage

	return(bl.component.result)
}

|******************************** Create Object *******************************
<#list protected.listProtectedComponents() as c>
	<#list c.componentImplementation.componentImplementationTable as componentImplementationTable>
		<#assign table=componentImplementationTable.table.idref>
		<#assign tableName=table.name>
	 		<#if componentImplementationTable.isReferentialIntegrityTable>
	 			<#assign methodName="CreateRef">
			<#else><#--if componentImplementationTable.isReferentialIntegrityTable-->
				<#assign methodName="Create">
	 		</#if><#--if componentImplementationTable.isReferentialIntegrityTable-->
	 		<#if common.methodPresent(methodName, c.componentImplementation) &&
		     protected.hasMethodAlternativeImplementation(methodName)=="">

function long ${methodName}.Object.${c.componentName}.${tableName}_${componentImplementationTable.position}()
{
	long	result

	result = 0
				<#if table.type == "table"> <#--!protected.isFunctionServerComponent(c.componentImplementation)> -->
					<#if !componentImplementationTable.isReferentialIntegrityTable>

	if not bl.${tableName}.set then
		return(0)
	endif
<#--LNEX-567.sn-->
						<#if !componentImplementationTable.isRootTable && !componentImplementationTable.isMandatory && methodName == "Create">
	if true
							<#list componentImplementationTable.table.idref.column as col>
								<#if !col.isPrimaryKey>
									<#assign a = protected.getAttributeImplementationLinkedToTableColumnByCit(c, componentImplementationTable, col.name)>
									<#if a?has_content>
										<#assign aEmptyValue=protected.getBaanDataInitializers(a.attributeImplementation)/>
										<#if aEmptyValue=="\"\"">
	   and isspace(bl.${a.componentName}.${a.attributeName})
			   							<#else>
	   and bl.${a.componentName}.${a.attributeName} = ${aEmptyValue}
										</#if><#--if aEmptyValue=="\"\""-->
									</#if><#--if a?has_content-->
								</#if><#--if !col.isPrimaryKey-->
							</#list><#--list componentImplementationTable.table.idref.column as col-->
	then
		return(0)
	endif
						</#if><#--if !componentImplementationTable.isRootTable && !componentImplementationTable.isMandatory && methodName == "Create"-->
<#--LNEX-567.en-->
					</#if><#--if !componentImplementationTable.isReferentialIntegrityTable-->
				</#if><#--if !protected.isFunctionServerComponent(c.componentImplementation)-->

	bl.method = "${methodName}" 
	bl.object = "<@names.BDE_Code/> ${names.businessInterfaceName}"
	bl.bodesc = "<@names.BDE_Code/> ${names.businessInterfaceDesc}"
	bl.component = "${c.componentName}"

				<#if table.type == "form"><#--protected.isFunctionServerComponent(c.componentImplementation)> -->
<@afs.generate_methods_create_object_code c=c.componentImplementation 
							compTable=componentImplementationTable/>
				<#else><#--if protected.isFunctionServerComponent(c.componentImplementation)-->

	result = dal.new.object("${tableName}")
<#--#dal-identifiers.sn-->
	if result <> 0 then
		log.identifiers.DAL.message.${c.componentName}()
	endif
<#--#dal-identifiers.en-->

	RETIFNOK(handle.result(result))
	<#--#TODO DAL doesn't seem to have much added value. Better generate actions directly on table, to avoid the need for a DAL? -->
				  <#if componentImplementationTable.isReferentialIntegrityTable>
					<#--Generate a SET.DAL.FIELD for each identifier and for ref_rkey (RefKey)-->
					<#list protected.listInternalIdentifiers(c.componentName, true) as iai>
						<#--note: ref int methods will only work if column names of ref int table match root table (except for ref_rkey, of course)-->
	SET.DAL.FIELD(${tableName}.${iai.attributeImplementation.column.idref.name}, ${iai.componentName}.${iai.attributeName})
					</#list><#-- protected.listInternalIdentifiers(c.componentName, true) as iai -->
	SET.DAL.FIELD(${tableName}.ref_rkey, RefKey)
				  <#else><#--componentImplementationTable.isReferentialIntegrityTable-->

	${c.componentName}.${componentImplementationTable.name}.set.dal.fields.for.create.change(true)
	 			  </#if><#--else for componentImplementationTable.isReferentialIntegrityTable-->

	result = dal.save.object("${tableName}", db.return.error)
<#--#dal-identifiers.sn-->
	if result <> 0 then
		log.identifiers.DAL.message.${c.componentName}()
	endif
<#--#dal-identifiers.en-->

	RETIFNOK(handle.result(result))

				<#if !componentImplementationTable.isReferentialIntegrityTable &&
				     table.type == "table"><#-- !protected.isFunctionServerComponent(c.componentImplementation)> -->
<#-- #VERS.o		${c.componentName}.${componentImplementationTable.name}.setters.after.create.change() -->
<#-- #VERS.sn -->
RETIFNOK(${c.componentName}.${componentImplementationTable.name}.setters.after.create.change())
<#-- #VERS.en -->
				</#if><#--if !componentImplementationTable.isReferentialIntegrityTable &&
				     !protected.isFunctionServerComponent(c.componentImplementation)-->
	<#list protected.listUsedPersistentAttributes(methodName, c.componentName) as a>
		|* >> ${a.attributeName}
		<#assign staticDefault=protected.getDefaultValueFromMethodArgumentImplementation(a.methodArgumentImplementation)>
		<#if staticDefault.present>
	if not bl.${c.componentName}.${a.attributeName}.set then
		|* Default value found in ${staticDefault.where}
		bl.${c.componentName}.${a.attributeName} = ${staticDefault.value}
		bl.${c.componentName}.${a.attributeName}.set = true
	endif
		</#if>
	</#list><#--list protected.listUsedPersistentAttributes(methodName, c.componentName) as a-->

				</#if><#--if protected.isFunctionServerComponent(c.componentImplementation)-->
	return(0)
}

	 		</#if><#--if common.methodPresent(methodName, c.componentImplementation)-->
	</#list><#--list c.componentImplementation.componentImplementationTable as componentImplementationTable-->
</#list><#--list protected.listProtectedComponents() as c-->

<#-- #VERS.sn -->
|****************** Assign attribute implementation from column ***************
<#-- Methods to enable business object to run even if some columns (or array elements) are missing -->

<#assign alreadyProcessed=[]>
<#list protected.listProtectedComponents() as c>
	<#list c.componentImplementation.componentImplementationTable as componentImplementationTable>
		<#if !protected.isFunctionServerComponent(c.componentImplementation)
				&& componentImplementationTable.table.idref.type=="table"
				&& !componentImplementationTable.isReferentialIntegrityTable>
			<#assign tableName = componentImplementationTable.table.idref.name>
			<#list componentImplementationTable.table.idref.column as col>
			  <#list protected.getMultipleAttributeImplementationsLinkedToTableColumnByCit(c, componentImplementationTable, col.name) as attrImpl>
				<#assign attributeImplementation = attrImpl.attributeImplementation>
				<#if attributeImplementation?has_content>
					<#assign ar=protected.fillArrayFieldForColumn(attributeImplementation, col)>
					<#assign columnName=col.name>
				    <#assign attributeName=common.getAttributeName(attributeImplementation)>
				    <#assign alreadyProcessedEntry = componentImplementationTable.name + "-" + c.componentName + "-" + attributeName>
				    <#if !alreadyProcessed?seq_contains(alreadyProcessedEntry)>
				    	<#assign alreadyProcessed=alreadyProcessed+[alreadyProcessedEntry]>

function long assign.${c.componentName}.${attributeName}.from.column.${componentImplementationTable.name}()
{
	long	retl	| return value to be checked
				    <#assign dimensions=common.getDimensionsForDataType(common.getMandatoryDatatype(attributeImplementation))/>
				    <#if (dimensions?number > 1)>
<#-- attribute implementation is array, so column must also be an array -->
	long	i		| array element

	for i = 1 to ${dimensions?number}
		if column.${tableName}.${columnName}.element.exists(i) then
						<#if attributeImplementation.column?exists && common.get_BaanDatatype_from_XMLSchemaDatatype(common.getMandatoryDatatype(attributeImplementation))=="DB.STRING">
			retl = get.indexed.var(pid, "${tableName}.${columnName}", bl.${c.componentName}.${attributeName}(1,i), i)
						<#else>
			retl = get.indexed.var(pid, "${tableName}.${columnName}", bl.${c.componentName}.${attributeName}(i), i)
						</#if><#-- attributeImplementation.column?exists && common.get_BaanDatatype_from_XMLSchemaDatatype(common.getMandatoryDatatype(attributeImplementation))=="DB.STRING"-->
			if retl <> 0 then
				dal.set.error.message("@Cannot assign ${c.componentName}.${attributeName} element %d from ${tableName}.${columnName} (error %d at %s-%d)", i, retl, __FILE__, __LINE__)
				return(DALHOOKERROR)
			endif
			bl.${c.componentName}.${attributeName}.set(i) = true
		else
			bl.${c.componentName}.${attributeName}.set(i) = false
		endif
	endfor
					<#else><#-- (dimensions?number > 1) -->
				    	<#-- attribute implementation is not an array, but column may be an array -->
						<#if ar.array>
	if column.${tableName}.${columnName}.element.exists(${ar.arrayPOS}) then
		retl = get.indexed.var(pid, "${tableName}.${columnName}", bl.${c.componentName}.${attributeName}, ${ar.arrayPOS})
		if retl <> 0 then
			dal.set.error.message("@Cannot assign ${c.componentName}.${attributeName} element ${ar.arrayPOS} from ${tableName}.${columnName} (error %d at %s-%d)", retl, __FILE__, __LINE__)
						<#else>
	if column.${tableName}.${columnName}.exists() then
		retl = get.var(pid, "${tableName}.${columnName}", bl.${c.componentName}.${attributeName})
		if retl = 0 then
			dal.set.error.message("@Cannot assign ${c.componentName}.${attributeName} from ${tableName}.${columnName} (error at %s-%d)", __FILE__, __LINE__)
						</#if> <#-- ar.array -->
			return(DALHOOKERROR)
		endif
		bl.${c.componentName}.${attributeName}.set = true
	else
<#-- use default value if column does not exist at runtime -->
						<#if attributeImplementation.defaultValue?exists>
							<#assign defaultVal=protected.getDefaultFromAttributeImplementation(attributeImplementation)>
							<#if defaultVal.dimensions==0 && defaultVal.present><#-- no defaults for arrays-->
		bl.${c.componentName}.${attributeName} = ${defaultVal.value}
		bl.${c.componentName}.${attributeName}.set = true
							<#else>
		bl.${c.componentName}.${attributeName}.set = false
							</#if>
						<#else>
		bl.${c.componentName}.${attributeName}.set = false
						</#if><#-- attributeImplementation.defaultValue?exists -->
	endif
					</#if><#-- (dimensions?number > 1) -->
	return(0)
}
				    </#if><#-- !alreadyProcessed?seq_contains(alreadyProcessedEntry) -->
				</#if><#-- attributeImplementation?has_content -->
			  </#list><#-- protected.getMultipleAttributeImplementationsLinkedToTableColumnByCit(c, componentImplementationTable, col.name) as attrImpl -->
			</#list><#-- componentImplementationTable.table.idref.column as col -->
		</#if><#-- !protected.isFunctionServerComponent(c.componentImplementation)
				&& componentImplementationTable.table.idref.type=="table"
				&& !componentImplementationTable.isReferentialIntegrityTable -->
	</#list><#-- c.componentImplementation.componentImplementationTable as componentImplementationTable -->
</#list><#-- protected.listProtectedComponents() as c -->
<#-- #VERS.en -->

|******************************** Read Object *********************************

<#list protected.listProtectedComponents() as c>
	<#list c.componentImplementation.componentImplementationTable as componentImplementationTable>
		<#if protected.isFunctionServerComponent(c.componentImplementation)>
<@afs.generate_methods_read_object_part comp=c compTable=componentImplementationTable/>
<#-- #VERS.note: versioning solution is not implemented for AFS --> 
		<#else><#--if protected.isFunctionServerComponent(c.componentImplementation)-->
			<#assign table=componentImplementationTable.table.idref>
			<#assign tableName=table.name>
			<#if !componentImplementationTable.isReferentialIntegrityTable>
function long Read.Object.${c.componentName}.${tableName}_${componentImplementationTable.position}()
{
	long	result
	long	i

	result = 0
	i = 0
	bl.object = "<@names.BDE_Code/> ${c.componentName}"
	bl.bodesc = "<@names.BDE_Code/> ${names.businessInterfaceName}"
	bl.component = "${c.componentName}"
	bl.method = "Read"

	result = dal.get.object("${tableName}", false
			<#list table.column as tc>
				<#if tc.isPrimaryKey>
						<#list protected.searchattrimpl(c.componentImplementation, componentImplementationTable, tc.name) as an>
		,"${tableName}.${tc.name}", bl.${c.componentName}.${an.attributeName}
						</#list>
				</#if>
			</#list>
		)
				<#if componentImplementationTable.isRootTable>
<#--#dal-identifiers.sn-->
	if result <> 0 then
		log.identifiers.DAL.message.${c.componentName}()
	endif
<#--#dal-identifiers.en-->
	bl.result = handle.result(result)
	if bl.result <> 0 then
		bl.${c.componentName}.initialize = false
		bl.ret = <@names.ST_DLLCode/>.finalize.Read(bl.result)
		return(bl.result)
	endif
				</#if><#--if componentImplementationTable.isRootTable-->
				<#if !componentImplementationTable.isRootTable>
	if result = 0 then
					<#assign pre_TAB="	">
				<#else>
					<#assign pre_TAB="">
				</#if><#--if !componentImplementationTable.isRootTable-->
	<#-- loop trough all the protected attributes (except identifiers)-->
				<#list c.componentImplementation.attributeImplementation as attributeImplementation>
					<#if !common.getIsIdentifier(attributeImplementation) &&
						  attributeImplementation.type="column" &&
						  protected.isMappedToTable(c.componentImplementation, attributeImplementation, tableName)>
<#-- #VERS.o			<#assign ar=protected.fillArrayField(attributeImplementation)> -->
						<#if attributeImplementation.componentImplementationTable?exists &&
						     attributeImplementation.componentImplementationTable.idref==componentImplementationTable>
<#-- #VERS.so
				    		<#assign dimensions=common.getDimensionsForDataType(common.getMandatoryDatatype(attributeImplementation))/>
				    		<#if (dimensions?number > 1)>
${pre_TAB}	for i = 1 to ${dimensions?number}
									<#if attributeImplementation.column?exists && common.get_BaanDatatype_from_XMLSchemaDatatype(common.getMandatoryDatatype(attributeImplementation))=="DB.STRING">
${pre_TAB}		bl.${c.componentName}.${common.getAttributeName(attributeImplementation)}(1,i) = ${componentImplementationTable.table.idref.name}.${attributeImplementation.column.idref.name}(1,i) |?
									<#else>
${pre_TAB}		bl.${c.componentName}.${common.getAttributeName(attributeImplementation)}(i) = ${componentImplementationTable.table.idref.name}.${attributeImplementation.column.idref.name}(i) |?
									</#if><#--if attributeImplementation.column?exists && common.get_BaanDatatype_from_XMLSchemaDatatype(common.getMandatoryDatatype(attributeImplementation))=="DB.STRING"- ->
${pre_TAB}		bl.${c.componentName}.${common.getAttributeName(attributeImplementation)}.set(i) = true
${pre_TAB}	endfor
							<#else>
${pre_TAB}	bl.${c.componentName}.${common.getAttributeName(attributeImplementation)} = ${componentImplementationTable.table.idref.name}.${attributeImplementation.column.idref.name}${ar.arrayFLD}
${pre_TAB}	bl.${c.componentName}.${common.getAttributeName(attributeImplementation)}.set = true
							</#if>
<#-- #VERS.eo -->
<#-- #VERS.sn -->
${pre_TAB}	bl.result = handle.result(assign.${c.componentName}.${common.getAttributeName(attributeImplementation)}.from.column.${componentImplementationTable.name}())
${pre_TAB}	if bl.result <> 0 then
${pre_TAB}		bl.${c.componentName}.initialize = false
${pre_TAB}		bl.ret = <@names.ST_DLLCode/>.finalize.Read(bl.result)
${pre_TAB}		return(bl.result)
${pre_TAB}	endif
<#-- #VERS.en -->
						<#elseif attributeImplementation.defaultValue?exists>
							<#assign defaultVal=protected.getDefaultFromAttributeImplementation(attributeImplementation)>
							<#if defaultVal.dimensions==0 && defaultVal.present><#-- no defaults for arrays-->
${pre_TAB}	bl.${c.componentName}.${common.getAttributeName(attributeImplementation)} = ${defaultVal.value}
${pre_TAB}	bl.${c.componentName}.${common.getAttributeName(attributeImplementation)}.set = true
							</#if>
						</#if><#--if attributeImplementation.type="column"-->
					</#if><#--if common.getIsIdentifier(attributeImplementation)-->
				</#list><#--list c.componentImplementation.attributeImplementation as attributeImplementation-->
				<#if !componentImplementationTable.isRootTable>
	endif
				</#if><#--if !componentImplementationTable.isRootTable-->
	return(0)
}
			</#if><#--if !componentImplementationTable.isReferentialIntegrityTable-->
		</#if><#--if protected.isFunctionServerComponent(c.componentImplementation)-->
	</#list><#--list c.componentImplementation.componentImplementationTable as componentImplementationTable-->
</#list><#--list protected.listProtectedComponents() as c-->

|******************************** Change Object *******************************
<#list protected.listProtectedComponents() as c>
| Old values, needed for updating tables when executing Change Object
	<#assign rootTableName=""/>
	<#list c.componentImplementation.componentImplementationTable as cit>
		<#if !cit.isRootTable>
			<#list cit.table.idref.column as column>
				<#if column.isPrimaryKey>
domain ${column.datatype.idref.nativeDatatype} old.${c.componentName}.${cit.name}.${column.name}
				</#if><#--if column.isPrimaryKey -->
			</#list><#--list cit.idref.column as column -->
		<#else>
			<#assign rootTableName=cit.table.idref.name/>
		</#if><#--if !cit.isRootTable -->
	</#list><#--list c.componentImplementation.componentImplementationTable as cit -->
	<#if !protected.isFunctionServerComponent(c.componentImplementation) &&
		(common.methodPresent("Change", c.componentImplementation) ||
		common.methodPresent("Delete", c.componentImplementation))>
function ${c.componentName}.GetOldValuesBeforeChangeDelete()
{
	<#if rootTableName!="">
		<#if names.applicationBackendRelease == "BaanIV" || names.applicationBackendRelease == "BaanERP5.0">
	#pragma language sql start 6
		</#if><#--if names.applicationBackendRelease == "BaanIV" || names.applicationBackendRelease == "BaanERP5.0"-->
	select *
	<#assign theFirst=true/>
	from ${rootTableName}
	<#assign printedFromTables=[rootTableName]/>
	<#list protected.listOfComponentTables(c, false) as theTable>
		<#assign parentTablesWithColumns=protected.getParentTablesWithColumns(c, theTable)/>
		<#assign previousParentTable="">
		<#list parentTablesWithColumns as column>
			<#assign parentTable=column.parentTable.name>
			<#if parentTable!=previousParentTable>
			<#assign previousParentTable=parentTable>
				<#if protected.containedIn(theTable, printedFromTables)>
		left outer join ${parentTable} on ${parentTable}.${column.name}=${theTable}.${column.toName}
						<#assign printedFromTables=printedFromTables+[column.parentTable.name]/>
				<#else>
		left outer join ${theTable} on ${column.parentTable.name}.${column.name}=${theTable}.${column.toName}
					<#assign printedFromTables=printedFromTables+[theTable]/>
				</#if><#--if protected.containedIn(theTable, printedFromTables)-->
			<#else>
				and ${parentTable}.${column.name}=${theTable}.${column.toName}
			</#if><#--if theFirst-->
		</#list>
	</#list><#--list protected.listOfComponentTables(c, false) as theTable-->
	<#assign theFirst=true/>
	<#list protected.getTableRelationIdentifiers(c, rootTableName) as identifier>
		<#if theFirst>
	where	${rootTableName}.${identifier.column} = :bl.${c.componentName}.${identifier.attribute}
			<#assign theFirst=false/>
			<#assign printedIdentifiers=[identifier.column]>
		<#else>
			<#if !protected.containedIn(identifier.column, printedIdentifiers)>
				<#assign printedIdentifiers=printedIdentifiers+[identifier.column]>
		and ${rootTableName}.${identifier.column} = :bl.${c.componentName}.${identifier.attribute}
			</#if><#--if !protected.containedIn(identifier.column, printedIdentifiers)-->
		</#if><#--if theFirst-->
	</#list><#--list protected.getTableRelationIdentifiers(c, rootTableName) as identifiers-->
	as set with 1 rows
	selectdo
	endselect
		<#if names.applicationBackendRelease == "BaanIV" || names.applicationBackendRelease == "BaanERP5.0">
	#pragma language sql end 6
		</#if><#--if names.applicationBackendRelease == "BaanIV" || names.applicationBackendRelease == "BaanERP5.0"-->
	<#else>
		<#if c.componentImplementation.componentImplementationTable?has_content>
			${logger.warn(object, "No root table specified in component ${c.componentName}")}
		</#if><#--if c.componentImplementation.componentImplementationTable?has_content-->
	</#if><#--if rootTableName!=""-->

	<#list c.componentImplementation.componentImplementationTable as cit>
		<#if !cit.isRootTable>
			<#list cit.table.idref.column as column>
				<#if column.isPrimaryKey>
	old.${c.componentName}.${cit.name}.${column.name} = ${cit.table.idref.name}.${column.name}
<#--TECH5785.so--
					<#assign a = protected.getAttributeImplementationLinkedToTableColumnByCit(c, cit, column.name)>
					<#if a?has_content>
<#--TECH5785.eo-->
<#--TECH5785.sn-->
					<#list protected.getMultipleAttributeImplementationsLinkedToTableColumnByCit(c, cit, column.name) as a>
<#--TECH5785.en-->
	if not bl.${a.componentName}.${a.attributeName}.set then
						<#assign aEmptyValue=protected.getBaanDataInitializers(a.attributeImplementation)/>
						<#if aEmptyValue=="\"\"">
		if not isspace(${cit.table.idref.name}.${column.name}) then
						<#else>
		if ${cit.table.idref.name}.${column.name} <> ${aEmptyValue} then
						</#if><#--if aEmptyValue=="\"\""-->
			bl.${a.componentName}.${a.attributeName} = ${cit.table.idref.name}.${column.name}
			bl.${a.componentName}.${a.attributeName}.set = true
			bl.${cit.table.idref.name}.set = true
		endif
	else
		| assign new value to table field
		${cit.table.idref.name}.${column.name} = bl.${a.componentName}.${a.attributeName}
		bl.${cit.table.idref.name}.set = true
	endif
<#--TECH5785.so--
					</#if>
<#--TECH5785.eo-->
<#--TECH5785.sn-->
					</#list><#--list protected.getMultipleAttributeImplementationsLinkedToTableColumnByCit(c, cit, column.name) as a-->
<#--TECH5785.en-->
				</#if><#--if column.isPrimaryKey -->
			</#list><#--list cit.idref.column as column -->
		</#if><#--if !cit.isRootTable -->
	</#list><#--list c.componentImplementation.componentImplementationTable as cit -->
}

	</#if><#--if !protected.isFunctionServerComponent(c.componentImplementation) &&
		(common.methodPresent("Change", c.componentImplementation) ||
		common.methodPresent("Delete", c.componentImplementation))-->
	<#list c.componentImplementation.componentImplementationTable as componentImplementationTable>
		<#assign table=componentImplementationTable.table.idref>
		<#assign tableName=table.name>
		<#if table.type=="table" || table.type=="form">
			<#assign methodName="Change">
	 		<#if common.methodPresent(methodName, c.componentImplementation)&&
		     protected.hasMethodAlternativeImplementation(methodName)=="">
				<#if !componentImplementationTable.isReferentialIntegrityTable>
function long Change.Object.${c.componentName}.${tableName}_${componentImplementationTable.position}()
{
	long	result
					<#if !componentImplementationTable.isRootTable>
	boolean	insert
	boolean	can.be.deleted
					</#if><#--if !componentImplementationTable.isRootTable-->
					<#if !componentImplementationTable.isReferentialIntegrityTable &&
					     !protected.isFunctionServerComponent(c.componentImplementation)>
	boolean	use.setters

	use.setters = true
					</#if><#--if !componentImplementationTable.isReferentialIntegrityTable &&
					     !protected.isFunctionServerComponent(c.componentImplementation)-->
	if not bl.${tableName}.set then
		return(0)
	endif
					<#if !componentImplementationTable.isRootTable>
	insert = false
	can.be.deleted = false
					</#if><#--if !componentImplementationTable.isRootTable-->
	bl.method = "Change"
	bl.object = "<@names.BDE_Code/> ${c.componentName}"
	bl.bodesc = "<@names.BDE_Code/> ${names.businessInterfaceName}"
	bl.component = "${c.componentName}"
					<#if protected.isFunctionServerComponent(c.componentImplementation)>
<@afs.generate_methods_change_object_part c=c.componentImplementation 
							compTable=componentImplementationTable/>
					<#else><#--if protected.isFunctionServerComponent(c.componentImplementation)-->

<#--LNEX-567.sn-->
						<#if !componentImplementationTable.isRootTable && !componentImplementationTable.isMandatory>
	if true
							<#list componentImplementationTable.table.idref.column as col>
								<#if !col.isPrimaryKey>
<#--TECH5785.so--
									<#assign a = protected.getAttributeImplementationLinkedToTableColumnByCit(c, componentImplementationTable, col.name)>
									<#if a?has_content>
<#--TECH5785.eo-->
<#--TECH5785.sn-->
									<#list protected.getMultipleAttributeImplementationsLinkedToTableColumnByCit(c, componentImplementationTable, col.name) as a>
<#--TECH5785.en-->
										<#assign aEmptyValue=protected.getBaanDataInitializers(a.attributeImplementation)/>
										<#if aEmptyValue=="\"\"">
	   and isspace(bl.${a.componentName}.${a.attributeName})
			   							<#else>
	   and bl.${a.componentName}.${a.attributeName} = ${aEmptyValue}
										</#if><#--if aEmptyValue=="\"\""-->
<#--TECH5785.so--
									</#if><#--if a?has_content-->
<#--TECH5785.eo-->
<#--TECH5785.sn-->
									</#list><#--list protected.getMultipleAttributeImplementationsLinkedToTableColumnByCit(c, componentImplementationTable, col.name) as a-->
<#--TECH5785.en-->
								</#if><#--if !col.isPrimaryKey-->
							</#list><#--list componentImplementationTable.table.idref.column as col-->
	then
		| delete old object
		result = dal.get.object("${tableName}", true
							<#list protected.listIdentifyingColumns(c, tableName) as column>
				, "${tableName}.${column.name}", old.${c.componentName}.${componentImplementationTable.name}.${column.name}
							</#list><#--list protected.listIdentifyingColumns(c, tableName) as column-->
				)
		if result = 0 then
			result = dal.destroy.object("${tableName}", db.return.error)
			if e = EREFEXISTS then
				| reference exist: do not return an error
				clear.recent.DAL.error.messages()
			else
				if result <> 0 then
					log.identifiers.DAL.message.${c.componentName}()
				endif
				RETIFNOK(handle.result(result))
			endif
		else
			| old object not present anymore: do nothing
			clear.recent.DAL.error.messages()
		endif
		return(0)
	endif

						</#if><#--if !componentImplementationTable.isRootTable && !componentImplementationTable.isMandatory-->
<#--LNEX-567.en-->
	set.current.number.of.DAL.messages()
	result = dal.get.object("${tableName}", true
						<#assign printedIdentifiers=[]>
						<#list protected.getTableRelationIdentifiersByCit(c, componentImplementationTable) as identifier>
							<#if componentImplementationTable == identifier.componentImplementationTable && !protected.containedIn(identifier.column, printedIdentifiers)>
		,"${tableName}.${identifier.column}", bl.${c.componentName}.${identifier.attribute}
								<#assign printedIdentifiers=printedIdentifiers+[identifier.column]>
							</#if><#--if tableName == identifier.table && !protected.containedIn(identifier.column, printedIdentifiers)-->
						</#list><#--list protected.getTableRelationIdentifiers(c, tableName) as indentifiers-->
		)
						<#if !componentImplementationTable.isRootTable>
	if e = ENOREC then
		clear.recent.DAL.error.messages()
		insert = true
	else
<#--#dal-identifiers.sn-->
		if result <> 0 then
			log.identifiers.DAL.message.${c.componentName}()
		endif
<#--#dal-identifiers.en-->
		RETIFNOK(handle.result(result))
	endif
						<#else><#--if !componentImplementationTable.isRootTable-->
<#--#dal-identifiers.sn-->
	if result <> 0 then
		log.identifiers.DAL.message.${c.componentName}()
	endif
<#--#dal-identifiers.en-->
	RETIFNOK(handle.result(result))
						</#if><#--if !componentImplementationTable.isRootTable-->

						<#if !componentImplementationTable.isRootTable>
	if true
							<#list protected.listIdentifyingColumns(c, tableName) as column>
								<#if column.emptyValue=="\"\"">
	   and not isspace(old.${c.componentName}.${componentImplementationTable.name}.${column.name})
								<#else>
	   and old.${c.componentName}.${componentImplementationTable.name}.${column.name} <> ${column.emptyValue}
								</#if><#--if column.emptyValue==""-->
							</#list><#--list protected.listIdentifyingColumns(c, tableName) as column-->
	then
		if insert then
			result = dal.new.object("${tableName}")
							<#list c.componentImplementation.attributeImplementation as attributeImplementation>
								<#if common.getIsIdentifier(attributeImplementation)>
									<#if attributeImplementation.type="column">
										<#if protected.isMappedToTable(c.componentImplementation, attributeImplementation, tableName)>
	 										<#assign ar=protected.fillArrayField(attributeImplementation)>
			SET.DAL.FIELD${ar.arrayDEF}(${tableName}.${attributeImplementation.column.idref.name}, ${c.componentName}.${common.getAttributeName(attributeImplementation)}${ar.arrayOPT})
										</#if><#--if protected.isMappedToTable(c.componentImplementation, attributeImplementation, tableName)-->
									</#if><#--if attributeImplementation.type="column"-->
								</#if><#--if common.getIsIdentifier(attributeImplementation)-->
							</#list><#--list c.componentImplementation.attributeImplementation as attributeImplementation-->
		else
			can.be.deleted = ${c.componentName}.${componentImplementationTable.name}.changed.record.can.be.deleted()
			if not can.be.deleted then
				result = dal.change.object("${tableName}")
<#--LNEX-567.sn-->
			else
				use.setters = false
<#--LNEX-567.en-->
			endif
		endif
						<#else><#--if !componentImplementationTable.isRootTable-->
		result = dal.change.object("${tableName}")
						</#if><#--if !componentImplementationTable.isRootTable-->
						<#if componentImplementationTable.isRootTable>
		${c.componentName}.${componentImplementationTable.name}.set.dal.fields.for.create.change(false)
		result = dal.save.object("${tableName}", db.return.error)
						<#else>
		if can.be.deleted then
			result = dal.destroy.object("${tableName}", db.return.error)
		else
			${c.componentName}.${componentImplementationTable.name}.set.dal.fields.for.create.change(insert)
			result = dal.save.object("${tableName}", db.return.error)
		endif
						</#if><#--if !componentImplementationTable.isRootTable-->

<#--#dal-identifiers.sn-->
		if result <> 0 then
			log.identifiers.DAL.message.${c.componentName}()
		endif
<#--#dal-identifiers.en-->
		RETIFNOK(handle.result(result))

						<#if !componentImplementationTable.isRootTable>
	endif
	if insert and
		(false
							<#assign emptySelection=true/>
							<#list c.componentImplementation.attributeImplementation as attributeImplementation>
								<#if attributeImplementation.type="column">
									<#list c.componentImplementation.componentImplementationTable as cit>
										<#list cit.componentImplementationTableDetail as citd>
											<#if citd.toComponentImplementationTable.idref==componentImplementationTable &&
										         citd.column.value==attributeImplementation.column.idref.name &&
						   					     citd.toColumn.idref.isPrimaryKey>
	   	or bl.${c.componentName}.${common.getAttributeName(attributeImplementation)} <> old.${c.componentName}.${componentImplementationTable.name}.${citd.toColumn.value}
												<#assign emptySelection=false/>
											</#if><#--if citd.toComponentImplementationTable.value==tableName &&
												     citd.column.value==attributeImplementation.column.idref.name &&
												     citd.toColumn.idref.isPrimaryKey -->
										</#list><#--list cit.componentImplementationTableDetail as citd -->
									</#list><#--list c.componentImplementation.componentImplementationTable as cit -->
									<#if attributeImplementation.componentImplementationTable.value==tableName &&
									     attributeImplementation.column.value==attributeImplementation.column.idref.name &&
									     attributeImplementation.column.idref.isPrimaryKey>
		or ${tableName}.${attributeImplementation.column.value} <> old.${c.componentName}.${componentImplementationTable.name}.${attributeImplementation.column.value}
												<#assign emptySelection=false/>
									</#if><#--if attributeImplementation.componentImplementationTable.value==tableName &&
													     attributeImplementation.column.value==attributeImplementation.column.idref.name &&
													     attributeImplementation.column.idref.isPrimaryKey -->
								</#if><#--if attributeImplementation.type="column"-->
							</#list><#--list c.componentImplementation.attributeImplementation as attributeImplementation-->
		)
	then
							<#if !emptySelection>
							<#assign parentTablesWithColumns=protected.getParentTablesWithColumnsByCit(c, componentImplementationTable)/>
							<#assign previousParentTable="">
							<#list parentTablesWithColumns as ptcolumn>
								<#assign parentTable=ptcolumn.parentTable.name/>
								<#if previousParentTable!=parentTable>
									<#assign previousParentTable=parentTable>
		| key has been changed
		| change reference on parent
		result = dal.get.object("${parentTable}", true
								<#list protected.getTableRelationIdentifiers(c, parentTable) as identifier>
			,"${parentTable}.${identifier.column}", bl.${c.componentName}.${identifier.attribute}
								</#list><#--list protected.getTableRelationIdentifiers(c, tableName) as identifier-->
			)
		if result = 0 then
			result = dal.change.object("${parentTable}")
								<#list parentTablesWithColumns as column>
								<#if column.parentTable.name == parentTable>
									<#list c.componentImplementation.attributeImplementation as attributeImplementation>
										<#if attributeImplementation.type="column">
											<#if attributeImplementation.column.idref.name==column.name>
												<#assign ar=protected.fillArrayField(attributeImplementation)>
			SET.DAL.FIELD${ar.arrayDEF}(${parentTable}.${column.name}, ${c.componentName}.${common.getAttributeName(attributeImplementation)}${ar.arrayOPT})
											</#if><#--if attributeImplementation.column.idref.name==column.name-->
										</#if><#--if attributeImplementation.type="column"-->
									</#list><#--list c.componentImplementation.attributeImplementation as attributeImplementation-->
								</#if><#--if column.parentTable.name == parentTable-->
								</#list><#--list parentTablesWithColumns as column-->

			result = dal.save.object("${parentTable}", db.return.error)
<#--#dal-identifiers.sn-->
			if result <> 0 then
				log.identifiers.DAL.message.${c.componentName}()
			endif
<#--#dal-identifiers.en-->
			RETIFNOK(handle.result(result))
		else
			clear.recent.DAL.error.messages()
		endif
									</#if><#--if previousParentTable!=parentTable-->
								</#list><#--list parentTablesWithColumns as ptcolumn-->
		| delete old object if key has been changed
		if true
								<#list protected.listIdentifyingColumns(c, tableName) as column>
									<#if column.emptyValue=="\"\"">
		    and not isspace(old.${c.componentName}.${componentImplementationTable.name}.${column.name})
									<#else>
		    and old.${c.componentName}.${componentImplementationTable.name}.${column.name} <> ${column.emptyValue}
									</#if><#--if column.emptyValue=="\"\""-->
								</#list><#--list protected.listIdentifyingColumns(c, tableName) as column-->
		then
			result = dal.get.object("${tableName}", true
								<#list protected.listIdentifyingColumns(c, tableName) as column>
					, "${tableName}.${column.name}", old.${c.componentName}.${componentImplementationTable.name}.${column.name}
								</#list><#--list protected.listIdentifyingColumns(c, tableName) as column-->
					)
								<#if !componentImplementationTable.isReferentialIntegrityTable &&
								     !protected.isFunctionServerComponent(c.componentImplementation)>
			use.setters = false
								</#if><#--if !componentImplementationTable.isReferentialIntegrityTable &&
								     !protected.isFunctionServerComponent(c.componentImplementation)-->
			if result = 0 then
				result = dal.destroy.object("${tableName}", db.return.error)
				if e = EREFEXISTS then
					| reference exist: do not return an error
					clear.recent.DAL.error.messages()
				else
<#--#dal-identifiers.sn-->
					if result <> 0 then
						log.identifiers.DAL.message.${c.componentName}()
					endif
<#--#dal-identifiers.en-->
					RETIFNOK(handle.result(result))
				endif
			else
				| old object not present anymore: do nothing
<#--LNEX-567.sn-->
				clear.recent.DAL.error.messages()
<#--LNEX-567.en-->
			endif
		endif

<#--LNEX-567.sn-->
		| create new object if not yet existing

		if false
								<#list protected.listIdentifyingColumns(c, tableName) as column>
									<#if column.emptyValue=="\"\"">
		   or isspace(old.${c.componentName}.${componentImplementationTable.name}.${column.name})
									<#else>
		   or old.${c.componentName}.${componentImplementationTable.name}.${column.name} = ${column.emptyValue}
									</#if><#--if column.emptyValue==""-->
								</#list><#--list protected.listIdentifyingColumns(c, tableName) as column-->
		then
			result = dal.new.object("${tableName}")
			${c.componentName}.${componentImplementationTable.name}.set.dal.fields.for.create.change(true)
			result = dal.save.object("${tableName}", db.return.error)
		endif
<#--LNEX-567.en-->
							</#if><#--if !emptySelection-->
	endif
							<#if emptySelection>
	if insert then
		| delete old instance
		result = dal.get.object("${tableName}", true
								<#list componentImplementationTable.table.idref.column as column>
									<#if column.isPrimaryKey>
					, "${tableName}.${column.name}", old.${c.componentName}.${componentImplementationTable.name}.${column.name}
									</#if><#--if column.isPrimaryKey -->
								</#list><#--list componentImplementationTable.idref.column as column -->
		)
		use.setters = false
		if result = 0 then
			result = dal.destroy.object("${tableName}", db.return.error)
			if e = EREFEXISTS then
				| reference exist: do not return an error
				clear.recent.DAL.error.messages()
			else
<#--#dal-identifiers.sn-->
				if result <> 0 then
					log.identifiers.DAL.message.${c.componentName}()
				endif
<#--#dal-identifiers.en-->
				RETIFNOK(handle.result(result))
			endif
		else
			| old object not present anymore: do nothing
<#--LNEX-567.sn-->
			clear.recent.DAL.error.messages()
<#--LNEX-567.en-->
		endif
	endif
							</#if><#--if emptySelection-->

						</#if><#--if !componentImplementationTable.isRootTable-->
						<#if !componentImplementationTable.isReferentialIntegrityTable &&
						     !protected.isFunctionServerComponent(c.componentImplementation)>
	if use.setters then
<#-- #VERS.o		${c.componentName}.${componentImplementationTable.name}.setters.after.create.change() -->
<#-- #VERS.sn -->
			RETIFNOK(${c.componentName}.${componentImplementationTable.name}.setters.after.create.change())
<#-- #VERS.en -->
	endif
						</#if><#--if !componentImplementationTable.isReferentialIntegrityTable &&
										     !protected.isFunctionServerComponent(c.componentImplementation)-->
	<#list protected.listUsedPersistentAttributes(methodName, c.componentName) as a>
		<#assign staticDefault=protected.getDefaultValueFromMethodArgumentImplementation(a.methodArgumentImplementation)>
		<#if staticDefault.present>
	if not bl.${c.componentName}.${a.attributeName}.set then
		|* Default value found in ${staticDefault.where}
		bl.${c.componentName}.${a.attributeName} = ${staticDefault.value}
		bl.${c.componentName}.${a.attributeName}.set = true
	endif
		</#if>
	</#list><#--list protected.listUsedPersistentAttributes(methodName, c.componentName) as a-->
					</#if><#--if protected.isFunctionServerComponent(c.componentImplementation)-->

	return(0)
}
					<#if tableName!=rootTableName>

function boolean ${c.componentName}.${componentImplementationTable.name}.changed.record.can.be.deleted()
{
	long	i
	i = 0
						<#list protected.listAttributesNotMappedToOtherByCit(c, componentImplementationTable) as attr>
				    		<#assign dimensions=common.getDimensionsForDataType(common.getMandatoryDatatype(attr.attributeImplementation))/>
				    		<#if (dimensions?number > 1)>
	for i = 1 to ${dimensions?number}
								<#if attr.emptyValue=="\"\"">
		if not bl.${c.componentName}.${attr.attribute}.set(i)
		  or not isspace(bl.${c.componentName}.${attr.attribute}(1,i))
								<#else>
		if not bl.${c.componentName}.${attr.attribute}.set(i) or
		  (bl.${c.componentName}.${attr.attribute}(i) <> ${attr.emptyValue})
								</#if><#--if attr.emptyValue=="\"\""-->
		then
			return(false)
		endif
	endfor
							<#else>
								<#if attr.emptyValue=="\"\"">
	if not bl.${c.componentName}.${attr.attribute}.set
	  or not isspace(bl.${c.componentName}.${attr.attribute})
								<#else>
	if not bl.${c.componentName}.${attr.attribute}.set or
	  (bl.${c.componentName}.${attr.attribute} <> ${attr.emptyValue})
								</#if><#--if attr.emptyValue=="\"\""-->
	then
		return(false)
	endif
						</#if>
						</#list>
	return(true)
}
					</#if><#--if tableName!=rootTableName-->

				</#if><#--if !componentImplementationTable.isReferentialIntegrityTable-->
			</#if><#--if common.methodPresent(methodName, c.componentImplementation)-->
		</#if><#--if table.type=="table"-->
	</#list><#--list c.componentImplementation.componentImplementationTable as componentImplementationTable-->
</#list><#--list protected.listProtectedComponents() as c-->

|******************************** Delete Object *******************************
<#list protected.listProtectedComponents() as c>
	<#list c.componentImplementation.componentImplementationTable as componentImplementationTable>
		<#assign table=componentImplementationTable.table.idref>
		<#assign tableName=table.name>
		<#if table.type=="table" || table.type=="form">
	 		<#if componentImplementationTable.isReferentialIntegrityTable>
	 			<#assign methodName="DeleteRef">
			<#else><#--if componentImplementationTable.isReferentialIntegrityTable-->
				<#assign methodName="Delete">
	 		</#if><#--if componentImplementationTable.isReferentialIntegrityTable-->
	 		<#if common.methodPresent(methodName, c.componentImplementation)&&
		     protected.hasMethodAlternativeImplementation(methodName)=="">

function long ${methodName}.Object.${c.componentName}.${tableName}_${componentImplementationTable.position}()
{
	long	result
				<#if methodName="DeleteRef">
	boolean	delete.all.refs
	long	hold.error.bypass
				</#if>

	result = 0
	bl.method = "${methodName}"
	bl.object = "<@names.BDE_Code/> ${c.componentName}"
	bl.bodesc = "<@names.BDE_Code/> ${names.businessInterfaceName}"
	bl.component = "${c.componentName}"

				<#if protected.isFunctionServerComponent(c.componentImplementation)>
<@afs.generate_methods_delete_object_part c=c.componentImplementation compTable=componentImplementationTable/>
				<#else><#--if protected.isFunctionServerComponent(c.componentImplementation)-->
					<#if !componentImplementationTable.isReferentialIntegrityTable>
	set.current.number.of.DAL.messages()
	result = dal.get.object("${tableName}", true
			<#list table.column as tc>
				<#if tc.isPrimaryKey>
						<#list protected.searchattrimpl(c.componentImplementation, componentImplementationTable, tc.name) as an>
		,"${tableName}.${tc.name}", bl.${c.componentName}.${an.attributeName}
						</#list>
				</#if>
			</#list>
		)
						<#if !componentImplementationTable.isRootTable>
	if e = ENOREC then
		clear.recent.DAL.error.messages()
		return(0)
	endif
						</#if><#--if !componentImplementationTable.isRootTable-->
					</#if><#--if !componentImplementationTable.isReferentialIntegrityTable-->
|*	RETIFNOKINITFIN_COMPONENT( ${methodName}, ${c.componentName}, handle.result(result))
<#--#dal-identifiers.sn-->
	if result <> 0 then
		log.identifiers.DAL.message.${c.componentName}()
	endif
<#--#dal-identifiers.en-->
	RETIFNOK(handle.result(result))

					<#if !componentImplementationTable.isReferentialIntegrityTable>
	result = dal.destroy.object("${tableName}", db.return.error)
						<#if !componentImplementationTable.isRootTable>
	if e = EREFEXISTS then
		clear.recent.DAL.error.messages()
		return(0)
	endif
						</#if><#--if !componentImplementationTable.isRootTable-->
					<#else><#--if !componentImplementationTable.isReferentialIntegrityTable-->
						<#--Generate an assignment for each identifier and for ref_rkey (RefKey)-->
						<#if c.componentName == names.businessInterfaceName>
							<#--if no identifiers filled, delete all rows having RefKey-->
	delete.all.refs = true
						<#else>
	delete.all.refs = false
						</#if>
						<#list protected.listInternalIdentifiers(c.componentName, true) as iai>
							<#--assumption on mapping/naming!? Or make component to ref table mapping explicit? (See also CreateRef)-->
	if bl.${iai.componentName}.${iai.attributeName}.set then
		${tableName}.${iai.attributeImplementation.column.idref.name} = bl.${iai.componentName}.${iai.attributeName}
		delete.all.refs = false
	endif
						</#list><#-- protected.listInternalIdentifiers(c.componentName, true) as iai -->
	if delete.all.refs then
		<#--it is doubtful whether we ever get here, because if the data are is empty, the protected implementation is not invoked either?-->
		hold.error.bypass = error.bypass
		error.bypass = 1
		select	${tableName}.*
		from	${tableName} for update
		where	${tableName}.ref_rkey = :bl.RefKey
		selectdo
			db.delete(t${tableName}, db.retry)
		selectempty
			dal.set.error.message("tlbctst0004", "${c.componentName}")
			|* External Reference not found
			error.bypass = hold.error.bypass
			return(DALHOOKERROR)
		endselect
		result = 0 | success
		error.bypass = hold.error.bypass
	else
		| delete reference for specific component instance
		${tableName}.ref_rkey = bl.RefKey
	 	result = db.eq.and.delete("${tableName}", 
			t${tableName}, 0, db.skip.dupl)
		if e = ENOREC then
			dal.set.error.message("tlbctst0004", "${c.componentName}")
			|* External Reference not found
			return(DALHOOKERROR)
		endif
	endif

					</#if><#--if !componentImplementationTable.isReferentialIntegrityTable-->
<#--#dal-identifiers.sn-->
	if result <> 0 then
		log.identifiers.DAL.message.${c.componentName}()
	endif
<#--#dal-identifiers.en-->
	RETIFNOK(handle.result(result))
				</#if><#--if protected.isFunctionServerComponent(c.componentImplementation)-->
	return(0)
}
			</#if><#--if common.methodPresent(methodName, c.componentImplementation)-->
		</#if><#--if table.type=="table"-->
	</#list><#--list c.componentImplementation.componentImplementationTable as componentImplementationTable-->
</#list><#--list protected.listProtectedComponents() as c-->

|* afs.set_error_message
<@afs.set_error_message/>

|****************************** Setting fields for create/change *************
<#list protected.listProtectedComponents() as c>
	<#list c.componentImplementation.componentImplementationTable as componentImplementationTable>
		<#assign table=componentImplementationTable.table.idref/>
		<#if table.type=="table">
			<#assign tableName=table.name/>
	 		<#if common.methodPresent("Create", c.componentImplementation) || common.methodPresent("Change", c.componentImplementation)>
				<#if !componentImplementationTable.isReferentialIntegrityTable &&
				     !protected.isFunctionServerComponent(c.componentImplementation)>
function ${c.componentName}.${componentImplementationTable.name}.set.dal.fields.for.create.change(boolean i.create)
{
					<#-- For all attributes that are directly or indirectly linked to a table column,
						the attribute implementation is looked up. The code is generated for table
						identifiers first, then for other table fields.
					-->
	long	i
	i = 0
					<#-- (1) identifiers -->
					<#list componentImplementationTable.table.idref.column as col>
						<#if col.isPrimaryKey>
<#--TECH5785a.so--
							<#assign a = protected.getAttributeImplementationLinkedToTableColumnByCit(c, componentImplementationTable, col.name)>
							<#if a?has_content>
<#--TECH5785a.eo-->
<#--TECH5785a.sn-->
							<#-- Note: In case multiple identifying attributes are connected to the same
							table field, it makes little sense to generate a SET.DAL.FIELD for each of them.
							It should be sufficient to generate this for the first found attribute.
							However, this is how it worked in Integration Studio 6.1 and an angry customer
							requires that it works the same in Business Studio.
							Now, if two attributes are available that map to the same identifying table
							column, then the second one will be used instead of the first one. Additionally,
							for an identifier you may not want to set the DAL field twice in all cases,
							because of the logic that may be implemented in the DAL. If this will cause
							problems, the mapping of multiple attributes to the same table field should be
							avoided.
							-->
							<#list protected.getMultipleAttributeImplementationsLinkedToTableColumnByCit(c, componentImplementationTable, col.name) as a>
<#--TECH5785a.en-->
					    		<#assign dimensions=common.getDimensionsForDataType(common.getMandatoryDatatype(a.attributeImplementation))/>
					    		<#if (dimensions?number > 1)>
	for i = 1 to ${dimensions?number}
		if bl.${a.componentName}.${a.attributeName}.set(i) and i.create then
									<#assign ar=protected.fillArrayField(a.attributeImplementation)>
									<#if a.attributeImplementation.column?exists && common.get_BaanDatatype_from_XMLSchemaDatatype(common.getMandatoryDatatype(a.attributeImplementation))=="DB.STRING">
			SET.DAL.FIELD${ar.arrayDEFSTR}(${tableName}.${col.name}, ${a.componentName}.${a.attributeName}, i)
									<#else>
			SET.DAL.FIELD${ar.arrayDEFLNG}(${tableName}.${col.name}, ${a.componentName}.${a.attributeName}, i)
									</#if><#--if a.attributeImplementation.column?exists && common.get_BaanDatatype_from_XMLSchemaDatatype(common.getMandatoryDatatype(a.attributeImplementation))=="DB.STRING"-->
		endif
	endfor
								<#else>
									<#assign ar=protected.fillArrayField(a.attributeImplementation)>
	if bl.${a.componentName}.${a.attributeName}.set and i.create then
		SET.DAL.FIELD${ar.arrayDEF}(${tableName}.${col.name}, ${a.componentName}.${a.attributeName}${ar.arrayOPT})
	endif
								</#if>
<#--TECH5785a.so--
							</#if><#--if a?has_content-->
<#--TECH5785a.eo-->
<#--TECH5785a.sn-->
							</#list><#--list protected.getMultipleAttributeImplementationsLinkedToTableColumnByCit(c, componentImplementationTable, col.name) as a-->
<#--TECH5785a.en-->
						</#if><#--if col.isPrimaryKey-->
					</#list><#--list componentImplementationTable.table.idref.column as col-->
					<#-- (2) non-identifiers -->
					<#list componentImplementationTable.table.idref.column as col>
						<#if !col.isPrimaryKey>
<#--TECH5785.so--
							<#assign a = protected.getAttributeImplementationLinkedToTableColumnByCit(c, componentImplementationTable, col.name)>
							<#if a?has_content>
<#--TECH5785.eo-->
<#--TECH5785.sn-->
							<#list protected.getMultipleAttributeImplementationsLinkedToTableColumnByCit(c, componentImplementationTable, col.name) as a>
<#--TECH5785.en-->
					    		<#assign dimensions=common.getDimensionsForDataType(common.getMandatoryDatatype(a.attributeImplementation))/>
					    		<#if (dimensions?number > 1)>
	for i = 1 to ${dimensions?number}
		if bl.${a.componentName}.${a.attributeName}.set(i) then
									<#assign ar=protected.fillArrayField(a.attributeImplementation)>
									<#if a.attributeImplementation.column?exists && common.get_BaanDatatype_from_XMLSchemaDatatype(common.getMandatoryDatatype(a.attributeImplementation))=="DB.STRING">
			SET.DAL.FIELD${ar.arrayDEFSTR}(${tableName}.${col.name}, ${a.componentName}.${a.attributeName}, i)
									<#else>
			SET.DAL.FIELD${ar.arrayDEFLNG}(${tableName}.${col.name}, ${a.componentName}.${a.attributeName}, i)
									</#if><#--if a.attributeImplementation.column?exists && common.get_BaanDatatype_from_XMLSchemaDatatype(common.getMandatoryDatatype(a.attributeImplementation))=="DB.STRING"-->
		endif
	endfor
								<#else>
									<#assign ar=protected.fillArrayField(a.attributeImplementation)>
	if bl.${a.componentName}.${a.attributeName}.set then
		SET.DAL.FIELD${ar.arrayDEF}(${tableName}.${col.name}, ${a.componentName}.${a.attributeName}${ar.arrayOPT})
	endif
								</#if>
<#--TECH5785.so--
							</#if><#--if a?has_content-->
<#--TECH5785.eo-->
<#--TECH5785.sn-->
							</#list><#--list protected.getMultipleAttributeImplementationsLinkedToTableColumnByCit(c, componentImplementationTable, col.name) as a-->
<#--TECH5785.en-->
						</#if><#--if !col.isPrimaryKey-->
					</#list><#--list componentImplementationTable.table.idref.column as col-->
}

<#-- #VERS.o function ${c.componentName}.${componentImplementationTable.name}.setters.after.create.change() -->
<#-- #VERS.sn -->
function long ${c.componentName}.${componentImplementationTable.name}.setters.after.create.change()
<#-- #VERS.en -->
{
					<#-- For all attributes that are directly or indirectly linked to a table column,
						the attribute implementation is looked up. The code is generated for table
						identifiers first, then for other table fields.
					-->
	long	i
	i = 0
					<#list componentImplementationTable.table.idref.column as col>
<#--TECH5785.so--
							<#assign a = protected.getAttributeImplementationLinkedToTableColumnByCit(c, componentImplementationTable, col.name)>
							<#if a?has_content>
<#--TECH5785.eo-->
<#--TECH5785.sn-->
							<#list protected.getMultipleAttributeImplementationsLinkedToTableColumnByCit(c, componentImplementationTable, col.name) as a>
<#--TECH5785.en-->
<#-- #VERS.so
								<#assign ar=protected.fillArrayField(a.attributeImplementation)>
					    		<#assign dimensions=common.getDimensionsForDataType(common.getMandatoryDatatype(a.attributeImplementation))/>
					    		<#if (dimensions?number > 1)>
	for i = 1 to ${dimensions?number}
									<#if common.get_BaanDatatype_from_XMLSchemaDatatype(common.getMandatoryDatatype(a.attributeImplementation))=="DB.STRING">
		bl.${a.componentName}.${a.attributeName}(1,i) = ${tableName}.${col.name}(1,i)
									<#else>
		bl.${a.componentName}.${a.attributeName}(i) = ${tableName}.${col.name}(i)
									</#if><#--if common.get_BaanDatatype_from_XMLSchemaDatatype(common.getMandatoryDatatype(a.attributeImplementation))=="DB.STRING"- ->
		bl.${a.componentName}.${a.attributeName}.set(i) = true
	endfor
								<#else>
	bl.${a.componentName}.${a.attributeName} = ${tableName}.${col.name}${ar.arrayFLD}
	bl.${a.componentName}.${a.attributeName}.set = true
								</#if>
<#-- #VERS.eo -->
<#-- #VERS.sn -->
	RETIFNOK(assign.${c.componentName}.${a.attributeName}.from.column.${componentImplementationTable.name}())
<#-- #VERS.en -->
<#--TECH5785.so--
							</#if><#--if a?has_content-->
<#--TECH5785.eo-->
<#--TECH5785.sn-->
							</#list><#--list protected.getMultipleAttributeImplementationsLinkedToTableColumnByCit(c, componentImplementationTable, col.name) as a-->
<#--TECH5785.en-->
					</#list><#--list componentImplementationTable.table.idref.column as col-->
<#-- #VERS.sn -->
	return(0) | OK
<#-- #VERS.en -->
}

				</#if><#--!componentImplementationTable.isReferentialIntegrityTable &&
				          !protected.isFunctionServerComponent(c.componentImplementation)-->
	 		</#if><#--common.methodPresent("Create", c.componentImplementation) || common.methodPresent("Change", c.componentImplementation)-->
		</#if><#--table.type=="table"-->
	</#list><#--c.componentImplementation.componentImplementationTable as componentImplementationTable-->
</#list><#--protected.listProtectedComponents() as c-->

|****************************** Set derived attributes ***********************

| The following function is used by any non-batch method implementation.
| So either standard methods such as Create/Change/Delete or List/Show or
| specific methods.
<#--#TODO What about batch implementations? Must also be able to invoke such logic?-->

<#-- CHECK:
* function below is invoked from protected.st.methods.ftl (this ftl file) if:
	<#list protected.listProtectedComponents() as c>
		<#list c.componentImplementation.methodImplementation as methodImplementation>
			<#assign methodName = methodImplementation.method.idref.name>
			<#if !common.isQueryMethod(methodName) && !common.isPublishMethod(methodName) && !common.isEventMethod(methodName) &&
			     methodImplementation.processingOrder != "batch">
* function below is invoked from protected.st.query.ftl if:
	<#if common.queryMethodPresent()>
		<#assign MethName="List">
		<#if common.methodPresent(MethName)>
	and
	<#if common.queryMethodPresent()>
		<#assign MethName="Show">
		<#if common.methodPresent(MethName)>
  In this case the component name is unused; instead the businessInterfaceName is used.
  And note that common.queryMethodPresent() only returns true if List/Show are not batch methods with hooks.

So the combined condition is:
	<#list protected.listProtectedComponents() as c>
		<#list c.componentImplementation.methodImplementation as methodImplementation>
			<#assign methodName = methodImplementation.method.idref.name>
			<#if !common.isQueryMethod(methodName) && !common.isPublishMethod(methodName) && !common.isEventMethod(methodName) &&
			     methodImplementation.processingOrder != "batch">
			     OR common.isQueryMethod(methodName) and c.componentName == names.businessInterfaceName

So it seems we've got a mismatch if a publish or event method exists which is not batch:
in that case unused functions are generated. But no error occurs then?
-->

<#list protected.listProtectedComponents() as c>
	<#list c.componentImplementation.methodImplementation as methodImplementation>
		<#assign methodName = common.getNameFromMethodImplementation(methodImplementation)/>
		<#if methodImplementation.processingOrder != "batch"&&
		     protected.hasMethodAlternativeImplementation(methodName)=="">
			<#-- for the current List/Show implementation, only generate this for the top-level component -->
function 
long <@names.ST_DLLCode/>.${c.componentName}.${methodName}.set.derived()
{
	FunctionUsage
	This function is be called after setting the public input arguments for a method,
	before starting the actual execution.
	In other words, at the start of the before.execute... function.
	It sets the protected/private attribute implementations that are derived from the
	public input arguments.
	For example, public attributes A1, A2, A3 and A4 exist.
	Protected attributes having on set hooks are P1 (used attribute A2),
	P2 (used attribute P1), P3 (used attributes A2 and P4),
	P4 (used attributes P2 and A3) and P5 (no used attributes).
	Then the following logic is executed (sequence must take dependencies into account!):
	- set P5
	- If A2 is set then set P1
	- If P1 is set then set P2
	- If P2 is set or(!) A3 is set then set P4
	- If A2 is set or(!) P4 is set then set P3
	EndFunctionUsage
	<#--#TODO Where are default values handled? Must be set before set.derived!?!-->

	<#-- determine used protected/private attribute implementations for method and their dependencies-->
	<#assign dependencyList = protected.listAttributeImplementationsWithDependencies(c.componentName, methodName)/>
	<#list dependencyList as ai>
	<#assign aiAttributeName = common.getAttributeName(ai.attributeImplementation)/>
	domain ${common.getDatatypeFromAttributeImplementation(ai.attributeImplementation).nativeDatatype} dum.${aiAttributeName}
	</#list><#--dependencyList as ai-->
	long	i

	i = 0
	<#assign uaList = []>
	<#list dependencyList as ai>
	<#assign aiAttributeName = common.getAttributeName(ai.attributeImplementation)/>
	dum.${aiAttributeName}=${protected.getBaanDataInitializers(ai.attributeImplementation)}
	</#list><#--dependencyList as ai-->
	<#list dependencyList as ai>
	<#assign aiAttributeName = common.getAttributeName(ai.attributeImplementation)/>
		<#list ai.dependentFrom as ua>
			<#if ua!="">
				<#assign dimensions=common.getDimensionsForDataType(common.getMandatoryDatatype(ua))/>
				<#if (dimensions?number > 1)>
					<#assign uaAttributeName = common.getAttributeName(ua)>
					<#if !protected.containedIn(uaAttributeName, uaList)>
						<#assign uaList = uaList + [uaAttributeName]>
		boolean	bl.${c.componentName}.${uaAttributeName}.set.any
		bl.${c.componentName}.${uaAttributeName}.set.any = false
		for i = 1 to ${dimensions?number}
			if bl.${c.componentName}.${uaAttributeName}.set(i) then
				bl.${c.componentName}.${uaAttributeName}.set.any = true
			endif
		endfor
					</#if>
				</#if> 
			</#if>
		</#list><#--ai.dependentFrom as ua-->
		<#assign uaCounter = 0/>
		<#list ai.dependentFrom as ua>
			<#if ua!="">
				<#assign uaCounter = uaCounter + 1/>
				<#if uaCounter == 1>
	if 
					<#assign dimensions=common.getDimensionsForDataType(common.getMandatoryDatatype(ua))/>
					<#if (dimensions?number > 1)>
	 (  bl.${c.componentName}.${common.getAttributeName(ua)}.set.any
					<#else>
	 (  bl.${c.componentName}.${common.getAttributeName(ua)}.set
					</#if> 
				<#else>
					<#assign dimensions=common.getDimensionsForDataType(common.getMandatoryDatatype(ua))/>
					<#if (dimensions?number > 1)>
	or	bl.${c.componentName}.${common.getAttributeName(ua)}.set.any
					<#else>
	or  bl.${c.componentName}.${common.getAttributeName(ua)}.set
					</#if> 
				</#if>
			</#if>
		</#list><#--ai.dependentFrom as ua-->
		<#if uaCounter != 0>
			<#assign dimensions=common.getDimensionsForDataType(common.getMandatoryDatatype(ai.attributeImplementation))/>
			<#if (dimensions?number > 1)>
	)
	then
		long	${aiAttributeName}.counter
		boolean	tmp.${aiAttributeName}IsSet(${dimensions})
		domain ${common.getDatatypeFromAttributeImplementation(ai.attributeImplementation).nativeDatatype}	tmp.${aiAttributeName}(${dimensions})

		for ${aiAttributeName}.counter = 1 to ${dimensions}
			if bl.${c.componentName}.${aiAttributeName}.set(${aiAttributeName}.counter) then
				tmp.${aiAttributeName}IsSet(${aiAttributeName}.counter) = true
						<#if ai.attributeImplementation.column?exists && common.get_BaanDatatype_from_XMLSchemaDatatype(common.getMandatoryDatatype(ai.attributeImplementation))=="DB.STRING">
				tmp.${aiAttributeName}(1,${aiAttributeName}.counter) = bl.${c.componentName}.${aiAttributeName}(1,${aiAttributeName}.counter)
						<#else>
				tmp.${aiAttributeName}(${aiAttributeName}.counter) = bl.${c.componentName}.${aiAttributeName}(${aiAttributeName}.counter)
						</#if><#--if ai.attributeImplementation.column?exists && common.get_BaanDatatype_from_XMLSchemaDatatype(common.getMandatoryDatatype(ai.attributeImplementation))=="DB.STRING"-->
			else
				tmp.${aiAttributeName}IsSet(${aiAttributeName}.counter) = false
						<#if ai.attributeImplementation.column?exists>
							<#if common.get_BaanDatatype_from_XMLSchemaDatatype(common.getMandatoryDatatype(ai.attributeImplementation))=="DB.STRING">
				tmp.${aiAttributeName}(1,${aiAttributeName}.counter) = ${protected.getBaanDataInitializers(ai.attributeImplementation.column.idref)}
							<#else>
				tmp.${aiAttributeName}(${aiAttributeName}.counter) = ${protected.getBaanDataInitializers(ai.attributeImplementation.column.idref)}
							</#if><#--if common.get_BaanDatatype_from_XMLSchemaDatatype(common.getMandatoryDatatype(ai.attributeImplementation))=="DB.STRING"-->
						<#else>
							<#if common.get_BaanDatatype_from_XMLSchemaDatatype(common.getMandatoryDatatype(ai.attributeImplementation))=="DB.STRING">
				tmp.${aiAttributeName}(1, ${aiAttributeName}.counter) = 0 
							<#else>
				tmp.${aiAttributeName}(${aiAttributeName}.counter) = 0 
							</#if><#--if common.get_BaanDatatype_from_XMLSchemaDatatype(common.getMandatoryDatatype(ai.attributeImplementation))=="DB.STRING"-->
						</#if><#--if ai.attributeImplementation.column?exists-->
			endif
		endfor
		RETIFNOK(<@names.ST_DLLCode/>.set.${c.componentName}.${aiAttributeName}(tmp.${aiAttributeName}, tmp.${aiAttributeName}IsSet))
	endif
			<#else>
	) and not bl.${c.componentName}.${aiAttributeName}.set
	then
		<#-- Default values ?? -->
				<#assign defaultfound = false>
				<#list protected.listProtectedAttributes(methodName, c.componentName) as ap>
					<#if aiAttributeName == common.getAttributeName(ap.attributeImplementation)>
						<#assign defaultVal=protected.getDefaultValueFromMethodArgumentImplementation(ap.methodArgumentImplementation)>
						<#if defaultVal.present && defaultVal.dimensions==0><#-- no defaults for arrays-->
		dum.${aiAttributeName}=${defaultVal.value}
							<#assign defaultfound=true>
						</#if>
					</#if>
				</#list>
			<#if !defaultfound>
		dum.${aiAttributeName}=${protected.getBaanDataInitializers(ai.attributeImplementation)}<#-- use empty value for irrelevant input variable-->
			</#if>
		RETIFNOK(<@names.ST_DLLCode/>.set.${c.componentName}.${aiAttributeName}(dum.${aiAttributeName}))
	endif
			</#if>
		<#else>
		 		<#-- No condition: if no used attributes, always set if not yet done -->
			<#assign dimensions=common.getDimensionsForDataType(common.getMandatoryDatatype(ai.attributeImplementation))/>
			<#if (dimensions?number > 1)>
	long	${aiAttributeName}.counter
	boolean	tmp.${aiAttributeName}IsSet(${dimensions})
	domain ${common.getDatatypeFromAttributeImplementation(ai.attributeImplementation).nativeDatatype} tmp.${aiAttributeName}(${dimensions})

	for ${aiAttributeName}.counter = 1 to ${dimensions}
		if bl.${c.componentName}.${aiAttributeName}.set(${aiAttributeName}.counter) then
						<#if ai.attributeImplementation.column?exists && common.get_BaanDatatype_from_XMLSchemaDatatype(common.getMandatoryDatatype(ai.attributeImplementation))=="DB.STRING">
			tmp.${aiAttributeName}(1,${aiAttributeName}.counter) = bl.${c.componentName}.${aiAttributeName}(1,${aiAttributeName}.counter)
						<#else>
			tmp.${aiAttributeName}(${aiAttributeName}.counter) = bl.${c.componentName}.${aiAttributeName}(${aiAttributeName}.counter)
						</#if><#--if ai.attributeImplementation.column?exists && common.get_BaanDatatype_from_XMLSchemaDatatype(common.getMandatoryDatatype(ai.attributeImplementation))=="DB.STRING"-->
			tmp.${aiAttributeName}IsSet(${aiAttributeName}.counter) = true
		else
						<#if ai.attributeImplementation.column?exists>
							<#if common.get_BaanDatatype_from_XMLSchemaDatatype(common.getMandatoryDatatype(ai.attributeImplementation))=="DB.STRING">
			tmp.${aiAttributeName}(1,${aiAttributeName}.counter) = ${protected.getBaanDataInitializers(ai.attributeImplementation.column.idref)}
							<#else>
			tmp.${aiAttributeName}(${aiAttributeName}.counter) = ${protected.getBaanDataInitializers(ai.attributeImplementation.column.idref)}
							</#if><#--if common.get_BaanDatatype_from_XMLSchemaDatatype(common.getMandatoryDatatype(ai.attributeImplementation))=="DB.STRING"-->
						<#else>
							<#if common.get_BaanDatatype_from_XMLSchemaDatatype(common.getMandatoryDatatype(ai.attributeImplementation))=="DB.STRING">
			tmp.${aiAttributeName}(1,${aiAttributeName}.counter) = 0
							<#else>
			tmp.${aiAttributeName}(${aiAttributeName}.counter) = 0
							</#if><#--if common.get_BaanDatatype_from_XMLSchemaDatatype(common.getMandatoryDatatype(ai.attributeImplementation))=="DB.STRING"-->
						</#if><#--if ai.attributeImplementation.column?exists-->
			tmp.${aiAttributeName}IsSet(${aiAttributeName}.counter) = false
		endif
	endfor
	RETIFNOK(<@names.ST_DLLCode/>.set.${c.componentName}.${aiAttributeName}(tmp.${aiAttributeName}, tmp.${aiAttributeName}IsSet))
			<#else>
				<#if uaCounter == 0>
	if
				</#if>
	not bl.${c.componentName}.${aiAttributeName}.set
	then
				<#-- Default values ?? -->
				<#assign defaultfound = false>
				<#list protected.listProtectedAttributes(methodName, c.componentName) as ap>
					<#if aiAttributeName == common.getAttributeName(ap.attributeImplementation)>
						<#assign defaultVal=protected.getDefaultValueFromMethodArgumentImplementation(ap.methodArgumentImplementation)>
						<#if defaultVal.present && defaultVal.dimensions==0><#-- no defaults for arrays-->
		dum.${aiAttributeName}=${defaultVal.value}
							<#assign defaultfound=true>
						</#if>
					</#if>
				</#list>
			<#if !defaultfound>
		dum.${aiAttributeName}=${protected.getBaanDataInitializers(ai.attributeImplementation)}<#-- use empty value for irrelevant input variable-->
			</#if>
		RETIFNOK(<@names.ST_DLLCode/>.set.${c.componentName}.${aiAttributeName}(dum.${aiAttributeName}))
	endif
			</#if>
		</#if>
	</#list><#--dependencyList as ai-->
	return(0) | OK
}
		</#if><#--methodImplementation.processingOrder != "batch"-->
	</#list><#--c.componentImplementation.methodImplementation as methodImplementation-->
</#list><#--protected.listProtectedComponents() as c-->

|***************************** Private Functions ******************************

function clear.recent.DAL.error.messages()
{
	long	ret.bl
	string  MessageCode(25)
	string  MessageContent(256) mb
	long    MessageTypeCode

	while dal.count.messages(MSG.ALL) > bl.dal.nr.messages
		ret.bl = dal.get.last.message(MSG.ALL, MessageCode,
			MessageContent,
		   MessageTypeCode)
	endwhile
}

function set.current.number.of.DAL.messages()
{
	bl.dal.nr.messages = dal.count.messages(MSG.ALL)
}

<#--#dal-identifiers.sn-->
<#list protected.listProtectedComponents() as c>
function log.identifiers.DAL.message.${c.componentName}()
{
	| Because the application DAL does not always log all identifiers,
	| it would be difficult to determine which instance causes the
	| reported problem. Therefore, the identifiers are logged in this
	| function.
	<#assign first=true>
	<#list c.componentImplementation.attributeImplementation as ai>
		<#if common.getIsIdentifier(ai)>
			<#assign attributeName=common.getAttributeName(ai)>
			<#if first>
				<#if common.get_BaanDatatype_from_XMLSchemaDatatype(common.getMandatoryDatatype(ai))=="DB.STRING">
	dal.set.error.message("@Identifiers: ${attributeName}=" &
				trim$(bl.${c.componentName}.${attributeName})
				<#else>
	dal.set.error.message("@Identifiers: ${attributeName}=" &
				str$(bl.${c.componentName}.${attributeName})
				</#if>
				<#assign first=false>
			<#else>
				<#if common.get_BaanDatatype_from_XMLSchemaDatatype(common.getMandatoryDatatype(ai))=="DB.STRING">
		& ", ${attributeName}=" &
				trim$(bl.${c.componentName}.${attributeName})
				<#else>
		& ", ${attributeName}=" &
				str$(bl.${c.componentName}.${attributeName})
				</#if>
			</#if>
		</#if>
	</#list>
<#--#identifierfix.sn-->
	<#if first>
		<#--no identifiers defined!-->
		${logger.warn(object, "No identifying attributes defined for component '"+c.componentName+"'")}
	<#else>
	)
	</#if>
<#--#identifierfix.en-->
}

</#list>
<#--#dal-identifiers.en-->
function long handle.result(long i.result)
{

	string	e.message(256) mb
	string	mscode(12)

	if i.result = 0 then
		return (0)
	endif
	if i.result = 0 or
	   i.result = DALHOOKERROR or
	   i.result = DALDBERROR or
	   i.result = DALNOSETPERM or
	   i.result = DALNOOBJPERM then
		|* error message already present
		if i.result <> 0 then
			dal.set.info.message("tlbctstgen",
				strip$(bl.method), strip$(bl.component),
				strip$(bl.bodesc))
			|* Error occurred in Method '%1$s' on component '2$s'
			|* of Object '%3$s'
		endif
		return(i.result)
	endif

	e.message = ""
<#if protected.generateFunctionServer()>
	if not isspace(bl.afs.session) then
		|* AFS controlled BO/Comp do error handling somewhere else
		RETIFNOK(handle.result.AFS(i.result))
	endif
</#if><#--if protected.generateFunctionServer()-->
	if i.result > 0 then
		|* get errormessage by messcode tlbcterrX
		mscode = "tlbcterr" & str$(i.result)
		e.message = sprintf$(form.text$(mscode),
					strip$(bl.method), strip$(bl.object))
	endif

	if i.result > 0 and pos(e.message, "???") = 0 then
		dal.set.error.message(mscode,
				bl.method, strip$(bl.object))
	else
		e.message = db.error.message()
		if isspace(e.message) then
			dal.set.error.message("tlbcts0021",
						strip$(bl.method),
						strip$(bl.object),
						i.result)
			|* Method '%1$s', Object '%2$s':
			|* error-code: %3$d ( Error description not present )
			tlbct.dll1000.log(__FILE__, __LINE__,
				sprintf$(form.text$("tlbcts0004"),
	 						i.result))
			|* Error description not present (code: %1$d).
		else
			dal.set.error.message("@" & e.message)
			dal.set.info.message("tlbctstgen",
				strip$(bl.method), strip$(bl.component),
				strip$(bl.bodesc))
			|* Error occurred in Method '%1$s' on component '2$s'
			|* of Object '%3$s'
		endif
	endif
	return(i.result)
}
