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

split a word into characters

Former Member
0 Likes
1,538

Hi Experts,

How can we split a single word into characters and store it in an internal table.

eg: '39EFN'

itab:3

9

E

F

N

Thanx in advance

Regards,

Hamsa Priya

9 REPLIES 9
Read only

Former Member
0 Likes
1,184

Hi,

Claculate the length of single word.


REPORT yjjtest1 .

DATA: BEGIN OF itab OCCURS 0,
           f1 TYPE c,
          END OF itab.

DATA: word(10) TYPE c VALUE '39EFN',
       vlen TYPE i,
       i TYPE i.
CLEAR: vlen, i.

vlen = strlen( word ).

DO vlen TIMES.
    i = i + 1.
  itab-f1 = word+0(i).
  APPEND itab.
  SHIFT word .
ENDDO.

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

Hope this oslves ur query, reward if this helsp.
This will work exactly

As I am using SHIFT i have increased the lenght of the word word(10).

Message was edited by:

Judith Jessie Selvi

Read only

0 Likes
1,184

Make a minor change in the code given by Judith,

DATA: BEGIN OF itab occurs 0,

f1 TYPE c,

END of itab.

word = '39EFN'.

Vlen = len(word).

<b>clear i.</b>

DO vlen TIMES.

itab-f1 = word+<b>i(1).</b>

APPEND itab.

<b>i = i + 1.</b>

END DO.

LOOP AT itab.

Write:/ itab-f1.

ENDLOOP.

Read only

sreeramkumar_madisetty
Active Contributor
0 Likes
1,184

Hi

Use the logic:

word = word+0(1).

Regards,

kumar

Read only

Former Member
0 Likes
1,184

data : v_string like string value 'abcedf',

cnt type i,

v type c,

n type i.

cnt = strlen( v_string ).

do cnt times.

move v_string+n(1) to itab-field.

append itab .

clear itab.

n = n + 1.

if n = cnt .

exit.

endif.

enddo.

Pls. reward if useful

Read only

Former Member
0 Likes
1,184

data: begin of itab occurs 0,

itm type c,

end of itab.

DATA: G_STR TYPE STRING.

DATA: LIN TYPE I,

CNT TYPE I,

CNT1 TYPE I.

DATA: VDAT.

G_STR = '123AB'.

LIN = STRLEN( G_STR ).

CNT = 0.

CNT1 = 1.

WHILE CNT < LIN.

VDAT = G_STR+CNT(1).

WRITE:/ VDAT.

CNT = CNT + 1.

CNT1 = CNT1 + 1.

ENDWHILE.

Read only

Former Member
0 Likes
1,184

hi hamsa,

execute this and check.

REPORT ZKEERTHI_TEST.

data: str type string value '39EFN'.

data:len type c.

data: n type c value '0'.

data: begin of itab occurs 0,

char type c,

end of itab.

len = strlen( str ).

while n < len.

itab-char = str+n(1).

append itab.

n = n + 1.

endwhile.

end-of-selection.

loop at itab.

write:/ itab-char.

endloop.

regards,

keerthi

Read only

Former Member
0 Likes
1,184

Some different method...

PARAMETER w_char(30) type c DEFAULT 'ABCDEF'.

DATA :

W_WORD LIKE W_CHAR,

W_INDEX TYPE I,

W_COUNT TYPE I,

W_LENGTH TYPE I.

DATA T_WORD LIKE STANDARD TABLE OF W_CHAR WITH HEADER LINE.

W_LENGTH = STRLEN( W_CHAR ).

WHILE W_COUNT LT W_LENGTH.

MOVE W_CHARW_COUNT(1) TO W_WORDW_INDEX(1).

ADD 1 TO : W_INDEX,W_COUNT.

MOVE ',' TO W_WORD+W_INDEX(1).

ADD 1 TO : W_INDEX.

ENDWHILE.

SPLIT W_WORD AT ',' INTO TABLE T_WORD.

LOOP AT T_WORD.

WRITE : / T_WORD.

ENDLOOP.

reward if it helps..

sai ramesh.

Read only

Former Member
0 Likes
1,184

S u can see the final code please try and revrt back.

REPORT yjjtest1 .

DATA: BEGIN OF itab OCCURS 0,
           f1 TYPE c,
          END OF itab.

DATA: word(5) TYPE c VALUE '39EFN',
       vlen TYPE i,
       i TYPE i.
CLEAR: vlen, i.

vlen = strlen( word ).

DO vlen TIMES.

    itab-f1 = word+i(1).
  APPEND itab.
   i = i + 1.
*  SHIFT word .
ENDDO.

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

Read only

Former Member
0 Likes
1,184

Hi Hames,

i think if you have only one word you don't need an internal table.

You can use

data: word(10) value '1234567890'.

and hande word0(1) or word3(1) etc.

You can also use an structure:

Data: begin of itab,

x1(1),

x2(1),

x3(1),

x4(1),

x5(1),

x6(1),

x7(1),

x8(1),

x9(1),

x0(1),

end of itab.

*

itab = word.

in itab-x1 you have the first character, in itab-x3 voe have the third character.

If you will handle more than one words use itab as an an internal table

and put all words in it.

Hope it helps.

regards, Dieter