09-11-2010 5:51 PM
Hello experts,
i´m looking for a function, that checks two date&time pairs for a collusion.
As example:
Pair 1 - Begin Date is 29.09.2010 time 10:00 End Date is 30.09.2010 time 22:00
Pair 2 - Begin Date is 30.09.2010 time 21:30 End Date is 01.10.2010 time 23:00
So the two pairs collide on 30.09.2010 at 21:30 for half an our.
Does anybody know a function which can handle this?
Thanks
Points guaranted
09-11-2010 7:18 PM
Hello Benjamin
I needed to do a FM to check this issue once.
FUNCTION zhrf030.
*"----------------------------------------------------------------------
*"*"Interface local:
*" IMPORTING
*" REFERENCE(I_REGEXIS) TYPE ZHRST035
*" REFERENCE(I_REGCRIA) TYPE ZHRST035
*" EXCEPTIONS
*" COLLISION_FOUND
*"----------------------------------------------------------------------
* Declaração das variáveis locais
DATA: vl_subrc TYPE sysubrc VALUE 1.
* Validação do Período do Novo Registro
IF ( ( i_regcria-begda GT i_regexis-endda ) OR
( i_regcria-endda LT i_regexis-begda ) OR
( ( i_regcria-begda EQ i_regexis-endda ) AND
( i_regcria-beguz GE i_regexis-enduz AND
( i_regexis-enduz IS NOT INITIAL AND i_regexis-enduz NE space )
) ) OR
( i_regcria-endda EQ i_regexis-begda ) AND
( i_regcria-enduz LE i_regexis-beguz AND
( i_regcria-enduz IS NOT INITIAL AND i_regcria-enduz NE space
)
) ) .
CLEAR vl_subrc.
ENDIF.
* Verifica se o registro está OK
IF vl_subrc IS NOT INITIAL.
RAISE collision_found.
ENDIF.
ENDFUNCTION.
Hope it helps
Kleber Santos
09-11-2010 7:18 PM
Hi Benjamin,
Are you just wanting to check if there is a collision or do you need to determine how long there is a collision?
Regards, Andy
09-11-2010 7:18 PM
Hello Benjamin
I needed to do a FM to check this issue once.
FUNCTION zhrf030.
*"----------------------------------------------------------------------
*"*"Interface local:
*" IMPORTING
*" REFERENCE(I_REGEXIS) TYPE ZHRST035
*" REFERENCE(I_REGCRIA) TYPE ZHRST035
*" EXCEPTIONS
*" COLLISION_FOUND
*"----------------------------------------------------------------------
* Declaração das variáveis locais
DATA: vl_subrc TYPE sysubrc VALUE 1.
* Validação do Período do Novo Registro
IF ( ( i_regcria-begda GT i_regexis-endda ) OR
( i_regcria-endda LT i_regexis-begda ) OR
( ( i_regcria-begda EQ i_regexis-endda ) AND
( i_regcria-beguz GE i_regexis-enduz AND
( i_regexis-enduz IS NOT INITIAL AND i_regexis-enduz NE space )
) ) OR
( i_regcria-endda EQ i_regexis-begda ) AND
( i_regcria-enduz LE i_regexis-beguz AND
( i_regcria-enduz IS NOT INITIAL AND i_regcria-enduz NE space
)
) ) .
CLEAR vl_subrc.
ENDIF.
* Verifica se o registro está OK
IF vl_subrc IS NOT INITIAL.
RAISE collision_found.
ENDIF.
ENDFUNCTION.
Hope it helps
Kleber Santos
09-11-2010 9:44 PM
Hi Benjamin,
there is no standard functionm to handle this, but you could create one:
to have it more transparent in easier to understand, convert all Date/time pairs to timestamp:
DATA:
lv_timestamp1 TYPE timestamp,
lv_timestamp2 TYPE timestamp,
lv_timestamp3 TYPE timestamp,
lv_timestamp4 TYPE timestamp,
CONVERT DATE iv_date1 TIME iv_time1 INTO TIME STAMP lv_timestamp1 TIME ZONE sy-zonlo.
CONVERT DATE iv_date2 TIME iv_time2 INTO TIME STAMP lv_timestamp2 TIME ZONE sy-zonlo.
CONVERT DATE iv_date3 TIME iv_time3 INTO TIME STAMP lv_timestamp3 TIME ZONE sy-zonlo.
CONVERT DATE iv_date4 TIME iv_time4 INTO TIME STAMP lv_timestamp4 TIME ZONE sy-zonlo.
if lv_timestamp1 > lv_timestamp2 or
lv_timestamp3 > lv_timestamp4.
* raise exception invalid date/time
endif.
CALL FUNCTION 'IGN_TIMESTAMP_DIFFERENCE'
EXPORTING
i_timestamp1 = lv_timestamp2
i_timestamp2 = lv_timestamp3
IMPORTING
E_DIFF_SECS = rv_n_of_seconds.
if rv_n_of_seconds < 0.
* * raise exception date/time range collision
endif.
something like this.
Regards,
Clemens