data in asceding way

kaushik

New Member
kindly help in this problem
i want to develope a code which counts prev data .

like
1 mandy
2 joseph
3 tt
4 uuu

but my o/p is like
4 uuu
3 tt
2 joseph
1 mandy

i m using this code
find prev item where item-num=xsome_var.
repeat i=0 to 4:
find prev item no-error no-lock.
if avail item then
do:
disp item-num name.
end.
end.

kindly help me in thid regard
 

RealHeavyDude

Well-Known Member
Performance-wise, doing a find in a repeat loop is not a good idea ...

If I were you I would do this using the BY option on the FOR EACH statement:

FOR EACH <TableName> NO-LOCK WHERE <TableName>.<FieldName> = "Your Value" BY <TableName>.<SortFieldName> [ ASC | DESC ]:
/* Do stuff */
END.
Heavy Regards, RealHeavyDude.
 

kaushik

New Member
thanks heavy for ur valuable reply .
but here i hv another problem ...
see first i m displaying only 5 items ,and i hv two buttons PREV and NXT. when i press next next 5 items should show
and if press prev button 5 records in asceding
item id item name
here is the total data
1 a
2 b
3 c
4 d
5 e
7 f
8 g
9 h
10 i
when i press next btn then next 5 recods come but if i press prev
data comes like this
10 i
9 h
-----
------
6 f

but i want to disply
6 f
7 g
8 h
9 i
10 j
as u suggest to use for each statement with asc or desc ,but for -each will fetch data in forward direction ,just we can reverse it but how to get prev data like this .may i m not able to use for each in correct way .


thanks a lot for valuble suggestion
 

RealHeavyDude

Well-Known Member
As Tom stated, you should have a look into queries. Doing FIND NEXT and FIND PREV to navigate is not exactly state of the art. Plus, a FOR EACH loop, per design is only one way.

Queries are exactly designed for your requirement. There are static ones which you define with the DEFINE QUERY statement, but I would urge you to go dynamic and use dynamic query objects.

Heavy Regards, RealHeavyDude.
 
Top