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!

Duplicating records

Status
Not open for further replies.

cobweb

IS-IT--Management
May 5, 2002
95
GB
Hi guys:
I am so impressed with your response to my "sequencing..and resequencing" thread that here is another; which I have solved but it looks messy.
I have a table comprising batches (yes, that table!) and sales orders and quantities of product in that order (it's glass, if you are interested).
What I need to do is find in each record where the quantity is greater than one and duplicate that record for the number of times that equals the quantity; so if qty = 5, duplicate 4 times(plus the first = 5)

The resulting table is then sequenced as you have so generously shown; and finally print out a label for each unit of glass!
Thanks!!
 
cobweb,

There are a number of ways you can do this, one that quickly comes to mind is to create a temporary table with the same table structure as the sequencing table (use the borrow feature when creating the table). Scan the seq. table and when quantity is greater than 1 use copyRecord to copy the record into the temp table the required number of times. After the scan add the temp table to the seq. table and re-sort the seq. table then add the sequencing numbers.

eg.
var
tcBatch, tcTemp tcursor
x number
endvar

tcBatch.open("batchTable")
tcTemp.open("tempBatchTable")
tcTemp.edit()

scan tcBatch:
if tcBatch.quantity > 1 then
for x from 1 to tcBatch.quantity - 1
; if quantity is greater than 1 then copy the record into the temp table the numberr of times quantity - 1
tcTemp.insertRecord()
tcTemp.copyRecord(tcBatch)
endfor
endif
endscan


tcTemp.close()
tcBatch.close()

If this method won't work for you let me know and I'll think of something else.

Keep me posted
Perrin
 
THank you very much.

THis is my code - does it look Ok? i defer to you experts!
var
tc tcursor
arcRec Array[] AnyType
endvar
tc.open("Label")
tc.edit()
scan tc:
while tc.Qty>1
tc.copyToArray(arcRec)
tc.insertAfterRecord()
tc.copyFromArray(arcRec)
tc.Qty = tc.Qty-1
endwhile
endscan
 
cobweb,

Your code should work ok provided you are working with a non-keyed table and I'm pretty sure you are. Personally I avoid inserting records in a scan loop, if you're not careful you can get less than desirable results. But then of course we all make backups of our data before manipulating it...

Perrin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top