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 : Dates

Former Member
0 Kudos

Hi All,

1) In selection screen if i enter any date range it should show the total month data

ex: suppose i given 15.01.2009.

i have to retrieve from 01.01.2009 to 31.01.2009

2) Actually my requirement is i have to retrieve the data which is entered from the current month of given date in selection screen, it should get me the previous 2 months data? whatsthe function module for getting this

ex: suppose i given 01-01-2009

i have to retrieve pervious months data between 01-11-2008 to 30-12-2008

thanks & regards

marreddy

5 REPLIES 5

Former Member
0 Kudos

Use FM SG_PS_GET_LAST_DAY_OF_MONTH to get last day of the month

To get previous month date use FM HR_JP_ADD_MONTH_TO_DATE

Hope this helps...

Former Member
0 Kudos

1) In selection screen if i enter any date range it should show the total month data

ex: suppose i given 15.01.2009.

i have to retrieve from 01.01.2009 to 31.01.2009

Ans: CONCATENATE p_date+0(6) '01' INTO v_beg_date.

CALL FUNCTION 'FKK_LAST_DAY_OF_MONTH'

EXPORTING

day_in = v_beg_date

IMPORTING

last_day_of_month = v_end_date.

p_date = 20090115

v_beg_date = 20090101.

v_end_date = 20090131.

2) Actually my requirement is i have to retrieve the data which is entered from the current month of given date in selection screen, it should get me the previous 2 months data? whatsthe function module for getting this

ex: suppose i given 01-01-2009

i have to retrieve pervious months data between 01-11-2008 to 30-12-2008

ANS :

CALL FUNCTION 'BKK_ADD_MONTH_TO_DATE'

EXPORTING

months = '-2'

olddate = v_beg_date " 01.01.2009

IMPORTING

newdate = v_ndate. " 01.11.2008

Former Member
0 Kudos

hi

you can try these fm's

FM_GET_DATES_FROM_PERIOD

RKE_GET_FIRST_DAY_IN_PERIOD

RKE_GET_LAST_DAY_IN_PERIOD

hope it helps

regards

Aakash Banga

SuhaSaha
Advisor
Advisor
0 Kudos

Hello,

You can make use of the class CL_HRPAD_DATE_COMPUTATIONS for your calculations.

Plz try the code below:



PARAMETERS: P_DATE TYPE SY-DATUM DEFAULT SY-DATUM.

DATA:
V_DATE TYPE DATUM,
V_DAT1 TYPE SY-DATUM,
V_DAT2 TYPE SY-DATUM.


CONCATENATE P_DATE+0(6) '01' INTO V_DATE. "First date of the monhn

V_DAT2 = V_DATE - 1. "Last day of previous month


CALL METHOD CL_HRPAD_DATE_COMPUTATIONS=>SUBTRACT_MONTHS_FROM_DATE
  EXPORTING
    START_DATE = V_DATE
    MONTHS     = 2
  RECEIVING
    DATE       = V_DAT1. "Lower Date i.e., 1st date of 2 months prior

WRITE: V_DAT1, V_DAT2.

Now you can use the variables V_DAT1 & V_DAT2 to get the data using BETWEEN addition.

BR,

Suhas

Former Member
0 Kudos

Hi,

Check the below code.


DATA: w_dat TYPE dats,
      w_date_s1 TYPE dats, 
      w_date_s2 TYPE dats,
      w_date_e1 TYPE dats,
      w_date_e2 TYPE dats,
      w_month1 TYPE ltx,
      w_month2 TYPE ltx.

w_dat = sy-datum. "So this is january as of now
PERFORM get_date USING 2
                 CHANGING w_date_s1 w_date_e1 w_month1. "Here you will get nov start and end date

PERFORM get_date USING 1
                 CHANGING w_date_s2 w_date_e2 w_month2. "Here you will get dec start and end date


WRITE:      / w_month1 , ':', w_date_s1, w_date_e1, 
            / w_month2 , ':', w_date_s2, w_date_e2.


FORM get_date USING p_month TYPE numc3
              CHANGING p_dat1 TYPE dats
                       p_dat2 TYPE dats
                       p_name TYPE ltx.

  DATA:lw_dat TYPE dats,
       lw_var(6) TYPE c,
       lw_month(2) TYPE c.


  DATA: lit_month LIKE t247 OCCURS 0 WITH HEADER LINE.

  CALL FUNCTION 'CCM_GO_BACK_MONTHS'
       EXPORTING
            currdate   = w_dat  "your date from select-option
            backmonths = p_month
       IMPORTING
            newdate    = lw_dat.


  CALL FUNCTION 'SG_PS_GET_LAST_DAY_OF_MONTH'
       EXPORTING
            day_in            = lw_dat
       IMPORTING
            last_day_of_month =
               p_dat2 "Now w_date_e is end date of last month
       EXCEPTIONS
            OTHERS            = 1. "of date in w_date


  lw_var = p_dat2+0(6).
  lw_month = p_dat2+4(2).

  CONCATENATE lw_var '01' INTO p_dat1. "Create first date

  CALL FUNCTION 'MONTH_NAMES_GET' "Get the month name
       TABLES
            month_names = lit_month.
  READ TABLE lit_month INDEX lw_month.
  p_name = lit_month-ltx.

ENDFORM.

o/p:

November                       : 01.11.2008 30.11.2008
December                       : 01.12.2008 31.12.2008

Now use w_date_s1, w_date_e1 to get Nov month details and

w_date_s2, w_date_e2 for dec month details.

Regards,

Manoj Kumar P