cancel
Showing results for 
Search instead for 
Did you mean: 

Breaking a period into there respective months

Former Member
0 Kudos

Hi,

I have period and I want to break this period into its respective month.

Like date_from = 15/01/2012 date_to = 24/02/2012

i want to break this period as 15/01/2012 to 31/01/2012 and 01/02/2012 to 24/02/2012.

Can you please suggest me a function module or any method with which i can perform this opertaion.

Thanks in advance.

Accepted Solutions (0)

Answers (3)

Answers (3)

amy_king
Active Contributor
0 Kudos

Hi Prakhar,

Though it is unreleased, function HR_99S_INTERVAL_BETWEEN_DATES may be useful to you. If you provide it with start and end dates and also specify TAB_MODE = 'I', export parameter MONTH_TAB will list all months between the specified dates. Just substitute your date_from for the first month's start date and your date_to for the last month's end date, and you'll have the result you're looking for.

CALL FUNCTION 'HR_99S_INTERVAL_BETWEEN_DATES'
     EXPORTING
       begda        = date_from
       endda        = date_to
       tab_mode  = 'I'    " Include boundary months
     IMPORTING
       month_tab = lt_month_tab.

Cheers,

Amy

Former Member
0 Kudos

Hi Prakhar,

Use FM 'DETERMINE_END_OF_MONTH' to determine no_of_days_in_month.

And use concatenate no_of_days_in_month with start month you will get to period.

For example in your case : date_from is 15/01/2012.

No-of_days_in_month = 31.

concatenate this with month and year.

Last day in month = 31/01/2012.

Add 1 day to this date you will get 1st day in next month. ( 01/02/2012 in your example )

And use this date with date_to, you will get second period.

raymond_giuseppi
Active Contributor
0 Kudos

What did you try before posting, did you try a logic like

do

  calculate first_day_of_ month from last_date changing day to '01'

  if first_day_of_ month greater than first_date

    create an interval from first_day_of_month to last_date

    last_date = last day of previous month (first_day_of_month - 1)

    " iterate.

  else.

    create an interval from first_day to last_day.

    exit.

  endif.

enddo.

Regards,

Raymond

Jelena
Active Contributor
0 Kudos

Raymond Giuseppi wrote:

What did you try before posting,

Indeed. But why try anything when you can post a basic question on SCN and within a few hours get 3 replies?

[sarcasm off]

Prakhar, please do some analysis yourself before posting. Try, for example, 'last day of month site:sap.com' in Google and see what happens. All date related functions have already been mentioned on SCN. Or simply search in SE37 using an asterisk (e.g. *LAST*DAY*).

Former Member
0 Kudos

Hi Jelena,

Thanks for your suggestion.

Except getting 'DETERMINE_END_OF_MONTH' from here rest of the whole logic and table i had found by myself.

Task is completed.