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

DMEE : String Conversion

Former Member
0 Likes
613

Hi all,

I have to conver the following string as below.

String coming as: ěeu0161sčcřržzÄAÓO

I need the output for the above string as below:

String need to be convert as : eěsu0161cčzžAÄOÓ

First character is going to second and second to first continuously..

Please give me some solution ..

Thanks in advance,

Regards,

Lakshma

4 REPLIES 4
Read only

Former Member
0 Likes
514

do like this...

data:char(25) value 'eEsS'.

replace all occurrences of 'e' in char with '*' .

replace all occurrences of 'E' in char with '&' .

replace all occurrences of '*' in char with 'E' .

replace all occurrences of '&'in char with 'e'.

replace all occurrences of 's' in char with '.'.

replace all occurrences of 'S' in char with ',' .

replace all occurrences of '.' in char with 'S'.

replace all occurrences of ',' in char with 's' .

write: char.

Read only

vinod_vemuru2
Active Contributor
0 Likes
514

Hi,

Check this logic.

DATA: l_str1 TYPE string,

l_str2 TYPE string,

l_cnt TYPE i,

l_cnt1 TYPE i,

l_cnt2 TYPE i.

l_str1 = 'ěeu0161sčcřržzÄAÓO'.

l_cnt = strlen( l_str1 ).

DO l_cnt TIMES.

l_cnt1 = sy-tabix MOD 2.

IF l_cnt1 = 0.

CLEAR l_cnt2.

l_cnt2 = sy-tabix + 1.

l_str2l_cnt2(1) = l_str1sy-tabix(1).

ELSE.

CLEAR l_cnt2.

l_cnt2 = sy-tabix - 1.

l_str2l_cnt2(1) = l_str1sy-tabix(1).

ENDIF.

ENDDO.

I haven't checked in my system.

Probably check this logic seperately and make the adjustments to the logic if required.

Thanks,

Vinod.

Read only

Former Member
0 Likes
514

Check the sample code.

REPORT  ztest_simpleer.

DATA: str(100),tmp(100).
DATA: len TYPE i.
DATA: ind TYPE i,
      inc TYPE i,
      var TYPE i.


str = 'aAbBcCdDeE'.
len = STRLEN( str ).

inc = 0.
ind = 1.
var = 1.

DO .

  tmp+inc(var) = str+ind(var) .
  tmp+ind(var) = str+inc(var).

  inc = inc + 2.
  ind = ind + 2.

  IF sy-index EQ len.
    EXIT.
  ENDIF.

ENDDO.

WRITE tmp.

Read only

Clemenss
Active Contributor
0 Likes
514

Hi Lakshma,

just tested:


FORM stringswap .
  DATA:
    lv_src                                TYPE string VALUE 'eeu0161sccrru017EzÄAÓO',
    lv_dst                                TYPE string,
    lv_c1                                 TYPE c,
    lv_len                                TYPE i,
    lv_mod2                               TYPE i,
    lv_ofs                                TYPE i.
  lv_len                                  = STRLEN( lv_src ).
  DO lv_len  TIMES.
    lv_ofs                                = sy-index - 1.
    lv_mod2                               = sy-index MOD 2.
    IF lv_mod2                            = 1.
      lv_c1                               = lv_src+lv_ofs(1).
    ELSE.
      CONCATENATE
        lv_dst
        lv_src+lv_ofs(1)
        lv_c1
        INTO lv_dst.
    ENDIF.
  ENDDO.
  WRITE:
    / lv_src,
    / lv_dst.
ENDFORM.                    " STRINGSWAP

Regards,

Clemens