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

Convert long char-number into p results in overflow

Hi,

how can i convert a long char into a p-number? The following code works fine for numbers up to 13 places. All above 13 decimal places results in a dump "Overflow when converting from ".

  DATA AMOUNT_C(20) TYPE C.
  DATA AMOUNT_P TYPE P DECIMALS 2.

  AMOUNT_C = '1234567890123,12'.
  REPLACE ',' IN AMOUNT_C WITH '.'.
  AMOUNT_P = AMOUNT_C.

Thanks,

Daniel

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    Posted on Dec 18, 2008 at 04:52 PM

    For type "P", a maximum length specification of 16 is allowed.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 18, 2008 at 04:50 PM

    It should work,beyond 16 char you might get dump,but not in 13 char.

    REPORT zztemp.
    DATA AMOUNT_C(20) TYPE C.
      DATA AMOUNT_P TYPE P DECIMALS 2.
    START-OF-SELECTION.
      AMOUNT_C = '1234567890123,12'.
      REPLACE ',' IN AMOUNT_C WITH '.'.
      AMOUNT_P = AMOUNT_C.
      WRITE:AMOUNT_P.

    This code works ok for me.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 19, 2008 at 08:35 AM

    Hi,

    thanks for this explanation. I was not aware the comma and decimal places are also being taken into account.

    So what can i do to extend the amount of digits being processed?

    I tried using float, but this results in max 15 digits (without decimal places). Is there any way to go further?

    Another constraint i have: Later on i need to pass the data into a p again, so i'm really confused why the code below works at all, as the Float "amount_p" is being moved to a p-type again.

    Any hints are welcome.

    REPORT  ZP_DPU_TEST.
    
    DATA AMOUNT_C(20) TYPE C.
    DATA AMOUNT_P TYPE f.
    DATA AMOUNT(9) TYPE p DECIMALS 2.
    
    AMOUNT_C = '123456789012345,23'.
    REPLACE ',' IN AMOUNT_C WITH '.'.
    AMOUNT_P = AMOUNT_C.
    
    amount = AMOUNT_P.
    
    WRITE:/ amount.

    best regards,

    Daniel

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Daniel,

      In your Case Type P or Type F cannot be used.Because they have certain limitation with their Length,which is not suffcient in your case.

      So you may use Below Data element(UC_IPA_GCIC_RET) like:

      Use this Data element

      REPORT:test.
      data: char TYPE char20  VALUE '123456789012345,23',
            num type UC_IPA_GCIC_RET .
      CALL FUNCTION 'MOVE_CHAR_TO_NUM'
        EXPORTING
          chr                   = char
       IMPORTING
         NUM                   = num.
      WRITE: num.

      It shoud work for your Case anyhow.

      Cheers,

      Amit.

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.