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

PROBLEM CREATING FILE WITH CRLF AND WHITESPACES

Former Member
0 Likes
1,566

Hi to all

I have the following problem:

I need create a file, where all the registers have white spaces in the end of the each register. Each record must be 320 characters in length.

In the end, I need put white spaces (sometimes small, sometimes many), until comple the lenght

But, this white spaces,.are not reflected in the file created.,. the length reaches where there is information.

I put the attribute: cl_abap_char_utilities=>cr_lf, but this character make the following in my file:

REGISTER1

REGISTER2

REGISTER3

ie, leave a blank line between each record.

Please, say me what is the better form that solve this issue

Thank you

regards

Dario

Hi to all

I have the following problem:

I need create a file, where all the registers have white spaces in the end of the each register. Each record must be 320 characters in length.

In the end, I need put white spaces (sometimes small, sometimes many), until comple the lenght

But, this white spaces,.are not reflected in the file created.,. the length reaches where there is information.

I put the attribute: cl_abap_char_utilities=>cr_lf, but this character make the following in my file:

REGISTER1

REGISTER2

REGISTER3

ie, leave a blank line between each record.

Please, say me what is the better form that solve this issue

Thank you

regards

Dario

9 REPLIES 9
Read only

Former Member
0 Likes
1,442

hi,

try using offset to while placing the cl_abap_char_utilities=>cr_lf. this might help you.

Read only

0 Likes
1,442

Hi

But when I use cl_abap_char_utilities=>cr_lf, this character make the following in my file:

REGISTER1

REGISTER2

REGISTER3

ie, leave a blank line between each record.

How do I prevent this line blank ?

Thnak you !

Regards

Dario

Read only

0 Likes
1,442

Hi,

If you are transfering the content to the file line by line, then you dont need to put the carriage return ( cl_abap_char_utilities=>cr_lf ). Each line of the internal table will be created on a new line.

regards,

Advait

Read only

Former Member
0 Likes
1,442

Hi ,

Try with below code.


TYPES:
  BEGIN OF t_test,
    eno TYPE char5,
    ename TYPE char10,
    END OF t_test.

DATA:
  i_test TYPE TABLE OF t_test WITH HEADER LINE.

**--Append records
i_test-eno = '100'.
i_test-ename = 'ABC'.
APPEND i_test.
CLEAR i_test.

i_test-eno = '101'.
i_test-ename = 'XYZ'.
APPEND i_test.
CLEAR i_test.

* These two calls are necessary so that trailing
* spaces are not cut at the end of every line.
  PERFORM set_trail_blanks(saplgrap) USING 'X'.

  CALL FUNCTION 'HR_99S_DOWNLOAD'
   EXPORTING
*   P_BIN_FILESIZE                =
     p_initial_directory           = 'H:test1.txt'
*   P_FILENAME                    = p_file+3(lv_str)
     p_filetype                    = 'ASC'
*   P_WRITE_LF                    =
     p_fsdialog                    = space
     p_append                      = space
*   P_ITEM                        = ' '
* IMPORTING
*   P_FILELENGTH                  =
*   P_FULLPATH                    =
    TABLES
      data_tab                      = i_test
   EXCEPTIONS
     file_save_dialog              = 1
     file_write_error              = 2
     no_batch                      = 3
     gui_refuse_filetransfer       = 4
     invalid_type                  = 5
     unknown_error                 = 6
     wrong_tab_format              = 7
     OTHERS                        = 8
            .

  PERFORM set_trail_blanks(saplgrap) USING ' '.

Read only

Former Member
0 Likes
1,442

hi

use the import parameters for gui_download

TRUNC_TRAILING_BLANKS

or

TRUNC_TRAILING_BLANKS_EOL

to retain the trailing blanks

Read only

0 Likes
1,442

Hi to all

I have done that you sugget, but the result is the following:

REGISTER1

REGISTER2

REGISTER3

How Do it, by all the registers start always in the left ?

Hoiw Do it, by make this in the SAP server ?

Thank you very much

Regards

Dario

Read only

0 Likes
1,442

Hi

With:

TRUNC_TRAILING_BLANKS = 'X'

TRUNC_TRAILING_BLANKS_EOL = 'X'

I can view the result that I need !!

But, now the question is: How I make the same, but creating the file in the application server ?

Thank you very much

Regards

Dario

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,442

Hello Dario,

After reading your problem i understand you need to keep the blanks & each register value will have 320 characters.


TYPES:
BEGIN OF ty_file,
  data TYPE string,
END OF ty_file.

DATA: 
it_file TYPE STANDARD TABLE OF ty_file,
wa_file TYPE ty_file.

LOOP AT it_final.
  wa_file-data = wa_final.
  wa_file+320(2) = cl_abap_char_utilities=>cr_lf.

  APPEND wa_file TO it_file.
ENDLOOP.

This is a sample code. The idea is to create an internal table of TYPE string & use cl_abap_char_utilities=>cr_lf at 320th position.

BR,

Suhas

Read only

Former Member
0 Likes
1,442

Hi Suhas

Thank you for your help.

But, I follow your instructions but the rsult is the same.

The mini program that I created is the following:

TYPES:

BEGIN OF ty_file,

data(32),

END OF ty_file.

DATA:

it_file TYPE STANDARD TABLE OF ty_file WITH HEADER LINE,

it_final TYPE STANDARD TABLE OF ty_file WITH HEADER LINE,

wa_file TYPE ty_file.

LOOP AT it_file.

wa_file-data = it_file-data.

wa_file-data+30(2) = cl_abap_char_utilities=>cr_lf.

APPEND wa_file TO it_final.

ENDLOOP.

OPEN DATASET name_archivo FOR OUTPUT IN TEXT MODE ENCODING default.

LOOP AT it_final.

length = STRLEN( it_final-data ).

TRANSFER it_final-data TO name_archivo LENGTH length.

ENDLOOP.

CLOSE DATASET name_archivo.

This code create a file with the following registers:

Reg1 #

Reg2 #

Reg3 #

If I use the data type String of the field Data, in the structure ty_file, I can´t doit the sentence: wa_file-data+30(2) = cl_abap_char_utilities=>cr_lf.

Please, tell me what is the best form, by in the file don´t appear one register in blank

Thank you very much

regards

Dario.