The nation's major supermarket chains, including Giant and Safeway, won a major legal battle yesterday when a federal judge in Dallas threw out a massive antitrust suit that could have cost the stores tens of millions of dollars in damages if they had gone to trial and lost.

Judge Patrick Higginbotham's ruling apparently ends a long struggle by thousands of cattle ranchers, who claimed that the supermarkets conspired with packing houses and a meat-price newsletter to hold down the prices the ranchers received for their steers.

"This takes the supermarkets out of the case," said Wilson Herndon, the Dallas attorney who represented the retail stores in the complex case. "The ball is in their court," he said, referring to the cattle ranchers, who have tried in vain for years to force the supermarkets to defend themselves at a full trial.

Lex Hawkins of Des Moines, Iowa, attorney for the Iowa-based organization of ranchers that instigated the case, the Meat Price Investigators Association, could not be reached yesterday for comment on the possibility of an appeal. Other attorneys familiar with the case, however, said it was unlikely that the U.S. Court of Appeals for the Fifth Circuit, which reinstated the case after Judge Higginbotham dismissed it once before, would overrule him again.

Assuming that the judge's decision stands, it ends a tangled, long-running chapter in a struggle that could have revolutionized the nation's entire system of marketing beef. It also lifts from the supermarkets a legal cloud that threatened to cost them heavily in the treble damages that would have been assessed if they had stood trial and lost.

The cattle ranchers sought to prove that the price they get from the packing houses is determined by the so-called Yellow Sheet, a meat-price newsletter based in Chicago, and that price in turn is based entirely on what Safeway and A&P say they will pay for beef in a given week. Instead of competing, the ranchers alleged, the packing houses simply pass along the price set by the supermarkets, which the ranchers said held down the bidding price.

Judge Higginbotham, however, accepted the supermarkets' argument that they could not be sued by the ranchers at all because they are shielded by a 1977 U.S. Supreme Court ruling known as the Illinois Brick decision.

The high court ruled, in effect, that only direct purchasers or sellers, not indirect or down-line purchasers or sellers, could be held liable for antitrust damages. Higginbotham applied that ruling to the ranchers' case and dismissed it once before, but the Fifth Circuit court reinstated it in 1979 to give the ranchers a chance to prove that the packing houses were only a "conduit" for a price set by the supermarkets and passed down in a rigid, inflexible formula.

Yesterday, Higginbotham said the ranchers had failed to prove that and therefore they could not sue the supermarkets.

His ruling leaves standing the ranchers' case against the biggest packing houses and against the Yellow Sheet.