By Jesús Aguado

The ruling is non-binding but could have implications for Caixabank and other Spanish banks - which still hold IRPH-derived mortgages valued at more than 16.5 billion euros (14.74 billion pounds) - including possibly having to pay compensation in some cases.

Such rulings are often followed up on by the court, which is expected to reach a final decision by early 2020 on IRPH, which was scrapped by the government in 2013.

Shares in Spanish banks fell after the advocate's conclusions were published, but later rebounded. Caixabank, Banco Sabadell and Bankia were all up by around 2% by 1220 GMT.

Spanish-based broker Alantra said in a note to clients that "if the final ECJ ruling goes in the same direction, we would not expect immediate losses for the banks in the 2019 accounts as this litigation risk would play out over several years".

Spanish banks are already under pressure due to low interest rates, which have squeezed their margins.

While analysing the level of transparency in IRPH contractual clauses, the advocate said its "mathematical calculation formula is complex and not very transparent for an average consumer".

Hundreds of thousands of mortgages set using this rate were sold, particularly in 2007 and 2008, but it tended to be higher than Euribor and did not fall as much when the European Central Bank cut borrowing costs.

"The advocate is basically paving the way to recognise that IRPH could be considered abusive," a spokesman for the ECJ court said.

The Spanish government scrapped the index six years ago saying it was unfair, leading customers to take banks to court demanding compensation.

Spanish courts have rejected these appeals, but a question focusing on the lack of transparency when selling mortgages with this clause had been lodged at the European Court of Justice.

ONLY FINAL RULING MATTERS

On Tuesday, Spain's acting Economy Minister Nadia Calvino said that the opinion from the advocate did not anticipate the final ruling. "We have to wait for the (final ruling) and the consequence for the Spanish courts, which are the ones that are going to decide on a case by case basis," Calvino said.

Spanish consumer associations, such as OCU, which estimated that banks had overcharged clients 37 billion euros by using the index, welcomed the news and shared the view from the advocate that control must be guaranteed on potential abusive clauses.

The Bank of Spain recently warned of a potential impact on Spanish banks' profits related to the IRPH.

Though there are no official figures for how many mortgages were sold under the IRPH, Spanish consumer association Asufin put the number of affected clients at around 1 million.

Goldman Sachs estimates a potential cost to the banking sector of between 7 billion and 44 billion euros.

On Tuesday, Credit Suisse said the opinion would prolong uncertainty for banks. The impact of an adverse ruling would be hard to quantify, it said, as it depended on a set of factors which were not known yet, such as what the IRPH index will be replaced with, whether retroactivity applies and, if so, until what date; and what amount of mortgages will be impacted.

Spanish banks have so far defended the validity of the IRPH, which they say was an official measure approved and published by the Bank of Spain.

The lender most exposed to this clause is Caixabank with up to 6.5 billion euros, followed by Santander, with 4.3 billion euros and BBVA with 3.1 billion euros though bigger lenders have a more diversified business model.

Bankia and Sabadell also have hefty exposures of 1.6 billion euros and 830 million, respectively.

Caixabank, Bankia and Sabadell declined to comment on the conclusions.

(Reporting By Jesús Aguado; additional reporting by Emma Pinedo; editing by Ingrid Melander/Andrey Khalip/Susan Fenton)

By Jesús Aguado