CRTDUPOBJ & CPYF
CRTDUPOBJ & CPYF are the two commands that are often used when it comes to creating a copy of the object and copying the data from a physical file to another.
Let's have a detailed look at each of these commands in detail and see the difference between two of them.
CRTDUPOBJ (Create Duplicate Object)
The Create Duplicate Object (CRTDUPOBJ) command copies a single object or a group of objects. It does not create an exact duplicate of files.CRTDUPOBJ can be used to copy a group of related objects by specifying a generic object name or by specifying *ALL or more than one object type.
When copying a group of related objects, 'To Library (TOLIB)' should be different from From Library (FROMLIB).
You can specify whether data in physical files or save files is copied. You can also specify whether any constraints or triggers associated with an existing database file are to be associated with the newly-created file and whether the file level and member level identifiers of an existing database file are to be copied to the newly-created database file.
CRTDUPOBJ on a Logical File will create Logical File. But, Dependent Physical File should be available on Target Library.
Below are some important parameters to note while copying Files.
- Duplicate Data (DATA) - *YES to copy the data from 'FROM FILE', '*NO' to not copy the data from 'FROM FILE'.
- Duplicate Constraints (CST) - *YES to copy the constraints from 'FROM FILE', '*NO' to not copy the constraints from 'FROM FILE'.
- Duplicate Triggers (TRG) - '*YES' to copy the triggers from 'FROM FILE', '*NO' to not copy the triggers from 'FROM FILE'.
- Duplicate File Identifiers (FILEID) - '*YES' to use the File level and Member level identifiers to create the 'TO FILE', '*NO' to not use the File level and Member level identifiers to create the 'TO FILE'.
CPYF (Copy File)
The Copy File (CPYF) command copies all or part of a file from the database or from an external device to the database or to an external device. It can,- Copy data and source files between database files. Records can be copied from physical or logical files. However, records can be copied only to physical files, not to logical files.
- Copy data and source files from external devices, such as diskette and tape, to the database.
- Copy data and source files from the database to external devices.
- Copy data and source files from external devices to other external devices.
- Copy data and source files from inline data files to the database or to external devices.
Below are some important parameters while using CPYF.
- Replace or Add records (MBROPT) - '*ADD' to add the records to the end of the current set of records, '*REPLACE' to replace the records in TOFILE, '*UPDADD' - to update the duplicate key records and add the new records.
- Create File (CRTFILE) - '*YES' to create the TOFILE, '*NO' if TOFILE is already present. CPYF on Logical file with CRTFILE(*YES) will create a Physical file and copies data.
- Record Format Field Mapping (FMTOPT) - '*NONE' no field mapping is done, '*NOCHK' if the record formats are different, no check would happen and records are directly copied, '*MAP *DROP' is used to map the fields and copy the data and drop if no matching fields present.
- Include Records by char test (INCCHAR) and/or Include Records by Field test (INCREL) - used to validate the record in the from file and copy to TOFILE if the condition satisfies.
- Number of Records to copy (NBRRCDS) - Specify the number of records to be copied. '*END' to copy all the records.
And, the difference (CRTDUPOBJ vs CPYF)?
- CRTDUPOBJ needs to allocate the file in order to create the duplicate. CPYF doesn't need to allocate the file to copy the data.
- CRTDUPOBJ would create a copy of the file with either no data or full data. With CPYF Subset of data can be copied using RRN, Key values, INCCHAR or INCREL.
- CPYF is also useful when populating a new version of the file which has new fields added (or removed) as fields can be transposed using FMTOPT(*MAP *DROP).
Comments
Post a Comment