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

Reg : Dates

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jan 15, 2009 at 05:57 AM

    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...

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 15, 2009 at 05:58 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 15, 2009 at 06:05 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 15, 2009 at 06:43 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 16, 2009 at 09:32 AM

    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

    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.