‎2013 Dec 05 9:33 AM
Hi expert,
I know this question is a bit silly but i really cant find a way to do it.
Suppose i have a string 'ABCDE'
I want to store it as an itab with 5 rows:
A
B
C
D
E
DATA: SPLIT_SEQ type table of string with header line.
SPLIT STR_TO_BE_SPLIT AT '' INTO TABLE SPLIT_SEQ. ' this line fail to perform what i need to do
can anyone help me on this?
Thanks so much !
‎2013 Dec 05 10:35 AM
Hi Christopher,
Try using this FM: SOTR_SERV_STRING_TO_TABLE
It splits a string into smaller ones with the provided lenght. In your case 1.
data: it_split TYPE TABLE OF string,
text TYPE string VALUE 'ABCDE'.
CALL FUNCTION 'SOTR_SERV_STRING_TO_TABLE'
EXPORTING
text = text
line_length = 1
TABLES
text_tab = it_split.
It worked for me.
Regards,
‎2013 Dec 05 9:54 AM
Try the FM "RSDG_WORD_WRAP". Pass your string to parameter textline and outpulen = 1. Table out_lines will contain desired result.
Also,try the following code:
DATA: str TYPE string VALUE 'ABCDE',ln TYPE i,count TYPE i.
DATA:BEGIN OF wa,
c1 TYPE char1,
END OF wa.
DATA itab LIKE TABLE OF wa.
ln = strlen( str ).
WHILE count lt ln.
MOVE str+count(1) to wa-c1.
append wa to itab.
CLEAR wa.
count = count + 1.
ENDWHILE.
LOOP AT itab INTO wa.
WRITE:/ wa-c1.
ENDLOOP.
Regards
‎2013 Dec 05 9:54 AM
Hello Christopher,
lets try this way.
lv_str = 'ABCDE'.
lv_lenght = strlen(lv_str).
lv_pos type i value 0.
lwa_line type line of ITAB.
do lv_length times.
lwa_line-value = lv_str+lv_pos(1)
append lwa_line to itab.
lv_pos = lv_pos+1.
enddo.
Please publish if you face any issue here.
thanks and regards,
Bhaskar
‎2013 Dec 05 9:59 AM
Hi
The problem is there's no separator element in your string, so you can use SPLIT statament, in your case you need to use a cycle in order to read the string, pick and move the elements into table, just as some guys have suggested you
Max
‎2013 Dec 05 10:35 AM
Hi Christopher,
Try using this FM: SOTR_SERV_STRING_TO_TABLE
It splits a string into smaller ones with the provided lenght. In your case 1.
data: it_split TYPE TABLE OF string,
text TYPE string VALUE 'ABCDE'.
CALL FUNCTION 'SOTR_SERV_STRING_TO_TABLE'
EXPORTING
text = text
line_length = 1
TABLES
text_tab = it_split.
It worked for me.
Regards,
‎2013 Dec 05 10:53 AM
Hi Pere,
I found your approach should be the best !
However, when i have to do something with the CString itab, i found it fail to do so.
CALL FUNCTION 'SOTR_SERV_STRING_TO_TABLE'
EXPORTING
text = INPUT_STR
line_length = 1
TABLES
text_tab = CSTR_ITAB. 'the table could be load here
DATA: v_line type i.
DATA: WA_CSTR like line of CSTR_ITAB.
DESCRIBE TABLE CSTR_ITAB LINES v_line.
LOOP AT CSTR_ITAB into WA_CSTR FROM v_line TO 1. ' doing a reverse loop
'do something here
ENDLOOP.
However, i found it is not possible to get within the loop, anyone can help?
BR - CB
‎2013 Dec 05 11:45 AM
Hi Christopher,
I am afraid that it's not possible using this syntax. The first index has to be greater than the second.
LOOP AT CSTR_ITAB into WA_CSTR FROM index1 TO index2
There is a thread talking about looping backwards.
But you could try this code:
DESCRIBE TABLE CSTR_ITAB LINES ind1.
WHILE ind1 >= 1.
READ TABLE CSTR_ITAB INDEX ind1.
"do something
ind1 = ind1 - 1.
ENDWHILE.
‎2013 Dec 05 10:53 AM
DATA: data TYPE string VALUE 'farid',
length TYPE i,
index TYPE i.
TYPES : BEGIN OF ty_tab,
char TYPE c,
END OF ty_tab.
DATA : t_tab TYPE TABLE OF ty_tab,
wa_tab TYPE ty_tab.
length = STRLEN( data ).
WHILE index < length.
wa_tab-char = data+index(1).
APPEND wa_tab to t_tab.
add 1 to index.
ENDWHILE.