Examples

The following figure gives an example that contains a one-to-one, a one-to-many and a many-to-one relationship for attributes and table columns.

Note: In the LN Business Object Repository (BOR), the predecessor of the on set hook was not linked to the attribute being set, but to the attribute that also had the on get hook. This is different in the LN Studio.

The mapping between the attributes and table columns can be as follows:

Set Get
stringColumn = aString(4) aString = “ERP_” & stringColumn
calculateInternalAmountColumn1(anAmount, amountColumn1); calculateInternalAmountColumn2(anAmount, amountColumn2) calculateExternalAmount(amountColumn1, amountColumn2, anAmount)
determineInternalCode(code1, code2, codeColumn) determineExternalCode1(codeColumn, code1); determineExternalCode2(codeColumn, code2)

Since we have got two separate on set hooks for amountColumn1 and amountColumn2, reuse of existing library functions has a drawback. For example, assume we have got an existing function calculateInternalAmounts(anAmount, amountColumn1, amountColumn2), we can use it from both the amountColumn1 on set hook and the amountColumn2 on set hook. But note that it will be executed twice if anAmount is set and consequently amountColumn1 and amountColumn2 are set.

For the example in the previous figure, the hooks are as follows:

On Get hook for aString:

| add prefix “ERP_”
o.aString = “ERP_” & i.stringColumn
return(0) | OK

Note that it is not needed to check whether stringColumn is set or not. If the model is OK, stringColumn is listed as a used attribute for the calculation, so the standard mechanism will take care that the required attribute is set. This also is the case for the following hooks:

On Set hook for stringColumn:

| remove prefix “…_”, for example “ERP_”; prefix will always be 3 characters plus underscore
if len(strip$(i.aString) < 4 then
	dal.set.error.message(“ppmmms1234.01”, i.aString)
	|* Component.aString %s does not have the required prefix (such as “ERP_”)
	return(DALHOOKERROR)
else
	o.stringColumn = i.aString(4)
	return(0) | OK
endif

On Get hook for anAmount:

#pragma used dll oppmmmamounts
| library ppmmmamount contains:
| function long ppmmmamount.calculateExternalAmount(
|				double		i.amountColumn1,
|				double		i.amountColumn2,
|		ref		double		o.anAmount)

long	retl		| return value to be checked

retl = ppmmmamount.calculateExternalAmount(i.amountColumn1, i.amountColumn2, 
											o.anAmount)
if retl <> 0 then
	dal.set.error.message(“ppmmms1234.02”, i.amountColumn1, i.amountColumn2)
	|* Cannot calculate Component.anAmount for amountColumn1 = %f and amountColumn2 = %f
	return(DALHOOKERROR)
else
	return(0) | OK
endif

On Set hook for amountColumn1:

#pragma used dll oppmmmamounts
| library ppmmmamount contains:
| function long ppmmmamount.calculateInternalAmountamountColumn1(
|				double		i.anAmount,
|		ref		double		o.amountColumn1)

long	retl		| return value to be checked

retl = ppmmmamount.calculateInternalAmountamountColumn1(i.anAmount, 
												o.amountColumn1)
if retl <> 0 then
	dal.set.error.message(“ppmmms1234.03”, i.anAmount)
	|* Cannot calculate Component.amountColumn1 for anAmount = %f
	return(DALHOOKERROR)
else
	return(0) | OK
endif

On Set hook for amountColumn2:

#pragma used dll oppmmmamounts
| library ppmmmamount contains:
| function long ppmmmamount.calculateInternalAmountamountColumn2(
|				double		i.anAmount,
|		ref		double		o.amountColumn2)

long	retl		| return value to be checked

retl = ppmmmamount.calculateInternalAmountamountColumn2(i.anAmount, 
												o.amountColumn2)
if retl <> 0 then
	dal.set.error.message(“ppmmms1234.04”, i.anAmount)
	|* Cannot calculate Component.amountColumn2 for anAmount = %f
	return(DALHOOKERROR)
else
	return(0) | OK
endif

On Get hook for code1:

#pragma used dll oppmmmcoding

long	retl		| return value to be checked

retl = ppmmmcoding.determineExternalCode1(i.codeColumn, o.code1)
if retl <> 0 then
	dal.set.error.message(“ppmmms1234.05”, i.codeColumn)
	|* Cannot determine Component.code1 for codeColumn = %s
	return(DALHOOKERROR)
else
	return(0) | OK
endif

On Get hook for code2:

#pragma used dll oppmmmcoding

long	retl		| return value to be checked

retl = ppmmmcoding.determineExternalCode2(i.codeColumn, o.code2)
if retl <> 0 then
	dal.set.error.message(“ppmmms1234.06”, i.codeColumn)
	|* Cannot determine Component.code2 for codeColumn = %s
	return(DALHOOKERROR)
else
	return(0) | OK
endif

On Set hook for codeColumn:

#pragma used dll oppmmmcoding

long	retl		| return value to be checked

retl = ppmmmcoding.determineInternalCode(i.code1, i.code2, o.codeColumn)
if retl <> 0 then
	dal.set.error.message(“ppmmms1234.07”, i.code1, i.code2)
	|* Cannot determine Component.codeColumn for code1 = %s and 4 = %s
	return(DALHOOKERROR)
else
	return(0) | OK
endif