Application Development and Automation 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: 
Read only

simple query

Former Member
0 Likes
684

Hi experts,

I have situation where I want to remve word "plant" from the characer string.

e.g harry mark plant.

from the above string I want to move the word "plant".

how should I go about it?

Saurabh

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
658

Try using SHIFT command. For e.g:

STR1 = 'harry mark plant'

STR2 = 'plant'.

SHIFT STR1 RIGHT DELETING TRAILING STR2.

Thanks,

SKJ

6 REPLIES 6
Read only

prabhu_s2
Active Contributor
0 Likes
658

make use of delete or replace keyword.

str = "harry mark plant".

replace all occurence of "plant" in str with space.

this might not be the exact syntax. just check with F1 help. and the same with delete

Message was edited by:

Prabhu S

Read only

Former Member
0 Likes
658

Hi

Str(20) = 'harry mark plant'

use REPLACE command to replace the word plant with space

reward if useful

regards

Anji

Read only

Former Member
0 Likes
659

Try using SHIFT command. For e.g:

STR1 = 'harry mark plant'

STR2 = 'plant'.

SHIFT STR1 RIGHT DELETING TRAILING STR2.

Thanks,

SKJ

Read only

ferry_lianto
Active Contributor
0 Likes
658

Hi,

Please try this.


DATA: WA_STRING TYPE STRING VALUE 'harry mark plant'.
                                                                        
REPLACE ALL OCCURRENCES OF 'plant' IN WA_STRING WITH ' '.
WRITE: / WA_STRING.

Regards,

Ferry Lianto

Read only

Former Member
0 Likes
658

Hi,

To replace a string in a field with a different string, use the REPLACE statement.

REPLACE <str1> WITH <str2> INTO <c> [LENGTH <l>].

The statement searches the field <c> for the first occurrence of the first <l> positions of the

pattern <str1>. If no length is specified, it searches for the pattern <str1> in its full length.

Then, the statement replaces the first occurrence of the pattern <str1> in field <c> with the string

<str2>. If a length <l> was specified, only the relevant part of the pattern is replaced.

If the return code value of the system field SY-SUBRC is set to 0, this indicates that <str1> was

found in <c> and replaced by <str2>. A return code value other than 0 means that nothing was

replaced. <str1>, <str2>, and <len> can be variables.

See the following example:

DATA: T(10) VALUE 'abcdefghij',

STRING LIKE T,

STR1(4) VALUE 'cdef',

STR2(4) VALUE 'klmn',

STR3(2) VALUE 'kl',

STR4(6) VALUE 'klmnop',

LEN TYPE I VALUE 2.

STRING = T.

WRITE STRING.

REPLACE STR1 WITH STR2 INTO STRING.

WRITE / STRING.

STRING = T.

REPLACE STR1 WITH STR2 INTO STRING LENGTH LEN.

WRITE / STRING.

STRING = T.

REPLACE STR1 WITH STR3 INTO STRING.

WRITE / STRING.

STRING = T.

REPLACE STR1 WITH STR4 INTO STRING.

WRITE / STRING.

The output appears as follows:

abcdefghij

abklmnghij

abklmnefgh

abklghij

abklmnopgh

Regards,

Bhaskar

Read only

Former Member
0 Likes
658

tx