12-23-2008 9:12 AM
Hi all,
We have usually met the problem of DUMP when moving or writing a data type of a variable to an other variable which haven't the same data type as data type of moved variable.
For example:
- var01 type char10 with content "char_test".
- var02 type QUAN.
- MOVE var01 TO var02 => DUMP (because program can't convert "char_test" into QUAN type).
(we can use instruction WRITE var01 TO var02 to avoid a DUMP, but after, when we use this var02 to compute => DUMP also occurs).
So could you please tell me if it exist a Function Module in ABAP to check the possibility of conversion between different data type?
Thanks a lot in advance,
Vinh Vo
12-23-2008 9:39 AM
Dear Vinh,
Field symbol should solve your problem. In case that does not work, then as per your requirement you can check for conversion using a try-catch block. The code below should give you an idea.
DATA: var01 TYPE char10 VALUE 'char_test', " CHAR or any other type
var02 TYPE quan1. "Field of type QUAN
TRY.
MOVE var01 TO var02.
CATCH cx_sy_conversion_no_number.
WRITE 'Steps in case conversion is not possible'.
ENDTRY.
WRITE / var02.
The above code will not dump in case of conversions to QUAN. In case a conversion to any other format is required, there will be a similar errors. Please let me know if you need any further help.
Regards,
Nimish
12-23-2008 9:19 AM
One way to do this is to loop through the character string, one letter at a time.
Check the first letter and determine if it is equal to 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9 or 0, if it succeeds, proceed to the next character and carry out the same check, go on until the last character, if the checks are okay all through till the last character, it would mean that the string is a number, only then use WRITE statement to convert it into QUAN.
12-23-2008 9:20 AM
HI ,
Ur problem will be solved by using field symbols.
take field-symbol: <fs> type any.
move char to <fs>.
move <fs> to quantity.
this will solve the problem.
Regards,
Naresh
12-23-2008 9:39 AM
Dear Vinh,
Field symbol should solve your problem. In case that does not work, then as per your requirement you can check for conversion using a try-catch block. The code below should give you an idea.
DATA: var01 TYPE char10 VALUE 'char_test', " CHAR or any other type
var02 TYPE quan1. "Field of type QUAN
TRY.
MOVE var01 TO var02.
CATCH cx_sy_conversion_no_number.
WRITE 'Steps in case conversion is not possible'.
ENDTRY.
WRITE / var02.
The above code will not dump in case of conversions to QUAN. In case a conversion to any other format is required, there will be a similar errors. Please let me know if you need any further help.
Regards,
Nimish