SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Using Week Day



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Programming Techniques | Приемы программирования -> Calendar
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Sat Sep 15, 2007 9:26 pm    Post subject: Using Week Day Reply with quote

Code:
report z.
include <LIST>.
*======================================================================*
selection-screen:  begin of line,
                   comment (5) ps_cycle.
parameters:        p_cycle(2) type n,
                   p_from like sy-datum.
selection-screen:  position 30,
                   comment (4) ps_from.
parameter          p_today like sy-datum.
selection-screen   end of line.
*----------------------------------------------------------------------*
data: w_delta   type i,
      w_start   like sy-datum,
      w_start_d like sy-datum,
      w_day     like sy-datum,
      w_end_d   like sy-datum,
      ws_month(20) type c,
      it_day(10)   type c occurs 0 with header line,
      begin of it_days occurs 0,
        day  like sy-datum,
        flag like icon-id,
      end of it_days.
*----------------------------------------------------------------------*
define get_day_name.
  select single varvalue from ttdtg into it_day
         where spras = sy-langu and varname = &1.
  if sy-subrc <> 0.
    select single varvalue from ttdtg into it_day
           where spras = 'EN' and varname = &1.
    if sy-subrc <> 0.
      select varvalue from ttdtg into it_day up to 1 rows
             where varname = &1.
      endselect.
      if sy-subrc <> 0.
        it_day = &2.
      endif.
    endif.
  endif.
  append it_day.
end-of-definition.

*======================================================================*
INITIALIZATION.
*----------------------------------------------------------------------*
  ps_cycle = 'Cycle:'.
  ps_from  = 'From'.
  p_cycle = 28.
  p_from  = '20031015'.
  p_today = sy-datum.
  get_day_name '%%SAPSCRIPT_DDD_01' 'Mon'.
  get_day_name '%%SAPSCRIPT_DDD_02' 'Tue'.
  get_day_name '%%SAPSCRIPT_DDD_03' 'Wen'.
  get_day_name '%%SAPSCRIPT_DDD_04' 'Thu'.
  get_day_name '%%SAPSCRIPT_DDD_05' 'Fri'.
  get_day_name '%%SAPSCRIPT_DDD_06' 'Sat'.
  get_day_name '%%SAPSCRIPT_DDD_07' 'Sun'.

*======================================================================*
AT SELECTION-SCREEN.
*----------------------------------------------------------------------*
  if p_today < p_from.
    message e899(mm) with 'Select from > cycle'.
  endif.

*======================================================================*
AT SELECTION-SCREEN OUTPUT.
*----------------------------------------------------------------------*
  loop at screen.
    if screen-name = 'P_CYCLE' or screen-name = 'P_FROM'.
      screen-input = 0.
      modify screen.
    endif.
  endloop.

*======================================================================*
START-OF-SELECTION.
*----------------------------------------------------------------------*
*###########################
  check sy-uname = 'VNDOVV'.
*###########################
  w_delta = ( p_today - p_from ) mod p_cycle.
  w_start = p_today - w_delta.
  CALL FUNCTION 'DATE_GET_FIRST_DAY_OF_WEEK'
    EXPORTING
      DATE_IN            = p_today
    IMPORTING
      DATE_OUT           = w_start_d
    EXCEPTIONS
      DATE_INVALID       = 1
      OTHERS             = 2.
  if sy-subrc <> 0.
    message e899(mm) with 'Cannot calculate Monday'.
  endif.
  if w_start < w_start_d.  w_day = w_start.
  else.                    w_day = w_start_d.
  endif.
  w_end_d = w_start_d + 27.

  do.
    it_days-day = w_day.
    if w_day >= w_start.
      w_delta = ( w_day - w_start ) mod p_cycle.
      if w_delta < 4.
        it_days-flag = ICON_MESSAGE_CRITICAL.
      elseif w_delta >= 4 and w_delta < 9.
        it_days-flag = ICON_GREEN_LIGHT.
      elseif w_delta >= 9 and w_delta < 12.
        it_days-flag = ICON_YELLOW_LIGHT.
      elseif w_delta >= 12 and w_delta < 16.
        it_days-flag = ICON_RED_LIGHT.
      elseif w_delta >= 16 and w_delta < 19.
        it_days-flag = ICON_YELLOW_LIGHT.
      elseif w_delta >= 19.
        it_days-flag = ICON_GREEN_LIGHT.
      endif.
    endif.
    append it_days.
    clear it_days.
    add 1 to w_day.
    if w_day > w_end_d.
      exit.
    endif.
  enddo.

*======================================================================*
END-OF-SELECTION.
*----------------------------------------------------------------------*
  constants: c_cell   type i value 10,
             c_varmon like ttdtg-varname value '%%SAPSCRIPT_MMMM_'.
  data: w_len      type i,
        w_len_m    type i,
        w_len_d    type i,
        w_pos      type i,
        w_pos2     type i,
        w____(200) type c,
        w_weekday  type i,
        w_varmon   like ttdtg-varname.

  w_len = c_cell * 7 + 1.
  w_len_m = w_len - 4.
  w_len_d = c_cell - 3.
  do w_len times.
    concatenate w____ sy-uline(1) into w____.
  enddo.

  w_pos = 1.
  format intensified off.
  write at /(w_len) w____ color col_heading.
  loop at it_day.
    if sy-tabix = 1.
      write: at /w_pos sy-vline, at (w_len_d) it_day color col_heading.
    else.
      if sy-tabix = 6.
        format intensified on.
      endif.
      write: at  w_pos sy-vline, at (w_len_d) it_day color col_heading.
    endif.
    add c_cell to w_pos.
  endloop.
  format intensified off.
  write: at (w_len) sy-vline, at /(w_len) w____ color col_heading.

  sort it_days by day ascending.
  w_weekday = 1.
  loop at it_days.
*  ws_month
    if it_days-day >= w_start_d.
      if ws_month is initial or it_days-day+6(2) = '01'.
        if not ws_month is initial.
          w_pos2 = ( w_weekday - 1 ) * c_cell + 1.
          if w_pos2 <> w_len.
            write at w_pos2 sy-vline.
          endif.
          write: at w_len sy-vline, at /(w_len) w____.
        endif.
        concatenate c_varmon it_days-day+4(2) into w_varmon.
        select single varvalue from ttdtg into ws_month
               where spras = sy-langu and varname = w_varmon.
        if sy-subrc <> 0.
          select single varvalue from ttdtg into ws_month
                 where spras = 'EN' and varname = w_varmon.
          if sy-subrc <> 0.
            select varvalue from ttdtg into ws_month up to 1 rows
                   where varname = w_varmon.
            endselect.
            if sy-subrc <> 0.
              ws_month = it_days-day+4(2).
            endif.
          endif.
        endif.
        concatenate ws_month it_days-day(4) into ws_month
                    separated by space.
        write: / sy-vline, at (w_len_m) ws_month color col_key,
                 at w_len sy-vline, at /(w_len) w____ color col_key.
      endif.
      w_pos = ( w_weekday - 1 ) * c_cell + 1.
      if w_weekday = 6.
        format intensified on.
      endif.
      if w_pos = 1.
        write: at /w_pos sy-vline.
      elseif it_days-day+6(2) = '01'.
        write: / sy-vline, at w_pos sy-vline.
      else.
        write: at  w_pos sy-vline.
      endif.
      if it_days-day = sy-datum.
        format color col_total on.
        write: it_days-day+6(2), it_days-flag as icon.
        format color col_total off.
      else.
        write: it_days-day+6(2), it_days-flag as icon.
      endif.
      add 1 to w_weekday.
      if w_weekday = 8.
        write at w_len sy-vline.
        format intensified off.
        write at /(w_len) w____.
        w_weekday = 1.
      endif.
    endif.
  endloop.
*--- End Of Code ---
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Programming Techniques | Приемы программирования -> Calendar All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.