We consider the possible anomaly free Abelian discrete symmetries of the MSSM that forbid the μ-term at perturbative order. Allowing for anomaly cancellation via the Green–Schwarz mechanism we identify discrete R-symmetries as the only possibility and prove that there is a unique Z4R symmetry that commutes with SO(10). We argue that non-perturbative effects will generate a μ-term of electroweak order thus solving the μ-problem. The non-perturbative effects break the Z4R symmetry leaving an exact Z2 matter parity. As a result dimension four baryon- and lepton-number violating operators are absent while, at the non-perturbative level, dimension five baryon- and lepton-number violating operators get induced but are highly suppressed so that the nucleon decay rate is well within present bounds.