‎2008 Nov 09 5:15 AM
Hi,
I have an internal table where we have x number of records. For example if we have 3 records.
I need to compare if the first records end date and 2nd records start date are same. if they are same combine them to one. now check if this records end date is same as the start date of 3rd record. if this is same combine them. if they are not same leave them as they are. if the consecutive records have same start and end dates combine else leave them.
my question is how will i compare the first records start date and second records end date.
I appreciate the help.
Thanks.
‎2008 Nov 10 3:32 AM
Hi,
Please try the following sample:
types: begin of t_stru,
start_date type SYDATS,
end_date type SYDATS,
end of t_stru.
data: itab type standard table of t_stru.
Data: wa1 like line of itab,
wa like line of itab.
Data: l_tabix like sy-tabix,
l_tabix1 like sy-tabix.
wa-start_date = '20081001'.
wa-end_date = '20081002'.
append wa to itab.
wa-start_date = '20081002'.
wa-end_date = '20081003'.
append wa to itab.
wa-start_date = '20081005'.
wa-end_date = '20081007'.
append wa to itab.
wa-start_date = '20081003'.
wa-end_date = '20081004'.
append wa to itab.
clear wa.
Sort itab by start_date end_date.
Loop at itab into wa1.
l_tabix = sy-tabix .
Clear wa.
l_tabix1 = l_tabix + 1.
loop at itab into wa from l_tabix1.
if wa1-end_date = wa-start_date.
wa1-end_date = wa-end_date .
modify itab from wa1 index l_tabix transporting end_date.
delete itab index l_tabix1.
else.
continue.
endif.
endloop.
Endloop.
clear: wa, wa1.
loop at itab into wa.
write: / wa-start_date ,'and ', wa-end_date.
endloop.Hope it can help you.
Regards,
Chris Gu
Edited by: Gu Chris on Nov 10, 2008 4:32 AM
‎2008 Nov 09 5:25 AM
Hi,
Data: wa like line of itab.
Data; l_tabix like sy-tabix.
Sort itab with key start_date, end_date.
Loop at itab.
l_tabix = sy-tabix.
Clear wa.
Read table itab into wa index l_tabix + 1.
if itab-end_date = wa-start_date.
***Combine the two records.
endif.
Endloop.
‎2008 Nov 10 3:32 AM
Hi,
Please try the following sample:
types: begin of t_stru,
start_date type SYDATS,
end_date type SYDATS,
end of t_stru.
data: itab type standard table of t_stru.
Data: wa1 like line of itab,
wa like line of itab.
Data: l_tabix like sy-tabix,
l_tabix1 like sy-tabix.
wa-start_date = '20081001'.
wa-end_date = '20081002'.
append wa to itab.
wa-start_date = '20081002'.
wa-end_date = '20081003'.
append wa to itab.
wa-start_date = '20081005'.
wa-end_date = '20081007'.
append wa to itab.
wa-start_date = '20081003'.
wa-end_date = '20081004'.
append wa to itab.
clear wa.
Sort itab by start_date end_date.
Loop at itab into wa1.
l_tabix = sy-tabix .
Clear wa.
l_tabix1 = l_tabix + 1.
loop at itab into wa from l_tabix1.
if wa1-end_date = wa-start_date.
wa1-end_date = wa-end_date .
modify itab from wa1 index l_tabix transporting end_date.
delete itab index l_tabix1.
else.
continue.
endif.
endloop.
Endloop.
clear: wa, wa1.
loop at itab into wa.
write: / wa-start_date ,'and ', wa-end_date.
endloop.Hope it can help you.
Regards,
Chris Gu
Edited by: Gu Chris on Nov 10, 2008 4:32 AM
‎2008 Nov 10 3:47 AM
Hi Oscar,
data: wa_table type t_itab.
loop at itab.
wa_itab = itab.
if itab-condition = wa_itab-condition.
it_final-total = it_final-total + wa_tab-total.
else.
append it_final.
endif.
endloop.
Thanks,
Chidanand