Application Development 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: 

Split up a string into parts of 3 chars ...

0 Kudos

Hi friends,

i have a special requirement:

i need to split a string in means of 3 chars ( so called trigrams ) that means that my name should look like this afterwards:

CLEMENS should be splitted ( in to an itab ? ) that contains:

CLE

LEM

EME

MEN

ENS

How could i achieve that ?

Thank you, points will be surely and instantly awarded!

Clemens

1 ACCEPTED SOLUTION

Former Member
0 Kudos

HEllo,

Check this code.


PARAMETERS: VAR(16) DEFAULT 'CLEMENS'.

DATA: BEGIN OF ITAB OCCURS 0,
        LINE(3),
      END OF ITAB.
DATA: INT TYPE I,
      INT1 TYPE I.
DO.
  INT1 = STRLEN( VAR+INT(3) ).
  IF INT1 EQ 3."IS INITIAL.
    MOVE VAR+INT(3) TO ITAB-LINE.
    APPEND ITAB.
    ADD 1 TO INT.
  ELSE.
    EXIT.
  ENDIF.
ENDDO.

LOOP AT ITAB.
  WRITE:/ ITAB-LINE.
ENDLOOP.

Vasanth

Message was edited by:

Vasanth M

8 REPLIES 8

Former Member
0 Kudos

hi,

check it once.

parameters: s(12) type c.

data: l type i,

s1(3),

i type i.

l = strlen( s ).

l = l - 2.

do l times.

s1 = s+i(3).

write:/ s1.

i = i + 1.

enddo.

regards,

ram.

Message was edited by:

rambabu kondepati

0 Kudos

refer this code and give a value at selection screen (string name), it wl work as per ur requirement.

award points if helpfull.



parameters: p1(20) .

data: begin of itab occurs 0,
       f1(20),
      end of itab.

data p2 type i.
data p3 type i.
data off type i.

p2 = strlen( p1 ).

data count type i.
if p2 ge 3.

do p2 times.
clear itab.
clear count.
count = strlen( p1+off(3) ).
if count = 3.
itab-f1 = p1+off(3).
append itab.
else.
exit.
endif.
off = off + 1.
enddo.

clear itab.

loop at itab.

write:/ itab-f1.

endloop.

endif.

Former Member
0 Kudos

hi,

To split a character string into two or more smaller strings, use the SPLIT statement as follows:

<b>SPLIT <c> AT <del> INTO <c1> ... <cn>.</b>

<b>You can also split a string into the individual lines of an internal table as follows:</b>

SPLIT <c> AT <del> INTO TABLE <itab>.

The system adds a new line to the internal table <itab> for each part of the string.

regards,

Ashokreddy.

Former Member
0 Kudos

HEllo,

Check this code.


PARAMETERS: VAR(16) DEFAULT 'CLEMENS'.

DATA: BEGIN OF ITAB OCCURS 0,
        LINE(3),
      END OF ITAB.
DATA: INT TYPE I,
      INT1 TYPE I.
DO.
  INT1 = STRLEN( VAR+INT(3) ).
  IF INT1 EQ 3."IS INITIAL.
    MOVE VAR+INT(3) TO ITAB-LINE.
    APPEND ITAB.
    ADD 1 TO INT.
  ELSE.
    EXIT.
  ENDIF.
ENDDO.

LOOP AT ITAB.
  WRITE:/ ITAB-LINE.
ENDLOOP.

Vasanth

Message was edited by:

Vasanth M

dev_parbutteea
Active Contributor
0 Kudos

Hi,

<b>HERE IS YOUR CODE</b>

data: I_TEMP_TAB(20) TYPE c VALUE 'CLEMENS',

vari1 TYPE i,

vari2 TYPE i,

vari3 TYPE i.

TYPES:begin of file,

name(3) type c,

end of file.

data:it_file TYPE STANDARD TABLE OF file,

wa_file TYPE file.

*REPLACE '&1' into text001 with 'teest'.

*message text001 type 'I'.

vari1 = STRLEN( I_TEMP_TAB ).

if vari1 > 3.

vari3 = vari1 - 2.

vari2 = 0.

do vari3 times.

if vari2 > vari3 .

exit.

else.

wa_file-name = I_TEMP_TAB+vari2(3).

append wa_file to it_file.

endif.

vari2 = vari2 + 1.

enddo.

endif.

loop at it_file INTO wa_file.

write:/ wa_file-name.

endloop.

Regards,

Sooness

Former Member
0 Kudos
REPORT ychatest MESSAGE-ID zz..

DATA : v_str(10) VALUE 'CLEMENS',
       v_len TYPE i,
       v_index LIKE sy-index.

DATA : BEGIN OF itab OCCURS 0,
         field(3),
       END OF itab.

v_len = STRLEN( v_str ).
v_len = v_len - 2.
DO v_len TIMES.
  v_index = sy-index - 1.
  itab-field = v_str+v_index(3).
  APPEND itab.
  CLEAR itab-field.
ENDDO.

LOOP AT itab.
  WRITE : / itab-field.
ENDLOOP.

Former Member
0 Kudos

hi,

To split a character string into two or more smaller strings, use the SPLIT statement as follows:

<b>SPLIT <c> AT <del> INTO <c1> ... <cn>.</b>

<b>You can also split a string into the individual lines of an internal table as follows:</b>

SPLIT <c> AT <del> INTO TABLE <itab>.

The system adds a new line to the internal table <itab> for each part of the string.

<b>logic:</b>

DATA: var type string value 'celmens',
           c1(3) type c,
           c2(3) type c,
           c3(3) type c,
           c4(3) type c,
           c5(3) type c.

   c1 = var(3).
   c2 = var+1(3).
   c3 = var+2(3).
   c4 = var+3(3).
   c5 = var+4(3).

write:/ c1,
          c2,
          c3,
          c4,
          c5.

regards,

Ashokreddy.

athavanraja
Active Contributor
0 Kudos

check this

REPORT YTESTSTR
       NO STANDARD PAGE HEADING.

data: begin of resulttab occurs 0 ,
      val(5) ,
      end of resulttab .

data: splitleng type i .
data: mystring type string .

mystring = 'abcdefghijklmnopqrstuvwxyz' .
splitleng = 3 .

CALL FUNCTION 'CONVERT_STRING_TO_TABLE'
  EXPORTING
    i_string               = mystring
    i_tabline_length       = splitleng
  TABLES
    et_table               = resulttab .

Raja