‎2007 Sep 22 4:10 AM
Hi All,
I have two requiremnts to find Monday value.
1. I need to validate the value of a variable whether it is a Monday date or not.
2. I need to validate another varaible whether the date entered is a Monday date which is between 4 weeks back and 20 weeks back.
ie. currentmonday-28 and currentmonday-140.
Please suggest the code for this.
Thanks in advance!
‎2007 Sep 22 4:30 AM
you can try this
data : curr_mon like sy-datum,
mon_4 like sy-datum,
mon_20 like sy-datum.
CALL FUNCTION 'BWSO_DATE_GET_FIRST_WEEKDAY'
EXPORTING
DATE_IN = sy-datum
IMPORTING
DATE_OUT = curr_mon
.
mon_4 = curr_mon - 28.
mon_20 = curr_mon - 140.
write : / 'Monday of 4 weeks ago : ' , mon_4.
write : / 'Monday of 20 weeks ago : ' , mon_20.
regards
shiba dutta
‎2007 Sep 22 4:16 AM
Hi Subha
use following sample report, you can find so many solutions
get week day 1st and use IF condition work with your statments
REPORT ZEXAMPLE.
DATA: BEGIN OF DAYNAMES OCCURS 0.
INCLUDE STRUCTURE T246.
DATA: END OF DAYNAMES.
DATA: V_WEEK LIKE SCAL-WEEK,
WOTNR TYPE P,
V_MONDAY LIKE SCAL-DATE.
GET THE CURRENT WEEK OF A DATE
CALL FUNCTION 'DATE_GET_WEEK'
EXPORTING
DATE = SY-DATUM
IMPORTING
WEEK = V_WEEK "YYYYWW
EXCEPTIONS
DATE_INVALID = 1
OTHERS = 2.
GET THE DATE OF THE FIRST MONDAY OF THE WEEK
CALL FUNCTION 'WEEK_GET_FIRST_DAY'
EXPORTING
WEEK = V_WEEK
IMPORTING
DATE = V_MONDAY
EXCEPTIONS
WEEK_INVALID = 1
OTHERS = 2.
DAY NUMBER OF A DATE
CALL FUNCTION 'DAY_IN_WEEK'
EXPORTING
DATUM = SY-DATUM
IMPORTING
WOTNR = WOTNR.
NAMES OF THE DAYS
CALL FUNCTION 'WEEKDAY_GET'
EXPORTING
LANGUAGE = SY-LANGU
TABLES
WEEKDAY = DAYNAMES.
READ TABLE DAYNAMES WITH KEY WOTNR = WOTNR.
WRITE:/ 'DATE:', SY-DATUM,
/ 'WEEK NUMBER:', V_WEEK+4,
/ 'FIRST DAY OF WEEK:', V_MONDAY,
/ 'CURRENT DAY OF WEEK:', DAYNAMES-LANGT.
Dont forget to rewards
‎2007 Sep 22 4:18 AM
1.I need to validate the value of a variable whether it is a Monday date or not.//
use the FM get_week_info based_on_date
by passing on a date it gives weekday information perhaps weekstart date.
suppose say that already u had a date in a variable u can compare with the date
u can do a bit of coding to achieve this requirement.
2.I need to validate another varaible whether the date entered is a Monday date which is between 4 weeks back and 20 weeks back.
ie. currentmonday-28 and currentmonday-140.//
im not clear on this requirement 2 .
you need to use one more fm RP_CALC_DATE*INTRVAL to go back n of days to find particular date .
But make clear with an example .
Im not on sap now so u can check the Fm for 1 . Try exe'g this Fm and u will have an idea .
regards,
vijay.
‎2007 Sep 22 4:30 AM
you can try this
data : curr_mon like sy-datum,
mon_4 like sy-datum,
mon_20 like sy-datum.
CALL FUNCTION 'BWSO_DATE_GET_FIRST_WEEKDAY'
EXPORTING
DATE_IN = sy-datum
IMPORTING
DATE_OUT = curr_mon
.
mon_4 = curr_mon - 28.
mon_20 = curr_mon - 140.
write : / 'Monday of 4 weeks ago : ' , mon_4.
write : / 'Monday of 20 weeks ago : ' , mon_20.
regards
shiba dutta
‎2007 Sep 22 6:00 AM
Thanks Shiba.
But I want all mondays between 4 weeks and 20 weeks.
Please suggest any way to store all monday values.
‎2007 Sep 22 6:11 AM
for this you have to loop.
data : count type i default 21.
do 16 times. " since 4th to 20th so 20 - 4 = 16 times and count should strt from 28
count = count + 7.
monday = curr_mon - count.
write : / monday.
clear : monday.
enddo.
regards
shiba dutta
‎2007 Sep 24 6:19 AM
Hi Shiba,
Can I write code like this
data : count type i default 21.
do 16 times. " since 4th to 20th so 20 - 4 = 16 times and count should strt from 28
count = count + 7.
monday = curr_mon - count.
write : / monday.
clear : monday.
enddo.
curr_mon = sy-datum.
mondate = LOC_VAR_RANGE-LOW.
CALL FUNCTION 'BWSO_DATE_GET_FIRST_WEEKDAY'
EXPORTING
DATE_IN = mondate
IMPORTING
DATE_OUT = curr_mon.
break-point.
IF mondate NE monday.
BREAK-POINT.
CALL FUNCTION 'RRMS_MESSAGE_HANDLING'
EXPORTING
I_CLASS = 'RSBBS'
I_TYPE = 'I'
I_NUMBER = '000'
I_MSGV1 = ' Monday Values between four weeks and 20 weeks back allowed '.
RAISE no_replacement.
Endif.
enddo.