project BLF > class BSharedSet > method ValidateComponent

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


oiReturnStatusoutputinteger


Internal usage


unused


program code (program/bsharedset.p)

<ANCESTOR-CODE>

if oiReturnStatus < 0
then return.

for each t_sSharedSet where
         t_sSharedSet.tc_Status <> "":U:
    /*initially loaded data*/
    if t_sSharedSet.tc_Status = "C":U or
       t_sSharedSet.tc_Status = "D":U
    then do:
        find first t_iSharedSet where
                   t_iSharedSet.tc_Rowid = t_sSharedSet.tc_Rowid no-error.
        if not available t_iSharedSet
        then do:
            assign vcMessage      = "t_iSharedSet 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  'BLF-208':U (icFcMsgNumber), 
           input  '' (icFcExplanation), 
           input  '' (icFcIdentification), 
           input  '' (icFcContext), 
           output viFcReturnSuper (oiReturnStatus)) in BSharedSet>
            return.
        end.
    end.
    /*Error:Cannot Modify SharedSetTypeCode if the shared set is already used*/
    /*Error:Cannot Delete - DB constraint*/
    if available t_iSharedSet and
       t_iSharedSet.SharedSetTypeCode <> t_sSharedSet.SharedSetTypeCode and
       t_sSharedSet.tc_Status = "C":U
    then do:
        /*Shared Set is already linked to a CompanySharedSet*/
        <Q-3 run CompanySharedSetBySharedSet (all) (Read) (NoCache)
          (input t_sSharedSet.SharedSet_ID, (SharedSetId)
           input ?, (CompanyId)
           output dataset tqCompanySharedSetBySharedSet) in BCompany >
        assign vcMessage = "":U.
        for each tqCompanySharedSetBySharedSet:
            assign vcMessage = vcMessage + ", ":U + trim(tqCompanySharedSetBySharedSet.tcCompanyCode).
        end.
        if vcMessage <> "":U
        then do:
            assign viFrom = lookup(t_iSharedSet.SharedSetTypeCode, vcListSharedSetTypePair, chr(2))
                   viTo   = lookup(t_sSharedSet.SharedSetTypeCode, vcListSharedSetTypePair, chr(2)).
            /*if display-value and data-value are identical viFrom/viTo point already to the right display-value string*/
            if viFrom > 0 
            then assign vcFrom = if (viFrom modulo 2) = 0
                                 then entry (viFrom - 1, vcListSharedSetTypePair, chr(2))
                                 else entry (viFrom, vcListSharedSetTypePair, chr(2)).
            else assign vcFrom = t_iSharedSet.SharedSetTypeCode.
            
            if viTo > 0 
            then assign vcTo   = if (viTo modulo 2) = 0
                                 then entry (viTo - 1, vcListSharedSetTypePair, chr(2))
                                 else entry (viTo, vcListSharedSetTypePair, chr(2)).
            else assign vcTo   = t_sSharedSet.SharedSetTypeCode.
            
            assign vcMessage      = trim(substitute(#T-5'Cannot change the type of shared set '&1' from '&2' to '&3'.':200(469)T-5#, 
                                         trim(t_sSharedSet.SharedSetCode), trim(vcFrom), trim(vcTo))) + chr(10) + 
                                    trim(substitute(#T-6'Shared set is already used in these entities: &1.':200(470)T-6#, left-trim(vcMessage, ", ":U))) + chr(10) +
                                    program-name(1)
                   oiReturnStatus = if oiReturnStatus  < 0
                                    then oiReturnStatus
                                    else -1.
            <M-4 run SetMessage (input  vcMessage (icMessage), 
                     input  '':U (icArguments), 
                     input  't_sSharedSet.SharedSetTypeCode':U (icFieldName), 
                     input  t_sSharedSet.SharedSetTypeCode (icFieldValue), 
                     input  'E':U (icType), 
                     input  3 (iiSeverity), 
                     input  t_sSharedSet.tc_Rowid (icRowid), 
                     input  'BLF-209':U (icFcMsgNumber), 
                     input  '' (icFcExplanation), 
                     input  '' (icFcIdentification), 
                     input  '' (icFcContext), 
                     output viFcReturnSuper (oiReturnStatus)) in BSharedSet>
        end.
    end.
end.