Seven years ago Indonesia's national oil company, Pertamina, nearly collapsed under the weight of a $10.6 billion debt, threatening to bring down the Indonesian economy with it. An investigation turned up vastly overextended borrowing, bad management and massive corruption. The company's auditors threw up their hands.

Today, all but about $500 million of the debt has been eliminated and management tightened up. "Pertamina has pretty much recovered," said a Western executive who deals with the company regularly.

"They've really come a long way," remarked a U.S. oilman. "One goal was to get themselves in shape so they would be debt-free and auditable. I think maybe this year they'll achieve that status."

Pertamina's success story is one reason that bankers and economists consider the Indonesian economy to be generally well managed and express confidence that the country can deal with the harsh effects of the world economic downturn. But problems persist. According to foreign and Indonesian officials, corruption remains rife, millions of dollars still "leak" through the system and many of those responsible go unpunished.

The Pertamina story tells much about how Indonesia works today. Run by generals, it traditionally has been a major source of funding for the armed forces. But not all of the diverted money has gone into the bank accounts of the generals and their associates, diplomats and oil industry sources here say. Much of it has been distributed in the Javanese style of sharing the bounty or channeled into enterprises that form part of the government's vast "bureaucratic capitalism."

"Very often the graft goes into pension funds or is divided up at the end of the month," one diplomat said. "The boss has to share a fair amount with everybody else." The Pertamina mess of the mid-1970s is only partly attributable to corruption, however.

"They were trying to do too many things," an American oil executive said. "There were too many big projects . . . I suppose some corruption contributed to the problem, but you can't explain it by corruption alone. There was a lot of mismanagement."

In charge of Pertamina at the time of its near-collapse was Ibnu Sutowo, a flamboyant general considered one of President Suharto's closest friends. Sutowo reportedly was instrumental in encouraging Suharto's move to take power from the late president Sukarno in 1966.

Given virtual carte blanche by Suharto to spearhead Indonesia's development effort, Sutowo built up Pertamina and extended its operations beyond the oil sector into such enterprises as a steel plant, a television station and high-rise office buildings.

As the Pertamina empire's lavish spending showed signs of spinning out of control, public protest obliged Suharto to launch an investigation in 1970. A commission of inquiry found that much of the revenue Pertamina collected was never passed on to the treasury, but the report was essentially ignored.

According to the book "Suharto's Indonesia" by Australian journalist Hamish McDonald, the International Monetary Fund and U.S. State Department began to worry about Pertamina's finances in 1972. U.S. aid was suspended and American authorities told American banks to stop plying the company with loan offers. One American banker is said to have grown concerned when he saw an open filing cabinet drawer at Pertamina with loan agreements casually tossed inside.

As the dimensions of Sutowo's mismanagement were becoming clear, he was "dismissed with honor" by Suharto in March 1976, and the following month parliament was told the full extent of Pertamina's indebtedness. The government took over the debts and began to whittle them down.

Although Sutowo admitted to irregularities, including conflict of interest in a billion-dollar supertanker fiasco, he was cleared of any wrongdoing and retired to preside over his business empire of at least 37 companies -- ranging from vehicle imports to shipyards and a major bank.

According to a directory published by a dissident group called the Committee on Abused Power, one of Sutowo's business partners was the president's wife, Tien Uharto, known by some wags as "Mrs. Tien percent."

Sutowo remains a subject of controversy and resentment among some Indonesians, particularly an educated elite fed up with rampant corruption. Sutowo was unavailable for comment. An associate at one of his offices said he was visiting the United States.

The death of a former aide to Sutowo in 1976 resulted in a three-way court battle in Singapore over the aide's fortune. According to court documents, the aide, Haji Achmad Thahir, had millions of dollars in Singapore bank accounts, although his Pertamina salary amounted to only about $9,000 a year. His widow, the documents said, withdrew most of the money before two sons by a previous wife and Pertamina also claimed the funds.

Pertamina charged that Thahir made his fortune through "illegal payments" by foreign contractors. The case is still before the Singapore high court.

After Sutowo's departure from Pertamina, Maj. Gen. Piet Haryono took over the company and is credited with putting it back on a sound footing. He purged the senior management, at one point denouncing a group of the reputedly more corrupt top officials as "cannibals."

"The whole thing I had to do was get back to the oil business," he said in an interview. "We have to be aware there is corruption indeed and try to build a better control system," he added. But he declined to "open old wounds" by going into details.

Despite his efforts, scandal tainted Haryono's administration. He retired after more than 100 middle-level Pertamina officials and employes were implicated in an oil piracy scheme that siphoned off $12 million worth of loads from tankers.

Suharto replaced Haryono in April 1981 with Brig. Gen. Joedo Sumbono, a 20-year Pertamina employe who had led the oil-piracy investigation. The choice was controversial because Sumbono was a close friend of Sutowo and has admitted he still seeks his former boss' advice from time to time. But he has denied accusations that he is implicated in the Thahir case.

Today, both Indonesian and Western oil officials agree that Pertamina is under tighter financial controls and that discipline among its more than 40,000 employes has improved.