CRTDUPOBJ and Logical Files
September 8, 2004 Hey, Ted
I want to build some test libraries from my production libraries. I am having trouble duplicating logical files that are stored in one library but point to physical files in another library. I thought Create Duplicate Object (CRTDUPOBJ) would create a logical in one test library but point it to another test library if the library list was set correctly. What is the best method to copy logical files and point them to the correct physical files?
You have to be careful when using CRTDUPOBJ with logical files. Which physical file the new logical file is based on depends on whether the original physical file and logical file are in the same library or in different libraries. Here are the rules.
Rule 1: If the logical file being copied and the physical file upon which it is based are in the same library, the new logical file will be based on a physical file in the library in which the new logical is being created.
Rule 2: If the logical file being copied and the physical file upon which it is based are in different libraries, the new logical will be based on the original physical file.
The library list doesn’t even enter the picture.
Maybe an example will make it clearer. Assume four libraries: PROD1, PROD2, TEST1, and TEST2. PROD1 and PROD2 contain the production data. TEST1 and TEST2 are to contain the duplicated objects.
Assume PROD1 has a physical file, CUSTOMER, which has two logical files. Logical file CUSTOMER1 is in PROD1, but logical file CUSTOMER2 is in PROD2. Your goal is to create physical file CUSTOMER and logical file CUSTOMER1 in TEST1, and to create logical file CUSTOMER2, based on TEST1/CUSTOMER, in TEST2.
You can use CRTDUPOBJ to create CUSTOMER1 and CUSTOMER2 in TEST1.
CRTDUPOBJ OBJ(CUSTOMER) FROMLIB(PROD1) + OBJTYPE(*FILE) TOLIB(TEST1) CRTDUPOBJ OBJ(CUSTOMER1) FROMLIB(PROD1) + OBJTYPE(*FILE) TOLIB(TEST1)
But if you use CRTDUPOBJ to create TEST2/CUSTOMER2, the system will build the new logical over PROD1/CUSTOMER.
It would be nice if Change Physical File (CHGPF) would allow you to assign a different physical file to a logical file, but it won’t. You can use Remove Member (RMVM) to remove the member of the new logical file, but Add Logical File Member (ADDLFM) won’t let you specify TEST1/CUSTOMER.
Here is a roundabout way to make the new logical point to the other test library.
First, duplicate the “renegade” logical to the same production library where its physical file resides.
CRTDUPOBJ OBJ(CUSTOMER2) FROMLIB(PROD2) + OBJTYPE(*FILE) TOLIB(PROD1)
At this point, PROD1/CUSTOMER has three logical files: PROD1/CUSTOMER1, PROD1/CUSTOMER2, and PROD2/CUSTOMER2.
Duplicate the logical you just created to the library containing the test copy of the physical.
CRTDUPOBJ OBJ(CUSTOMER2) FROMLIB(PROD1) + OBJTYPE(*FILE) TOLIB(TEST1)
Since the copied logical was in the library that contained its physical file, TEST1/CUSTOMER2 points to TEST1/CUSTOMER.
Move the test CUSTOMER2 to the second test library.
MOVOBJ OBJ(TEST1/CUSTOMER2) + OBJTYPE(*FILE) TOLIB(TEST2)
TEST2/CUSTOMER2 continues to point to physical file TEST1/CUSTOMER.
Be sure to delete the copy of the logical file that you made in the production library.
I don’t like roundabout methods. I hope there’s an easier way that I’m overlooking and that someone will tell me about it.