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: 

Insert a break line in a content of a variable

Former Member
0 Kudos

Hi all, my problem is:

I want to put a break line at position 40 of a string (where exist a space), for example.

DATA: v_string TYPE string.

v_string = 'testline1_testline1_testline1_testline1 testline2_testline2_testline2_testline2'.

Because i want a result like this

testline1_testline1_testline1_testline1

testline2_testline2_testline2_testline2.

I tried with cl_abap_char_utilities=>cr_lf but are printing testline1_testline1_testline1_testline1##testline2_testline2_testline2_testline2.

I tried too with cl_abap_char_utilities=>new_line but don´t work.

Tks to all.

6 REPLIES 6

Former Member
0 Kudos

Hi bruno.mota ,

using off set u can achieve this easily ,first of all the find the total length of that string, if that length is less than 40 print it , else

if it is greater than 40 , loop it using dived that length with 40.

so if string is contains 100 chars very first time the off set will be like this

do.

l_string+l_val(l_pos). here initially l_val = 0 . and l_pos if it less than 40 total length of that string , else 40

next l_string+l_val(l_pos) , here l_val increased to 40 so l_val = 40 and l_pos = remaing characters if those are more than 40 then it is l_pos = 80 .

do loop like this until total characters print .

Regards

Siva

0 Kudos

Hi sadavisa,

follow my program:

start----


DATA: gv_string TYPE string,

gv_result TYPE string,

gv_len TYPE i,

gv_div TYPE f,

gv_num_lin TYPE i,

gv_len_upd type i,

gv_position type i,

gv_count type i,

gv_40(1) type c,

gv_39(1) type c,

gv_38(1) type c,

gv_37(1) type c,

gv_36(1) type c,

gv_35(1) type c.

gv_string = 'testline1_testline1_testline1_testline1 testline2_testline2_testline2_testline2'.

gv_len = STRLEN( gv_string ).

IF gv_len <= 40.

WRITE gv_string.

ELSE.

gv_div = gv_len / 40.

gv_num_lin = CEIL( gv_div ).

gv_count = 1.

WHILE gv_num_lin => gv_count.

IF gv_num_lin = sy-index. "this code is executed only in the last time

CONCATENATE gv_result gv_string INTO gv_result.

gv_count = gv_count + 1.

CONTINUE.

ENDIF.

gv_40 = gv_string+40(1).

gv_39 = gv_string+39(1).

gv_38 = gv_string+38(1).

gv_37 = gv_string+37(1).

gv_36 = gv_string+36(1).

gv_35 = gv_string+35(1).

IF gv_40 = space.

gv_position = 40.

PERFORM update_variables USING gv_position.

continue.

ELSEIF gv_39 = space.

gv_position = 39.

PERFORM update_variables USING gv_position.

continue.

ELSEIF gv_38 = space.

gv_position = 38.

PERFORM update_variables USING gv_position.

continue.

ELSEIF gv_37 = space.

gv_position = 37.

PERFORM update_variables USING gv_position.

continue.

ELSEIF gv_36 = space.

gv_position = 36.

PERFORM update_variables USING gv_position.

continue.

ELSEIF gv_35 = space.

gv_position = 35.

PERFORM update_variables USING gv_position.

continue.

endif.

gv_count = gv_count + 1.

ENDWHILE.

ENDIF.

write gv_result.

&----


*& Form UPDATE_VARIABLES

&----


  • Update variables

----


  • -->P_POSITION text

----


form UPDATE_VARIABLES using p_position type i.

CONCATENATE gv_result gv_string(p_position) cl_abap_char_utilities=>cr_lf INTO gv_result.

gv_len_upd = gv_len - p_position.

gv_string = gv_string+p_position(gv_len_upd).

CONDENSE gv_string.

gv_count = gv_count + 1.

endform. " UPDATE_VARIABLES

end----


So my question is why when i write CR_LF on file text go right and when i join into a variable and then write on screen go wrong.

Tks.

0 Kudos

well dont force so much on ABAP

just store it in a internal table and display the result in a loop. wont that do??

Former Member
0 Kudos

hi,

As per my understanding you have a string in a variable v_string.

So u want break line at "space".

u can you do as follows :-



data : v_string TYPE string,
      v1 type string,
      v2 type string.

SPLIT v_string at space INTO v1 v2.

write : v1.
write : /n v2.

Hope it helps...

Thanks & Regards,

Mihir.

0 Kudos

Hi mihir6666 i want join a CR_LF with a string into a variable and then write this in a screen.

Tks Bruno Mota.

Former Member
0 Kudos

Hi,

split string into two different strings/variables and then use it as you want.

you can use split string at space.

Regards,

Prabhat