This routine aims at removing records of transaction tables and balance tables in periods already closed, i.e., periods whose reports have already been printed and registered and will no longer be used for history queries or for comparison of fiscal years.

This routine obtains final balances of the fiscal year indicated, makes security copies (backup) of entries to be removed and deletes all entries and balances up to the last date of the fiscal year entered (including prior fiscal years). Finally, it generates an entry batch with final balances of the fiscal year that was cleaned, in order to maintain the integrity of balances for the following fiscal years.

Procedures executed by the Database Cleaning routine

1. A warning is displayed informing that balances must be updated and that the calendar(s) of fiscal year indicated in the routine must be closed, i.e., calendars with “Closed” status.

2. All currencies and balance types registered and bound are considered and transferred.

3. Final balances of the fiscal year entered are obtained and saved in a temporary file.

    • Final balances are considered according to final dates identified in the calendars. In the event of calendars with different final dates between the currencies, these dates are considered as dates of the entries. Different documents are generated for each currency.

Note:

The quoted balance is not considered for the backup. However, quoted balances are also removed from balance tables during the cleaning (tables CV1 and CV2, of quotation origin, are maintained) based on the concept that in “Carried Forward“ periods, the base is no longer available for query. The backup table keeps a copy of the entries saved in the table CT2 to be removed.

    • Balances obtained (by currency and by balance type) are saved in a work file (TRB) in the directory “\System” in Protheus with the nomenclature 01012004, which corresponds to:

01

Company in which the cleaning is being performed

01

Branch in which the cleaning is being performed

2004

Year/Fiscal Year in which the cleaning is being performed

4. Records of movements of table CT2 are copied up to the final dates of calendar(s) (considering each currency) to the table of entries backup (table CV6).

Tip:

The structure of the backup table must be the same as the entries table's (CT2), adding the column CV6_EXERC, character with size 4, in order to identify the cleaning fiscal year in the event of a later recovery.

 

5. The transaction records of table CT2 up to the final dates of the calendars are removed, considering the possibility of calendars with different final dates among the currencies.

    • If final dates of other currencies are after the final date of currency 01, only records of currency 01 between the final date of currency 01 and the final date of “other currency” are kept.
    • If final dates of other currencies are earlier than the final date of currency 01, records of currency 01 between the final date of other currencies and the final date of currency 01 have their value zeroed.

6. Final balances are read from the work file (TRB). These final balances are saved in the format of the new entries, separated by document, according to balance type, currency and calendar dates, in the table of accounting entries (the lot and sub-lot numbers and the document indicated in the questions of the routine with sequential increase are considered). These entries are kept representing initial balances for the subsequent fiscal year.

7. Once entries with final balances are saved, recalculation of balances (reprocessing) is performed for the whole period that was cleaned, considering from the earlier date of movements transferred carried forward in CT2 to the later final date of the fiscal year, keeping only the balance records for the final date of the period.

8. After recalculating balances, status of the calendar(s) turns into “Carried Forward.”

9. At the end of processing, the user is asked to delete the work file (TRB), confirming the routine execution.

 Notes:

  • Entries of final balances in other currencies have criterion 4 (Entered) for values in other currencies (they do not go through changes in case of update of the currencies, since it is a closed period).
  • All balance types are considered (except quoted balance, which comes from table CV1). If there is more than one balance type, documents are "sorted" by balance type and by currency.
  • If processing is interrupted after a full setup of the final balance file (from step 4), the routine may resume processing from the work file (TRB) already filled in. The user must ensure that the work file with final balances has already been fully saved for its reuse (avoiding the step of recalculation of final balances). If the routine is interrupted while carrying forward entries to the backup table, processing can continue from where coping was interrupted, since entries already carried forward to the backup table are verified.