I have one PlayStation 3 with my main account in use. I'm planning on getting another PS3 in a few months and I will use my account of course. But first, I want to share that account with a friend. I know how the sharing accounts works on the PS4, but, for instance, if my friend and I use the account, how will I be able to use it in my new PS3 later? Do he has to erase the account on the PlayStation or how does it work on the PS3?
Your friend has to create a new user on his PS3 (name doesn't matter) and connect to the PSN using your existing PSN account. He then has access to your download list and is able to download any game you bought. Once he deletes the user from his PS3 he is not able to play games downloaded via your PSN account anymore.
Unfortunately, since Sony changed the rules for sharing some time ago, you can only download any bought game on up to two consoles. So if you want to re-download your games on your new PS3 you first have to deactivate one of the two consoles currently activated for your account (i.e. your old PS3 or your friend's PS3).
To deactivate a system choose Account Management on the XMB. Go to System Activation > PS3 System > Game > Deactivate System.