Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

converting string to numeric

Former Member
0 Likes
878

Hi Experts,

I want to convert string to numeric for some calculation and want to pass the calculated amount back to string. I am using the below given code:


METHOD get_percent_inc_amt.
data: lv_percent TYpe numc3,
      lv_base_sal TYPE i,
      lv_cal_amt TYPE i.

*WRITE iv_base_salary to lv_base_sal.
*WRITE iv_percent to lv_percent.

CALL FUNCTION 'CONVERT_STRING_TO_INTEGER'
  EXPORTING
    p_string            = iv_base_salary
 IMPORTING
   P_INT               = lv_base_sal
* EXCEPTIONS
*   OVERFLOW            = 1
*   INVALID_CHARS       = 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.


CALL FUNCTION 'CONVERT_STRING_TO_INTEGER'
  EXPORTING
    p_string            = iv_percent
 IMPORTING
   P_INT               = lv_percent
* EXCEPTIONS
*   OVERFLOW            = 1
*   INVALID_CHARS       = 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.

  lv_cal_amt = ( lv_base_sal * lv_percent ) / 100.
   ev_calculated_amt = lv_cal_amt.

ENDMETHOD.

I am getting dump in my application. Can anyone suggest me on how should I do the conversion.

Thanks,

Shilpa

4 REPLIES 4
Read only

Former Member
0 Likes
701

Hello,

Change the type of lv_percent from numc3 to interger (i).

Dump occuring due to type mismatch conflict.

Regards,

Sachin

Read only

Former Member
0 Likes
701

Hi,

What is the dump?

By the way, the FM accepts data type of Integer for theexporting parameter.

You have specified


data: lv_percent TYpe numc3.

Change the data type to integer.

Read only

Former Member
0 Likes
701

Hi Shilpa

you must have got dump beacuse of type mismatch

Change the type and it will run fine

regards

Nilesh

Read only

Former Member
0 Likes
701

Use this


DATA: lv_percent   TYPE i.

It should work fine.