Every Db2 shop keeps more history than it needs. Old orders, expired events and audit rows stay in the tables long after anyone reads them, and every query, REORG, copy and recovery pays for them. REORG DISCARD can remove them in the same pass that reorganizes the data, but using it safely is hard work: the conditions have to be written into each job, the dependent tables have to be cleaned up with CHECK DATA, exception tables have to exist, and the removed rows have to be kept somewhere they can be found again. TUC automates the whole process, from the condition that says which rows can go to the integrity check of the last dependent table, and keeps every removed row ready to be reloaded.
Key Benefits
Separate Roles — The application decides what data may go and when; the DBA team processes the discard without owning the decision.
Conditions That Adapt — Each table has its own discard condition, kept apart from the jobs, with values from the run or from a query, so one condition serves every region and retention period.
Existing Jobs Included — Archiving jobs that compute their own conditions come under TUC control without JCL changes, and their conditions are captured at every run.
Integrity Built In — Dependent tables are found, exception tables are created and CHECK DATA runs automatically, so nothing is left in check pending.
Nothing Lost — Every discarded row is recorded and can be recalled, reloaded into the source table or loaded into an archive table.
Only When Needed — A table with nothing to discard is not reorganized for it, and an accelerated table is not reloaded when no rows left it.
Why Archiving With REORG DISCARD Is Hard
REORG DISCARD removes rows that match a condition while it rebuilds the tablespace. It is the most efficient way to purge history: there is no DELETE, no logging of every row and no second pass. Yet most sites use it only for a few tables, and for good reasons.
The conditions live in the utility statements of each job. When the retention period changes, or a new application needs a different period, the jobs have to be edited. When the rows to remove depend on business data, an application step has to compute the condition and write it into the job input. When a parent row is discarded, its dependent rows remain, the dependent tables are left in check pending, and someone has to run CHECK DATA with DELETE YES, which needs an exception table for every dependent table. The DBA who writes the conditions also becomes the one answerable for every row they remove. When the job ends, the discarded rows sit in datasets that nobody records, and getting them back means searching the output for the dataset names. A REORG that ran to discard rows that were never there has cost a full reorganization for nothing.
Each of these steps is simple on its own. Together they make data archiving a project of its own that is easy to postpone, while the tables keep growing.
Separating the Roles
Deciding which data may be deleted is a business decision. Running the REORG that removes it is a technical task. When the DBA writes the discard conditions into the jobs, the two are merged, and the DBA becomes the person who deleted the data. If the wrong rows go, or rows go too early, the question lands on the DBA team, even though nobody there could know which history the business still needs.
TUC keeps the two roles apart:
- The application decides. The application team owns the discard conditions and the values behind them. It defines which rows of its tables may be removed, keeps the retention periods in its own parameter table, or computes the conditions in its own batch job, and it triggers the discard when the business is ready, from its own batch flow.
- The DBA processes. The DBA team owns the execution: the REORG, the space, the concurrency, the integrity of the dependent tables and the safekeeping of the removed rows. It runs the discard exactly as the application asked, without writing or changing a single condition.
Every discard is traceable to its source. Conditions captured from an application job are recorded under the name of that job, every order is recorded with the job that placed it, and every discarded row is kept in a recorded dataset. When someone asks why rows are missing, the answer shows which job asked for it, with which conditions, and where the rows are, and they can be reloaded. The DBA team is no longer the one held responsible for deleting data; it is the team that removed it safely and can bring it back.
Conditions That Belong to the Data
A Condition for Each Table
The discard condition belongs to the table, not to a job. It is defined once for each table that holds history: rows whose event date is older than the retention period, rows of closed accounts, rows of a test region. A table can have several named conditions for different purposes, and a condition can be checked before it is used, by running it in preview against the real table.
Values Supplied at Run Time
The condition does not have to carry fixed values. It can name a variable, such as the number of days to keep or the region to purge, and the value is supplied when the work runs. The same condition then serves a monthly purge of ninety days and a yearly purge of seven years, without being changed.
Values From a Query
The values can also come from the data itself. A condition can be paired with a query that runs first, and the query result supplies the values. The retention period of each region can be kept in an ordinary parameter table that the business maintains: the query reads it, and the condition is resolved for each region it returns. When the query returns several rows, TUC repeats the condition once for each row and combines them, so a single condition removes ninety days of history for one region and two years for another in the same run. The query can join and compute what a discard condition alone cannot express, which extends REORG DISCARD far beyond the simple predicates it accepts.
Processed Where a Condition Exists
The archiving work is ordered for a group of tables, and TUC processes only the tables in the group that have a discard condition. Tables without one are left out automatically. Changing the retention period, adding a table or moving the purge to another night are each a single change in one place, and none of them touches a job. The REORG policy still decides when an object needs reorganization for performance; the discard conditions decide what history may leave it.
Only When There Is Something to Remove
Before it orders a REORG to discard rows, TUC can first check whether any row in the table matches its condition. When none does, the table is left alone, and the cost of a reorganization that would remove nothing is avoided. Where the work does run, TUC counts the rows that were really discarded. Empty discard datasets can be deleted at once, and an accelerated table is reloaded into the accelerator only when rows actually left it.
Keeping Referential Integrity
Discarding parent rows leaves their dependent rows behind and places the dependent tables in check pending. TUC follows the referential structure and handles the dependents in the same piece of work:
- Dependent tables are found. All descendant tables of a discarded table are added to the processing, even when they are not part of the group being archived.
- Exception tables are created. An exception table is created for every dependent table, with the same structure, page size and encoding, in a database set aside for them, with its LOB tables when needed.
- CHECK DATA runs after the discard. CHECK DATA with DELETE YES removes the orphan rows and copies them to the exception tables, and the dependent tables are clear again.
- The check fits the conditions. When the dependent tables have discard conditions of their own that already remove every orphan, only the untouched dependents are checked. When orphans may remain, every table is checked. When integrity is guaranteed in another way, the pending state is simply reset.
The rows CHECK DATA removed stay in the exception tables. They can be listed per table and merged back into the source table once the reason for their removal has been resolved. Empty and expired exception tables are cleaned up by a regular job, which also reports the ones that still hold rows, so that no row is lost by mistake.
Every Discarded Row Kept and Recorded
The discarded rows are written to discard datasets, and TUC records every one of them with the table it belongs to and the run that wrote it. The names are resolved from the dataset templates, so the record does not depend on reading the job output, and it is complete even when the job was cancelled or restarted.
From the record, the data can be used again:
- Recalled. The rows can be browsed, sorted and edited, with the column layout identified automatically.
- Reloaded. All the datasets of one run can be loaded back into their source tables in a single step.
- Archived. The rows can be loaded into history tables under another owner, and TUC can create a missing archive table or add the columns it lacks.
Rows that a condition would discard can also be unloaded without removing them, for example to give the business a copy before the purge or to build an archive first and discard later.
Existing Archiving Jobs Under TUC Control
Many sites already have REORG DISCARD jobs, and many of them compute their conditions at run time: an application step works out the cut-off date or the keys to remove and writes them into the utility input. TUC takes control of those jobs without any change to their JCL. When the job calls REORG, TUC captures the discard conditions it was about to use, records them for each table under the job's name, and orders the REORG with exactly those conditions.
Because the conditions are captured again at every run, a job that computes them dynamically keeps working as it always has. The ordered work then gets everything described above: the dependent tables are checked, exception tables are created, the discarded rows are recorded, and when the original job waits for the result, the discard datasets are transferred into the output it expects, so its later steps read them as before.
Handled Automatically
Many details of REORG DISCARD are taken care of without the DBA having to know them:
- Tables with LOB columns. The options that LOB tables require are set, and options that would make the REORG fail with them are adjusted for that run only.
- Utility products. Where a REORG product does not leave dependent tables in check pending, the check is widened automatically so that orphans are still found.
- Restart. The work runs as an order with a recorded history, so a failed run can be restarted and the record of discarded rows stays complete.
Without and With TUC
| Task | Without TUC | With TUC |
| Who decides what is deleted | The DBA who writes the job. | The application, through its conditions, values or job. |
| Discard conditions | Written into each job's statements. | Defined once per table, apart from the jobs. |
| Changing the retention period | Edit every job that uses it. | Change one value or one row in a parameter table. |
| Conditions from business data | An application step builds the job input. | A query resolves the condition, repeated for each row it returns. |
| Tables with nothing to discard | Reorganized anyway. | Left alone. |
| Dependent tables | Found from the catalog and checked separately. | Added, checked and cleaned up in the same work. |
| Exception tables | Defined separately for each dependent table. | Created automatically, listed, merged back and cleaned up. |
| Discarded rows | In datasets nobody records. | Recorded, ready to recall, reload or archive. |
| Existing archiving jobs | Rewritten to change anything. | Taken over as they are, with their conditions captured at every run. |
In short — TUC turns REORG DISCARD into managed data archiving. The application decides what may be removed and when, and the DBA team processes it without owning that decision. The discard conditions belong to each table and are kept apart from the jobs, their values can come from the run or from a query, and the purge runs only where there is something to remove. Dependent tables are checked, exception tables are created, every discarded row is recorded and can be brought back, and existing archiving jobs come under the same control without a change to their JCL.
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article