Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

function module ..for dates between two dates..

Former Member
0 Likes
4,738

hi i need a function module which gives the month start and end dates as out put if i give two dates as input.

ex : input : a :01.01.2006

b: 01.06.2006

the o/p shld be :

01.01.2006 31.01.2006

01.02.2006 28.02.2006

01.03.2006 31.02.2006

upto the enddate ....

plz help.i have tried HR_BR_SPLIT_MONTHS but its of no use if the year changes ...

16 REPLIES 16
Read only

Nkrish
Contributor
0 Likes
2,289

hi,

Could you elaborate on "no use if the year changes ".

I tried to reproduce your problem, I even tried for 2008 the values are different.I am not sure what is the exact problem

Regards,

Narayani

Read only

Former Member
0 Likes
2,289

HI ,

narayani ,,the exact pblm is if i give input as 02.04.2007 and 03.04.2008 i want in between start and end dates of the months .

but o/p sdates will have 9 entries and pdates will have 2007 years dates only. thy are not getting the 2008 values......hope u have understood.

vishnu reddy.

Read only

SantoshKallem
Active Contributor
0 Likes
2,289

wrong post

Edited by: Santhosh Reddy on Mar 5, 2008 2:06 PM

Read only

p291102
Active Contributor
0 Likes
2,289

Hi,

Try this FM.

SD_DATETIME_DIFFERENCE

Thanks,

Sankar M

Read only

Former Member
0 Likes
2,289

Try using the FM "FIMA_DAYS_BETWEEN_TWO_DATES_2".

or

Use this FM


data: No_of_days TYPE I
CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'
EXPORTING
I_DATUM_BIS = G_T_PURO-AEDAT " Enddate
I_DATUM_VON = G_T_EBAN-BADAT " Start Date
IMPORTING
E_TAGE = No_of_days 
EXCEPTIONS
DAYS_METHOD_NOT_DEFINED = 1
OTHERS = 2.
write: No_of_days .

TO find out the difference in the form of months try


MONTHS_BETWEEN_TWO_DATES 
MONTHS_BETWEEN_TWO_DATES_NEW
HR_99S_MONTHS_BETWEEN_DATES
HR_MONTHS_BETWEEN_TWO_DATES

Regards,

Chandru

Read only

Former Member
0 Likes
2,289

Hi,

I have created a small function module which might your requirement as below:



FUNCTION zcalculatedates.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     REFERENCE(START_DATE) TYPE  BEGDA
*"     REFERENCE(END_DATE) TYPE  ENDDA
*"  EXPORTING
*"     REFERENCE(DATE_OUTPUT) TYPE  DBSTODATE
*"  EXCEPTIONS
*"      DATE_CALC_ERROR
*"      CHECK_DATES
*"----------------------------------------------------------------------

  DATA: v_date TYPE sy-datum, v_datec(8), w_date_output TYPE dbssodate.

  IF START_DATE GT END_DATE. RAISE CHECK_DATES. ENDIF.

  MOVE start_date TO v_datec. v_datec+6(2) = '01'.
  MOVE v_datec TO v_date.

  DO.

    MOVE v_date TO w_date_output-low.

    CALL FUNCTION 'SLS_MISC_GET_LAST_DAY_OF_MONTH'
      EXPORTING
        day_in            = v_date
      IMPORTING
        last_day_of_month = w_date_output-high
      EXCEPTIONS
        day_in_not_valid  = 1
        OTHERS            = 2.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
     RAISING date_calc_error.
    ELSE.
      IF  w_date_output-low > end_date.
        EXIT.
      ELSE.
        APPEND w_date_output TO date_output.
      ENDIF.
    ENDIF.

    CALL FUNCTION 'BKK_ADD_MONTH_TO_DATE'
      EXPORTING
        months  = 1
        olddate = v_date
      IMPORTING
        newdate = v_date.

  ENDDO.

ENDFUNCTION.

Examples of the function:

Exampe 1:

Input

Import parameters Value

START_DATE 01.01.2006

END_DATE 01.06.2006

Output

LOW HIGH

01.01.2006 31.01.2006

01.02.2006 28.02.2006

01.03.2006 31.03.2006

01.04.2006 30.04.2006

01.05.2006 31.05.2006

01.06.2006 30.06.2006

Example 2:

Input

Import parameters Value

START_DATE 01.08.2006

END_DATE 01.02.2007

Output

LOW HIGH

01.08.2006 31.08.2006

01.09.2006 30.09.2006

01.10.2006 31.10.2006

01.11.2006 30.11.2006

01.12.2006 31.12.2006

01.01.2007 31.01.2007

01.02.2007 28.02.2007

Cheers

Read only

0 Likes
2,289

thx a lot aditya.....

Read only

0 Likes
2,289

hi aditya ,

wht type structure will be DBSTODATE and dbssodate .

plz let me know .

Read only

Former Member
0 Likes
2,289

type of strucure not clear

Read only

0 Likes
2,289

Hi Vishnu,

DBSTODATE is a table type and its structure is DBSSODATE.

DBSSODATE is a range structure for DATE field, i.e. it contains the following fields: SIGN, OPTION, LOW and HIGH.

However, you can replace the table type and structure with your own declarations in SE11 as per your convinience.

Read only

0 Likes
2,289

Its a Range for Dates...

Line type DBSSODATE

SIGN CHAR 1 0

OPTION CHAR 2 0

LOW DATS 8 0

HIGH DATS 8 0

Cheers!!

Lokesh

Read only

Former Member
0 Likes
2,289

Hi try this,

This will give total days, months, and years between two dates.

HR_HK_DIFF_BT_2_DATES

Regards,

kavitha.

Read only

Former Member
0 Likes
2,289

HI,

You can use FM CSCP_PARA1_GET_PERIODS.

Thanks,

Sriram Ponna.

Read only

0 Likes
2,289

hi,

sriram its giving only month start dates i want end dates also ....

regards,

vishnu.

Read only

Former Member
0 Likes
2,289

thx sriram ..got tht .

Read only

Former Member
0 Likes
2,289

Use this FM

data: No_of_days TYPE I

CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'

EXPORTING

I_DATUM_BIS = G_T_PURO-AEDAT " Enddate

I_DATUM_VON = G_T_EBAN-BADAT " Start Date

IMPORTING

E_TAGE = No_of_days

EXCEPTIONS

DAYS_METHOD_NOT_DEFINED = 1

OTHERS = 2.

write: No_of_days .

TO find out the difference in the form of months try

MONTHS_BETWEEN_TWO_DATES

MONTHS_BETWEEN_TWO_DATES_NEW

HR_99S_MONTHS_BETWEEN_DATES

HR_MONTHS_BETWEEN_TWO_DATES

Please reward points, if its helpful.