We present a method of both polarization and amplitude modulations on an incident beam to obtain a longitudinally polarized subwavelength-sized optical needle. A 4-f system with a spatial light modulator is used to generate experimentally a two-mode alternate cylindrical vector beam by polarization modulation, enhancing performance and facilitating implementation. We optimize the beam focusing properties after passing the beam through an annular aperture to obtain amplitude modulation by the simulated annealing algorithm. Numerical results indicate that a sharp focal spot (0.417A) with a long focal depth (8A) and a strong longitudinally polarized field can be easily achieved.