The Soviet Union has announced that it is cutting off all arms supplies to Somalia, creating a potential dilemma for Western nations grateful for President Mohammed Said Barre's help ending this week's Lufthansa hijack saga.

Anatoly Ratanov, the Soviet ambassador to Ethiopia, said at a news conference Wednesday in Addis Ababa that Moscow had "officially and formally . . . stopped arms supplies to Somalia."

He said the Soviets were now providing "defensive weapons" to Ethiopia to aid it in repulsing the Somali forces that have advanced deep into Ethiopia's disputes Ogaden region.

U.S. analysts said yesterday that they had anticipated the Soviet decision to cut off arms supplies to Somalia ever since Siad Barre's mission to Moscow in early September ended in failure.

"The indicators are that Soviet shipments of major weapons to Somalia have halted, although they probably have not cut off spare parts," a U.S. official said. "At the same time, the Soviets are pouring a lot of stuff into Ethiopia."

The big question is how long Somalia can scrape along without a major arms supplier before the flow of Soviet arms into Ethiopia begins to turn the desert war in Ethopia's favor?

Siad Barre has been frantically searching for an alternative source of weapons in recent months, and at one point, it apeared that the Carter administration was willing - even eager - to end Somalia's dependence on Soviet arms supplies.

American and European interest in helping Somalia began to wane, however, when it became clear that regular Somalia forces had driven deep into Ogaden and were also threatening the newly independent Red Sea nation of Djihouti.

Now, speculation is rife in Europe that Somalia's helpful role in ending the Lufthansa hijacking may have at least slightly altered the equation.

President Carter appealed directly to Siad Barre to assist Germany in saving the lives of the hostages and both Carter and West German Chancellor Helmut Schmidt subsequently expressed their strong appreciation for the Somali leader's stand.

Somalia yesterday joined West Germany in denying that there was any formal quid pro quo. A Somalia spokesman said his government had acted out of "humanitarian" considerations, and labeled reports that it had attached preconditions to its cooperation "baseless and pure propaganda."

German Minister of State Hans-Jurgen Wischnewski, who represented the Bonn government in negotiating with the hijackers at Mogadishu, also insisted that Siad Barre had placed "no conditions" on Somalia's assistance.

But the Bonn government indicated that it would continue furnishing some equipment and aid to Somalia, and it remained to be seen whether Western countries will now show a renewed interest in weaning Siad Barre away from Moscow.