Skip to Content
avatar image
Former Member

Problem with writing a structure to file - trailing spaces are lost

Hi Experts,

I have the following requirement. I have a fairly large structure with the fields of CHAR type (but of the different length). Let's say the structure is as follows (simplified for a clarity):

 TYPES: BEGIN OF l_typ_file_row,
          field1(4)          TYPE c,
          field2(10)         TYPE c,
          field3(6)          TYPE c,
        END OF l_typ_file_row.

Then I want to write the content of the structure to the file as a single line, but I need that the line had always fixed length, i.e. (4106)=20 characters (independent of the content of the fields - e.g. if field3 was empty, I would like to have 6 spaces at the end of the line).

To save the file I use the code like the following:

DATA:  ls_dxrawdata TYPE dxrawdata, 
       lt_dxrawdata TYPE STANDARD TABLE OF dxrawdata, 
       ls_single_row TYPE l_typ_file_row.
ls_single_row-field1 = 'abcd'.
ls_single_row-field2 = '0123456789'.
ls_single_row-field3 = '      '.          "six spaces
ls_dxrawdata-data = ls_single_row.
*   Upload to application server
       filename            = lv_filename
       pc                  = ''
       data_tab            = lt_dxrawdata.

Unfortunately the line has only 14 characters - trailing spaces are lost. If I would add another field, e.g. field4 of the type CHAR1 and filled it with e.g. ';' - then the spaces in field3 would be preserved. But I cannot use such a solution, because I have a strictly defined format of the file line.

Do you have any idea how to solve the problem?

I would be very grateful for any suggestions.

Best regards,

Adam Sas

Edited by: AdamSas on Apr 8, 2010 10:38 PM

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • Apr 08, 2010 at 08:54 PM

    Don't have access to a system now, so guessing a little bit.

    For CHAR fields, trailing spaces would be sent to the file, for string fields, trailing spaces are truncated, as far as I remember. So either the move to ls_dxrawdata-data or the function DX_FILE_WRITE is moving the data to a string type field and so the spaces are lost.

    Try writing ls_single_row directly to the file via OPEN DATASET and TRANSFER statements.


    Add comment
    10|10000 characters needed characters exceeded

  • Apr 08, 2010 at 09:05 PM

    even me too dont have a system with me 😊

    Can you please try this

    ls_single_row-field1 = 'abcd'.

    ls_single_row-field2 = '0123456789'.

    ls_single_row-field3 = ' '. "six spaces

    call method cl_abap_container_utilities=>fill_container_c


    im_value = ls_single_row


    ex_container = ls_dxrawdata-data


    illegal_parameter_type = 1

    others = 2.


    loop at lt_dxrawdata into ls.

    transfer ls to lv_dos.



    Also go through this thread once link:add-trailing-spaces-to-a-text;

    Edited by: Keshav.T on Apr 9, 2010 2:35 AM

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 08, 2010 at 09:06 PM

    I have checked the option with OPEN DATASET and TRANSFER statements as well.

    Unfortunately it doesn't help.

    Add comment
    10|10000 characters needed characters exceeded