Hmmm... depends mostly on how much troops you've left and how much you're facing, I think.
Staying put using the cover of the wall may provide cover vs. small arms fire, but most of his artillery will fall on your side, so the wall is not much help. And staying put won't get you anywhere.
If you retreat into scattered trees or woods your opponent can easily walk his artillery aim there, too. Treebursts are fun to watch, but mostly for him. But if you have lost so many men already that you can't assault him anyway (less than 2:1 ratio, better 3:1), you'd better run now than never.
If not, rushing over the wall might be your best bet. I mean, you either move forward to attack or move back to retreat. Staying put in enemy fire is the worst you can do in my opinion. If you have the numbers, attack _now_ or retreat _now_.
If you face SMG squads, it's better to fight them from 100-150 m plus your support weapins from even greater distance, where they can't hurt you that much. This costs ammo, but it saves lives.
Afterthoughts :
If you weren't so close already, you could think about splitting your force so he can't concentrate his artillery. Possibly too late now.
Smoke (artillery, mortars, tanks, whatever) comes quite handy in such situations. A few rounds could allow you to advance into that cover. Mortars + tanks are ideal, because it only takes them ~ 30 seconds to deploy a small smoke screen.