Requirement is for COBOL; that's what the end-state program will be.
-----Original Message-----
From: IBM Mainframe Discussion List <[email protected]> On Behalf Of
Andrew Rowley
Sent: Friday, April 28, 2023 8:18 PM
To: [email protected]
Subject: Re: COBOL to dynamic DD name
On 29/04/2023 6:29 am, Schmitt, Michael wrote:
> I have an input file that contains thousands of records. They are in groups:
> header record, then a bunch of segments all for one database name, then
> another header, records for another database. But the same database can
> appear more than once in the input.
Have you considered Java?
This is untested, and I don't know File Manager so I'm not 100% sure of
the logic or even the field definitions, but it should give you the
idea. Run under JZOS Batch Launcher so JCL DDs are available.
A complete Java program:
import java.io.*;
import java.util.*;
import com.ibm.jzos.*;
import com.ibm.jzos.fields.*;
import com.ibm.jzos.fields.daa.*;
public class App
{
public static void main(String[] args) throws IOException
{
BinaryUnsignedIntField keyField = new BinaryUnsignedIntField(0, 2);
BinaryUnsignedIntField countField = new
BinaryUnsignedIntField(4, 4);
StringField ddField = new StringField(8, 8);
byte[] nextHeader = null;
Map<String, OutEntry> outEntries = new HashMap<>();
RecordReader in = null;
try
{
in = RecordReader.newReaderForDD("INPUT");
int bytesRead = 0;
byte[] record = new byte[in.getLrecl()];
while ((bytesRead = in.read(record)) >= 0)
{
if (keyField.getInt(record) == 0)
{
nextHeader = Arrays.copyOfRange(record, 0, bytesRead);
}
else
{
String ddname = ddField.getString(record);
OutEntry out = outEntries.get(ddname);
if (out == null)
{
out = new OutEntry(ddname);
outEntries.put(ddname, out);
out.writer.write(nextHeader);
}
out.count++;
countField.putInt(out.count, record);
out.writer.write(record, 0, bytesRead);
}
}
}
finally
{
if (in != null)
in.close();
for (OutEntry entry : outEntries.values())
{
entry.writer.close();
}
}
}
private static class OutEntry
{
OutEntry(String ddname) throws IOException
{
writer = RecordWriter.newWriterForDD(ddname);
}
int count = 0;
RecordWriter writer;
}
}
--
Andrew Rowley
Black Hill Software
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN