‎2005 May 13 4:27 PM
hi folks,
Need some urgent help in this regard.
I have this character data(size 44) to convert that into integer value. I used the move statement and moved the value to a string and then to the integer. it is giving SHORT DUMP SAYING IT IS AN OVERFLOW CONDITION. The data in the variable is huge and I need to convert it into integer as it is.
Also I am wondering that after converting into integer I need to mutiply the numbers in the positions 1,3.. with 2,and even positioned numbers with 1. How can i track them separately if I am using the integer type?
Because I need to perform arithematic calculations I wanted to convert into integer.
If there is a better way do suggest me?
thanks
Thanks for your help in advance. it would really help.
Santhosh
‎2005 May 13 5:06 PM
Hi Santhosh,
Here is a small piece of code to achieve what you wanted to achieve.
DATA: v_char44(44) TYPE c,
v_value TYPE i,
v_digit TYPE i,
v_oddoreven TYPE i,
v_pos TYPE i.
START-OF-SELECTION.
v_char44 = '12345678901234567890123456789012345678901234'.
*-- get rid of leading spaces.
SHIFT v_char44 LEFT DELETING LEADING space.
DO 44 TIMES.
v_pos = sy-index - 1.
IF v_char44+0(1) IS INITIAL.
*-- no more filled in positions, exit
EXIT.
ENDIF.
v_digit = v_char44+v_pos(1).
v_oddoreven = sy-index MOD 2.
IF v_oddoreven = 0.
*-- even number
v_value = v_value + v_digit.
ELSE.
*-- odd number
v_value = v_value + ( v_digit * 2 ).
ENDIF.
ENDDO.
WRITE: v_value.Hope it helps,
Srinivas
‎2005 May 13 5:06 PM
Hi Santhosh,
Here is a small piece of code to achieve what you wanted to achieve.
DATA: v_char44(44) TYPE c,
v_value TYPE i,
v_digit TYPE i,
v_oddoreven TYPE i,
v_pos TYPE i.
START-OF-SELECTION.
v_char44 = '12345678901234567890123456789012345678901234'.
*-- get rid of leading spaces.
SHIFT v_char44 LEFT DELETING LEADING space.
DO 44 TIMES.
v_pos = sy-index - 1.
IF v_char44+0(1) IS INITIAL.
*-- no more filled in positions, exit
EXIT.
ENDIF.
v_digit = v_char44+v_pos(1).
v_oddoreven = sy-index MOD 2.
IF v_oddoreven = 0.
*-- even number
v_value = v_value + v_digit.
ELSE.
*-- odd number
v_value = v_value + ( v_digit * 2 ).
ENDIF.
ENDDO.
WRITE: v_value.Hope it helps,
Srinivas
‎2005 May 13 5:28 PM
hey srinivas thanks a lot. it really helped. Here is the situation. It is a bit complicated code if you could help here that would solve my problem.
For example take the number(the real number is 43 characters) like this:
4 1 2 9 7 9 6
2 1 2 1 2 1 2 ( mutiply the odd digit numbers with 2 and
even with 1)
8 1 4 9 14 9 12
Now where the result is double digit, I have add the double digit numbers
I am confused at how to track the double digits out here and add them all.......
8 1 4 9 5 9 3
Now add these numbers = 39/10 = 3 remainder 9
last step 10 -9 = 1 This is the number I want it to be converted back into character format.
I am working on it.. Your input would help me out here.
Thanks a lot.
Santhosh
‎2005 May 13 5:33 PM
Numerology in SAP?
Is this perhaps for sales forecasting...
Brad
‎2005 May 13 5:51 PM
it is for the scanline code and I need to generate this number after all these operations it is a 43 character variable using which I need to perform these steps and generate the number.
Santhosh
‎2005 May 13 7:23 PM
Here is the modified code.
DATA: v_char44(44) TYPE c,
v_value(2) TYPE n,
v_digit TYPE n,
v_oddoreven TYPE i,
v_pos TYPE i,
v_result TYPE i,
v_value_i TYPE i.
START-OF-SELECTION.
v_char44 = '4129796'.
*-- get rid of leading spaces.
SHIFT v_char44 LEFT DELETING LEADING space.
DO 44 TIMES.
v_pos = sy-index - 1.
IF v_char44+0(1) IS INITIAL.
*-- no more filled in positions, exit
EXIT.
ENDIF.
v_digit = v_char44+v_pos(1).
v_oddoreven = sy-index MOD 2.
v_value = v_digit.
IF v_oddoreven = 0.
*-- even number,
v_value_i = v_value.
ELSE.
*-- odd number
v_value = v_digit * 2.
IF v_value > 9.
*-- number has two digits
v_value_i = v_value+0(1) + v_value+1(1).
ELSE.
v_value_i = v_value.
ENDIF.
ENDIF.
v_result = v_value_i + v_result.
ENDDO.
CLEAR: v_value_i, v_digit, v_value.
v_value_i = v_result MOD 10.
CLEAR v_result.
v_result = 10 - v_value_i.
WRITE:/ v_result.
Srinivas
‎2005 May 13 8:12 PM
Thank you Srinivas. It solved my problem. I really appreciate your help in this regard. have nice weekend.