Application Development 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: 

How to get number of digits in given amount

Former Member
0 Kudos

Hi Experts,

How to get number of digits in given amount.

Regards

Mohit

1 ACCEPTED SOLUTION

former_member222860
Active Contributor
0 Kudos

Check this :

data: v_data1 type p decimals 3 value '12.860',
      v_char1 type char20,
      v_char2 type char20,
      v_char3 type char20,
      len type i.
write v_data1 to v_char1.

split v_char1 at '.' into v_char2 v_char3.

len = strlen( v_char3 ).

write:/ v_char2,
      / v_char3, " this holds the digit value
      / len.     " number digits

6 REPLIES 6

former_member212002
Active Contributor
0 Kudos

Hi,

If you want to calculate the number of digits in a given amount then you can do something like this,

Convert the variable that contains the amount into Type C.

Then Calculate the length using strlen(x).

Where X is the Variable.

Regards,

Abhinab Mishra.

former_member222860
Active Contributor
0 Kudos

Check this :

data: v_data1 type p decimals 3 value '12.860',
      v_char1 type char20,
      v_char2 type char20,
      v_char3 type char20,
      len type i.
write v_data1 to v_char1.

split v_char1 at '.' into v_char2 v_char3.

len = strlen( v_char3 ).

write:/ v_char2,
      / v_char3, " this holds the digit value
      / len.     " number digits

Former Member
0 Kudos

Suppose your digit = x

data y type i .

Initialize x to y.

y = x.

do .

y = x % 10.

if y = 0.

exit.

endif.

count = count + 1.

enddo.

The variable count has number of digits.

0 Kudos

Why to be so complicated???

If you can use ABAP Keywords to achieve the same, in a simple and cosy way.

Regards,

Abhinab Mishra

Former Member
0 Kudos

You will get the no. of decimals from the FM 'BAPI_CURRENCY_GETDECIMALS' into lv_decimals variable.

Former Member
0 Kudos

Dear Bansal,

Declare a variable and then STRLEN( filed ) in your coding you will get number of digit.

e.g.

Data : g_cnt type i.

g_cnt = strlen ( itab-field1) .

Hope this will help you.

Regards,

Vijay