The Supreme Court, in its first decision on testing for drug and alcohol abuse in the American workplace, ruled Tuesday that some workers in sensitive government jobs and some entrusted with public safety may be forced to undergo such tests.

By a 7-2 vote, the justices upheld mandatory blood and urine tests for railroad workers involved in accidents. By a separate 5-4 vote, they upheld urine tests for U.S. Customs Service employees seeking drug-enforcement jobs.The court said tests for the railway and customs workers do not violate privacy rights, even when there is no evidence in advance of individual drug or alcohol abuse.

The rulings do not affect private employment, although the decisions likely will encourage private employers who impose or plan to impose such tests. Today's rulings also do not deal directly with random drug tests.

In the railway workers case, Justice Anthony M. Kennedy said for the court, "The government interest in testing without a showing of individual suspicion is compelling. Employees subject to the tests discharge duties fraught with such risks of injury to others that even a momentary lapse of attention can have disastrous consequences."

In his opinion for the court in the Customs Service case, Kennedy said the nation's fight against drug smuggling demands that customs workers be healthy and not likely to be bribed by offers of money or drugs.

"The government has a compelling interest in ensuring that front-line interdiction personnel are physically fit and have unimpeachable integrity and judgment," he said. "This national interest in self-protection could be irreparably damaged if those charged with safeguarding it were, because of their own drug use, unsympathetic to their mission of interdicting narcotics."

Joining Kennedy in upholding the tests for the railway workers were Chief Justice William H. Rehnquist and Justices Byron R. White, Harry A. Blackmun, Sandra Day O'Connor, Antonin Scalia and John Paul Stevens. Justices Thurgood Marshall and William J. Brennan dissented.

In the Customs Service case, Marshall and Brennan were joined in dissent by Scalia and Stevens.

Marshall, in a dissenting opinion in the railway workers case, accused the court of being "shortsighted" in allowing "basic constitutional rights to fall prey to momentary emergencies."

"History teaches that grave threats to liberty often come in times of urgency when constitutional rights seem too extravagant too endure," he said.

Scalia, in his dissenting opinion in the Customs Service ruling, said there is a crucial distinction between the tests for that agency's workers and those involved in rail accidents.

"The demonstrated frequency of drug and alcohol use" by railway workers "and the demonstrated connection between such use and grave harm" makes those tests reasonable, he said.

By contrast, Scalia continued, the evidence to support the tests for Customs Service employees is lacking. "The Customs Service rules are a kind of immolation of privacy and human dignity in symbolic opposition to drug use," he said.

Tuesday's rulings will have an important bearing on other drug and alcohol testing programs conducted by federal, state and local governments.

Former President Reagan signed an executive order in September 1986 calling for drug testing of government employees. That call for a drug-free workplace has been echoed by numerous public officials.

In other actions, the court:

-Ruled that creditors owed money by insolvent savings and loans do not have to wait for a federal regulatory agency to act before they take the thrift institutions to court.

-Revived a lawsuit by the family of a man killed when the allegedly stolen car he was driving smashed into a police roadblock in Inyo County, Calif. The justices sent the case back to San Francisco-based 9th U.S. Circuit Court of Appeals to decide whether the police conduct was unreasonably dangerous.