In this letter, we propose a novel algorithm to design beamformer with flat beampattern for massive multi-input-multi-output systems where the base station is equipped with large-scale uniform planar array (UPA). This flat beam can be both used for transmissions in broadcast channels and beam alignment for millimeter wave systems. Given the ideal flat beampattern, the beamforming design is formulated as the minimum mean squared error problem under the constraint of total transmit power or equal per-antenna power. A twofold alternative Riemannian optimization algorithm is proposed to solve the problem and the conventional method via multiconvex transformation is used for algorithm initialization. For UPA with massive antennas, the angle grid for beamforming should be dense enough and our proposed scheme can achieve better beampattern with even lower computational complexity compared to conventional schemes. Simulations validate the superiority of our proposed scheme.