‎2005 Sep 26 2:40 PM
Hai,
Iam new to abap can any one solve the above example:
data: c type i,
c1 type i,
len type i,
flag type c.
parameters word(20).
c = 0.
len = strlen( word ).
c1 = len - 1.
len = len / 2.
flag = ' '.
do len times.
if ( wordc(1) <> wordc1(1) ).
flag = 'X'.
endif.
enddo.
if flag = 'X'.
write: / 'Word', word, 'is not Palindrome'.
else.
write: / 'Word', word, 'is Palindrome'.
endif.
Inthe above program
if word = abap
than what is the value of
wordc(1) and wordc1(1)
and how many times the do statement work.
Please explain the above program with the above example.
‎2005 Sep 26 2:48 PM
hi,
you can find out these values through debugging
word+c(1) = 'a'
word+c1(1) = 'b'
do statment execute once.
cheers,
sasi
‎2005 Sep 26 2:48 PM
hi,
you can find out these values through debugging
word+c(1) = 'a'
word+c1(1) = 'b'
do statment execute once.
cheers,
sasi
‎2005 Sep 26 2:53 PM
Hi,
i think there is a function too (to compare with your source code) for your problem:
STRING_REVERSE
Andreas
‎2005 Sep 26 2:53 PM
Hai,
I have one doubt,
here len=len/2
then len =2
so do statement will execute twice, why once.
‎2005 Sep 26 2:54 PM
hi,
sorry for my above answer
word+c(1) = 'a'
word+c1(1) = 'a'
loop will execute 2 times
sasi
‎2005 Sep 26 2:50 PM
Hi
data: c type i,
c1 type i,
len type i,
flag type c.
parameters word(20).
len = strlen( word ).
c1 = len - 1.
flag = ' '.
do.
if ( wordc(1) <> wordc1(1) ).
flag = 'X'.
exit.
endif.
c = c + sy-index.
c1 = len - sy-index.
if c = c1.
exit.
endif.
enddo.
if flag = 'X'.
write: / 'Word', word, 'is not Palindrome'.
else.
write: / 'Word', word, 'is Palindrome'.
endif.
Max
Message was edited by: max bianchi
‎2005 Sep 26 2:55 PM
Hi bhargav,
than what is the value of
wordc(1) and wordc1(1)
here the value of word+c(1) is <b>a</b>
here the value of word+c1(1) is <b>p</b>
and how many times the do statement work.
len = len / 2.
the length of the word divide by 2 that no of times it works.
reward points for helpfull answers and close the thread if your question is solved.
regards,
venu.
‎2005 Sep 26 3:03 PM
hai,
If do statement execute twice than what is the value of wordc(1) and wordc1(1).
please clear this point.
‎2005 Sep 26 3:14 PM
Hi
If you have the WORD 'ABAP'
LENGTH = 4
C = 0
C1 = LENGTH - 4.
DO.
IF WORDC(1) <> WORDC1(1).
If this control doesn't fail, then it stop the searching, because it useless to go on
FL_PAL = 'X'.
EXIT.
ENDIF.
Add + 1 to left offset
C = C + 1.
-1 to right offset
C1 = C1 - 1.
IF C = C1.
You stop the research becuase you're comparing the same letter:
EXIT.
ENDIF.
ENDDO.
So:
1 WORD+C(1) = 'A': C = 0
WORD+C1(1) = 'P': C1 = 3.
So stop the research:
IF WORD was 'ABA':
1 WORD+C(1) = 'A': C = 0
WORD+C1(1) = 'A': C1 = 2.
2 WORD+C(1) = 'B': C = 1
WORD+C1(1) = 'B': C1 = 1.
So it stop the research:
and so...
Max
‎2005 Sep 26 3:27 PM
Hi,
The Palindrom is a word which could be read from left to right and from right to left an the result should be the same.
Below you could see my version of programm that you need.
Because of the Palindroms could contain from odd and even numbers of charakters I didn't use "do len times".
REPORT ZZ_PALINDROM .
DATA: C TYPE I,
C1 TYPE I,
LEN TYPE I,
FLAG TYPE C.
PARAMETERS WORD(20).
C = 0.
LEN = STRLEN( WORD ).
C1 = LEN - 1.
WHILE C <> C1.
IF ( WORDC(1) <> WORDC1(1) ).
FLAG = 'X'.
EXIT.
ELSE.
C = C + 1.
C1 = C1 - 1.
ENDIF.
ENDWHILE.
IF FLAG = 'X'.
WRITE: / 'Word', WORD, 'is not Palindrome'.
ELSE.
WRITE: / 'Word', WORD, 'is Palindrome'.
ENDIF.
The value of WORDc(1) will be the first, the second, the third and so on charekters of the WORD and the value of WORDC1(1) will be the last, the prelast and so on charekters of the WORD.
The do statements In your example works len times!?
Best regards
Vladimir