2006 Sep 17 11:47 AM
i have been using the FM string_reverse for reversing a string, but itz throwing an error.
Can anyone explain it with an example.
Thanks in Advance.....
Rijish
2006 Sep 17 11:53 AM
hi rijish,
DATA : LOC_string(30) type c.
DATA : in_string(30) type c.
CALL FUNCTION 'STRING_REVERSE'
EXPORTING
STRING = IN_STRING
LANG = 'E'
IMPORTING
RSTRING = LOC_STRING
EXCEPTIONS
TOO_SMALL = 1
OTHERS = 2.
rgds
anver
if helepd mark points
Message was edited by: Anversha s
2006 Sep 17 12:31 PM
2007 Feb 22 9:12 AM
hi,
shall we able to reverse a string without using string_ reverse function. and also i want to find all the position of particular character in a string
2007 Feb 22 9:41 AM
yes u can do it without using FM.
U can find the character position using the offset.
For example see this program.
data : c(5) value 'ABCDE'.
data : l type i,i type i value -1.
data : str(5) .
l = strlen( c ).
do l times.
i = i + 1.
l = l - 1.
STRi(1) = Cl(1).
enddo.
write STR.
2007 Mar 12 6:45 AM
thanks ram. we can find how many times a particular character occurs in string but shall we able to find each ones position. for ex. if banana is the string i want all position of 'a'. is it posible
2007 Mar 12 6:51 AM
U just copy and paste the below code....
<b>This gives u the no. of ocuurances of a given character in the given string ...</b>
parameter :
p_str(30) type c, " Input string.
p_char type c. " Character to be searched.
data :
w_pos type i value 1, " Position.
w_search type i, " sy-subrc.
w_count type i,
w_index type i,
w_key type i,
w_arr1(30) type c,
w_arr2(30) type c.
if p_char EQ space.
message 'Enter a character to be searched...'(006) type 'I'.
exit.
endif. " If p_char EQ space.
write : 'The character '(001), p_char , 'occured'(002),/ .
do.
split p_str at space into w_arr1 w_arr2.
w_key = 0.
w_pos = 1.
while w_search eq 0.
search w_arr1 for p_char starting at w_pos.
if sy-subrc eq 0.
w_key = sy-fdpos.
w_pos = w_key + w_pos.
add w_pos to w_count.
write: /'at postion'(003), w_count.
add 1 to : w_pos, w_index.
else.
exit.
endif. " If sy-subrc eq 0.
w_search = sy-subrc.
endwhile. " While w_search eq 0.
if w_pos ne 1.
write : 'in the word'(004), w_arr1.
add 1 to w_count.
skip.
endif. " If w_pos ne 1.
w_count = w_count + strlen( w_arr1 ).
if w_arr2 EQ space.
exit.
endif. " If w_arr2 EQ space.
clear p_str.
move w_arr2 to p_str.
enddo. " Do.
skip.
write : / 'The total no. of occurances : '(005), w_index.
reward points if helpful...
sai ramesh.
2007 Mar 13 4:22 AM
2007 Mar 13 9:05 AM
hi ,
for what tcode IMA11 is used. Shall we able to create reblica of that.
2007 Mar 13 9:37 AM
Hi please check ur code its not providing exact output. .number of occurances is correct . but the positions in which they occur are not correct.
2007 Mar 13 9:53 AM
DATA : TEXT(20) TYPE C VALUE 'BANANA',
SRCH(1) TYPE C VALUE 'A',
CMPARE(1),
COUNT TYPE I,
POS TYPE I,
OCCURPOS TYPE I,
LENGTH TYPE I.
DATA : BEGIN OF ITAB.
OCCRPOS TYPE I,
END OF ITAB.
LENGTH = STRLEN( TEXT ).
DO LENGTH TIMES.
CMPARE = TEXT+POS(1).
IF COMPARE = SRCH.
COUNT = COUNT + 1.
OCCURPOS = POS + 1.
ITAB-OCCRPOS = OCCURPOS.
APPEND ITAB.
ENDIF.
POS = POS + 1.
ENDDO.
LOOP AT ITAB.
WRITE : / 'OCCURING POS ' , ITAB-OCCRPOS.
ENDLOOP.
REGARDS
SHIBA DUTTA
Message was edited by:
SHIBA DUTTA
2007 Mar 13 9:55 AM
parameter :
p_str(30) type c, " Input string.
p_char type c. " Character to be searched.
data :
w_pos type i value 1, " Position.
w_count type i,
w_index type i.
w_count = strlen( p_str ).
w_pos = 0.
do w_count times.
if p_str+w_pos(1) eq p_char.
w_pos = w_pos + 1.
write: / w_pos.
w_pos = w_pos - 1.
w_index = w_index + 1.
endif.
w_pos = w_pos + 1.
enddo.
write : / 'The total no. of occurances : '(005), w_index.
2007 Mar 13 12:34 PM
Hi thanks. Your coding is working fine. will you have any idea about transaction IMA11 for what it is used.
2007 Mar 13 12:38 PM
hi thanks. your coding is working fine. can u tell me how to reward points
2006 Sep 17 11:56 AM
Hi,
report YXYZ.
parameter S(10) type C.
data S1(10) type C.
<b>call function 'STRING_REVERSE'
exporting
STRING = S
LANG = 'E'
importing
RSTRING = S1.</b>
if S = S1.
write 😕 S, 'is palindrom'.
else.
write 😕 S, 'is not palindrom'.
endif.
Regards
Sudheer
2006 Sep 17 12:31 PM
2006 Sep 17 12:09 PM
2007 Mar 13 10:17 AM
Hi,
U have to export the input string in STRING field and RSTRING will be imported to the output string u want and this will contain the reverse of the string or else u can go for looping and reversing.
Regards,
S.Ravi Kumar