Parameters
| oiNumberOfValidatedRecords | output | integer | Number of validated records |
| olEof | output | logical | |
| oiReturnStatus | output | integer | Return status of the method. |
Internal usage
unused
program code (program6/bsharedsetmerge.p)
/* =================================================================================================== */
/* Method : MergeValidateCompare */
/* STEP 5 */
/* Desc : This method compares sorted content of two shared sets (stored in two temporary */
/* tables). Method reports missing records and also differences of definitions of */
/* coresponding records */
/* =================================================================================================== */
assign oiReturnStatus = -98
viLocalReturn = 0.
MAIN_BLOCK:
do:
/* =================================================================================================== */
/* Initial values */
/* =================================================================================================== */
assign olEof = false.
/* =================================================================================================== */
/* Find records in resulting data table */
/* =================================================================================================== */
find bSharedSetMergeValResTotal where
bSharedSetMergeValResTotal.tcInfoType = {&SHAREDSETMERGE-INFOTYPE-TOTAL} no-error.
find bSharedSetMergeValResMiss where
bSharedSetMergeValResMiss.tcInfoType = {&SHAREDSETMERGE-INFOTYPE-MISS} no-error.
if not available bSharedSetMergeValResTotal or
not available bSharedSetMergeValResMiss
then do:
assign vcMessage = #T-88'Cannot find mandatory records in resulting dataset.':255(16669284)T-88#
vcContext = 'available bSharedSetMergeValResTotal=&1|available bSharedSetMergeValResMiss=&2':U
vcContext = substitute(vcContext, available bSharedSetMergeValResTotal, available bSharedSetMergeValResMiss)
vcContext = replace(vcContext, '|':U, chr(2)).
<M-20 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'S':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-475108':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input vcContext (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BSharedSetMerge>
assign viLocalReturn = -1.
leave MAIN_BLOCK.
end.
/* =================================================================================================== *
* Make query to go through all data in one shared set table *
* =================================================================================================== */
if not valid-handle(vhMasterQuery)
then do:
assign vhBuffer = vhMergeValidateTableQuery:get-buffer-handle(vhMergeValidateTableQuery:num-buffers)
viIndex = integer(vhBuffer::tc_Rowid)
vcParentTableName = vhBuffer::tcParentTableName
vhMasterTable = vhMasterSharedSetData[viIndex]
vhRedundantTable = vhRedundantSharedSetData[viIndex]
vlIsReportMissingRecords = false
vhParentTable = ?.
if vcParentTableName <> ?
then do:
find bParentMergeValidateTable where
bParentMergeValidateTable.tcTableName = vcParentTableName no-error.
if not available bParentMergeValidateTable
then do:
assign vcMessage = #T-84'Cannot find parent record in tMergeValidateTable for table with name &1.':255(64085)T-84#
vcMessage = substitute(vcMessage, vcParentTableName).
<M-28 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'S':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-638048':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BSharedSetMerge>
assign viLocalReturn = -1.
leave MAIN_BLOCK.
end.
assign viIndex = integer(bParentMergeValidateTable.tc_Rowid)
vhParentTable = vhRedundantSharedSetData[viIndex]
vlIsReportMissingRecords = true.
end.
/* =================================================================================================== */
/* Construct query for browsing through all records in compared shered set */
/* =================================================================================================== */
if vhParentTable <> ?
then do:
/* go throuth all records from parent table */
assign vcParentTableQuery = substitute('for each &1':U, vhParentTable:name).
/* construct part of query for relation */
assign vcRelation = '':U.
for each tMergeValidateField where
tMergeValidateField.tc_ParentRowid = vhBuffer::tc_Rowid and
tMergeValidateField.tiMergeType = {&SHAREDSETMERGE-FIELDTYPE-KEY}:
if vcRelation <> '':U
then assign vcRelation = vcRelation + ' and ':U.
assign vcRelation = substitute('&1.&2 = &3.&4':U,
vhMasterTable:name,
tMergeValidateField.tcFieldName,
vhParentTable:name,
tMergeValidateField.tcFieldName).
end.
/* construct whole query */
assign vcQuery = substitute('&1, each &2 where &3':U,
vcParentTableQuery,
vhMasterTable:name,
vcRelation).
end.
else assign vcQuery = substitute('for each &1':U, vhMasterTable:name).
/* create queries to browse through */
create query vhMasterQuery in widget-pool "non-persistent".
if vhParentTable <> ? then vhMasterQuery:add-buffer(vhParentTable:default-buffer-handle).
vhMasterQuery:add-buffer(vhMasterTable:default-buffer-handle).
vhMasterQuery:query-prepare(vcQuery).
vhMasterQuery:query-open().
vhMasterQuery:get-first().
create query vhRedundantQuery in widget-pool "non-persistent".
if vhParentTable <> ? then vhRedundantQuery:add-buffer(vhParentTable:default-buffer-handle).
vhRedundantQuery:add-buffer(vhRedundantTable:default-buffer-handle).
vhRedundantQuery:query-prepare(vcQuery).
vhRedundantQuery:query-open().
vhRedundantQuery:get-first().
end.
/* =================================================================================================== */
/* Go throuch data of the shared set and compare them */
/* =================================================================================================== */
assign viStartTime = time
vlIsTimeElapsed = false.
do while not vhMasterQuery:query-off-end or
not vhRedundantQuery:query-off-end:
/* =============================================================================================== */
/* Calculate time in seconds elapsed from start of validation (in sec) */
/* =============================================================================================== */
assign viNowTime = time
viElapsedTime = (if viNowTime >= viStartTime
then viNowTime - viStartTime
else viNowTime + 24 * 60 * 60 - viStartTime).
if viElapsedTime > 60
then do:
assign vlIsTimeElapsed = true.
leave.
end.
/* In case redundant element should be deleted only, no any comparison is required */
if tMergeValidateTable.tlDeleteRedundantOnly
then do:
/* Increase counter with total number of the records */
assign bSharedSetMergeValResTotal.tiInfoValue = bSharedSetMergeValResTotal.tiInfoValue + 1.
/* go to the next record in redundant shared set */
vhRedundantQuery:get-next().
/* go to the next record in redundant shared set */
next.
end.
/* Compare, whether we have cursor on the same records */
assign viCompareResult = <M-12 MergeValidateCompareKeys
(input tMergeValidateTable.tcTableName (icTableName),
input vhMasterQuery (ihQuery1),
input vhRedundantQuery (ihQuery2),
output vcKeyValue (ocKeyValue)) in BSharedSetMerge>.
case viCompareResult:
when -1 /* master record is lower then redundant -> missing in source record */
then do:
if vlIsReportMissingRecords
then do:
assign bSharedSetMergeValResMiss.tiInfoValue = bSharedSetMergeValResMiss.tiInfoValue + 1.
/* create details about missing record */
if vlIsReportDetails
then do:
create tSharedSetMergeValResMis.
assign viValidateResultDetailCount = viValidateResultDetailCount + 1
tSharedSetMergeValResMis.tcTableName = tMergeValidateTable.tcTableName
tSharedSetMergeValResMis.tcKeyValue = vcKeyValue
tSharedSetMergeValResMis.tcMissingIn = dynamic-function ('GetTranslation':U in {&TARGETPROCEDURE}, 733717823, 'QadFin':U, 'Source Shared Set')
tSharedSetMergeValResMis.tc_Rowid = string(viValidateResultDetailCount)
tSharedSetMergeValResMis.tc_ParentRowid = bSharedSetMergeValResMiss.tc_Rowid.
end.
end. /* if ilIsReportMissingRecords */
else if vhParentTable = ?
then assign bSharedSetMergeValResTotal.tiInfoValue = bSharedSetMergeValResTotal.tiInfoValue + 1.
/* go the the next record in master shared set */
vhMasterQuery:get-next().
end.
when 0 /* master record is the same as redundant */
then do:
/* Increase counter with total number of the records */
if vhParentTable = ?
then assign bSharedSetMergeValResTotal.tiInfoValue = bSharedSetMergeValResTotal.tiInfoValue + 1.
/* compare values of fields */
<M-31 run MergeValidateCompareFields
(input vhMasterQuery (ihQueryMaster),
input vhRedundantQuery (ihQueryRedundant),
input vlIsReportDetails (ilIsReportDetails),
input vcKeyValue (icKeyValue),
output vlIsContainError (olIsContainError),
output vlIsContainWarning (olIsContainWarning),
output viFcReturnSuper (oiReturnStatus)) in BSharedSetMerge>
if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
if viLocalReturn < 0 then leave MAIN_BLOCK.
if vhParentTable = ?
then do:
/* when there is warning, records get merge, but values of result element is different with */
/* values of redundant element -> this leads to repplication of merged (master) element to Mfg */
if vlIsReportChangedElements and
vlIsContainWarning
then do:
assign viMasterObjectId = <M-52 MergeValidateGetId
(input vhMasterQuery (ihQuery)) in BSharedSetMerge>.
if not can-find (first tSharedSetMergeChangedElem where
tSharedSetMergeChangedElem.tiMasterObjectId = viMasterObjectId)
then do:
create tSharedSetMergeChangedElem.
assign tSharedSetMergeChangedElem.tiMasterObjectId = viMasterObjectId.
end.
end.
/* validate profile data linkeed to this element */
<M-73 run MergeValidateCompareProfileData
(input vcKeyValue (icKeyValue),
input vlIsReportDetails (ilIsReportDetails),
output viFcReturnSuper (oiReturnStatus)) in BSharedSetMerge>
if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
if viLocalReturn < 0 then leave MAIN_BLOCK.
end.
/* go to the next record in master and redundant */
vhMasterQuery:get-next().
vhRedundantQuery:get-next().
end.
when 1 /* master record is greater then redundant -> missing in Target SS */
then do:
assign bSharedSetMergeValResMiss.tiInfoValue = bSharedSetMergeValResMiss.tiInfoValue + 1.
/* create details about missing master record */
if vlIsReportDetails
then do:
create tSharedSetMergeValResMis.
assign viValidateResultDetailCount = viValidateResultDetailCount + 1
tSharedSetMergeValResMis.tcTableName = tMergeValidateTable.tcTableName
tSharedSetMergeValResMis.tcKeyValue = vcKeyValue
tSharedSetMergeValResMis.tcMissingIn = #T-40'Target Shared Set':255(73437899)T-40#
tSharedSetMergeValResMis.tc_Rowid = string(viValidateResultDetailCount)
tSharedSetMergeValResMis.tc_ParentRowid = bSharedSetMergeValResMiss.tc_Rowid.
end.
/* go to the next record in redundant shared set */
vhRedundantQuery:get-next().
end.
end case.
end. /* end of do while not vhMasterQuery:query-off-end or */
if not vlIsTimeElapsed and
vhMasterQuery:query-off-end and
vhRedundantQuery:query-off-end
then do:
/* relaease queries */
vhMasterQuery:query-close().
vhRedundantQuery:query-close().
delete object vhMasterQuery.
delete object vhRedundantQuery.
assign vhMasterQuery = ?
vhRedundantQuery = ?.
/* Go to the next table to be validated */
vhMergeValidateTableQuery:get-next().
/* if all tables were validated - stop */
if vhMergeValidateTableQuery:query-off-end
then assign olEof = true.
end.
end. /* of MAIN_BLOCK */
/* =================================================================================================== */
/* Return */
/* =================================================================================================== */
assign oiNumberOfValidatedRecords = bSharedSetMergeValResTotal.tiInfoValue
oiReturnStatus = viLocalReturn.