A D.C. Superior Court judge has ruled that the common practice of sharing winnings from lottery tickets cannot be enforced legally despite an agreement by the ticket holders.

Judge Rufus King III had been asked to rule in a case involving two former friends who regularly bought lottery tickets together until they won $20,000.

In apparently the first such ruling on the issue in the District, King found that even though betting on lottery tickets is legal in the District, an arcane part of the city code prevents the courts from enforcing gambling contracts.

Although the judge's ruling late last week does not legally affect any similar suits that may be pending in Superior Court, lawyers said the decision should strike a note of caution among lottery ticket buyers who regularly pool resources.

"The failure to enforce an otherwise valid agreement would chill an everyday practice reported widely in the media of sharing or pooling the purchase of lottery tickets, and encourage, indeed, sanction, fraud and deceit in such arrangements," wrote Richard Fields, the lawyer for the spurned bettor.

Harold Pearsall, a Silver Spring resident, claimed in his lawsuit that on Dec. 16, 1982, he and friend Joe Alexander bought two pairs of lottery tickets as they often did. Pearsall said the two had an understanding that the proceeds would be split and, if small, would be reinvested in tickets.

That agreement, however, came to a halt, Pearsall said, when the pair Alexander bought late in the day came up with winning numbers and paid $20,000. Pearsall said Alexander refused to split the money.

In his opinion, the judge said he believed that a regular agreement to share the proceeds existed between the men, including the case before him. However, the judge said he was prohibited from enforcing the contract between the men by a part of the city code that was enacted at a time when all forms of gambling in the District were illegal. That part of the code invalidates any gambling obligation or loan, wrote the judge.

Alexander's attorney, Joseph Levin, said yesterday that his client planned to abide by the judge's decision and was "not going to give {Pearsall} anything."