Skip to Content
author's profile photo Former Member
Former Member

Converting time into integer

Hi ,

I performing time claculations ,Is there FM to convert a field of type T into type Integer ?

i have 3 fields

tot begtime endtime

0.98 08:59 09:58

tot is of type Curr with 2 decimals,betime,endtime are of

T

i am getting problem when i am performing calculations like

tot = beg - end.

Regards.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

8 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Nov 28, 2005 at 06:41 PM

    Hi Aima,

    Have two char and two integer varaibles.

    1. Move the Start Time and End time to char variables.

    2. Move the char values to integer variables.

    3. Now subtract Endtime from Start time to get total.

    Regards,

    Rajasekhar

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Aima,

      Rich's example is perfect for time differences within the same day.

      If the time can span multiple days, use Func Module : SD_DATETIME_DIFFERENCE

      It allows you to enter dates and times.

  • Posted on Nov 28, 2005 at 06:47 PM

    One question, in what unit is the integar value to be. You have two times, do you need to see the difference in hours/minutes/seconds? If not, what could you possibly be trying to do?

    As you can see in this sample program, the difference between the times is 59 mintues.

    report zrich_0001.
    
    
    data: time1 type sy-uzeit,
          time2 type sy-uzeit,
          time_diff type sy-uzeit.
    
       time1 = '095800'.
       time2 = '085900'.
    
    
       time_diff = time1 - time2.
    
       write:/ time1,
             / time2,
             / time_diff.

    Regards,

    Rich Heilman

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 28, 2005 at 06:47 PM

    What are you trying to get, difference between the times in seconds, or minutes, or hours or all? If you declare the tot as type i(integer), then you will get the difference as the number of seconds, or if you define tot as another time field, then you will get it time format HHMMSS.

    Srinivas

    Add a comment
    10|10000 characters needed characters exceeded

    • Ok, that is making some sense now. Let us now concentrate on what should be the data type for "tot". When you have a value of 0.98 what does that mean? Is it 0.98 hours or what? You can define your "tot" as type p decimals 2. But I don't see how you can have a '.98' difference when you are doing the subtraction on the time fields.

      Difference between two time fields is always an integer value.

      More clarification is needed on this aspect.

      Thanks,

      Srinivas

  • Posted on Nov 28, 2005 at 07:06 PM

    I prefer to use TimeStamps for this sort of thing, especially if you must cross days.

    The following is an example from 640 that uses the new cl_abap_tstmp class.

     cl_abap_tstmp=>systemtstmp_syst2utc(
            exporting
              syst_date = <wa_joblist>-strtdate
              syst_time = <wa_joblist>-strttime
            importing
              utc_tstmp = start_stamp ).
    
          cl_abap_tstmp=>systemtstmp_syst2utc(
            exporting
              syst_date = sy-datum
              syst_time = sy-uzeit
            importing
              utc_tstmp = now_stamp ).
    
          seconds = cl_abap_tstmp=>subtract(
              tstmp1 = now_stamp
              tstmp2 = start_stamp ).

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 28, 2005 at 07:24 PM

    From the help on 'COMPUTE':

    DATA: SECONDS TYPE I, 
          TIME_FROM TYPE T VALUE '200000', 
          TIME_TO   TYPE T VALUE '020000'. 
    SECONDS = ( TIME_TO - TIME_FROM ) MOD 86400. 
    

    SECONDS has the value 21600 (6 hours). The "MOD 86400" operation in this example ensures that the result is not negative, even if the time period spans midnight.

    Rob

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 28, 2005 at 07:26 PM

    Hi Aima,

    How to determine of the times(Beg,End) are on the same date? Ignore my earlier post.

    As srinivas suggested, post the code, how you are getting the beg and end times...plz

    Regards,

    Raj

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 28, 2005 at 07:41 PM

    Use Function Module SD_CALC_DURATION_FROM_DATETIME

    It returns a DEC 11 value. It also returns a parameter tells you which of the 2 dates is greater.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 28, 2005 at 09:07 PM

    Hi Rich

    <b>.98 means the difference is .98 of an hour.</b>

    From my understanding it is .98 Hours.

    <b>@Srinivas</b>

    <b>Difference between two time fields is always an integer value.</b>

    Yes , if u declare as resultant variable as type i then it is,but for me i have received as 0.98 hours .

    for the difference of 08:59 and 09:59.

    0.98 08:59 09:58

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.