ZFile.read() to prds members returning extraneous data

General discussion on the JZOS batch launcher and toolkit
Post Reply
cscs010
Posts: 37
Joined: Tue Jul 31, 2007 3:50 pm

ZFile.read() to prds members returning extraneous data

Post by cscs010 »

I am trying to read members from a fixed length pds and ZFile seems to return extra data which is not in the file.

for example,
this pds is defined with lrecl=80,blksize=18400,recfm=fb

this member ZRECSTST contains 2 records:


ISPF EDIT DISPLAY:


RECORD11111111111111111111111111111111111111111111111111111111111
RECORD 222222222222222222

i read the member with ZFile using the following code:

byte[] recBuf = new byte[zFile.getLrecl()];
while ((nRead = zFile.read(recBuf)) >= 0) {
count++;
sbuf = new String(recBuf);
System.out.println("record #"+count +"= " +sbuf);

the display shows the records read as being:

record #1= RECORD 11111111111111111111111111111111111111111111111111111111111111
RECORD
record #2= 222222222222222222
11111111111111111111111111111111111111111111111111111
RECORD

the word RECORD gets appended to the 1st record and extra spaces + word RECORD + data from 1st record
gets added onto the 2nd record.
these show up when i try to copy the data to a new file.

how can i avoid this and just get the data that ISPF edit shows it to be in the member?
________
SUNDANCE
Last edited by cscs010 on Sat Feb 12, 2011 2:23 pm, edited 1 time in total.
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

How did you open the ZFile?

ZFile is simply a wrapper on the z/OS C/C++ library's I/O functions.
The underlying C-library really has three modes for reading a dataset sequentially:
- "text"/stream e.g: new ZFile(name, "rt")
- "binary"/stream eg: new ZFile(name, "rb")
- "binary"/record eg: new ZFile(name, "rb,type=record,noseek")

Refer to the z/OS C/C++ Programmer's Guide for more info.

I'm assuming that you want "binary/record", but that you are maybe getting text/stream, in which case the C-library will trim spaces from each record and add newline characters. In stream mode, you will get the number of bytes that you ask to read, regardless of record boundaries.

In binary/record mode, each read will read a logical record.

For another example of doing record I/O with ZFile, see the ZFileCopy example program.
cscs010
Posts: 37
Joined: Tue Jul 31, 2007 3:50 pm

Post by cscs010 »

i changed the input and ouput members to open in rb/wb mode.
the first record is okay but the 2nd gets part of the first record appended to it.
zFile = new ZFile("//DD:" + ddname + "(" + memberName + ")","rb,type=record,noseek");
tFile = new ZFile("//DD:" + ddname + "(" + newmemb + ")","wb");

this is the output file - (the display also shows the extra data being read in).

RECORD 11111111111111111111111111111111111111111111111111111111111111111
RECORD 222222222222222222
11111111111111111111111111111111111111111111111111111
RECORD
________
Hotels In Mexico
Last edited by cscs010 on Sun Mar 06, 2011 7:39 am, edited 1 time in total.
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

I doesn't look like your output is opened in record mode.
Post the complete code and maybe that will help us figure it out.
cscs010
Posts: 37
Joined: Tue Jul 31, 2007 3:50 pm

Post by cscs010 »

filemode rb did work properly.

ignore my last update - the java class file had not been updated as i thought.

thanks for the info about using the binary mode file options.
________
Chevrolet cobalt ss specifications
Post Reply