Register Login

Subtracting time variables

Updated May 18, 2018

Hello,

I have two variables that I’m using to populate time confirmation in t-code IW41.  The variables are working fine for recording the actual start and finish times.  I would also like to record actual work.  That requires entering either hours or minutes in decimal format.

I am getting some very hard to understand results when I subtract the start time from the finish time.  Can anyone provide some guidance as to what I should be seeing here, and how to interpret the results?  I am setting a variable with the following syntax:

Set V[z_iw41_work_s]    "&V[z_iw41_endtime]" - "&V[z_iw41_start_time]"

I should also mention that my variables are in the format h:m:s.  At first it appeared that the result was simply seconds plus 40, but that doesn’t hold up when the duration is higher.  I then thought it was minutes in the hundreds column and seconds + 40 following, but then I got a result of 4436 for a duration of 4:36.  Should I be formatting the difference variable somehow?  Any suggestions would be appreciated.  Thanks in advance!

Thanks,
 


Comments

  • 03 Sep 2010 7:05 am rekha
    Hi,

    GuiXT knows how to calculate with date formats, but not with time. You have to do it on your own. Example:

    Set V[t1] "09:11:32"
    Set V[t2] "17:21:04"

    // seconds since 00:00:00 for t1
    Set V[sec1] &V[t1](1-2)
    Set V[sec1] &V[sec1] * 60
    Set V[sec1] &V[sec1] + &V[t1](4-5)
    Set V[sec1] &V[sec1] * 60
    Set V[sec1] &V[sec1] + &V[t1](7-8)

    // seconds since 00:00:00 for t2
    Set V[sec2] &V[t2](1-2)
    Set V[sec2] &V[sec2] * 60
    Set V[sec2] &V[sec2] + &V[t2](4-5)
    Set V[sec2] &V[sec2] * 60
    Set V[sec2] &V[sec2] + &V[t2](7-8)

    // difference in seconds and in minutes
    Set V[diffsec] &V[sec2] - &V[sec1]
    Set V[diffmin] &V[diffsec] / 60 decimals=0


    Message "Difference in minutes: &V[diffmin]"

    Regards,
  • 03 Sep 2010 7:07 am rekha
    Hello,

    Thank you very much for the explanation and the sample code. It works quite well. In case anyone else is interested, here is what I ended up with. I can’t enter minutes above 24 in IW41, so have to go to decimal hours in that case, hence the if statement.

    Screen SAPLCORU.3200

    // add 09/02/10 for actual start time

    Set F[AFRUD-ISDZ] "&V[z_iw41_start_time]"

    Set V[z_iw41_endtime] "&V[today-1m_h:m:s]"

    Set F[AFRUD-IEDZ] "&V[z_iw41_endtime]"

    // seconds since 00:00:00 for start time

    Set V[sec1] &V[z_iw41_start_time](1-2)

    Set V[sec1] &V[sec1] * 60

    Set V[sec1] &V[sec1] + &V[z_iw41_start_time](4-5)

    Set V[sec1] &V[sec1] * 60

    Set V[sec1] &V[sec1] + &V[z_iw41_start_time](7-8)

    // seconds since 00:00:00 for end time

    Set V[sec2] &V[z_iw41_endtime](1-2)

    Set V[sec2] &V[sec2] * 60

    Set V[sec2] &V[sec2] + &V[z_iw41_endtime](4-5)

    Set V[sec2] &V[sec2] * 60

    Set V[sec2] &V[sec2] + &V[z_iw41_endtime](7-8)

    // difference in seconds and in minutes

    Set V[z_iw41_work_s] &V[sec2] - &V[sec1]

    Set V[z_iw41_work_min] "&V[z_iw41_work_s]" / "60" Decimals=2 DecimalSeparator="."

    // can only use minutes if less than 24

    if V[z_iw41_work_min<24]

    Set F[Actual Work] "&V[z_iw41_work_min]"

    Set F[AFRUD-ISMNU] "MIN"

    else

    Set V[z_iw41_work_h] "&V[z_iw41_work_s]" / "3600" Decimals=2 DecimalSeparator="."

    Set F[Actual Work] "&V[z_iw41_work_h]"

    Set F[AFRUD-ISMNU] "H"

    endif

    // end add 09/02/10

    Enter "/11" // Save



    Thanks,

×