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: 

How to Split String

former_member200872
Active Participant
0 Kudos

Hi,

I have a string with fields each of length 40, I need to split it at the mutilples of 40 and put in an internal table , i.e.

field1(40),

field2(40),

field3(40)

v_str = (field1 field2 field3 .. ).

thanks

points will rewarded

7 REPLIES 7

Former Member
0 Kudos

DATA: s1 TYPE string,

s2 TYPE string,

s3 TYPE string,

it_tab TYPE TABLE OF string,

text = ` ur text `.

SPLIT text AT ',' INTO: s1 s2 s3,

TABLE it_tab.

Regards,

Jagadish

Former Member
0 Kudos

Hi,

try this

DATA: str1 TYPE string,

str2 TYPE string,

str3 TYPE string,

itab TYPE TABLE OF string,

text TYPE string.

text = `What,a,drag,it,is,getting,old`.

SPLIT text AT ',' INTO: str1 str2 str3,

TABLE itab.

Regards,

Raja

Sm1tje
Active Contributor
0 Kudos

do.

move string+offset(40) to lv_field.

offset = offset + 40.

enddo.

Within DO ENDDO also check if offset + length does not exceed the total length of the field, else you will get a short dump.

0 Kudos

HI Micky,

Thanks for the answer.

1. iam uploading the data . looping at the internal table(upload data) and putting tht in a string .Now the data tht iam uploading is each of length 40 . when iam puting tht in a string each field is separated by space i.e next field is starting at 41 and so on .

2. Now again i need to remove these spaces and put in an internal table .

this is my requirement ..

thanks .

Former Member
0 Kudos
v_len = STRLEN( gs_string ).
   If not v_len is initial.
IF v_len GT '40'.
   wa_tab-field1  = gs_string+0(40).
 SHIFT gs_string LEFT BY 40PLACES.
   wa_tab-field2 = gs_string+0(40). 
* Similary do for all the fields.
    ENDIF.
    ENDIF.

Regards

Kannaiah

Former Member
0 Kudos

hi wajid

try to give offset while splitting.

or after getting the strings into unternal table again split them acording to space..

split str1 at space into str2 str3 str4..

table itab.

try it

regards

sachhi.

mahaboob_pathan
Contributor
0 Kudos

hi,

first condense the string.

like

fld = u r text.

condense fld.

and then split as u requitred.

like

split var5 at ',' into var 6 var 7 var 8.