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

System Date calculation

Former Member
0 Likes
2,266

Hi Gurus

I have to update the data from one DSO to another DSO using transformation. We generally load the data on Monday but we can do so even sometime in middle of the week. The logic which we are looking for is

Take the system date and calculate the From Date and To Date

Logic

From Date:- Monday of the previous week

To Date:- Sunday of the previous week

Eg. say today is 6/8/09

so the From data will be 6/1/09

and To Date will be 6/7/09

Can you please give me the logic for this.

Really Appreciated

Prat

14 REPLIES 14
Read only

Former Member
0 Likes
1,996
  • Determine current week dates

CALL FUNCTION 'GET_WEEK_INFO_BASED_ON_DATE'

EXPORTING

DATE = SY-DATUM

IMPORTING

WEEK = V_WEEK

MONDAY = V_MONDAY

SUNDAY = V_SUNDAY.

This function will retrieve the Monday and sunday of week based on date entered.

Read only

Former Member
0 Likes
1,996

Hi Prat,

It is simple. try to use this FM modules accordingly...

This logic will surely works,

First you need to calculate last week,,,

So there is a week difference.... So subtract 7 from your current date,,,


Eg. say today (P_DATUM) is 6/8/09
P_DATUM = sydatum - 7.

*To calculate week Start & End date
        CALL FUNCTION 'HRWPC_BL_DATES_WEEK_INTERVAL'
          EXPORTING
            DATUM                = P_DATUM 
            WEEK_PST             = '0'
            WEEK_FTR             = '0'
         IMPORTING
           BEGDA                = STR_WEEK_DATE  " Week start date
           ENDDA                = END_WEEK_DATE. " Week end date

so the From data will be 6/1/09 " STR_WEEK_DATE
and To Date will be 6/7/09 "END_WEEK_DATE

Thanks & regards,

Dileep .C

Read only

0 Likes
1,996

While the recommendations to use the ''GET_WEEK_INFO_BASED_ON_DATE'' or 'HRWPC_BL_DATES_WEEK_INTERVAL' Function Modules are very good for an R3/ECC environment, they won't work in a BI environment because they are not included as standard FMs.

To get the first day of the week, in BI, use FM 'BWSO_DATE_GET_FIRST_WEEKDAY'. Here's some sample code using that FM along with an FM to change the date to the next weekday falls on a weekend. In this example, I hardcoded a date of this past Sunday (7 June 2009) for testing purposes.


DATA: l_today TYPE sy-datum,
      l_wk_start TYPE sy-datum,
      l_wk_end TYPE sy-datum.

l_today = '20090607'.

CALL FUNCTION '/OSP/GETDATE_WEEKDAY'
 EXPORTING
   IV_START_DATE             = l_today
 IMPORTING
   EV_DATE_DAY_OF_WEEK       = l_today
          .

CALL FUNCTION 'BWSO_DATE_GET_FIRST_WEEKDAY'
  EXPORTING
    date_in        = l_today
 IMPORTING
   DATE_OUT       = l_wk_start
          .

l_wk_end = l_wk_start + 5.

Read only

0 Likes
1,996

Hi Dennis

I was trying to check the FM but when i entered 6/8/2008 the output was 6/8/2009.

I wan previous weeks date....

Can you please let me know what changes we need to make in the code.

Regards

Prat

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,996

Hello,

Try to use the FM like this:

DATA:
V_DATE TYPE DATUM,
V_SUN   TYPE DATUM,
V_MON   TYPE DATUM.

V_DATUM = SY-DATUM - 7.

  CALL FUNCTION 'GET_WEEK_INFO_BASED_ON_DATE'
    EXPORTING
      date = fp_v_erdat
    IMPORTING
*      week = 
      MONDAY        = V_SUN
      SUNDAY        = V_MON.
  IF sy-subrc = 0.

  ENDIF.

Hope this helps.

BR,

Suhas

Read only

0 Likes
1,996

Susha

FM 'GET_WEEK_INFO_BASED_ON_DATE' doesnot exist in BI.

Regards

Prat

Read only

0 Likes
1,996

You can subtract 7 days from the date being passed to, or substract 7 from the date being sent back from, the BWSO_DATE_GET_FIRST_WEEKDAY FM.

I took a closer look at the first FM that I provided to get the next weekday and there's code in that FM that will move it forward to the following week. For example the date of 7 June 2009 passed to that FM today (9 June 2009) will bring back a date of 15 June 2009. If the date is Saturday, and perhaps Sunday depending on your config, you're going to have to account/test for that to see if it provides the correct result.

Read only

Former Member
0 Likes
1,996

Hi,

First use the Function module GET_WEEK_INFO_BASED_ON_DATE

you will get the current week.

pass this current week to the function module LAST_WEEK

you will the previous week begin and end dates.

Regards,

Kumar Bandanadham

Read only

0 Likes
1,996

As stated previously, the FM GET_WEEK_INFO_BASED_ON_DATE doesn't exist in BI and the initial question was related BI (DSO to DSO using transformation). It's the correct FM to use in R3/ECC.

Read only

Former Member
0 Likes
1,996

Use the function module "LAST_WEEK" for getting the date of last monday and sunday. It works like this:

FUNCTION LAST_WEEK.

""Lokale Schnittstelle:

IMPORTING = '200924'

*" REFERENCE(CURRENT_WEEK) LIKE SCAL-WEEK

*" EXPORTING

REFERENCE(LAST_WEEK) = w_lastweek

REFERENCE(MONDAY) = w_lastmonday

REFERENCE(SUNDAY) = w_lastsunday

Result would be:

W_lastweek = '200923'

w_lastmonday = 01.06.2009

w_lastsunday = 07.06.2009

Here, '200924' is the concatenation of current fiscal year '2009' and '24' is current week.

Use function module GET_WEEK_INFO_BASED_ON_DATE to get the week information based on current date.

Read only

0 Likes
1,996

Pavan

FM LAST_WEEK doesnot exist in BI system.

Read only

0 Likes
1,996

Hi Prat,

You replied to everyone, But not to me...!

I just want to know, Does this one is working or not.

'HRWPC_BL_DATES_WEEK_INTERVAL' Did you tried this...!

-Dileep .C

Read only

0 Likes
1,996

Hi Dileep

This FM doesnot exist in BI/BW.

Read only

0 Likes
1,996

Hi Prat,

Ok then Do it in the Other way...

Just Subtract 7 days to go to the last week,,,,

& Use this FM 'WEEK_GET_FIRST_DAY' to get the first day of that week & Add 7 to that to get last day of last week,,,

Thanks & regards,

Dileep .C