A lot information is stored in delimited or fixed-length text files, such as CSV (comma-separated variable) or tab-delimited files. Usually Microsoft Excel functions can handle these. But sometimes the data is not consistent from row to row, or Excel misinterprets data as dates or times when they should be plain text. For example: Excel treats 10:09 as a time, but not 89:09.
You can use Microsoft Text File Driver (ODBC) to process this kind of information. This article shows you one way to use it and also some of the difficulties with using Text File Driver.

Creating a DSN for Text Files

To use the Text File Driver with a file, there has to be an information file in the same directory as the text file. The name is always schema.ini. You can create this file can manually with any text editor, with the ODBC wizard, or programmatically. This article shows you how to use the ODBC wizard to start out and then make additional edits, as needed.
  1. Go to Start > Settings > Control Panel > Administrative Tools > Data Sources (ODBC).

    ODBC Data Source Administator opens.

  2. On the System DSN tab, click Add.

    Create a New Data Source displays.

    1. Choose Microsoft Text Driver (*.txt; *.csv).

    2. Click Finish.

      ODBC Text Setup displays.

  3. In ODBC Text Setup:
    1. Type a Data Source Name.
    2. Type a Description.
    3. Uncheck Use Current Directory.

  4. Click Select Directory.
    1. In Folders, double-click the directory you want.
    2. Click OK.
  5. Back in ODBC Text Setup, click Options>>.

    ODBC Text Setup expands to display more options.

    1. Click Define Format.

      Define Text Format displays.

    2. Choose nameaddr.csv.

    3. Check Column Name Header and click Guess.

      A list of columns displays.

    4. Click OK as many times as you need to until you are back to ODBC Data Source Administrator.
  6. Open schema.ini in a text editor such as NotePad or TextPad.

    Entries for all files in the selected directory display.

  7. Edit schema.ini as follows:

    1. Delete everything except the [nameaddr.csv] entry.
    2. Change the data types.

      For example: Make everything a character with appropriate lengths.

    3. Save schema.ini.

RPG2SQL Connection String

Rtn = SQL_DBOpenConn(SQL_Socket : 'DSN=NameAddr;');
Note: Use can use other options in the connection string. See Setting Options Programmatically for the Text File Driver.


Rtn = SQL_RunSQLSel(SQL_Socket: 'SELECT * FROM nameaddr.csv');
Note: When you use a default directory, do not qualify the file name.
Now you can continue with the rest of your RPG2SQL code, as with any other SQL resource.

Other Resources

Still have questions? We can help. Submit a case to technical support

Last Modified On:
You don't have the appropriate permissions.
No, open a new Support Case