Recursive procedure calls in SQLScript

Recursive procedure calls in SQLScript

Up to SAP HANA 2.0 SPS03 recursive calls in SQLScript were not allowed. This means that a procedure may not call itself either directly or indirectly via other procedures. This restriction was removed with SPS04. However, the call depth is limited to 32 and procedures in libraries also do not allow recursive calls. In the listing you see an example for the recursive calculation of the Fibonacci numbers. Please be careful, if you call this procedure with too large parameters (>20), it can quickly happen that the SAP HANA system reaches its limits.

CREATE PROCEDURE fibonacci(IN iv_value INT,
OUT rv_result INT)

IF iv_value IN (1, 2)
THEN rv_result = 1;
fibonacci( iv_value - 1 , rv_result );
fibonacci( iv_value - 2 , lv_tmp );
rv_result = rv_result + lv_tmp;

CALL fibonacci(20, ?);

Listing: Recursive calculation of the Fibonacci Numbers

Here is the link to SAP documentation on the topic. As far as I know, recursive queries are not supported.

This post is also available in: Deutsch

Jörg Brandeis

Jörg Brandeis

Independent Trainer, Consultant and Author. I am interested in all technical topics around SAP HANA, SQLScript and BW/4HANA.

Planned events

0 replies on “Recursive procedure calls in SQLScript”

Request more information

Wollen Sie mehr Informationen?

Unverbindliche Anfrage

Do you want more information?


%d bloggers like this: