2006 Oct 24 9:59 AM
hi everyone,
how to get to check if one string means date or time? Any sugestion is appreciated.
Julian
2006 Oct 24 10:14 AM
HI,
DATA: FLD LIKE SY-DATUM,
FLD1 LIKE SY-UZEIT,
F_TYPE(4),
F_TYPE1(4).
DESCRIBE FIELD FLD TYPE F_TYPE.
DESCRIBE FIELD FLD1 TYPE F_TYPE1.
WRITE: F_TYPE,F_TYPE1..
if f_type = 'D'
write 'date'.
elseif f_type = 'T'.
write 'time'.
endif.
Regards
amole
2006 Oct 24 10:02 AM
Use the FM DATE_CHECK_PLAUSIBILITY to check if the passed parameter is a date or not. If an exception is raised it is not a date.
2006 Oct 24 10:06 AM
Hi Julian
can you give more details?
Have you a generic string field or do you have a field of which you don't now the type. In this case there is a class that give you runtime the type of a field.
Bye
enzo
2006 Oct 24 10:09 AM
You can play as well with abap operator 'CP' - contain pattern, but I suppose it is the last thing worth doing.
2006 Oct 24 10:10 AM
A formatted time field wil be of 8 characters(Along with separators).
A formatted date field wil be of 10 characters(Along with separators).
An unformatted time field wil be of 6 characters(Along with separators).
An unformatted date field wil be of 8 characters(Along with separators).
Find the length.
len = strlen( v_var ).
case len.
when 8.
Write:/ 'Its Time'.
when 10.
Write:/ 'Its Date'.
endcase.
Regards,
Ravi
2006 Oct 24 10:11 AM
Hi,
use describe
DATA: FLD(8) TYPE N,
F_TYPE.
DESCRIBE FIELD FLD TYPE F_TYPE.
Result: F_TYPE contains the value 'N'.
Regards
amole
2006 Oct 24 10:14 AM
HI,
DATA: FLD LIKE SY-DATUM,
FLD1 LIKE SY-UZEIT,
F_TYPE(4),
F_TYPE1(4).
DESCRIBE FIELD FLD TYPE F_TYPE.
DESCRIBE FIELD FLD1 TYPE F_TYPE1.
WRITE: F_TYPE,F_TYPE1..
if f_type = 'D'
write 'date'.
elseif f_type = 'T'.
write 'time'.
endif.
Regards
amole
2006 Oct 24 10:43 AM
Hi erveryone,
sorry, maybe i didn't explain it too detail. I read data from a text file, so all data strings of type c initially. But i wanna check if these data are correct date or time format. How to do that?
Thanks.
Julian
2006 Oct 24 10:58 AM
an example of CP usage:
if string CP '+++..+'.
...
elseif string CP ':'.
else...
Message was edited by: Tomasz Kozerski
2006 Oct 24 11:01 AM
Hi Julian,
You can use the FMs:
DATE_CHECK_PLAUSIBILITY Date plausibility check
TIME_CHECK_PLAUSIBILITY Time plausibility check
for checking the string for validity of date or time.
Usage:
call function 'DATE_CHECK_PLAUSIBILITY'
exporting
date = v_date exceptions
plausibility_check_failed = 1
others = 2.
if sy-subrc <> 0.
Write:/ 'NOt a valid date'.
endif.
call function 'TIME_CHECK_PLAUSIBILITY'
exporting
time = v_time
exceptions
others = 1.
if sy-subrc ne 0.
Write:/ 'NOt a valid time'.
endif.
Regards,
Ravi
Message was edited by: Ravi Kanth Talagana
2006 Oct 24 11:12 AM
Julian
before to use one of right solution above, do a MOVE.
MOVE $your_variable$ TO $variable_to_test$
$your_variable$ is a sequence of CHAR(8) or CHAR(10), you know.
$variable_to_test$ could be LIKE sy-datum or something else.
2006 Oct 24 12:46 PM
Hi julian ,
just give the example for a string how u are storing the formats for date and time in ur system ,
i mean what is the length of the date field and time field in ur text format
will it be same ,,if so give us a value (or a set of values )to work on a specific logic
cause system takes 8 chars for date field and 6 chars for time field ,,
also ur requirement is asking for a date or time check on a specific string ,
but i cant put the same string for two fields check ...
???
if that is the scenario y dont u put
field string
DXXXXXX,
TXXXXXX,
DXXXXXX,
DXXXXXX,
TXXXXXX,
this way ..
differentiate with a tag
field string+0(1) = 'D', --->DATE FIELD
ELSE TIME FIELD.
regards,
vijay
data date type d value '20061014'.
DATA TIME TYPE T VALUE '154633'.
WRITE (8) TIME USING EDIT MASK '__:__:__'. "Output: 15:46:33
write (10) date using edit mask '__/__/____'.
write time using edit mask '______'.
*my logic is system uses internally 8 chars for date field and 6 chars
*for time field