Convert time unit into seconds

Convert time unit into seconds

The goal is to convert whatever time unit declared on system into hour in ABAP.
One way to proceed is to check table T006.
Filter dimension (DIMID) on ‘TIME’ to get only time unit and retrieve fields numerator (ZAEHL), denominator (NENNR) and exponent (EXP10) to get time in seconds.

Application with ABAP :


FORM convert_time_to_seconds USING uv_time    TYPE vgwrt
                                   uv_unit    TYPE meins
                          CHANGING cv_seconds TYPE vgwrt.


  CHECK uv_time IS NOT INITIAL AND uv_unit IS NOT INITIAL.

  " Sap table buffered, OK for select on every process
  SELECT SINGLE  zaehl AS conv_to_sec,
                 nennr AS denom,
                 exp10
    FROM t006 INTO @DATA(ls_unit_info)
    WHERE msehi = @uv_unit
      AND dimid = 'TIME' ##NOTEXT.    " Keep only time units

  IF sy-subrc <> 0. " INVALID_TIME_UNIT
    " Your error process
    RETURN.
  ENDIF.

  IF ls_unit_info-denom <> 0.
    " Convert to seconds
    cv_seconds = uv_time * ls_unit_info-conv_to_sec / ls_unit_info-denom * 10 ** ls_unit_info-exp10.  
                                                                        
  ENDIF.

ENDFORM.   " END OF convert_time_to_seconds

T006 :

About the author

fjourneau administrator

Hi, I'm Florian Journeau, SAP ABAP R3 Freelance, based in Toulouse, France. You want to know more about me, have a look on my CV : cv.fjourneau.net.

1 Comment so far

uttara divtePosted on10:30 am - Oct 18, 2022

could you provide a code for Creating a new Form to print serial numbers with GET_SERNOS_OF_DOCUMENT

Leave a Reply