I have a table that logs the games played by users:
USRGAM (UsrID, GamID)
The two keys COMBINED form the primary key.
The table looks like this:
10, 1
10, 2
11, 1
11, 2
10, 3
10, 4
12, 1
11, 3
10, 5
12, 2
...
Now I want to read from the table and find out what the last game
is for a specified user (MyUsr).
In SQL it would be this:
SELECT Max(gam)
FROM UsrGam
WHERE MyUsr = usrID
ow do I have to do this in RPG with klist, read, setgt statements ...?
I already have something like this:
Dkeyusrid S 4 0
Dkeygamid S 4 0
C keyusrgam klist
C kfld keyUsrID
C kfld keyGamID
...
C keyusrgam setgt usrgamrec
C readp (e)usrgamrec
C if %error
C eval GamID = 1
C else
C eval GamID = GamID + 1
C endif
C eval UsrID = MyUsrID
C write usrgamrec
C endsr
But this gives the following error:
*RNF7055 30 154 000928 Factor 1 KEYUSRGAM is not valid for the specified
operation; the specification is ignored.
I've tried lots of things but I can't find a solution.
I'd appreciate any feedback.
Greetings,
Francis
from a command line do:
DSPFD USRGAM
and look at the section that starts "Access Path Description".
Also, your compile listing will tell you what keys are defined for the
file you are reading.
HTH,
Charles
In article <71714e61.04030...@posting.google.com>,
francis...@hotmail.com says...
You only need the 1st kfld in the klist. The Setgt moves the file pointer to
just before the next user then you want 'keyusrgam readpe (e)'. This
ensures you select a record for the same user, otherwise %eof is seton. It
will select the highest game for the user.
You also require a K in the Fspecification in the RAT column.
Also Charles is right to say check the index on the file. It must match what
is required by the RPG program. You may want to either generate a logical
file using DDS or use SQL to create an index. In this case the filename will
change in the RPG.
--
Jonathan.
> Well, I'd guess that your file doesn't have a key defined.
>
> from a command line do:
> DSPFD USRGAM
>
> and look at the section that starts "Access Path Description".
The file probably has a key, but he didn't specify that
the file is keyed in his RPG 'F' specification for it
(which we don't see).
> Hello,
>
> I have a table that logs the games played by users:
>
> USRGAM (UsrID, GamID)
> The two keys COMBINED form the primary key.
>
> The table looks like this:
> 10, 1
> 10, 2
> 11, 1
> 11, 2
> 10, 3
> 10, 4
> 12, 1
> 11, 3
> 10, 5
> 12, 2
> ...
>
>
> Now I want to read from the table and find out what the last game
> is for a specified user (MyUsr).
>
> In SQL it would be this:
> SELECT Max(gam)
> FROM UsrGam
> WHERE MyUsr = usrID
Why would the highest numbered game be the 'last' one
played? What if a user played game 1 after playing
2,3,4,5?
It's a log table. So every time a user starts playing a game a new
record is inserted in the table with GamID = lastGamID + 1.
But adding the K in the RAT field for the F description solved the
error. Thank you very much.
I also see now the only the first kfld was necessary.
Greets,
Francis
Good catch, I should have thought of that.
Charles