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

Program to create .CSV file in Background mode

ricky_shaw
Contributor
0 Likes
3,550

Hi Experts,

I need to create a .CSV file when running my program in background.

I did google search also but there is no staight forward answer. I am only seeing answer for foreground.

Can anyone please tell me.

Thanks

7 REPLIES 7
Read only

abo
Active Contributor
2,676

There is nothing special to a CSV file: just open a file in text mode and write to it.

On the other hand, if you wish to write a proper Excel (non CSV) file in background, I suggest that you check out abap2xlsx

Read only

Sandra_Rossi
Active Contributor
0 Likes
2,676

In background mode, you cannot write file to foreground.

Workaround: store file in the server, and give user a custom app to retrieve this file from the server.

As simple as that.

Read only

ricky_shaw
Contributor
0 Likes
2,676

Hi Again,

I am actually loop at my itab & using concatenating the fields separated by ','.

I can see the file in Al11 and then i had to download the file as .CSV.

Is this the right approach?

Code Snippet below:

DATA : filename(128) TYPE c VALUE '/sapxchange/IS/ce/out/reg.csv',

DATA : lv_str TYPE string, ls_datatab(600).

OPEN DATASET filename FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
CONCATENATE 'Header' 'Pay ConnexionLoad' '20190802' 'IPM' 'PAY' INTO lv_str SEPARATED BY ','.
TRANSFER lv_str TO filename.

CONCATENATE 'UserProfile' '1236173000' 'JONES FAMILY LLC' INTO lv_str SEPARATED BY ','.
CLEAR lv_str.
CLOSE DATASET filename.

After downloading i am seeing the File name & Directory details on top 2 rows on left hand side of the file. How can i eliminate this as well?

Read only

2,676

Please use the COMMENT button for comments, questions, adding details, replying to OP comment, etc., ANSWER is only to propose a solution, dixit SAP text at the right of the answer area.

Read only

Sandra_Rossi
Active Contributor
0 Likes
2,676

I don't understand your question. If you know what a CSV file is, then I don't see any difficulty in generating one? Or is it a question just about writing a file to AL11 with OPEN DATASET, TRANSFER and so on?

Read only

ricky_shaw
Contributor
2,676

Obviously i am asking about writing a .CSV file to AL11 with OPEN DATASET, TRANSFER and open it as .CSV..

There is no rocket science in it. lol

Read only

MateuszAdamus
Active Contributor
0 Likes
2,676

Hello ricky.shaw

Here are some posts about creating a CSV file from internal table:

https://answers.sap.com/questions/1822772/how-to-create-csv-file.html

https://blogs.sap.com/2014/09/09/understanding-csv-files-and-their-handling-in-abap/

From the second one you can take, that there is a class designed for handling a CSV file creation/read. This class is called CL_RSDA_CSV_CONVERTER. Using its method STRUCTURE_TO_CSV you can create a CSV line from a structure without worrying about value with double quotes or commas.

Then write the string value to a file on your server and you're done.

Kind regards,
Mateusz