FAQ on properly accessing fields in records

General discussion on the JZOS batch launcher and toolkit
Post Reply
JohnMcKown
Posts: 39
Joined: Sat Nov 21, 2009 2:59 pm

FAQ on properly accessing fields in records

Post by JohnMcKown »

Sorry for the poor Subject!

I used the Assembler Record Generator to create a large package which includes most of the SMF records. But I had a problem accessing the fields. This was due to my ignorance. My first try looked like:

Code: Select all

byte[] buffer=new byte[32768];
Smf.BaseRecord baseRecord=new Smf.BaseRecord(buffer);
for(;;) {
      bytes_read=vbsinfile.read(buffer,4);
      if (bytes_read=-1) then break; 
      int record_number=baseRecord.getBaseRecord_Rty();
      RecordNumber[record_number]++;
}

This did not work. My problem turned out that I thought that when I changed the contents of the buffer, that the contents of the baseRecord also changed. I found that I had to change the above code to:

Code: Select all

byte[] buffer=new byte[32768];
for(;;) {
      bytes_read=vbsinfile.read(buffer,4);
      if (bytes_read=-1) then break; 
      Smf.BaseRecord baseRecord=new Smf.BaseRecord(buffer);
      int record_number=baseRecord.getBaseRecord_Rty();
      RecordNumber[record_number]++;
}
But this was not obvious to me. Perhaps due to my ignorance of Java. I did look at the code generated by asm.ClassRecordGenerator, but I was completely confused by it. Again, this was due to my ignorance. If there had been an example of accessing records, then I would have realized that the new of the Smf.BaseRecord had to be inside the loop, after reading the record. I guess I was thinking like an HLASM or COBOL programmer. I.e. that the "new Smf.BaseRecord" set up the equivalent of a DSECT or 01 level and that reading new content into the underlying record/byte[] would change the values retrieved by the various get... methods.

Again, it was due to my ignorance, but an example really would have been helpful!

Or did I miss this information somehow?

--
John McKown
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

John,

The problem that you stumbled on may not be obvious until you realize that the record class that is generated has instance variables that "cache" the value of the fields. So you can't just modify the underlying buffer contents of the record and have it work properly.

There are some examples of using records generated from Cobol in the JZOS Cookbook project. Other than being generated from COBOL, these are the same as the Assembler records.

Another tricky thing to understand about the generated record classes is how there are *static* "field" objects created which are preconfigured for accessing (getting and setting values in) each field in the record.
JohnMcKown
Posts: 39
Joined: Sat Nov 21, 2009 2:59 pm

Post by JohnMcKown »

That was my problem. I didn't look at the COBOL stuff, just the assembler stuff. My bad.

Thanks!
Post Reply