VishalMistry
21st April 2016, 14:41
Hi all,

Whenever a session starts, i want the records to be sorted on a particular field which is not part of any index.

This is in Baan IVc4 and I tried to.key but no luck as it resulted in fatal error.

Anybody can guide ?

Vishal

mark_h
21st April 2016, 15:15
The only way I know how to do this is to control every step of a program - that means when they come into the session you run a query to get the initial records, then if they hit next record you run another query to get the next record. I have only done this once and I do not recommend it. In my case it was not because of the sort order - but because of the data on the session they wanted. You are better off adding a new index.
Below are some snipped lines of code just show the agony of what I had to go thru. Maybe someone else has something better for 4c4.

choice.prev.view:
before.choice:
hold.orno = tipgc521.orno

after.choice:
| Check the filters for the records.
if(filter.set) then
record_event = 3
get_record()
execute(find.data)
endif
execute(first.set)
get_pgc520_record()
display.all()

choice.last.view:
after.choice:
hold.orno = tipgc521.orno
| Check the filters for the records.
if(filter.set) then
record_event = 4
get_record()
execute(find.data)
endif
get_pgc520_record()
display.all()

unction get_record()
{
domain tcbool record.found
domain tcorno original.order
long sql_id

| Use record.found to make sure a record is found.
record.found = false
original.order = tipgc521.orno

| Find all records greater than current record. Run through them
| looking for the first order that matches all filters.
| Use the >= sign because by the time this routine is called the main program
| has increased the order number.
build_sql_query()

| Setup the query
sql_id = sql.parse(sql_query)

| Bind the variables.
sql.where.bind(sql_id,1,original.order)
sql.where.bind(sql_id,2,ccot.filter)
sql.where.bind(sql_id,3,item.filter)
sql.where.bind(sql_id,4,suno.filter)
sql.where.bind(sql_id,5,buyr.filter)
| Execute the query.
sql.exec(sql_id)

| Fetch the first record.
e = sql.fetch(sql_id)
if e = 0 then
record.found = true
else
message("No more records.")
select tipgc521.*
from tipgc521
where tipgc521.orno = :hold.orno
as set with 1 rows
selectdo
endselect
endif
sql.close(sql_id)

}
|******************************************************************************
| Function to build the sql
|******************************************************************************
function build_sql_query()
{
| Same for all queries
sql_query =
"select tipgc520.*, tipgc521.* " &
"from tipgc520,tipgc521 "

on case record_event
case 1: | First record
case 4: | Last record
sql_query = sql_query &"where tipgc521.orno = tipgc520.orno "
break
case 2: | Next record
sql_query = sql_query &"where tipgc520.orno >= :1 " &
"and tipgc521.orno = tipgc520.orno "
break
case 3:
sql_query = sql_query &"where tipgc520.orno <= :1 " &
"and tipgc521.orno = tipgc520.orno "
break
endcase
if(ccot.filter<>"") then
sql_query = sql_query & "and tipgc520.ccot = :2 "
endif
if(item.filter<>"") then
sql_query = sql_query & "and tipgc520.item = :3 "
endif
if(suno.filter<>"") then
sql_query = sql_query & "and tipgc520.suno = :4 "
endif
if(buyr.filter<>0) then
sql_query = sql_query & "and tipgc520.buyr = :5 "
endif

on case record_event
case 1: | First record
sql_query = sql_query & "order by tipgc520.orno asc "
sql_query = sql_query & "as set with 1 rows "
break
case 2: | Next record
break
case 3: | Previous record
sql_query = sql_query & "order by tipgc521.orno desc"
break
case 4: | Last record
sql_query = sql_query & "order by tipgc520.orno desc "
sql_query = sql_query & "as set with 1 rows "
break
endcase
}

vamsi_gujjula
22nd April 2016, 16:49
May be query.extend.order can help , not sure if it works for baan 4

http://www.baanboard.com/baanboard/showthread.php?t=58863

mark_h
25th April 2016, 16:01
As far as I know query.extend type functions do not work in 4c4.