Good suggestion Marc. Only comment I have is that, especially on a library with numerous files, is that many people forget to scroll all the way to the bottom, or use the icon near the lower left in Run SQL Scripts to go to the bottom. So their work around is to wrap the above in a create table like this:
create table qtemp.memberlist as (
SELECT TABLE_NAME, SYSTEM_TABLE_MEMBER, QSYS2.QCMDEXC('CLRPFM FILE(yourlib/' concat TABLE_NAME concat ') MBR(' concat SYSTEM_TABLE_MEMBER concat ')')
FROM QSYS2.SYSMEMBERSTAT
WHERE TABLE_SCHEMA = 'yourlib'
) with data
------------------------------
Robert Berendt IBMChampion
Business Systems Analyst, Lead
Dekko
Fort Wayne
------------------------------
Original Message:
Sent: Mon January 20, 2025 03:48 AM
From: Marc Rauzier
Subject: Backup of PF & LF
Hello
I am not aware of any way to save physical files without data. But you could try to use CPYLIB DATA(*NO) to create a new library without data. However, there are some ownership and authority changes when using this command. Checkout https://www.ibm.com/docs/en/i/7.5?topic=ssw_ibm_i_75/cl/cpylib.html.
So, if you restore the library like it was saved, you can try to play with IBM i SQL Services to clear all members.
I did not complete full tests with the following, but you can use:
SELECT TABLE_NAME, SYSTEM_TABLE_MEMBER, QSYS2.QCMDEXC('CLRPFM FILE(yourlib/' concat TABLE_NAME concat ') MBR(' concat SYSTEM_TABLE_MEMBER concat ')')
FROM QSYS2.SYSMEMBERSTAT
WHERE TABLE_SCHEMA = 'yourlib';
Checkout https://www.ibm.com/docs/en/i/7.5?topic=services-qcmdexc-scalar-function and https://www.ibm.com/docs/en/i/7.5?topic=services-sysmemberstat-view
------------------------------
Marc Rauzier
------------------------------