Newsletters   Subscriptions  Forums  Store   Career  Media Kit  About Us  Contact  Search   Home 
fhg
Volume 5, Number 14 -- April 6, 2005

Yet Another Way to Build a Tab-Delimited File


Hey, Ted:


Thanks for the tip on creating CSV files with SQL. If the data itself contains commas or double quotes, import programs such as Microsoft Excel may get confused on where fields start and end. I think it's much safer to use a tab (X'05') as the delimiter and use the PC file extension "txt".

Keep up the great work!

--Chris

That sounded like a good suggestion to me, so I gave it a whirl, Chris. You were right. I had no trouble opening a tab-delimited file with embedded commas in Microsoft Excel. But that's not to say I didn't have any trouble.

CRTPF FILE(QTEMP/CUSTEXPORT) RCDLEN(512)

Next, I used SQL/400 to load some data into the file.

INSERT INTO QTEMP/CUSTEXPORT
SELECT char(CUSNUM)||x'05'||LSTNAM||x'05'||INIT||x'05'||
           CITY||x'05'||STATE||x'05'||char(baldue) from qiws/custody

Then I copied the program-described file to a stream file.

CPYTOSTMF FROMMBR('/qsys.lib/qtemp.lib/custexport.file/custexport.mbr')
           TOSTMF(custexport.txt) STMFCODPAG(*PCASCII)

I FTP'ed the file to my PC and opened it with Excel, which made me go through an import wizard, but it made the correct guesses. By the way, the file that is generated with the SQL command shown above doesn't have any commas in the fields, but I did test with data that included commas.

That seems to work OK. However, when I tried to use Qshell to create the IFS file, I ran into a small problem. Qshell's db2 command generates header and trailer lines in addition to the data. In the original version of this tip, Joe used the stream editor, sed, to select only the data lines. And how did he do that? By selecting lines that contained commas. Making sed select lines that contain a tab is another matter, since sed doesn't allow escape sequences for control characters in the command expression. There may be a way to make this work, but I haven't had enough time to find it yet.

--Ted


Click here to contact Ted Holt by e-mail.


Sponsored By
ADVANCED SYSTEMS CONCEPTS

SEQUEL can be used for virtually ALL data access functions on the iSeries.

A Windows-based user interface makes it easy to design queries and reports.

SEQUEL offers executive dashboards, drill-down data analysis and run-time prompts to deliver important iSeries data to managers and other non-technical users.

E-mail and FTP delivery let you deliver information to remote users and servers.

www.asc-iseries.com


Technical Editors: Howard Arner, Joe Hertvik, Ted Holt,
Shannon O'Donnell, Kevin Vandever
Contributing Technical Editors: Joel Cochran, Wayne O. Evans, Raymond Everhart,
Bruce Guetzkow, Marc Logemann, David Morris
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.


THIS ISSUE
SPONSORED BY:

WorksRight Software
Advanced Systems Concepts
Guild Companies


Four Hundred Guru

BACK ISSUES

TABLE OF
CONTENTS
Using FTP to Poll for File

Yet Another Way to Build a Tab-Delimited File

Admin Alert: Using OS/400 Prestart Jobs for Repetitious Server Processing


The Four Hundred
SoftLanding Goes Open Source with TurnOverSVN

PHP is Almost Certainly Coming to the iSeries

iTera Says Business is Brisk

Where Is i5/OS Small Business Suite?

Four Hundred Stuff
BMC Updates iSeries Management and Planning Products

Profound Logic Keeps Focus on Simplification with RPG Smart Pages

IPS Eases IPDS Printing with OnePrint G2 for Windows

NetManage Streamlines Mobile Access to Host Data

Four Hundred Monitor


Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc. (formerly Midrange Server), 50 Park Terrace East, Suite 8F, New York, NY 10034
Privacy Statement