You can "remember" that reference in a shiftregister. To have shiftregister you need either a while or a for loop.
So Add a while to your diagram (with all code inside) and store the result of the open in the shiftregister. In the close store a NIL in the shiftregister.
In the other cases simply connect the input and output of the shift register.
Be carefull not to initialize the shiftregister !
greetings from the Netherlands