• 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
    Computer Keyes

    Fax Directly from your IBM i

    KeyesFax is a full function automated IBM i fax system. Spooled files are burst by fax number and auto transmitted with overlays.  It combines both a send and receive facsimile processing system with a complete image package.

    The fax software will edit, send, receive, display, print, and track fax documents or images using any standard IBM i without additional expensive hardware, software or subscriptions.

    Computer Keyes has been developing Software Solutions since 1978!

    www.computerkeyes.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

  • IBM Unveils Manzan, A New Open Source Event Monitor For IBM i
  • Say Goodbye To Downtime: Update Your Database Without Taking Your Business Offline
  • i-Rays Brings Observability To IBM i Performance Problems
  • Another Non-TR “Technology Refresh” Happens With IBM i TR6
  • IBM i PTF Guide, Volume 27, Number 18
  • Will The Turbulent Economy Downdraft IBM Systems Or Lift It?
  • How IBM Improved The Database With IBM i 7.6
  • Rocket Celebrates 35th Anniversary As Private Equity Owner Ponders Sale
  • 50 Acres And A Humanoid Robot With An AI Avatar
  • IBM i PTF Guide, Volume 27, Number 17

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