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

working with internal table dates and getting weekstart and enddates

Former Member
0 Likes
932

Hi,

I am working with dates in an internal table.

I need to populate entries (rows) for each week.

if date difference in between 2 existing dates is 1 then there should be one row.

if date differeence in between 2 existing dates is 2 then there should be 2 rows.

also what i need is week start and end date for each row.

I was able to get number of times but how do i get the dates info.

week start date & week end date.

REPORT x.
TYPES: BEGIN OF t_itab,
matnr TYPE mara-matnr,
date1 TYPE sy-datum,
date2 TYPE sy-datum,
weeks(2) TYPE c,
wstart TYPE sy-datum,
wenddt TYPE sy-datum,

END OF t_itab.

DATA: v_days TYPE pea_scrdd.

DATA: it_itab TYPE STANDARD TABLE OF t_itab.
DATA: wa_itab TYPE t_itab.

DATA: it_final TYPE STANDARD TABLE OF t_itab.
DATA: wa_final TYPE t_itab.

wa_itab-matnr = '100'.
wa_itab-date1 = sy-datum .
wa_itab-date2 = sy-datum + 4.
APPEND wa_itab TO it_itab.

wa_itab-matnr = '100'.
wa_itab-date1 = sy-datum .
wa_itab-date2 = sy-datum + 7.
APPEND wa_itab TO it_itab.


wa_itab-matnr = '100'.
wa_itab-date1 = sy-datum .
wa_itab-date2 = sy-datum + 14.
APPEND wa_itab TO it_itab.

wa_itab-matnr = '100'.
wa_itab-date1 = sy-datum .
wa_itab-date2 = sy-datum + 21.
APPEND wa_itab TO it_itab.

wa_itab-matnr = '100'.
wa_itab-date1 = sy-datum .
wa_itab-date2 = sy-datum + 31.
APPEND wa_itab TO it_itab.

WRITE:/10 'Material' , 20 'Date1' , 40 'Date2', 55 'No.of Weeks', 70 'Week Start' , 90 'Week End'.
ULINE.

LOOP AT it_itab INTO wa_itab.

  CLEAR: v_days.
  v_days = wa_itab-date2 - wa_itab-date1.
  IF v_days > 7 .
    wa_itab-weeks = v_days / 7.
  ELSE.
    wa_itab-weeks = '1'.

  ENDIF.
  DO wa_itab-weeks TIMES.
    APPEND wa_itab TO it_final.
  ENDDO.

ENDLOOP.

LOOP AT it_final INTO wa_final.

  wa_final-wstart =  wa_itab-date1 .

  WRITE:/10 wa_final-matnr, 20 wa_final-date1, 40 wa_final-date2 , 60 wa_final-weeks, 70 wa_final-wstart, 90 wa_final-wenddt.

ENDLOOP.

rgds

Vara

Edited by: Vara K on Aug 24, 2009 8:47 PM

Edited by: Vara K on Aug 24, 2009 8:48 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
812

Hi,

if date difference in between 2 existing dates is 1 week then there should be one row.

if date differeence in between 2 existing dates is 2 weeks then there should be 2 rows.

Material   Date1                   date2      Weeks      start date            End-date
100       08/24/2009          08/28/2009          1         08/24/2009          08/30/2009
100       08/24/2009          08/31/2009          1         08/24/2009          08/30/2009
100       08/24/2009          09/07/2009          2         08/24/2009          08/30/2009
100       08/24/2009          09/07/2009          2         08/31/2009          09/07/2009

rgds

Vara

Hi,

I am working with dates in an internal table.

I need to populate entries (rows) for each week.

if date difference in between 2 existing dates is 1 then there should be one row.

if date differeence in between 2 existing dates is 2 then there should be 2 rows.

also what i need is week start and end date for each row.

I was able to get number of times but how do i get the dates info.

week start date & week end date.

REPORT x.
TYPES: BEGIN OF t_itab,
matnr TYPE mara-matnr,
date1 TYPE sy-datum,
date2 TYPE sy-datum,
weeks(2) TYPE c,
wstart TYPE sy-datum,
wenddt TYPE sy-datum,

END OF t_itab.

DATA: v_days TYPE pea_scrdd.

DATA: it_itab TYPE STANDARD TABLE OF t_itab.
DATA: wa_itab TYPE t_itab.

DATA: it_final TYPE STANDARD TABLE OF t_itab.
DATA: wa_final TYPE t_itab.

wa_itab-matnr = '100'.
wa_itab-date1 = sy-datum .
wa_itab-date2 = sy-datum + 4.
APPEND wa_itab TO it_itab.

wa_itab-matnr = '100'.
wa_itab-date1 = sy-datum .
wa_itab-date2 = sy-datum + 7.
APPEND wa_itab TO it_itab.


wa_itab-matnr = '100'.
wa_itab-date1 = sy-datum .
wa_itab-date2 = sy-datum + 14.
APPEND wa_itab TO it_itab.

wa_itab-matnr = '100'.
wa_itab-date1 = sy-datum .
wa_itab-date2 = sy-datum + 21.
APPEND wa_itab TO it_itab.

wa_itab-matnr = '100'.
wa_itab-date1 = sy-datum .
wa_itab-date2 = sy-datum + 31.
APPEND wa_itab TO it_itab.

WRITE:/10 'Material' , 20 'Date1' , 40 'Date2', 55 'No.of Weeks', 70 'Week Start' , 90 'Week End'.
ULINE.

LOOP AT it_itab INTO wa_itab.

  CLEAR: v_days.
  v_days = wa_itab-date2 - wa_itab-date1.
  IF v_days > 7 .
    wa_itab-weeks = v_days / 7.
  ELSE.
    wa_itab-weeks = '1'.

  ENDIF.
  DO wa_itab-weeks TIMES.
    APPEND wa_itab TO it_final.
  ENDDO.

ENDLOOP.

LOOP AT it_final INTO wa_final.

  wa_final-wstart =  wa_itab-date1 .

  WRITE:/10 wa_final-matnr, 20 wa_final-date1, 40 wa_final-date2 , 60 wa_final-weeks, 70 wa_final-wstart, 90 wa_final-wenddt.

ENDLOOP.

rgds

Vara

Edited by: Vara K on Aug 24, 2009 8:47 PM

Edited by: Vara K on Aug 24, 2009 8:48 PM

4 REPLIES 4
Read only

former_member156446
Active Contributor
0 Likes
812

[Program to get date list of a year's particular months' particular week |http://wiki.sdn.sap.com/wiki/x/AwATBQ]

DATE_IN_FUTURE - will give the future date..

RP_CALC_DATE_IN_INTERNAL- can add 7 days for a date...

Read only

Former Member
0 Likes
813

Hi,

if date difference in between 2 existing dates is 1 week then there should be one row.

if date differeence in between 2 existing dates is 2 weeks then there should be 2 rows.

Material   Date1                   date2      Weeks      start date            End-date
100       08/24/2009          08/28/2009          1         08/24/2009          08/30/2009
100       08/24/2009          08/31/2009          1         08/24/2009          08/30/2009
100       08/24/2009          09/07/2009          2         08/24/2009          08/30/2009
100       08/24/2009          09/07/2009          2         08/31/2009          09/07/2009

rgds

Vara

Read only

0 Likes
812

/SDF/CMO_DATETIME_DIFFERENCE - Calculates difference between two dates/timestamps.

Use[ this WIKI|http://wiki.sdn.sap.com/wiki/x/moBMB] from Avinash which will surely solve ur problem by using combination of functions.

Read only

Jelena_Perfiljeva
Active Contributor
0 Likes
812

Your program determines how many 7 day periods are there between the dates. It's not necessarily "weeks". E.g. there are only 3 days from Friday to Monday but they're on different weeks.

Try FM DATE_COMPUTE_DAY. You need to determine what day is the first date and what's the start/end date of that week. From there you can just keep adding 7. Make some provisions for when the are no dates at all within certain weeks.