Skip to Content
-2

how to set blank spaces at end of txt file into file system?

Hello guys I need to print blank spaces at end of line on txt file, pleas echeck my code below:


DATA:

     lv_space TYPE string,

     line TYPE string,

     ruta TYPE string.



  ruta = '/tmp/file.txt'.



    line = 'test'.

    lv_space = cl_abap_conv_in_ce=>uccp( '00a0' ).

CONCATENATE line lv_space INTO line.





  OPEN DATASET  ruta FOR OUTPUT IN LEGACY BINARY MODE .



     TRANSFER line TO ruta .



   CLOSE DATASET ruta.

My code works but I have one problem, the space in the file its a extranger character, and I need a space:

If I open from word:

There is any way to put blank spaces on the file correctly without extranger characrers???

captura.png (4.0 kB)
word.png (723 B)
Add a comment
10|10000 characters needed characters exceeded

  • Explanation of the error in your code, for UCCP, you must put letters in UPPER CASE:

    lv_space = cl_abap_conv_in_ce=>uccp( '00A0' ).

    If you use 00a0, you'll get lv_space = NULL character (similar to using 0000)

    If you use a text literal with straight quotes (internal type is then a C type of fixed length), the trailing spaces are ignored during the assignment and evaluations. You must use back quotes (internal type is then a STRING of characters) so that to consider trailing spaces.

Assigned Tags

Related questions

5 Answers

  • Best Answer
    Posted on Oct 22, 2019 at 07:22 PM

    You will get "new line character" for each "TRANSFER LINE" statement. I have executed your code and got only 1 line-feed. That means first row and a blank line, which is correct. Try to remove "WINDOWS LINEFEED" and execute again.

    I do have a question. How are you opening the file? Are you downloading it from any where?

    Thanks,

    Gourab

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 22, 2019 at 05:05 PM

    Hi Luis Roberto Franco,

    I can see you are only transferring text(.txt) to application server(t-code: AL11). So, you have to use "TEXT MODE" instead of "BINARY MODE". Below code for your reference. Binary mode is used to transfer binary data to application mode, for example, if you want to upload a text document from "GUI" and want to save it in AL11.

    DATA:
     lv_space TYPE string,
     line TYPE string,
     ruta TYPE string.
    
    ruta = '/tmp/file.txt'.
    line = 'test'.
    CONCATENATE line lv_space INTO line.
    OPEN DATASET  ruta FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    TRANSFER line TO ruta .
    CLOSE DATASET ruta.

    Cheers!

    Gourab

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 22, 2019 at 05:58 PM

    Gourab Dey

    I have modified my code :

    DATA:
    
         line     TYPE string,
         ruta     TYPE string.
      ruta = '/tmp/file.txt'.
    
      line = 'test'.
    
    DO 3 TIMES.
     CONCATENATE line ` `   INTO line.
    
    ENDDO.
    
    
    OPEN DATASET  ruta  FOR OUTPUT IN TEXT MODE ENCODING DEFAULT WITH WINDOWS LINEFEED.
    
         TRANSFER line TO ruta .
    
       CLOSE DATASET ruta.

    And now Works, put space correctly but now I have other problem, the file its begin generated with 2 more line emptys, and I need only one:

    I need only one line I dont know why I have 3 lines


    fiel.png (9.6 kB)
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 22, 2019 at 09:48 PM

    You are execute the same code? I cant beleve that, I download my fiel from a z program, this z program allows navigate from file system, and download or upload file or directories, I select my file and press on download:

    I only select the directory where I want to save and change file format to ASC


    download.png (47.1 kB)
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 22, 2019 at 11:30 PM
    -1

    I openend the file from other computer in notepad and I see only two ros, first row with data and second tow empty,

    If I open in my computer I see one row with data and two and three row empty, wathever I need one instruction to delete emptys row or I donk know what I need to do. Any Idea?

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.