No other nation is more immediately affected by the political upheaval in Iran than South Africa.

Without Iranian oil -- and this country imports about 90 percent of its petroleum from Iran -- the highly industrialized South African economy will be in serious trouble.

The government here already has warned South Africans that they may soon face gasoline rationing.

Minister of Economic Affairs Chris Heunis has his experts trying to find another major oil-exporting country willing to deal with South Africa. Failing that, South Africa is expected to begin to buy oil -- at an estimated 20 percet above present world prices -- from the black market.

"We have to face up to the prospect that the future Iranian leader, whether the shah or somebody else, is not going to want to continue the special relationship between our two countries," a high Sough African official said.

That special relationship has existed since World War II, when the father of the present shah come to South Africa in exile. He died here and his body was returned to Iran. A statue and museum in a Johannesburg suburb are dedicated to his memory.

South Africa's support for the present Iranian monarch, Shah Mohammad Reza Pahlavi, has been consistent since he came to power. Iran is South Africa's best customer in the Middle East, importing cars, mobile homes and citrus fruit.

Iran has returned that support. In 1973, when most Arab oil states imposed an embargo on South Africa because of its racial discrimination, the shah continued to supply all the needed oil.

Iranians also have a 17 percent interest in a South African refinery.

South Africa's fears that the Iranian political crisis will leave this country in the lurch were heightened last week. Iran's new prime minister, Shahpour Bakhtiar, said has government would end oil sales to South Africa and to Israel, another country largely dependent on Iranian petroleum.

South Africa, which has no oil of its own, imports about 430,000 barrels daily. The total would be far greater except that about 75 percent of the country's energy requirements are met by coal and hydroelectric power. South Africa has substantial coal reserves and is building several atomic power plants.

Fearing a U.N. embargo because of its racial preactices, the government here also has built up a large stockpile of oil, storing it in abandoned mind shafts. Althoiugh the amount is kept secret, the supply on hand is believed to be sufficient for South Africa's basic needs, depending on the severity of rationing, for a period from 18 months to three years. The stored oil would be doled out only in an emergency and is not expected to be tapped at this time, an official said.

Any oil shortage in South Africa also would have serious consequences in neighboring land-locked Rhodesia, Rhodesia, because of its racial policies, has endured U.N sanctions for 12 years, but it continues to receive gasoline and diesel fuel through South African channels.

Because of its precarious position as an industrialized nation without oil, South Africa is the would leader in producing oil from coal by several chemical processes.

The government agency, South African Coal, Oil and Gas Corp., has a plant that produces about 5 percent of the country's needs.