CopyToPDS

This command is used to copy source files, binary files, and load modules from a zSeries File System (zFS) to a partitioned data set (PDS). The source of the command can be one of the following types:

  • A single zFS file
  • A zFS directory
  • A list of physical dependencies generated by the DBB DependencyResolver

The target of the command is a PDS. By default, the copied PDS member name is derived from the source file name by removing any file extension and uppercasing the result. When copying a single file, an optional PDS member name can be set.

// Copy a single file
def copyFile = new CopyToPDS()
copyFile.setFile(new File("/u/usr1/build/helloworld.cbl"))
copyFile.setDataset("USR1.BUILD.COBOL")
copyFile.setMember("HELLO")
copyFile.execute()

// CopyToPDS supports setter method chaining
new CopyToPDS().file(new File("/u/usr1/build/helloworld.cbl")).dataset("USR1.BUILD.COBOL").member("HELLO").execute()

// Copy a entire directory to PDS
new CopyToPDS().file(new File("/u/usr1/src/cobol")).dataset("USR1.SRC.COBOL").execute()

//Copy resolved dependencies to PDS
def resolver = tools.getDefaultDependencyResolver(file)
def deps = resolver.resolve()
new CopyToPDS().dependencies(deps).dataset("USR1.SRC.COPYBOOK").execute()

The CopyToPDS class also has a createMemberName(name) static method that can be used to create a PDS member name from a zFS file path. It can be useful if the member name of a copied file is needed later in a build script.

def fileName = "/u/usr1/build/hello.cbl"
def dsName = "USR1.BUILD.COBOL"
def memberName = CopyToPDS.createMemberName(fileName)  // memberName = HELLO
new CopyToPDS().file(new File(fileName)).dataset(dsName).member(memberName).execute()
. . .
compile.dd(new DDStatement().name("SYSIN").dsn("$dsName($memberName)").options("shr"))

The value of copyMode can be TEXT, BINARY, or LOAD. If copyMode is not specified, the default TEXT is used. For more information, see setCopyMode(DBBConstants.CopyMode copyMode) and copyMode(DBBConstants.CopyMode copyMode) in Class CopyToPDS in the DBB Javadoc.

Archive files support

You can also use CopyToPDS to copy files contained within archives. This is useful for copying binary or text files to a data set from archived or compressed archive files.

// copy individual binary file with standard member name
copy = new CopyToPDS()
copy.setDataset("USR.INDIV") // data set to copy to
copy.setArchive("archive/archive_bin.tar") // acrhive to copy from
copy.setArchivedFile("bin/EPSMLIST").copyMode(CopyMode.BINARY) // file in archive
copy.execute()

// CopyToPDS supports setter method chaining
cmd = new CopyToPDS().dataset("USR.INDIV").archive("archive/archive_bin.tar").archivedFile("bin/EPSMLIST").copyMode(CopyMode.BINARY)
cmd.execute()

Handling code pages

By default, the copied PDS member has the same code page as the source zFS file. The code page of the file is determined in the following order:

  1. The file encoding tag of the source file is used if present.

    • Rocket Git client automatically adds file encoding tags when cloning or pulling source files from a distributed Git server.
  2. The ZLANG environment variable is used if set.

  3. The default IBM-1047 code page is used.

Additionally, you can manually set both the source file code page and the target data set member code page.

// Indicates that the file is encoded as IBM-037 and will write the PDS member as IBM-037
new CopyToPDS().file(new File(fileName)).hfsEncoding("IBM-037").dataset(dsName).member(memberName).execute()

If the PDS encoding differs from the HFS encoding, a code page conversion is automatically performed during the copy process.

// Indicates that the file is encoded as UTF-8 and will write the PDS member as IBM-1047
new CopyToPDS().file(new File(fileName)).hfsEncoding("UTF-8").dataset(dsName).member(memberName).pdsEncoding("IBM-1047").execute()

Note: The PDS and HFS encoding options are applied only when the value of copyMode is TEXT. These values are ignored for BINARY or LOAD values.