06-05-2008 1:59 PM
Hi
I am looking for a way to find whether a timestamp exists in a string..
The filename will be like this
rmaorder_palco_0060073508_20080228T063210.635Z.txt
where T is the seperator between date and time format.. can u tell me a way to filter the date and time from this string..
Is there any way I can check for a string pattern in this case where date and time are dynamically determined...
Will command CP help us out here
06-05-2008 2:09 PM
Hello Grame,
Addictionaly, you can use also regular expressions for this.
Here's an example:
DATA: lv_string TYPE string VALUE 'rmaorder_palco_0060073508_20080228T063210.635Z.txt'.
DATA: lv_pattern TYPE string VALUE '([0-9]+)T([0-9]+)'.
DATA: lv_date TYPE string.
DATA: lv_time TYPE string.
FIND REGEX lv_pattern IN lv_string SUBMATCHES lv_date lv_time.
In variables lv_date and lv_time you'll find the values you need.
Kind regards.
06-05-2008 2:04 PM
hi,
do this way ...
data : v_char(30) value 'rmaorder_palco_0060073508_20080228T063210.635Z.txt',
v_string1(30),
v_string2(30),
v_string3(30).
split v_char at 'T' into v_string1 v_string2 v_string3.
if v_string2 is initial.
write ' No time stamp'.
endif.
06-05-2008 2:10 PM
HI Santosh
Thanks for the answer, almost solves the problem.. but if the filename already has a second T... I need to run this in a loop for n times.. where n is the number of T's in it..
Please suggest any alternative if possible.. this will still do though
06-05-2008 2:17 PM
Hi Grame,
If you are using the above block of code then definaltly you need to execute in the loop.
and make sure that when it matches then exit from the loop, otherwise it will go into the endless loop.
&********** Reward Point if helpful*******&
06-05-2008 2:09 PM
06-05-2008 2:09 PM
Hello Grame,
Addictionaly, you can use also regular expressions for this.
Here's an example:
DATA: lv_string TYPE string VALUE 'rmaorder_palco_0060073508_20080228T063210.635Z.txt'.
DATA: lv_pattern TYPE string VALUE '([0-9]+)T([0-9]+)'.
DATA: lv_date TYPE string.
DATA: lv_time TYPE string.
FIND REGEX lv_pattern IN lv_string SUBMATCHES lv_date lv_time.
In variables lv_date and lv_time you'll find the values you need.
Kind regards.
06-05-2008 2:19 PM
Hi Bruno,
That was what I was looking for but this pattern should search for 8 characters before T and 6 characters after T..
please help me with this too
06-05-2008 2:23 PM
Hello Grame,
It's automatic. It will get all numbers at left of T until non-digit character and all numbers at right of T until non-digit character.
But if you want to ensure the lenght, just add this two lines at pieces of code above:
lv_date = lv_date(8).
lv_time = lv_time(6).
Kind regards.
Bruno
Edited by: Bruno Garcia on Jun 5, 2008 2:23 PM
06-05-2008 2:28 PM
If your character string will always have the same length with each set of values starting at a fixed position, you could just define a structure with a field defined for the length each of your values and copy your string into that. That should split it up effectively.
06-05-2008 2:32 PM
That was absolutely awesome... next time i will look forward to your solutions
06-05-2008 2:31 PM
another way to do it:
DATA : V_CHAR(80) VALUE
'rmaorder_palco_0060073508_20080228T063210.635Z.txt',
V_STRING1(80),
OFFSET TYPE I.
V_STRING1 = V_CHAR.
TRANSLATE V_STRING1 USING '0/1/2/3/4/5/6/7/8/9/'.
SEARCH V_STRING1 FOR '////////T//////'.
IF SY-SUBRC = 0.
OFFSET = SY-FDPOS.
WRITE: / 'date=', V_CHAR+OFFSET(8).
ADD 9 TO OFFSET.
WRITE: / 'time=', V_CHAR+OFFSET(6).
ENDIF.