03-08-2013 3:06 PM
I would like to know how to calculate a Date/Time Intervall.
There will be two selection options. In the first one you can enter a range of date. In the other one have the ability to enter the corresponding time.
Now i need an algorithm which calculates the timinvervall.
I have variables with date and time as timestamp and also separatet as date and time.
Now I would like to list the dates in an alv grid.
An Example:
Selection dates:
Date: 08.03.2013 to 08.03.2013
Time: 09:00 to 12:00
The format of the output I am expecting:
09:00 10:00
10:00 - 11:00
11:00 - 12:00
The Intervall is exact one Hour.
Does anyone know how to code this in abap?
Coding:
*********************************************************************
" Selektion screen
SELECTION-SCREEN FUNCTION KEY 1.
SELECTION-SCREEN BEGIN OF BLOCK a100 WITH FRAME TITLE text-100.
PARAMETERS p_lgtyp LIKE z9labpo-lgtyp DEFAULT 'ATL'.
PARAMETERS p_status LIKE z9labpo-status DEFAULT '80'.
SELECT-OPTIONS s_datum FOR z9labpo-datum.
SELECT-OPTIONS s_zeit FOR sy-uzeit.
SELECTION-SCREEN END OF BLOCK a100.
**********************************************************************
Form: read_data:
lv_datum_low = s_datum-low.
lv_zeit_low = s_zeit-low.
CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
EXPORTING
date = lv_datum_low
EXCEPTIONS
plausibility_check_failed = 1.
"convert to timestamp
"datum = TT.MM.JJJJ -> JJJJMMTT
SPLIT lv_datum_low AT '.' INTO lv_tag lv_monat lv_jahr.
CONCATENATE lv_jahr lv_monat lv_tag INTO lv_datum_low.
SPLIT lv_datum_high AT '.' INTO lv_tag lv_monat lv_jahr.
CONCATENATE lv_jahr lv_monat lv_tag INTO lv_datum_high.
"JJJJMMTTHHMMSS
CONCATENATE lv_datum_low lv_zeit_low INTO lv_aezt_low.
CONCATENATE lv_datum_high lv_zeit_high INTO lv_aezt_high.
-> fill alv structure
"todo calculate time intervall (one hour)
"here is the problem!
DO.
ls_data-datum = lv_datum_low.
ls_data-zeit_von = lv_zeit_low.
ls_data-zeit_bis = "+ 60 min
APPEND ls_data TO gt_data.
IF ls_data-zeit_bis < lv_zeit_high.
ls_data-zeit_von = ls_data-zeit_bis.
ls_data-zeit_bis = ls_data-zeit_von + 60.
SELECT COUNT( * )
FROM z9labpo
INTO ls_data-anz_picks
WHERE lgtyp = p_lgtyp
AND status = p_status
AND aenzt IN lt_aenzt_rt.
ELSE.
EXIT.
ENDIF.
ENDDO.
03-11-2013 7:09 AM
hi mareike..
i had a situation similar to something like this,let me give my idea..
First the time user enters should be in 24hrs format (railway time),if not the calculations will be wrong.
Now if he enters two values,
Ex: 6:00 to 10:00
we can subtract the second interval from first interval.
10-6 = a <i.e 4>.
now we have to add the first interval from the difference of the time we obtained,loop or do with condition.
Ex:
6 + a = 10 <i.e 10>.
now subtract a from 1--> a = a-1. <i.e a= 3>
again add,
6 + a = 9,
6 + a = 8
6 + a = 7
6 + a = 6 here a = 0 and end the loop.
you can concatenate the values.
Hope its helpfull,if any doubt please ask.
Thanks
Regards..
Askar
03-11-2013 7:09 AM
hi mareike..
i had a situation similar to something like this,let me give my idea..
First the time user enters should be in 24hrs format (railway time),if not the calculations will be wrong.
Now if he enters two values,
Ex: 6:00 to 10:00
we can subtract the second interval from first interval.
10-6 = a <i.e 4>.
now we have to add the first interval from the difference of the time we obtained,loop or do with condition.
Ex:
6 + a = 10 <i.e 10>.
now subtract a from 1--> a = a-1. <i.e a= 3>
again add,
6 + a = 9,
6 + a = 8
6 + a = 7
6 + a = 6 here a = 0 and end the loop.
you can concatenate the values.
Hope its helpfull,if any doubt please ask.
Thanks
Regards..
Askar
03-11-2013 11:47 AM
Hi Maruieke,
Try with the following logic its working as per ur requirement.
REPORT yh2592_date_time NO STANDARD PAGE HEADING.
DATA:
w_date TYPE sy-datum,
w_time TYPE sy-uzeit,
w_days TYPE i,
w_days2 TYPE i,
w_tim TYPE i,
w_tim2 TYPE i,
w_rem TYPE i.
SELECT-OPTIONS:
s_date FOR w_date,
s_time FOR w_time .
w_days = s_date-low.
w_days2 = s_date-high.
w_tim = s_time-low+0(2).
w_tim2 = s_time-high+0(2).
w_rem = ( ( w_days2 * 24 ) + w_tim2 ) - ( ( w_days * 24 ) + w_tim ).
DO w_rem TIMES .
WRITE 😕 s_time-low.
s_time-low+0(2) = s_time-low+0(2) + 1.
IF s_time-low+0(2) EQ '24'.
s_time-low+0(2) = '00'.
ENDIF.
WRITE : s_time-low.
ENDDO.
Regards,
Vineesh.
03-14-2013 4:51 PM
Hello,
thank you for your helpful tips!
I solved the problem by using the following Code
But there is one big problem: The performance is really bad.
Do you have tips to solve the performance problem?
DO.
CLEAR: ls_data-anz_picks
, ls_aezt_rz
, lt_aezt_rt
.
IF sy-tabix = 1.
ls_data-datum = p_ctdfr.
ls_data-zeit_von = lv_zeit_von.
ls_data-zeit_bis = lv_zeit_von + 3600. "Eine Stunde in Sekunden
"create timestamp
CONCATENATE ls_data-datum lv_zeit_von INTO lv_aezt_low.
CONCATENATE ls_data-datum ls_data-zeit_bis INTO lv_aezt_high.
"set timestamp with actual conditions
"create timestamp range
ls_aezt_rz-option = 'BT'.
ls_aezt_rz-sign = 'I'.
ls_aezt_rz-low = lv_aezt_low.
ls_aezt_rz-high = lv_aezt_high.
APPEND ls_aezt_rz TO lt_aezt_rt.
SELECT COUNT( * )
FROM z9labpo
INTO ls_data-anz_picks
WHERE status = p_status
AND lgtyp = p_lgtyp
AND aenzt IN lt_aezt_rt.
APPEND ls_data TO gt_data.
ENDIF.
"auf datumsgrenze prüfen
IF ls_data-zeit_bis = '000000'
AND ls_data-datum <= p_ctdto.
ls_data-datum = ls_data-datum + 1.
ELSE.
ls_data-datum = ls_data-datum.
ENDIF.
CONCATENATE p_ctdto p_cttto INTO lv_aezt_to.
CONCATENATE ls_data-datum ls_data-zeit_bis INTO lv_aezt_high.
"check timestamp
IF lv_aezt_high < lv_aezt_to. "check timestamp
ls_data-zeit_von = ls_data-zeit_bis.
ls_data-zeit_bis = ls_data-zeit_von + 3600. "Eine Stunde in Sekunden
"create timestamp
CONCATENATE ls_data-datum ls_data-zeit_von INTO lv_aezt_low.
CONCATENATE ls_data-datum ls_data-zeit_bis INTO lv_aezt_high.
"set timestamp with actual conditions
"create timestamp range
ls_aezt_rz-sign = 'I'.
ls_aezt_rz-option = 'BT'.
ls_aezt_rz-low = lv_aezt_low.
ls_aezt_rz-high = lv_aezt_high.
APPEND ls_aezt_rz TO lt_aezt_rt.
SELECT COUNT( * )
FROM z9labpo
INTO ls_data-anz_picks
WHERE status = p_status
AND lgtyp = p_lgtyp
AND aenzt IN lt_aezt_rt.
APPEND ls_data TO gt_data.
ELSE.
EXIT.
ENDIF.
ENDDO.