Hi Alonso,
It's close to impossible to analyze complex multidimensional allocation without understanding the data and master data, but one thing is clear:
Side effect of *ENDALLOCATION - is scope reset! You have to put you scope definition *XDIM_MEMBERSET... inside the inner FOR/NEXT loop.
B.R. Vadim