Read text in a data set

The following samples show how to read text in a data set.

Scenario 1: The entire file

With ZOAU, you can print the data set ${prefix}.MY.DCAT in the following ways:

  • Issuing a shell command:

    • Option 1:
    dcat "${prefix}.MY.DCAT"
    
    • Option 2:
    mvscmd --pgm=IEBGENER --sysprint=* --sysin=dummy --sysut2=* --sysut1="${prefix}.MY.DCAT"
    

  • Calling an API in Python programs:

    datasets.read("%s.MY.DCAT" % HLQ)
    

Without ZOAU, to achieve the same purpose, you need to write the following JCL statements:

//* Print the contents of @@HLQ@@.ZOASAMP.MY.DCAT
//* to SYSUT2 (the console)
//*
//DCAT  EXEC PGM=IEBGENER
//SYSPRINT DD SYSOUT=*
//SYSIN   DD DUMMY
//SYSUT1  DD DSN=@@HLQ@@.ZOASAMP.MY.DCAT,DISP=SHR
//SYSUT2  DD SYSOUT=*


Scenario 2: First n lines

With ZOAU, you can print the first 5 lines of data set ${prefix}.MY.DHEAD in the following ways:

  • Issuing a shell command:

    • Option 1:
    dhead -n 5 "${prefix}.MY.DHEAD"
    
    • Option 2:
    mvscmd --pgm=ICETOOL --toolmsg=dummy --dfsmsg=dummy --out=* --in="${prefix}.MY.DHEAD" --toolin=stdin <<zz
    SUBSET FROM(IN) TO(OUT) KEEP INPUT HEADER(5)
    zz
    

Without ZOAU, to achieve the same purpose, you need to write the following JCL statements:

//*
//* Write the first 5 lines of @@HLQ@@.ZOASAMP.MY.DHEAD
//* to OUT (the console).
//* Returns 0 if successful, non-zero otherwise
//*
//DHEAD EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG  DD SYSOUT=*
//IN      DD DSN=@@HLQ@@.ZOASAMP.MY.DHEAD,DISP=SHR
//OUT     DD SYSOUT=*
//TOOLIN DD *
  SUBSET FROM(IN) TO(OUT) KEEP INPUT HEADER(5)
/*


Scenario 3: Last n lines

With ZOAU, you can print the last 2 lines of data set ${prefix}.MY.DTAIL in the following ways:

  • Issuing a shell command:

    • Option 1:
    dtail -n -2 "${prefix}.MY.DTAIL"
    
    • Option 2:
    mvscmd --pgm=ICETOOL --toolmsg=dummy --dfsmsg=dummy --out=* --in="${prefix}.MY.DTAIL" --toolin=stdin <<zz
    SUBSET FROM(IN) TO(OUT) KEEP INPUT LAST(2)
    zz
    

  • Calling an API in Python programs:

    datasets.read("%s.MY.DTAIL" % HLQ, tail=2)
    

Without ZOAU, to achieve the same purpose, you need to write the following JCL statements:

//*
//* Write the last 2 lines of the dataset
//* @@HLQ@@.ZOASAMP.MY.DTAIL to OUT (the console)
//* Returns 0 if successful, non-zero otherwise
//*
//DTAIL EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG  DD SYSOUT=*
//IN      DD DSN=@@HLQ@@.ZOASAMP.MY.DTAIL,DISP=SHR
//OUT     DD SYSOUT=*
//TOOLIN DD *
  SUBSET FROM(IN) TO(OUT) KEEP INPUT LAST(2)
/*

Scenario 4: From the nth line

With ZOAU, you can print from the third line of dataset ${prefix}.MY.DTAIL in the following ways:

  • Issuing a shell command:

    • Option 1:
    dtail -n +3 "${prefix}.MY.DTAIL"
    
    • Option 2:
    mvscmd --pgm=ICETOOL --toolmsg=dummy --dfsmsg=dummy --out=* --in="${prefix}.my.dtail" --toolin=stdin <<zz
    SUBSET FROM(IN) TO(OUT) REMOVE INPUT FIRST(2)
    zz
    

  • Calling an API in Python programs:

    datasets.read("%s.MY.DTAIL" % HLQ, from_line=3)
    

Without ZOAU, to achieve the same purpose, you need to write the following JCL statements:

//*
//* Write from the first 3 lines of @@HLQ@@.ZOASAMP.MY.DTAIL
//* to OUT (the console).
//* Returns 0 if successful, non-zero otherwise
//*
//DHEAD EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG  DD SYSOUT=*
//IN      DD DSN=@@HLQ@@.ZOASAMP.MY.DTAIL,DISP=SHR
//OUT     DD SYSOUT=*
//TOOLIN DD *
  SUBSET FROM(IN) TO(OUT) REMOVE INPUT FIRST(2)
/*