Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

time conversion

Former Member
0 Likes
482

Hi all,

I would like to convert a number that has a time unit into a time like HH:MM:SS.

For example,

1.5 H => 00:30:00

600S => 00:10:00

Is there a FM or a simple way to do this ?

Thanks

Olivier

1 REPLY 1
Read only

former_member199581
Active Participant
0 Likes
373

Try this method I wrote:


  METHOD dur_into_hms.

    DATA:      seconds TYPE i.
    CONSTANTS: hours24_in_seconds TYPE i     VALUE 86400,
               hours24_in_hms     TYPE uzeit VALUE '240000'.
* // To manage extra 24 times:
    DATA:      sec_delta      TYPE i,
               dur_delta          TYPE abstd,
               hms_delta          TYPE uzeit.
* // For calculation:
    DATA:      hms_24_c           TYPE n LENGTH 6 VALUE '240000',
               hms_delta_c        TYPE n LENGTH 6,
               hms_out            TYPE n LENGTH 6.

    seconds = im_dur * 3600.
    IF seconds EQ hours24_in_seconds.
      ex_hms = hours24_in_hms.
    ELSEIF seconds GT hours24_in_seconds.
* // Get the exceeding time:
      sec_delta = seconds - hours24_in_seconds.
* // Convert from int to dur and dur to hms
* // INT to DUR
      dur_delta = sec_delta / 3600.
* // DUR to HMS
      hms_delta = dur_into_hms( dur_delta ).
* // Write in C dobj:
      hms_delta_c  = hms_delta.
      hms_out      = hms_24_c + hms_delta_c.
* // Export
      ex_hms       = hms_out.
    ELSE.
      ex_hms = seconds.
    ENDIF.

  ENDMETHOD.                    "dur_into_hms

The method expects in input a Duration data type (such as ABSTD type, like the P2001-STDAZ field) and output this one into HHMMSS format.

Hope this helps,

Roby.