• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Yet Another Way to Build a Tab-Delimited File

    April 6, 2005 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.


    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    NetManage Streamlines Mobile Access to Host Data SecureZIP for iSeries Now Available from PKWARE

    Leave a Reply Cancel reply

Volume 5, Number 14 -- April 6, 2005
THIS ISSUE
SPONSORED BY:

WorksRight Software
Advanced Systems Concepts
Guild Companies

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

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Public Preview For Watson Code Assistant for i Available Soon
  • COMMON Youth Movement Continues at POWERUp 2025
  • IBM Preserves Memory Investments Across Power10 And Power11
  • Eradani Uses AI For New EDI And API Service
  • Picking Apart IBM’s $150 Billion In US Manufacturing And R&D
  • FAX/400 And CICS For i Are Dead. What Will IBM Kill Next?
  • Fresche Overhauls X-Analysis With Web UI, AI Smarts
  • Is It Time To Add The Rust Programming Language To IBM i?
  • Is IBM Going To Raise Prices On Power10 Expert Care?
  • IBM i PTF Guide, Volume 27, Number 20

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle