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

String Operations

former_member214498
Contributor
0 Likes
875

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
818

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

7 REPLIES 7
Read only

Former Member
0 Likes
819

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

Read only

0 Likes
818

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

Read only

0 Likes
818

Maximum is 255 charcters for each line..

Hope this help you

Thanks

Seshu

Read only

0 Likes
818

I mean, the length for the input string. Can it be 1000 characters?

Read only

0 Likes
818

Oh.. There is no limit.. sorry for mis understood

Thanks

Seshu

Read only

JozsefSzikszai
Active Contributor
0 Likes
818

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

Read only

ferry_lianto
Active Contributor
0 Likes
818

Hi,

I think there is no limit for size of type string.

Regards,

Ferry Lianto