Description
Loads or creates records of BankNumber table based on t_sBankNumberRef table
Parameters
Internal usage
QadFinancials
program code (program1/bbanknumber.p)
for each t_sBankNumberRef: /*where
t_sBankNumberRef.tc_Status <> "":U:*/
/*find tBankNumber of t_sBankNumberRef no-error.*/
find first tBankNumber where
tBankNumber.BankNumber_ID = t_sBankNumberRef.BankNumber_ID no-error.
if not available tBankNumber
then do:
/* load the existing record */
if t_sBankNumberRef.tc_Status <> "N":U
then Load_Block: do:
assign vlRunCalculate = false.
<M-1 run DataLoad
(input '':U (icRowids),
input string(t_sBankNumberRef.BankNumber_ID) (icPkeys),
input '':U (icObjectIds),
input '' (icFreeform),
input true (ilKeepPrevious),
output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
/*JBA: it can happen that somebody else in another session deleted the record
I can still see in my session (returnStatus -4)
In that case I will act as if this record was newly added (tc_Status = "N")*/
if viFcReturnSuper = -4
then do:
assign t_sBankNumberRef.tc_Status = "N":U.
leave Load_Block.
end.
if viFcReturnSuper <> 0 and
viFcReturnSuper <> -4
then do:
assign oiReturnStatus = viFcReturnSuper.
return.
end.
end. /* load the existing record */
/*JBA: create a new record
this is in fact an 'else' part of the previous 'if' statement but as I assign
the tc_Status to "N" in there I have to use another 'if' statement in here*/
if t_sBankNumberRef.tc_Status = "N":U
then do:
<M-4 run AddDetailLine (input 'BankNumber':U (icTable),
input '':U (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
return.
end.
/*as in the SetBankNumberPayCode I work with this new tBankNumber.BankNumber_Id
I have to rewrite all the t_sBankNumberPayCodeRef.BankNumber_Id linked to this BankNumber*/
for each t_sBankNumberPayCodeRef where
t_sBankNumberPayCodeRef.tc_ParentRowid = t_sBankNumberRef.tc_Rowid:
assign t_sBankNumberPayCodeRef.BankNumber_Id = tBankNumber.BankNumber_ID.
end.
/* We also need to rewrite the ID held in the t_sBankNumberSectionRef table... */
for each t_sBankNumberSectionRef
where t_sBankNumberSectionRef.tiBankNumber_ID = t_sBankNumberRef.BankNumber_ID:
assign t_sBankNumberSectionRef.tiBankNumber_ID = t_sBankNumberRef.BankNumber_ID.
end.
end. /* create */
/*JBA 02/03/2005 ignore all the records created and deleted afterwards*/
if t_sBankNumberRef.tc_Status = "D":U and
not can-find (first tBankNumber where
tBankNumber.BankNumber_ID = t_sBankNumberRef.BankNumber_ID)
then next.
/*find first tBankNumber*/
if not available tBankNumber
then find first tBankNumber where
tBankNumber.BankNumber_ID = t_sBankNumberRef.BankNumber_ID no-error.
if not available tBankNumber
then do:
/* error handling */
assign oiReturnStatus = -1
vcMessage = trim(substitute(#T-7'&1 not available.':200(406)t-7#, "tBankNumber":U)) + chr(10) +
program-name(1).
<M-6 run SetMessage (input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'D':U (icType),
input 2 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-1203':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
return.
end.
end.
if t_sBankNumberRef.tc_Status = "D":U
then assign tBankNumber.tc_Status = "D":U.
else buffer-copy t_sBankNumberRef except BankNumber_ID tc_Rowid tc_ParentRowid to tBankNumber.
end. /* for each */
/* Now we need to go through all bank numbers not being deleted.
Even if the number itself is unchanged, the sections might be... */
for each tBankNumber
where tBankNumber.tc_Status <> "D":U:
if tBankNumber.BankNumberIsBankCharge = ? then assign tBankNumber.BankNumberIsBankCharge = no.
/* See if there's a new/deleted/changed section... */
find first t_sBankNumberSectionRef
where t_sBankNumberSectionRef.tc_ParentRowid = tBankNumber.tc_Rowid
and t_sBankNumberSectionRef.tc_Status <> "":U no-error.
if not available t_sBankNumberSectionRef then next.
/* In this next part, we reconstruct the bank number from the passed in bank number sections... */
assign vcBankNumberFromSections = "":U.
for each t_sBankNumberSectionRef
where t_sBankNumberSectionRef.tc_ParentRowid = tBankNumber.tc_Rowid
by t_sBankNumberSectionRef.tiBankAccFormatSectSequence:
/* Verify that the section is not blank if mandatory... */
if t_sBankNumberSectionRef.tlBankAccFormatSectIsMandat
and (
t_sBankNumberSectionRef.tcSectionValue = "":U
or t_sBankNumberSectionRef.tcSectionValue = ?
) then do:
assign vcMessage =
substitute(
#T-13'Bank Number Section (&1) is mandatory, but blank.':200(70763)T-13#,
t_sBankNumberSectionRef.tcBankAccFormatSectLabel
).
<M-12 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sBankNumberSectionRef.tc_Rowid (icRowid),
input 'QadFin-6339':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
end.
/* Verify that the section does not exceed it's maximum length... */
if length(t_sBankNumberSectionRef.tcSectionValue, "CHARACTER":U)
> t_sBankNumberSectionRef.tiBankAccFormatSectLength then do:
assign vcMessage =
substitute(
#T-11'Bank Number Section (&1) has a value of (&2) which exceeds the maximum length of &3':200(70764)T-11#,
t_sBankNumberSectionRef.tcBankAccFormatSectLabel,
t_sBankNumberSectionRef.tcSectionValue,
t_sBankNumberSectionRef.tiBankAccFormatSectLength
).
<M-10 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sBankNumberSectionRef.tc_Rowid (icRowid),
input 'QadFin-6338':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
end.
/* Add the section to the bank number... */
assign vcBankNumberFromSections = vcBankNumberFromSections
+ ( /* It may be necessary to pad out the section with leading zeros... */
if t_sBankNumberSectionRef.tlBankAccFormatSectIsLdZero then
fill("0":U,
minimum(
0,
t_sBankNumberSectionRef.tiBankAccFormatSectLength
- length(t_sBankNumberSectionRef.tcSectionValue, "CHARACTER":U)
)
)
else
"":U
)
+ t_sBankNumberSectionRef.tcSectionValue.
end. /* for each t_sBankNumberSectionRef */
if tBankNumber.BankNumber <> vcBankNumberFromSections then
assign
tBankNumber.BankNumber = vcBankNumberFromSections
tBankNumber.tc_Status = "C":U when tBankNumber.tc_Status = "":U.
end. /* for each tBankNumber */