Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Skipping records 1

Status
Not open for further replies.

EKC

Technical User
Jan 13, 2001
43
0
0
CA
Hi,
I posted my problem earlier but now I have new question( I decided different approach):
I have set of records in one cursor(fields are order,orderline ,part,orderdate,QTY).If 2 records have the same order and orderline fields (those records following each other -I sorted them by order,orderline ),I want to skip the second record but add QTY to first record QTY field(first and second record refer to records with same order and orderline fields).How to manipulate data in this cursor and create second cursor that don't contain records with same order and orderline fields.What commands should I use?How to loop through records in cursor and implement logic to skip the records with same order and orderline fields but add QTY field?
I need help on this,
Thanks, Lyn
 
Assuming that your original cursor already exists and is called ordercursor, here's the code I used for this task:

create cursor tempcursor(order n(5,0), orderline n(5,0),;
part c(10), orderdate d, QTY n(3))
select ordercursor
set order to orderplusline && (order and orderline)
goto top
do while !eof()
m.order=order
m.orderline=orderline
m.part=part
m.orderdate=orderdate
m.qty=0
do while order=m.order and orderline=m.orderline;
and !eof()
m.qty=m.qty+qty
skip
enddo
insert into tempcursor from memvar
enddo

The code starts by dumping the contents of a record to memory variables and setting qty=0. Then it steps through records, adding each record's qty to the qty variable. When either the order field or orderline field changes, it writes a new record to tempcursor with the current variables and starts over with the next field. Hope this helps.
 
Hi Lyn,

SELECT Order,OrderLine,SUM(QTY) As TotalQty
FROM OrderCursor
GROUP BY Order,OrderLine
INTO Cursor 'TotalCursor'

Chpicker,

FWIW, you can replace

m.order=order
m.orderline=orderline
m.part=part
m.orderdate=orderdate
m.qty=0


with

SCATTER MEMVAR

Jon Hawkins

The World Is Headed For Mutiny,
When All We Want Is Unity. - Creed
 
jonscott8, Re: SCATTER MEMVAR...

Personally, I like the simplicity of using this command, however I've tried intentionally to stay away from it since the source code I've recently inherited (and since modified) has tables with 150+ fields. Also, while it might be negligible, I believe it is a little faster to assign the 5 variables as above instead of using SCATTER to assign them, then resetting QTY to 0. I haven't tested this theory yet...maybe SCATTER has a built-in optimization method where it works faster than individual commands. This has never been my experience with other languages, but you never know.

On a side note...does the code you listed have the same effect as mine? I haven't taken the time to learn how to use the SQL SELECT command yet...
 
SQL Select is definetely far more qucker and easier (nore straight forward). What Jon Hawkins mentined is the way I would have suggested.
Chpicker's Code... Even the 'goto TOP' can be replaced by 'LOCATE' which executes much faster (While this makes no sense at this point of time, I just mentioned it as a point of learning to code in a better way). It appears EKC likes your way of coding, I would still suggest .. surely .. TRY :) the SQL select and you wont be disappointed, you will be far more happier with less of code and less of code to debug and get results much faster as the DBF grows :)
ramani :-9
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top