Is it possible to compare two file values using while loop?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Is it possible to compare two file values using while loop?

Anbu
Is it possible to compare two file values using while loop?

If yes, how to give 1st iteration updated columns are the input of 2nd iteration columns.

I am totally confused. Can anyone explain comparing two files using while loop with proper input and output.

Expected input:

delivery_input

delivery_id count_reqd   prod_id    qty_delivered  
    1           30        101           15
    2           40        101           10
    3           20        102            0

Product_input

prod_id prod_name    qty_mgfd
101     prod1            10
101     prod2            50
102     prod3            10

Inventory_input

 prod_id          qty_available
  101                 0
  102                 30
Explaining the condition clearly:

In delivery file, count_reqd = 30 and qty_delivered = 15 so remaining 15.
This remaining 15 need to be reduce from product file based on prod_id. (here in 1st iteration qty_mgfd is 10 in product file then goto the next record if prod_id is same).
Now qty_delivered= 15+10=25 in delivery file and and qty_mgfd =0 productfile so now still count_reqd=!qty_delivered
Means remaining 5 will reduce from 2nd record of product table (50-5). now updated qty_mgfd =45.
Now qty_delivered= 25+5=30 in delivery file and and updated qty_mgfd =45 productfile so now count_reqd=qty_delivered(30=30) 2 iteration (delivery)
Now 2nd iteration in delivery file, count_reqd = 40 and qty_delivered = 10 So remaining 30.
1st row in product file so qty_mgfd is 0 now. (refer 3)
So goto next(2nd) row from product file based on prod_id. So this remaining 30 will reduce from qty_mgfd. so (45 -30 =15) now updated qty_mgfd =15 will be updated in product file.
Now qty_delivered= 10+30=40 for 2nd row in delivery file. so count_reqd = qty_delivered(40=40).

3 iteration (delivery)
In delivery file, count_reqd = 20 and qty_delivered = 0 so remaining 20. This remaining 20 need to be reduce from product file based on prod_id.
So the prod_id =102 qty_mgfd=10 in product file.
Means remaining 20 will reduce from 3rd record of product table (20-10). now updated qty_mgfd =0.
Now qty_delivered= 0+10=10 in delivery file and and updated qty_mgfd = 0 productfile. so now still count_reqd=!qty_delivered.
Now only will go to the Inventory_input (Note: Not available in product then will go to inventry)

Here qty_available = 20 still we need 10. So the prod_id =102 qty_available =10 in Inventory file.
Now qty_delivered= 10+10=20 in delivery file and and updated qty_available =10 in Inventory file so now count_reqd=qty_delivered(20=20)
Expected Output : Output

delivery_outputfile

delivery_id count_reqd   prod_id    qty_delivered  
    1           30        101           30
    2           40        101           40
    3           20        102           20


Product_outputfile

prod_id prod_name    qty_mgfd
101     prod1            0
101     prod2            15
102     prod3            0

Inventory_outputfile

  prod_id          qty_available
  101                 0
  102                 20

Thanks in advance,
Anbu k