‎2007 Sep 17 6:03 PM
Hi Folks
I have to split long strings into multiple small strings of fixed length.
For example:
the 1st line of itab contains a numeric field and a character field containing string of 500 characters.
I want to create 5 more records with a string length of 100 characters. so the 1st line of itab is now split into 5 new records in itab2 with 5 strings of 100 characters each.
Points will be rewarded for a helpful answer.
Regards
Waz
‎2007 Sep 17 6:11 PM
use FM :
SWA_STRING_SPLIT
check the sample code :
data : d_string type string.
data: begin of i_inst occurs 0.
include structure swastrtab.
data: end of i_inst.
call function 'SWA_STRING_SPLIT'
exporting
input_string = d_string
max_component_length = 100
tables
string_components = i_inst
exceptions
max_component_length_invalid = 1
others = 2.
Thanks
Seshu
‎2007 Sep 17 6:11 PM
use FM :
SWA_STRING_SPLIT
check the sample code :
data : d_string type string.
data: begin of i_inst occurs 0.
include structure swastrtab.
data: end of i_inst.
call function 'SWA_STRING_SPLIT'
exporting
input_string = d_string
max_component_length = 100
tables
string_components = i_inst
exceptions
max_component_length_invalid = 1
others = 2.
Thanks
Seshu
‎2007 Sep 17 6:20 PM
Hi Seshu
Thanx, it was helpful. One last question before I close this thread. Is there a limit to the length of the string? I mean user can input a whole paragraph as input.
Regards
Waz
‎2007 Sep 17 6:23 PM
Maximum is 255 charcters for each line..
Hope this help you
Thanks
Seshu
‎2007 Sep 17 6:26 PM
I mean, the length for the input string. Can it be 1000 characters?
‎2007 Sep 17 6:37 PM
‎2007 Sep 17 6:14 PM
hi Waz,
bst is to use the FM TEXT_SPLIT like this:
do 5 times
CALL FUNCTION 'TEXT_SPLIT'
EXPORTING
length = 100
text = main_text
AS_CHARACTER =
IMPORTING
LINE = curent line
REST = main_text
.
case sy-index.
when 1.
text1 = current_line.
when 2.
text2 = current_line.
when 3.
text3 = current_line.
when 4.
text4 = current_line.
when 5.
text5 = current_line.
endcase.
enddo.
in each do process the 100 hundred characters of main_text is cutted and copied into text1, text2, etc.
hope this helps
ec
‎2007 Sep 17 6:32 PM
Hi,
I think there is no limit for size of type string.
Regards,
Ferry Lianto