The Supreme court ruled yesterday that company pension plans must credit the time spent in military service by employees on leave from their jobs.

The Labor Department said the ruling affects possibly hundreds of thousands of veterans who joined the armed forces after 1940 and then returned to their former employers.

Pension payments "are predominantly rewards for continuous employment with the same employer," Justice Thurgood Marshall wrote for a unanimous court.

"Protecting veterans from the loss of such rewards when the break in their employment resulted from their response to the country's military needs is the purpose" of the Military Selective Act of 1970, the court held.

The justices rejected a claim by Alabama Power Co. that pension payments are like vacation payments: compensation for service rendered to the firm.

By taking that position, the company calculated that the monthly pension payment it owed to World War II veteran Raymond E. Davis was $198.95. Had Alabama Power credited him with the 2 1/2 years he spent in service, he would have gotten $17.11 more, or $216.06.

The government acted as Davis' lawyer, under a section of the draft law authorizing the Labor Department to investigate claims of veterans such as Davis and the Justice Department to the represent them.

In this case, the government contended - and the court agreed - that Alabama Power violated a provision of the law requiring employers to restore a permanent employee who returns from military service to his former status "without loss of seniority" and with the right "to participate in insurance or other benefits offered by the employer . . ."

Davis became a permanent employee of Alabama Power in August, 1936, went into the service in March, 1943, returned to his job 30 months later, returned to his job 30 months later, and retired June 1, 1971. He was on active military duty when the company established its fully funded pension plan in July, 1944.

In other action: WELFARE

The court let stand a ruling upholding a law requiring each state to compel unwed mothers, as a condition of seeking or getting federal welfare aid, to cooperate in establishing paternity.

The ruling was handed down last Nov. 11 by a federal judge here. The Supreme Court denied a petition to review it filed by the state in Alaska, the Neighborhood Legal Services Assocation and the National Welfare Rights Organization. The ruling affects mothers who receive aid for an estimated 2.5 million dependent, illegitimate children.