Error reading from data queue
Last Post 30 Aug 2006 07:35 PM by Ringer. 13 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Not Resolved
J Taylor
Senior Member
Senior Member
Posts:4007

--
18 Aug 2006 05:16 PM
I am trying to read from a data queue (using com.ibm.as400.access.KeyedDataQueue) and I keep receiving a java.lang.ArrayIndexOutOfBoundsException error. I cannot figure out what is causing the problem.

private static short readDataQ() {
    try {
        Record inqData = new Record(inqFmt, inputDq.read(readKey, 0, "EQ").getData());
        dataStructure = (String)inqData.getField("Data_Queue");
    }
    catch (Exception e) {
        e.printStackTrace();
        return -1;
    }
            
    return 0;
}
The error is on the Record inqData statement.
Jax
New Member
New Member
Posts:13
Avatar

--
18 Aug 2006 09:52 PM Accepted Answer
And the rest of the declarations?
J Taylor
Senior Member
Senior Member
Posts:4007

--
21 Aug 2006 12:02 PM Accepted Answer
The remainder are defined at the class level,
readKey = uid.toBytes("xxx");
inputDq = new KeyedDataQueue(as400, name.getPath());
inqFmt.addFieldDescription(new CharacterFieldDescription(
    new AS400Text(34,as400),"Data_Queue"));
Jax
New Member
New Member
Posts:13
Avatar

--
21 Aug 2006 02:42 PM Accepted Answer
What's the spec of toBytes()? Does it *create* a byte array or *fill in an extant* byte array? (uid.toBytes() in your code above?
J Taylor
Senior Member
Senior Member
Posts:4007

--
21 Aug 2006 04:40 PM Accepted Answer
AS400Text uid = new AS400Text(10);
(forgot that one) Edit: It seems to be something related to the data queue. I changed to a different data queue and it runs without errors. I compared the two queues but could not see a difference. I even re-created the original data queue but it still gives errors.
J Taylor
Senior Member
Senior Member
Posts:4007

--
22 Aug 2006 12:14 PM Accepted Answer
After some trial and error, I determined that the problem was not with the data queue but with the records on the data queue. The records contain zoned decimal and character fields, and read fine using the QRCVDTAQ API. In case it helps, here is the complete stack trace.
java.lang.ArrayIndexOutOfBoundsException
    at java.lang.System.arraycopy(Native Method)
    at com.ibm.as400.access.Record.<init>(Record.java:312)
    at com.ibm.as400.access.Record.<init>(Record.java:201)
    at x.y.BomDisplay.readDataQ(BomDisplay.java:141)
    at x.y.BomDisplay.showBom(BomDisplay.java:125)
    at x.y.BomDisplay.access$1(BomDisplay.java:90)
    at x.y.BomDisplay$1.keyPressed(BomDisplay.java:83)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:121)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:796)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:820)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:805)
    at org.eclipse.swt.widgets.Control.sendKeyEvent(Control.java:1734)
    at org.eclipse.swt.widgets.Text.sendKeyEvent(Text.java:1147)
    at org.eclipse.swt.widgets.Control.sendKeyEvent(Control.java:1730)
    at org.eclipse.swt.widgets.Control.WM_CHAR(Control.java:3067)
    at org.eclipse.swt.widgets.Text.WM_CHAR(Text.java:1748)
    at org.eclipse.swt.widgets.Control.windowProc(Control.java:2970)
    at org.eclipse.swt.widgets.Display.windowProc(Display.java:3339)
    at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
    at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1473)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2430)
    at x.y.BomDisplay.main(BomDisplay.java:62)
Jax
New Member
New Member
Posts:13
Avatar

--
22 Aug 2006 09:56 PM Accepted Answer
Now that you have got this far in the forensics, you should ask on the JTOpen Toolbox for Java forum.
J Taylor
Senior Member
Senior Member
Posts:4007

--
28 Aug 2006 04:58 PM Accepted Answer
I determined that the RPGLE program was writing records to the data queue that were shorter than the max length for that queue. This did not cause a problem when another RPGLE program used the QRCVDTAQ API to read the data queue but it did when I tried to read it from Java. I padded the data with spaces when writing to the data queue and the problem disappeared.
Jax
New Member
New Member
Posts:13
Avatar

--
29 Aug 2006 04:31 PM Accepted Answer
Glad you found it.
Ringer
Veteran Member
Veteran Member
Posts:1761
Avatar

--
29 Aug 2006 11:44 PM Accepted Answer
I determined that the RPGLE program was writing records to the data queue that were shorter than the max length for that queue.
I'm confused. Aren't you telling the QSNDDTAQ API the number of bytes to write to the data queue? As in %Size(YourBigCharField)? I use the java toolbox to read from non-keyed data queues just fine with this method. If the data queue has a MAXLEN of 5000, I can only write 1000 bytes if that's all I need. Chris
J Taylor
Senior Member
Senior Member
Posts:4007

--
30 Aug 2006 03:06 AM Accepted Answer
The RPGLE program was using the QSNDDTAQ API to write 14 bytes to a 34 byte keyed data queue. My Java app defined the data queue as 34 long, and gave an error every time it tried to read from the data queue. I changed the QSNDDTAQ to write the full 34 bytes (14 bytes of data padded with blanks) and now it works.
Ringer
Veteran Member
Veteran Member
Posts:1761
Avatar

--
30 Aug 2006 11:43 AM Accepted Answer
The RPGLE program was using the QSNDDTAQ API to write 14 bytes to a 34 byte keyed data queue. My Java app defined the data queue as 34 long, and gave an error every time it tried to read from the data queue. I changed the QSNDDTAQ to write the full 34 bytes (14 bytes of data padded with blanks) and now it works.
Why don't you have the java class and the RPG program reference the same external record definition for the data queue entry so there's no mismatch? Chris
J Taylor
Senior Member
Senior Member
Posts:4007

--
30 Aug 2006 06:57 PM Accepted Answer
Why don't you have the java class and the RPG program reference the same external record definition for the data queue entry so there's no mismatch? Chris
Do you mean something like an external data structure?
Ringer
Veteran Member
Veteran Member
Posts:1761
Avatar

--
30 Aug 2006 07:35 PM Accepted Answer
Do you mean something like an external data structure?
Exactly. They both reference the same external PF definition as the "data structure" of the data queue entries. Here's a snippet of code. The RPG would use the same "PART" file in an external data structure to write to the data queue. I'm using non-keyed data queues but should work in the same way for you.
// connect
sys = new AS400("YOUR400") ; 
        
// get physical file attributes (DSPFD)
myFileRecDesc = new AS400FileRecordDescription(sys, 
   "/QSYS.LIB/%LIBL%.LIB/PART.FILE") ;

// set record format to the first one (the only one!)
RecordFormat myRecFormat = myFileRecDesc.retrieveRecordFormat()[0] ;
// Record myRec = myRecFormat.getNewRecord() ;  for writing to DQ
        
// create reference to a data queue
DataQueue ioDataQueue = new DataQueue(sys, 
   "/QSYS.LIB/%LIBL%.LIB/YOURDTAQ.DTAQ") ;
            
// now read part data from data queue 
DataQueueEntry ioDQE = ioDataQueue.read(60) ; // wait 60 seconds

// get raw EBCDIC from data queue entry
byte[] myRecBytes = ioDQE.getData() ;
        
// convert EBCDIC into toolbox record of data types
Record myRec = myRecFormat.getNewRecord(myRecBytes) ;
            
// extract java data types from whatever fields are needed
String partNum = (String) myRec.getField("PMPARTNUM") ;
String partDesc = (String) myRec.getField("PMPARTDESC") ;
BigDecimal qtyAvail = (BigDecimal) myRec.getField("PMQTYAVAIL") ;
// etc... 
Chris
You are not authorized to post a reply.

Acceptable Use Policy