×

Good News Everybody!

The new search engine is LIVE!

Please report any problems to david (at) midrange.com.




RObert, you're finding out one of the key differences between record level
access and data I/O the way we think of it.  In RLA, the cursor is "on" a
record, not between them, so when you do a position and then a read next,
you actually get the NEXT record, not the one you positioned to.  This is a
little different than what we do in RPG.  I tried many combinations before I
realized that I could just trap the error and handle it.  My SETLL code
looks like this:

        try {
                keyedFile.positionCursor(keys, KeyedFile.KEY_LT);
        }
        catch (AS400Exception e) {
                String msgID = e.getAS400Message().getID();
                if (msgID.equals("CPF5006"))
                        rewind();
                else
                        error(e);
        }
        catch (Exception e) {
                error(e);
        }

And rewind looks like this:

        try {
                file.positionCursorBeforeFirst();
        }
        catch (Exception e) {
                error(e);
        }

Notice that if I get an error on the positionCursor, I simply do a
positionCursorBeforeFirst.  Now, if the file is empty, I think you might
still get an error.  I don't remember.

This code, and a whole bunch of other classes, are freely available in my
freeware classes:

http://www.zappie.net/revitalization/Alpha_2_download.htm

If you want more info, go here:

http://www.zappie.net/Java/Techniques/JDB400/com_pbd.htm


Joe Pluta
www.plutabrothers.com



> -----Original Message-----
> From: java400-l-admin@midrange.com
> [mailto:java400-l-admin@midrange.com]On Behalf Of Robert Upshall
> Sent: Thursday, December 06, 2001 9:51 PM
> To: java400-l@midrange.com
> Subject: Need help with KeyedFile.positionCursor()
>
>
> I happened to stumble accross a problem today by mistake.
>
> I have a KeyedFile object, say file.  I am trying to mimic a
> setll and reade
> in RPG terms.  The KeyedFile has 6 fields in the key but I'm only
> concerened
> with the first field.  The first key field is a 2S 0 in DSS.
> Here is a code
> snipet.
>
> KeyedFile = new KeyedFile(system,  path);
>
> file.setRecordFormat((new AS400FileRecordDescription(system,
> path)).retrieveRecordFormat()[0]);
>
> file.open(AS400File.READ_ONLY, 0, AS400File.COMMIT_LOCK_LEVEL_NONE);
>
> Object[] key = new Object[1];
> key[0] = new BigDecimal("01");
>
> file.positionCursorBefore(key);
>
> Record record = file.readNextEqual(key);
>
> The problem is, when the file only has one record it will not get a hit on
> the readNextEqual?
>
> What am I doing wrong here?
>
>
> Robert Upshall
> Professional Software of Amarillo
> (806) 358-8928
> rupshall@psasoft.com
>
>
> _______________________________________________
> This is the Java Programming on and around the iSeries / AS400
> (JAVA400-L) mailing list
> To post a message email: JAVA400-L@midrange.com
> To subscribe, unsubscribe, or change list options,
> visit: http://lists.midrange.com/cgi-bin/listinfo/java400-l
> or email: JAVA400-L-request@midrange.com
> Before posting, please take a moment to review the archives
> at http://archive.midrange.com/java400-l.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2026 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.