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 calculation

Former Member
0 Likes
470

Hi ABAP'ers,

I am having an internal table with the following data.I need to recalculate the valid from and valid to date as follows.

| Material|Code|Valid from|Valid to |Done

-


1001472

C1

04/01/2002

09/30/2003

1001472

C1

10/01/2003

12/31/9999

1001472

C3

01/01/2007

12/31/9999

1001472

C3

10/01/2003

12/31/2006

| 1001472 |C4 |08/01/2000|12/31/9999|X

1001472

C5

03/01/2002

12/31/9999

For each material.

PASS 1.

1.Select the least date from the from date values and mark the variable done as X. This is done because in the next steps we dont have to conisder this record,since it has been already visited.

2.Take the corresponding valid to date and compare it with the from date values of the other records whose priority is less than that(C1 having the highest priority,C2,C3...) and select the least one from that and minus one day from that to date and put it as the to date of that record.

PASS2.

1.Select the valid to date just calculated and compare it with the other from dates greater than that an select the least one(which one will be the next from date) and mark the variable done as X.

2.Then calculate the Valid to date of that by using the logic of Step 2 in PASS1.

PASS 3.

Continue the process till u can't find the from date anymore.i.e there is no higher priority than this and whose date is more than the previous ones valid to date.

<b>

Example.</b>

After PASS1

Material Valid from Valid to

1001472 08/01/2000 03/31/2002

After PASS2

04/01/2002 09/29/3003

-


etc

<b>Explanation</b>

First we are taking the least date from that valid frm dates which is 08/01/2000 and markd that record's done as X,then we are taking the corresponding valid to date(12/31/9999) and compare it with the valid from dates of allthe others whose done is not equal to X an having higher priority than this record(C1) and find the least of all which is 04/01/2002,we minus one day from this and put 03/31/2002 as the valid to date.

Next to find the next valid from date we use last valid to date(03/31/2002) and compare it other valid from date and find the least of all and also greater than this.we found the first one 04/01/2002,mark this records done variable as X and calculate the valid to of this by comparing it with the other from dates whose done is not equal to X and also having more priority than this and find the least of all.We found 09/30/2003.Minus one day from this and put 09/29/2003 as valid to date.

Continue the process untilwe cant find the from to date anymore.

Can any one please provide me the logic for this.

1 REPLY 1
Read only

Former Member
0 Likes
388

USE THIS CODE

sort i_tab by frmdt.

loop at i_tab.

clear: tmpdt, idx.

if sy-tabix = 1.

else.

tmpdt = i_tab-frmdt - 1.

idx = sy-tabix - 1.

read table i_tab index idx.

i_tab-todt = tmpdt.

modify i_tab index idx transporting todt.

endif.

endloop.