The purpose of the Berlin Wall was, officially, to prevent fascists from infiltrating the Eastern Bloc from the west; to this end, the wall was called Antifaschistischer Schutzwall, or “anti-fascist protection wall”, which further means the DDR (East Germany)/Eastern Bloc saw the West/NATO, and the BRD (West Germany) in particular, to be fascist states.
Realistically, it was to prevent the flight of East Germans/other Eastern Bloc citizens from fleeing to the West. Several million East Germans left the DDR for the BRD by way of the West Berlin/East Berlin border up until the Wall's construction. Among other effects, this resulted in a brain-drain in the DDR, something the ruling Socialist Unity Party (SED) wanted to prevent/end.
Was it effective? Did it achieve the goals for its construction? Arguably, yes. After the Wall’s construction, only a few thousand people attempted bypassing it. Several hundred people were killed attempting to do so. East-West migration was severely hampered by the Wall and the Inner German Border.