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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need instructions on how to read a file using Alternate Key

Status
Not open for further replies.

ImDaEggman

Programmer
Nov 29, 2010
1
0
0
BR
Hello friends,

After some unhappy googling, i was not able to find references on how to use an alternate key. Here is my dilemma:

I declared the file using the alternate key - File is opening and starting without troubles.
The problem is while reading, i'm making a random access on the file, moving an account number to be found so i can obbtain its status, and it does not return the correct status, it is as if the account number is always zero.

Ex: account 010
status R
account 000
status L
(It always returns L)

Here is what i'm doing to read:
MOVE WS-ACCOUNT TO BOOK04ACC.

READ FILE4
INVALID KEY
DISPLAY 'DOES NOT EXIST'
AT LINE 25 COL 5
DISPLAY WS-ACCOUNT BOOK04ACC
AT LINE 26 COL 5
ACCEPT KEY-W.

Also it always gives INVALID KEY.
I use the file in the program more than once and i'm initializing like this:

MOVE ZEROS TO FILEAKEY.
START FILE4 KEY IS GREATER THAN BOOK04KEY
END-START.

File declaration:
SELECT FILE4 ASSIGN TO "FIL4"
ORGANIZATION INDEXED
ACCESS MODE IS DYNAMIC
RECORD KEY IS BOOK04KEY WITH DUPLICATES
ALTERNATE KEY IS BOOK04STATUS WITH DUPLICATES
ALTERNATE KEY IS BOOK04CRE WITH DUPLICATES
FILE STATUS IS FS-BOOK04S.

The file has 2 alternate keys... i would like to, in the future, read the account in one and, if not found ,read on the other... but that's for later...

Am i doing this right? What i would have to do to obtain the correct status? I am missing something regarding the use of alternate keys?

Any help would be aprecciated!
 
I usually do after START:

READ FILE4 NEXT RECORD AT END GO TO XXX-END
IF FILE-STAT = "00" OR "02" OR "04" NEXT SENTENCE
ELSE MOVE "X" TO ERR-FLAG
GO TO XXX-END.
 
In either the READ statement or the START statement, you must specify the name of the ALTERNATE KEY, otherwise the prime (RECORD) key will be used.
Code:
READ FILE4 KEY IS BOOK04KEY . . .
Just specifying it on the START statement is not persistant. You must specify it on every START or READ statement in which you want the key used.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top