Looping all line's amount until the sum of all lines amount matches to Total Amount

I have a input file which has a column as Total Amount. (vStrTotalAmount = “\$400”)
In the Application there can be N number of lines. Each line will have some amount which we read and store it into (vDoublePaidAmount). Now we have to loop all the N lines until the total amount is recovered.
So basically there can be 4 scenarios, First, say we have 10 line and each line has \$40 each then sum of all 10 lines would be \$400 which means using all 10 lines we recovered “vStrTotalAmount”. Second scenario , we have 10 lines and each line has \$80 that we can recovery which means by line 5 we will recover \$400. This means rest 5 lines will be ignored.
Third scenario would be in each line we have \$10 that we can recover and we have only 10 lines then we will only recover \$100. This would be partial recovery.
Fourth scenario would be i Line 1 i have \$430 that I can recover but I only need \$400 to be recovered so we only take 400 from that line.
How can we achieve ?
TIA

To achieve this task in UiPath, you can use a loop to iterate through each line in your input file, and keep track of the total recovered amount until it reaches or exceeds the target total amount. Here’s a general outline of how you can implement this:

1. Read the input file to get the total amount (`vStrTotalAmount`).
2. Initialize variables to keep track of the total recovered amount (`vDoubleTotalRecoveredAmount`) and the line count (`vIntLineCount`).
3. Start a loop to iterate through each line in the input file.
4. Inside the loop, read the amount from the current line and store it in a variable (`vDoublePaidAmount`).
5. Check if adding the amount from the current line to the total recovered amount will exceed the target total amount:
• If yes, calculate the difference between the target total amount and the current total recovered amount and subtract this difference from the amount on the current line. Update the total recovered amount accordingly.
• If no, add the amount from the current line to the total recovered amount.
1. Increment the line count (`vIntLineCount`) by 1.
2. Check if the total recovered amount equals or exceeds the target total amount:
• If yes, exit the loop.
• If no, continue to the next line.
1. After the loop, you will have either fully or partially recovered the target total amount. You can then proceed with further processing or output the result as needed.

Thanks,
Ashok

We have a chance to condense the implementation

The Array with the numbers represents the Line with amounts and we can grab it in advance into an Array Variable

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.