Sure this is possible, I never done this exactly (not from Caesar) but the last part is quite easy.
First, why "nothing happens" ? You should write some log inside your code to know what happen and what your variable contains.
I just tried, and i think in your code, the problem come from line 51, the !DistPrev equal the !DistCE,
I don't like his code, there are several mistakes or dangerous behaviour (the loop 1 to 100, why 100 ?, you can have more than 100 branch, the var name ListATTA which is not a list of ATTA but a list of branch member without the tubi, the Next, forward, you don't know your current position, the missing $p to inform what's going on, ...).
You should rewrite the code yourself, take what you need and recreate the pml code.