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 put a carriage return and a feed line in a string

Former Member
0 Kudos

Hi,

I need to these two sentences in a string. Can anybody tell me how to do this?

For example:

data: var_string(50) type c.

var_string = 'my first line

                  my second line'.

It returns an error, of course. But I need to be able to write the following when I write the var_string variable:

my first line

my second line

Thanks in advance.

Regards.

10 REPLIES 10

former_member212002
Active Contributor
0 Kudos

Hello ,

Try this

Concatenate 'My first line' cl_abap_char_utilities=>cr_lf 'My second line' into var_string.

Cheers

Abhinab

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

Try this for cl_abap_char_utilities=>cr_lf linefeed. Similarly for others, you can check the class->attributes of cl_abap_char_utilities.

concatenate 'my first line' cl_abap_char_utilities=>cr_lf 'my second line' into var_string.

0 Kudos

I get the following:

'my first line##my second line'....

raymond_giuseppi
Active Contributor
0 Kudos

You could "play" with CL_ABAP_CHAR_UTILITIES=>CR_LF in a concatenation, but you will only get some ## junk character with statement WRITE, so you must use two "WRITE / text." or a "WRITE: / text1, / text2." syntax.

DATA: text1 TYPE c LENGTH  30 VALUE 'ABDCDEFGHIJ',
       text2 TYPE c LENGTH  30 VALUE 'ZYXWVUTSRQP',
       text  TYPE c LENGTH 132.
CONCATENATE text1 cl_abap_char_utilities=>cr_lf text2 INTO text SEPARATED BY ` `.
WRITE: / text.
WRITE: / text1, / text2.

Regards,

Raymond

0 Kudos

Ok.

Actually I haven't explained the goal of the cr and lf. Once I've the cr and lf between both lines and the string saved in a char variable, I call this sentence:

CALL FUNCTION 'GUI_DOWNLOAD'

passing this variable.

So, I need to get the

'my first line

my second line'

in my var_variable variable, if possible, of course.

Thanks.

0 Kudos

Okay, in this case notepad should display the downloaded text as you wish.

(But same result can be achieved by inserting two lines in DATA_TAB parameter and setting parameter WRITE_LF too.)

Regards,

Raymond

0 Kudos

I'm using notepad to see the downloaded text but I only see the first line..

Any suggestion why I don't see the second line?

0 Kudos

Hi,

As mentioned, you can simply add two records as well in internal table and use write_lf = 'X' in gui_download.

lv_string = 'First line'.
append lv_string to lt_string.

lv_string = 'Second line'.

append lv_string to lt_string.

  cl_gui_frontend_services=>gui_download(   EXPORTING   filename  = <lv_filename>

                                             write_lf = 'X'            

                                              filetype  = 'ASC'
                                            changing    data_tab  = lt_string
                                            EXCEPTIONS  ....).

former_member184569
Active Contributor
0 Kudos

data: lv_string(50) type c.

Concatenate : 'My first line' CL_ABAP_CHAR_UTILITIES=>NEWLINE 'My second line' INTO lv_string.


You wont get the output in multi line with WRITE statement, it will give just '##", because, WRITE statement doesn't print this content in the desired way.

You can download that string in the text file to see the output.

former_member184569
Active Contributor
0 Kudos

types l_string(50) type c.

data : lt_string type STANDARD TABLE OF l_string.
  data : lv_string type l_string.

Concatenate : 'My first line' CL_ABAP_CHAR_UTILITIES=>CR_LF 'My second line' INTO lv_string.
append lv_string to lt_string.

  cl_gui_frontend_services=>gui_download(   EXPORTING   filename  = 'C:\Documents and Settings\susmitha\Desktop\test1.txt'
                                              filetype  = 'ASC'
                                            changing    data_tab  = lt_string
                                            EXCEPTIONS  others    = 24        ).