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.
