My advice: please forget that it has worked in the past, just analyze the current situation as if it was new.
4 GB of data is huge. Did you make sure the volume has not changed? I also see that you have 2 "bad" things in your query : 1) combination of join and for all entries, it's better to do one join, and 2) appending table which adds rows, so it intends to be a loop to repeat the SELECT!
Did you try to change the code to make it work? Did you check whether some corrections exist at SAP and at your database?