In yet another thrust by commercial bankers into investment banking, the BankAmerica Corporation will announce today that it is buying Robertson, Stephens & Company, a San Francisco investment firm specializing in technology, health care and other high-growth areas.

People close to the transaction said that BankAmerica would pay a total of $540 million in cash for the investment firm, or about five times book value.

After months of courtship and four weeks of intense negotiations, the deal was cinched with a handshake in the middle of last week. The formal preliminary agreement was signed yesterday.

Last night, David A. Coulter, the chairman of BankAmerica, and two vice chairmen of the bank met for a celebratory dinner at a private club in San Francisco with Sanford R. Robertson, the founder and chief executive of Robertson, Stephens, and all of its more than 60 partners.

Those close to the deal said that Robertson, Stephens would remain a distinct entity within the bank. Mr. Robertson is to remain in charge and is to become a member of the bank's board. The rest of the investment banking firm's senior managers, including Michael G. McCaffery, the president, and Randy Hecht, the chief operating officer, will also continue in their posts.

Under the terms of the deal, the bank will pay the $540 million entirely in cash -- about half is to be paid immediately with the balance to be paid over three years. Of the total, about $70 million is designated for contracts to insure the retention of key Robertson, Stephens executives.

One person close to the deal said that nearly all the firms' partners were expected to stay after the acquisition. ''A huge number of people are going to be signed up for several-year contracts,'' he said.

Executives of both companies declined to comment publicly on the deal yesterday.

The wall that was thrown up between commercial and investment banking in the Depression was definitively breached only two months ago when the Bankers Trust New York Corporation agreed to buy Alex. Brown & Sons, the nation's oldest stock brokerage firm, for about $1.7 billion. Then in mid-May, the Swiss Bank Corporation agreed to acquire Dillon, Read & Company, a New York investment company, for about $600 million.

For more than a decade Congress has debated whether to repeal the Glass-Steagall Act of 1933, which bans banks from underwriting stocks. But while that debate continues, court cases and rulings by the Federal Reserve and other regulators have given commercial banks permission to perform virtually all of the functions of a brokerage firm.

The rules have been most stringent on underwriting, raising capital for companies by selling their stock or bonds to investors. Last year, the Fed raised the amount of underwriting business a bank affiliate was permitted, to 25 percent from 10 percent of its revenues derived from the securities business. That was like dropping the starting flag, and banks scrambled to set up strong beachheads in investment banking.

The deal being announced this morning was, for many financial experts, the latest evidence of a trend gathering momentum. Asked what the next step in the industry was likely to be, the chief executive of another financial services company, who spoke on condition of anonymity, responded without missing a beat: ''After this? More consolidation, particularly among the larger banks and securities firms.''

The banks have their eyes on about two dozen investment firms known in the trade as ''major bracket'' and ''bulge bracket'' firms. They are considered attractive either because they are giants or, like Robertson, Stephens, they are focused in fast-growing segments of the economy.

Robertson, Stephens, which was formed in 1969, had estimated revenue last year in the vicinity of $300 million, industry experts said.

''Robertson, Stephens is serving growing companies that are most likely to grow into large firms,'' one financial specialist said. ''The bank wants to tie into that growth. It is buying a strong franchise.''

Among the clients of Robertson, Stephens have been Intuit, Sun Microsystems, Pixar, Centocor and the retailer Ann Taylor.

A spurt in growth for Robertson, Stephens is likely, too. ''They're getting access to the bank's marvelous client base,'' one investment specialist said, ''and they're going to have access to more capital than virtually any of their competitors.''

People close to the deal said that among the unsuccessful suitors in the deal were several Eastern banks, which they would not identify, as well as several in Europe.

One senior investment executive who has been following talk within the industry about a possible purchase of Robertson, Stephens by BankAmerica, the nation's third-largest banking company, said the transaction was ''a terrific deal'' for both companies. It is a merger, he said, in which the strengths of each will complement the other.

BankAmerica, for example, has been successful as a global, commercial banker. But it has not been as successful in entrepreneurial efforts, such as raising money to start companies and expand others in Silicon Valley. That money-raising talent, however, has been a hallmark of Robertson, Stephens.

BankAmerica has also developed a reputation for developing and holding relationships for decades. Robertson, Stephens has not been as successful at this.

''Robertson, Stephens has been sales driven,'' said an executive in a competing investment firm. ''They've been new-business driven, not as good at servicing customers over the long haul as they might have been. And the bank is going to bring something to them on this score.''

But one investment specialist said that the merger could present problems. ''They are two very different cultures,'' he said. ''One is stodgy, bureaucratic. The other is extremely entrepreneurial.''

On Friday, shares of BankAmerica gained $2.625, to close at $123.25, on the New York Stock Exchange, after The San Francisco Chronicle reported that the company was believed to be in talks to acquire Robertson, Stephens.

As the deal has built, Robertson, Stephens has been advised by Greenhill & Company and BankAmerica has been working with Lazard Freres. Robertson, Stephens has had Shearman & Sterling as its lawyers while the bank has had a team from Wachtel, Lipton, Rosen & Katz.

Whatever cultural differences may exist between the two companies, some aspects of the merger are expected to go quite smoothly. One thing is certain: neither will have to adjust to new quarters. Both are already ensconced in BankAmerica's towering headquarters on Nob Hill overlooking San Francisco Bay.