‎2022 Jun 14 11:50 AM
PARAMETERS:int_01 TYPE i DEFAULT 25,
int_02 TYPE i DEFAULT 20.
DO int_01 TIMES.
IF sy-index < int_02.
CONTINUE.
ENDIF.
WRITE: / |{ sy-index }|.
ENDDO.
Also tried using
DO int_01 TIMES.
CHECK sy-index between int_02 AND int_01.
WRITE: / |{ sy-index} |
ENDDO.
but also not getting the result I need.
Result of the first code is:
20
21
22
23
24
25.
I only need to print the numbers 21,22,23,24 and 25. Why is 20 being included?
‎2022 Jun 14 12:03 PM
Hi,
In below code, what happening is when sy-index is equal to 20 it will check if condition.
Then if condition 20 < 20 condition is false hence it will not go inside if statement and will execute write statement. and will print 20.
PARAMETERS:int_01 TYPE i DEFAULT 25,
int_02 TYPE i DEFAULT 20.
DO int_01 TIMES.
IF sy-index < int_02.
CONTINUE.
ENDIF.
WRITE: / |{ sy-index }|.
ENDDO.if you want result from 21 then you will have to change the if condition like below code.
PARAMETERS:int_01 TYPE i DEFAULT 25,
int_02 TYPE i DEFAULT 20.
DO int_01 TIMES.
IF sy-index <= int_02.
CONTINUE.
ENDIF.
WRITE: / |{ sy-index }|.
ENDDO.Regards,
Anuja Kawadiwale
‎2022 Jun 14 12:05 PM
Hi,
This is related to the do loop nature, it will run first then will check the value on the next loop.
you can try the bellow code it is working as per your requirements
PARAMETERS:int_01 TYPE i DEFAULT 25,
int_02 TYPE i DEFAULT 20.
DATA Counter TYPE I.
Counter = int_02.
WHILE Counter < int_01 .
Counter = Counter + 1.
WRITE: / |{ Counter }|.
ENDWHILE.
Thanks
‎2022 Jun 14 12:14 PM
You can try the bellow code too, same of your code with little change on the condetion,
PARAMETERS:int_01 TYPE i DEFAULT 25,
int_02 TYPE i DEFAULT 20.
DO int_01 TIMES.
IF sy-index > int_02.
WRITE: / |{ sy-index }|.
ENDIF.
ENDDO.Output:
21
22
23
24
25
‎2022 Jun 14 1:03 PM
Are you really asking, if you use CHECK number BETWEEN 20 and 25, why the condition is true between 20 and 25 ?
‎2022 Jun 15 7:53 AM
PARAMETERS:INT_01 TYPE I DEFAULT 25,
INT_02 TYPE I DEFAULT 20.
DO INT_01 TIMES.
CHECK SY-INDEX BETWEEN INT_02 + 1 AND INT_01.
WRITE: / |{ SY-INDEX }| .
ENDDO.