Foreign Ministers of the nine Common Market countries decided today to put economic pressure on South Africa to help force change in that country's strict racial segregation system.

The first step will be to draw up a code of conduct for European companies operating in South Africa. If that is not effective, informed sources said, the European countries will prepare economic and legal sanctions.

The decisions by the ministers of the European Economic Community follow recent efforts by the Carter administration to force changes in South Africa's racial policies.

"We must erode apartheid at its foundations," British Foreign Secretary David Owen told journalists after the ministers' meeting on African issues. "To show credibility, the European Community must develop a colerent strategy that uses its economic lower as a catalyst for change in South Africa."

Castigated in the past by Third World nations that denounced their declaration against racial justice in Southern Africa as ineffectual, the Common Market countries have now decided to use their economic weight to exert greater influence and reinforce the flagging Anglo-American efforts to achieve majority rule.

British companies account for about 50 per cent of all foreign investment in South Africa, but West Germany, France and the Netherlands also have large holdings.

The Common Market nations plan to coordinate their views on the proposed code of conduct in coming weeks and present a common set of principles at the United Nations conference on apartheid to be held in Laos, Nigeria, in late August.

The aims of the code will include allaviating wage differences between black workers and whites, abolishing discrimination in factories and granting blacks the right to join labor unions. Companies that do not adhere to the code would lose state investment guarantees, Common Market Sources said.

Beigian Foreign Minister Henri Sinonet, who was chairman of today's strategy session, said that commercial and legal sanctins would "not be excluded" if the code of conduct failed to alter South Africa's rules on apartheid.

Apart from the firm stance against apartheid, the Common Market countries have insisted that South Africa evacuate the "occupied territory" of Namibia, which South Africa rules as the territory of Southwest Africa despite U.N. resolutions that it should be independent. They support a United Nations conference - one that includes the participation of South West Africa People Organization - to determine Namibia's destiny.

Several ministers noted that reaching a Community consensus on economic action against South Africa is necessary so that companies of a particular country would not be aided or past, British firms companies of a particular country would not be aided or penalized by national policy. In the past, British firms complained that they lost business in Africa to European competitors whose governments did not pursue a hard moral line on wage exploitation and discrimination.

To some exent, the European Community's newly assertive policy toward Africa has been affected by its member state's colonialist history. To resolve the dilemma posed by special trade links maintained by Britain and France with their former colonies, the Community as a whole signed a preferential trade accord in 1975 - called the Lome Conveniton - with 46 developing countries, including all of independent black Africa.

While European policy toward Southern Africa may, in part, be influenced by moral and historical impulses. Common Market views on the delicate situation around the "Horn of Africa" stem from pragmatic concern about growing Soviet influence there.

Common Market foreign ministers privately expressed caution today about the temptation to provide aide to Eritrean secessionists fighting the pro-Soviet military rulers in Ehthiopia.

"For the moment, we just want to encourage Somalia to move toward non-alignment, but that's all we can ask," remarked one foreign minister.

Sources here said they are pleased that Saudi Arabia is increasing its economic aid to Somalia. European experts feel the Saudis could exert a moderating influence in the region by helping to quell pro-Soviet movements.

"The Horn of Africa is a sensitive and difficult area and a sudden flareup there could be just as dangerous as in Southern Africa," Owen said.

Since the sea lanes near the Horn are vital for shipping oil to Europe. Common Market politica sources say their governments are anxious to maintain amicable relations with stable regimes in neighboring countries.

But, above all, the Community plans to harp against big-power involvement in Africa.

"We perceive a role for Europe as the arbiters who oppose foreign interference on the African continent," Simonet said.