BookmarkSubscribeRSS Feed
Choose Language Hide Translation Bar
mazook
New Contributor

Load CSV from variable

We have a use case where we call Run Program, and the result is a CSV formatted string. Basically, Run Program is running an application which fetches a remote file in CSV format. I know you can write the CSV to the file system, and then read it to a data table from the file system, but is it possible to read the CSV string in memory from a variable, directly to a datatable?

0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: Load CSV from variable

This example uses the dos echo command to send a small CSV file back to JMP. It also passes a blob, rather than a filename, to the open function.

csvdata = Run Program(
    Executable( "CMD.EXE" ),
    Options( {"/a", "/q", "/c echo a,b,c&echo 1,2,3&echo 4,5,6"} ),
    ReadFunction( "blob" )
);
show(blobtochar(csvdata));
dt = open(csvdata, "text");

When the open function sees a blob rather than a filename, it depends on the 2nd parameter to find out the type of data. CharToBlob will convert the text you got back from RunProgram to a blob, or you can get RunProgram to give you the blob directly as shown above.

Capture.PNGCSV loaded into JMP

Craige
1 REPLY 1
Highlighted

Re: Load CSV from variable

This example uses the dos echo command to send a small CSV file back to JMP. It also passes a blob, rather than a filename, to the open function.

csvdata = Run Program(
    Executable( "CMD.EXE" ),
    Options( {"/a", "/q", "/c echo a,b,c&echo 1,2,3&echo 4,5,6"} ),
    ReadFunction( "blob" )
);
show(blobtochar(csvdata));
dt = open(csvdata, "text");

When the open function sees a blob rather than a filename, it depends on the 2nd parameter to find out the type of data. CharToBlob will convert the text you got back from RunProgram to a blob, or you can get RunProgram to give you the blob directly as shown above.

Capture.PNGCSV loaded into JMP

Craige