TSO provides powerful commands for handling files and datasets on the mainframe. Understanding these commands is essential for managing data, copying files, viewing contents, and working with dataset attributes. This tutorial covers the key TSO commands for dataset handling: ALLOCATE, FREE, REPRO, PRINT, and LISTDS.
These commands form the foundation of dataset operations in TSO. While ISPF provides menu-driven interfaces for many of these operations, knowing the TSO command syntax gives you flexibility, enables scripting, and allows you to perform operations from the command line efficiently.
The ALLOCATE command associates a dataset with a DD (Data Definition) name, making it available for use by programs or TSO commands. Allocation is a fundamental operation that connects datasets to the programs and commands that need to access them.
The basic syntax for ALLOCATE is:
1ALLOCATE FILE(DDNAME) DATASET('DSNAME') [options]
Where:
Common ALLOCATE options include:
Allocate a dataset for shared read access:
1ALLOCATE FILE(INPUT) DATASET('USERID.SOURCE.COBOL') SHR
Allocate a dataset for exclusive write access:
1ALLOCATE FILE(OUTPUT) DATASET('USERID.OUTPUT.DATA') OLD
Allocate a new dataset:
123ALLOCATE FILE(NEWFILE) DATASET('USERID.NEW.DATA') NEW - SPACE(TRK,(10,5)) - RECFM(FB) LRECL(80) BLKSIZE(3120)
The FREE command releases an allocation, freeing the DD name and making it available for other uses. FREE is important for resource management and cleanup.
To free a specific allocation:
1FREE FILE(DDNAME)
To free all allocations:
1FREE ALL
Use FREE when:
While allocations are automatically freed when you log off, it's good practice to explicitly free allocations when you're done with them, especially in scripts or long-running sessions.
Free a specific allocation:
1FREE FILE(INPUT)
Free all current allocations:
1FREE ALL
The REPRO command copies data from one dataset to another. REPRO can copy entire datasets or specific members from partitioned datasets, making it useful for backing up data, duplicating datasets, or copying data between locations.
To copy data using REPRO, you first allocate both the input and output datasets, then use REPRO:
1234ALLOCATE FILE(INFILE) DATASET('SOURCE.DSNAME') SHR ALLOCATE FILE(OUTFILE) DATASET('TARGET.DSNAME') OLD REPRO INFILE(INFILE) OUTFILE(OUTFILE) FREE FILE(INFILE) FILE(OUTFILE)
REPRO supports various options:
Copy an entire sequential dataset:
1234ALLOCATE FILE(IN) DATASET('USERID.SOURCE.DATA') SHR ALLOCATE FILE(OUT) DATASET('USERID.BACKUP.DATA') OLD REPRO INFILE(IN) OUTFILE(OUT) FREE FILE(IN) FILE(OUT)
Copy a member from a PDS:
1234ALLOCATE FILE(IN) DATASET('USERID.SOURCE.COBOL(MEMBER1)') SHR ALLOCATE FILE(OUT) DATASET('USERID.BACKUP.COBOL(MEMBER1)') OLD REPRO INFILE(IN) OUTFILE(OUT) FREE FILE(IN) FILE(OUT)
The PRINT command displays dataset contents on your terminal or sends them to a printer. PRINT is useful for viewing dataset contents, generating printed output, or examining data.
To print dataset contents to your terminal:
1PRINT 'USERID.SOURCE.COBOL'
To send output to a printer:
1PRINT 'USERID.SOURCE.COBOL' DEST(printername)
PRINT may support options like:
Display dataset contents on terminal:
1PRINT 'USERID.SOURCE.COBOL'
Print a specific member:
1PRINT 'USERID.SOURCE.COBOL(MEMBER1)'
The LISTDS command displays dataset attributes and information. LISTDS helps you understand dataset structure, properties, and characteristics.
To list dataset information:
1LISTDS 'USERID.SOURCE.COBOL'
LISTDS displays information including:
LISTDS may support options like:
List basic dataset information:
1LISTDS 'USERID.SOURCE.COBOL'
List dataset information with members (for PDS):
1LISTDS 'USERID.SOURCE.COBOL' MEMBERS
These commands are often used together in workflows. Here's an example workflow:
A complete workflow might look like:
1234567LISTDS 'USERID.SOURCE.COBOL' ALLOCATE FILE(IN) DATASET('USERID.SOURCE.COBOL') SHR ALLOCATE FILE(OUT) DATASET('USERID.BACKUP.COBOL') OLD REPRO INFILE(IN) OUTFILE(OUT) FREE FILE(IN) FILE(OUT) LISTDS 'USERID.BACKUP.COBOL' PRINT 'USERID.BACKUP.COBOL'
This workflow:
Following best practices helps you use these commands effectively and safely:
These commands are commonly used for:
Think of dataset handling commands like tools for working with filing cabinets:
So these commands help you work with the computer's filing system, opening drawers, copying files, looking at what's inside, and reading the labels!
Complete these exercises to reinforce your understanding of TSO dataset handling commands:
Practice allocating datasets with different options. Allocate a dataset with SHR, then with OLD. Use LISTDS to verify the allocations. Practice freeing allocations individually and with FREE ALL. Document your experiences.
Create a complete workflow using REPRO: allocate source and target datasets, copy data using REPRO, verify the copy with LISTDS and PRINT, then free the allocations. Practice this workflow until it becomes natural.
Use LISTDS to examine various datasets in your environment. Document the attributes you find (RECFM, LRECL, BLKSIZE, organization, etc.). Use PRINT to view the contents of some datasets. Compare LISTDS output with what you see in PRINT.
Create workflows that combine multiple commands. For example, list a dataset, allocate it, print it, copy it, list the copy, and clean up. Practice creating efficient command sequences for common tasks.
Practice handling common errors: try to allocate a non-existent dataset, try to copy to a dataset that doesn't exist, try operations with insufficient permissions. Learn to read error messages and understand what went wrong.
1. What command copies data from one dataset to another?
2. What command lists dataset attributes?
3. What command prints dataset contents?
4. What does ALLOCATE do?
5. How do you free all allocations?