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: 

String pattern search

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

BGarcia
Active Contributor
0 Kudos

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.

10 REPLIES 10

Former Member
0 Kudos

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. 

0 Kudos

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

0 Kudos

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*******&

former_member598013
Active Contributor
0 Kudos

Hi Grame,

Try command CS: Contain String

timestamp CS 'T'.

BGarcia
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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

BGarcia
Active Contributor
0 Kudos

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

0 Kudos

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.

Former Member
0 Kudos

That was absolutely awesome... next time i will look forward to your solutions

former_member194797
Active Contributor
0 Kudos

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.