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

Rotating a character or string data

Former Member
0 Likes
1,491

Is there a key word or function module in ABAP which rotates a character or a string data. For example if the data is 'SAP', I should get it as 'PAS'.

Regards,

Aravind

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
980

See this code samepl


DATA: string11(15) type c.
CALL FUNCTION 'STRING_REVERSE'
  EXPORTING
    string          =  'TEST PROGRAM'
    lang            =  'E'
 IMPORTING
   RSTRING         =  string11
* 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.
Write:/ string11.

DATA: ALPHABET(10) VALUE 'ABCDEFGHIJ', 
      THREE(3)     VALUE    'DEF', 
      FOUR(4)      VALUE    'DEF '. 
SHIFT ALPHABET UP TO FOUR. 

SY-SUBRC is now set to 4, and the field ALPHABET remains unchanged. 

SHIFT ALPHABET UP TO THREE CIRCULAR. 

SY-SUBRC is now set to 0 and ALPHABET has the contents 'DEFGHIJABC'.

DATA: ALPHA1(11) TYPE C VALUE 'ABCDEFGHIJ', 
      ALPHA2     TYPE STRING. 
ALPHA2 = ALPHA1. 
SHIFT ALPHA1 CIRCULAR. 
SHIFT ALPHA2 CIRCULAR.

<b>

ALPHA1 now has the contents 'BCDEFGHIJ A' and ALPHA2 the contents 'BCDEFGHIJA'.</b>

Message was edited by:

Judith Jessie Selvi

5 REPLIES 5
Read only

Former Member
0 Likes
980

data : str(3) type c value 'PAS',

str1(3) type c,

len type i,

pos type i,

len1 type i.

len = strlen( str ).

len1 = len.

len = len - 1.

do len1 times.

str1pos(1) = strlen(1).

pos = pos + 1.

len = len - 1.

enddo.

write : / str1.

regards

shiba dutta

Message was edited by:

SHIBA DUTTA

Read only

Former Member
0 Likes
980
Use function module STRING_REVERSE

or u can use.

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.
STR+i(1) = C+l(1).
enddo.
write STR.
Read only

Former Member
0 Likes
980

HI,

USe:

<b>SHIFT C CIRCULAR.</b>

Shifts C cyclically, that is, the character that is pushed out

is reinserted at the other end of the string. You can use this

addition with both the RIGHT and LEFT additions.

DATA: ALPHA1(11) TYPE C VALUE 'ABCDEFGHIJ',

ALPHA2 TYPE STRING.

ALPHA2 = ALPHA1.

SHIFT ALPHA1 CIRCULAR.

SHIFT ALPHA2 CIRCULAR.

ALPHA1 now has the contents 'BCDEFGHIJ A' and ALPHA2 the

contents 'BCDEFGHIJA'.

Hope this helps.

Reward if helpful.

Regards,.

Sipra

Read only

Former Member
0 Likes
980

Hi,

Use this FM STRING_REVERSE

pass the value to string

Regards

Shiva

Read only

Former Member
0 Likes
981

See this code samepl


DATA: string11(15) type c.
CALL FUNCTION 'STRING_REVERSE'
  EXPORTING
    string          =  'TEST PROGRAM'
    lang            =  'E'
 IMPORTING
   RSTRING         =  string11
* 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.
Write:/ string11.

DATA: ALPHABET(10) VALUE 'ABCDEFGHIJ', 
      THREE(3)     VALUE    'DEF', 
      FOUR(4)      VALUE    'DEF '. 
SHIFT ALPHABET UP TO FOUR. 

SY-SUBRC is now set to 4, and the field ALPHABET remains unchanged. 

SHIFT ALPHABET UP TO THREE CIRCULAR. 

SY-SUBRC is now set to 0 and ALPHABET has the contents 'DEFGHIJABC'.

DATA: ALPHA1(11) TYPE C VALUE 'ABCDEFGHIJ', 
      ALPHA2     TYPE STRING. 
ALPHA2 = ALPHA1. 
SHIFT ALPHA1 CIRCULAR. 
SHIFT ALPHA2 CIRCULAR.

<b>

ALPHA1 now has the contents 'BCDEFGHIJ A' and ALPHA2 the contents 'BCDEFGHIJA'.</b>

Message was edited by:

Judith Jessie Selvi