arunkw
3rd February 2003, 12:39
I want to retrive next record of the current record in table
my code is come thing like this
Select tablename.*
from tablename
select do
functionname()
endselect
functionname()
{
db.next()
}
but here I get error as Error 112 (No Current record) on tablename in db_next
Please help
Arun
OmeLuuk
3rd February 2003, 12:53
In the function name you should read the record (using alias for the same table) with the index being bigger than current record. Use SQL.
arunkw
3rd February 2003, 14:03
:( I am not able to get the desired results :(
when i am using db.curr or db.next I am getting error "Error 112 No current record"
Please OmeLuuk send me code to retrive next record from the table
Thansk
Arun
OmeLuuk
3rd February 2003, 16:34
select *
from tablename
where tablename._index1 = {:a, :b, :c}
selectdo
select aliasname.flda:nxta, aliasname.fldb:nxtb, aliasname.fldc:nxtc
from tablename aliasname
where aliasname._index1 > {:a, :b, :c}
selectdo
endselect
message("Next record is" & nxta & nxtb & nxtc)
endselectconceptually spoken
NPRao
3rd February 2003, 21:13
Arun,
I think you need to use the db.eq() (http://www.baanboard.com/programmers_manual_baanerp_help_functions_db_operations_db_eq) and then use the db.next() (http://www.baanboard.com/programmers_manual_baanerp_help_functions_db_operations_db_next)
Here is an example code-
long tableid
string buffer(256)
tableid = db.bind( "tttadv100", buffer, 000)
if tableid then
ttadv100.cpac = "tt"
if not db.eq( tableid ) then
message("Package-%s", ttadv100.cpac)
if not db.next( tableid ) then
message("Package-%s", ttadv100.cpac)
endif
endif
endif
I still do not understand why do you need this kind of requirement.
Youp2001
4th February 2003, 14:04
I also don't see why you need it but anyway. Have you tried using continue so:
select tablename.*
from tablename
where <condition>
selectdo
if <condition> then
continue | go to next record
endif
<do anything>
endselect
You also could use dynamic sql. See Baan Tools help for details on this, but you then can control how and when to get your next record:
sql = sql.parse("select tablenam.* from tablename" &
"where <condition>")
sql.where.bind(sql, ...) | depends on condition
sql.exec(sql)
With sql.fetch you can now get your records one by one.
You shouldn't use the db-statements.
Youp
arunkw
5th February 2003, 10:34
Hi Guys,
Thanks for your help I tried the code which "OmeLuuk" had given on his secode reply and it worked for my problem thanks to you all once again
I did not tried the rest of the replys/codes as my problem is solved, but I think they sure will be correct and effective.
bye.
NPRao
5th February 2003, 19:34
Glad it worked for you Arun.
But Omeluuk's code needs a small adjustments that you need to take care that your selected record is not the last one and also only one record is fetched after the current matching record.
long found
found = 0
select tablename.*
from tablename
where tablename._index1 = {:a, :b, :c}
selectdo
select aliasname.flda:nxta, aliasname.fldb:nxtb, aliasname.fldc:nxtc
from tablename aliasname
where aliasname._index1 > {:a, :b, :c}
as set with 1 rows
|* this is to ensure that no more than 1 record is fetched
selectdo
found = 1
endselect
if found then
message("Next record is" & nxta & nxtb & nxtc)
endif
endselect
OmeLuuk
6th February 2003, 10:49
NPRao: ... the art of perfection ...You are right... and to mention perfection, I have the feeling that in my example I did use some overkill to be absolutely sure: both an alias and bind the table fields to variables. I don't do programming in my current role, but I think either one is enough: reading via alias or binding into variables to leave the current record in the main select correct... Can you confirm this?
NPRao
7th February 2003, 03:14
Well, I never used alias till now...
but here is an example with your method -
long found
select ttadv100.*
from ttadv100
where ttadv100.cpac = "tt"
order by ttadv100._index1
selectdo
found = 0
select ttadv100.*
from ttadv100
where ttadv100.cpac > :ttadv100.cpac
order by ttadv100._index1
as set with 1 rows
selectdo
found = 1
endselect
if found then
message("Next Package is %s", ttadv100.cpac)
endif
endselect
NPRao
4th March 2003, 23:35
You shouldn't use the db-statements.
Youp
I agree with Youp. We shouldnt use the db-statements unless its unavoidable.
I found more info in - Application Performance Guide - M2017 B US.pdf
2.14 DB functions
Problem
DB functions do not take into account the table (field) permissions that are set per user
by customer in the Authorization Management System (ttams) module. This module
can be found in the Baan Tools menu.
DB functions (db.eq(), db.ge(), db.last(), etc.) are outdated functions.
Solution
Do not implement db functions anymore. Implementation of SQL is highly preferable.
Programming constructions
BAAN Application Performance Guide
16
Example
Bad situation
if not db.first(table) then
execute.a.function()
endif
Correct situation
select table.field
from table
order by table._index1
as set with 1 rows
selectdo
execute.a.function()
endselect
arunkw
13th March 2003, 12:08
Thanks for help pals,
I was able to resolve the problem using select query only
I wanted to retrive the next record of a particular specifice record, I used as set with 1 rows and used ">" sign in where clause
This has solved my problem and I have learnt a lot be it a hard way or the easy way.
Thank you all once again...