Application Development 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: 

Time range Functions

Former Member
0 Kudos

Dear Gurus ,

I have a time and i want to check it if is in a time range that i give .

For example i want to test if the time 06:02:21 is inside the range 07:00:00 and 15:00:00

Is there any function ?

I do it with code but i can't get the right results.

LOOP AT PERNR_HOURS WHERE VIRWC = ITAB-VIRWC.

IF ITAB_TIME-ERTIM > PERNR_HOURS-IN AND

ITAB_TIME-ERTIM < PERNR_HOURS-OUT.

ADD 1 TO MAN_COUNTER.

ENDIF.

ENDLOOP.

Thanks in advance ....

1 ACCEPTED SOLUTION

Former Member
0 Kudos

My problem is that the in hour is 19:00:00 and out time is 07:00:00 .

The time that i want to check is 06:54:00 ....

14 REPLIES 14

ThomasZloch
Active Contributor
0 Kudos

You can simply compare time fields just as you can compare date fields, but they all have to be of TYPE t (or TIMS in DDIC).

Thomas

MarcinPciak
Active Contributor
0 Kudos

You must have either something wrong in your logic or you are using wrong type. Check this


DATA: time_in TYPE t VALUE '070000',
      time_out TYPE t VALUE '150000'.

PARAMETERS: pa_time TYPE t.

AT SELECTION-SCREEN.
  IF pa_time BETWEEN time_in AND time_out.
    MESSAGE 'Time is in range' TYPE 'S'.
  ELSE.
    MESSAGE 'Time is out of range' TYPE 'S'.
  ENDIF.

Regards

Marcin

Former Member
0 Kudos

Hello

Use RANGES for this:


data: time like mkpf-cputm.
ranges: r_cputm for mkpf-cputm.
r_cputm-sign = 'I'.
r_cputm-option = 'BT'.
r_cputm-low = '07:00:00'.
r_cputm-high = '15:00:00'.
append r_cputm.

time = '06:00:00'.
if time in r_cputm.
  write: 'Inside range'.
else.
  write: 'Outside range'.
endif.

kesavadas_thekkillath
Active Contributor
0 Kudos

data:pa_c type sy-uzeit.
pa_c = '09:02:21'.

if pa_c between '07:00:00' and '15:00:00'.
  write 'TRUE'.
else.
  write 'FALSE'.
endif.

Former Member
0 Kudos

My problem is that the in hour is 19:00:00 and out time is 07:00:00 .

The time that i want to check is 06:54:00 ....

0 Kudos

You should include a corresponding date field in the comparison. Any more important secrets?

Thomas

0 Kudos

Dear Thomas ,

I understand now what do you mean but how can i do it ?

Thanks a lot ...

0 Kudos

Hello

Try this logic:


data: time like mkpf-cputm.
ranges: r_cputm for mkpf-cputm.
r_cputm-sign = 'I'.
r_cputm-option = 'BT'.
r_cputm-low = '070000'.
r_cputm-high = '150000'.
append r_cputm.

time = '060000'.
if time in r_cputm.
  if r_cputm-low < r_cputm-high.
    write: 'Inside range'.
  else.
    write: 'Outside range'.
  endif.
else.
  if r_cputm-low < r_cputm-high.
    write: 'Outside range'.
  else.
    write: 'Inside range'.
  endif.
endif.

0 Kudos

The problem is with the date ...

Th clock-in date is 19:00:00 (02.09.2009) and clock-out is at 06:00:00 (03.09.2009) .

The date that i want to compare is 05:55:00 at 03.09.2009 ....

How ....

0 Kudos

Hello Dimath,

Thats why we use date time stamp. Using Time stamp alone may pose potential errors like the one you faced.

Can you not use date time stamp instead?

BR,

Suhas

0 Kudos

I suppose i can . I have the dates .

Do you have an example ?

0 Kudos

Hello,

Just for your case, i wrote this code ( you need to modify it accordingly )

DATA: v_string TYPE string.

"Please note that TIMESTAMP is always in YYYYMMDDhhmmss format

DATA:
      v_timein  TYPE timestamp,
      v_timeout TYPE timestamp,
      v_time    TYPE timestamp.

CONCATENATE '20090902' '190000' INTO v_string.

v_timein = v_string.
CLEAR v_string.

CONCATENATE '20090903' '060000' INTO v_string.

v_timeout = v_string.
CLEAR v_string.

CONCATENATE '20090903' '055500' INTO v_string.

v_time = v_string.
CLEAR v_string.

IF v_time BETWEEN v_timein AND v_timeout.
  WRITE: 'Hurray !!!'.
ENDIF.

Hope this helps.

BR,

Suhas

0 Kudos

i just did it with FM ...

lOOK ..

CALL FUNCTION 'CACS_DATE_GET_TIMESTAMP'

EXPORTING

I_DATE = '02.09.2009'

I_TIME = '23:00:20'

IMPORTING

E_TIMESTAMP = timestamp_in.

CALL FUNCTION 'CACS_DATE_GET_TIMESTAMP'

EXPORTING

I_DATE = '03.09.2009'

I_TIME = '07:00:00'

IMPORTING

E_TIMESTAMP = timestamp_out. .

CALL FUNCTION 'CACS_DATE_GET_TIMESTAMP'

EXPORTING

I_DATE = '03.09.2009'

I_TIME = '04:36:08'

IMPORTING

E_TIMESTAMP = timestamp_chk.

if timestamp_chk between timestamp_in and timestamp_out .

break dpadio121ras.

endif.

0 Kudos

Hello Dimath,

Do you need the FM? If you see the code it basically CONCATENATEs the date-time values.

Upto you to decide.

Good luck !!