Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

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
   CALL FUNCTION 'DX_FILE_WRITE'
     EXPORTING
       filename            = lv_filename
       pc                  = ''
     TABLES
       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

Former Member
Not what you were looking for? View more on this topic or Ask a question