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.

1 ACCEPTED SOLUTION

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>

2 REPLIES 2

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>

Former Member
0 Kudos

Plz try this FM:-

GET_WEEK_INFO_BASED_ON_DATE will give the week info.

and FM month_names_get will give the month name.

Rewards point if helpful.....

regards......

ABhay Singh.