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

String format

Former Member
0 Likes
917

Dear Friends,

I have a value like 'C-1000010' in a variable and i need to eliminate the Hyphen and result should be 'C1000010'.

pls give me an idea.

Thanks in advance

8 REPLIES 8
Read only

vinod_gunaware2
Active Contributor
0 Likes
885

Use <b>replace</b> statement.

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

Note how, in the last line, the field STRING is truncated on the right. The search pattern 'cdef' of length 4 is replaced by 'klmnop' of length 6. Then, the rest of the field STRING is filled up to the end of the field.

regards

vinod

Read only

rahulkavuri
Active Contributor
0 Likes
885

use the replace command

Data p(6) value ‘ABCABC’.

Replace ‘A’ with ‘’ into p.

Write:/ p. DEFABC

(Replaces first occurrence only)

If the above doesnt work then use the following code

<b>data : a(10),b(10), d(20).

Split STR at '-' into a b.

Concatenate a b into d.</b>

<b>Sorry to edit this once again</b>

Read only

Former Member
0 Likes
885

hii

<b>REPLACE ‘&’ WITH ‘ ’ into value.

CONDENSE value [NO-GAPS].</b>

otherwise you can break the value into two using offset

and then concatenate again .

Regards

Naresh

Read only

Former Member
0 Likes
885

Hi Kalimuthu

Try the following:

DATA: str1 type string value 'C-1000010'.

DATA: str2 type string.

concatenate str1 0(1) + str1 2(7) into str2 .

Regards

Prabhu

Read only

Former Member
0 Likes
885

Hi Kalimuthu,

This logic will work.

data : str(15) type c value '1-23000234',

replace '-' with ' ' into str.

condense str NO-GAPS.

Thanks,

Susmitha

Read only

Former Member
0 Likes
885

hi,

Use Replace

REPLACE ALL OCCURRENCES OF '-' IN v_text WITH ' '.

Read only

Former Member
0 Likes
885

hi

try this


split yoursting at '-' into str1 str2.
concatente  str1 str2 into yourstring.

reward if useful

Read only

Former Member
0 Likes
885

replace '-' with space in v_text.

condense v_text