×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Trying to START logical file but READ NEXT goes to beginning of file

Trying to START logical file but READ NEXT goes to beginning of file

Trying to START logical file but READ NEXT goes to beginning of file

(OP)
I have done this one hundred million times and I don't know what is wrong.  I created a very simple logical file on AS/400 that is keyed on a numeric field and duplicates are allowed.   I issue the START statement for a value that IS in the file with multiple records.  I don't have a bad start situation.  Immediately do a READ NEXT and the record returned is the first record in the logical indexed file.   WTH am I doing wrong???

RE: Trying to START logical file but READ NEXT goes to beginning of file

Cant you post the START statement and the initial value of your key? Also include the block where it READs the record.

RE: Trying to START logical file but READ NEXT goes to beginning of file

(OP)
Not sure what you mean by the "block where it reads the record".  The START statement is there and it gives no error at all.   But the READ NEXT following the START returns the very first record in the Logical File (access path).

RE: Trying to START logical file but READ NEXT goes to beginning of file

Usually you set a criteria for a key, START once and loop to READ NEXT until end of file. If you can post that part where you set the KEY, the START routine and the routine for the READing of records.

 

RE: Trying to START logical file but READ NEXT goes to beginning of file

You may also look at the source of your logical file. There could have been a hard coded value in your key when it was compiled. Sorry but I have not been doing programming with AS400 since 2007.

This is the first place I would look.

RE: Trying to START logical file but READ NEXT goes to beginning of file

Post your code.  Vague speculations will get you nowhere.

RE: Trying to START logical file but READ NEXT goes to beginning of file

Look in your file section, how your logical file is declared. I'm using for example somethng like this

CODE

       ENVIRONMENT DIVISION.
       ...
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
       ...
           SELECT P600011L
               ASSIGN TO DATABASE-P600011L
                   ORGANIZATION IS INDEXED
                   ACCESS MODE IS DYNAMIC
                   RECORD KEY IS EXTERNALLY-DESCRIBED-KEY
                   WITH DUPLICATES           
                   FILE STATUS IS DB-STAT, DB-OS4-RC.
       ...
       DATA DIVISION.
       FILE SECTION.
       ...
       FD  P600011L.
       01  P600011L-RECORD-AREA.           
           COPY DDS-ALL-FORMATS OF P600011L.
       ...
Then after

CODE

READ P600011L NEXT RECORD
examine your FILE STATUS field - in my case DB-STAT. If it's not '00', then look in the file status reference what's error occured.

I could probably help you, if you could post here a complete minimalistic code example which doesn' work for you, i.e DDS or PF, DDS for LF and the COBOL code.

RE: Trying to START logical file but READ NEXT goes to beginning of file

How did you describe your numeric key?  This could be the problem in your code, but without seeing the specifics...

Quote (webrabbit):

Vague speculations will get you nowhere.

Tom Morrison
Micro Focus

RE: Trying to START logical file but READ NEXT goes to beginning of file

(OP)
ok before I copy and paste all the code in here - what difference does it make if the LF key is a numeric field?

RE: Trying to START logical file but READ NEXT goes to beginning of file

Who knows.  Just post the code.

RE: Trying to START logical file but READ NEXT goes to beginning of file

COBOL indexed file keys are alphanumeric, unless you are using a proprietary extension.  If you index is comprised of a signed numeric field, you may get an unexpected result.

So, post the SELECT statement, the FD including the definition of the key in question (fields not in the key are irrelevant), and the sequence of statements used to do the START.

Finally, if you are using compiler options that affect the USAGE of the numeric item(s) in your key, we need to know those as well.

Tom Morrison
Micro Focus

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close