• 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 CSV Files

    February 2, 2005 Hey, Ted

    I know offshoring gets a lot of blame for the decline in programmer positions these days, but there’s another culprit that I never hear about: the vast array of reporting and data-mining tools available to users.

    Twenty years ago a programmer had to write code to build a report program. Now users create their own reports with Microsoft Excel. In my shop, that means we have lots of programs that create CSV (comma-separated values) files. Let me add a simple but effective technique to the Copy to Import File (CPYTOIMPF) command and the plethora of third-party products that create files in CSV (and other) formats.

    SQL presents an easy way to create CSV files. Use the CHAR function to convert numeric fields to alpha format. SQL puts in the necessary minus signs and decimal points. Concatenate all the fields together to get one big comma-delimited output field.

    The following SQL command is an example of the technique. I use Qshell to retrieve the data and load it into a file in the Integrated File System (IFS).

    db2 "SELECT char(CUSNUM)||','||LSTNAM||','||INIT||','||
        CITY||','||STATE||','||char(baldue) from qiws.qcustcdt"
        | sed -n '/,/p' >> custdata.CSV
    

    The CSV file looks like this:

       938472  ,Henning ,G K,Dallas,TX,37.00
       839283  ,Jones   ,B D,Clay  ,NY,500.00
       392859  ,Vine    ,S S,Broton,VT,439.00
       938485  ,Johnson ,J A,Helen ,GA,3987.50
       397267  ,Tyron   ,W E,Hector,NY,.00
       389572  ,Stevens ,K L,Denver,CO,58.75
       846283  ,Alison  ,J S,Isle  ,MN,10.00
       475938  ,Doe     ,J W,Sutter,CA,250.00
       693829  ,Thomas  ,A N,Casper,WY,.00
       593029  ,Williams,E D,Dallas,TX,25.00
       192837  ,Lee     ,F L,Hector,NY,489.50
       583990  ,Abraham ,M T,Isle  ,MN,500.00
    

    It isn’t necessary to run SQL under Qshell, of course, but doing so sure makes it easy to build an IFS file.

    –Just call me “Joe”


    If you need to get rid of extra blanks, use the TRIM function. If a character field might contain commas, use the TRANSLATE function to convert them to something else.

    –Ted

    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

    Stampede Regains Edge for Compression of Notes/Domino R6 JDE Shops Have Plenty of Options for Third-Party Maintenance

    Leave a Reply Cancel reply

Volume 5, Number 5 -- February 2, 2005
THIS ISSUE
SPONSORED BY:

WorksRight Software
Advanced Systems Concepts
COMMON

Table of Contents

  • Repeated Characters in SQL
  • Yet Another Way to Build CSV Files
  • Admin Alert: Things to Check After Upgrading OS/400 V5R1 to V5R3

Content archive

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

Recent Posts

  • To Comfort The Afflicted And Afflict The Comfortable
  • How FalconStor Is Reinventing Itself, And Why IBM Noticed
  • Guru: When Procedure Driven RPG Really Works
  • Vendors Fill In The Gaps With IBM’s New MFA Solution
  • IBM i PTF Guide, Volume 27, Number 27
  • With Power11, Power Systems “Go To Eleven”
  • With Subscription Price, IBM i P20 And P30 Tiers Get Bigger Bundles
  • Izzi Buys CNX, Eyes Valence Port To System Z
  • IBM i Shops “Attacking” Security Concerns, Study Shows
  • IBM i PTF Guide, Volume 27, Number 26

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