• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Build SQL to Define Your Existing Files, Take 2

    May 17, 2016 Ted Holt

    Converting physical files to tables is a good thing to do, but if you work in the sorts of shops where I’ve worked, you already have more than you can do and you don’t have time to fix what isn’t broken. However, if I could make it easy for you, maybe you’d find the time to convert physical files where doing so is to most advantageous. Let me show you how easy it can be.

    First, you need a place to put the SQL DDL (data definition language) source.

    crtpf  mylib/sqlsrc
    

    Second, you need an SQL client. I have used both green screen Start SQL (STRSQL) and the Run SQL Scripts utility that is part of Access Client Solutions.

    Run two measly commands, replacing appropriately.

    call qcmdexc ('addpfm mylib/sqlsrc somepf');
    

    If the member in which you will store the SQL does not exist, you must create it.

    call qsys2.generate_sql
            (database_object_name => 'SOMEPF',
             database_object_library_name => 'SOMELIB',
             database_object_type => 'TABLE',
             database_source_file_name=> 'SQLSRC',
             database_source_file_library_name => 'MYLIB',
             database_source_file_member => 'SOMEPF',
             replace_option => '1',
             statement_formatting_option => '0');
    

    Voilà! You have SQL.

    --  Generate SQL
    --  Version:                   V7R2M0 140418
    --  Generated on:              05/17/16 08:00:00
    --  Relational Database:       BR549000
    --  Standards Option:          DB2 for i
    
    CREATE TABLE SMITH.ACUST (
    --  SQL150B   10   REUSEDLT(*NO) in table ACUST in SMITH ignored.
      ACCOUNT_NUMBER FOR COLUMN ACCOUNT    DECIMAL(7, 0) NOT NULL DEFAULT 0 ,
      NAME CHAR(20) CCSID 37 NOT NULL DEFAULT '' ,
      CITY CHAR(16) CCSID 37 NOT NULL DEFAULT '' ,
      STATE CHAR(2) CCSID 37 NOT NULL DEFAULT '' ,
      ZIP CHAR(10) CCSID 37 NOT NULL DEFAULT '' ,
      PRIMARY KEY( ACCOUNT_NUMBER ) )
    
      RCDFMT CUSTOMER   ;
    
    LABEL ON COLUMN SMITH.ACUST
    ( ACCOUNT_NUMBER IS '                    Customer            number' ,
      NAME IS '                    Customer            name' ,
      CITY IS '                                        City' ,
      STATE IS '                                        State' ,
      ZIP IS '                    ZIP                 Code' ) ;
    
    LABEL ON COLUMN SMITH.ACUST
    ( ACCOUNT_NUMBER TEXT IS 'Customer account number' ,
      NAME TEXT IS 'Customer name' ,
      CITY TEXT IS 'City' ,
      STATE TEXT IS 'State' ,
      ZIP TEXT IS 'Postal codee' ) ;
    
    GRANT DELETE , INSERT , SELECT , UPDATE
    ON SMITH.ACUST TO PUBLIC ;
    
    GRANT ALTER , DELETE , INDEX , INSERT , REFERENCES , SELECT , UPDATE
    ON SMITH.ACUST TO SMITH WITH GRANT OPTION ;
    

    Notice the last parameter, statement_formatting_option. Be sure to pass a zero to this parameter, otherwise you’ll get a bunch of garbage on the end of each line.

    There are more parameters, but the ones I’ve given you have been enough for my purposes so far. You can read about the parameters on the IBM developerWorks site.

    I realize that there are other good ways to build SQL DDL. See the links below for more on this topic.

    I also realize that generating the SQL DDL is only the beginning of the process, but sometimes getting started is the hardest part.

    Ted Holt welcomes your comments and questions. Email him through the IT Jungle Contacts page.

    RELATED STORIES

    TR8 DB2 For i Enhancements, Part 1

    Retrieving and Storing SQL Source for DB2 Database Objects

    Build SQL to Define Your Existing Files, Revisited

    Build SQL to Define Your Existing Files

    generate_sql documentation at IBM developerWorks

    Winnie-the-Pooh

    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

    Sponsored Links

    System i Developer:  RPG & DB2 Summit - October 4-6 2016 in Chicago. Register now!
    BCD:  View Recorded IBM i Webinar: Mobile and desktop web applications. . . Together at last!
    Profound Logic Software:  'i on the Enterprise' Worldwide Virtual Event. June 8. Register Now!

    AURA Hopes U.S. Modernization Crowd Has Silver Lining Product Highlights From Spring COMMON 2016

    Leave a Reply Cancel reply

Volume 16, Number 12 -- May 17, 2016
THIS ISSUE SPONSORED BY:

WorksRight Software
System i Developer
T.L. Ashford

Table of Contents

  • DB2 for i 7.2 TR3 and 7.1 TR11 Features
  • Build SQL to Define Your Existing Files, Take 2
  • RDi Debug Without SEPs

Content archive

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

Recent Posts

  • AI Is Coming for ERP. How Will IBM i Respond?
  • The Power And Storage Price Wiggling Continues – Again
  • LaserVault Adds Multi-Path Support To ViTL
  • As I See It: Spacing Out
  • IBM i PTF Guide, Volume 27, Numbers 34, 35, And 36
  • The Power11 Transistor Count Discrepancies Explained – Sort Of
  • Is Your IBM i HA/DR Actually Tested – Or Just Installed?
  • Big Blue Delivers IBM i Customer Requests In ACS Update
  • New DbToo SDK Hooks RPG And Db2 For i To External Services
  • IBM i PTF Guide, Volume 27, Number 33

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