Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

mch1202

Programmer
Apr 29, 2011
4
US
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???
 
Cant you post the START statement and the initial value of your key? Also include the block where it READs the record.
 
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).
 
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.

 
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.
 
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.
 
How did you describe your numeric key? This could be the problem in your code, but without seeing the specifics...
webrabbit said:
Vague speculations will get you nowhere.

Tom Morrison
Micro Focus
 
ok before I copy and paste all the code in here - what difference does it make if the LF key is a numeric field?
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top