Application Development 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: 

Number of mondays , tuesdays,wed,thu,fri,sat,sun for a particular month

Former Member
0 Kudos

Hi all,

i requried no. of mondays ,tuesdays, wed,thu,fri,sat for a particular month.

please give me the solution.

Regards,

P L V Satyanarayana.

4 REPLIES 4

jaideeps
Advisor
Advisor
0 Kudos

hi,

i just have an idea..

1.find first day of the month.

2.find the first Monday

3.using a case statement you can easily count the no of mondays etc..

thankx

jaideep

if useful reward points

Former Member
0 Kudos

Hello,

Use the FM <b>DATE_TO_DAY.</b> This will return the day of the current date.

Regards,

Vasanth

younes_bouaouad
Explorer
0 Kudos

hi,

loop over the month dates, you can get the last date of the month by using some FM kinda ladtdayget

then for every date, use FM date_to_day or some similar one,

and using a case, you count the number of everyday

hope it helps

Former Member
0 Kudos

Hi,

Please try this code.

REPORT zgm_date_test .
DATA: lv_first_date TYPE sy-datum.
DATA: lv_last_date  TYPE sy-datum.
DATA: lv_day_start  TYPE scal-indicator.
DATA: lv_days_inmonth       TYPE p0347-scrdd.
DATA: lv_index TYPE sy-index.

DATA: lt_days TYPE TABLE OF int1.

FIELD-SYMBOLS: <fs_days> LIKE LINE OF  lt_days.

parameter: pdate type sy-datum default sy-datum.


*lv_first_date = '20070709'.

lv_first_date = pdate.


* Change the date to the start date of the month
lv_first_date+6(2) = '01'.



* Get the Last day of the month
CALL FUNCTION 'SG_PS_GET_LAST_DAY_OF_MONTH'
     EXPORTING
          day_in            = lv_first_date
     IMPORTING
          last_day_of_month = lv_last_date.


CALL FUNCTION 'DATE_COMPUTE_DAY'
     EXPORTING
          date = lv_first_date
     IMPORTING
          day  = lv_day_start.


lv_days_inmonth = ( lv_last_date - lv_first_date ) + 1.

WRITE:/ 'First Date', 28 ':- ', 32 lv_first_date.
WRITE:/ 'Last Date', 28 ':- ', 32 lv_last_date.
WRITE:/ 'Nr of Days in the month', 28 ':- ' , 30 lv_days_inmonth.

skip 2.

* From 1-28 all all days will have 4 weeks
DO 7 TIMES.
  APPEND 4 TO lt_days.
ENDDO.


* From 29th onwards treat diferently.

lv_index = lv_day_start.

IF lv_days_inmonth >= 29.
  READ TABLE lt_days ASSIGNING <fs_days> INDEX lv_index.
  IF sy-subrc = 0.
    ADD 1 TO <fs_days>.
    IF lv_days_inmonth >= 30.
      ADD 1 TO lv_index.
      IF lv_index = 8.
        lv_index = 1.
      ENDIF.
      READ TABLE lt_days ASSIGNING <fs_days> INDEX lv_index.
      IF sy-subrc = 0.
        ADD 1 TO <fs_days>.
        IF lv_days_inmonth >= 31.
          ADD 1 TO lv_index.
          IF lv_index = 8.
            lv_index = 1.
          ENDIF.
          READ TABLE lt_days ASSIGNING <fs_days> INDEX lv_index.
          IF sy-subrc = 0.
            ADD 1 TO <fs_days>.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.


ENDIF.



LOOP AT lt_days ASSIGNING <fs_days>.
case sy-tabix.
when 1. write:/ 'Monday'.
when 2. write:/ 'Tuesday'.
when 3. write:/ 'Wednesday'.
when 4. write:/ 'Thursday'.
when 5. write:/ 'Friday'.
when 6. write:/ 'Saturday'.
when 7. write:/ 'Sunday'.
endcase.
  WRITE: 15 ':-', 18 <fs_days>.
ENDLOOP.

Regards

Geogy

<b>PS: Reward points for usefull answers</b>