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 comparison

Former Member
0 Likes
3,890

Hi,

is it possible to suppress the seconds of type SY-UZEIT. For a compare it is

important only the HOUR:and MINUTES.

To keep it simple I also agree with FM's which are useful for that

purposes.

Regards

Ilhan

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,873

Hello,

A simple solution:

In variable type TIMS, value is stored in the database as format HHMMSS.

Ex: if you have two TIMS variable.

DATA: var_time1 LIKE sy-uzeit.

var_time2 LIKE sy-uzeit.

And you want to compare only HHMM of the time, you can use the normal SAP logical operators like this:

Sol. 1.

IF var_time1(4) <any logical operator> var_time2(4).

*Your code

ENDIF.

<any logical operator> means EQ, NE, GE, GT, LT, LE etc.

2.soln:

CLEAR: var_time1, <------000000

var_time2. <------000000

MOVE <Your time variable1>(4) TO var_time1. <-------HHMM00

MOVE <Your time variable2>(4) TO var_time2. <-------HHMM00

Now you can use any noraml logical opeartors var_time1 & var_time2.

IF var_time1 [EQ, NE, GE, GT, LT, LE] var_time2.

*Your code

ENDIF.

Regards,

A.Singh

8 REPLIES 8
Read only

Former Member
0 Likes
1,873

hi,

Take a local variable of 5 characters and put the time in your local variable using the concept of Split and concatenate your original time.

Use this local variable at the place where is your requirement

like...........

data ws_time(6) type c.

concatenate sy-uzeit0(2) ':' sy-uzeit2(2) into ws_time.

now your time will have only hrs and mins.

or............

use

set time = 'HH:MM'.

Hope this solves ur issue. Reward if helpful.

~~Guduri

Read only

Former Member
0 Likes
1,873

Here I have one simple example :

data v_time type sy-uzeit.

data : v_time1(10) type c.

data : v_time2(5) type c.

  • split the 2 diffrent variable

data : v_hh(2) type c,

v_mm(2) type c.

start-of-selection.

v_time = sy-uzeit.

move v_time to v_time1.

v_hh = v_time1+0(2).

v_mm = v_time1+2(2).

concatenate v_hh ':' v_mm into v_time2.

write 😕 v_time2.

Thanks

Seshu

Read only

Former Member
0 Likes
1,873

Ok, thanks a lot of for these heplful hints.

But can you show me how a compare of two times takes place ?

Regeards

Ilhan

Read only

0 Likes
1,873

do you want to compare both times ? Can you please explian how you want ?

i will tell you simple example :

if sy-uzeit = time. " Here both are time related variables.

whatever you have HH:MM -> convert them into HH:MM::SS ( as like sy-uzeit),move the value HH:MM:SS format,here SS always zero then do compare.

I do always above method,explian me how you want.

Thanks

Seshu

Read only

0 Likes
1,873

I guess you can try below FM to get time comparision or time diff

CCU_TIMESTAMP_DIFFERENCE

SCSM_TIME_DIFF_GET

CBIH_LB39_TIMESTAMP_COMPARE

RH_WF_TIMESTAMP_COMPARE

Thanks

Seshu

Read only

Former Member
0 Likes
1,874

Hello,

A simple solution:

In variable type TIMS, value is stored in the database as format HHMMSS.

Ex: if you have two TIMS variable.

DATA: var_time1 LIKE sy-uzeit.

var_time2 LIKE sy-uzeit.

And you want to compare only HHMM of the time, you can use the normal SAP logical operators like this:

Sol. 1.

IF var_time1(4) <any logical operator> var_time2(4).

*Your code

ENDIF.

<any logical operator> means EQ, NE, GE, GT, LT, LE etc.

2.soln:

CLEAR: var_time1, <------000000

var_time2. <------000000

MOVE <Your time variable1>(4) TO var_time1. <-------HHMM00

MOVE <Your time variable2>(4) TO var_time2. <-------HHMM00

Now you can use any noraml logical opeartors var_time1 & var_time2.

IF var_time1 [EQ, NE, GE, GT, LT, LE] var_time2.

*Your code

ENDIF.

Regards,

A.Singh

Read only

Former Member
0 Likes
1,873

Simply do like this.


data: v_time1 like sy-uzeit,
      v_time2 like sy-uzeit.

v_time1+4(2) = '00'. " remove the seconds from v_time1
v_time2+4(2) = '00'. " remove the seconds from v_time2

*-- now you can compare them
if v_time1 = v_time2.
  write:/ 'The two times are same.'.
else.
  write:/ 'The two times are not same.'.
endif.

Read only

Former Member
0 Likes
1,873

I thank you very very much for all your helps.

<b>Long life the SAP COMMUNITY NETWORK!</b>

Regards

Ilhan