/* update-block */
for each ttcustomer where ttcustomer. found:
----
UpdateBLOCK:
DO TRANSACTION ON ERROR UNDO UpdateBLOCK, RETRY UpdateBLOCK:
if retry - then do:
---
end.
hCustomer:FIND-FIRST (SUBSTITUTE ('WHERE Customer.CustomerId = &1', ttCustomer.CustomerId ), EXCLUSIVE-LOCK) NO-ERROR.
---
FOR LAST bEmailRec NO-LOCK
WHERE bEmailRec.CustomerId = hCustomer:BUFFER-FIELD ('CustomerId'):BUFFER-VALUE:
iRecPtr = bEmailRec.RecPtr.
END.
---
EMAIL-BLOCK:
FOR EACH ttEmailRec
WHERE ttEmailRec.CustomerId = ttCustomer.CustomerId
AND NOT ttEmailRec.ErrorFlag
BREAK BY ttEmailRec.CustomerId: /* why break-by ? - probably for the LAST( ), but won't hurt, only a small table for 1 customer*/
------
RUN Create-CustomerEmail
(INPUT-OUTPUT iRecPtr,
INPUT-OUTPUT bCustomer.MainEmailRecPtr,
INPUT bCustomer.CustomerId,
INPUT ttEmailRec.EmailAddress,
INPUT ttEmailRec.Description,
INPUT {fn getuserId},
INPUT bImportHeader.DataSourceId,
INPUT LAST (ttEmailRec.CustomerId),
BUFFER bEmailRec,
OUTPUT po-lSuccess,
OUTPUT po-cError).
IF NOT lSuccess THEN
UNDO update-block, RETRY update-block.
----
END.
-----
END.
/* create-block */
for each ttcustomer where not ttcustomer.found:
----
NEWBLOCK:
DO TRANSACTION ON ERROR UNDO NEWBLOCK, RETRY NEWBLOCK:
if retry - then do:
-- undo, leave ...
end.
---
FOR EACH ttEmailRec
WHERE ttEmailRec.CustomerId = ttCustomer.CustomerId
AND NOT ttEmailRec.ErrorFlag
BREAK BY ttEmailRec.CustomerId: /* same break-by again */
----
----
/* Create batch when first-of etc */
----
EMAIL-BLOCK:
RUN Create-CustomerEmail
(INPUT-OUTPUT iRecPtr,
INPUT-OUTPUT bCustomer.MainEmailRecPtr,
INPUT bCustomer.CustomerId,
INPUT ttEmailRec.EmailAddress,
INPUT ttEmailRec.Description,
INPUT {fn getuserId},
INPUT bImportHeader.DataSourceId,
INPUT LAST (ttEmailRec.CustomerId),
BUFFER bEmailRec,
OUTPUT po-lSuccess,
OUTPUT po-cError).
IF NOT lSuccess THEN
UNDO create-block, RETRY create-block.
----
END.
----
end.