Convert lines of itab into csv
Hi!
I have an itab with many lines and want to save this itab to a file as csv. That means, that the fields of the structure the table consists of should be separated by a comma, not the lines!
I found the solution in this forum, the function 'SAP_CONVERT_TO_CSV_FORMAT' should do this!
But on our system this function is missing!? Is there a class which can do this conversion?
Thanks
Manfred
Edited by: Manfred Fettinger on Sep 18, 2009 2:37 PM
Hi
Which is your release?
Anyway this is a method I've developed for my reports:
CLASS LC_FILE DEFINITION.
CLASS-METHODS: INSERT_SEPARATOR_CHAR
IMPORTING
SEPARATOR TYPE STRING
RECORD_IN TYPE ANY
NO_GAPS TYPE C DEFAULT SPACE
EXPORTING
RECORD_OUT TYPE STRING.
ENDCLASS.
.CLASS LC_FILE IMPLEMENTATION.
METHOD INSERT_SEPARATOR_CHAR.
FIELD-SYMBOLS: <FS_FIELD> TYPE ANY.
DATA: WA_STRING(10000) TYPE C,
WA_VALUE(1000) TYPE C.
DATA: LEN_SEPAR TYPE I,
LEN_FIELD TYPE I,
LEN_STRING TYPE I,
LEN_VALUE TYPE I.
DATA: TYPE_FIELD TYPE C.
LEN_SEPAR = STRLEN( SEPARATOR ).
DO.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE RECORD_IN TO <FS_FIELD>.
IF SY-SUBRC <> 0. EXIT. ENDIF.
* DESCRIBE FIELD <FS_FIELD> LENGTH LEN_FIELD IN CHARACTER MODE
* TYPE TYPE_FIELD.
DESCRIBE FIELD <FS_FIELD> LENGTH LEN_FIELD IN BYTE MODE
TYPE TYPE_FIELD.
IF TYPE_FIELD = 'g'.
LEN_FIELD = STRLEN( <FS_FIELD> ).
ENDIF.
CLEAR WA_VALUE.
WRITE: <FS_FIELD> TO WA_VALUE(LEN_FIELD),
<FS_FIELD> TO WA_STRING+LEN_STRING(LEN_FIELD).
LEN_VALUE = STRLEN( WA_VALUE ).
IF NOT NO_GAPS IS INITIAL.
LEN_FIELD = LEN_VALUE.
ENDIF.
LEN_STRING = LEN_STRING + LEN_FIELD.
WRITE: SEPARATOR(LEN_SEPAR) TO WA_STRING+LEN_STRING.
LEN_STRING = LEN_STRING + LEN_SEPAR.
ENDDO.
LEN_STRING = STRLEN( WA_STRING ).
MOVE WA_STRING(LEN_STRING) TO RECORD_OUT.
ENDMETHOD. "INSERT_SEPARATOR_CHAR
ENDCLASS.
Some stataments are adjusted for rel ECC 6.00
Max
Similar Messages
-
Converting PIX/ASA logs into CSV
I work as a network forensics analyst for a gov't agency. We are getting large amounts of PIX and ASA logs being pushed to our Syslog server. I'm trying to create a script to parse/convert the standard PIX/ASA logs into CSV files in order to assist with integration to other products. Has anyone had success with this, or have a perl / shell script(awk grep, etc) written for this task? I would like to capture as much data as possible.
What syslog server are you using? The free kiwi syslog has an option to spin a new file based on the time or day to a text file automatically which can be archived later. Seems like kiwi can export in .csv format. http://www.kiwisyslog.com/help/syslogwebaccess/index.html?export_to_csv.htm
-KS -
Hello,
Can somebody suggest me how to read from an excel file (consisting of 10 work sheets) to an array?
Thanks,
SheYou have to be careful when using the spreadsheet-files vi's. They are located in the Functions Palette under File IO, you will find "Write To / Read From Spreadsheet File.vi"s.
Here is what the Context Help says about the vi function:
"Reads a specified number of lines or rows from a numeric text file beginning at a specified character offset and converts the data to a 2D, single-precision array of numbers. You optionally can transpose the array. The VI opens the file before reading from it and closes it afterwards. You can use this VI to read a spreadsheet file saved in text format. This VI calls the Spreadsheet String to Array function to convert the data. "
This is quick & easy when the spreadsheet is all the same format. You can set the format to string as well. HOWEVER... you do have to convert the Excel spreadsheet to text before using it.
I haven't experimented with the Active-X, but it may look as the way to go if you have combination text / numeric values in the spreadsheet.
If you did convert it to text, then you can use array functions as well and treating the file as an array of strings (see very brief example attached). The example is to illustrate a point only
JLV
Attachments:
starting point for spreadsheet.vi 28 KB -
Converting .xls sheet into .csv sheet
Dear All,
Is there any program available which will convert an excel sheet into .csv sheet.
If anyone has worked on this then please forward me the code for the same.
Regards,
N.JainHi Nishu,
Use the following code
data: fname type string value 'C:\file.csv'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = fname.
FILETYPE = 'ASC'
WRITE_FIELD_SEPARATOR = ','
TABLES
DATA_TAB = itab
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
Here above declare file variable fname of type string and pass the file path. In the function module 'itab' is the internal table where you have data that needs to be exported to .csv file and make sure that you have given WRITE_FIELD_SEPARATOR = ',' which is comma separator.
Here I am assuming that you have taken data from excel sheet to internal table 'itab' using Santhosh posting message.
Regards,
yellappa.
Edited by: yellappa m on Feb 8, 2008 12:07 PM -
How to convert from line chart data to CSV format
Hi ,
I am using Flex 3 and AS.
I am getting data from MS SQL and display the data as line
chart this is ok.
But i want to convert this line chart data to CSV or .xsl
format.I find one example in fourms the from data grid to CSV
For this URL is
http://www.abdulqabiz.com/blog/archives/flash_and_actionscript/datagriddataexporter.php
But i want Line chart to CSV.Please help me.Line chart is a just a visual representation of some data
that's sitting in your database. Isn't it? You load this in Flex,
probably using HTTPService class, and pass it to some chart object.
Now when use says that she needs it in CSV format, you're
gonna have to send another request to the server to produce the
same data, convert into CSV or XLS format and let user download it.
Of course, if use doesn't want to download, you don't have to
go to the server, at least for CSV format. You can convert the same
data that used plot the chart to convert to CSV.
Am I missing something here?
ATTA -
Converting excel source into csv format
Hi,
I have to convert excle source into csv format.
my excel source has around 40000 records.
Please give me the suggestions how to do it.
Thanks,
VenkatOr, if this is going to be an ongoing issue with new files needing to be converted, there are several utilities out there of various quality and price which can be considered. A quick google turned up a whole host of options for various platforms.
I can't comment on any of them as I haven't used them, but clearly there are several converters with command-line interfaces which should be capable to be utilized as an external command in your process flow.
Like: http://www.softinterface.com/Convert-XLS/Features/Convert-XLS-To-CSV.htm
Heck, if you really want to have fun and DIY, I know that there are native Perl Excel modules, so you could always build your own and make it cross-platform! -
Problem in converting table data into CSV file
Hi All,
In my Process i need to convert my error table data into csv file,my data is converted as csv file by using OdisqlUnload function,but the column headers are not converted,i use another procedure for converting column headers but iam getting below error ...
com.sunopsis.sql.SnpsMissingParametersException: Missing parameter string.find, string.find
SQL: import string import java.sql as sql import java.lang as lang import re sourceConnection = odiRef.getJDBCConnection("SRC") output_write=open('C:/Oracle/Middleware/Oracle_ODI2/oracledi/pro/PRO.txt','r+') myStmt = sourceConnection.createStatement() my_query = "select * FROM E$_LOCAL_F0911Z1" my_query=my_query.upper() if string.find(my_query, '*') > 0: myRs = myStmt.executeQuery(my_query) md=myRs.getMetaData() collect=[] i=1 while (i <= md.getColumnCount()): collect.append(md.getColumnName(i)) i += 1 header=','.join(map(string.strip, collect)) elif string.find(my_query,'||') > 0: header = my_query[7:string.find(my_query, 'FROM')].replace("||','||",',') else: header = my_query[7:string.find(my_query, 'FROM')] print header old=output_write.read() output_write.seek(0) output_write.write (header+'\n'+old) sourceConnection.close() output_write.close()
And i used below code for converting.......
import string
import java.sql as sql
import java.lang as lang
import re
sourceConnection = odiRef.getJDBCConnection("SRC")
output_write=open('C:/Oracle/Middleware/Oracle_ODI2/oracledi/pro/PRO.txt','r+')
myStmt = sourceConnection.createStatement()
my_query = "select FROM E$_COMPANY"*
*my_query=my_query.upper()*
*if string.find(my_query, '*') > 0:*
*myRs = myStmt.executeQuery(my_query)*
*md=myRs.getMetaData()*
*collect=[]*
*i=1*
*while (i <= md.getColumnCount()):*
*collect.append(md.getColumnName(i))*
*i += 1*
*header=','.join(map(string.strip, collect))*
*elif string.find(my_query,'||') > 0:*
*header = my_query[7:string.find(my_query, 'FROM')].replace("||','||",',')*
*else:*
*header = my_query[7:string.find(my_query, 'FROM')]*
*print header*
*old=output_write.read()*
*output_write.seek(0)*
*output_write.write (header+'\n'+old)*
*sourceConnection.close()*
*output_write.close()*
Any one can you help regarding this
Edited by: 30021986 on Oct 1, 2012 6:04 PMThis may not be an option for you but in pinch you may want to consider outputing your data to an MS Spreadsheet, then saving it as a CSV. It's somewhat of a cumbersome process, but it will get you by for now.
You will need to change your content type to application/vnd.ms-excel.
<% response.setContentType("application/vnd.ms-excel"); %> -
How do I convert a .pub file into a PDF, 2 page spread without the dotted line down the center? I can select 2 page view and cover page in 2 page view, but the dotted line shows up. Thank you!!
Hi skt102711,
I would like to inform you that acrobat doesn't support .epub to .pdf format conversion. Please browse this Link for more information : Supported file formats | Acrobat, Reader
Regards,
Rahul -
How to SAP data convert into csv file.
hi,
i have a one internal table , and i want to extract SAP data into csv file with filed separator ','(comma).
Thanksyou can use this coding for slove yours issue
tables: vbak.
Use type pool:
TYPE-POOLS: TRUXS.
parameters: p_erdat like vbak-erdat.
DATA: COM TYPE C . For comma SEPERATOR
data: begin of itab occurs 0,
vbeln like vbak-vbeln,
erdat like vbak-erdat,
end of itab.
DATA: ITAB1 TYPE TRUXS_T_TEXT_DATA OCCURS 0 .
COM = ','.
select vbeln
erdat
into table itab
from vbak
where erdat = p_erdat.
FM:
CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
EXPORTING
I_FIELD_SEPERATOR = COM
I_LINE_HEADER =
I_FILENAME =
I_APPL_KEEP = ' '
TABLES
I_TAB_SAP_DATA = ITAB
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.
FM:
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE =
FILENAME = 'C:\TEST.CSV'
FILETYPE = 'ASC' -
I create name plaques using TypeStyler, but my laser cutter says they must be converted into two vector files; a cut file to cut the outlines of all the letters and an "etch" to etch the letter intersect lines. Can AI convert my TypeStyler file into a cut file and an etch file?
Thanks. I might use it soon...
Does it automatically make folders named after the volume labels? And does it handle the conversion of spaces and non-alphanumeric characters to octal codes?
I could read the script but it would be faster for everyone reading, if you leave the answer as a reply.
I also think that there should be some major work done on modernizing the fstab, either by replacing it with a better implementation of file system mounting or changing the file structure and adding in better handling of non-alphanumerics. I don't want to have to look up a stupid octal table every time I type in my labels. -
How to convert accdb file of Microsoft access into csv file using java coding. Is there any jar available to do so ?
The JDBC-ODBC Bridge and a FileWriter, and a good amount of program logic both in exporting and in the (I assume eventual) parsing/reloading.
[Character Streams|http://java.sun.com/docs/books/tutorial/essential/io/charstreams.html]
[Lesson: JDBC Basics|http://java.sun.com/docs/books/tutorial/jdbc/basics/index.html]
[Using DSN-less connection|http://www.java2s.com/Code/Java/Database-SQL-JDBC/UsingDSNlessconnection.htm] -
Converting an Excel file into a CSV with the DI API
Hello everyone,
it's my first post and also my first project with SBO, As the topic's header implies I have to write a program which converts an excel sheet into a CSV file, I have been reading a little about the DI API, and I would like to have further information about how to use the DI to access file data and/or alter it, other than what is already listed in the tutorials.
Thanks in advance.Hi Amin,
Unfortunately I am not aware of any way to this using only the DI API, it will be neccesary to include some other APIs or manual work.
Off the top of my head I can only think of two workarounds to this:
- Using the recordset and Excel combined. Read all the data from one column in a table and write it to a column in an Excel file possibly using a loop. Once the process of copying all desired columns and their data is complete, save the file as .csv using the excel API. I'm afraid I don't have an example of this. (It also may be possible using Microsofts SMO or another database API rather than the recordset.)
With this approach the drawback is it might take a long time to figure out and develop in the short term, but in the long term would save alot of manual work as it could be automatic.
- The alternative is unfortunately a manual approach: Simply run a query on the table, and then copy all the values from a column and paste it into the excel file.
This has no short term work but is alot of manual work in the long term.
Hope this is useful,
Regards,
Niall -
XSLT Mapping to convert u201C.CSVu201D file into XML Structure.
Hi All,
I wanted to know can we use XSLT Mapping to convert u201C.CSVu201D file into XML Structure.
I am communicating between two XI Systems. First XI system is going to give u201C.CSVu201D file as main document. I need to post IDOC Corresponding to this. So what I want to do is read this u201C.CSVu201D file (Main document in payload) and first convet it into XML and then use second mapping which will convert XML to IDOC.
I know this is possible with JAVA Mapping but just wanted to confirm can we do this with XSLT mapping as well?
Regards,
GouriHi Amit,
I know this way it shd work as i am able see other XSLT files. But this particular file is not visible.
I am copying following code only in sample.xslt file.
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="fn"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.0" exclude-result-prefixes="xs fn">
<xsl:output indent="yes" encoding="US-ASCII" />
<xsl:param name="pathToCSV" select="'file:///c:/csv.csv'" />
<xsl:function name="fn:getTokens" as="xs:string+">
<xsl:param name="str" as="xs:string" />
<xsl:analyze-string select="concat($str, ',')" regex='(("["]*")+|[,]*),'>
<xsl:matching-substring>
<xsl:sequence select='replace(regex-group(1), "^""|""$|("")""", "$1")' />
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:function>
<xsl:template match="/" name="main">
<xsl:choose>
<xsl:when test="unparsed-text-available($pathToCSV)">
<xsl:variable name="csv" select="unparsed-text($pathToCSV)" />
<xsl:variable name="lines" select="tokenize($csv, ' ')" as="xs:string+" />
<xsl:variable name="elemNames" select="fn:getTokens($lines[1])" as="xs:string+" />
<root>
<xsl:for-each select="$lines[position() > 1]">
<row>
<xsl:variable name="lineItems" select="fn:getTokens(.)" as="xs:string+" />
<xsl:for-each select="$elemNames">
<xsl:variable name="pos" select="position()" />
<elem name="{.}">
<xsl:value-of select="$lineItems[$pos]" />
</elem>
</xsl:for-each>
</row>
</xsl:for-each>
</root>
</xsl:when>
<xsl:otherwise>
<xsl:text>Cannot locate : </xsl:text><xsl:value-of select="$pathToCSV" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Is this correct?
-Gouri -
CLR to get the SQL Server Data into .CSV File
Hi,
I transformed 10 columns 1000 rows from the source table to 1 column 1000 rows in the destination table by making the comma separated columns ( Just like ..
Insert into DestinationTable
SELECT col1+','+col2 ....
FROM SourceTable
Then I want to take this column into CSV file.
I dont have the rights to command shell.
I heard that we may use CLR procedure for this. Can someone throw light?using System;
using System.IOM
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
public class ExportFileClass {
[Microsoft.SqlServer.Server.SqlProcedure]
public static void export_file()
using (SqlConnection connection = new SqlConnection(
"context connection=true"))
connection.Open();
// Operation to open file goes here.
SqlCommand command = new SqlCommand("SELECT col FROM YourTable");
// Consume result set and write rows.
Build this from the command line:
sn -k keypair.snk
csc /target:library /keyfile:keypair.snk exportfile.cs
Then run in SQL Server (assuming that the files are in C:\temp on the SQL
Server machine:
[sql]
USE master
go
-- To be able to create an external-access assembly, we need to load
-- the key, the assembly is signed with. The key needs a password, but we
-- don't need to know the password.
DECLARE @sql nvarchar(MAX),
@password char(40)
SELECT @password = convert(char(36), newid()) + 'Ab4?'
SELECT @sql = 'CREATE ASYMMETRIC KEY slog_loopback FROM FILE = ' +
'''C:\temp\keypair.snk'' ' +
'ENCRYPTION BY PASSWORD = ''' + @password + ''''
PRINT @sql
EXEC(@sql)
-- And then a login to carry the permission.
CREATE LOGIN exportfile$asymkey FROM ASYMMETRIC KEY ExportFile
GRANT EXTERNAL ACCESS ASSEMBLY TO exportfile$asymkey
go
-- Now we can go back to our regular database and create the assembly.
USE youddatabase
go
CREATE ASSEMBLY ExportFile FROM 'C:\temp\exportfile.dll'
WITH PERMISSION_SET = EXTERNAL_ACCESS
go
CREATE PROCEDURE ExportFile AS
EXTERNAL NAME ExportFile.ExportFileClass.export_file
[sql]
It is likely that you will have to do ask your DBA to do things in the
master database.
Erland Sommarskog, SQL Server MVP, [email protected] -
How to download dynamic table data into CSV format
Hi,
I have data in dynamic table <it_data>, and I want to download that into CSV format.
so I tried to use FM SAP_CONVERT_TO_CSV_FORMAT but how to use this FM with dynamic table?
here <it_data> type standard table, we can pass this to I_TAB_SAP_DATA. but problem is with changing parameter. (TRUXS_T_TEXT_DATA), what type of table it should be?
and one more thing is <it_data> structure is also dynamic , depending on input the structure of <it_data> may vary.
Regards,
MrunalHi,
check this one may be help full to u...........
*Use FM SAP_CONVERT_TO_CSV_FORMAT and pass a Delimiter and ITAB. This
returns an Ouput_String
Convert Internal Table to ; delimited format
There is a filename parameter on this FM but I don't think it's used
call function 'SAP_CONVERT_TO_CSV_FORMAT'
exporting
i_field_seperator = Delimiter "default ';'
i_filename = Filename
tables
i_tab_sap_data = ITAB
changing
i_tab_converted_data = Ouput_String
exceptions
conversion_failed = 1
others = 2.
Regard's
SHAIK.
Maybe you are looking for
-
Following error is getting displayed while udpating the order: Saving order 804880053 failed because doing so would result in data being overwritten. Order data for your browser window was out of date. Please re-submit your changes for them to take e
-
I upgraded my camera and opening a camera raw file no longer works
I went from a Nikon D3000 to a Nikon D5200. I have an old version of Elements (version 8) and I no longer can open a camera raw file. I tried finding an answer in the support area but am not sure I found what I needed to know. Since my camera is n
-
N:1 Mapping in PI 7.1
Hi, I have a scenario on PI 7.1 (RFC to file) where I need to map the RFC node to target node and also a value to target node. RFC Data Type T_CUSTOMER DT_CUSTOMER (Element
-
When I opened firefox the search page just showed Mozilla firefox and had a search inptu boxwih google underneath to show the search engine being used. Suddenly I opened firefox and the page is showing lots of text and is Crawler.com. I have tried to
-
SegregatingTable data into different bucket with equal numebr of
Hi Guys, I wanted to process table data in chunks not all the rows at a time. How can we achieve this in oracle. Example : I have one table EMP which has ten thousands rows(10,000) rows. Now these ten thousands rows are joined with other tables to pr