Description
Write here all tests on database update (new / modify / delete) that cannot be coded with a validation mask.
The type of update can be found in tc_status (N/C/D).
If you find incorrect data, you must write an entry in tFcMessages (using SetMessage) and set the return status of this method to either +1 or -1.
Return status +1 = data will still be accepted.
Return status -1 = data will not be accepted.
This method is run from SetPublicTables, before transferring the received data into the class temp-tables.
Validations:
run StopExternalInstances
run ValidateBusinessKey
Ancestor Code
Check if Rounding Method was changed
Parameters
| oiReturnStatus | output | integer | |
Internal usage
unused
program code (program/bcurrency.p)
<M-6 run StopExternalInstances (output viFcReturnSuper (oiReturnStatus)) in BCurrency>
for each t_sCurrency where
t_sCurrency.tc_Status <>'D':U and
(t_sCurrency.CurrencyCode <> ? and
t_sCurrency.CurrencyCode <> "":U):
assign t_sCurrency.CurrencyCode = trim(t_sCurrency.CurrencyCode).
end.
<M-1 run ValidateBusinessKey (output viFcReturnSuper (oiReturnStatus)) in BCurrency>
if(viFcReturnSuper < 0) then do:
oiReturnStatus = viFcReturnSuper.
return.
end.
<ANCESTOR-CODE>
assign viLocalReturnStatus = oiReturnStatus
oiReturnStatus = -98.
/* ==================================== */
/* Check if Rounding Method was changed */
/* ==================================== */
for each t_sCurrency where
(t_sCurrency.tc_Status = 'N':U or
t_sCurrency.tc_Status = 'C':U):
assign vlCalculateNumberOfDecimals = (t_sCurrency.tc_Status = 'N':U)
vdOldRoundingUnit = 0
vdNewRoundingUnit = 0.
if t_sCurrency.tc_Status = 'C':U
then do:
find t_iCurrency where
t_iCurrency.tc_Rowid = t_sCurrency.tc_Rowid
no-lock no-error.
if available t_iCurrency and
t_iCurrency.RoundingMethod_ID <> t_sCurrency.RoundingMethod_ID
then do:
/* Get the Initial Rounding Method */
<Q-43 run RoundingMethodPrim (all) (Read) (NoCache)
(input t_iCurrency.RoundingMethod_ID, (RoundingMethodID)
input t_iCurrency.tcRoundingMethodCode, (RoundingMethodCode)
output dataset tqRoundingMethodPrim) in BRoundingMethod>
find tqRoundingMethodPrim where
tqRoundingMethodPrim.tiRoundingMethod_ID = t_iCurrency.RoundingMethod_ID and
tqRoundingMethodPrim.tcRoundingMethodCode = t_iCurrency.tcRoundingMethodCode
no-error.
if available tqRoundingMethodPrim
then assign vdOldRoundingUnit = tqRoundingMethodPrim.tdRoundingMethodUnit.
/* Get the New Rounding Method */
<Q-35 run RoundingMethodPrim (all) (Read) (NoCache)
(input t_sCurrency.RoundingMethod_ID, (RoundingMethodID)
input t_sCurrency.tcRoundingMethodCode, (RoundingMethodCode)
output dataset tqRoundingMethodPrim) in BRoundingMethod>
find tqRoundingMethodPrim where
tqRoundingMethodPrim.tiRoundingMethod_ID = t_sCurrency.RoundingMethod_ID and
tqRoundingMethodPrim.tcRoundingMethodCode = t_sCurrency.tcRoundingMethodCode
no-error.
if available tqRoundingMethodPrim
then assign vdNewRoundingUnit = tqRoundingMethodPrim.tdRoundingMethodUnit.
/* If the Rounding Method changed raise some information or error */
if t_iCurrency.RoundingMethod_ID <> 0 and
t_iCurrency.RoundingMethod_ID <> ? and
t_iCurrency.RoundingMethod_ID <> t_sCurrency.RoundingMethod_ID
then do:
if vdNewRoundingUnit > vdOldRoundingUnit
then do:
assign viLocalReturnStatus = -1
vcMessage = #T-78'Change to Rounding Method not allowed. Rounding Method can be increased, but not decreased':255(194716143)T-78# + chr(10) +
trim(substitute(#T-85'Old rounding method was &1. New rounding method is &2':255(539975030)T-85#, t_iCurrency.tcRoundingMethodCode, t_sCurrency.tcRoundingMethodCode)).
<M-47 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'tCurrency.tcRoundingMethodCode':U (icFieldName),
input t_sCurrency.tcRoundingMethodCode (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sCurrency.tc_Rowid (icRowid),
input 'qadfin-903855':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCurrency>
end. /* if vdNewRoundingUnit > vdOldRoundingUnit */
else do:
assign vcMessage = #T-36'Changing the rounding method may result in different rounding logic between existing amounts and future amounts':255(128011009)T-36# + chr(10) +
trim(substitute(#T-81'Old rounding method was &1. New rounding method is &2.':100(861104013)T-81#, t_iCurrency.tcRoundingMethodCode, t_sCurrency.tcRoundingMethodCode))
viLocalReturnStatus = 1
vlCalculateNumberOfDecimals = true.
<M-90 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'tCurrency.tcRoundingMethodCode':U (icFieldName),
input t_sCurrency.tcRoundingMethodCode (icFieldValue),
input 'W':U (icType),
input 3 (iiSeverity),
input t_sCurrency.tc_Rowid (icRowid),
input 'qadfin-691049':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCurrency>
end. /* else do */
end. /* if t_iCurrency.RoundingMethod_ID <> 0 and */
end. /* if available t_iCurrency ... */
end. /* if t_sCurrency.tc_Status = 'C' ... */
if vlCalculateNumberOfDecimals
then do:
<Q-7 run RoundingMethodPrim (all) (Read) (NoCache)
(input t_sCurrency.RoundingMethod_ID, (RoundingMethodID)
input ?, (RoundingMethodCode)
output dataset tqRoundingMethodPrim) in BRoundingMethod >
for first tqRoundingMethodPrim:
assign vhFcComponent = ?.
<M-8 run CalculateNumberOfDecimals
(input tqRoundingMethodPrim.tdRoundingMethodUnit (idRoundingMethodUnit),
output t_sCurrency.CurrencyNumberOfDecimals (odNumberOfDecimals),
output viFcReturnSuper (oiReturnStatus)) in BRoundingMethod>
end. /* for first tqRoundingMethodPrim: */
end. /* if vlCalculateNumberOfDecimals */
/* Extra validation to check if CurrencyNumberOfDecimals is set */
if t_sCurrency.CurrencyNumberOfDecimals = ?
then do:
assign vcMessage = trim (substitute(#T-66'The number of decimals for the currency '&1' is not specified yet. The rounding method linked is '&2'.':255(123512835)T-66#,t_sCurrency.CurrencyCode,t_sCurrency.tcRoundingMethodCode))
viLocalReturnStatus = -1.
<M-14 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'tCurrency.CurrencyNumberOfDecimals' (icFieldName),
input string (t_sCurrency.CurrencyNumberOfDecimals) (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sCurrency.tc_Rowid (icRowid),
input 'qadfin-195089':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCurrency>
end.
end. /* for each t_sCurrency where... */
assign oiReturnStatus = viLocalReturnStatus.