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: 

gui_download issue - trailing spaces getting truncated for fixed length fil

Former Member
0 Kudos

Hi All,

I have a requirement where I need to download an internal table as a fixed length file.

The code is as follows:

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

BIN_FILESIZE =

FILENAME = L_FILE

FILETYPE = 'ASC'

APPEND = 'X'

WRITE_FIELD_SEPARATOR = ' '

HEADER = '00'

TRUNC_TRAILING_BLANKS = ' '

WRITE_LF = ' '

COL_SELECT = ' '

COL_SELECT_MASK = ' '

DAT_MODE = ' '

IMPORTING

FILELENGTH =

TABLES

DATA_TAB = IT_TEXT

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6

HEADER_NOT_ALLOWED = 7

Each row in the internal table IT_TEXT is 242 chars long.

The FM is truncatinf the trailing blanks on the file. How do I get the FM to not truncate the trailing blanks in each row?

My internal table has multiple rows and the number of rows on the table should be same as the number of rows on the downloaded file.

I tried setting the WRITE_LF parameter to space.

In this case, the trailing spaces are not truncated(which is as per my requirement), BUT all the rows in the internal table appear in a single line on the downloaded file instead of multiple rows.

I also tried setting the TRUNC_TRAILING_BLANKS field to space but that does not work either. Spaces at the end of the row are still truncated.

so the requirement is: the spaces at the end of each row should not be truncated and

each row on the internal table should have a corresponding row on the downloaded file.

(it is a fixed length file)

I also tried using the following code

class cl_abap_char_utilities definition load.

DATA: BEGIN OF IT_TEXT OCCURS 0,

TEXT(242) TYPE C,

cr_lf TYPE c VALUE cl_abap_char_utilities=>cr_lf,

END OF IT_TEXT.

when i compile, i get the following error

The type "CL_ABAP_CHAR_UTILITIES" is unknown.

Im using R/3 4.6C. Could this be a problem?

Please suggest a solution for this problem.

Thanks!

Sandeep

Edited by: sandeep reddy on Jul 25, 2008 7:16 PM

18 REPLIES 18

Former Member
0 Kudos

Hi,

If it is 4.6C,

DATA: BEGIN OF IT_TEXT OCCURS 0,

TEXT(242) TYPE C,

cr_lf TYPE x value '0D', 'zero D for EOL

END OF IT_TEXT.

CL_ABAP_CHAR_UTILITIES does not exist in earlier versions. It is there in ECC6.0

Regadrs,

Subramanian

Edited by: Subramanian PL on Jul 25, 2008 10:35 AM

0 Kudos

Hi Subramanian,

Thank you for the reply.

4.6 C does not allow the CL_ABAP declaration. i know for a fact that 4.7 has it.

I tried what you said but on the file, at the end of the first line, '0D' appears and at the end of the rest of the lines, i get 00.

Is there any way we can keep the spaces and not have '0D' at the end?

Thanks again.

Sandeep

0 Kudos

how did u declare:

cr_lf(2) type x value '0D'.

0 Kudos

This is exactly what i have

DATA: BEGIN OF IT_TEXT OCCURS 0,

TEXT(242) TYPE C,

CR_LF TYPE X VALUE '0D',

END OF IT_TEXT.

If I declare it as CR_LF(2) TYPE X VALUE '0D', 0D00 appear at the end of the first line,

0000 appear at the end of the rest of the lines

Any workaround?

Thanks!

Sandeep

Former Member
0 Kudos

Try filetype 'BIN' instead of 'ASC'.

Brian

Former Member
0 Kudos

Hi,

Try this..

data: CR_LF TYPE X VALUE '0D'.

DATA: BEGIN OF IT_TEXT OCCURS 0,
TEXT(242) TYPE C,
END OF IT_TEXT.

CONCATENATE it_text ' ' separated by CR_LF.

Thanks

Naren

0 Kudos

Hi Naren,

Can you please throw some more light on your code?

CONCATENATE IT_TEXT ' ' (into what) SEPARATED BY CR_LF.

The into clause is missing and hence it is giving me an error.

Do you want me to loop at it_text.

then concatenate it_text-text and spcae sep by CR_LF into itab-text(another table,for example)

append itab.

and then pass this to GUI_DOWNLOAD?

Thanks!

Sandeep

Former Member
0 Kudos

Hi,

Try this...

Instead of enter key..I have changed it to tab..it is working fine..

DATA: BEGIN OF IT_TEXT OCCURS 0,

TEXT(242) TYPE C,

CR_LF TYPE X VALUE '09', " Tab

END OF IT_TEXT.

Thanks

Naren

0 Kudos

Hi Narendran,

When i do this,

DATA: BEGIN OF IT_TEXT OCCURS 0,

TEXT(242) TYPE C,

CR_LF TYPE X VALUE '09',

END OF IT_TEXT.

At the end of the first line on the downloaded file, there is '09' and at the end of subsequent lines there is '00'.

How can I not have the 09 and 00 at the end, but still have the spaces at the end?

Thank you for your inputs.

Sandeep

Former Member
0 Kudos

Hi,

Actually into to the same header line of the internal table..

Please ignore that reply and check my last reply using hexadecimal for tab.

Thanks

Naren

Former Member
0 Kudos

I just add a literal like ';' in the last column of the record and then it won't truncate.

Former Member
0 Kudos

I just add a literal like ';' in the last column of the record and then it won't truncate.

0 Kudos

Hi Richard,

I put a period at the end of each row of the internal table and when i download the file, the spaces are not getting truncated. So far so good. However, I am not sure if the file can have the '.' at the end.

Is there any other way I can have the spaces but not the special chars or literals?

Thank you for your time!

Sandeep

0 Kudos

In the program attributes is the unicode check box active ?

if yes please remove the check and run the code .

Former Member
0 Kudos

Hi,

Not sure why it is putting 09 at the end of the file..Please check this sample code..And I am not getting 09 in the file at the end..

PARAMETERS: p_file TYPE rlgrap-filename
            default 'c:\test_download.txt'.

DATA: BEGIN OF s_data,
        data TYPE char10,
        cr_lf(2) TYPE x VALUE '09',
      END OF s_data.

DATA: t_data LIKE TABLE OF s_data.

s_data-data = 'Test'.APPEND s_data TO t_data.
s_data-data = 'Test2'.APPEND s_data TO t_data.
s_data-data = 'Test3'.APPEND s_data TO t_data.
s_data-data = 'Test4'.APPEND s_data TO t_data.

* Download.
DATA: v_file TYPE string.
v_file = p_file.
CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
    filename                = v_file
  TABLES
    data_tab                = t_data
  EXCEPTIONS
    file_write_error        = 1
    no_batch                = 2
    gui_refuse_filetransfer = 3
    invalid_type            = 4
    no_authority            = 5
    unknown_error           = 6
    header_not_allowed      = 7
    separator_not_allowed   = 8
    filesize_not_allowed    = 9
    header_too_long         = 10
    dp_error_create         = 11
    dp_error_send           = 12
    dp_error_write          = 13
    unknown_dp_error        = 14
    access_denied           = 15
    dp_out_of_memory        = 16
    disk_full               = 17
    dp_timeout              = 18
    file_not_found          = 19
    dataprovider_exception  = 20
    control_flush_error     = 21
    OTHERS                  = 22.

Thanks

Naren

0 Kudos

Hi Naren,

I copy pasted your code and ran the program and this is the output i got

Test 0900

Test2 0900

Test3 0900

Test4 0900

I am using R/3 4.6C. Is there a chance the FM is not recognizing the actual purpose of the hex declaration?

Appreciate your help.

Thanks!

Sandeep

Former Member
0 Kudos

Hi,

Try this..This worked..Add a dummy character at the end of the internal table...Then pass trunc_trailing_blanks = ' '...

PARAMETERS: p_file TYPE rlgrap-filename
            DEFAULT 'c:\test_download.txt'.

DATA: BEGIN OF s_data,
        data TYPE char10,
        dummy,      " Added this.
      END OF s_data.

DATA: t_data LIKE TABLE OF s_data.

s_data-data = 'Test'.
APPEND s_data TO t_data.

s_data-data = 'Test2'.
APPEND s_data TO t_data.

s_data-data = 'Test3'.
APPEND s_data TO t_data.

s_data-data = 'Test4'.
APPEND s_data TO t_data.

* Download.
DATA: v_file TYPE string.
v_file = p_file.
CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
    filename                = v_file
    trunc_trailing_blanks   = ' '
  TABLES
    data_tab                = t_data
  EXCEPTIONS
    file_write_error        = 1
    no_batch                = 2
    gui_refuse_filetransfer = 3
    invalid_type            = 4
    no_authority            = 5
    unknown_error           = 6
    header_not_allowed      = 7
    separator_not_allowed   = 8
    filesize_not_allowed    = 9
    header_too_long         = 10
    dp_error_create         = 11
    dp_error_send           = 12
    dp_error_write          = 13
    unknown_dp_error        = 14
    access_denied           = 15
    dp_out_of_memory        = 16
    disk_full               = 17
    dp_timeout              = 18
    file_not_found          = 19
    dataprovider_exception  = 20
    control_flush_error     = 21
    OTHERS                  = 22.

Thanks

Naren

Former Member

Hi there, I know it's quite old post but I would like to post my solution in case of anyone needed.

Please add the following parameter.

TRUNC_TRAILING_BLANKS_EOL   = ' '

As per its documentation.

FU GUI_DOWNLOAD                   TRUNC_TRAILING_BLANKS_EOL

____________________________________________________

Short Text

Removes spaces at end of last column

Description

By default, possible blanks at the end of a text column are not transferred. You can use this parameter to change this behavior for the last column of the table so that the blanks are kept. The parameter does not influence the other columns of the table. To keep them, use parameter TRUNC_TRAILING_BLANKS.

Value range

'X': Blanks in the last column are removed.

SPACE: Blanks in the last column are transferred.

Default

'X'

Function Module

GUI_DOWNLOAD