Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Increment Value in FOR Loop in sap hana

Hi All,

The default incremented value for FOR loop is 1 (shown in the below example). Is there any way to modify it?

In the below example, the value of i gets incremented by 1 each time, i would like to increment it by '2'  (or '3'). 

Create procedure forrr(IN inval INT, out val int)

as

i int :=0;

begin

Declare  a1 int default 0;

  For i in 1..inval DO

  a1:=a1+i;

  End For;

  Val:=a1;

end;

Call forrr(5,?)---> Output is: 15 (sum of digits from 1 to 5)

I tried with a statement i:=i+1; after   a1:=a1+i;  but it is throwing the below error:


Error: Could not execute 'Create procedure forrr(IN inval INT, out val int) as i int :=0; begin Declare a1 int default 0; For ...' in 446 ms 111 µs .

SAP DBTech JDBC: [1288] (at 135): expression cannot be used as an assignment target: I: line 8 col 3 (at pos 135)

I am looking forward for your inputs.

Thanks,

Sree

Former Member
Not what you were looking for? View more on this topic or Ask a question