# Want to cretae a script for FIFO

#### vik

##### New Coder
I have a database with lot No and quantity as below. I have to use first in first out concept (FIFO) to issue these materials

LOTNOQuantity
12
24
313
If requested quantity is 1 the i have to decrease quantity of lotNo 1 by 1 if the requested quantity is more than the quantity available in that lot i have to remove from lotNo 1 then 2 till i get the required quanty.

eg if requested quantity is 8, i have to remove 2 from lot 1 4 from lot 2 and remining 4 from lot 3.

I'm using classic asp as programming language with VBScript and JavaScript

#### vishvajitd

##### Coder
You can use a loop to check the requested quantity against the available quantity in each lot until the requested quantity is fulfilled. Here's an example of a possible implementation in VBScript:
JavaScript:
``````Dim requestQty
requestQty = 8

Dim lots(3)
lots(0) = Array(1,2)
lots(1) = Array(2,4)
lots(2) = Array(3,13)

Dim i
For i = 0 To UBound(lots)
If requestQty > lots(i)(1) Then
requestQty = requestQty - lots(i)(1)
lots(i)(1) = 0
Else
lots(i)(1) = lots(i)(1) - requestQty
requestQty = 0
End If
If requestQty = 0 Then
Exit For
End If
Next

' Display the result
Response.Write "The remaining quantity in each lot after fulfilling the request:<br>"
For i = 0 To UBound(lots)
Response.Write "Lot No. " & lots(i)(0) & ": " & lots(i)(1) & "<br>"
Next``````

#### OldMan

##### King Coder
This is why I hate it when people post in two or more forums. I just spent a half hour writing an algorithm for this problem.

#### vik

##### New Coder
You can use a loop to check the requested quantity against the available quantity in each lot until the requested quantity is fulfilled. Here's an example of a possible implementation in VBScript:
JavaScript:
``````Dim requestQty
requestQty = 8

Dim lots(3)
lots(0) = Array(1,2)
lots(1) = Array(2,4)
lots(2) = Array(3,13)

Dim i
For i = 0 To UBound(lots)
If requestQty > lots(i)(1) Then
requestQty = requestQty - lots(i)(1)
lots(i)(1) = 0
Else
lots(i)(1) = lots(i)(1) - requestQty
requestQty = 0
End If
If requestQty = 0 Then
Exit For
End If
Next

' Display the result
Response.Write "The remaining quantity in each lot after fulfilling the request:<br>"
For i = 0 To UBound(lots)
Response.Write "Lot No. " & lots(i)(0) & ": " & lots(i)(1) & "<br>"
Next``````
Hi Thanks for the code its working but the lot No is dynamic and will keep on increasing in the database as new lots will be purchased.