dos2unix on z/OS

  • Post category:Utilities
  • Reading time:1 mins read

On z/OS UNIX, the dos2unix utility is not included. You can achieve similar functionality using other tools available on z/OS UNIX, such as sed or tr. These tools can be used to convert DOS-style line endings (CRLF) to Unix-style line endings (LF).

For example, you can use sed to remove carriage return characters:

sed 's/\r$//' inputfile > outputfile

Or you can use tr

tr -d '\r' < inputfile > outputfile

Exchange an MVS dataset with Windows

  • Post category:Utilities
  • Reading time:2 mins read

I have discussed in another article how you can convert data from one codepage to another.

Also I have described a method to copy unix files to MVS datasets.

This article summarizes a method to copy an MVS dataset to Windows, while keeping records and converting from ebcdic to the utf8 codepage.

This job copies the MVS dataset to a UNIX files, indicating to keep record indicators with the Windows CR character (UNIX uses the CRLF typically as record / line separators). The dataset below ‘YOUR.TEST.PS’ should be a PS – physical sequential – dataset or a PDS(E) member.

//STEP1    EXEC PGM=BPXBATCH                                         
//STDOUT   DD SYSOUT=*                                               
//STDERR   DD SYSOUT=*                                                
//STDIN    DD DUMMY    
//* Values in STDENV below are kept but have no meaning for this function                                              
//STDENV   DD *                                                      
JAVA_HOME=/usr/lpp/java/J8.0_64                                      
PATH=/usr/lpp/mqm/web/bin:/bin:/usr/sbin                      
LIBPATH=/usr/lpp/mqm/java/lib                                 
//STDPARM  DD   *                                                    
SH cp -v -F cr "//'YOUR.TEST.PS'" /your/unixdir/tst.txt 

You can now convert the EBCDIC data to UTF-8 as follows:

iconv -f 37 -t 1208 /your/unixdir/tst.txt  > /your/unixdir/utf8-tst.txt

Now you can transfer the file to Windows. Transfer the file in binary mode, otherwise another unwanted code page conversion will happen.

Test if a directory exists in z/OS Unix System Services

  • Post category:Utilities
  • Reading time:1 mins read

Snippet of shell script code to test if a directory exists in z/OS Unix System Services.

#!/bin/sh                                
DEST="/app/somedirectory"                        
if test -d "$DEST"                       
then                                     
    # It is a directory #                
    echo "Directory found ..."           
else                                     
    # does not exist                     
    echo "Directory does not exist"      
fi            

Converting any file from one code page to another

  • Post category:Utilities
  • Reading time:1 mins read

The easiest way on z/OS to convert a file from one code page to another is to use the standard unix iconv utility.

The sample below is using a traditional batch job, but you can see it can just as easily be run from a shell environment or a shell script.

//STEP1    EXEC PGM=BPXBATCH                                   
//STDERR   DD SYSOUT=*                                         
//STDPARM  DD   *                                              
SH  iconv -f UTF-8 -t IBM-1140 inputfile.utf8 outputfile.ebcdic                
/*                                                             
//      ebcdic - Windows                                                       
SH  iconv -f IBM-1140 -t IBM-1252 inputfile.ebcdic outputfile.ibm1252            
//      Windows - ebcdic                                                        
SH  iconv -f IBM-1252 -t IBM-1140 inputfile.ibm1252 outputfile.ibm1140           
//      ebcdic - utf8                                                       
SH  iconv -f IBM-1140 -t UTF-8 inputfile.ebcdic outputfile.utf8                
//                                                              
 

A job to submit a job

  • Post category:JCLUtilities
  • Reading time:1 mins read

A simple trick that is often used in more complex JCL scripts, is to submit a job from a job. z/OS has a facility for this called the Internal Reader. The name Internal Reader stems from the old days when physical devices where used to read input in punch cards. These physical devices where called (external) readers. The Internal Reader is a logical device operating functionally, but virtually, like the physical device from the old days.

Anyway, this is the JCL.

//SUBJOB EXEC PGM=IEBGENER
//SYSIN DD DUMMY
//SYSPRINT DD DUMMY
//SYSUT1 DD DSN=DATASET.NAME.JCL(NEXTJOB),DISP=SHR
//SYSUT2 DD SYSOUT=(A,INTRDR)

With this JCL you copy the JCL script in dataset DATASET.NAME.JCL(NEXTJOB) to the internal reader, which fundamentally submit the content as a job.

Turning a PDS into a PS with standard tools (for email)

  • Post category:Utilities
  • Reading time:2 mins read

I recently got a question from a collegue. He wanted to transfer an entire PDS in an email to someone else. You can download all the member of the PDS with FTP, zip up all the files and transfer that. But it might be easier to use this trick.

Create a PS from in PDS by using the XMIT command. XMIT is a TSO command that you can use to transfer a dataset to another user, or system, or both.

The trick now to “zip” a PDS with XMIT is to XMIT the PDS to yourself on the same system:

xmit userid.node dsn(dataset) outdsn(outdsn)

This creates the “zipped” PS dataset, that you can send through email. If you download the file to your Mac or PC, makes sure you download it in binary mode.

The receiver can “unzip” the file into a PDS with the accompanying receive command:

RECEIVE INDSN(dataset) DSN(outdataset)

Filewatch utility – file triggering

  • Post category:JCLUtilities
  • Reading time:2 mins read

The filewatch utility is not a well known utility, that can be very handy. I have used it especially when I needed process a unix file after it has been copied to a certain directory.

This is the documentation about the filewatch utility:

https://www.ibm.com/support/knowledgecenter/SSRULV_9.3.0/com.ibm.tivoli.itws.doc_9.3/zos/src_man/eqqr1hfszfstrig.htm

Th job below is submitted and then waiting and activated when there is a change in the input directory /yourdirectory/testfileloc

The job itself moves the files in the input directory to a processing directory, starts the next “watch” job and then the processing job for the files in the processing directory.

The setup is clearly to test the mechanism – and not necessarily a model for a production-like situation. In a production situation you might want to use TWS applications etc, but that is up to your application design of course.

I hope this helps.

 //STEP01  EXEC PGM=EQQFLWAT,PARM='/-c wcr -dea 900 -i 20
 //             -r 123 -t 3 -fi /yourdirectory/testfileloc'
 //*
 //* Register and move files
 //RUNSCRPT EXEC PGM=IKJEFT01,REGION=0M
 //STDOUT   DD SYSOUT=*
 //STDERR   DD SYSOUT=*
 //SYSTSPRT DD SYSOUT=*
 //SYSTSIN  DD *
 BPXBATSL SH  -
   mv /yourdirectory/testfileloc* /yourdirectory/testfileloc/processing
 //*
 //* Then kick off separate job
 //* - Next filewatch job
 //*
 //SUBJOB   EXEC PGM=IEBGENER
 //SYSIN    DD DUMMY
 //SYSPRINT DD DUMMY
 //SYSUT1   DD DISP=SHR,DSN=YOURPDS.JCL(EQQFLWAT)
 //SYSUT2   DD SYSOUT=(A,INTRDR)
 //*
 //* - Processing job
 //*
 //SUBJOB   EXEC PGM=IEBGENER
 //SYSIN    DD DUMMY
 //SYSPRINT DD DUMMY
 //SYSUT1   DD DISP=SHR,DSN=YOURPDS.JCL(PROCJOB)
 //SYSUT2   DD SYSOUT=(A,INTRDR)
 //*
 //* 

Code page conversion of a file in a batch job

  • Post category:JCLUtilities
  • Reading time:2 mins read

In this post a sample of how to perform a code page conversion of z/OS Unix files in a batch job. The different iconv utility lines show invocation for different code pages.

//*                                      
//STEP1    EXEC PGM=BPXBATCH   
//STDERR   DD SYSOUT=*  
//STDPARM  DD   *              
 SH  iconv -f UTF-8 -t IBM-1140 < inutf8 > outebc 
/*                                                     
//               
 SH  iconv -f IBM-1140 -t IBM-1252 < inebc > out1252 
//  
 SH  iconv -f IBM-1252 -t IBM-1140 < in1252 > out1140 
//     
 SH  iconv -f IBM-1140 -t UTF-8 < inebc > oututf8  
 //                       

Copying Unix files to MVS Datasets

  • Post category:JCLUtilities
  • Reading time:1 mins read

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

//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) 
/*