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

Error when transferring table data to a CSV format file.

Former Member
0 Likes
712

Hi

I am getting an error when I am passing the parameter value for the file name from the selection screen. If i hard code the path and name it works fine. can any one help me please. here is my code:

PARAMETERS: OUTFILE LIKE dxfile-filename

DEFAULT 'C:\Apositivepay.txt',

RUNDATE LIKE PAYR-LAUFD,

Bank LIKE T012K-HBKID. "List of Possible Banks

...

type-pools:TRUXS.

DATA: BEGIN OF OUTPUT_REC OCCURS 0, "Output file for USBANK

ACCT(12), "bank account no

...

Payee2(40) type c, "payee 2

END OF OUTPUT_REC.

data: itab1 type TRUXS_T_TEXT_DATA.

...

...

CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'

EXPORTING

I_FIELD_SEPERATOR = ','

TABLES

I_TAB_SAP_DATA = OUTPUT_REC

CHANGING

I_TAB_CONVERTED_DATA = itab1

EXCEPTIONS

CONVERSION_FAILED = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

      • filename = OUTFILE "This doesn't work

filename = 'C:\Apositivepay.txt' "This works

TABLES

DATA_TAB = itab1

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_WRITE_ERROR = 2

INVALID_FILESIZE = 3

INVALID_TABLE_WIDTH = 4

INVALID_TYPE = 5

NO_BATCH = 6

UNKNOWN_ERROR = 7

OTHERS = 8.

Message was edited by: Anwarul Kabir

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
657

<b>data: v_outputfile type string.

v_outputfile = OUTFILE.</b>

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

<b>filename = v_OUTputFILE</b>

TABLES

DATA_TAB = itab1

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_WRITE_ERROR = 2

INVALID_FILESIZE = 3

INVALID_TABLE_WIDTH = 4

INVALID_TYPE = 5

NO_BATCH = 6

UNKNOWN_ERROR = 7

OTHERS = 8.

Make the highlighted changes

Message was edited by: Ravi Kanth Talagana

4 REPLIES 4
Read only

Former Member
0 Likes
658

<b>data: v_outputfile type string.

v_outputfile = OUTFILE.</b>

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

<b>filename = v_OUTputFILE</b>

TABLES

DATA_TAB = itab1

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_WRITE_ERROR = 2

INVALID_FILESIZE = 3

INVALID_TABLE_WIDTH = 4

INVALID_TYPE = 5

NO_BATCH = 6

UNKNOWN_ERROR = 7

OTHERS = 8.

Make the highlighted changes

Message was edited by: Ravi Kanth Talagana

Read only

0 Likes
657

Thanks its working now.

But another problem I am noticing now. Which is my I_TAB is holding an extra blank row. so the output is putting an extra smi-colon at the end. Any solutions for that? and also its putting smi-colon though I used coma to separate them? Is there anything else I need to do in order to have the coma as a separator instead of smi-colon?

Thanks

Read only

Former Member
0 Likes
657

Hi

try this:

<b>DATA: FILENAME TYPE STRING.

MOVE OUTFILE TO FILENAME.</b>

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

<b>filename = FILENAME</b>

TABLES

DATA_TAB = itab1

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_WRITE_ERROR = 2

INVALID_FILESIZE = 3

INVALID_TABLE_WIDTH = 4

INVALID_TYPE = 5

NO_BATCH = 6

UNKNOWN_ERROR = 7

OTHERS = 8.

Max

Read only

Former Member
0 Likes
657

hi,

use this code and save that file in CSV format it will work

OPEN DATASET P_IFILE FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF SY-SUBRC NE 0.

MESSAGE E000 WITH 'Problem in opening Application Server file'.

ELSE.

DO.

READ DATASET P_IFILE INTO IT_UPLOAD.

IF SY-SUBRC NE 0.

EXIT.

ELSE.

APPEND IT_UPLOAD.

CLEAR IT_UPLOAD.

ENDIF.

ENDDO.

CLOSE DATASET P_IFILE.

ENDIF.

IF IT_UPLOAD[] IS INITIAL.

MESSAGE E000 WITH 'NO data in the file/upload problem'.

ENDIF.

LOOP AT IT_UPLOAD.

SPLIT IT_UPLOAD AT ','

INTO

IT_FDATA-MATNR

IT_FDATA-WERKS.

  • IT_FDATA-SLGORT.

APPEND IT_FDATA.

CLEAR IT_FDATA.

ENDLOOP.

IT_TOTAL1[] = IT_FDATA[].