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 internal table field at length.

Former Member
0 Likes
2,862

Hello friends,

I want to split a internal table field at the 10th charakter into two strings. (first string gets the first 10 charakters second gets the rest)

Is it possible to do this with SPLIT?

Or is there a function module for this?

All of this happens in a loop with a field-symbol.

Thanks in advance.

1 ACCEPTED SOLUTION
Read only

IN
Contributor
2,744

Hello teaman,

CALL FUNCTION 'TEXT_SPLIT'   
EXPORTING  
	length =  "  Length for split 
	text =  "  Input 
	as_character = 
IMPORTING
	line =  "  Result  
	rest =  "  Remaining text  .  


Regards,

Igor

9 REPLIES 9
Read only

IN
Contributor
2,745

Hello teaman,

CALL FUNCTION 'TEXT_SPLIT'   
EXPORTING  
	length =  "  Length for split 
	text =  "  Input 
	as_character = 
IMPORTING
	line =  "  Result  
	rest =  "  Remaining text  .  


Regards,

Igor

Read only

Former Member
0 Likes
2,744

Thank you very much.

Read only

Sandra_Rossi
Active Contributor
0 Likes
2,744

Nils Bla

There is simply the assignment operator or ABAP built-in functions (as proposed in the other answers) which are much faster than calling a function module.

I think it's not the best answer.

Read only

IN
Contributor
0 Likes
2,744

teaman

You are welcome.

Read only

Former Member
0 Likes
2,744

@Sandra Rossi

Oh I'm sorry I didn't know that.

I just tried this and it worked for me so I made it best answer.

Read only

FredericGirod
Active Contributor
0 Likes
2,744

the important is to find an answer, when you have several choose the one you better understand. (to be able to maintain it)

Read only

Sandra_Rossi
Active Contributor
0 Likes
2,744
Nils Bla Sorry about my inappropriate words, you can't know what is the "best answer" of course. Look at the other answers eventually. The number of votes may be of some importance too.
Read only

cdprasanna
Active Participant
2,744

hi,

Try like below.

TRY.
    data(lv1) = substring( val = lv_longtext off = 0 len = 10 ).
    data(lv2) = substring( val = lv_longtext off = 0 len = strlen( lv_teststring ) ).
CATCH cx_sy_range_out_of_bounds INTO DATA(lx_too_long).
    data(lv_error_lx_too_long) = lx_too_long->get_text( ).
ENDTRY.
Read only

FredericGirod
Active Contributor
2,744
types: begin of type_1,
         field type text20,
       end   of type_1,
       tt_type_1 type standard table of type_1 with key field,


       begin of type_2,
         field1 type text10,
         field2 type text10,
       end   of type_2,
       tt_type_2 type standard table of type_2 with key field1 field2.



data(lt_table_1) = value tt_type_1( ( field = '0123456789abcdefghjk' )
                                    ( field = '0123456789abcdefghjk' ) ).
data(lt_table_2) = value tt_type_2( for ls_table_1 in lt_table_1 ( field1 = ls_table_1+0(10)
                                                                   field2 = ls_table_1+10(10) ) ).




cl_demo_output=>write_data( lt_table_1 ).
cl_demo_output=>write_data( lt_table_2 ).
cl_demo_output=>display( ).

the important part is

data(lt_table_2) = value tt_type_2( for ls_table_1 in lt_table_1 ( field1 = ls_table_1+0(10)
                                                                   field2 = ls_table_1+10(10) ) ).