I had a visa to Portugal for 3 months to visit my family. My point of first entry was Germany, but they denied me entry, because I didn't have a return ticket from Portugal to Germany, but I had a return ticket from Germany back to my country. They stamped my passport, but told me my visa is still valid, I'm not sure how it works, can anybody please tell me if its possible to enter with the same visa, which was stamped refused entry?
If you were told your visa is still valid, then there is no reason to believe it isn't. Under the Schengen regulations, denying entry, revoking a visa and annulling a visa are three different things that are supposed to happen in different circumstances. Border guards always have the option to deny entry without revoking/annulling the visa if they see fit.
This possibility is explicitly touched upon in one of the examples in the Handbook for the processing of visa applications and the modification of issued visas:
Example: A Ukrainian national holding a multiple entry visa issued (for business purposes) by the Hungarian consulate in Uzhgorod (Ukraine) flies from Kyiv (Ukraine) to Rome (Italy) with the purpose of tourism and he cannot prove the possession of sufficient means of subsistence for staying in Italy. It is obvious that he has already used his visa for business purposes in Hungary and the visa is still valid.
In this case the visa should not be annulled but entry should be refused.
It means that the German border guards considered that you were not able to show that you fulfilled the requirements to enter the Schengen area at the moment but that there were no reasons to suspect you could not or that you had obtained the visa fraudulently. It's therefore possible for you to come back at a later time, perhaps with additional documents as appropriate.
By contrast, if the visa had been annulled, the stamp would say “Annulled” (or, in German, “Annulliert”). Border guards are supposed to stamp this on the visa itself (not on another page next to it) and to scrap the word “visa” and a couple of security features from the sticker to make it absolutely clear that the visa is not valid anymore. You are also supposed to get a notification under the guise of a standard form informing you of the grounds for the annulment and of your right to an appeal (article 34 of the Schengen Visa code). Since you did not describe anything like this, it seems that your visa is indeed still valid.
For completeness, note that a visa can also be “revoked”. In that case, the visa becomes invalid too but the stamp says “Revoked” (German: “Aufgehoben”), not “Annulled” (the distinction is that a visa should be annulled when you are suspected of fraud and merely revoked in other cases). The visa sticker should be defaced and the person should get a standard notification form in case of revocation too.
Obviously, border guards will see the “entry denied” stamp (and perhaps an entry in the visa database, I am not sure) and probably look at your situation a little more carefully than usual the next time you present yourself at the border. If they ask, just explain candidly what happened, be genuine about your intent and tell them what you did to remediate the situation (e.g. get a ticket all the way to Portugal). But as long as it hasn't been revoked or annulled, you are still allowed to (try to) enter the Schengen area with your current visa.