Skip to Content
0
Former Member
Mar 08, 2013 at 03:06 PM

Calculate Date/Time Interval

320 Views

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.