Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Print numbers between specific numbers using Control Check statement

walkerist79
Participant
3,896
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?

5 REPLIES 5
Read only

anujawani242683
Active Participant
0 Likes
3,847

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

Read only

Yasin
Active Participant
0 Likes
3,847

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

Read only

Yasin
Active Participant
0 Likes
3,847

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

Read only

Sandra_Rossi
Active Contributor
0 Likes
3,847

Are you really asking, if you use CHECK number BETWEEN 20 and 25, why the condition is true between 20 and 25 ?

Read only

former_member808116
Participant
0 Likes
3,847
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.