‎2008 Apr 24 11:30 AM
Hi All,
The following code gives the output of the first monday of a month. Can any one help me in getting the first monday of the last month.
DATA: G_DATE0 LIKE SY-DATUM.
DATA: G_DATE1 LIKE SY-DATUM.
DATA: G_WOTNR TYPE P.
G_DATE1 = G_DATE0.
DATE1+6(2) = '01'.
DO.
CALL FUNCTION 'DAY_IN_WEEK'
EXPORTING
DATUM = G_DATE1
IMPORTING
WOTNR = WOTNR.
if g_wotnr = 1.
exit.
endif.
ADD 1 TO G_DATE1.
ENDDO.
Points will be awarded for sure.
Regards,
Srik.
‎2008 Apr 24 11:36 AM
Hi,
see this code.
DATA: G_DATE0 LIKE SY-DATUM.
DATA: G_DATE1 LIKE SY-DATUM.
DATA: G_WOTNR TYPE P.
g_date0 = sy-datum.
G_DATE1 = G_DATE0.
g_DATE1+4(2) = g_DATE1+4(2) - 1.
g_DATE1+6(2) = '01'.
DO.
CALL FUNCTION 'DAY_IN_WEEK'
EXPORTING
DATUM = G_DATE1
IMPORTING
WOTNR = g_WOTNR.
if g_wotnr = 1.
exit.
endif.
ADD 1 TO G_DATE1.
ENDDO.
write:/ g_date1.
rgds,
bharat.
‎2008 Apr 24 11:36 AM
Hi,
see this code.
DATA: G_DATE0 LIKE SY-DATUM.
DATA: G_DATE1 LIKE SY-DATUM.
DATA: G_WOTNR TYPE P.
g_date0 = sy-datum.
G_DATE1 = G_DATE0.
g_DATE1+4(2) = g_DATE1+4(2) - 1.
g_DATE1+6(2) = '01'.
DO.
CALL FUNCTION 'DAY_IN_WEEK'
EXPORTING
DATUM = G_DATE1
IMPORTING
WOTNR = g_WOTNR.
if g_wotnr = 1.
exit.
endif.
ADD 1 TO G_DATE1.
ENDDO.
write:/ g_date1.
rgds,
bharat.
‎2008 Apr 24 11:43 AM
if you use the above code, ensure you modify it as such
g_date0 = sy-datum.
G_DATE1 = G_DATE0.
g_DATE1+4(2) = g_DATE1+4(2) - 1.
if g_DATE1+4(2) = '00'.
g_DATE1+4(2) = '12'.
g_DATE1+0(4) = g_DATE1+0(4) - 1.
endif.
g_DATE1+6(2) = '01'.
There is a Function that will compute the date with adjustments to Month or Year. It might be better to look for that FM. I can't recall the name of hand.
‎2008 Apr 24 11:44 AM
if actual month is 01 above code will not work. you have to use this syntax.
if G_DATE1+4(2) eq '01'.
move '12' to G_DATE1+4(2).
subtract 1 from G_DATE1+0(4) .
else.
subtract 1 from G_DATE1+4(2) .
endif.
move '01' to G_DATE1+6(2).
ibrahim
‎2008 Apr 24 1:32 PM
try:
PARAMETERS g_date0 LIKE sy-datum.
DATA: g_date1 LIKE sy-datum.
DATA: g_wotnr TYPE p.
INITIALIZATION.
CONCATENATE sy-datum(4) '1201' INTO g_date0.
START-OF-SELECTION.
g_date1 = g_date0.
DO.
CALL FUNCTION 'DAY_IN_WEEK'
EXPORTING
datum = g_date1
IMPORTING
wotnr = g_wotnr.
IF g_wotnr = 1.
EXIT.
ENDIF.
ADD 1 TO g_date1.
ENDDO.
WRITE : g_date0, / g_date1, g_wotnr.
hope that helps
Andreas