I PLEDGE ALLEGIANCE . . . The True Story of the Walkers: An American Spy Family By Howard Blum Simon & Schuster. 438 pp. $18.95

AS Howard Blum tells us in his deftly written and carefully researched new book, John A. Walker Jr., retired U.S. Navy chief warrant officer, was almost, but not quite, the perfect spy.

Walker was a textbook mercenary, an agent without scruple: bold, but responsive to direction. Best of all, he offered painless access to a level of intelligence certain to keep his Moscow masters salivating. Small wonder that the KGB man credited with developing the Walker case was declared a "Hero of The Soviet Union."

But the Johnny Walker operation had a built-in flaw. Within months of his first visit to the Soviet Embassy in Washington, Walker's alcoholic wife had learned of his secret career. Another drawback in Walker's spy personality was his inability to maintain a semblance of a normal personal life. He abused his children physically and tormented them emotionally. Although he fancied himself an entrepreneur, he had as little business judgment as he had moral decency.

Walker was a romantic, hungering for status and yearning to cut a fine figure. Yet in a 1986 photograph he looks like Sergeant Bilko masquerading in a Navy cap -- even his mustache, a slim hairline affair, lacks conviction. For all his bragging and broad hints, no one, least of all the bar chicks he wanted to impress, was ever to take Walker for a glamorous man of the world. In later years a beard tempered his slick, small-town aspect, but much of the effect was cancelled by his wig, an artless patch of bogus hair.

Blum, a reporter for The New York Times, a novelist and author of Wanted! The Search for Nazis in America, has waded deep into Walker's sordid world, conducting scores of interviews and studying the mass of investigative material, affidavits, trial records and interrogation reports. He spoke at length with members of the Walker family, and on the telephone with Walker himself. This immersion in the Walker milieu makes it possible for Blum to catch the flavor of their speech, and the sad compass of their dreams.

Johnny Walker's alcoholic father had a yen for show business and the habit of beating his wife and children. When he lost his job as a late-night, radio disk jockey in his hometown, Scranton, Pa., he abandoned his family. Johnny drifted through Catholic schools until, in the 11th grade, he quit. At loose ends, he joined an acquaintance in four spur-of-the-moment burglaries. He was arrested and sentenced to an indefinite term in a state correctional institution. When his older brother Arthur, a Navy submariner, interceded, the judge granted probation. Johnny was 17. A year later, he was old enough to follow his brother into the Navy.

Whatever other mistakes the Navy made in handling Walker, the aptitude assessment was right -- the young recruit had a definite flair for electronic communications, and a genuine enthusiasm for life as a submariner. To all appearances, he had an exemplary naval career, and retired as a chief warrant officer. One must wonder just how Navy security practices allowed a convicted burglar to have 20 years' access to such highly marketable top secrets.

At 20, Walker married Barbara Crowly, a 19-year-old whose childhood had been as miserable as his own. They had four children in rapid succession. Money was short, Johnny was at sea for months at a time, and even when at home, he was a rotten husband, brutally indifferent to his family. Vodka made the days shorter for Barbara.

In 1968, Walker was a highly competent communications technician with a thorough knowledge of naval cipher machines and systems. He was also broke, depressed and despairing of his future, when he slipped into the Soviet Embassy in Washington. When he was smuggled out, he had $2,000 or $3,000 in his pocket -- he can't remember how much. For the next 17 years, Johnny Walker passed his Soviet controller every scrap of communications intelligence he could get his hands on. As he told an interrogator, "If I had access, color it gone."

AS HIS own Navy service was coming to term, Walker envisaged a romantic and profitable second career as a spymaster. He recruited a friend, Jerry Whitworth, another enlisted naval man and communications specialist. If anything, Whitworth's data were even more damaging than the flood of information Walker dredged up on his own.

Then in 1980, Johnny repaid his older brother's earlier kindness by recruiting him into the KGB apparat. Walker's last gift to the KGB was to maneuver his son, Mike, into joining the Navy -- and the family firm.

Along with technical data on modern cipher systems, and an appalling picture of Pentagon security practices, Blum provides fascinating glimpses of KGB methodology. The instructions for servicing dead-drops in the Washington area were so complicated that on at least two occasions Walker enlisted a co-pilot to drive while he juggled snapshots showing the various landmarks. In January 1978, at one of his rare face-to-face meetings with the KGB, Walker, lightly shod, trudged through an Austrian blizzard for almost an hour before the man from Moscow appeared. They then strolled through the deepening snow for another 45 minutes. By the time the meeting came to an end -- always signaled by a dose of motivational therapy congratulating the spy on his role as a "world patriot" -- Walker was convinced that both his feet were frozen.

It was his messy personal life that eventually led to Walker's downfall. Even after their 1976 divorce, and during the years when Johnny offered no help to his destitute ex-wife and their children, Barbara Walker kept the knowledge of Walker's treason loyally to herself. It was 1985 before the weight of the guilty knowledge and pressure from her daughter -- who had refused her father's attempt to enlist her into the family trade -- moved Barbara Walker to call the FBI.

In the meantime, Walker and his confederates had looted the Navy's most secret data, enabled the KGB to decipher more than a million of the Navy's most secret communications, and given the Soviet Union an intimate view of the Navy's secret underwater warfare tactics and strategy.

Johnny Walker is serving two life sentences and a 10-year term. Jerry Whitworth, whose broken family background parallels that of the Walkers, was sentenced to 365 years in prison and a $410,000 fine. Arthur Walker is serving three life terms and another 40 years. Twenty-year-old Mike, who loved his father and wanted a new Subaru, was given two 25-year terms.

Defense Secretary Caspar Weinberger, probably quoting an assessment made by Vitaly Yurchenko, the high-ranking KGB man who defected to the CIA and then changed his mind, has alleged that the KGB considered the Walker case the "most important" operation in its history. One can only hope that Secretary Weinberger has it right -- considering the chores the Navy is facing these days, it would be painful indeed to think the KGB is running a more important case.

William Hood, a veteran of the OSS and CIA, is the author of "Mole" and the novel "Spy Wednesday." He is working on a biography of the late James Angleton.