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

CSV file issue

Former Member
0 Likes
386

i need to write internal table data into a CSV file and then put CSV file into application server and then my infopackage will read from the application server. Now i have my data in the internal table i have to write those records to a CSV file in the application server. I checked if there are any Function modules to convert internal table to .CSV file. The function module "sap_convert_to_csv_format" is not available in SAP BI server any other alternatives available.

The code that i used to create the file in application server is given below, please let me know if its fine.

REPORT Z_SAP_CONVERT_TO_CSV_FORMAT.

DATA : BEGIN OF XX,

NODE_ID TYPE N LENGTH 8,

INFOOBJECT TYPE C LENGTH 30,

NODENAME TYPE C LENGTH 60,

PARENT_ID TYPE N LENGTH 8,

END OF XX.

DATA : I_TAB LIKE STANDARD TABLE OF XX.

DATA: FILE_NAME TYPE RLGRAP-FILENAME.

FILE_NAME = './temp.CSV'.

OPEN DATASET FILE_NAME FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = '5'

IMPORTING

OUTPUT = XX-NODE_ID.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = 'ZEMP_H'

IMPORTING

OUTPUT = XX-INFOOBJECT.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = '5'

IMPORTING

OUTPUT = XX-NODENAME.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = '1'

IMPORTING

OUTPUT = XX-PARENT_ID.

APPEND XX TO I_TAB.

CLEAR XX.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = '6'

IMPORTING

OUTPUT = XX-NODE_ID.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = 'ZEMP_H'

IMPORTING

OUTPUT = XX-INFOOBJECT.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = '6'

IMPORTING

OUTPUT = XX-NODENAME.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = '1'

IMPORTING

OUTPUT = XX-PARENT_ID.

APPEND XX TO I_TAB.

LOOP AT I_TAB INTO XX.

TRANSFER XX TO FILE_NAME.

ENDLOOP.

CLOSE DATASET FILE_NAME.

Do i need to put any character for "data separtor" and "escape sign"?

Moderator message : Duplicate post locked.

Warning : Non-adherence of forum rules will lead to deletion of user-id.

Edited by: Vinod Kumar on Sep 8, 2011 4:07 PM

1 REPLY 1
Read only

Former Member
0 Likes
305

Hi,

CSV file means file having comma seperated values. You dont have to convert anything. Just open a .CSV file and transfer comma seperated values into it.

Keep semicolon ( as seperator for each field in same row. And then transfer this to the file opened. This will solve the problem.

In your case

LOOP AT I_TAB INTO XX.
CONCATENATE xx-field1 xx-field2........ INTO wa_data SEPERATED BY ';'.
TRANSFER wa_data TO FILE_NAME.
ENDLOOP.