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

Read Also
To find out the Previous Saturday for a given date

ABAP Books List
ABAP/4 Certification, Programming, Smartforms, Sapscripts and Object Oriented Programming Books

Smart Forms
SAP Smartforms

ABAP Menu:
ABAP Example Hints and Tips

Return to Index:-
SAP ABAP/4 Programming, Basis Administration, Configuration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.  The site www.gotothings.com is in no way affiliated with SAP AG.
Any unauthorised copying or mirroring is prohibited.