Using commands and APIs provided by ZOAU
With ZOAU, you can use shell commands, Python APIs, or your customized libraries to work with MVS resources in multiple ways.
For example, assume that you want to merge the following two data sets:
Data set 1:
USER.ZOAD.DFSORT.GROUPA
Charles Field 278 323 6045
David George 397 132 6025
William Young 178 333 5045
Data set 2:
USER.ZOAD.DFSORT.GROUPB
Emma Hill 149 589 5045
Sharon Miller 153 232 6045
Steve Green 748 111 6025
You could merge these two data sets with JCL in MVS by entering the following statements:
USER.MVSCMD.JCL(SORT)
//USERS JOB 'SORT',NOTIFY=&SYSUID,MSGCLASS=S,MSGLEVEL=(1,1)
//SORT EXEC PGM=SORT,PARM='MSGPRT=CRITICAL,LIST'
//SORTIN01 DD DSN=USER.MVSCMD.DFSORT.GROUPA,DISP=SHR
//SORTIN02 DD DSN=USER.MVSCMD.DFSORT.GROUPB,DISP=SHR
//SORTOUT DD DSN=USER.MVSCMD.DFSORT.MERGE,DISP=SHR
//SYSIN DD DSN=USER.MVSCMD.DFSORT.CMD,DISP=SHR
//SYSOUT DD SYSOUT=*
The merged data set looks as follows:
USER.MVSCMD.DFSORT.MERGE
Charles Field 278 323 6045
David George 397 132 6025
Emma Hill 149 589 5045
Sharon Miller 153 232 6045
Steve Green 748 111 6025
William Young 178 333 5045
Using shell commands
With ZOAU, you can opt to use a shell command to perform the sort operation, redirect output to stdout if needed, and quickly check the program return code for pass or fail.
For example, you can use the following single command, which is divided into multiple lines for readability:
mvscmd --pgm=sort --args='MSGPRT=CRITICAL,LIST'
--sortin01=user.mvscmd.dfsort.groupa
--sortin02=user.mvscmd.dfsort.groupb
--sysin=user.mvscmd.dfsort.cmd
--sortout=user.mvscmd.dfsort.merge
--sysout=*
The data set USER.MVSCMD.DFSORT.CMD
is as follows:
MERGE FORMAT=CH,FIELDS=(1,9,A)
Note: The characters #
and $
must be escaped with a backslash (like \#) or single-quoted (like '$') when used in shell commands.
To get help information for ZOAU shell commands, enter the utility name followed by -h
(such as dls -h
).
Calling Python APIs
With ZOAU, you can also perform the sort operation by calling the Python APIs.
First, import the Z Open Automation Utilities Python API packages:
from zoautil_py import mvscmd, datasets
from zoautil_py.ztypes import DDStatement
Next, create a list of DD statements to be used by the MVSCmd API:
dd_statements = []
dd_statements.append(DDStatement(name="sortin01",
definition="USR.MVSCMD.DFSORT.GROUPA"))
# Normally we create a definition, but you can use a string as
# shorthand for simple DDs.
dd_statements.append(DDStatement(name="sortin02",
definition="USR.MVSCMD.DFSORT.GROUPB"))
dd_statements.append(DDStatement(name="sysin",
definition="USR.MVSCMD.DFSORT.CMD"))
dd_statements.append(DDStatement(name="sortout",
definition="USR.MVSCMD.DFSORT.MRGE"))
dd_statements.append(DDStatement(name="sysout", definition="*"))
Finally, call the MVSCmd execute API to run the sort command, passing in the sort arguments and the list of DDStatements created in the previous step:
response = mvscmd.execute(pgm="sort", pgm_args="MSGPRT=CRITICAL,LIST", dds=dd_statements)
print(response.rc)