| ictAPMAtchingTcRowid | input | character | icAPMatchingTcRowid: TcRowid of the APMatching record. Mandatory |
| tSPTAPMatchingLn | input-output | temp-table | Temp-table holding the Lines of the matching |
| tSPTAPMatchingLnTax | input-output | temp-table | Temp-table holding the Taxes of the Lines of the matching |
| tSPTAPMatchingLnWHT | input-output | temp-table | |
| oiReturnStatus | output | integer | Return status of the method. |
/* ============================================================================================================ */
/* This method is implemented in order to improve the performance: */
/* At the moment 'Save' is pressed on the UI - that only supports maintaining a single APMatching at the time , */
/* the normal approach would be that for every new record in APMatchingLn, APMatchingLnTax or APMatchingLnWHT, */
/* a call to the BL is made to actualy create the record in the instance-data (eg method CreateAPMatchingLnTax) */
/* This method receives the datasets from the UI for assigning the IDs and tc_status fields into it */
/* Note these records are only created at the moment the APMatching gets saved. */
/* ============================================================================================================ */
/* Making a single all from UI to BL for every APMatchingLn and every underlying record is far less performing */
/* than making a single call from UI to BL and doing all logic at once. This however implies that all required */
/* data from the UI is passed to BL and back again (so the UI holds the updated data). */
/* This data that comes from the UI and is send back to the UI is contained in the parameter-temp-tables of */
/* this method whose name all starts with 'tSPTAPMatchingLn'. */
/* ============================================================================================================ */
/* Some info on the input: */
/* TEMP-TABLE tSPTAPMatchingLn */
/* (this temp-table doesn't hold any deleted records, only the unchanged, changed and new ones): */
/* If tc_status = N */
/* then APMatching_ID and APMatchingLn_ID are empty */
/* tc_ParentRowid is empty */
/* tc_Rowid has an artibrary value */
/* If tc_status = C */
/* then APMatching_ID, APMatchingLn_ID, tc_ParentRowid and tc_Rowid are properly filled */
/* TEMP-TABLE tSPTAPMatchingLnTax (and the same for WHT): */
/* (this temp-table doesn't hold any deleted or changed records, only unchanged and new ones): */
/* If tc_status = N */
/* then APMatching_ID, APMatchingLn_ID and APMatchingLnTax_ID are empty */
/* tc_ParentRowid is filled with a value of a tSPTAPMatchingLn.tc_Rowid */
/* tc_Rowid has an artibrary value */
/* If tc_status = "" */
/* then APMatching_ID, APMatchingLn_ID and APMatchingLnTax_ID are properly filled */
/* tc_ParentRowid is filled with a value of a tSPTAPMatchingLn.tc_Rowid */
/* tc_Rowid is properly filled */
/* ============================================================================================================ */
/* ================== */
/* Exception handling */
/* ================== */
assign oiReturnStatus = -98
viLocalReturnStatus = 0.
/* ===================== */
/* Main processing block */
/* ===================== */
MAIN_BLOCK:
do on error undo, leave MAIN_BLOCK:
/* ================================================== */
/* 0. Verify the correctness of the parameters passed */
/* ================================================== */
if ictAPMatchingTcRowid = "":U or
ictAPMatchingTcRowid = ?
then do:
assign vcMsgAPMatching = trim(substitute(#T-19'Internal error: the system cannot find the matching as the internal row-ID is empty.':255(516794138)T-19#))
viLocalReturnStatus = -3.
<M-6 run SetMessage
(input vcMsgAPMatching (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-234853':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
leave MAIN_BLOCK.
end. /* if not available tAPMatching */
find tAPMatching where
tAPMatching.tc_Rowid = ictAPMatchingTcRowid
no-lock no-error.
if not available tAPMatching
then do:
assign vcMsgAPMatching = trim(substitute(#T-96'Internal error: the system cannot find the matching based upon the internal row-ID (&1)':230(270897944)T-96#,ictAPMatchingTcRowid))
viLocalReturnStatus = -3.
<M-15 run SetMessage
(input vcMsgAPMatching (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-570623':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
leave MAIN_BLOCK.
end. /* if not available tAPMatching */
/* ===================================================================================================================================== */
/* 1. Loop through the all tSPTAPMatchingLn and: */
/* - run AddDetailLine for it in case of new-mode (tc_ParentRowid is empty and tc_status = N) */
/* - run AddDetailLine for its underlying (tSPTAPMatchingLnTax and tSPTAPMatchingLnWHT) records as well */
/* The functional content of the tSPT-records is copied into the t-records and after that the t-records are copied into the tSPT-records */
/* ===================================================================================================================================== */
repeat preselect each tSPTAPMatchingLn :
find next tSPTAPMatchingLn.
/* ============================================================= */
/* Actions for new tSPTAPMatchingLn: Create a new tAPMatchingLn */
/* Check on tc_status and tc_ParentRowid to see if its a new one */
/* ============================================================= */
if tSPTAPMatchingLn.tc_status = "N":U and
(tSPTAPMatchingLn.tc_ParentRowid = "":U or
tSPTAPMatchingLn.tc_ParentRowid = ?)
then do :
<M-27 run AddDetailLine
(input 'APMatchingLn':U (icTable),
input tAPMatching.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
if viFcReturnSuper < 0 or
(viFcReturnSuper > 0 and
viLocalReturnStatus = 0)
then assign viLocalReturnStatus = viFcReturnSuper.
if viLocalReturnStatus < 0
then leave MAIN_BLOCK.
end. /* if tSPTAPMatchingLn.tc_status = "N":U and */
/* ========================================================= */
/* Actions for changed Lines: Find the tAPMatchingLn */
/* Check on tc_status to see if its a changed one */
/* ========================================================= */
if tSPTAPMatchingLn.tc_status = "C":U and
tSPTAPMatchingLn.tc_rowid <> "":U and
tSPTAPMatchingLn.tc_rowid <> ?
then do :
find tAPMatchingLn where
tAPMatchingLn.tc_rowid = tSPTAPMatchingLn.tc_rowid
no-lock no-error.
if not available tAPMatchingLn
then do :
assign vcMsgAPMatching = trim(substitute(#T-11'Internal error: the system cannot find the matching-line based upon the internal row-ID (&1)':255(848355533)T-11#,tSPTAPMatchingLn.tc_rowid))
viLocalReturnStatus = -3.
<M-66 run SetMessage
(input vcMsgAPMatching (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-764570':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
leave MAIN_BLOCK.
end. /* if not available tAPMatchingLn */
end. /* if tSPTAPMatchingLn.tc_status = "C":U and */
/* ====================================================================================================================== */
/* By now we should always have a tAPMatchingLn record available - if not then just go to the next iteration of this loop */
/* ====================================================================================================================== */
if not available tAPMatchingLn
then next.
/* ============================================================== */
/* Copy functional content of tSPTAPMatchingLn into tAPMatchingLn */
/* ============================================================== */
buffer-copy tSPTAPMatchingLn
except tc_RowId tc_ParentRowId tc_status APMatchingLn_ID APMatching_ID
to tAPMatchingLn.
/* ============================================================================================================= */
/* Go trough all the tSPTAPMatchingLnTax linked to the tSPTAPMatchingLn and create a new tAPMatchingLnTax for it */
/* Do exactly the same for APMatchingLnWHT as for APMatchingLnTax */
/* ============================================================================================================= */
for each tSPTAPMatchingLnTax where
tSPTAPMatchingLnTax.tc_parentRowid = tSPTAPMatchingLn.tc_rowid and
tSPTAPMatchingLnTax.tc_Status = "N":U:
<M-1 run AddDetailLine
(input 'APMatchingLnTax':U (icTable),
input tAPMatchingLn.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
if viFcReturnSuper < 0 or
(viFcReturnSuper > 0 and
viLocalReturnStatus = 0)
then assign viLocalReturnStatus = viFcReturnSuper.
if viLocalReturnStatus < 0 then
leave MAIN_BLOCK.
/* Copy functional content of tSPTAPMatchingLnTax into tAPMatchingLnTax */
buffer-copy tSPTAPMatchingLnTax
except tc_RowId tc_ParentRowId tc_Status APMatchingLn_ID APMatchingLnTax_ID APMatching_ID
to tAPMatchingLnTax.
/* Copy complete content of tAPMatchingLnTax into tSPTAPMatchingLnTax */
buffer-copy tAPMatchingLnTax
to tSPTAPMatchingLnTax.
end. /* for each tSPTAPMatchingLnTax */
for each tSPTAPMatchingLnWHT where
tSPTAPMatchingLnWHT.tc_parentRowid = tSPTAPMatchingLn.tc_rowid and
tSPTAPMatchingLnWHT.tc_Status = "N":U:
<M-52 run AddDetailLine
(input 'APMatchingLnWHT':U (icTable),
input tAPMatchingLn.tc_rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
if viFcReturnSuper < 0 or
(viFcReturnSuper > 0 and
viLocalReturnStatus = 0)
then assign viLocalReturnStatus = viFcReturnSuper.
if viLocalReturnStatus < 0
then leave MAIN_BLOCK.
/* Copy functional content of tSPTAPMatchingLnWHT into tAPMatchingLnWHT */
buffer-copy tSPTAPMatchingLnWHT
except tc_RowId tc_ParentRowId tc_status APMatchingLn_ID APMatching_ID APMatchingLnWHT_ID
to tAPMatchingLnWHT.
/* Copy complete content of tAPMatchingLnWHT into tSPTAPMatchingLnWHT */
buffer-copy tAPMatchingLnWHT
to tSPTAPMatchingLnWHT.
end. /*for each tSPTAPMatchingLnWHT */
/* ============================================================ */
/* Copy complete content of tAPMatchingLn into tSPTAPMatchingLn */
/* ============================================================ */
buffer-copy tAPMatchingLn
to tSPTAPMatchingLn.
end. /* for each tSPTAPMatchingLn : */
/* ====================================================================================== */
/* 2. Now delete tAPMatchingLn records that are not in tSPTAPMatchingLn and do the same */
/* for the underlying records on APMatchingLnTax and APMatchingLnWHT */
/* As the content of the records that exist both in tAPMatchingLn and tSPTAPMatchingLn is */
/* the same, we can now simply use relations based upon tc_Rowid and tc_parentRowid. */
/* The same applies to the underlying tables. */
/* ====================================================================================== */
for each tAPMatchingLn where
tAPMatchingLn.tc_ParentRowid = tAPMatching.tc_Rowid :
/* ========================================================================= */
/* The tAPMatchingLn needs to be deleted (together with its underlying data) */
/* ========================================================================= */
if not can-find (tSPTAPMatchingLn where
tSPTAPMatchingLn.tc_Rowid = tAPMatchingLn.tc_Rowid)
then do :
/* Actions when tAPMatchingLn is in create mode */
if tAPMatchingLn.tc_Status = "N":U
then do:
for each tAPMatchingLnTax where
tAPMatchingLnTax.tc_ParentRowid = tAPMatchingLn.tc_Rowid:
delete tAPMatchingLnTax.
end. /* for each tAPMatchingLnTax */
for each tAPMatchingLnWHT where
tAPMatchingLnWHT.tc_ParentRowid = tAPMatchingLn.tc_Rowid:
delete tAPMatchingLnWHT.
end. /* for each tAPMatchingLnWHT */
delete tAPMatchingLn.
next.
end. /* if tAPMatchingLn.tc_Status = "N":U */
/* Actions when tAPMatchingLn is in modify mode */
if tAPMatchingLn.tc_Status = "C":U
then do:
for each tAPMatchingLnTax where
tAPMatchingLnTax.tc_ParentRowid = tAPMatchingLn.tc_Rowid:
assign tAPMatchingLnTax.tc_Status = "D":U.
end. /* for each tAPMatchingLnTax */
for each tAPMatchingLnWHT where
tAPMatchingLnWHT.tc_ParentRowid = tAPMatchingLn.tc_Rowid:
assign tAPMatchingLnWHT.tc_Status = "D":U.
end. /* for each tAPMatchingLnWHT */
assign tAPMatchingLn.tc_Status = "D":U.
next.
end. /* if tAPMatchingLn.tc_Status = "C":U */
end. /* if not can-find (first tSPTAPMatchingLn where */
/* ===================================================================================================== */
/* If tAPMatchingLn has not yet been deleted or marked as deleted then delete the underlying records in */
/* APMatchingLnTax and APMatchingLnWHT that are in the t-temp-table but no longer in the tSPT-temp-table */
/* ===================================================================================================== */
if available tAPMatchingLn and
tAPMatchingLn.tc_Status <> "D":U
then do :
for each tAPMatchingLnTax where
tAPMatchingLnTax.tc_ParentRowid = tAPMatchingLn.tc_Rowid:
if not can-find (tSPTAPMatchingLnTax where
tSPTAPMatchingLnTax.tc_Rowid = tAPMatchingLnTax.tc_Rowid)
then do :
if tAPMatchingLnTax.tc_Status = "N":U
then delete tAPMatchingLnTax.
else assign tAPMatchingLnTax.tc_Status = "D":U.
end. /* if not can-find (tSPTAPMatchingLnTax where */
end. /* for each tAPMatchingLnTax where */
for each tAPMatchingLnWHT where
tAPMatchingLnWHT.tc_ParentRowid = tAPMatchingLn.tc_Rowid:
if not can-find (tSPTAPMatchingLnWHT where
tSPTAPMatchingLnWHT.tc_Rowid = tAPMatchingLnWHT.tc_Rowid)
then do :
if tAPMatchingLnWHT.tc_Status = "N":U
then delete tAPMatchingLnWHT.
else assign tAPMatchingLnWHT.tc_Status = "D":U.
end. /* if not can-find (tSPTAPMatchingLnWHT where */
end. /* for each tAPMatchingLnWHT where */
end. /* if available tAPMatchingLn and */
end. /* 2. for each tAPMatchingLn where */
END. /* MAIN_BLOCK */
/* ================== */
/* Exception handling */
/* ================== */
assign oiReturnStatus = viLocalReturnStatus.