‎2020 Nov 19 6:04 PM
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
‎2020 Nov 19 6:11 PM
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
‎2020 Nov 19 8:15 PM
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.
‎2020 Nov 20 5:49 AM
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?
‎2020 Nov 20 8:23 AM
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.
‎2020 Nov 20 8:25 AM
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?
‎2020 Nov 20 3:10 PM
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
‎2020 Nov 20 3:26 PM
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,