Receiving a BOD
To be able to receive a Sync BOD, a public OnSync method is modeled. This method is implemented on the top-level component, using processing scope ‘batch’. Additionally protected methods Create, Change and Delete are available.
Assuming the implementation identifier is ppmmm123, the on execute hook for the OnSync method contains the following code:
| Important: this is a hypothetical example for an OnSync hook,
| for educational purposes only.
| If is not necessarily a realistic, optimal or advised implementation.
table tppmmm123 | orders
domain ppmmm.docu document.id | first identifying attribute
domain ppmmm.revi revision.id | second identifying attribute
domain ppmmm.docu dum.doc.id | dummy variable to avoid change of record buffer
string action.code(20) | action to be done, either “add”, “change” or “delete” or
| empty/missing
long ret.method | return value from business object method
long ret.exec | return value from exec_dll_function
#define EXEC_METHOD_AND_RETURN(method_name)
^ | we must dynamically invoke methods to avoid a dependency loop
^ | between public and protected library.
^ ret.exec = exec_dll_function(“oppmmmbl123sb00”,
^ “ppmmm.bl123sb00.##method_name##”,
^ ret.method, i.request, o.response, o.result)
^ if retl.exec <> 0 then
^ dal.set.error.message(“ppmmm.0003”, “##method_name##”)
^ |* Unable to handle incoming Sync message because method %s is
^ |* missing in OrderBOD
^ return(DALHOOKERROR)
^ else
^ return(ret.method) | either 0 (OK) or DALHOOKERROR
^ endif
if not getControlAttribute(“actionCode”, action.code) then
| no problem, action.code is empty
endif
if strip$(tolower$(action.code)) = “delete” then
| invoke Delete method
EXEC_METHOD_AND_RETURN(Delete)
else
| action code is ‘Add’, ‘Change’ or undefined;
| determine required action based on existence of object instance
| get identifying values
if not getAttributeValueFromRequest(i.request,
“OrderBOD. Header.ID.DocumentID”, document.id)
then
dal.set.error.message(“ppmmm.0001”)
|* Incoming Sync message does not contain DocumentID
return(DALHOOKERROR)
endif
if not getAttributeValueFromRequest(i.request,
“OrderBOD. Header.ID.RevisionID”, revision.id)
then
| no problem; assuming revision id can be empty
endif
| check existence of order
select ppmmm123.docu:dum.doc.id
from ppmmm123
where ppmmm123.docu = :document.id and ppmmm123.revi = :revision.id
as set with 1 rows
selectdo
| order already exists; invoke Change method
EXEC_METHOD_AND_RETURN(Change)
selectempty
| order does not exist; invoke Create method
EXEC_METHOD_AND_RETURN(Create)
endselect
| we must not get here…
dal.set.error.message(“ppmmm.0002”, document.id, revision.id)
|* Error reading order ‘%s-%s’ from the database
return(DALHOOKERROR)
endif
A simplified example for the on execute hook of an OnProcess method (again a ‘batch’ implementation), to illustrate the setting of the actionCode, which makes sure that an Acknowledge BOD is sent in reply:
| Important: this is a hypothetical example for an OnProcess hook,
| for educational purposes only.
| If is not necessarily a realistic, optimal or advised implementation.
long ret.method | return value from business object method
long ret.exec | return value from exec_dll_function
| we will dynamically invoke the Create method to avoid a dependency loop
| between public and protected library.
ret.exec = exec_dll_function(“oppmmmbl123sb00”, “ppmmm.bl123sb00.Create”,
ret.method, i.request, o.response, o.result)
if retl.exec <> 0 then
dal.set.error.message(“ppmmm.0004”)
|* Unable to handle incoming Process message because Create method is missing
|* in OrderBOD
return(DALHOOKERROR)
else
if ret.method <> 0 then
dal.set.error.message(“ppmmm.0005”)
|* Unable to handle incoming Process message because Create method in
|* OrderBOD returned an error
return(DALHOOKERROR)
else
if not setControlAttributeInResponse(o.response, "actionCode", "Modified") then
dal.set.error.message(“ppmmm.0006”)
|* Cannot set actionCode; unable to send Acknowledge reply for incoming
|* Process message
return(DALHOOKERROR)
else
return(0) | OK
endif
endif
endif