The CL program below will reorganize all physical files in all user libraries that contain deleted records. We run this program every weekend during off hours. The CL program creates a list of all user files on the system using the DSPFD command. A query then reads the file created above and selects only the physical data files that contain deleted records (MBNDTR NE 0) as shown in the query select statement below.
AND/OR Field Test Value
(Field, Number, 'Ch
MBFTYP EQ 'P'
AND MBDTAT EQ 'D' AND MBNDTR NE 0
AND MBFILE NLIST 'BIGPF'
The query outputs to file MYLIB/DLTRCDS1. The CL program then reads the file created in the query and reorganizes each file. You might want certain files excluded from the reorganization. This can be accomplished using the query NLIST test with the files to exclude as shown above.
I would initially try this on a couple of libraries to determine the time it takes on your system. We were previously doing reorganization on all files and this latest procedure cut the time to process from two days down to a couple of hours.PGM
DSPFD FILE(*ALLUSR/*ALL) TYPE(*MBR) +
/* QRY BELOW CREATES FILE MYLIB/DLTRCDS1 WHICH ONLY HAS FILES WITH */
/* DELETED RECORDS WHICH IS USED FOR THE REORG BELOW */
/* REORG FILES FROM ABOVE */
READ: RCVF /* Read a record */
MONMSG MSGID(CPF0864) EXEC(GOTO EOF) /* EOF */
MONMSG CPF2981 /* NOT REORGANIZED - POSSIBLY IN USE */