08-30-2007 7:04 AM
Hi,
Please find a small program code.
data : a(18),
result = a * 25 * 36 / 12.
My question is ..
'a' has a value 4,589. If I use this value in the calculation part, it gives me a dump.
I need to interpret this value as a number and use it for the calculation.
Kindly help me.
Thanks in advance.
08-30-2007 7:11 AM
Hi karthik
declare result type as integer
data result type i.
Regards
sandhya
08-30-2007 7:11 AM
Hi karthik
declare result type as integer
data result type i.
Regards
sandhya
08-30-2007 7:11 AM
HI
ASSIGN - obsolete_casting
. ... TYPE name
This form of addition casting_spec, in which you specify TYPE or DECIMALS without the CASTING addition, is not allowed in classes. In addition, it can neither be used together with the statement INCREMENT in mem_area nor with the addition RANGE. However, the field symbol may have been typed using the - obsolete - addition STRUCTURE of the FIELD-SYMBOLS statement.
... TYPE name
After TYPE, a character-type data object name of length 1 is expected, which must contain exactly one of the case-sensitive letters "C", "D", "F", "I", "N", "P", "T", "X", "b", or "s" when the statement is executed. These letters label the respective built-in ABAP types and have the following effects:
If the field symbol <fs> is typed completely or in parts, the typing must match the ABAP type specified after TYPE. The assigned memory area is casted to the type of the field symbol.
If the field symbol is typed completely generically, the type of the assigned memory area is casted to the ABAP type specified after TYPE.
TRY THIS U WILL GET
REWARD IF USEFULL
08-30-2007 7:16 AM
Hi,
Give value for a. a=10.
Declare result type integer and check it out.
Reward points if helpful.
Regards,
Vimal
08-30-2007 7:16 AM
Hello Karthik,
Try with this code... its working...
REPORT ZSAMPLE .
data : a(18).
data: result type i.
move '4589' to a.
result = a * 25 * 36 / 12.
write: result.
-
o/p is 344.175.
Reward If Useful.
Regards
--
Sasidhar Reddy Matli.
08-30-2007 7:16 AM
Use this, reward if useful.
data : result type i.
data : a type i.
result = a * 25 * 36 / 12.
Regards
Amit Singla
08-30-2007 7:16 AM
Hi Karthik,
If you are passing integer values in A then declare it as
<b>DATA a TYPE i.</b>
if you are passing decimal also then declare a as
<b>DATA a TYPE p DECIMALS 3.</b>
*Always reward points for helpful answers
Regards,
Amit
08-30-2007 7:17 AM
Hi karthik,
what you have to do is convert the string '4,589' into another string that can be interpreted as a number by SAP. And you can do that with
TRANSLATE a USING ',.'.
That will replace the comma by a period.
Anyway, if the value of variable <i>a</i> is produced itself by a conversion <b>from</b> a number (for example, 'WRITE number TO a'), you should consider some user-dependent conversion:
select single * from usr01 where bname = sy-uname.
case usr01-dcpfm.
when space.
translate a using '. ,.'.
condense a no-gaps.
when 'X'.
translate a using ', '.
condense a no-gaps.
when 'Y'.
translate a using ',.'.
condense a no-gaps.
endcase.
This will put in variable <i>a</i> a string that be directly interpreted as a number in internal form.
I hope it helps. Best regards,
Alvaro
08-30-2007 7:22 AM
Hi,
Pass value of into another variable of type I
also make sure result is type I .
Hope this Helps.
Praveen
08-30-2007 8:55 AM
Hi All,
Thanks a lot for everyone who contributed their ideas here.
Since the value for 'a' (ie. 4,589) is automatically generated from input_table-value, i tried with an other logic that gave the exact result.
DATA : A(18),
FIRST(8),
SECOND(8),
IF INPUT_TABLE-VALUE CA ','.
SPLIT INPUT_TABLE-VALUE AT ',' INTO FIRST SECOND.
CONCATENATE FIRST SECOND INTO A.
ELSE.
MOVE input_table-value TO A.
ENDIF.
Thanks a lot for everyone, once again.
08-30-2007 8:56 AM