• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Specify SQL Table-creation Library at Runtime

    April 25, 2012 Hey, Ted

    I have an RPG programs that creates work tables in QTEMP. I’d like to be able to specify the library at runtime. I tried using a host variable for the library in a CREATE TABLE command, but that didn’t fly. I am using the system naming convention. Can you help?

    –Ben

    I wish CREATE TABLE would allow a host variable for the explicit qualifier, but it doesn’t. Here are a few ways that work.

    1. Use dynamic SQL. Embed the library name in the SQL command.

    D SqlCommand      s            256a   varying
    D WorkLib         s             10a
     /free
         *inlr = *on;
         SqlCommand = ('create table ' + %trim(WorkLib) +
                       '/SomeTable +
                           (OneFish     char(3), +
                            TwoFish     dec (5,0), +
                            RedFish     char(1), +
                            BlueFish    date)');
         exec sql
            execute immediate :SqlCommand;
    

    2. Use the CURRENT SCHEMA special register with dynamic SQL. Note that the CREATE TABLE command does not include a qualifier.

    D SqlCommand      s            256a   varying
    D WorkLib         s             10a
     /free
         *inlr = *on;
         exec sql
            set Current Schema = :WorkLib;
         SqlCommand = ('create table SomeTable +
                           (OneFish     char(3), +
                            TwoFish     dec (5,0), +
                            RedFish     char(1), +
                            BlueFish    date)');
         exec sql
            execute immediate :SqlCommand;
    

    3. Change the current library. Be aware that the system will not allow you to set the current library to QTEMP. You might want to reset it before the job ends.

    A portion of the CL caller:

    dcl    &CurLib    *char      10
               
    /* change the current library */
    rtvjoba   curlib(&CurLib)
    chgcurlib SomeLib
    
    /* do the work */
    call rpgpgm
    
    /* reset the current library */
    if (&CurLib *eq *NONE) +
      then(  chgcurlib   *CRTDFT)
      else ( chgcurlib   &CurLib)
    

    A portion of the RPG “callee”:

    exec sql
       create table SomeTable
          (OneFish     char(3),
           TwoFish     dec (5,0),
           RedFish     char(1),
           BlueFish    date);
    



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    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

    SEQUEL Software:  FREE webinar: Application Development Control Starts with the Right Tools. April 26
    ASNA:  FREE one-day ASNA Wings® workshops: Dallas, May 10; Malvern, May 24
    COMMON:  Join us at the 2012 Conference & Expo, May 6 - 9 in Anaheim, CA

    IT Jungle Store Top Book Picks

    BACK IN STOCK: Easy Steps to Internet Programming for System i: List Price, $49.95

    The iSeries Express Web Implementer's Guide: List Price, $49.95
    The iSeries Pocket Database Guide: List Price, $59
    The iSeries Pocket SQL Guide: List Price, $59
    The iSeries Pocket WebFacing Primer: List Price, $39
    Migrating to WebSphere Express for iSeries: List Price, $49
    Getting Started with WebSphere Express for iSeries: List Price, $49
    The All-Everything Operating System: List Price, $35
    The Best Joomla! Tutorial Ever!: List Price, $19.95

    Kronos Takes iSeries Central on the Road, Gets SMART IBM i 7.1 Tech Refresh Sports Live Partition Mobility

    Leave a Reply Cancel reply

Volume 12, Number 11 -- April 25, 2012
THIS ISSUE SPONSORED BY:

Bytware
SEQUEL Software
WorksRight Software

Table of Contents

  • NOMAX? No Way!
  • Specify SQL Table-creation Library at Runtime
  • Getting PC5250 F1-F24 Keys to Work Correctly on HP Laptops

Content archive

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

Recent Posts

  • EvolveWare Makes Progress With RPG Code Modernization Using AI
  • Why The IBM i Market Needed Another VTL Option
  • What Price Power?
  • Cloud Revenues Saved By The GenAI Boom
  • IBM i PTF Guide, Volume 27, Number 44
  • Power Systems Grows Nicely In Q3, Looks To Grow For All 2025, Too
  • Beta Of MCP Server Opens Up IBM i For Agentic AI
  • Sundry IBM i And Power Stack Announcements For Your Consideration
  • Please Take The IBM i Marketplace Survey
  • IBM i PTF Guide, Volume 27, Number 43

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