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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sequencing...and resequencing 1

Status
Not open for further replies.

cobweb

IS-IT--Management
May 5, 2002
95
GB
Hi guys:
I have a problem.
I have a table with several batches in it. In this case a batch is a group of records that share the same batch number.
I need to be able to sequence the records in each batch in a particular order, numbered by the number of records in each batch.
So...batch 1 has 50 records; I need to sequence each record in the batch,order 1 to 50.
Batch 2 has 75 records; I need to sequence each record in the batch,order 1 to 75.
The sequencing does not exist at the moment; I want to sort the table and the batches in the table into the order I want (I think I can handle that) then create a unique number for each record in each batch.
So I need a'break' between batches in the same table.
A kind of "while batch 1, sequence from 1 to 50, then while batch 2 sequence from 1 to 75..etc"

Is this feasible?

Thanks!
 
cobweb,

If I understand you correctly then yes, this is feasible using a scan in objectpal. I'm a little puzzled when you say you want to create a sequence number for each record in each batch then you want to create a unique number for each record in each batch. Wouldn't the sequence number be a unique number?

A simple way would be to sort the table by batch then scan the table and while the batch number is the same increment a number and add it to the table in a new sequence field and if the batch number changes start the increment number at 1 again.

If this is what you need to do and need help with the code let me know and I'll write an example for you.

Perrin
 
THanks: I think that is exactly what i want.
It is this "while the batch number is the same" bit that has had me stumped.

And in answer to the first paragraph the sequence number is unique for that batch; so batch 1 will have a sequence number of 1, and so will batch 2, but in each case that number is unique to that batch.
 
var
tc tcursor
bNumber string
n number
ednvar

tc.open("tableName")
tc.home()

bNumber = tc.batchNumberField
; assign the batchnumber to the first record to a variable

n = 0

scan tc:
if tc.batchNumberField = bBumber then
; if the batchNumber is the same as the variable incriment the number

n = n + 1
else
bNumber = tc.batchNumberField
; if the batchNumber is different re-assign the variable to the new batch number and reset the incriment number.

n = 1
endif
tc.sequenceField = iNumber
; Assign the increment number to the sequence field

endscan
 
cobweb,

Hit the send button befoe I finished, the above code is one way to handle the changing batch number issue. This sould work fine as long as the table is sorted by batch number.

let me know how it goes.
Perrin
 
Thank you very much!

I am off until monday ..but I'll let you know!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top