The D.C. Court of Appeals yesterday upheld the constitutionally of the District's preventive detention law, which allows some accused persons to be held in jail without bond on grounds that their past records and their potential for committing more crimes make them too dangerous for pretrial release.

The 7-to-2 decision by the city's highest court was one of the first legal tests for preventive detention laws.The District's 10-year-old law has been especially controversial in recent months because prosecutors have requested more frequent use of it in the face of a sharply rising crime rate in the city.

While the court overwhelmingly upheld the law, it also ruled that two D.C. Superior Court judges acted improperly last year when they closed their courtrooms to the press and public during preventive detention hearings.

The such hearings are to be held, Chief Judge Theodore R. Newman wrote in the majority opinion, trial judges must keep them open to all unless they determine that there are extraordinary circumstances that make closing courtrooms necessary. Defense attorneys had said that adverse publicity at such hearings would hurt the chances of defendants to later have fair trials.

The Supreme Court has not ruled on the constitutionality of preventive detention laws. But Supreme Court Chief Justice Warren E. Burger recently called for giving judges greater leeway to lock up potentially dangerous defendants pending their trials.

Robert W. Ogren, Principal Assistant U.S. Attorney, said he welcomed yesterday's court decision. "The court sustained our view, which we felt was proper for years," Ogren said.

The Public Defender Service sharply attacked the decision. Attorney James H. McComas said in a prepared statement that the ruling reduced constitutional protections for accused but presumptively innocent persons by "establishing a system in which the accused person can in effect be sentenced to jail while he is waiting for his trial on the charges against him."

McComas and the other public defender attorneys who handled the challenge of the preventive detention law, Mary Lou Soller and Silas J. Wassertrom, said an appeal of the ruling to the Supreme Court is being considered.

The challenge to the District's preventive detention law resulted from two separate court cases involving Marvin L. Edwards, a 17-year-old youth with a lengthy juvenile record, who was arrested on March 18, 1980 on a charge of armed rape.

At a closed hearing 10 days later, government prosecutors asked Superior Court Judge Shellie Bowers to order Edwards held without bond pending his trial, and presented evidence that he had acknowleged involvement in 16 other violent crimes. Bowers, hoever, refused the request on the basis that various procedures used in preventive detention hearings violated a defendant's constitutional rights.

On April 1, Edwards was charged with burglary, robbery, and sodomy in a separate incident. At a second, partially closed hearing a week later before another judge, prosecutors again requested that Edwards be held without bond pending trial. Judge David L. Norman granted the request.

The Public Defender Service, representing Edwards, appealed Norman's order approving the preventive detention while the U.S. Attorney's office appealed Bower's refusal to order preventive detention. The government also appealed the courtroom closures and lawyers for The Washington Post filed a friend of the court legal brief claiming that closing the courtrooms violated the First Amendment guarantees of freedom of the press.

The controversy over preventive detention centers on whether defendants in the District have a Constitutional right to be released on bail while awaiting trial, and also how far government prosecutors must indicate before trial what evidence they have and what testimony witnesses will give.

In the District, the vast majority of criminal suspects are released on bond. Judges can set various conditions in releasing suspects to protect the community, such as ordering that suspects must stay away from witnesses who are likely to testify against them.

However, if a defendant is ordered held without bond pending trial, the government must bring the case to trial within 60 days, or bail must be set.

In a 54-page decision written by Newman and joined in whole or in part by all but one judge on the nine-judge court, the court ruled against that holding defendants without bond was unconstitutionally because it deprived them of their liberty before they were found guilty.

The court also rejected the Public Defender's contention that defendants have the right to cross-examine government withnesses.

The court said that judges could instead consider hearsay evidence -- such as testimony of a police officer about his conversation with a witness -- in determining whether to grant a preventive detention request.

Newman's opinion also rejected the contention that preventive detention is a form of punishment. ". . . Pretrial detention was intended to protect the safety of the community until it can be determined whether society may properly punish the defendant," Newman wrote, citing procedural safeguards for defendants which are part of D.C. law.

The preventive detention statute has been invoked sparingly in the District since it became law in 1970, with judges granting about 55 of the 65 requests by prosecutors in the past five years, according to U.S. Attorney's Office statistics.

However, U.S. Attorney Charles F. C. Ruff recently announced a policy calling for increased use of preventive detention and the number of prosecutors' requests have jumped, according to more recent figures. The 13 requests made in the first four months of this year already exceed the dozen requests made in 1980.

Preventive detention recently was approved in the higly publicized case of Bernard C. Welch, who later was convicted of fatally shooting physician Michael Halberstam, and David I. Garris, convicted of murdering a WMAL radio advertising executive. According to prosecutors, there were two requests for preventive detention made last week, including one yesterday.

In a strongly written dissent, Judge Julia Cooper Mack suggested that Newman's opinion "treads where wise men have feared to tread," where wise men have feared to tread," noting that the Supreme Court "has left unresolved, for over a century and a half, any question of whether the Bill of Rights confers a right to bail.

"My concern is with MY constitutional rights," Mack wrote, "For I, like millions of Americans have lived for a time at least, believing that the United States Constitution prohibited my punishment for a crime until such time as I have been found guilty of committing that crime."

The American Civil Liberties Union criticized the court's decision. "We think it's a terrible idea," said legal director Arthur B. Spitzer, "because we don't think you can predict who's going to be a danger and who's going to commit a crime while out awaiting trial. In addition it deprives the defendant of the ability to prepare for his trial because he is locked up."

The court rejected the Public Defender's position that the burden of proof required at criminal trials -- proof beyond a reasonable doubt -- should also be the required standard for holding a suspect under preventive detention. aInstead, it said only a lesser standard of proof is necessary.

Had the court ruled otherwise, one law enforcement source contended, it would have forced prosecutors to reveal too much of their case before trial and discourage the use of preventive detention requests. One law enforcement source believed the court "didn't want them [the hearings] to be fishing expeditions, or a way for the defendant to see the government's case in advance."

Law enforcement sources predicted that even with the court's ruling preventive detention would continue to be used selectively, much the way it has been in recent weeks.

Public Defender McComas said he believed the result was a "political answer to perceived community concerns," in much the same way that capital punishment has been approved by the Supreme Court yet rarely implemented.

The other dissenter from part of the majority opinion was Judge John M. Ferren.