09-07-2009 12:11 PM
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 ....
09-07-2009 12:30 PM
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 ....
09-07-2009 12:17 PM
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
09-07-2009 12:21 PM
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
09-07-2009 12:23 PM
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.
09-07-2009 12:27 PM
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.
09-07-2009 12:30 PM
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 ....
09-07-2009 12:31 PM
You should include a corresponding date field in the comparison. Any more important secrets?
Thomas
09-07-2009 12:34 PM
Dear Thomas ,
I understand now what do you mean but how can i do it ?
Thanks a lot ...
09-07-2009 12:53 PM
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.
09-07-2009 1:04 PM
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 ....
09-07-2009 1:10 PM
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
09-07-2009 1:14 PM
09-07-2009 1:22 PM
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
09-07-2009 1:23 PM
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.
09-07-2009 1:29 PM
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 !!