 Former Member

# Calculating the No of days....

Hi All,

In my sales report, I need to calculate % time.

The user inputs a date and I need to calculate %Time as:

%TIME= Days lapsed upto that selected date in the month in which the selected date is present/total No of days in that month.

This formula is valid if the selected date is in the current month. If the selected date is not in current month:

%TIME = 100%

Can anyone tell me how to achieve this?

Vinay

10|10000 characters needed characters exceeded

### Related questions

• Former Member
Posted on May 17, 2005 at 01:36 PM

You could use a formula variable that is filled by a user exit. The coding could look like this:

```...
CASE I_VNAM.
WHEN 'TIMEPRC'.
* Calculate Time percentage
check i_step = 2.
WHERE VNAM = 'IDATE'. "Input Date variable
IF l_s_var_range-low(6) = sy-datlo(6).
*     Same month
l_s_range-sign = 'I'.
l_s_range-opt  = 'EQ'.
DATA: l_d_this_month type d,
l_d_next_month type d,
l_d_this_day   type d.
l_d_this_day = l_s_var_range-low(8).
l_d_next_month = l_d_this_month = sy-datlo.
*     The following three lines determine the first
*     of the next month
l_d_next_month+6(2) = '28'.
l_d_next_month = l_d_next_month + 4.
l_d_next_month+6(2) = '01'.
*     Set l_d_this_month
l_d_this_month+6(2) = '01'.
*     Calculate formula
l_s_range-low = ( l_d_this_day - l_d_this_month
+ 1 ) /
( l_d_next_month - l_d_this_month )
* 100.
else.
*     Other month
l_s_range-sign = 'I'.
l_s_range-opt = 'EQ'.
l_s_range-low = '100'.
endif.
endcase.
```

I hope this helps a bit.

Best regards

Dirk

10|10000 characters needed characters exceeded
• Former Member

Dirk,

I have a similar situation where we need to extract the no of days based on user input which is stored in variable Fiscal Period (0fper) as 2005002, for eg.(for Feb 2005).

I am an ABAP illiterate. How should I change your code to get the result I want?

Thank you,

Malli