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

Number Conversion Error

Former Member
0 Likes
2,169

Hi All,

In smartforms a variable is defined as;

v_gamng(13) type c

A query put's the following value in this variable;

v_gamng = 1,000.000

When I goto do a calculation it throws a error message;

The program attempted to interpret the value "1,000.000 " as a number, but

since the value contravenes the rules for correct number formats, this was not possible.

Then I declared the following variable;

v_gamng_n like afko-gamng

This is a numeric when I went to assign;

v_gamng_n = v_gamng.

Yet it thows the same above error message.

Thanks,

Kishan

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,629

Kishan,

I am not sure why you have declared V_GAMNG as C. Shouldn't it be of TYPE I / P?

Regards,

Ravi

12 REPLIES 12
Read only

Former Member
0 Likes
1,630

Kishan,

I am not sure why you have declared V_GAMNG as C. Shouldn't it be of TYPE I / P?

Regards,

Ravi

Read only

0 Likes
1,629

Hi Ravikumar,

Assume it has to be declared as V_GAMNG Type C. How could I convert this to numeric?

Thanks,

Kishan

Read only

0 Likes
1,629

See if you can use this function - CONVERT_FROM_CHAR_SORT_RFW

Regards,

Ravi

Read only

0 Likes
1,629

Points awarded accordingly.

If someone could give a example of using the FM CONVERT_FROM_CHAR_SORT_RFW. I would close the thread as solved.

Thanks,

Kishan

Read only

0 Likes
1,629

use this code.

data: amt(20) .

data: pamt(16) type p decimals 2 .

amt = '1,2345678.80' .

CALL FUNCTION 'MOVE_CHAR_TO_NUM'

EXPORTING

chr = amt

IMPORTING

NUM = pamt

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.

Raja

Read only

Former Member
0 Likes
1,629

What is the requirement that is forcing you to populate the values first into a Char field and then into a Packed value??

Read only

vinod_gunaware2
Active Contributor
0 Likes
1,629

if u use data type c then v_gamng = <b>'</b>1,000.000<b>'</b>.

otherwise use F,P,I with decimals.

U can use format which store in profile->own data

or OY01

regards

vinod

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
1,629

Hi,

Just try putting the value from query into v_gamng_n.

Use the same for calculation.

Read only

Former Member
0 Likes
1,629

Hi,

Try using this data element.

P05_DEC15_4

Regards,

Gayathri

Read only

Former Member
0 Likes
1,629

Hi,

DATA: v_gamng(13) type c,

v_gamng_n like afko-gamng.

v_gamng = '10'.

SHIFT v_gamng LEFT DELETING LEADING space.

TRANSLATE v_gamng USING ', '.

CONDENSE v_gamng NO-GAPS.

MOVE v_gamng TO v_gamng_n.

Thanks,

Pramod

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
1,629

Hi,

Here is the sample code for converting the char into numeric.

data : v1(13),

v2 type afko-gamng.

v1 = '10,000.00'.

replace all occurrences of ',' in v1 with ''.

v2 = v1.

write v2.

Read only

Former Member
0 Likes
1,629

Hi Kishnan,

"The program attempted to interpret the value "1,000.000 " as a number, but

since the value contravenes the rules for correct number formats, this was not possible. "

In my opinion the problem is that 1,000.000 is indeed no number. 1.000,000 would be a better way to use that. But you should try first to eliminate ',' and then try if '.' or ',' is recommended for correct number conversion.

If you solved that problem yet please let me know because i encountered another problem with packed numbers in smartforms.

Hope it helps,

Claus