Hi,
I don't know if there is a way in query level..I think this can be done by using virtual characteristics BADI..I'm just not sure how can this be done..I'm not familiar with BADI..The only way I can think right now is by doing this in transformation level..
If the data of your allocation number and purchasing document are PURE NUMBERS, then we can do this in BEx level..
Regards,
Loed