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

inserting line feed in text.

Former Member
0 Likes
4,026

HI,

I have a text which needs to be created in header/item texts of sales order.

text ='THIS IS!HEADERTEXT!WELCOME' ..

now it needs to be saved in the header/item text as shown below:-

THIS IS

HEADER TEXT

WELCOME.

i.e., '!' needs to be replaced by the line feed

REPLACE all OCCURRENCES OF '!' in text WITH cl_abap_char_utilities=>cr_lf. .but still am unable to save the text with line feed..

pls suggest me the alternatives.

thanks

sures

1 ACCEPTED SOLUTION
Read only

kesavadas_thekkillath
Active Contributor
2,270

hi,

You can check this


data:lv_string type string.
data:it type table of string.

lv_string = 'THIS IS!HEADERTEXT!WELCOME' .
split lv_string at '!' into table it.
loop at it into lv_string.
  if sy-tabix = 1.
  lines-tdformat = '*'.
  else.
  lines-tdformat = '/'.  
  endif.
  lines-tdline = lv_string.
  append lines.
endloop.

Hello Suresh,

try the following code for your requirement:

DATA: lt_message_body TYPE bcsy_text VALUE IS INITIAL,

ls_message TYPE string,

ls_text TYPE string VALUE 'THIS IS!HEADERTEXT!WELCOME',

lv_char TYPE c VALUE '!',

ls_rest TYPE string.

SPLIT ls_text AT lv_char INTO ls_message ls_rest.

APPEND ls_message TO lt_message_body.

WHILE ls_rest IS NOT INITIAL.

MOVE ls_rest TO ls_text.

CLEAR ls_message.

SPLIT ls_text AT lv_char INTO ls_message ls_rest.

APPEND ls_message TO lt_message_body.

ENDWHILE.

APPEND ls_rest TO lt_message_body.

"lt_message_body" will contain the text in desired format.

thanks,

Koushik

11 REPLIES 11
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,270
REPLACE all OCCURRENCES OF '!' in text WITH cl_abap_char_utilities=>cr_lf.

Where have you written this code? How are you "saving" this text? Please elaborate.

Read only

Former Member
0 Likes
2,270

HI Suhas,

this is the following code

text = 'THIS IS!HEADER TEXT!WELCOME'.

now i want to save the text as

THIS IS

HEADER TEXT

WELCOME

that means "!" should be replace by the line feed so that the next character will be printed on the next line.

pls. suggest the possibilities to achieve this.

thanks

Read only

Former Member
0 Likes
2,270

Hi,

The replace statement will work fine.. It will result in "THIS IS##HEADERTEXT##WELCOME." But then how you are saving your text in Sales header/text. Explain briefly about your requirement. Where you are trying to see the output.

Regards,

Vimala P

Read only

0 Likes
2,270

HI Vimala,

Yes, in debuggind mode its appearing as 'THIS IS##HEADER TEXT##WELCOME' ..but when i execute it , in the output its showing as 'THIS IS##HEADER TEXT##WELCOME' rather than in different lines.

i need to save the text in differentl lines in the header text of the sales order.

thanks

Read only

0 Likes
2,270

Hi Suresh,

Do you use the function 'SAVE_TEXT' for saving the header text?

In this case, you have split the text in three different lines of internal table which you are filling.

Regards,

Filippo

Read only

Former Member
0 Likes
2,270

Try using below one in the replace statement.

CL_ABAP_CHAR_UTILITIES=>NEWLINE

Read only

kesavadas_thekkillath
Active Contributor
2,271

hi,

You can check this


data:lv_string type string.
data:it type table of string.

lv_string = 'THIS IS!HEADERTEXT!WELCOME' .
split lv_string at '!' into table it.
loop at it into lv_string.
  if sy-tabix = 1.
  lines-tdformat = '*'.
  else.
  lines-tdformat = '/'.  
  endif.
  lines-tdline = lv_string.
  append lines.
endloop.

Read only

koolspy_ultimate
Active Contributor
0 Likes
2,270

try this.

Read only

koolspy_ultimate
Active Contributor
0 Likes
2,270

try this.


lv_string = 'THIS IS
                 HEADERTEXT
                 WELCOME' .

Read only

hubert_heitzer
Contributor
0 Likes
2,270

Hi Sures,

maybe following approach works:

If not, you can further try ASCII-code 10 instead of 13.


DATA:
  lv_hex_cr  TYPE x VALUE 13 LENGTH 4,
  lv_char_cr TYPE c
.
FIELD-SYMBOLS:
  <lv_char_cr> TYPE c
.

ASSIGN lv_hex_cr TO <lv_char_cr> CASTING TYPE c.
MOVE <lv_char_cr> TO lv_char_cr.
REPLACE all OCCURRENCES OF '!' in text WITH lv_char_cr

Regards, Hubert

Read only

Former Member
0 Likes
2,270

Hello Suresh,

try the following code for your requirement:

DATA: lt_message_body TYPE bcsy_text VALUE IS INITIAL,

ls_message TYPE string,

ls_text TYPE string VALUE 'THIS IS!HEADERTEXT!WELCOME',

lv_char TYPE c VALUE '!',

ls_rest TYPE string.

SPLIT ls_text AT lv_char INTO ls_message ls_rest.

APPEND ls_message TO lt_message_body.

WHILE ls_rest IS NOT INITIAL.

MOVE ls_rest TO ls_text.

CLEAR ls_message.

SPLIT ls_text AT lv_char INTO ls_message ls_rest.

APPEND ls_message TO lt_message_body.

ENDWHILE.

APPEND ls_rest TO lt_message_body.

"lt_message_body" will contain the text in desired format.

thanks,

Koushik