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

detect all days until

Former Member
0 Likes
703

Hello friends,

how can detect all mondays and assign to internal table.

From 04th April 2008 Monday

Until 20th April 2009 Monday

Please help me in this regard

Regards

erdem sas

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
686

Here, you get in itab all the days from begin to end, there's also a day parameter to choose wich day to count (1= monday,... 7=sunday).


PARAMETERS: begin TYPE sy-datum,
            end   TYPE sy-datum,
            day   TYPE c.

DATA: l_date TYPE sy-datum,
      l_day TYPE p,
      itab TYPE TABLE OF sy-datum.

l_date = begin.

WHILE l_date <= end.

  CALL FUNCTION 'DAY_IN_WEEK'
       EXPORTING
            datum = l_date
       IMPORTING
            wotnr = l_day.
  IF l_day = day.
    APPEND l_date TO itab.
    l_date = l_date + 7.
    EXIT.
  ENDIF.
  l_date = l_date + 1.
ENDWHILE.

WHILE l_date <= end.

  APPEND l_date TO itab.
  l_date = l_date + 7.
ENDWHILE.

Hello friends,

how can detect all mondays and assign to internal table.

From 04th April 2008 Monday

Until 20th April 2009 Monday

Please help me in this regard

Regards

erdem sas

4 REPLIES 4
Read only

Former Member
0 Likes
687

Here, you get in itab all the days from begin to end, there's also a day parameter to choose wich day to count (1= monday,... 7=sunday).


PARAMETERS: begin TYPE sy-datum,
            end   TYPE sy-datum,
            day   TYPE c.

DATA: l_date TYPE sy-datum,
      l_day TYPE p,
      itab TYPE TABLE OF sy-datum.

l_date = begin.

WHILE l_date <= end.

  CALL FUNCTION 'DAY_IN_WEEK'
       EXPORTING
            datum = l_date
       IMPORTING
            wotnr = l_day.
  IF l_day = day.
    APPEND l_date TO itab.
    l_date = l_date + 7.
    EXIT.
  ENDIF.
  l_date = l_date + 1.
ENDWHILE.

WHILE l_date <= end.

  APPEND l_date TO itab.
  l_date = l_date + 7.
ENDWHILE.

Read only

Former Member
0 Likes
686

I thank you very much !

Ramiro

can you please tell me how can I replace

PARAMETERS: begin TYPE sy-datum,

end TYPE sy-datum,

through select-options fields instead parameters.

Additional what happens if end date is not selected ?

How can prevent an error ?

regards

sas

Read only

0 Likes
686

hi give some condition for the end value if the end is not defined..

DATA: l_date TYPE sy-datum,

l_day TYPE p,

itab TYPE TABLE OF sy-datum.

select-options: begin for sy-datum no intervals,

end for sy-datum no intervals.

data: day TYPE c.

l_date = begin.

if end is initial .

end = end + 20 .

endif .

WHILE l_date <= end.

CALL FUNCTION 'DAY_IN_WEEK'

EXPORTING

datum = l_date

IMPORTING

wotnr = l_day.

IF l_day = day.

APPEND l_date TO itab.

l_date = l_date + 7.

EXIT.

ENDIF.

l_date = l_date + 1.

ENDWHILE.

WHILE l_date <= end.

APPEND l_date TO itab.

l_date = l_date + 7.

ENDWHILE.

regards,

venkat

Read only

0 Likes
686

A few changes that should avoid an error, The write sentences are just there for me to debug.

The above suggestion seems ok if you want to use select-options, because of the nature of the problem I don't think that is possible to use ranges and multiple selections


PARAMETERS: begin TYPE sy-datum OBLIGATORY,
            end   TYPE sy-datum OBLIGATORY,
            day   TYPE c OBLIGATORY.

DATA: l_date TYPE sy-datum,
      l_day TYPE p,
      itab TYPE TABLE OF sy-datum.

AT SELECTION-SCREEN.
  IF end < begin.
    MESSAGE e001(00) WITH 'End must be greather than begin'.
  ENDIF.

  IF NOT day CO '1234567'.
    MESSAGE e001(00) WITH 'Day must be from 1 to 7'.
  ENDIF.


START-OF-SELECTION.
  l_date = begin.

  WHILE l_date <= end.

    CALL FUNCTION 'DAY_IN_WEEK'
         EXPORTING
              datum = l_date
         IMPORTING
              wotnr = l_day.
    IF l_day = day.
      APPEND l_date TO itab.
      WRITE / l_date.
      l_date = l_date + 7.
      EXIT.
    ENDIF.
    l_date = l_date + 1.
  ENDWHILE.

  WHILE l_date <= end.
    WRITE / l_date.
    APPEND l_date TO itab.
    l_date = l_date + 7.
  ENDWHILE.