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

Date period

Former Member
0 Likes
1,207

Hi friends,

Pls advise.

I need to write the date period in month basis to my internal table fields as period_beg and period_end.

For ex: if the user gives date range 04.04.2007 to 28.09.2007

then in my internal table, i've to update it as....

period_beg period_end

04.04.2007 03.05.2007

04.05.2007 03.06.2007

04.06.2007 03.07.2007

04.07.2007 03.08.2007

04.08.2007 03.09.2007

04.09.2007 28.09.2007

Just reply me, how to fix this.

thanks & regards

sankar.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,172

What did the table look like before you updated it?

I can see that you put the first date of the range in the first date of the frist row and did basically the same for the second date of the last row.

What would be done if the user entered a date range in the middle of your existing table?

8 REPLIES 8
Read only

Former Member
0 Likes
1,172

hi

do this it will work

let the variable comtaining the date are

date_beg and date_end

now declare ur fiels as like this

data : begin of itab occurs 0,

.

.

.

period_beg(10) type c,

period_end(10) type c ,

.

.

.

end of itab.

now do this

itab-period_beg0(2) = date_beg6(2).

itab-period_beg+2(1) = '.'

itab-period_beg3(2) = date_beg4(2).

itab-period_beg+5(1) = '.'

itab-period_beg6(2) = date_beg0(4).

itab-period_end0(2) = date_end6(2).

itab-period_end+2(1) = '.'

itab-period_end3(2) = date_end4(2).

itab-period_end+5(1) = '.'

itab-period_end6(2) = date_end0(4).

Append Itab .

Cheers

Snehi Chouhan

Read only

Former Member
0 Likes
1,173

What did the table look like before you updated it?

I can see that you put the first date of the range in the first date of the frist row and did basically the same for the second date of the last row.

What would be done if the user entered a date range in the middle of your existing table?

Read only

0 Likes
1,172

Hi Paul,

I think u didn't got my req'mnet correctly....I want to update the internal table based on the date range given by the user.

Ex: If the user gives date range in sel screen.

Date: 09.04.2008 to 15.07.2008

then In my internal table, I've to update(after this) the date period as monthly basis,like in my internal tab

Period_beg Period_end

09.04.2008 08.05.2008

09.05.2008 08.06.2008

09.06.2008 08.07.2008

07.07.2008 29.07.2008

No point of asking that the user giving the range in middle...since i'll update my table based on the date given by the user.

Pls advise.

thanks & regards

sankar.

Read only

0 Likes
1,172

in ur qn:

09.04.2008 08.05.2008

09.05.2008 08.06.2008

09.06.2008 08.07.2008

07.07.2008 29.07.2008 "How 7.7 and 29.7

check the below code


REPORT a.

TABLES:mkpf.

DATA:BEGIN OF itab OCCURS 0,
      dat1(10) TYPE c,
      dat2(10) TYPE c,
     END OF itab.

DATA:startdate TYPE sy-datum.

SELECT-OPTIONS:so_dat FOR mkpf-budat NO-EXTENSION.

startdate = so_dat-low.

WHILE startdate LE so_dat-high.
  WRITE startdate TO itab-dat1.
  PERFORM get_changed_date CHANGING startdate.
  startdate = startdate - 1.
  WRITE startdate TO itab-dat2 .
  IF startdate >= so_dat-high.
    APPEND itab.
    EXIT.
  ENDIF.
  startdate = startdate + 1.
  APPEND itab.
ENDWHILE.

BREAK-POINT.
*&---------------------------------------------------------------------*
*&      Form  GET_CHANGED_DATE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_STARTDATE  text
*----------------------------------------------------------------------*
FORM get_changed_date  CHANGING p_startdate.

  CALL FUNCTION 'HR_HK_ADD_MONTH_TO_DATE'
    EXPORTING
      dmm_datin = p_startdate
      dmm_count = '1'
      dmm_oper  = '+'
      dmm_pos   = '*'
    IMPORTING
      dmm_daout = p_startdate
    EXCEPTIONS
      unknown   = 1
      OTHERS    = 2.

  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.



ENDFORM.                    " GET_CHANGED_DATE

Read only

0 Likes
1,172

Hi Keshu,

thanks for ur prompt reply and coding.

the FM what u sent ('HR_HK_ADD_MONTH_TO_DATE') is not available at my system and so I've taken a similar one of u as 'HR_JP_ADD_MONTH_TO_DATE' and got my result after did some few changes in code as per my req'ment.

Thanks & Regards

sankar.

Read only

Former Member
0 Likes
1,172

u can use this function to add days at the begin date. until you arrive at end date.

FM : NUMBER_OF_DAYS_PER_MONTH_GET

this FM export the number of days of a month of one year.

Read only

Former Member
0 Likes
1,172

Hi,

Something like this;

Put your 'from' date into the first row of your internal table.

e.g.

period_beg period_end

04.04.2007

Take your 'from' date and increase it by one month (checking for the change of year).

e.g. 04.04.2007 becomes 04.05.2007

If this date is less that your 'to' date subtract 1 from the date and put this into period_end

e.g

period_beg period_end

04.04.2007 03.05.2007

Now, add one date to this date and put this in the period_beg row, then add one month to this date. If this date is less that your 'to' date subtract 1 from the date and put this into period_end.

e.g

period_beg period_end

04.04.2007 03.05.2007

04.05.2007 03.06.2007

Repeat this until the addition of one month takes you beyond the from date, when it does, put the from date into your internal table.

Regards,

Nick

Read only

former_member435013
Active Participant
0 Likes
1,172

Hi,

check this code perhaps it is a solution for you:

REPORT ztest.

PARAMETERS:

beg LIKE sy-datum,

end LIKE sy-datum,

new_val TYPE i.

DATA:

BEGIN OF it OCCURS 0,

beg LIKE sy-datum,

end LIKE sy-datum,

val TYPE i,

END OF it,

ind TYPE i.

it-beg = '00000000'.

it-end = '20071231'.

it-val = 1.

APPEND it.

it-beg = '20080101'.

it-end = '20080131'.

it-val = 1.

APPEND it.

it-beg = '20080201'.

it-end = '20080229'.

it-val = 1.

APPEND it.

it-beg = '20080301'.

it-end = '20080331'.

it-val = 1.

APPEND it.

it-beg = '20080401'.

it-end = '99991231'.

it-val = 1.

APPEND it.

ind = 1.

DO.

READ TABLE it INDEX ind.

IF sy-subrc IS NOT INITIAL.

EXIT.

ENDIF.

IF ( ( beg >= it-beg ) AND ( beg <= it-end ) ) OR

( ( end >= it-beg ) AND ( end <= it-end ) ).

it-val = new_val.

MODIFY it INDEX ind.

ENDIF.

ind = ind + 1.

ENDDO.

LOOP AT it.

WRITE: / it-beg, it-end, it-val.

ENDLOOP.

Edited by: Walter Habich on May 21, 2008 3:04 PM