‎2022 Jun 09 11:34 PM
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
‎2022 Jun 09 11:38 PM
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.
‎2022 Jun 10 4:55 AM
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.
‎2022 Jun 10 8:06 AM
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.
‎2022 Jun 10 11:10 AM
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.
‎2022 Jun 10 1:29 PM
No it is an training project, it is what was asking to do...
just to learn how to loop is working.
‎2022 Jun 11 9:57 PM
‎2022 Jun 10 1:45 PM
Hi
Please try as below
if (n MOD 10) NE 0.
lv_count = (10 - n MOD 10).