locked
do while RRS feed

  • Question

  • hi its me again,

    whew! am sorry if i'm going to bother some of you again.. Fact is, i'm trying to learn.. heh ehe
    anyways, i need help again.
    I'm trying to use the do while statement in my fifo inventory but i'm having troubles in it.

    i have a table named fifo_inventory with fields (item_code,qty1,priority)
    i have 3 records in it;

    item001, 20, 1
    item001, 30, 2
    item001, 10, 3

    if i am going to get an item which is item001 and the value is 25 or i am going to get item001 and the value is 60 based on its priority

    so if i iam going get 25

    1st record will be minus to 25 and so it becomes 0 then it should be deleted and the 2nd record priority will become 1
    so the remaining 5 will be minus to the 2nd record. since second record still has a value it will retain its priority. i hope this is clear now .. i'm sorry
    my english is very limited.

    should i used the do while or loop statement.. please help

    please correct this codes below.;

    sele fifo_inventory
    do while thisform.text1.value!=0
       set filter to item_code=trim(thisform.text1.value)
       locate for priority=1
       if found()
           do case
               case thisform.text1.value>qty1
                     thisform.text1.value=thisform.text1.value-qty1
                     set safety off
                     delete
                     pack
                     repla all priority with priority-1
               case thisform.text1.value=qty1
                       thisform.text1.value=thisform.text1.value-qty1
                      set safety off
                     delete
                     pack
                     repla all priority with priority-1
               case thisform.text1.value<qty1
                     thisform.text1.value=thisform.text1.value-qty1
                     repla qty with qty-thisform.text1.value
          endcase
      endif
      loop
      exit
    enddo

    thanks.. I would appreciate for any help thay may extend..

    Youngfox





    • Edited by Young_fox Sunday, August 16, 2009 4:46 PM
    Sunday, August 16, 2009 3:34 PM

Answers

  • Can you explain in English what did you want to achieve with the above code? For now I can tell, you don't need DO WHILE at all, it probably should have been

    IF thisform.text1.value!=0
      your code
    ENDIF

    But I think your task can be accomplished with a simple UPDATE command.
    Premature optimization is the root of all evil in programming.

    Donald Knuth, repeating C. A. R. Hoare

    My blog
    Sunday, August 16, 2009 3:59 PM

All replies

  • Can you explain in English what did you want to achieve with the above code? For now I can tell, you don't need DO WHILE at all, it probably should have been

    IF thisform.text1.value!=0
      your code
    ENDIF

    But I think your task can be accomplished with a simple UPDATE command.
    Premature optimization is the root of all evil in programming.

    Donald Knuth, repeating C. A. R. Hoare

    My blog
    Sunday, August 16, 2009 3:59 PM
  • i have a table named fifo_inventory with fields (item_code,qty1,priority)
    i have 3 records in it;

    item001, 20, 1
    item001, 30, 2
    item001, 10, 3

    if i am going to get an item which is item001 and the value is 25 or i am going to get item001 and the value is 60 based on its priority

    so if i iam going get 25

    1st record will be minus to 25 and so it becomes 0 then it should be deleted and the 2nd record priority will become 1
    so the remaining 5 will be minus to the 2nd record. since second record still has a value it will retain its priority. i hope this is clear now .. i'm sorry
    my english is very limited.

    should i used the do while or loop statement.. please help

    Sunday, August 16, 2009 4:15 PM
  • I see - a bit complex.

    local lnQuantityToGet as Integer
    lnQuantityToGet = 25

    do while lnQuantityToGet > 0
      scan myTable && Ordered by Priority
         If Qty >=lnQuantityToGet
            replace Qty with Qty - lnQuantityToGet
            if Qty = 0
               delete && we delete this record
           endif
          lnQuantityToGet = 0
          exit
         else && Qty is less than the requested qty
             lnQuantityToGet = m.lnQuantityToGet - Qty
             replace Qty with 0
             delete
        endif
       endscan
    enddo

    Something like this or perhaps we don't need the outer DO WHILE at all, the SCAN itself with EXIT would be sufficient or even

    SCAN WHILE lnQuantityToGet > 0
     and here the above logic from scan
    ENDSCAN

    Not tested (from the top of my head) - you may want to do some final tweaking.

    Premature optimization is the root of all evil in programming.

    Donald Knuth, repeating C. A. R. Hoare

    My blog
    Sunday, August 16, 2009 5:24 PM
  • wow! thank you..very kind of you..it works! really it works!

    Another problem has been solve... thanks for the help.


    young fox

    • Marked as answer by Young_fox Monday, August 17, 2009 1:40 AM
    • Unmarked as answer by Naomi N Thursday, May 24, 2012 1:33 AM
    Sunday, August 16, 2009 10:58 PM
  • You're welcome, you can mark the response as an answer then.
    Premature optimization is the root of all evil in programming.

    Donald Knuth, repeating C. A. R. Hoare

    My blog
    Sunday, August 16, 2009 11:05 PM