Skip to Content
author's profile photo Former Member
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?

Thanks in advance

Vinay

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • author's profile photo Former Member
    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.
        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.
        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

    Add a comment
    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

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.