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.
Parameters
oiReturnStatus | output | integer | |
Internal usage
unused
program code (program/bsafstructure.p)
assign vllinkCheck = false.
<M-11 run PreValidateComponent (output viPreValidateStatus (oiReturnStatus)) in BSafStructure>
<ANCESTOR-CODE>
assign oiReturnStatus = if (oiReturnStatus > 0 and
viPreValidateStatus = 0) or
oiReturnStatus < 0
then oiReturnStatus
else viPreValidateStatus.
/*go through all SafStructure records not only N/C/D for there can be a SafStructureLine in N/C/D status*/
for each t_sSafStructure:
/* Validate that deactivated SAF structure is not associated with an
active GL, cost center or project (open project) */
if(t_sSafStructure.tc_Status = "C":U and not t_sSafStructure.SafStructureIsActive) then do:
/* Note that check existence version of query returns ? if multiple records are
found. This requires checks that value is not ? and not false. */
<Q-49 run GetGLLinkForSafStructure (all) (Read) (NoCache)
(input t_sSafStructure.SafStructure_ID, (SafStructureId)
input true, (GLIsActive)
input ?, (CompanyId)
output dataset tqGetGLLinkForSafStructure) in BSafStructureLink >
find first tqGetGLLinkForSafStructure where
tqGetGLLinkForSafStructure.tiSafStructure_ID = t_sSafStructure.SafStructure_ID and
tqGetGLLinkForSafStructure.tlGLIsActive = true no-error.
if not available tqGetGLLinkForSafStructure
then do:
<Q-50 run GetCCLinkForSafStructure (all) (Read) (NoCache)
(input t_sSafStructure.SafStructure_ID, (SafStructureId)
input true, (CostCentreIsActive)
input ?, (CompanyId)
output dataset tqGetCCLinkForSafStructure) in BSafStructureLink >
find first tqGetCCLinkForSafStructure where
tqGetCCLinkForSafStructure.tiSafStructure_ID = t_sSafStructure.SafStructure_ID and
tqGetCCLinkForSafStructure.tlCostCentreIsActive = true no-error.
if not available tqGetCCLinkForSafStructure
then do:
<Q-51 run GetProjectLinkForSafStructure (all) (Read) (NoCache)
(input t_sSafStructure.SafStructure_ID, (SafStructureId)
input 'OPEN':U, (ProjectCode)
input ?, (CompanyId)
output dataset tqGetProjectLinkForSafStructure) in BSafStructureLink >
find first tqGetProjectLinkForSafStructure where
tqGetProjectLinkForSafStructure.tiSafStructure_ID = t_sSafStructure.SafStructure_ID and
tqGetProjectLinkForSafStructure.tcProjectStatusCode = 'OPEN':U no-error.
if available tqGetProjectLinkForSafStructure
then do:
assign vllinkCheck = true
vcMessage = subst(#T-52'You cannot deactivate a SAF structure if it is linked to an active project &1.':255(73430084)T-52#, tqGetProjectLinkForSafStructure.tcProjectCode).
end.
end.
else do:
assign vllinkCheck = true
vcMessage = subst(#T-53'You cannot deactivate a SAF structure if it is linked to an active cost center &1.':255(413922367)T-53#, tqGetCCLinkForSafStructure.tcCostCentreCode).
end.
end.
else do:
assign vllinkCheck = true
vcMessage = subst(#T-54'You cannot deactivate a SAF structure if it is linked to an active GL &1.':255(591251319)T-54#, tqGetGLLinkForSafStructure.tcGLCode).
end.
if (vllinkCheck <> false) then do:
assign oiReturnStatus = -1.
<M-42 run SetMessage
(input vcMessage (icMessage),
input '' (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'QadFin-4987':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BSafStructure>
return.
end.
end.
if t_sSafStructure.tc_Status <> "N":U
then do:
find first tFcRowidConvert where
tFcRowidConvert.tcFcOldRowid = t_sSafStructure.tc_Rowid no-error.
if available tFcRowidConvert
then find first t_iSafStructure where
t_iSafStructure.tc_Rowid = tFcRowidConvert.tcFcNewRowid no-error.
else find first t_iSafStructure where
t_iSafStructure.tc_Rowid = t_sSafStructure.tc_Rowid no-error.
if not available t_iSafStructure and
t_sSafStructure.tc_Status <> "D":U
then do:
assign vcMessage = "t_iSafStructure not available.":U + chr(10) + program-name(1)
oiReturnStatus = -1.
<M-1 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'D':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-6':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BSafStructure>
return.
end.
end.
/*check whether the SafStructure is already used somewhere*/
if t_sSafStructure.SafStructure_ID = 0 or
t_sSafStructure.SafStructure_ID = ? or
t_sSafStructure.tc_Status = "N":U
then assign vlIsSafStructureReferenced = false.
else assign vlIsSafStructureReferenced = <M-15 GetSafStructureIsReferenced
(input t_sSafStructure.SafStructure_ID (iiSafStructureId),
output viFcReturnSuper (oiReturnStatus)) in BSafStructure>.
/*Warning: SafStructure changed active -> inactive*/
if available t_iSafStructure and
t_iSafStructure.SafStructureIsActive = true and
t_sSafStructure.SafStructureIsActive = false and
t_sSafStructure.tc_Status = "C":U and
vlIsSafStructureReferenced
then do:
assign vcMessage = trim(substitute (#T-23'The SAF structure &1 you want to make inactive is already linked to other object(s).':200(3655)T-23#, t_sSafStructure.SafStructureCode))
+ chr(10) + program-name(1)
oiReturnStatus = if oiReturnStatus < 0
then oiReturnStatus
else 1.
<M-7 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'tSafStructure.SafStructureIsActive':U (icFieldName),
input string(t_sSafStructure.SafStructureIsActive) (icFieldValue),
input 'W':U (icType),
input 3 (iiSeverity),
input t_sSafStructure.tc_Rowid (icRowid),
input 'QADFIN-8':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BSafStructure>
end.
/*Error: SafStructure deleted (should be DB restriction)*/
if available t_iSafStructure and
t_sSafStructure.tc_Status = "D":U and
vlIsSafStructureReferenced
then do:
assign vcMessage = trim(substitute (#T-24'Cannot delete SAF structure &1. The SAF structure is already linked to other object(s).':200(3656)T-24#, t_sSafStructure.SafStructureCode))
+ chr(10) + program-name(1)
oiReturnStatus = if oiReturnStatus < 0
then oiReturnStatus
else -1.
<M-9 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'D':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-11':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BSafStructure>
end.
/*JBA 21/04/2005 we have to go through all lines (not only N, C and D ones)
as one of the checks below is checking whether the sequence starts with number 1*/
assign viLastSeq = 0
viFirstSeq = 5.
for each t_sSafStructureLine where
t_sSafStructureLine.tc_ParentRowid = t_sSafStructure.tc_Rowid /*and
t_sSafStructureLine.tc_Status <> "":U*/
break by t_sSafStructureLine.SafStructure_ID
by t_sSafStructureLine.SafStructureLineNumber:
if t_sSafStructureLine.tc_Status <> "N":U
then do:
find first tFcRowidConvert where
tFcRowidConvert.tcFcOldRowid = t_sSafStructureLine.tc_Rowid no-error.
if available tFcRowidConvert
then find first t_iSafStructureLine where
t_iSafStructureLine.tc_Rowid = tFcRowidConvert.tcFcNewRowid no-error.
else find first t_iSafStructureLine where
t_iSafStructureLine.tc_Rowid = t_sSafStructureLine.tc_Rowid no-error.
if not available t_iSafStructureLine and
t_sSafStructureLine.tc_Status <> "D":U
then do:
assign vcMessage = "t_iSafStructureLine not available.":U + " ":U +
trim(substitute(#T-25'(SAF Structure &1, Line Sequence &2)':200(3657)T-25#,
t_sSafStructure.SafStructureCode,
string(t_sSafStructureLine.SafStructureLineNumber))) + chr(10) +
program-name(1)
oiReturnStatus = -1.
<M-2 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'D':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-7':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BSafStructure>
return.
end.
end.
/*keep the first sequence number of the saf structure*/
if t_sSafStructureLine.tc_Status <> "D":U and
t_sSafStructureLine.SafStructureLineNumber < viFirstSeq
then assign viFirstSeq = t_sSafStructureLine.SafStructureLineNumber.
/*keep the last sequence number of the saf structure, max 5*/
if t_sSafStructureLine.tc_Status <> "D":U and
t_sSafStructureLine.SafStructureLineNumber > viLastSeq and
t_sSafStructureLine.SafStructureLineNumber <= 5
then assign viLastSeq = t_sSafStructureLine.SafStructureLineNumber.
/*Error: line sequence only from 1 to 5*/
if t_sSafStructureLine.tc_Status <> "D":U and
(t_sSafStructureLine.SafStructureLineNumber < 1 or
t_sSafStructureLine.SafStructureLineNumber > 5)
then do:
assign vcMessage = trim(#T-26'The line number is out of range.':200(3658)T-26#) + " ":U +
trim(#T-27'You have to enter a number between 1 and 5.':200(3659)T-27#) + " ":U +
trim(substitute(#T-28'(SAF Structure &1, Line Sequence &2)':200(3657)T-28#,
t_sSafStructure.SafStructureCode,
string(t_sSafStructureLine.SafStructureLineNumber))) + chr(10) +
program-name(1)
oiReturnStatus = -1.
<M-18 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'tSafStructureLine.SafStructureLineNumber':U (icFieldName),
input string(t_sSafStructureLine.SafStructureLineNumber) (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sSafStructureLine.tc_Rowid (icRowid),
input 'QADFIN-1777':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BSafStructure>
end.
/*Error: SafStructureLine.SafStructureLineNumber and SafConcept_ID changed*/
if available t_iSafStructureLine and
(t_sSafStructureLine.SafStructureLineNumber <> t_iSafStructureLine.SafStructureLineNumber or
t_sSafStructureLine.SafConcept_ID <> t_iSafStructureLine.SafConcept_ID) and
t_sSafStructureLine.tc_Status = "C":U and
vlIsSafStructureReferenced
then do:
assign vcMessage = trim(substitute (#T-29'Cannot modify the SAF structure line &1. This SAF structure line is already linked to other object(s).':200(3660)T-29#, t_sSafStructure.SafStructureCode))
+ chr(10) + program-name(1)
oiReturnStatus = if oiReturnStatus < 0
then oiReturnStatus
else -1.
if t_sSafStructureLine.SafStructureLineNumber <> t_iSafStructureLine.SafStructureLineNumber
then do:
<M-8 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'tSafStructureLine.SafStructureLineNumber':U (icFieldName),
input string(t_sSafStructureLine.SafStructureLineNumber) (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sSafStructureLine.tc_Rowid (icRowid),
input 'QADFIN-9':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BSafStructure>
end.
if t_sSafStructureLine.SafConcept_ID <> t_iSafStructureLine.SafConcept_ID
then do:
<M-16 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'tSafStructureLine.tcSafConceptCode':U (icFieldName),
input t_sSafStructureLine.tcSafConceptCode (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sSafStructureLine.tc_Rowid (icRowid),
input 'QADFIN-1666':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BSafStructure>
end.
end.
/*Error: SafStructureLine deleted
in case the SafStructure is deleted as a whole, then this should be validated by the Delete constraint of SAFSTRUCTUREINSAFSTRUCTURELINK relation*/
if available t_iSafStructureLine and
t_sSafStructureLine.tc_Status = "D":U and
vlIsSafStructureReferenced
then do:
assign vcMessage = trim(substitute (#T-30'Cannot delete SAF structure line. The SAF structure &1 is already linked to other object(s).':200(3661)T-30#, t_sSafStructure.SafStructureCode))
+ chr(10) + program-name(1)
oiReturnStatus = if oiReturnStatus < 0
then oiReturnStatus
else -1.
<M-10 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'tSafStructureLine.SafStructureLineNumber':U (icFieldName),
input string(t_sSafStructureLine.SafStructureLineNumber) (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sSafStructureLine.tc_Rowid (icRowid),
input 'QADFIN-10':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BSafStructure>
end.
/*Error: SafStructureLine added
SafStructureLine can't be added if the SafStructure is already used*/
if t_sSafStructureLine.tc_Status = "N":U and
vlIsSafStructureReferenced
then do:
assign vcMessage = trim(substitute (#T-31'Cannot add the SAF structure line. The SAF structure line &1 is already linked to other object(s).':200(3662)T-31#, t_sSafStructure.SafStructureCode))
+ chr(10) + program-name(1)
oiReturnStatus = if oiReturnStatus < 0
then oiReturnStatus
else -1.
<M-14 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'tSafStructureLine.SafStructureLineNumber':U (icFieldName),
input string(t_sSafStructureLine.SafStructureLineNumber) (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sSafStructureLine.tc_Rowid (icRowid),
input 'QADFIN-346':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BSafStructure>
end.
/*JBA 23/02/2005 - new request sequence must start with 1*/
if last-of (t_sSafStructureLine.SafStructure_ID) and
viFirstSeq > 1
then do:
assign vcMessage = trim(#T-32'The sequence of line numbers must start with 1.':200(3663)T-32#) + " ":U +
trim(substitute(#T-33'(SAF Structure: &1)':200(3664)T-33#,
t_sSafStructure.SafStructureCode))
oiReturnStatus = -1.
<M-22 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'tSafStructureLine.SafStructureLineNumber':U (icFieldName),
input string(t_sSafStructureLine.SafStructureLineNumber) (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sSafStructureLine.tc_Rowid (icRowid),
input 'QADFIN-1782':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BSafStructure>
end.
/*JBA error: line sequence must be unique - should be checked by FC (unique index) but they have a problem with this
so for the moment the unique index is not defined and we write the test ourselves*/
if first-of (t_sSafStructureLine.SafStructureLineNumber)
then assign viCount = 0.
if t_sSafStructureLine.tc_Status <> "D":U
then assign viCount = viCount + 1.
if last-of (t_sSafStructureLine.SafStructureLineNumber) and
viCount > 1
then UNIQUE_BLOCK: do:
/*JBA 22/04/2005 - viCount > 2 and one of them is <> deleted = error*/
assign viSeq = t_sSafStructureLine.SafStructureLineNumber
viSafStructureLineId = t_sSafStructureLine.SafStructureLine_ID.
if can-find (first t_sSafStructureLine where
t_sSafStructureLine.SafStructure_ID = t_sSafStructure.SafStructure_ID and
t_sSafStructureLine.SafStructureLineNumber = viSeq and
t_sSafStructureLine.SafStructureLine_ID <> viSafStructureLineId and
t_sSafStructureLine.tc_Status <> "D":U)
then do:
assign vcMessage = trim(#T-34'The line number must be unique.':200(3665)T-34#) + " ":U +
trim(substitute(#T-35'The SAF structure &1 has &2 lines with sequence number &3.':200(3666)T-35#,
t_sSafStructure.SafStructureCode,
string(viCount),
string(t_sSafStructureLine.SafStructureLineNumber)))
oiReturnStatus = -1.
<M-19 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'tSafStructureLine.SafStructureLineNumber':U (icFieldName),
input string(t_sSafStructureLine.SafStructureLineNumber) (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sSafStructureLine.tc_Rowid (icRowid),
input 'QADFIN-1778':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BSafStructure>
end.
end.
/*JBA 23/02/2005 - error if there are gaps in sequence*/
assign vcGaps = "":U.
if last-of (t_sSafStructureLine.SafStructure_ID)
then do viSeq = 1 to min(viLastSeq - 1, 5):
if not can-find (first t_sSafStructureLine where
t_sSafStructureLine.SafStructureLineNumber = viSeq and
t_sSafStructureLine.tc_Status <> "D":U)
then assign vcGaps = vcGaps + ", ":U + string(viSeq).
end.
if vcGaps <> "":U
then do:
assign vcMessage = trim(#T-36'The sequence of line numbers must be continuous and between 1 and 5.':200(3667)T-36#) + " ":U +
trim(substitute(#T-37'The sequence number &2 is missing in SAF structure &1.':200(3668)T-37#,
t_sSafStructure.SafStructureCode,
trim(vcGaps, ", ":U)))
oiReturnStatus = -1.
<M-21 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'tSafStructureLine.SafStructureLineNumber':U (icFieldName),
input string(t_sSafStructureLine.SafStructureLineNumber) (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sSafStructureLine.tc_Rowid (icRowid),
input 'QADFIN-1781':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BSafStructure>
end.
end.
/* Active flag FIN-1706 Temporar workaround ============================= *
* Active flag cannot be changed, if there is any posting in transient layer *
* This is just workaround to ensure, once this posting is transferred from *
* transient layer into official one, GL account stays active. Today during *
* this transfer, no validation for active account is executed. Therefore we *
* prevent user to change Activity flag in this case *
* ========================================================================= */
if t_sSafStructure.tc_Status ="C":U and
t_sSafStructure.SafStructureIsActive <> t_iSafStructure.SafStructureIsActive and
t_sSafStructure.SafStructureIsActive <> true
then do:
<Q-56 assign vlFcQueryRecordsAvailable = PostingSafForValSafTrans (NoCache)
(input ?, (CompanyId)
input {&LAYERTYPECODE-TRANSIENT}, (LayerTypes)
input t_sSafStructure.SafStructure_ID, (SafStructure_ID)
input ?, (Saf_ID)) in BPosting >
if vlFcQueryRecordsAvailable <> false
then do:
assign vcMessage = #T-55'SAF Structure &1 cannot be deactivated, until there are pending postings in Transient layer which can be transferred into official layer.':255(733709264)T-55#
vcMessage = substitute(vcMessage, t_sSafStructure.SafStructureCode).
<M-57 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'tSafStructure.SafStructureIsActive':U (icFieldName),
input string(t_sSafStructure.SafStructureIsActive) (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sSafStructure.tc_Rowid (icRowid),
input 'QadFin-9497':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BSafStructure>
assign oiReturnStatus = -1.
end.
end.
end.