Normal Topic XResultSetRemoveRecord (Read 1790 times)
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
XResultSetRemoveRecord
Jul 29th, 2009 at 10:17pm
Print Post Print Post  
little brain, big headache ....

Sales Order records are created.  If partial delivery is made, then a backorder record is created for the balance of product.  The backorder record # is the original SalesOrder# + an "A" or a "B" or a "C".  

I've trying to pull all sales orders for a client in a date range, then remove the backorder records from the result set, so that I can display a report that shows sales orders for the date range, with  $ totals per sales order and per month.  The following code is not removing all of the backorder tickets (designated by an A, B, or C on the end of the SalesOrder #).  I suspect it's my treatment of XResultSetCurrentPosition when used with XResultSetRemoveRecord, but I cannot get there.

vTot = @XResultSetTotal(vRS5)
For vLoop = 1 to vTot

   XResultSetCurrentPosition(vRS5, vLoop)
         writeln("vLoop " + vLoop)
   vSONum = @XResultSetValue(vRS5, "SONum")
         writeln("vSONum " + vSONum)
   vBO = @ContainsStringArray(vSONum, "A;B;C;D;E", 0)
         writeln("vBO " + vBO)
   If vBO <> ""
      {
         XResultSetRemoveRecord(vRS5)
      }
Next

this code gives me the following writeln slate (this result set has 8 records, 3 of which are backorder records, so the final result should be 8 to start, then 3 each of the 11579A records, removed, leaving 5 in the result set.  But it leaves 6 in the final result set, and doesn't remove one of the 11579A backorder records.

vTot 8
vSONum 11579
vBO
vSONum 11579
vBO
vSONum 11579
vBO
vSONum 11579
vBO
vSONum 11579
vBO
vSONum 11579A
vBO 11579A
vSONum 11579A
vBO 11579A
vSONum                    [color=#ff0000]this vSONum should also be a 11579A[/color]
vBO                          [color=#ff0000]this vBO should also be a 11579A[/color]
vTot2 6

the manual warns of using Xremove inside a loop with Xcurrent, but I cannot seem to see another angle to my goal.
  

Larry
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: XResultSetRemoveRecord
Reply #1 - Jul 29th, 2009 at 10:25pm
Print Post Print Post  
I haven't really looked at your code yet, but why have backorder records?
Each line could have a status, Open/Partial/Closed that is based on qty shipped.  BO qty can be calculated from Order Qty - Qty Shipped.  Each Order can also have a status that is the lowest of any line item, will not be Closed until all line items have a status of Closed.  You could also be able to set the Status manually if you needed to Close an item short, before all are shipped.

This also allows you to track order lines by their original due date without any need to duplicate that information in a BO record.  Now you can age all backorder items by Retreiving all  line items that have Status = Partial.

Just a thought......
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: XResultSetRemoveRecord
Reply #2 - Jul 29th, 2009 at 11:00pm
Print Post Print Post  
Hi Bob,

You're right of course - your suggestion would be the best way to do it. What you suggest is how I have our Purchase Orders/Receiving set up.

On our sales orders, we play everything very close to the edge with 'just in time' on inventory and deliveries to clients.  We take printed orders, divide them into different van routes, then take each route to the whs, pull products for each order - handwriting adjustments on the ticket (if the order is for 10 ctgs and we only have 8 on the shelf, we'll handwrite the ticket 6 each, and write backorder 4 each on the bottom of the ticket, print delivery labels for those 6, then move on to the next ticket.   After the vans are gone, we make a list of products that need to be reordered, and those get entered into PO's to be placed later that day.  When the van comes back after its route, the backorder tickets are generated for those incomplete tickets that just came in.  They go in a backorder file, and are pulled when the product arrives tomorrow or the next day from our vendor.  This happens twice each day (3 vans make two runs per day).  We're small and try to be very quick in delivery (one of our selling points - order by lunch, get it before dinner), and our experience is that we have to move faster sometimes than textbook computer procedure allows.   After the dust clears, then we process what we just did into the system.

We developed the 'add an A or B or C' to the original ticket # as a way to group tickets on a screen report (we used to remanufacture laser ctgs inhouse for clients, and the original order was actually a pickup ticket for empty cartridges to be remanufactured, then completion tickets would be made - sometimes 3 or 4 tickets would have to be generated before the entire order got filled, on bigger orders).  This gave our reps a quick and dirty way to get a chronological view of order patterns for a client.  
      It just seems an intuitive way to 'see' an order from start to finish.

I'm trying to give some of my clients a button to run an HTML report they can see what they ordered last month, find a PO, etc.  And if the backorder tickets don't get excluded, then the report give inaccurate $$$ and quantity info.

In any event, my wife says I'm always grumpy when I'm stumped, so for her sake  Cool I'd love to see how to Xremove records from a result set that catches all of them


  

Larry
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: XResultSetRemoveRecord
Reply #3 - Jul 29th, 2009 at 11:03pm
Print Post Print Post  
[quote author=lksseven link=1248905856/0#0 date=1248905854]
the manual warns of using Xremove inside a loop with Xcurrent, but I cannot seem to see another angle to my goal.[/quote]

The manual is warning about this very case. Imagine that you have 8 showboxes and you are running your attention from the first to the last. You get to the third shoebox and decide it shouldn't be included, so you remove it from the line of shoeboxes. Now you only have 7 boxes and your attention is either on the second box or the new third box. In either case, a single loop won't do. It will either count wrong or skip boxes.

Instead, consider either running through all of your records and keep track of those that you want to remove, then remove them in a second loop that simply counts through the list you have made of records that need to be removed. Or, you can use an inner loop and an outer loop. The inner loop runs through the records you have and removes one that needs to be removed. The outer loop keep going until the inner loop cannot find any single record that needs to be removed.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: XResultSetRemoveRecord
Reply #4 - Jul 29th, 2009 at 11:22pm
Print Post Print Post  
Hi Mark,

I think I found my specific solution ... Bharat had mentioned something in June 2008 and I stumbled on it just now ..
http://www.lantica.com/Forum3/cgi-bin/yabb2/YaBB.pl?num=1214768607/1#1

vTot = @XResultSetTotal(vRS5)
             
For vLoop = 1 to vTot
     XResultSetCurrentPosition(vRS5, vLoop)
     vSONum = @XResultSetValue(vRS5, "SONum")
     vBO = @ContainsStringArray(vSONum, "A;B;C;D;E", 0)
     If vBO <> ""
       
         {
            XResultSetRemoveRecord(vRS5)
            vLoop = vLoop - 1
            vTot = vTot - 1

         }
Next

Once I added the 'code in red' it seems to do what I intended.  Thanks, guys!
  

Larry
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: XResultSetRemoveRecord
Reply #5 - Jul 29th, 2009 at 11:27pm
Print Post Print Post  
I am not saying that you shouldn't use that code. It will probably do fine. But, from a CS perspective, it is a good idea to avoid affecting a loop counter or limit (especially using a "for" loop) while inside that loop. This is how infinite loops are born.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: XResultSetRemoveRecord
Reply #6 - Jul 29th, 2009 at 11:40pm
Print Post Print Post  
Mark,

I appreciate your time !!!   I will gladly rework this code to however you suggest would be proper form (I just don't know what that proper form would be, but I'm eager to learn).
  

Larry
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: XResultSetRemoveRecord
Reply #7 - Jul 30th, 2009 at 12:01am
Print Post Print Post  
As I said, you don't need to rework the code. But you should be aware of the issue as you code and try to avoid the case. Here is an overly simple example:

Code
Select All
for xx = 1 to 100
    writeln(xx)
    xx = xx - 1
next
 



The "for" loop automatically and invisibly increments xx. Simultaneously, the code in the loop is decrementing xx. In the end, xx stays right where it is and the code never exits the loop.

Another simple example:
Code
Select All
for xx = 1 to limit
   limit = limit + 2
next
 



Here, because the limit keeps going up, xx can't keep up, and the code never exits the loop.

In the case you posted, you are affecting both the limit and the counter. In are both cases you are working with obvious constraints. But, imagine that you only have one record in your result set and it needs to be removed. Will your loop work correctly? I'm not sure. It probably will. Or, let's say that you need to remove all the records in your set. Will that be okay? Probably, but I wouldn't let it go without a few tests.

If you decide to rework the code, consider using an inner and an outer loop, as I mentioned in my first post. Its a bit more code, but it is simpler and more predictable code.

Pseudo code:
Code
Select All
// THIS IS PSEUDO CODE, NOT SBASIC
any_done = 1
while(any_done = 1)
{
    any_done = 0
    cnt = 1
    did_any = 0
    total = NumberOfRemainingRecords()
    while((cnt <= total) and (did_any = 0))
    {
	  if(condition = TRUE)
	  {
		RemoveRecord(cnt)
		did_any = 1
	  }
	  cnt = cnt + 1
    }
    if(did_any = 1)
    {
	  any_done = 1
    }
}
 


  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: XResultSetRemoveRecord
Reply #8 - Jul 30th, 2009 at 12:50am
Print Post Print Post  
Mark,

thank you.  I'll study this over the next day or two and try to implement your suggestions.  Will report on progress.

I appreciate it!
  

Larry
Back to top
IP Logged