A dataset has many reports in it. I need the first report alone to another dataset. How can we achieve using JCL?
Below is the sample how the dataset looks like. My requirement is to sort out only the records under R0A report.
---Report - R0A---
List of Payments
Date : 23/07/2021
Name Payment-Amt Due-Date
AAAA 233.04 15/08/2021
BBBB 38.07 16/08/2021
---Report - R0B---
List of Payments
Date : 23/07/2021
Name Payment-Amt Due-Date
AAAA 233.04 15/08/2021
BBBB 38.07 16/08/2021
---Report - R0C---
List of Payments
Date : 23/07/2021
Name Payment-Amt Due-Date
AAAA 233.04 15/08/2021
BBBB 38.07 16/08/2021
If the size of the reports is fixed, you can use sort with the COPY
and STOPAFT=
options:
SORT FIELDS=COPY,STOPAFT=6
If you need a report beyond the first, you can add the SKIPREC=
option. E.g. to get the third report, specify:
SORT FIELDS=COPY,SKIPREC=12,STOPAFT=6
If the reports differ in length, you could run a simple REXX.
/* REXX - NOTE This is only a skeleton. Error checking must be added. */
/* This code has not been tested, so thorough testing is due. */
"ALLOC F(INP) DS('your.fully.qualed.input.data.set.name') SHR"
"EXECIO * DISKR INP ( STEM InpRec. FINISH"
"FREE F(INP)"
TRUE = 1
FALSE = 0
ReportStartIndicator = "---Report"
ReportName = "- R0B---"
ReportHeader = ReportStartIndicator ReportName
ReportCopy = FALSE
do ii = 1 to InpRec.0 while ReportCopy = FALSE
if InpRec.ii = ReportHeader
then ReportCopy = TRUE
end
if ReportCopy
then do
OutRec.1 = InpRec.ii
Outcnt = 1
do jj = ii + 1 to InpRec.0 while ReportCopy = TRUE
if word( InpRec.jj, 1 ) = ReportStartIndicator /* Start of next report? */
then ReportCopy = FALSE
else do
OutCnt = OutCnt + 1
OutRec.Outcnt = InpRec.jj
end
end
"ALLOC F(OUT) DS('your.fully.qualed.output.data.set.name')" ,
"NEW CATLG SPACE(......) RECFM(....) LRECL(....)"
"EXECIO" OutCnt "DISKW OUT ( STEM OutRec. FINIS"
"FREE F(OUT)"
say "Done copying report." OutCnt "records have been copied."
end
else do
say "Report" ReportName "not found."
exit 16
end
As written in the comment in the REXX, I haven't tested this code. Also, error checking need to be added, especially for TSO HOST commands (ALLOC, EXECIO, FREE).
All of the solutions copy a single report to another data set. In the title, you wrote to multiple datasets. I'm sure you'll find solutions for this using above single report solutions.