(Reuters) - Wal-Mart Stores Inc WMT.N on Tuesday forecast a 40 percent rise in U.S. online sales next year as it ramps up competition with Amazon.com Inc AMZN.O, boosting shares of world's biggest brick-and-mortar retailer to the highest in more than two years.

Wal-Mart also forecast overall net sales would rise by at least 3 percent in the year ending January 2019, and said it would buy back $20 billion of its shares over the next two years.

Wal-Mart shares rose 4.5 percent to close at $84.13, the top driver of gains in the Dow Jones Industrial Average .DJI and S&P 500 index .SPX.

“We are going to lean into places like technology, e-commerce, international stores,” Wal-Mart Chief Financial Officer Brett Biggs said at the Bentonville, Arkansas company’s annual investor meeting which was webcast.

Wal-Mart, which is battling Amazon for market share, has been investing in its online business and letting customers pick up online orders at its 4,700-plus stores.

The company has already started offering free two-day shipping and said on Tuesday it planned to roughly double the locations for shipping online grocery orders. On Monday, it said it would speed up the process for in-store returns of items bought on its website.

Wal-Mart, which expects online sales to hit about $11.5 billion for the fiscal year ending January 2018, did not break out U.S. e-commerce sales last year. It reported growth of about 62 percent for the first half of fiscal 2018, up from 12 percent in the year-ago period.

With a steady rise in online shopping, Wal-Mart’s e-commerce sales growth has been outstripping brick-and-mortar, leading the company to slash new store openings.

The company plans to open fewer than 15 supercenters and less than 10 neighborhood markets in the United States in fiscal 2019, it said in a statement on Tuesday. That is half the stores it intends to open in fiscal 2018.

“Digital has been a recent highlight for WMT and it expects this momentum to carry into FY ‘19,” UBS said in a note. “Faster growth in (e-commerce) should lead to earnings pressure though, as this operation is likely still several years away from profitability.”

In August, Wal-Mart warned that current-quarter profit could miss market estimates as margins are hurt by price-cutting and heavy spending on e-commerce.

The company on Tuesday estimated capital expenditures of about $11 billion for fiscal 2018 and 2019.

Grocery competition has increased since Amazon bought Whole Foods and started to cut prices at the upmarket grocer in August.

Wal-Mart forecast fiscal 2019 profit would increase about 5 percent over its expected adjusted earnings of $4.30 to $4.40 per share for the year ending January 2018.

The new buyback replaces the existing $20 billion program announced in October 2015. In the seven quarters since, Wal-Mart had bought back $15.10 billion worth of shares.