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

Get last monday date using current date ???

Former Member
0 Likes
3,171

Hi all ,

I need an FM or any logic with the following functionality :

Take the current system date and find what is the date on the last Monday ?

Can anyone guide me how to do this ?

Regards ,

Vijay .

Hi all ,

I need an FM or any logic with the following functionality :

Take the current system date and find what is the date on the last Monday ?

Can anyone guide me how to do this ?

Regards ,

Vijay .

10 REPLIES 10
Read only

Former Member
0 Likes
1,898

Hi,

At present I am not in front of PC.. But there is a function module for factory calender where u can do this work.

Plz go to se37 and find function module by putting string Factory IN Description.

Darshan

Read only

Former Member
0 Likes
1,898

Hi all ,

Hopefully I found the solution . You can always correct me if I am wrong .

Using the FM <b> HR_GB_DAY_RELATIVE_TO_DATE</b> if you give the current date it will give you the last Sunday date . Adding 1 to that will give you Monday's date .

This is the solution I have found . If any one see any issues please reply to this .

Thanks ,

Vijay .

Read only

Former Member
0 Likes
1,898

Try using this FM:

HRVE_GET_FIRST_LAST_MONDAY

Thanks,

Santosh

Read only

Former Member
0 Likes
1,898

There r plenty of FMs available in SAP but u hav to check it out for which country u need the FM. go to SE15 for any SAP repository. and put FM description there...

try to check out wat is the calender id

hope this will help

Ashwani

Read only

Former Member
0 Likes
1,898

Try this:


REPORT ztest MESSAGE-ID 00.

DATA: start_date   TYPE sy-datum,
      day_name     TYPE hrvsched-daytxt.

start_date   = sy-datum.

DO.
  CALL FUNCTION 'RH_GET_DATE_DAYNAME'
    EXPORTING
      langu               = sy-langu
      date                = start_date
    IMPORTING
      daytxt              = day_name
    EXCEPTIONS
      no_langu            = 1
      no_date             = 2
      no_daytxt_for_langu = 3
      invalid_date        = 4
      OTHERS              = 5.

  IF day_name = 'Monday'.
    EXIT.
  ELSE.
    start_date = start_date - 1.
  ENDIF.

ENDDO.

WRITE: 'Monday is', start_date.

Rob

Read only

Former Member
0 Likes
1,898

Hi Vijay,

Please try this.


DATA: DAY TYPE P,
      WA_DATE LIKE SY-DATUM.
      
CALL FUNCTION 'DAY_IN_WEEK'
     EXPORTING
          datum = sy-datum
     IMPORTING
          wotnr = day.
 
CASE DAY.
    WHEN '1'.
       WA_DATE = SY-DATUM.
    WHEN '2'.
       WA_DATE = SY-DATUM - 1.
    WHEN '3'.
       WA_DATE = SY-DATUM - 2.
    WHEN '4'.
       WA_DATE = SY-DATUM - 3.
    WHEN '5'.
       WA_DATE = SY-DATUM - 4.   
    WHEN '6'.
       WA_DATE = SY-DATUM - 5.
    WHEN '7'.
       WA_DATE = SY-DATUM - 6.
ENDCASE.
 
WRITE: / 'Last Monday date from today date is ', WA_DATE.

Regards,

Ferry Lianto

Read only

Former Member
0 Likes
1,898

The solution I suggested in my 2nd reply works well and I have tested it well to confirm the results .

Thanks to all for your inputs .

Even Rob's and Ferry's soution are also working .

Read only

0 Likes
1,898

Maybe I'm confused about your problem, but does your solution still work if you enter a date that is a Sunday into that FM?

Message was edited by:

Matt Nagel

Message was edited by:

Matt Nagel

Read only

0 Likes
1,898

What do you want to do if today is Monday? Take today or go back a week?

Rob

Read only

0 Likes
1,898

Hi ,

The FM I have suggested works for my situation since we are not going to run the report on Sunday .This report is scheduled to run any time on Wed, Thu, Fri once in a week .

Just in case we enter Sunday it returns the same date , in that case we are planning to abort the run of the report .

Any suggestions ??

Thanks ,

Vijay .