A new, to our knowledge, iterative algorithm for achieving optimization of beam profiles in a threedimensional volume is presented. The algorithm is based on examining the region of interest at discrete plane locations perpendicular to the propagation direction. At each such plane an intensity constraint is imposed within a well-defined transverse spatial region of interest, whereas the phase inside that region as well as the complex amplitude outside the region is left unchanged from the previous iteration. Once the optimal solution is found, the mask that generates the desired distribution can be readily implemented with a planar diffractive optical element such as a computer-generated hologram. Several computer simulations verified the utility of the proposed approach.