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

syntax error

Former Member
0 Likes
1,575

REPLACE all occurances of '-' WITH space INTO lv_temp.

Please advise

regards

Kumar

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,513

hii Praneeth

use

<b>SPLIT STRING AT ‘-’ INTO P1 P2 P3 P4 .

CONCATENATE P1 P2 P3 P4 INTO P SEPARATED BY SPACE .</b>

I tried it ..it worked .

Regards

Naresh

16 REPLIES 16
Read only

Former Member
0 Likes
1,513

replace all occu<b>rr</b>ences of '-' in lv_temp with space.

give 2 R's in occurrences

Message was edited by: Chandrasekhar Jagarlamudi

Read only

0 Likes
1,513

EXCELLENT CHANDRASEKHAR ITS WORKING.

AWARDED MAXIMUM POINTS

THANKS AGAIN

REGARDS

PRANEETH

Read only

Former Member
0 Likes
1,513

hii

<b>REPLACE ALL OCCURRENCES OF ‘-’ WITH SPACE into lv_string .</b>

REPLACE<strl>WITH<str2>INTO<c>[LENGTH<1>].

ABAP/4 searches the field <c> for the first occurrence of the first, <1> positions of the pattern <str1>. If no length is specified, it searches for the pattern <str1> in its full length.

Regards

Naresh

Read only

Former Member
0 Likes
1,513

try

REPLACE ALL OCCURRENCES OF 'abc' IN myText WITH 'XYZ'.

Read only

0 Likes
1,513

REPORT ZNEGIDEMO .

DATA: A(4) TYPE C,A1(20) VALUE 'Welcome - to-- ABA-P'.

REPLACE ALL OCCURRENCES OF '-' IN a1 with space.

write a1.

it is workin(tested).

Read only

Former Member
0 Likes
1,513
REPORT abc.

DATA : cha(10) VALUE 'cha-sek'.

REPLACE ALL OCCURRENCES OF '-' IN cha WITH space.

WRITE : cha.

Reward points if helpful and close thread if solved

Read only

Former Member
0 Likes
1,513

Hi praneeth,

check the below code,it is working.

data: lv_data(30) type c value 'kee-rt-hi'.

REPLACE all occurrences of '-' IN lv_data WITH ' '.

write:/ lv_data.

Award points if helpful.

regards,

keerthi.

Message was edited by: keerthi kiran varanasi

Read only

Former Member
0 Likes
1,513

Hi,

check this..

REPLACE ALL <b>OCCURRENCES</b> OF '-' WITH SPACE into lv_temp.

regards

vijay

Read only

vinod_gunaware2
Active Contributor
0 Likes
1,513

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.

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

vinod

Read only

Former Member
0 Likes
1,513

Hi Praneeth,

The correct Syntax is,

replace all occurrences of '-' in lv_temp with space.

regards,

Kiran

Read only

Former Member
0 Likes
1,513

Hai Praneeth

Basic form

REPLACE f WITH g INTO h.

Addition

... LENGTH len (length specification for field f )

Effect

Replaces the first occurrence of the contents of field f in field h with the contents of field g . All fields are handled in their defined length; this means that closing blanks are not ignored.

The return code value indicates whether the string f was found in h and replaced by g :

SY-SUBRC = 0 String replaced.

SY_SUBRC = 4 String not replaced.

Example

DATA FIELD(10).

MOVE 'ABCB' TO FIELD.

REPLACE 'B' WITH 'string' INTO FIELD.

returns:

FIELD = 'AstringCB', SY-SUBRC = 0

Note

The fields f and g in the REPLACE statement should not overlap. Otherwise, the result is undefined.

Addition

... LENGTH len ... (length specification for field f )

Effect

Searches for the string f in the field h not in its (full) field length, but in the length len .

Example

DATA: PATTERN(5) VALUE 'ABC',

LEN TYPE I,

REPL_STRING(5) VALUE '12345',

FIELD(12) VALUE 'abcdeABCDE'.

REPLACE PATTERN WITH REPL_STRING

INTO FIELD.

does not change FIELD , since 'ABC ' does not occur in abcdeABCDE ' .

LEN = STRLEN( PATTERN ).

REPLACE PATTERN LENGTH LEN

WITH REPL_STRING

INTO FIELD.

changes FIELD to 'abcde12345DE' .

Related SEARCH , TRANSLATE , OVERLAY

Thanks & Regards

Sreenivasulu P

Read only

Former Member
0 Likes
1,513

Thanks for all your replies.

But i am not getting space in between,the two strings are concatenated without space in between.

Thanks

praneet

Read only

rahulkavuri
Active Contributor
0 Likes
1,513

hi then u need to use split command and then use concatenatation

data : a(10),b(10),d(40).
	D = ‘Apple/Orange’.
	Split d at ‘/’ into a b.

Concatenate a b into d separated by ‘ ’.
	Write:/ d.

Read only

Former Member
0 Likes
1,514

hii Praneeth

use

<b>SPLIT STRING AT ‘-’ INTO P1 P2 P3 P4 .

CONCATENATE P1 P2 P3 P4 INTO P SEPARATED BY SPACE .</b>

I tried it ..it worked .

Regards

Naresh

Read only

0 Likes
1,513

Hi Naresh,

The problem is I am not sure how many occurences of - will be there in my string.In that case i think this will fail.

Regards

Praneeth

Read only

0 Likes
1,513
[code]In that case declare one itab and concatenate those

check the modified one

REPORT abc.

DATA : BEGIN OF itab OCCURS 0,
            str(50),
       END OF itab.

DATA : cha(50) VALUE 'cha-sek-jskjfsjf',
       str(2000).

SPLIT cha AT '-' INTO TABLE itab.

loop at itab.

 concatenate str itab-str into str separated by space.

 endloop.

 write : str.

Message was edited by: Chandrasekhar Jagarlamudi