Skip to Content
author's profile photo Former Member
Former Member

Do it exist a FM to check possibility of convertion between different type?

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Dec 23, 2008 at 09: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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 23, 2008 at 09: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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 23, 2008 at 09: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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.