메뉴 건너뛰기

SAP 한국 커뮤니티

How to add hours, minutes and seconds

sapjoy 2006.12.13 06:13 조회 수 : 4381 추천:50

How to add hours, minutes and seconds
Considering a table ztime with a field ztime of type tims and has 2 records.
To get the sum of the times of these records  plz  see the following code :

REPORT ZTIME .

DATA : IZTIME LIKE ZTIME OCCURS 0 WITH HEADER LINE.
DATA : TOTTIME LIKE SY-UZEIT.
DATA : N TYPE I, TOTHRS TYPE I.

START-OF-SELECTION.
PERFORM GET-DATA.
PERFORM CAL-TOT-TIME.
PERFORM WRITE.
END-OF-SELECTION.

*&--------------------------------------------------------------------
-*
*&      Form  GET-DATA
*&--------------------------------------------------------------------
-*
*       text
*---------------------------------------------------------------------
-*
*  -->  p1        text
*  <--  p2        text
*---------------------------------------------------------------------
-*
FORM GET-DATA.
SELECT * FROM ZTIME
INTO CORRESPONDING FIELDS
OF TABLE IZTIME.

ENDFORM.                    " GET-DATA

*&--------------------------------------------------------------------
-*
*&      Form  CAL-TOT-TIME
*&--------------------------------------------------------------------
-*
*       text
*---------------------------------------------------------------------
-*
*  -->  p1        text
*  <--  p2        text
*---------------------------------------------------------------------
-*
FORM CAL-TOT-TIME.


LOOP AT IZTIME.
TOTTIME = TOTTIME + IZTIME-ZTIME.
ENDLOOP.

LOOP AT IZTIME.
N = IZTIME-ZTIME+0(2).
TOTHRS = TOTHRS + N.
ENDLOOP.


ENDFORM.                    " CAL-TOT-TIME

*&--------------------------------------------------------------------
-*
*&      Form  WRITE
*&--------------------------------------------------------------------
-*
*       text
*---------------------------------------------------------------------
-*
*  -->  p1        text
*  <--  p2        text
*---------------------------------------------------------------------
-*
FORM WRITE.

DATA : HRS TYPE I, MIN TYPE I, SECS TYPE I.

LOOP AT IZTIME.
WRITE :/ IZTIME-ZTIME.
ENDLOOP.

SKIP 2.

HRS = TOTHRS.
MIN = TOTTIME+2(2).
SECS = TOTTIME+4(2).

WRITE :/ 'total time : ' , (2)HRS NO-GAP,
                       ':' NO-GAP,(2)MIN NO-GAP,
                       ':' NO-GAP,(2)SECS NO-GAP.


ENDFORM.                    " WRITE