Note:
- im = in dem (in the)
- beim = bei dem (at the)
- am = an dem (on the or at the)
im = in dem
Ich war im Supermarkt.
I was in the supermarket.
You entered the shop, i.e you were inside it.
beim = bei dem
Ich war beim Supermarkt.
I was at the supermarket.
In most cases this also means, that you were in the market, but you also could have been there and found it closed:
Ich war beim Supermarkt, aber er hatte zu.
I was at the supermarket, but it was closed.
am = an dem (regional also: auf dem)
You normally won't use am in such a sentence, because it doesn't make much sense:
Ich war am Supermarkt.
I was on the supermarket.
In Austria »am« can also mean »auf dem« (like in St. Anton am Arlberg). In this case this sentence means that you was standing on the roof of the market.
In the rest of the German spoken area »am« only means »an dem« (like in Velden am Wörther See) which in most contexts means "beside" or "close to". But this doesn't make much sense fort a supermarket.
If the grammatical gender of the location is feminine, there is no short form of preposition+article. There is no short form for »bei der« (the word beir doesn't exist), so you have to use the long form:
neuter
das Haus, das Arbeitsamt, das Gerüst
Ich war im Haus. = Ich war in dem Haus.
Ich war beim Arbeitsamt. = Ich war bei dem Arbeitsamt.
Das Plakat klebt am Gerüst. = Das Plakat klebt an dem Gerüst.
masculine
der Palast, der Schuster, der Pfeiler
Ich war im Palast. = Ich war in dem Palast.
Ich war beim Schuster. = Ich war bei dem Schuster.
Das Plakat klebt am Pfeiler. = Das Plakat klebt an dem Pfeiler.
feminine
die Hütte, die Wäscherei, die Wand
Ich war in der Hütte.
Ich war bei der Wäscherei.
Das Plakat klebt an der Wand.