07-31-2006 6:33 PM
hello SDNs,
can anyone write a code for finding whether number entered on the selection-screen is PALADROM number?
thanks and regards,
aravind.
07-31-2006 7:10 PM
Hai Aravind
Go through the following Code
DATA: REVERSESTRING(10).
CALL FUNCTION 'STRING_REVERSE'
EXPORTING STRING = 'SAPABAP'
LANG = sy-langu
IMPORTING RSTRING = REVERSESTRING
EXCEPTIONS TOO_SMALL = 1.
write : REVERSESTRING.
Regards
Sreeni
07-31-2006 6:37 PM
hi aravind,
check the FM <b>STRING_REVERSE</b>
CALL FUNCTION 'STRING_REVERSE'
EXPORTING
STRING = v_str1
LANG = 'E'
IMPORTING
RSTRING = v_str2
EXCEPTIONS
TOO_SMALL = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
hope this helps,
do reward if it helps,
priya
Message was edited by: Priya
07-31-2006 6:40 PM
Hi,
STRING REVERSE
YOU CAN SEE THE LOGIC BY GOING INTO TO THE FUNCTION MODULE
DATA : L_NAME(30) TYPE C.
DATA : R_STRING(30) TYPE C.
DATA : STR_LEN TYPE I.
L_NAME = 'UMA'.
call function 'STRING_REVERSE'
exporting
string = L_NAME
lang = 'E'
IMPORTING
RSTRING = R_STRING.
WRITE 😕 R_STRING.
SECOND WAY TO REVERSE THE STRING
data : name1(26) type c value 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
data : len1 type i.
data : name2(26) type c.
data : counter type i.
write : 'Original String..'.
write 😕 name1.
len1 = strlen( name1 ).
counter = len1.
counter = counter - 1.
do len1 times.
concatenate name2 name1+counter(1) into name2.
counter = counter - 1.
enddo.
Write 😕 'After reversing...'.
write : / name2.
compare the 2 strings.
if they are equal,it isa palindrome.
reward helpful answers and close the thread,
regards,
keerthi.
07-31-2006 7:10 PM
Hai Aravind
Go through the following Code
DATA: REVERSESTRING(10).
CALL FUNCTION 'STRING_REVERSE'
EXPORTING STRING = 'SAPABAP'
LANG = sy-langu
IMPORTING RSTRING = REVERSESTRING
EXCEPTIONS TOO_SMALL = 1.
write : REVERSESTRING.
Regards
Sreeni
07-31-2006 7:24 PM
Of course using the FM string_reverse is probably the best way, but if you need to do it without a function module, you can do it like this.
report zrich_0003
line-count 65
line-size 132
no standard page heading.
types: begin of ttab,
index type i,
value(1) type c,
end of ttab,
begin of tchk,
value(1) type c,
end of tchk.
data: itab type table of ttab with header line,
itab2 type table of ttab with header line.
data: ichk type table of tchk with header line,
ichk2 type table of tchk with header line.
data: index type i.
parameters: p_input(35) type c.
start-of-selection.
do 35 times.
if p_input+index(1) <> space.
itab-index = sy-index.
itab-value = p_input+index(1).
append itab.
itab2-index = sy-index.
itab2-value = p_input+index(1).
append itab2.
endif.
index = index + 1.
enddo.
sort itab ascending by index.
sort itab2 descending by index.
loop at itab.
move-corresponding itab to ichk.
append ichk.
endloop.
loop at itab2.
move-corresponding itab2 to ichk2.
append ichk2.
endloop.
if ichk[] = ichk2[].
write:/ 'it is a palindrome'.
else.
write:/ 'its not a palindrome'.
endif.
Regards,
Rich Heilman