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 operation end of the string

Former Member
0 Likes
1,841

Hi ,

My internal table having the below data.

2340-8901

4566-8902

5672-8901

4567-8903

3435-8904

2345-8903

Only 8901 or 8902, or 8903 or 8904 will there in end of string I want to replace with space like below

2340

4566

5672

4567

3435

2345

Instead of writing 4 times of replace statement in the Loop . I wrote like below. But it is not working . Correct me where I am going wrong

loop at lit_tab.

lw_tabix1 = sy-tabix.

CLEAR : lw_len.

if lit_tab-xblnr CS '-8901' AND

lit_tab-xblnr CS '-8902' AND

lit_tab-xblnr CS '-8903' AND

lit_tab-xblnr CS '-8904'.

lw_len = sy-fdpos.

lit_tab-xblnr = lit_tab+0(lw_len).

MODIFY lit_tab INDEX lw_tabix1 TRANSPORTING xblnr.

clear lit_tab.

endif.

ENDLOOP.

Regards,

Ajay

Edited by: Ajay reddy on Jan 13, 2010 12:39 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,798

Hi Ajay,

The condition should be OR , not AND.

regards,

amit m.

Hi ,

My internal table having the below data.

2340-8901

4566-8902

5672-8901

4567-8903

3435-8904

2345-8903

Only 8901 or 8902, or 8903 or 8904 will there in end of string I want to replace with space like below

2340

4566

5672

4567

3435

2345

Instead of writing 4 times of replace statement in the Loop . I wrote like below. But it is not working . Correct me where I am going wrong

loop at lit_tab.

lw_tabix1 = sy-tabix.

CLEAR : lw_len.

if lit_tab-xblnr CS '-8901' AND

lit_tab-xblnr CS '-8902' AND

lit_tab-xblnr CS '-8903' AND

lit_tab-xblnr CS '-8904'.

lw_len = sy-fdpos.

lit_tab-xblnr = lit_tab+0(lw_len).

MODIFY lit_tab INDEX lw_tabix1 TRANSPORTING xblnr.

clear lit_tab.

endif.

ENDLOOP.

Regards,

Ajay

Edited by: Ajay reddy on Jan 13, 2010 12:39 PM

11 REPLIES 11
Read only

Former Member
0 Likes
1,799

Hi Ajay,

The condition should be OR , not AND.

regards,

amit m.

Read only

Former Member
0 Likes
1,798

Hello,

Well if the number of characters is fixed, you can try this


loop at itab.
itab-field1 = itab-field1+0(4).
modify itab.
endloop.

Vikranth

Read only

0 Likes
1,798

Hi Vikranth

Only 8901 or 8902, or 8903 or 8904

May be you missed to read this.

Read only

0 Likes
1,798

Hi Vikki,

Sorry !! the number of chars not same . it migh be 34567999-8902 or

like char also ...... RTYUHU-8901

i need to display 34567999

RTYUHU

regards

Aj

Read only

0 Likes
1,798

check


loop at lit_tab.
lw_tabix1 = sy-tabix.
if lit_tab-xblnr CS '-8901' or lit_tab-xblnr CS '-8902' or lit_tab-xblnr CS '-8903' or lit_tab-xblnr CS '-8904'.
split lit_tab-xblnr at '-' into lv1 lv2.
lit_tab-xblnr = lv1.
clear lv1.
MODIFY lit_tab INDEX lw_tabix1 TRANSPORTING xblnr.
clear lit_tab.
endif.
ENDLOOP.

or

check if this works


loop at lit_tab.
lw_tabix1 = sy-tabix.
if lit_tab-xblnr CS '-8901' or lit_tab-xblnr CS '-8902' or lit_tab-xblnr CS '-8903' or lit_tab-xblnr CS '-8904'.
lit_tab-xblnr = lit_tab-xblnr+sy-fdpos(*) = space.
MODIFY lit_tab INDEX lw_tabix1 TRANSPORTING xblnr.
clear lit_tab.
endif.
ENDLOOP.

Edited by: Keshav.T on Jan 13, 2010 5:31 PM

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,798

Replace AND with OR in you if condition.

Read only

Former Member
0 Likes
1,798

Hi Ajay,

Please check out below modification in your code. Use 'OR' insted of 'AND'.

if lit_tab-xblnr CS '-8901' OR

lit_tab-xblnr CS '-8902' OR

lit_tab-xblnr CS '-8903' OR

lit_tab-xblnr CS '-8904'.

lw_len = sy-fdpos.

lit_tab-xblnr = lit_tab+0(lw_len).

MODIFY lit_tab INDEX lw_tabix1 TRANSPORTING xblnr.

Thanks,

Archana

Read only

Former Member
0 Likes
1,798

>if lit_tab-xblnr CS '-8901' AND

>lit_tab-xblnr CS '-8902' AND

>lit_tab-xblnr CS '-8903' AND

>lit_tab-xblnr CS '-8904'.

ajay,

is it possible that all 4 condition be true at the same time

so its not AND its OR..

Read only

Former Member
0 Likes
1,798

Hi

Why don't you try splitting the string at '-' then you've got youre first

part sepperated.

Split wa at '-' into var1 var2.

Read only

Former Member
0 Likes
1,798

Well am still not sure if i understood your question properly seeing Keshu's reply

If the number is not fixed try with split


loop at itab.
Split itab-field at '-' into var1 var2.
itab-field = var1.
modify itab.
endloop.

Vikranth

Read only

Former Member
0 Likes
1,798

Hi ajay,

we can also use this simple logic. Just extend it to your variables and values.



report abc.

data : abc(15) type c.

abc = '2340-8901'.
write :/ abc.

if abc cs '-8901' or  abc cs '-8902'.
abc = abc(sy-fdpos).
endif.

write :/ abc.

regards,

amit m.