Skip to Content
author's profile photo Former Member
Former Member

User Exit - Need to calculate days in months counting 8 months backwards

Hello All,

I get the month and year as user input. Based on this I need to be able to display the number of days for the months counting backwards upto 8 months and display them in columns in my report.

For example if the user enters 09/2007

I need to be able to display:

column 1: 30 (Sept)

column 2: 31 (Aug)

column 3 31 (July)

column 4: 30 (June)

column 5: 31 (May)

column 6: 30 (April)

column 7: 31 (March)

column 8: 28 (Feb)

I would need steps to implement this please.

Thx

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Posted on Oct 21, 2007 at 03:33 AM

    Hi Srikanth,

    welcome to SDN..

    Just one ques are you going to display only the no of days for past 8 months and have you designed a key figure for the same....

    ajay

    Note:assigning points is way of saying thanks in SDN

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Srikanth,

      Please try below code (modify if some correction required):

      In the below code i have prepared the start date 8 month back & Ending date of selected date.

      i.e if 200709 is selected then 8 month back date is : 01.01.2007 & Last date is 30.09.2007, days difference is calculated between these two date's.

      Correct me if i am wrong while considering the final and inital date,

      DATA: w_year(4),

      w_year_ne(4),

      w_mth(2),

      w_mnth type i,

      w_tempdate(8) TYPE c,

      w_tempdate1(8) TYPE c,

      w_date type sy-datum,

      w_date1 type sy-datum,

      w_days type i,

      w_clmnth(6).

      w_date = '20070501'.

      w_clmnth = w_date+0(6). //This will only take the year & month

      w_mth = w_clmnth+4(2). //Taking out month

      w_year = w_clmnth+0(4). //Taking out year

      w_year_ne = w_clmnth+0(4). //Taking out year in other variable also

      /* Calculating month & year 8 month back.

      if w_mth < 8.

      w_mnth = 8 - w_mth.

      w_mnth = 12 - w_mnth.

      w_year = w_year - 1.

      else.

      w_mnth = w_mth - 8.

      endif.

      if w_mnth < 10.

      w_mth = w_mnth.

      CONCATENATE '0' w_mth INTO w_mth IN CHARACTER MODE.

      else.

      w_mth = w_mnth.

      endif.

      //Forming the inital date first of 8 month back

      CONCATENATE w_year w_mth '01' INTO w_tempdate IN CHARACTER MODE

      .

      w_date = w_tempdate.

      /* Calculation of last date of selected month

      w_mth = w_clmnth+4(2).

      if w_mth eq '12'.

      w_mth = '01'.

      w_year_ne = w_year_ne + 1.

      else.

      w_mnth = w_mth + 1.

      w_mth = w_mnth.

      if w_mnth < 10.

      CONCATENATE '0' w_mth INTO w_mth IN CHARACTER MODE.

      endif.

      endif.

      CONCATENATE w_year_ne w_mth '01' INTO w_tempdate1 IN CHARACTER MODE

      .

      w_date1 = w_tempdate1.

      w_date1 = w_date1 - 1.

      /*Function module for calculating days difference between two dates:

      CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS'

      EXPORTING

      i_date_from = w_date

      • I_KEY_DAY_FROM =

      i_date_to = w_date1

      • I_KEY_DAY_TO =

      • I_FLG_SEPARATE = ' '

      IMPORTING

      E_DAYS = w_days

      E_MONTHS = w_mnth

      • E_YEARS =

      .

      write :/ 'Days ', w_days.

  • author's profile photo Former Member
    Former Member
    Posted on Nov 24, 2007 at 07:36 PM

    Thanks Guys, Created 8 variables, and wrote User Exits for each to solve this problem.

    Add a comment
    10|10000 characters needed characters exceeded

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.