project QadFinancials > class BPeriod > method AdditionalUpdates

Description

This empty method allows to do additional updates on class temp-tables after records were received (and validated) from outside, using method SetPublicTables.
You can start instances of other business classes to do those updates.
Specific:
Update the period records in logistic module.


Parameters


oiReturnStatusoutputinteger


Internal usage


QadFinancials
method BPeriod.ApiActivatePeriodForPeriodicCosting
method BPeriod.ApiCreatePeriod
method BPeriod.ApiDeactivatePeriodForPeriodicCosting
method BPeriod.ApiStdMaintainTT
method BPeriod.ApiUpdatePeriodStatus
method BPeriod.LoadAndUpdateInstanceData
method BPeriod.SynchronizePeriod
method BPeriod.ValidateBCAndAdditionalUpdates


program code (program/bperiod.p)

    
    /* ======================================================================================================= */
    /* First, we load all relevant Period records in a separate temp-table. This will make it easier to do     */
    /* some additional validations, because we can just check this temp-table and don't have to check both the */
    /* instance temp-table and the database.                                                                   */
    /* ======================================================================================================= */
    empty temp-table tPeriodTemp.

    for each tPeriod where
             tPeriod.tc_Status <> "D":U:
        create tPeriodTemp.
        buffer-copy tPeriod to tPeriodTemp.
    end.

    empty temp-table tqPeriodByYearPeriod.
    <Q-78 run PeriodByYearPeriod  (Start) in BPeriod >
    for each tPeriod where
             tPeriod.tc_Status <> "D":U
             break by tPeriod.Company_ID :
        if first-of (tPeriod.Company_ID)
        then do :
            <Q-17 run PeriodByYearPeriod (all) (Append) (NoCache)
               (input tPeriod.Company_ID, (CompanyId)
                input ?, (PeriodYear)
                input ?, (PeriodPeriod)
                input ?, (PeriodId)
                output dataset tqPeriodByYearPeriod) in BPeriod >
        end. /* if first-of (tPeriod.Company_ID) */
    end. /* for each tPeriod where */
    for each tqPeriodByYearPeriod:
        if can-find (first tPeriodTemp where
                           tPeriodTemp.Company_ID   = tqPeriodByYearPeriod.tiCompany_ID    and
                           tPeriodTemp.PeriodYear   = tqPeriodByYearPeriod.tiPeriodYear and
                           tPeriodTemp.PeriodPeriod = tqPeriodByYearPeriod.tiPeriodPeriod) or
           can-find (first tPeriod where
                           tPeriod.Company_ID   = tqPeriodByYearPeriod.tiCompany_ID   and
                           tPeriod.PeriodYear   = tqPeriodByYearPeriod.tiPeriodYear   and
                           tPeriod.PeriodPeriod = tqPeriodByYearPeriod.tiPeriodPeriod and
                           tPeriod.tc_Status    = "D":U)
        then next.
        create tPeriodTemp.
        assign tPeriodTemp.Company_ID               = tqPeriodByYearPeriod.tiCompany_ID
               tPeriodTemp.Period_ID                = tqPeriodByYearPeriod.tiPeriod_ID
               tPeriodTemp.PeriodYear               = tqPeriodByYearPeriod.tiPeriodYear
               tPeriodTemp.PeriodPeriod             = tqPeriodByYearPeriod.tiPeriodPeriod
               tPeriodTemp.PeriodStartDate          = tqPeriodByYearPeriod.ttPeriodStartDate
               tPeriodTemp.PeriodEndDate            = tqPeriodByYearPeriod.ttPeriodEndDate
               tPeriodTemp.PeriodStatus             = tqPeriodByYearPeriod.tcPeriodStatus
               tPeriodTemp.PeriodTypeCode           = tqPeriodByYearPeriod.tcPeriodTypeCode
               tPeriodTemp.tc_Rowid                 = tqPeriodByYearPeriod.tc_Rowid.
    end. /* for each tqPeriodByYearPeriod: */ 
    <Q-80 run PeriodByYearPeriod  (Stop) in BPeriod > /* Only stop the query once we don't need the result-set anymore */
    

    /***
     * We test on  status <> "D":U because period records must be successive so no gaps allowed
     * eg I delete 2004/07 and then I test on status C or N, he doesn't do anything and you can
     * save the record what's wrong
     ***/
    for each tPeriod where
             tPeriod.tc_Status <> "D":U :
             
        /*** 
         * The year of a Period must be consecutive. This means that either:
         *   * The previous year is already defined
         *   * This is the first year being defined
         ***/
        if not can-find (first tPeriodTemp where
                               tPeriodTemp.Company_ID = tPeriod.Company_ID and
                               tPeriodTemp.PeriodYear = tPeriod.PeriodYear - 1) and
           can-find (first tPeriodTemp where
                           tPeriodTemp.Company_ID = tPeriod.Company_ID and
                           tPeriodTemp.PeriodYear < tPeriod.PeriodYear)
        then do:
            assign vcMessage      = trim (substitute(#T-27'You first must define the GL periods for &1.':255(3059)T-27#, string(tPeriod.PeriodYear - 1)))
                   vcFcContext    = 'tPeriod.Company_ID=' + string (tPeriod.Company_ID)
                   oiReturnStatus = -1.
            
            <M-18 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  'tPeriod.PeriodYear':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  tPeriod.tc_Rowid (icRowid), 
                input  'QADFIN-196':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  vcFcContext (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPeriod>
        end.
        
        
        /* Periods are not allowed to overlap    */
        
        if tPeriod.PeriodTypeCode <> {&PERIODTYPECODE-YEARCLOSING} and
           tPeriod.PeriodTypeCode <> {&PERIODTYPECODE-CORRECTION}
        then do:
        
           if can-find (first tPeriodTemp where   
                           tPeriodTemp.Company_ID       = tPeriod.Company_ID            and
                           tPeriodTemp.PeriodStartDate <= tPeriod.PeriodStartDate       and
                           tPeriodTemp.PeriodEndDate   >= tPeriod.PeriodStartDate       and
                           tPeriodTemp.PeriodTypeCode  <> {&PERIODTYPECODE-YEARCLOSING} and
                           tPeriodTemp.PeriodTypeCode  <> {&PERIODTYPECODE-CORRECTION}  and
                           tPeriodTemp.tc_Rowid        <> tPeriod.tc_Rowid)             or
           can-find (first tPeriodTemp where    
                           tPeriodTemp.Company_ID       = tPeriod.Company_ID            and           
                           tPeriodTemp.PeriodStartDate <= tPeriod.PeriodEndDate         and
                           tPeriodTemp.PeriodEndDate   >= tPeriod.PeriodEndDate         and
                           tPeriodTemp.PeriodTypeCode  <> {&PERIODTYPECODE-YEARCLOSING} and
                           tPeriodTemp.PeriodTypeCode  <> {&PERIODTYPECODE-CORRECTION}  and
                           tPeriodTemp.tc_Rowid        <> tPeriod.tc_Rowid)             or
           can-find (first tPeriodTemp where                
                           tPeriodTemp.Company_ID       = tPeriod.Company_ID            and
                           tPeriodTemp.PeriodStartDate >= tPeriod.PeriodStartDate       and
                           tPeriodTemp.PeriodEndDate   <= tPeriod.PeriodEndDate         and
                           tPeriodTemp.PeriodTypeCode  <> {&PERIODTYPECODE-YEARCLOSING} and
                           tPeriodTemp.PeriodTypeCode  <> {&PERIODTYPECODE-CORRECTION}  and
                           tPeriodTemp.tc_Rowid        <> tPeriod.tc_Rowid)             or
           can-find (first tPeriodTemp where                
                           tPeriodTemp.Company_ID       = tPeriod.Company_ID            and 
                           tPeriodTemp.PeriodStartDate <= tPeriod.PeriodStartDate       and
                           tPeriodTemp.PeriodEndDate   >= tPeriod.PeriodEndDate         and
                           tPeriodTemp.PeriodTypeCode  <> {&PERIODTYPECODE-YEARCLOSING} and
                           tPeriodTemp.PeriodTypeCode  <> {&PERIODTYPECODE-CORRECTION}  and
                           tPeriodTemp.tc_Rowid        <> tPeriod.tc_Rowid)
           then do:
               assign vcMessage      = trim (#T-14'GL Periods cannot overlap in time.':255(957642246)T-14#)            
               oiReturnStatus = -1.
               
               <M-96 run SetMessage
                  (input  vcMessage (icMessage), 
                   input  '':U (icArguments), 
                   input  tPeriod.PeriodStartDate (icFieldName), 
                   input  '':U (icFieldValue), 
                   input  'E':U (icType), 
                   input  3 (iiSeverity), 
                   input  tPeriod.tc_Rowid (icRowid), 
                   input  'qadfin-283674':U (icFcMsgNumber), 
                   input  '':U (icFcExplanation), 
                   input  '':U (icFcIdentification), 
                   input  '':U (icFcContext), 
                   output viFcReturnSuper (oiReturnStatus)) in BPeriod>           
           end.   
        end.                 
                           

        /*** 
         * The period of a Period must be consecutive. This means that either:
         *   * The previous period is already defined
         *   * This is the first period being defined
         ***/
        if tPeriod.PeriodPeriod > 1 and
           not can-find (first tPeriodTemp where
                               tPeriodTemp.Company_ID   = tPeriod.Company_ID    and
                               tPeriodTemp.PeriodYear   = tPeriod.PeriodYear and
                               tPeriodTemp.PeriodPeriod = tPeriod.PeriodPeriod - 1)
        then do:
            assign vcMessage      = trim (subst (#T-28'You first must define GL period &1/&2.':255(3060)T-28#, string(tPeriod.PeriodYear), string(tPeriod.PeriodPeriod - 1)))
                   vcFcContext    = 'tPeriod.Company_ID=' + string (tPeriod.Company_ID)
                   oiReturnStatus = -1.
            <M-19 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  'tPeriod.PeriodPeriod':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  tPeriod.tc_Rowid (icRowid), 
                input  'QADFIN-197':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  vcFcContext (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPeriod>

        end.

        /***
         * The start date of a Period must be consecutive (no corr period). This means that either:
         *   * There is a period with end date 1 day before this start date 
         *   * This is the first period being defined 
         ***/
        if tPeriod.PeriodTypeCode = {&PERIODTYPECODE-NORMAL} and 
           not can-find (first tPeriodTemp where
                               tPeriodTemp.Company_ID     = tPeriod.Company_ID and
                               tPeriodTemp.PeriodTypeCode = {&PERIODTYPECODE-NORMAL} and
                               tPeriodTemp.PeriodEndDate  = tPeriod.PeriodStartDate - 1) and
           can-find (first tPeriodTemp where
                           tPeriodTemp.Company_ID     = tPeriod.Company_ID and
                           tPeriodTemp.PeriodTypeCode = {&PERIODTYPECODE-NORMAL} and
                           tPeriodTemp.PeriodEndDate  < tPeriod.PeriodStartDate)
        then do:
            assign vcMessage      = trim (subst (#T-29'You first must define a GL period ending on &1.':100(3061)T-29#, string(tPeriod.PeriodStartDate - 1)))
                   vcFcContext    = 'tPeriod.Company_ID=' + string (tPeriod.Company_ID)
                   oiReturnStatus = -1.
            <M-20 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  'tPeriod.PeriodEndDate':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  tPeriod.tc_Rowid (icRowid), 
                input  'QADFIN-198':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  vcFcContext (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPeriod>
        end.

        /*** 
         * the start and end date of a normal accounting period cannot be the same
         * as the previous period unless it is a correction period or yearclosing
         ***/
        if tPeriod.PeriodTypeCode = {&PERIODTYPECODE-NORMAL} and
           can-find (first tPeriodTemp where
                           tPeriodTemp.Company_ID      = tPeriod.Company_ID       and
                          (tPeriodTemp.PeriodStartDate = tPeriod.PeriodStartDate  or
                           tPeriodTemp.PeriodEndDate   = tPeriod.PeriodEndDate)   and
                           tPeriodTemp.PeriodTypeCode  = {&PERIODTYPECODE-NORMAL} and
                          (tPeriodTemp.PeriodYear     <> tPeriod.PeriodYear       or
                           tPeriodTemp.PeriodPeriod   <> tPeriod.PeriodPeriod))
        then do:
            assign vcMessage      = trim(#T-30'The period start and end date must be unique when it is not a correction period.':250(59830)t-30#)
                   vcMessage      = vcMessage + chr(10) + trim(#T-31'GL Calendar Year/GL Period':255(3063)T-31#) + " : ":U + string(tPeriod.PeriodYear) + " / ":U + string(tPeriod.PeriodPeriod)
                   vcFcContext    = 'tPeriod.Company_ID=' + string (tPeriod.Company_ID)
                   oiReturnStatus = -1.
            <M-21 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  'tPeriod.PeriodStartDate':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  tPeriod.tc_Rowid (icRowid), 
                input  'QADFIN-199':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  vcFcContext (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPeriod>
        end.

        /* Find the last normal period */
        for each tPeriodTemp where
                 tPeriodTemp.Company_ID      = tPeriod.Company_ID and
                 tPeriodTemp.PeriodTypeCode  = {&PERIODTYPECODE-NORMAL} and
                 tPeriodTemp.PeriodYear      = tPeriod.PeriodYear
        by tPeriodTemp.PeriodPeriod descending:
            leave.
        end.

        if tPeriod.PeriodTypeCode = {&PERIODTYPECODE-CORRECTION}
        then do:

            /* Set warning for new correction period */
            if tPeriod.tc_Status = "N":U
            then do:
                assign vcMessage      = trim(#T-67'You cannot change the end date of the accounting year once a correction period has been added.':250(59889)t-67#)
                       vcFcContext    = 'tPeriod.Company_ID=' + string (tPeriod.Company_ID)
                       oiReturnStatus = if oiReturnStatus = 0 then 1
                                        else oiReturnStatus.

                <M-68 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  'tPeriod.PeriodPeriod':U (icFieldName), 
                    input  tPeriod.PeriodPeriod (icFieldValue), 
                    input  'W':U (icType), 
                    input  3 (iiSeverity), 
                    input  tPeriod.tc_Rowid (icRowid), 
                    input  'QadFin-6132':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  vcFcContext (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BPeriod>
            end.

             /* Correction period must be after the last normal period */
            if not available tPeriodTemp or
                tPeriod.PeriodPeriod <= tPeriodTemp.PeriodPeriod
            then do:
                assign vcMessage      = trim(#T-51'A correction period must be after the last normal period.':150(59852)t-51#)
                       vcMessage      = if available tPeriodTemp
                                        then vcMessage + chr(10) + trim(substitute(#T-52'Information: Last normal period is &1.':150(59854)t-52#, string(tPeriodTemp.PeriodPeriod)))
                                        else vcMessage
                       vcMessage      = vcMessage + chr(10) + trim(substitute(#T-53'Accounting Year/Period : &1/&2':150(59846)T-53#,string(tPeriod.PeriodYear),string(tPeriod.PeriodPeriod)))
                       vcFcContext    = 'tPeriod.Company_ID=' + string (tPeriod.Company_ID)
                       oiReturnStatus = -1.
                
                <M-54 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  'tPeriod.PeriodPeriod':U (icFieldName), 
                    input  tPeriod.PeriodPeriod (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  tPeriod.tc_Rowid (icRowid), 
                    input  'QadFin-6116':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  vcFcContext (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BPeriod>
            end.
       
            /* The start date of a correction period must be within the last normal period */
            if available tPeriodTemp and
                tPeriod.PeriodStartDate < tPeriodTemp.PeriodStartDate or
                tPeriod.PeriodStartDate > tPeriodTemp.PeriodEndDate
            then do:
                assign vcDatetemp = <M-42 DisplayDate  (input  tPeriod.PeriodStartDate (itDate)) in BPeriod>
                       vcDatetemp1 = <M-49 DisplayDate  (input  tPeriodTemp.PeriodStartDate (itDate)) in BPeriod>.
                assign vcMessage      = trim(#T-58'The start date of a Correction period must be within the last Normal period in the accounting year.':250(59850)T-58#)
                       vcMessage      = vcMessage + chr(10) + trim(substitute(#T-59'Information: Start Date of last normal period is &1.':250(59845)t-59#,string(vcDatetemp1)))
                       vcMessage      = vcMessage + chr(10) + trim(substitute(#T-60'Accounting Year/Period : &1/&2':150(59846)T-60#,string(tPeriod.PeriodYear),string(tPeriod.PeriodPeriod)))
                       vcFcContext    = 'tPeriod.Company_ID=' + string (tPeriod.Company_ID)
                       oiReturnStatus = -1.

                <M-65 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  'tPeriod.PeriodStartDate':U (icFieldName), 
                    input  vcDatetemp (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  tPeriod.tc_Rowid (icRowid), 
                    input  'QadFin-6119':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  vcFcContext (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BPeriod>
            end.
            
            /* The end date of a correction period must be the same as the end date of the last normal period */
            if available tPeriodTemp and
                tPeriod.PeriodEndDate <> tPeriodTemp.PeriodEndDate
            then do:
                assign vcDatetemp  = <M-10 DisplayDate  (input  tPeriod.PeriodEndDate (itDate)) in BPeriod>
                       vcDatetemp1 = <M-33 DisplayDate  (input  tPeriodTemp.PeriodEndDate (itDate)) in BPeriod>.
                assign vcMessage      = trim(#T-61'The end date of a Correction period must be the same as the end date of the last Normal period in the accounting year.':250(59961)T-61#)
                       vcMessage      = vcMessage + chr(10) + trim(substitute(#T-62'Information: End Date of last normal period is &1.':250(59848)t-62#,string(vcDatetemp1)))
                       vcMessage      = vcMessage + chr(10) + trim(substitute(#T-63'Accounting Year/Period : &1/&2':150(59846)T-63#,string(tPeriod.PeriodYear),string(tPeriod.PeriodPeriod)))
                       vcFcContext    = 'tPeriod.Company_ID=' + string (tPeriod.Company_ID)
                       oiReturnStatus = -1.

                <M-66 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  'tPeriod.PeriodEndDate':U (icFieldName), 
                    input  vcDatetemp (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  tPeriod.tc_Rowid (icRowid), 
                    input  'QadFin-6120':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  vcFcContext (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BPeriod>
            end.
        end.  /* if tPeriod.PeriodTypeCode = {&PERIODTYPECODE-CORRECTION} */

        /***
         * When the normal period is replicated from the domain, the tPeriod temp-table will not contain
         * only normal periods so additional validation is necessary for new/changed normal period
         ***/
        if tPeriod.PeriodTypeCode = {&PERIODTYPECODE-NORMAL} and
          (tPeriod.tc_Status = "N":U or tPeriod.tc_Status = "C":U)
        then do:
            if can-find(first tPeriodTemp where
                           tPeriodTemp.Company_ID      = tPeriod.Company_ID           and
                           tPeriodTemp.PeriodTypeCode  = {&PERIODTYPECODE-CORRECTION} and
                           tPeriodTemp.PeriodYear      = tPeriod.PeriodYear           and
                           tPeriodTemp.PeriodPeriod   <= tPeriod.PeriodPeriod)
            then do:
                assign vcMessage      = trim(#T-35'A correction period must be preceded by a normal period.':250(59890)t-35#)
                       vcMessage      = vcMessage + chr(10) + trim(#T-36'GL Calendar Year/GL Period':255(3063)T-36#) + " : ":U + string(tPeriod.PeriodYear) + " / ":U + string(tPeriod.PeriodPeriod)
                       vcFcContext    = 'tPeriod.Company_ID=' + string (tPeriod.Company_ID)
                       oiReturnStatus = -1.

                <M-23 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  'tPeriod.PeriodTypeCode':U (icFieldName), 
                    input  tPeriod.PeriodTypeCode (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  tPeriod.tc_Rowid (icRowid), 
                    input  'QADFIN-201':U (icFcMsgNumber), 
                    input  '' (icFcExplanation), 
                    input  '' (icFcIdentification), 
                    input  vcFcContext (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BPeriod>
            end.

            /* If this is the last period, then validate start and end of all correctiong periods */
            if tPeriod.tc_Status     = "C":U and
               tPeriod.Company_ID    = tPeriodTemp.Company_ID and
               tPeriod.PeriodYear    = tPeriodTemp.PeriodYear and
               tPeriod.PeriodPeriod  = tPeriodTemp.PeriodPeriod
            then do:
                for each tPeriodTemp where
                         tPeriodTemp.Company_ID     = tPeriod.Company_ID           and
                         tPeriodTemp.PeriodTypeCode = {&PERIODTYPECODE-CORRECTION} and
                         tPeriodTemp.PeriodYear     = tPeriod.PeriodYear           and
                         tPeriodTemp.PeriodPeriod   > tPeriod.PeriodPeriod:
                    
                    if tPeriodTemp.PeriodStartDate < tPeriod.PeriodStartDate or
                       tPeriodTemp.PeriodStartDate > tPeriod.PeriodEndDate
                    then do:

                        assign vcDatetemp = <M-12 DisplayDate  (input  tPeriod.PeriodStartDate (itDate)) in BPeriod>
                               vcDatetemp1 = <M-6 DisplayDate  (input  tPeriodTemp.PeriodStartDate (itDate)) in BPeriod>.
                        assign vcMessage      = trim(#T-69'The start date of a Correction period must be within the last Normal period in the accounting year.':250(59850)T-69#)
                               vcMessage      = vcMessage + chr(10) + trim(substitute(#T-70'Information: Start Date of last normal period is &1.':250(59845)t-70#,string(vcDatetemp)))
                               vcMessage      = vcMessage + chr(10) + trim(substitute(#T-71'Accounting Year/Period : &1/&2':150(59846)T-71#,string(tPeriodTemp.PeriodYear),string(tPeriodTemp.PeriodPeriod)))
                               vcFcContext    = 'tPeriod.Company_ID=' + string (tPeriod.Company_ID)
                               oiReturnStatus = -1.

                        <M-72 run SetMessage
                           (input  vcMessage (icMessage), 
                            input  '':U (icArguments), 
                            input  'tPeriod.PeriodPeriod':U (icFieldName), 
                            input  vcDatetemp1 (icFieldValue), 
                            input  'E':U (icType), 
                            input  3 (iiSeverity), 
                            input  tPeriodTemp.tc_Rowid (icRowid), 
                            input  'QadFin-6133':U (icFcMsgNumber), 
                            input  '':U (icFcExplanation), 
                            input  '':U (icFcIdentification), 
                            input  vcFcContext (icFcContext), 
                            output viFcReturnSuper (oiReturnStatus)) in BPeriod>
                    end.

                    if tPeriodTemp.PeriodEndDate <> tPeriod.PeriodEndDate
                    then do:
                        assign vcDatetemp  = <M-764 DisplayDate  (input  tPeriodTemp.PeriodEndDate (itDate)) in BPeriod>.
                               
                        assign vcMessage      = trim(#T-73'The end date of a correction period must be the end date of the last normal period in the accounting year.':250(59851)t-73#)
                               vcMessage      = vcMessage + chr(10) + trim(substitute(#T-74'Information: End Date of last normal period is &1.':250(59848)t-74#,string(vcDatetemp)))
                               vcMessage      = vcMessage + chr(10) + trim(substitute(#T-75'Accounting Year/Period : &1/&2':150(59846)T-75#,string(tPeriod.PeriodYear),string(tPeriod.PeriodPeriod)))
                               vcFcContext    = 'tPeriod.Company_ID=' + string (tPeriod.Company_ID)
                               oiReturnStatus = -1. 

                        <M-76 run SetMessage
                           (input  vcMessage (icMessage), 
                            input  '':U (icArguments), 
                            input  'tPeriod.PeriodEndDate':U (icFieldName), 
                            input  vcDatetemp (icFieldValue), 
                            input  'E' (icType), 
                            input  3 (iiSeverity), 
                            input  '':U (icRowid), 
                            input  'QadFin-6134':U (icFcMsgNumber), 
                            input  '':U (icFcExplanation), 
                            input  '':U (icFcIdentification), 
                            input  vcFcContext (icFcContext), 
                            output viFcReturnSuper (oiReturnStatus)) in BPeriod>
                    end.
                end.
            end.
        end.

        if tPeriod.PeriodTypeCode = {&PERIODTYPECODE-YEARCLOSING} and
           tPeriod.PeriodPeriod  <> 0                             and
           can-find(first tPeriodTemp where
                          tPeriodTemp.Company_ID     = tPeriod.Company_ID and
                          tPeriodTemp.PeriodYear     = tPeriod.PeriodYear and
                          tPeriodTemp.PeriodPeriod  >= tPeriod.PeriodPeriod and
                          tPeriodTemp.Period_ID     <> tPeriod.Period_ID)
        then do:
           assign vcMessage = trim(#T-55'A year closing period must be the last period in the accounting year.':150(59855)t-55#)
                  vcMessage = vcMessage + chr(10) + trim(substitute(#T-56'Accounting Year/Period : &1/&2':150(59846)T-56#,string(tPeriod.PeriodYear),string(tPeriod.PeriodPeriod)))
                  vcFcContext    = 'tPeriod.Company_ID=' + string (tPeriod.Company_ID)
                  oiReturnStatus = -1.

           <M-57 run SetMessage
              (input  vcMessage (icMessage), 
               input  '':U (icArguments), 
               input  'tPeriod.PeriodPeriod':U (icFieldName), 
               input  tPeriod.PeriodPeriod (icFieldValue), 
               input  'E':U (icType), 
               input  3 (iiSeverity), 
               input  tPeriod.tc_Status (icRowid), 
               input  'QadFin-6117':U (icFcMsgNumber), 
               input  '':U (icFcExplanation), 
               input  '':U (icFcIdentification), 
               input  vcFcContext (icFcContext), 
               output viFcReturnSuper (oiReturnStatus)) in BPeriod>
        end.                                                    
    end.

    /* only the first and the last accounting year may be deleted */
    if not can-find (first tPeriod where
                           tPeriod.tc_Status <> "D":U)
    then do:
        find first tPeriod no-lock no-error.
        if available tPeriod and 
           can-find (first tPeriodTemp where
                           tPeriodTemp.Company_ID = tPeriod.Company_ID and
                           tPeriodTemp.PeriodYear < tPeriod.PeriodYear) and
           can-find (first tPeriodTemp where
                           tPeriodTemp.Company_ID = tPeriod.Company_ID and
                           tPeriodTemp.PeriodYear > tPeriod.PeriodYear)
        then do:
            assign vcMessage      = trim (#T-37'You can only delete the first or last GL calendar year.':100(3067)T-37#)
                   vcFcContext    = 'tPeriod.Company_ID=' + string (tPeriod.Company_ID)
                   oiReturnStatus = -1.
            <M-24 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  tPeriod.tc_Rowid (icRowid), 
                input  'QADFIN-283':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  vcFcContext (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPeriod>
        end. /* if available tPeriod and  */
    end. /* if not can-find (first tPeriod where */

    if oiReturnStatus < 0
    then return.
    
<ANCESTOR-CODE>

    /* Create Period Marks when changing the status */
    <M-26 run UpdatePeriodMark (output viFcReturnSuper (oiReturnStatus)) in BPeriod>
    if viFcReturnSuper <> 0
    then do:
        assign oiReturnStatus = viFcReturnSuper.
        if oiReturnStatus < 0 then return.        
    end.    

    if oiReturnStatus = 0
    then assign oiReturnStatus = -98.

    /* Replicate changes to MFG/PRO GL Calendar Detail */
    if viBMfgPeriodID = 0 or viBMfgPeriodID = ?
    then do:
        <I-38 {bFcStartAndOpenInstance
            &ADD-TO-TRANSACTION = "true"
            &CLASS              = "BMfgPeriod"}>
    end.
    else do:
        <I-43 {bFcOpenInstance
            &CLASS           = "BMfgPeriod"}>
    end.

    <M-39 run MaintainData (input  tPeriod (tPeriod), 
                            output viLocalReturnStatus (oiReturnStatus)) in BMfgPeriod>

    <I-40 {bFcCloseInstance
            &CLASS           = "BMfgPeriod"}>

    if viLocalReturnStatus <> 0
    then assign oiReturnStatus = viLocalReturnStatus.

    if viLocalReturnStatus < 0 
    then do :
        <M-77 run StopExternalInstances
           (output viFcReturnSuper (oiReturnStatus)) in BPeriod>
        return.
    end. /* if viLocalReturnStatus < 0  */
    
    /* GL Consistency check: set batch flag to false when locking the period */
    for each t_sPeriod where
             t_sPeriod.PeriodStatus = {&PERIODSTATUS-LOCKED} and
             t_sPeriod.tc_Status    = 'C':U:
        find first t_iPeriod where
                   t_iPeriod.Period_ID    = t_sPeriod.Period_ID  and
                   t_iPeriod.PeriodStatus = {&PERIODSTATUS-OPEN} no-error.   
        if available t_iPeriod
        then do:        
            <I-25 {bFcStartAndOpenInstance
                 &ADD-TO-TRANSACTION   = "false"
                 &CLASS                = "BConCheck"}>
            
            <M-34 run UpdateConCheckToDate
               (input  t_sPeriod.Company_ID (iiCompanyID), 
                input  t_sPeriod.Period_ID (iiPeriodID), 
                output viFcReturnSuper (oiReturnStatus)) in BConCheck>
            if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus >= 0)
            then assign oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0 then return.
            
            <I-89 {bFcCloseAndStopInstance
                 &CLASS           = "BConCheck"}>
           /* to be developed:call method BConCheck.ModifyConCheck to assign tConCheck.ConCheckIsUpToDate = false */
        end.
    end. /* for each t_sPeriod */
    
    /* Set ReturnStatus = OK    */
    if oiReturnStatus = -98
    then assign oiReturnStatus = 0.