Description
When looking for an address of some type, a fallback mechanisme will be programmed:
for instance, when looking for a Reminder address, first the system looks if there is a reminder address. If that is not found, the program will look for an HeadOffice adress which is always there.
Parameters
iiBusinessRelationId | input | integer | Business Relation ID |
icBusinessRelationCode | input | character | Business Relation Code |
iiAddressTypeId | input | integer | Address Type ID |
icAddressTypeCode | input | character | Address Type Code |
tAddressQuery | output | temp-table | All address information composed by query information |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program3/bbusinessrelation.p)
empty temp-table tAddressQuery.
/* ==================================================== */
/* Skip Unknown-values and Convert the Code into the ID */
/* Filled but non-existing code -> Error */
/* ==================================================== */
if icAddressTypeCode = ? then assign icAddressTypeCode = "":U.
if iiAddressTypeId = ? then assign iiAddressTypeId = 0.
if icBusinessRelationCode = ? then assign icBusinessRelationCode = "":U.
if iiBusinessRelationId = ? then assign iiBusinessRelationId = 0.
/* ========================================================================= */
/* give an error when the id and the code of the Address Type are not filled */
/* => not necessary, if not filled then we search for the headoffice address */
/* ========================================================================= */
if iiAddressTypeId = 0 and icAddressTypeCode = "":U
then assign icAddressTypeCode = {&ADDRESSTYPECODESYSTEM-HEADOFFICE}.
/* =============================================================================== */
/* give an error when the id and the code of the Business Relation are not filled */
/* => not necessary, you can get all delivery addresses for all business relations */
/* probably we not use it, but it should be possible */
/* =============================================================================== */
/* ====================================================== */
/* Reset the code-parameter if the ID-parameter is filled */
/* ====================================================== */
if iiAddressTypeId <> 0 then assign icAddressTypeCode = "":U.
if iiBusinessRelationId <> 0 then assign icBusinessRelationCode = "":U.
/* =============================================== */
/* search the address with the giving address type */
/* if not found, search the head office address */
/* => must always exist */
/* =============================================== */
<Q-2 assign vlFcQueryRecordsAvailable = AddressByAddressBusRelType (NoCache)
(input iiAddressTypeId, (AddressTypeId)
input (if iiAddressTypeId = 0 then icAddressTypeCode else '':U), (AddressTypeCode)
input iiBusinessRelationId, (BusinessRelationId)
input (if iiBusinessRelationId = 0 then icBusinessRelationCode else '':U), (BusinessRelationCode)
input ?, (AddressId)) in BBusinessRelation >
if vlFcQueryRecordsAvailable
then do:
<Q-3 run AddressByAddressBusRelType (first) (Read) (NoCache)
(input iiAddressTypeId, (AddressTypeId)
input (if iiAddressTypeId = 0 then icAddressTypeCode else '':U), (AddressTypeCode)
input iiBusinessRelationId, (BusinessRelationId)
input (if iiBusinessRelationId = 0 then icBusinessRelationCode else '':U), (BusinessRelationCode)
input ?, (AddressId)
output dataset tqAddressByAddressBusRelType) in BBusinessRelation >
end.
else do:
/* ============================== */
/* search the head office address */
/* ============================== */
<Q-4 run AddressByAddressBusRelType (first) (Read) (NoCache)
(input ?, (AddressTypeId)
input 'HEADOFFICE':U, (AddressTypeCode)
input iiBusinessRelationId, (BusinessRelationId)
input (if iiBusinessRelationId = 0 then icBusinessRelationCode else '':U), (BusinessRelationCode)
input ?, (AddressId)
output dataset tqAddressByAddressBusRelType) in BBusinessRelation >
end.
find first tqAddressByAddressBusRelType
no-lock no-error.
if available tqAddressByAddressBusRelType
then buffer-copy tqAddressByAddressBusRelType to tAddressQuery.