Showing results for 
Search instead for 
Did you mean: 

Calculating the No of days....

Former Member
0 Kudos

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?

Thanks in advance


Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

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

* Calculate Time percentage
    check i_step = 2.
    READ TABLE I_T_VAR_RANGE into l_s_var_range 
         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.
*     Other month
      l_s_range-sign = 'I'.
      l_s_range-opt = 'EQ'.
      l_s_range-low = '100'.

I hope this helps a bit.

Best regards


Former Member
0 Kudos


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,