Find overlapping dates in transportation lanes
I need to locate transportation lane records where a Receiver location is assigned to multiple Source locations. The internal table contains the fields: material, source location, Receiver location, 'From' date, and 'To' date.
Material Source Receiver From date To date
12345 XX01 XX02 1/1/1999 5/31/2006
12345 XX03 XX02 5/1/2006 12/31/9999
I need to flag that material 12345 is assigned to two Source locations for the 5/1/2006-5/31/2006 period. Does anyone have any ideas on an efficient way of finding these situations?
Thanks and best regards,
Neil Woodruff replied
If your table is declared something like below I think my code will be pretty efficient. If the table is not sorted and has a lot of entries the code will be slow:
data itab type sorted table of xyz with non-unique key
material source receiver.
<prime> type xyz,
<duplicate> type xyz.
loop at itab assigning <prime>.
loop at itab assigning <duplicate>
where material = <prime>-material
and source = <prime>-source
and receiver = <prime>-receiver.
if <duplicate>-from between <prime>-from
or <duplicate>-to between <prime>-from and <prime>-to.