01-15-2008 5:32 PM
I need to convert a string (it is a packed number stored in a string variable) into an integer. I tried just saying integer = string but it throws a run-time error. Then I tried to use fm convert_string_to_integer but that FM isn't at all what it sounds like (it doesn't' accept a string of numbers). How can I do this?
Davis
01-15-2008 5:35 PM
what's the problem?
data: str type string value '123456'.
data: i type i.
i = str.
write:/ i.
what is the value in your string? Does it contain something other than numbers? If so you would need to get rid of those. For example, say that your string contained a number with a thousand separator like ','.
data: str type string value '123,456'.
data: i type i.
translate str using ', '. "< get rid of the comma
condense str no-gaps.
i = str.
write:/ i.
Regards,
Rich Heilman
01-15-2008 5:35 PM
what's the problem?
data: str type string value '123456'.
data: i type i.
i = str.
write:/ i.
what is the value in your string? Does it contain something other than numbers? If so you would need to get rid of those. For example, say that your string contained a number with a thousand separator like ','.
data: str type string value '123,456'.
data: i type i.
translate str using ', '. "< get rid of the comma
condense str no-gaps.
i = str.
write:/ i.
Regards,
Rich Heilman
01-15-2008 5:40 PM
Rich, you hit the nail on the head, I have commas and decimal points in the string. I will make the change which you posted.
Thanks a lot!
Davis
01-15-2008 5:40 PM
report zars no standard page heading
line-size 170
line-count 65(4).
data : int type i.
data : char(10) type c value '123'.
class cl_abap_container_utilities definition load.
call method cl_abap_container_utilities=>read_container_c
exporting
im_container = char
importing
ex_value = int
exceptions
illegal_parameter_type = 1
others = 2.
write : int.
a®