ipineda
11th March 2011, 00:07
Hi my friends,

I'm working with AFS to the session tisfc0205m000 and this is what i have get.


stpapi.put.field("tisfc0205m000", "tisfc001.grid", current.grid)

g.ret = stpapi.find("tisfc0205m000", g.error)

if g.ret = 2 then
stpapi.put.field("tisfc0205m000", "tisfc001.grid", current.grid)
g.ret = stpapi.find("tisfc0205m000", g.error)
endif


In the first call of stpapi.find() the return value is 2, even when i know the register exits, and if i call the function again the problem is solved and 1 is returned.

I used the api.log file to see what is going on and i found this:


26dll->serv (start tisfc0205m000 1 0 0)
55serv<-4gl (api.child.startedtisfc0205m00026)
55serv<-4gl (init.ready)
tisfc0205m000(55)-RUNNING:
>tisfc0205m000(55) put.field:tisfc001.grid G90000023
>tisfc0205m000 Find
26dll->serv (def.find 55)
tisfc0205m000(55)-RUNNING:def.find
55serv<-4gl (def.find 0 0)

tisfc0205m000(55)-RUNNING:
<tisfc0205m000 an other record found (2)

>tisfc0205m000(55) put.field:tisfc001.grid G90000023
>tisfc0205m000 Find
26dll->serv (def.find 55)
tisfc0205m000(55)-RUNNING:def.find
55serv<-4gl (def.find 0 1)
tisfc0205m000(55)-RUNNING:
<tisfc0205m000 record found (1)


I see that a value differes in the following lines

55serv<-4gl (def.find 0 0) |* AFS returns 2, does not find the record
55serv<-4gl (def.find 0 1) |* AFS returns 1, find the record

But i don't kwon what the values in the log file means, maybe someone knows what this means or what this problem is about.

It is not the first time this problem occurs and i would really like to know the reason for it.

Thanks for any help you could give me.

JaapJD
11th March 2011, 12:19
The "problem" is that the key of session tisfc0205m000 contains two fields: the order group and the order. The first stpapi.find tries to find the record with an empty order number, so the one that is found is always another one. When you do the second find, it uses the found order number of the first find, so in that case the correct record is found.
So, in your case the return value 2 is a good situation. I would program this in a defending way. Just put also the order number field (with value "") and be prepared for a return value 2. But check also the tisfc001.grid after the find call, to be sure you have the correct group.

ipineda
11th March 2011, 18:02
Thanks for the aswer.

I understand what you mean, it makes a lot of sense. But i have one more question... as you can see i put an "if" statement to check the return value of the stpapi.find() that is because sometimes in the first call of the stpapi.find() it finds the record, what i mean is that the problem does not occurs always even when i never put the value of the field tisfc001.pdno that is what you suggest me to do. Does it have an explanation?

JaapJD
11th March 2011, 18:13
Maybe it has to do with the rows that were displayed when you used the normal session. When the session is restarted it starts at the row that was on top last time. If AFS fires up the session it may see the right order group or not. Makes that sense?

mark_h
17th March 2011, 06:24
Missed this thread somehow - there was at least one case with a multi-occurence session that I had to do the find twice. But that was everytime - I just put the records twice and did the find twice. I can't remember what session that was - not the one mentioned in the thread, but another.

ipineda
21st March 2011, 15:35
Hi friends,

I found the reason why the AFS's was finding the record in some cases and not in others. The reason is that I was searching in a scenario like the following:

G90000001
G90000002
G90000003
G90000004
G91000001
G91000002
G91000003

When I search the group G90000004 the AFS's returns 2 because it finds the record G91000001, but when I look G91000003 it returns 1, it finds the record. The logic is that when the record you are looking for is the last record of the table the AFS's doesn't need the two parts of the index. This problem was not detected before because we were using only one group series so I was always looking for the last record.

Conclusion: Solved, thanks friends for your help.