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: 

Find and delete timestamp in string

former_member293658
Participant
0 Kudos
640

Hi,

can you advise if there is a way to find and delete a timestamp in a string field please? For example sting field contains this:

'joe bloggs     first contact 19.06.2012   05:33:67    '.

is there a way to find an remove the 05:33:67 from the string field?

Thanks for your help.

1 ACCEPTED SOLUTION

Jelena_Perfiljeva
Active Contributor
0 Kudos
208

I don't believe there is a function to search for "timestamp", probably because the SAP's "timestamp" concept is a different thing.

The few search/replace commands available in ABAP are very well documented in Help (and a good suggestion provided above). The only thing needed is to define what to search for and what to do with it. In this case some assumptions may have to be made, such as location of "timestamp" within a string and/or its format. So if you can define what's "timestamp" for the purposes of your program, you're already half way there.

5 REPLIES 5

Former Member
0 Kudos
208

If the time stamp comes at the end of the string all the time, you can use this piece of code.

data: lv_len type i.

lv_len = strlen( string ).

lv_len = lv_len - 8 . " length of time field

new_string = string+0(lv_len)

You can also use REGEX.

REPLACE REGEX `*:*:*` IN text WITH space.

Use DEMO_REGEX_TOY program to check the regular expression

Hope this helps. Don't have access to my system now, so cant check if this works

Thanks,

Shambu

Jelena_Perfiljeva
Active Contributor
0 Kudos
209

I don't believe there is a function to search for "timestamp", probably because the SAP's "timestamp" concept is a different thing.

The few search/replace commands available in ABAP are very well documented in Help (and a good suggestion provided above). The only thing needed is to define what to search for and what to do with it. In this case some assumptions may have to be made, such as location of "timestamp" within a string and/or its format. So if you can define what's "timestamp" for the purposes of your program, you're already half way there.

Clemenss
Active Contributor
0 Kudos
208

Hi Michael,

the regular expression approach is best way to go. The proposal `*:*:*` my match a lot more than wanted. REPLACE \d\d:\d\d:\d\d with '' in stringvar. is somewhat more restrictive but not yet perfect.

Herr regular expression syntax at

http://www.addedbytes.com/download/regular-expressions-cheat-sheet-v1/png/

http://www.addedbytes.com/download/regular-expressions-cheat-sheet-v1/pdf/

Regards,

Clemens

Kartik2
Contributor
0 Kudos
208

Hi,

Here is what you can do.

Let lv_string be the variable in which your string is there, from which we have to extract the time.

1. Monitor for the position at which first occurance of colon ( : ) is there. Say lv_pos

2. Decrement lv_pos by 2. I.e. lv_pos = lv_pos - 2.

3. Now extract the time by using the string operation as follows

lv_string2 = lv_string+lv_pos(8).

Now lv_string2 will hold only the time of the time stamp. Hope it helps

Thanks and regards,

kartik

0 Kudos
208

Do you have any control on the code where it is populating of the string.?? or atleast try to find out how the string is getting populated? based on the logic.. you come to conclusion at what position the timestamp is getting filled and then with offset option, replace the string...