King Khalid of Saudi Arabia arrived here today on his first state visit to West Germany, an indication of the recent strengthening of relations between Europe's most powerful economy and the Middle East's richest oil-producing state.

Not only has Saudi Arabia become West Germany's largest Arab trading partner and its largest supplier of oil, but this year Bonn took the unprecedented step of going to Riyadh for a loan of about 3 billion German marks (rougly $1.7 billion) to help finance its higher oil bills.

For Bonn, the visit also is another demonstration of the general European urge for more diplomatic involvement in the Middle East. There is likely to be keen West German interest during Khalid's four-day trip in the Saudi response to last week's declaration on the Middle East by the nine Common Market leaders. The Europeans formally declared the right of Palestinians to self-determination and urged that the Palestine Liberation Organization be associated with the peace talks.

The statement, a compromise between Europe's desire to take an initiative in the Middle East and its reluctance to undermine President Carter's effort, has irritated both the Israelis and the Arabs.

The European leaders also said they will start exploring formulas to bring about direct discussions between the Israelis and Palestinians about the autonomy of those living in Israeli-occupied territory in Gaza and the West Bank of the Jordan River.

In this connection, the king's visit has given Chancellor Helmut Schmidt a timely opportunity to sound out Saudi views on Middle East peace prospects before he and other West European leaders meet Carter at the seven-power summit starting in Venice this weekend.

For the Saudis, this visit highlights a shift in their foreign policy orientation as well. Shocked by the revolution in neighboring Iran, and by the inability of the United States to guarantee stability in the area, Saudi officials have sought to secure firmer ties with Europe.

While the royal family has strengthened internal security, it still faces the sensitive process of economic development to establish a solid base that will outlast its oil reserves -- an area in which the West Germans are expected to play a major role.

More difficult still is the problem of guaranteeing security in the Persian Gulf region generally. In spite of the presence of 10,000 mostly American military advisers in the region, plus a 60,000-man Saudi Army, the Saudis worry about security.

Riyadh's answer is for the nations of the area to take joint responsibility for their security and for defense of the vital Persian Gulf oil route. How to achieve this is another topic for talks between Schmidt and Khalid, according to German sources.