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

Statement WHILE

d4xtian
Participant
0 Likes
1,544

Can somebody lead me tot the solution please..

I want to test if a number is a multiple of 10, if yes it display a sentence that say yes, if not i want it to add 1 to that number until it become a multiple of 10 and i want to count how manu time it add.

how to say « if P_VPI is not MOD 10 » in abap to put this condition in my While statement ?


thanks

P_VPI = P_VOLUME MOD 10.

WRITE 'Le volume est divisible par 10'.
w
WHILE ??? .
P_VOLUME = P_VOLUME + 1.WRITE SY-INDEX.
ENDWHILE.
7 REPLIES 7
Read only

d4xtian
Participant
0 Likes
1,400

by the way in my programme i have already declare P_VOLUME

is it right if i put like this :


P_VPI = P_VOLUME MOD 10.


WRITE 'Le volume est divisible par 10'.

WHILE P_VPI <> 0.
P_VOLUME = P_VOLUME + 1.WRITE SY-INDEX.
ENDWHILE.
Read only

former_member808116
Participant
1,400

This may be of help to you.

PARAMETERS: P_VPI TYPE I.
DATA: LV_MOD TYPE P LENGTH 8 DECIMALS 2,
LV_INT TYPE INT8.

LV_INT = P_VPI.
LV_MOD = P_VPI MOD 10.
IF LV_MOD = 0.
WRITE: 'Number: ', P_VPI , 'divisible par 10'.
ELSE.
WHILE LV_MOD <> 0.
P_VPI = LV_INT + SY-INDEX.
LV_MOD = P_VPI MOD 10.
IF LV_MOD = 0.
WRITE: 'SY-INDEX:', SY-INDEX.
CONTINUE.
ENDIF.
ENDWHILE.
ENDIF.
Read only

1,400

For fun, assuming SY-INDEX can be used in the logical expression of WHILE (the ABAP documentation says it can be used only in the statement block of WHILE, not in the logical expression), the code can be simplified to:

PARAMETERS: P_VPI TYPE I.
IF P_VPI MOD 10 = 0.<br>  WRITE: 'Number: ', P_VPI , 'divisible par 10'.
ELSE.
  WHILE ( P_VPI + sy-index - 1 ) MOD 10 <> 0.
    WRITE: 'SY-INDEX:',  SY-INDEX.
  ENDWHILE.
ENDIF.
Read only

matt
Active Contributor
0 Likes
1,400

Isn't this just ordinary maths, not requiring a loop.

IF p_vpi MOD 10 = 0.
  WRITE 'YES!!!'.
ELSE.
  DATA(iterations) = 10 - p_vpi MOD 10.
  WRITE 'I need to add 1 to p_vpi', iterations, 'times to get to divisible by ten'.
ENDIF.
Read only

1,400

No it is an training project, it is what was asking to do...

just to learn how to loop is working.

Read only

matt
Active Contributor
0 Likes
1,400

Ah, OK. Training exercise.

Read only

venkateswaran_k
Active Contributor
0 Likes
1,400

Hi

Please try as below

if (n MOD 10) NE 0.
    lv_count = (10 - n MOD 10).