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: 

Split internal table field at length.

0 Kudos
742

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

IN
Contributor
624

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

IN
Contributor
625

Hello teaman,

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


Regards,

Igor

0 Kudos
624

Thank you very much.

Sandra_Rossi
Active Contributor
0 Kudos
624

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.

IN
Contributor
0 Kudos
624

teaman

You are welcome.

0 Kudos
624

@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.

FredericGirod
Active Contributor
0 Kudos
624

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

Sandra_Rossi
Active Contributor
0 Kudos
624
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.

cdprasanna
Active Participant
624

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.

FredericGirod
Active Contributor
624
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) ) ).