International Business Machines Corp., the world's largest computer maker, yesterday said its second-quarter earnings gained 12.7 per cent over those of the year before.

IBM said it earned $658 million ($4.44 a share), against $593 million ($3.94) in the second quarter of 1976. Revenue rose from $4.014 billion to $4.419 billion.

For the first half, IBM earned $1.23 billion ($8.26) compared with last year's first-half earnings of $1.14 billion ($7.57). The number of shares outstanding fell from 150.2 million a year ago to 149.2 million, IBM said. Revenue rose from $7.828 billion to $8.509 billion.

IBM chairman Frank Cary said "outright purchases of data processing equipment for the second quarter increased substantially over the level of both the first quarter of 1977 and the second quarter of 1976 . . . first half.

"Incoming orders and shipments continued to show good increases over the comparable 1976 periods, reflecting the continuing strong demand for the company's major products lines throughout the world," he added.

Westinghouse Electric Corp. profits in the first half of 1977 were the highest in the company's history.

Net income for the six months ended June 30 was $117.2 million ($1.34 a share) on sales of $2.96 billion compared with profits of $101.7 million ($1.16) on revenues of $2.99 billion in the same six months of 1976.

Second-quarter profits were $64 million (73 cents) on sales of $1.53 billion compared with net income of $54.5 million (62 cents) on revenues of $1.55 billion a year ago.

Westinghouse said the gain in second-quarter results was due in part to strong sales and earnings advances in the company's nuclear segment. Power generation also showed an improvement over last year.

Colgate-Palmolive Co., a major soap and cosmetics maker, yesterday reported a 9.6 per cent gain in second-quarter earnings and announced it is raising its commond stock dividend.

Colgate-Palmolive said its dividend will be increased from 22 to 25 cents a share, payable Aug. 15 to shareholders of record July 25.

The company earned $43.8 million (57 cents a share) in the second quarter, up from $39.6 million (52 cents) a year ago. Revenues increased from $899.3 million in the second quarter of 1976 to $945.6 million this year. More than half of Colgate-Palmolive's sales come from foreign operations.

For the first half, unaudited net earnings totaled $75.6 million (98 cents) compared with $68.2 million (89 cents) the year before. Sales rose from $1.75 billion to $1.87 billion.

Colgate-Palmolive said it had 77.3 million shares outstanding at the end of the second quarter of 1977 and 76.1 million outstanding at the end of 1976's second quarter.

NCR Corp. yesterday posted sharply higher earnings for the second quarter and first half.

Second-quarter net income was $34.4 million ($1.23 a share fully diluted) on $627.8 million in revenue compared with 1976 second-quarter net income of $18.5 million (72 cents) on $556.3 million in revenue.

During the first half, net income climbed from $31.7 million ($1.26) to $51 million ($1.84) as sales grew from $1.03 billion to $1.14 billion.

NCR said second-quarter net income from overseas was ahead of last year in contrast to the first quarter, when earnings from abroad were relatively flat. However, domestic operations were the largest contributor to the second-quarter earnings gain, the company said.

PPG Industries, Inc., said second-quarter sales were the highest in company history and produced earnings matching a 1976 record.

PPG earned $43 million on sales of $640 million compared with $43 million $568 million in sales in the same period in 1976. Stated on the basis of a June 23 three-for-two stock split, earnings per share were $1.38 for the second quarter in each year.

"Second-quarter sales were up for all of PPG's major businesses," said chairman Robinson F. Barker. "Prime factors were the continuing strength of the automotive and residential construction markers, which benefited glass, coatings, resins and fiber glass sales, and the generally firm demand for chemicals."

Earnings for the first half of 1977 were $78.2 million ($2.51 per current share) compared with $87 million ($2.50) on a comparable basis for the first six months of 1973. First-half sales rose from $1.1 billion to $1.2 billion.