It is going to be complicated since there is no limit to the no. of such time pairs which can exist. Here is a gist of the solution.
You will have to first create daily time types for ZMS1, ZME1 , ZMS2, ZME2....ZMS9, ZME9 where S is for start time and E for end time.
Then write a PCR to pass the values of start and end time to these time types for processing type M.
*
****
OUTTPVTYPE
*
COLOP*
M
HRS=DZMS1
HRS?0
<
COLOP*
=
HRS=PBEG
ADDDBZMS1Z
HRS=PEND
ADDDBZME1Z
>
HRS=DZMS2
HRS?0
<
repeat the above.
Basically, we are trying to record the start time and end time of each time pair with processing type M.
The next step is to find out which time pairs need to be merged.
You can write a simple PCR to compare the values by calling multiple sub PCRs using PCY operation.
And then under each sub PCR, you write the below logic.
HRS=DZMS2
HRS-DZME1
HRS?0
=
HRS=1
ADDDBZM12 (merge 1st and 2nd time pair)...Similarly create for ZM23, ZM34, ZM45, ZM56 and so on.
*
after the above step, you will have to write another PCR to find the value of these time types ZM12 and so on. If their value is greater than 1, it means that time pairs need to be merged.
You will write a PCR where you will match the PBEG of the time pair with ZMS1. If it matches, it implies this is the time pair whose end time needs to be changed. You change the end time by taking value from time type ZME2.
Next you will have to remove the time pair with timings ZMS2 and ZME2. You can write another PCR where the timings match the time types and block them from going further forward.
You will have to repeat this logic for 9 such pairs.
We are assuming there can be 9 such pairs.
Regards,
Vivek Barnwal