Application Development 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: 

reg caluclating date range?

Former Member
0 Kudos

hi friends

my requirement is i have to retrive data based on the one month date range given on the date in my selection screen . how to caluclate one month range for the given date ? is there any function module available ? can i use hr function modules in abap ?

thanks & regards

deepurd

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

FIMA_DAYS_AND_MONTHS_AND_YEARS : Find the difference between two dates in years, months and days.

DAY_ATTRIBUTES_GET : Returns attributes for a range of dates specified

MONTHS_BETWEEN_TWO_DATES : To get the number of months between the two dates.

use any of the above fm as per your requirement.

you can use hr fm also in abap.

Rgds,

BabuSrinath

16 REPLIES 16

Former Member
0 Kudos

Hi,

Derive year and Month of the date using CACS_DATE_GET_YEAR_MONTH and use the below FM for first and last day of the month:


FIRST_AND_LAST_DAY_IN_YEAR_GET

Thanks,

Sriram Ponna.

Edited by: Sriram Ponna on Dec 16, 2008 11:31 AM

Former Member
0 Kudos

Hi,

FIMA_DAYS_AND_MONTHS_AND_YEARS : Find the difference between two dates in years, months and days.

DAY_ATTRIBUTES_GET : Returns attributes for a range of dates specified

MONTHS_BETWEEN_TWO_DATES : To get the number of months between the two dates.

use any of the above fm as per your requirement.

you can use hr fm also in abap.

Rgds,

BabuSrinath

0 Kudos

hi buddies

actually my requirement is i have to retrieve the data which is entered from the last one month of given date in selection screen? whatsthe function module for getting this

ex: suppose i given 20-11-2008

i have to retrieve the data between 20-10-2008 to 20-12-2008

thanks & regards

deepurd

0 Kudos

Hi,

Use FM DATE_IN_FUTURE.

First call it with your date and -30 to get previous month date.

Then call it with your date and 30 to get next month date.

data : doc_date type RM06B-EEIND, from_date type d, to_date type d.

doc_date = '20112008'.

CALL FUNCTION 'DATE_IN_FUTURE'
  EXPORTING
    anzahl_tage                   = '-30'
    import_datum                  = doc_date
 IMPORTING
*   EXPORT_DATUM_EXT_FORMAT       =
   EXPORT_DATUM_INT_FORMAT       = from_date. " this will become 21102008

CALL FUNCTION 'DATE_IN_FUTURE'
  EXPORTING
    anzahl_tage                   = '30'
    import_datum                  = doc_date
 IMPORTING
*   EXPORT_DATUM_EXT_FORMAT       =
   EXPORT_DATUM_INT_FORMAT       = to_date.  " this will become 20122008

This will solve your problem.

Regards

Karthik D

Edited by: Karthik D on Dec 16, 2008 12:13 PM

0 Kudos

hi karthik

i have to caluclate -1month

for few months there will be 28 days for few 31 days

so how to do it?

0 Kudos

Hi,

Its seems like its not possible. Because, if you give 20.11.2008 and want previous month and next month data, what will you consider November's No. of days or October's No. of days or December's No. of days ?

So let me know which one you want to consider in this case so that i can guide accordingly.

Regards

Karthik D

0 Kudos

hi,

use this logic.


data: d1 like sy-datum,
        d2 like sy-datum.
  d2 = sy-datum.
  d2+6(2) = '01'.
  d2 = d2 - 1. "prev mnth last date
  d1 = d2.
  d1+6(2) = '01'. "prev mnth start date
write : / d1,d2.

0 Kudos

Ok,

If i understood correctly, no need for FM use the following code;

data : doc_date type d, from_date type d, to_date type d, month(2) type n.

doc_date = '20081120'.
month = doc_date+4(2).
from_date = doc_date.

IF month NE '01'.  " If not january
     from_date+4(2) = Month - 1. "Assign the previous month
ELSE.                                            " if January
    from_Date(4) = from_Date(4) - 1.  " Assign previous year
    from_date+4(2) = '12'.                  " Assign December
ENDIF.

to_date = doc_date.
IFmonth NE '12'.  " If not December
   to_date+4(2) = Month + 1. "Assign the next month
ELSE.                                      " if December
  to_Date(4) = to_Date(4) + 1.    " Assign next year
  to_date+4(2) = '01'.                 " Assign January
ENDIF.

Output:

If given date is 20.11.2008 then from_Date = 20.10.2008 & to_date = 20.12.2008

If given date is 20.12.2008 then from_Date = 20.11.2008 & to_date = 20.01.2009

If given date is 20.01.2008 then from_Date = 20.12.2007 & to_date = 20.02.2008

Regards

Karthik D

Edited by: Karthik D on Dec 16, 2008 12:50 PM

0 Kudos

Hi,

You can use the below FM 'RP_CALC_DATE_IN_INTERVAL'

CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'

EXPORTING

date = '20081020'

months = 1

SIGNUM = '+'

"if you want 1 month less then use '-' (MINUS) symbol. if you want 1 month more then use '+' (PLUS) symbol

IMPORTING

CALC_DATE = '20080920'.

Hope this may helpful.

Regards,

Sravanthi

0 Kudos

hi sravanthi

when i was trying to use the HR function module its giving dump .

my requiremnt is

if selection screen input date is 25-12-2008 i have to retrive documents posted within 1 month range . data between 24-11-2008 to 25-12-2008.

regards

deepurd

0 Kudos

Hello Deepu RD,

You can try the method SUBTRACT_MONTHS_FROM_DATE of the Class CL_HRPAD_DATE_COMPUTATIONS.


DATA:
  l_v_month TYPE i VALUE '1',
  v_date2 TYPE TYPE datum.

      TRY.
          CALL METHOD _HRPAD_DATE_COMPUTATIONS=>SUBTRACT_MONTHS_FROM_DATE
            EXPORTING
              start_date = p_date1 "To Date - Higher Value 
              months     = l_v_month
            RECEIVING
              date       = v_date2.
        CATCH cx_hrpa_violated_postcondition .
      ENDTRY.

Hope this is clear.

BR,

Suhas

0 Kudos

First You told this;

>

>actually my requirement is i have to retrieve the data which is entered from the last one month of given date >in selection screen? whatsthe function module for getting this

>ex: suppose i given 20-11-2008

>i have to retrieve the data between 20-10-2008 to 20-12-2008

Now you are telling this;

>

> hi sravanthi

> when i was trying to use the HR function module its giving dump .

> my requiremnt is

> if selection screen input date is 25-12-2008 i have to retrive documents posted within 1 month range . data between 24-11-2008 to 25-12-2008.

>

> regards

> deepurd

Do you know that thus you are effectively wasting yours as well as others time? Can't you use the above codings and FM's given by all to achieve your requirement. First of all you come to a conclusion on what you want, then you can arrive at the solution using all the above inputs and ideas.

Regards

Karthik D

Former Member
0 Kudos

Hi,

Use FM BKK_GET_MONTH_LASTDAY to get the last day of the month and use the following code to get the first day of month.

first_day = date.
first_day+6(2) = '01'.

Regards

Karthik D

Former Member
0 Kudos

hi deepu,

You can use HR function modules but you need to to diclare some sturcture before using any hr function modules like tables: pernr.

i have an doubt about your requirement

do you want 30days in a month or as per calender month.

can you tell me which one do you want

Regards,

Arjun.

Former Member
0 Kudos

hi deepu,

You can use HR function modules but you need to to diclare some sturcture before using any hr function modules like tables: pernr.

i have an doubt about your requirement

do you want 30days in a month or as per calender month.

can you tell me which one do you want

Regards,

Arjun.

0 Kudos

tyu