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

"ABAP Basics" Book - arithmetic expression error in the sample code

Former Member
0 Likes
1,875

Hi all,

I have just started learning ABAP on mini SAP system (NW7.01) by following "ABAP Basics" book.

This question might be a FAQ, but I have spent a few days searching a right answer without success.

I appreciate if you could help me on this.

On the page 162, there is a function module sample, which contains the line as following:

e_amount = i_km * '0.3'.

Here l_km (import) is type of i, and e_amount (export) is type of f.

Though I do not think of any problem with this line, it throws an arithmetic expression error when executed directly for testing as well as when called from a program.

When I tried a similar thing in a program, it was fine.

However within a function module it throws this error.

Thanks in advance.

Terry

1 ACCEPTED SOLUTION
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,684

hi it throws no error for me while executing function module.

May be you would have done a mistake some where. please check.

hi it throws no error for me while executing function module.

May be you would have done a mistake some where. please check.

12 REPLIES 12
Read only

Former Member
0 Likes
1,684

which FM is that?

Read only

0 Likes
1,684

That is zptb00_calculate_travel_expens .

Thanks.

Read only

0 Likes
1,684

hi,

first let me welcome you to SDN,.

now,its a custom FM, so you have to show us what code you have for that FM. could you?

Read only

Former Member
0 Likes
1,684

Hi,

Are you sure this line is causing error?? I executed only this line in a test FM ..and I got the following output:

Import parameters Value

I_KM 1

Export parameters Value

E_AMOUNT 2,9999999999999999E-01

Read only

0 Likes
1,684

Like I said before, I do not think any problem about the code itself.

I suspect some environmental things?

I should have mentioned SAP mini system NW7.01 is running on Vista Business?

To be specifc, I receive this message:

Arithmetic operations are only expected for operands that can be converted to numbers.

(numeric operands). - (numeric operands). - - - -

with the following function module:

[code]

FUNCTION ZPTB00_CALCULATE_TRAVEL_EXPENS.

*"----


""Local Interface:

*" IMPORTING

*" VALUE(I_KM) TYPE REF TO I

*" EXPORTING

*" VALUE(E_AMOUNT) TYPE REF TO F

*" EXCEPTIONS

*" FAILED

*"----


e_amount = i_km * '0.3'.

IF sy-subrc <> 0.

RAISE failed.

ENDIF.

ENDFUNCTION.

[/code]

Read only

0 Likes
1,684

Well use correct code..

In the first post you mentioned type, while actually you are using Type Ref.

Keshu is correct, do not use Type Ref To.

Read only

0 Likes
1,684
*"IMPORTING
*" VALUE(I_KM) TYPE REF TO I
*" EXPORTING
*" VALUE(E_AMOUNT) TYPE REF TO F

this is where the error stays.

define them as:

I_KM TYPE I .

E_AMOUNT TYPE F.

dont use type ref to

Read only

0 Likes
1,684

Thank you guys all.

I feel as if I were so stupid......

Thanks again all.

Terry

Read only

0 Likes
1,684

Hi,

I am making the exercises of the book. Do you have the source code anywhere available. It would be nice to have it for speeding up the learning process.

Thanks

Read only

0 Likes
1,684

plz note that if u do a arithmatic on f type and i no issues as long as the var to hold res is also f type.

Plz go thru SAP HELP AND SAP online materials alongwith ur books

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,685

hi it throws no error for me while executing function module.

May be you would have done a mistake some where. please check.

Read only

0 Likes
1,684

"TYPE REF TO "

Instead of this use "TYPE" for both export and import.

When I tried a similar thing in a program, it was fine.

How did it happen ? I dont think so it will be correct in program

Edited by: Keshu Thekkillam on Sep 18, 2009 1:17 PM