Roberto - Yes, if you run a business in Spain or practice your trade or profession you are obliged to get in the system and it isn't in any way optional. I was trying to say, in as delicate a way as possible, that if you are working in the black economy there are some pros as well as cons for going legal.
Last time I asked my Spanish partner who knows much more about these things than I do, he said that the self-employed got more or less nothing if they became unemployed. That was last year some time and I did read a thread about some kind of assistance being available now. Sorry I haven't got the details. If I get them, I'll post them.
Poppyseed - I have clients whose house and family are in Spain but go abroad regularly to work. Some register as self-employed in Spain and invoice the overseas clients from here. Some only work for one company (like a firm of consultants) and are employed by them in Spain even when the firm is foreign - the company registers here as employers and pay salaries using a payroll agency or accountants. Others have companies in the place where they do their contracts (e.g. UK) and the company bills their clients and pays them a salary or dividends. Finally some have offshore companies which bill their clients and pay them a salary and/or dividends.
All these are legitimate structures but have very different tax implications. All involve income being declared in Spain because once you are tax resident worldwide income is declared in Spain - but there are big variations to do with double taxation treaties, treatment of dividends, tax free allowances etc
The other point to note is that if you actually do some of your work in Spain (e.g. you travel to clients abroad but then write reports, offer advice etc back in Spain) then you have to set up shop here e.g. being self-employed, employed or setting up an SL company.