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

How to convert a character to number

hi,

i want to convert a character to number in abap which function can i use? and how to use this function?

Add comment
10|10000 characters needed characters exceeded

6 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Dec 10, 2007 at 10:48 AM

    Sample code below:

    DATA: lv_chr(4) type c,
          lv_num    type p.
    
    CALL FUNCTION 'MOVE_CHAR_TO_NUM'
      EXPORTING
        CHR             = lv_chr
      IMPORTING
        NUM             = lv_num
      EXCEPTIONS
        CONVT_NO_NUMBER = 1
        CONVT_OVERFLOW  = 2
        OTHERS          = 3.
    IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

    Add comment
    10|10000 characters needed characters exceeded

    • PACK f TO g.

      Places the character field f in packed format in the field g. Reverse of the UNPACK statement.

      Example

      DATA C_FIELD(4) TYPE C VALUE '0103',

      P_FIELD(2) TYPE P.

      PACK C_FIELD TO P_FIELD.

      C_FIELD: C'0103' --> P_FIELD: P'103C'

      Note

      The field f can contain up to 16 characters.

  • author's profile photo Former Member
    Former Member
    Posted on Dec 10, 2007 at 11:11 AM

    Hi,

    Use the following Code :

    DATA NO1(10) TYPE C VALUE '1234567890'.

    DATA NO2 TYPE I.

    NO2 = NO1.

    WRITE NO2.

    the foll code will convert the string to interger.

    DATA NO1 TYPE STRING.

    DATA NO2 TYPE I.

    NO1 = '1234567890'.

    NO2 = NO1.

    WRITE NO2.

    Also you can use the FM <b>CONVERT_STRING_TO_INTEGER,</b>.

    Hope this would be helpful.

    Regards,

    Lalit

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi

      I am working in one PO enhancement.

      Here in field i.e. charactertype fileld and storing as v_charvalue = '1,950 US GAL' ( v_Charvalue is type C).

      Now I want to fetch only numeric value i.e 1950 into v_num ( this is type N ).

      From the v_charvalu how will fetch only 1950 ....here it should exclude comma (,) and US GAL.

      finally I need v_num = 1950

      Pls guide me how to fetch only the numeric value.

  • Posted on Dec 10, 2007 at 11:14 AM

    Hi,

    Use Fms

    MOVE_CHAR_TO_NUM

    C14W_CHAR_NUMBER_CONVERSION

    CHAR_NUMC_CONVERSION

    Regards,

    PRashant

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 10, 2007 at 11:26 AM

    Hi,

    try this...

    data : n type I.

    data : C(20).

    C = '356'.

    move C to n.

    n = n + 1.

    write n.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 27, 2008 at 09:03 AM

    CALL FUNCTION 'MOVE_CHAR_TO_NUM'

    Add comment
    10|10000 characters needed characters exceeded

  • Posted on May 20, 2016 at 06:44 AM
    -1

    I think you didn't required any FM to do it.

    Just assign c type variable to variable type P. It will work fine.

    Like:

    DATA : lv_ch(4) type c,

    lv_num type p length 4.

    lv_num = lv_ch.

    write:/ lv_num.

    It's just simply work in case of your problem.

    Add comment
    10|10000 characters needed characters exceeded