2008 Dec 08 4:16 AM
Hi All,
I have an internal table.
two of the fields are
FROM TO
7.7.2008 8.7.2008
7.7.2008 7.7.2008
9.7.2008 10.7.2008 is to be deleted(not overlapping with other dates)
8.7.2008 8.7.2008
11.7.2008 13.7.2008
12.7.2008 14.7.2008
Now I have to delete the records whose dates do not overlap.
i.e each and every record has to be compared with each each and every other record.
As per the above data, my final internal table should have
FROM TO
7.7.2008 8.7.2008
7.7.2008 7.7.2008
8.7.2008 8.7.2008
11.7.2008 13.7.2008
12.7.2008 14.7.2008
How do you achieve it?
Thanks,
Sandeep.
2008 Dec 08 6:13 AM
Hello Sandeep
Assuming that there are no duplicated records in your dates itab then sample report ZUS_SDN_CHECK_DATE_RANGES should fulfil your requirement:
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_CHECK_DATE_RANGES
*&
*&---------------------------------------------------------------------*
*& Thread: to delete records whose dates are not overlapping
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1157341"></a>
*&---------------------------------------------------------------------*
REPORT zus_sdn_check_date_ranges.
TYPES: BEGIN OF ty_s_data.
TYPES: from TYPE begda.
TYPES: to TYPE endda.
TYPES: END OF ty_s_data.
TYPES: ty_t_data TYPE STANDARD TABLE OF ty_s_data
WITH DEFAULT KEY.
DATA: gt_data TYPE ty_t_data,
gs_data TYPE ty_s_data,
gd_idx TYPE i.
DEFINE mac_add_date.
gs_data-from = &1.
gs_data-to = &2.
append gs_data to gt_data.
END-OF-DEFINITION.
DEFINE mac_write_list.
loop at &1 into gs_data.
write:/ 'Date=', gs_data-from, gs_data-to.
endloop.
skip.
END-OF-DEFINITION.
START-OF-SELECTION.
** 7.7.2008 8.7.2008
** 7.7.2008 7.7.2008
** 9.7.2008 10.7.2008 is to be deleted(not overlapping
** with other dates)
** 8.7.2008 8.7.2008
** 11.7.2008 13.7.2008
** 12.7.2008 14.7.2008
REFRESH: gt_data.
mac_add_date: '20080707' '20080708',
'20080707' '20080707',
'20080709' '20080710',
'20080708' '20080708',
'20080711' '20080713',
'20080712' '20080714'.
mac_write_list gt_data.
BREAK-POINT.
LOOP AT gt_data INTO gs_data.
gd_idx = syst-tabix.
LOOP AT gt_data TRANSPORTING NO FIELDS
WHERE NOT ( from = gs_data-from AND to = gs_data-to )
AND ( ( from BETWEEN gs_data-from AND gs_data-to )
OR
( to BETWEEN gs_data-from AND gs_data-to ) ).
EXIT.
ENDLOOP.
IF ( sy-subrc NE 0 ).
DELETE gt_data INDEX gd_idx.
ENDIF.
ENDLOOP.
mac_write_list gt_data.
END-OF-SELECTION.
Regards
Uwe
Hi All,
I have an internal table.
two of the fields are
FROM TO
7.7.2008 8.7.2008
7.7.2008 7.7.2008
9.7.2008 10.7.2008 is to be deleted(not overlapping with other dates)
8.7.2008 8.7.2008
11.7.2008 13.7.2008
12.7.2008 14.7.2008
Now I have to delete the records whose dates do not overlap.
i.e each and every record has to be compared with each each and every other record.
As per the above data, my final internal table should have
FROM TO
7.7.2008 8.7.2008
7.7.2008 7.7.2008
8.7.2008 8.7.2008
11.7.2008 13.7.2008
12.7.2008 14.7.2008
How do you achieve it?
Thanks,
Sandeep.
2008 Dec 08 4:21 AM
loop at itab into watab.
read table itab into watab1 with key from >= watab-from
to <= watab-to.
if sy-subrc ne 0.
delete watab from itab.
endif.
endloop.
2008 Dec 08 5:28 AM
Hi Prashant,
Will this logic compare all the records with all the other records?
i.e if I have 10 records, each record should be checked with all the other 9 records.
Thanks,
Sandeep.
2008 Dec 08 5:32 AM
Yes sandeep it will scan all the records.
Best regards,
Prashant
2008 Dec 08 5:32 AM
2008 Dec 08 6:04 AM
Hi,
so i think
11.7.2008 13.7.2008
12.7.2008 14.7.2008, these two should alos be deleted!!
try to do like this:
data:temp_tab type......."Declare a temp internal table which will hold the FROM and TO dates with fields "DATE" and a "FLAG" to hold whether its an overlapping entry or not.
SORT i_tab with from to.
loop at I_tab into wa_tab.
if temp_tab is initial.
move wa_iab-from to wa_temp-date.
append wa_temp to temp_tab.
move wa_iab-to to wa_temp-date.
append wa_temp to temp_tab.
else.
read table temp_tab into wa_temp with key date = wa_itab-from.
if sy-subrc = 0.
wa_temp-flag = 'X'
modify table temp_tab from wa_temp transporting flag.
else.
move wa_iab-from to wa_temp-date.
append wa_temp to temp_tab.
endif.
read table temp_tab into wa_temp with key date = wa_itab-to.
if sy-subrc = 0.
wa_temp-flag = 'X'
modify table temp_tab from wa_temp transporting flag.
else.
move wa_iab-to to wa_temp-date.
append wa_temp to temp_tab.
endif.
endif.
endloop.
loop at temp_tab into wa_temp.
if wa_temp-flag is initial.
==>delete the entries from i_tab where FLAG is initial.
endif.
endloop.
Edited by: Neha Shukla on Dec 8, 2008 11:35 AM
2008 Dec 08 6:13 AM
Hello Sandeep
Assuming that there are no duplicated records in your dates itab then sample report ZUS_SDN_CHECK_DATE_RANGES should fulfil your requirement:
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_CHECK_DATE_RANGES
*&
*&---------------------------------------------------------------------*
*& Thread: to delete records whose dates are not overlapping
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1157341"></a>
*&---------------------------------------------------------------------*
REPORT zus_sdn_check_date_ranges.
TYPES: BEGIN OF ty_s_data.
TYPES: from TYPE begda.
TYPES: to TYPE endda.
TYPES: END OF ty_s_data.
TYPES: ty_t_data TYPE STANDARD TABLE OF ty_s_data
WITH DEFAULT KEY.
DATA: gt_data TYPE ty_t_data,
gs_data TYPE ty_s_data,
gd_idx TYPE i.
DEFINE mac_add_date.
gs_data-from = &1.
gs_data-to = &2.
append gs_data to gt_data.
END-OF-DEFINITION.
DEFINE mac_write_list.
loop at &1 into gs_data.
write:/ 'Date=', gs_data-from, gs_data-to.
endloop.
skip.
END-OF-DEFINITION.
START-OF-SELECTION.
** 7.7.2008 8.7.2008
** 7.7.2008 7.7.2008
** 9.7.2008 10.7.2008 is to be deleted(not overlapping
** with other dates)
** 8.7.2008 8.7.2008
** 11.7.2008 13.7.2008
** 12.7.2008 14.7.2008
REFRESH: gt_data.
mac_add_date: '20080707' '20080708',
'20080707' '20080707',
'20080709' '20080710',
'20080708' '20080708',
'20080711' '20080713',
'20080712' '20080714'.
mac_write_list gt_data.
BREAK-POINT.
LOOP AT gt_data INTO gs_data.
gd_idx = syst-tabix.
LOOP AT gt_data TRANSPORTING NO FIELDS
WHERE NOT ( from = gs_data-from AND to = gs_data-to )
AND ( ( from BETWEEN gs_data-from AND gs_data-to )
OR
( to BETWEEN gs_data-from AND gs_data-to ) ).
EXIT.
ENDLOOP.
IF ( sy-subrc NE 0 ).
DELETE gt_data INDEX gd_idx.
ENDIF.
ENDLOOP.
mac_write_list gt_data.
END-OF-SELECTION.
Regards
Uwe
2008 Dec 08 7:13 AM
Hi Uwe Schieferstein,
Thank you soo much for your code.
Its working fine.
Regards,
Sandeep.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |