2010 Oct 01 8:05 PM
Hi,
A quick search could not provide me with an answer whether in ABAP we can reverse a string using the SHIFT keyword alone? I am not supposed to use the function or the offset and length. Also, my data object is a string type, not a character type.
In which ever way I tried, I am breaking the code when characters repeat successive in the string.
Thanks.
2010 Oct 01 8:18 PM
shift circular comes to mind...
you could get the length and shift circular up to lv_length places?
In NetWeaver 7.02, I think there's a statement that does....At least, I think I saw that in Thomas Jung's presentation on the future of ABAP.
2010 Oct 02 2:36 AM
The circular shift just shifts the first character tot he last and so on.
The catch is not to use the offset and length.
We could have acheived by using a combination of left right shift, but then the STRING data type will always contain all the characters however shifted.
2010 Oct 02 5:22 AM
Hi ,
use function STRING_REVERSE
Pass String 'Deepak'
Language keep blank it will take default .
it will show output kapeed
Regards
Deepak.
2010 Oct 02 5:44 AM
2010 Oct 02 8:57 AM
Guys, thanks for posting. But I guess you overlooked my question.
I am supposed to use only the SHIFT and its variants. No offset, no function.
2010 Oct 02 10:05 AM
If you are allowed to use STRLEN keyword. You can try like this.
DATA: gv_text TYPE STRING VALUE 'Hello. How are you?',
gv_text_temp TYPE STRING .
DATA: gv_length TYPE i,
gv_index TYPE i.
DATA: gt_char TYPE TABLE OF c,
gwa_char TYPE c.
gv_length = STRLEN( gv_text ).
gv_text_temp = gv_text.
DO gv_length TIMES.
gv_index = gv_length - sy-index.
SHIFT gv_text BY gv_index PLACES.
gwa_char = gv_text.
APPEND gwa_char TO gt_char.
gv_text = gv_text_temp.
ENDDO.
LOOP AT gt_char INTO gwa_char.
WRITE: gwa_char.
ENDLOOP.
2010 Oct 06 3:23 PM
A combination of SHIFT LEFT and SHIFT RIGHT CIRCULAR can do the trick.
PARAMETERS in_str TYPE string.
DATA : length TYPE i,
index TYPE i,
rev_str LIKE in_str,
buf_str LIKE in_str.
length = STRLEN( in_str ).
index = length - 1.
buf_str = in_str.
DO length TIMES.
SHIFT buf_str BY index PLACES.
CONCATENATE rev_str buf_str INTO rev_str.
buf_str = in_str.
SHIFT buf_str BY sy-index PLACES RIGHT CIRCULAR.
ENDDO.
WRITE / rev_str.
2010 Oct 06 5:51 PM
2010 Oct 02 1:49 AM
Hi
You can use code below as a FORM in your code
DATA:
x_string(50) TYPE c VALUE 'ABCDE',
x_length TYPE i,
x_revert(50) TYPE c,
x_index TYPE i.
x_length = strlen( x_string ) + 1.
DO x_length TIMES.
x_index = sy-index - 1.
CONCATENATE x_string+x_index(1) x_revert INTO x_revert.
ENDDO.
WRITE x_revert.
Kind regards
2010 Oct 02 5:54 AM
Use FM CALL FUNCTION 'STRING_REVERSE'
REPORT ZSTRINGREV .
Parameters: p_string(200).
Data: r_string(100).
CALL FUNCTION 'STRING_REVERSE'
EXPORTING
STRING = p_string
LANG = 'E'
IMPORTING
RSTRING = r_string
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.
*Inputted String.
Write:/ 'Inputted String', p_string.
SKIP.
*The reverse string.
Write:/ r_string.
Edited by: kk.adhvaryu on Oct 2, 2010 6:54 AM
2010 Oct 02 4:30 PM