On the last day of its session in early January, the Massachusetts legislature overrode a gubernatorial veto and enacted a law requiring the two major state employe pension funds to sell off all investments in banks or corporations that do business in or with South Africa.

It was a major victory for an anti-apartheid coalition that pressed the divestment bill against the opposition of the South African government and several major corporations, and it followed a year in which several states and cities took similar actions.

Overall, as much as $300 million in publicly controlled funds will be withdrawn from companies doing business with South Africa as a result of action by states and cities in 1982 alone, according to reports compiled by the American Committee on Africa.

The Massachusetts law, adopted by votes of 133 to 2 in the state house and 23 to 5 in the senate, requires the pension funds for state employes and public school teachers to divest themselves within three years of any interest in corporations that do business in South Africa or banks that make loans there.

State Sen. Jack Backman, a Democrat who sponsored the measure, said the pension funds hold about $91 million in securities of such corporations as Ford Motor Co., Citicorp and Manufacturers Hanover, which are known to have business dealings in South Africa.

"We put together a coalition that was insurmountable," he said. "We had the public employe unions, so nobody could argue this went against the interest of their members. It's their money. We had the religious community. We had the black community. And we had a number of community change and political action organizations, freelance activists who came together around this one issue."

Similar coalitions have been trying for many years to persuade corporations in this country to give up their investments in South Africa and stop doing business there. Since 1972, the National Council of Churches and other religious groups have called on such major corporations as General Motors Corp. , Union Carbide Corp., Texaco Inc. and General Electric Co. to withdraw from South Africa, on the grounds that investment in South Africa supports and encourages the white-supremacist goverment.

The foes of apartheid have had limited success with the corporations, but they appear to be making considerable headway with investments controlled by state and local governments.

Many states and cities have enacted laws prohibiting future investment in South Africa or in companies doing business there. Divestiture of at least some existing holdings has been voted by Nebraska, Connecticut, Kansas, Michigan, Multnomah County (Portland), Ore., and Philadelphia, in addition to Massachusetts.

Similar bills are pending, or are expected to be introduced this year, in Minnesota, Wisconsin, Oregon and New York City.

In the short run, it probably makes little difference to South Africa who holds the stocks or bonds of companies that do business there. But according to Dumisani Kumalo, an exiled South African black who is the point man on this issue for the American Committee on Africa, "it has a tremendous impact" over a period of years.

"South Africa raises a lot of money in this country, and more and more investment houses are refusing to handle South African issues because of the politics," he said. "If a state like Massachusetts says, 'We won't allow our money to be used to make loans to South Africa,' this cuts off a big source of capital."