• 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:

    • Share on Reddit (Opens in new window) Reddit
    • Share on Facebook (Opens in new window) Facebook
    • Share on LinkedIn (Opens in new window) LinkedIn
    • Share on X (Opens in new window) X
    • Email a link to a friend (Opens in new window) Email

    Tags:

    Sponsored by
    Raz-Lee Security

    The MFA Mobile App provides a secure and user-friendly way to add strong authentication without complicating access. It enables users to approve login requests or generate one-time passwords directly from their mobile device, ensuring that access is granted only after a second, trusted factor is verified.

    Learn More

    Share this:

    • Share on Reddit (Opens in new window) Reddit
    • Share on Facebook (Opens in new window) Facebook
    • Share on LinkedIn (Opens in new window) LinkedIn
    • Share on X (Opens in new window) X
    • Email a link to a friend (Opens in new window) 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

    NOMAX? No Way! Getting PC5250 F1-F24 Keys to Work Correctly on HP Laptops

    Leave a ReplyCancel 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

  • Bob Code Assistant Gets Better Understanding Of IBM i Applications
  • IBM i In The Cloud And The Case For Reversing Replication
  • Guru: From Hiking Boots To Long-Term Memory
  • Inside IBM’s New PowerHA Cloud Offering, Full System Manager
  • IBM i PTF Guide, Volume 28, Number 39
  • Power Systems Turns In Another Great Quarter
  • Big Blue Is Right On Schedule With Fall 2026 IBM i Tech Refreshes
  • Guru: Environment Variables – Global Variables Wearing Hiking Boots
  • A New IBM i Entity Takes Shape: Power By Fortra
  • IBM i PTF Guide, Volume 28, Number 38

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