Copying Unix files to MVS Datasets

A common task in z/OS environments is moving data between the Unix file system and traditional MVS datasets. Here is how to do it using the OCOPY utility in a JCL batch job.

As mentioned in the previous post, another sample. This one copies a z/OS unix file to an MVS dataset. Also using OCOPY.

When working with z/OS, you often need to move data between the Unix file system (zFS) and traditional MVS datasets. This is a common task for system administrators and developers integrating Unix-based tools with mainframe applications.

The OCOPY utility is the standard tool for this. It handles character set conversion between ASCII (Unix) and EBCDIC (MVS) automatically when you specify TEXT and CONVERT(YES).

//STEP5 EXEC PGM=IKJEFT01 
//INUNIX DD PATH='/mydir/infile.txt',PATHOPTS=(ORDONLY) 
//OUTMVS DD DSN='TEST.MVS.OUTDS',DISP=SHR 
//* 
//SYSTSPRT DD SYSOUT=* 
//SYSTSIN DD * 
//SYSTSIN DD * 
 OCOPY IND(INUNIX) OUTDD(OUTMVS) TEXT CONVERT(YES) PATHOPTS(USE) 
/* 
 

Parameters explained

  • INUNIX: The Unix input file (ORDONLY = open for read only)
  • OUTMVS: The target MVS dataset
  • TEXT: Tells OCOPY this is text data (triggers EBCDIC conversion)
  • CONVERT(YES): Enables ASCII to EBCDIC conversion
  • PATHOPTS(USE): Uses the PATHOPTS specified on the DD statement

The reverse: copying MVS to Unix

To copy in the other direction (MVS dataset to Unix file), simply swap the IND and OUTDD parameters and adjust the DD statements accordingly. See: Copying MVS Datasets to Unix files

Working with both Unix and MVS on z/OS is a perfect example of how modern the mainframe platform really is. Want to understand the full picture of modern mainframe capabilities? My book Don’t Be Afraid of the Mainframe covers the Unix side of z/OS, integration patterns, and much more.

Learn more →

Copying MVS Datasets to Unix files

Recently I had to get some people started with a few utilities. I thought to share this here. They will be in the next few posts for searchability reasons.

There are more ways to Rome, as we say here, so please feel free share you variants in a comment. (I unfortunately need manually curate comments to filter out the spam which is even with this small site overwhelming.)

//STEP1 EXEC PGM=IKJEFT01
//INMVS DD DSN=TEST.TRADMVS.DATA,
// DISP=SHR
//OUTFILE DD FILEDATA=TEXT,
// PATHOPTS=(OWRONLY,OCREAT,OTRUNC),
// PATHMODE=SIRWXU,
// PATH='/mydir/myunixfile.txt’
//SYSTSPRT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*//SYSTSIN DD *
 OCOPY IND(INMVS) OUTDD(OUTFILE)
//*

Here’s a link to the IBM documentation on OCOPY.