• Can anyone post an example of creating a table in lets say...QTEMP from SQLRPGLE program?

    Thanks in advance,
    Jamie


  • Parick,

    There really is no limit for us.. I know the server admin ;)


    In the future you need something changed just let me know...

    Thanks for the DOC I will try to make sense of it.

    Have a great weekend
    Jamie


  • A friend from http://www.sysrq.com/

    Helped me on this one

    code to generate a table on the fly from SQLRPGLE


    Ã *-------------------------------------------------------------------
    Ã * CREATETBL - Create a table on the fly into QTEMP
    Ã *
    Ã * Had to create query over QSYS/QADBXFIL and extract my 5 fields
    Ã * to a file called workfile.
    Ã *-------------------------------------------------------------------
    fWORKFILE if e k Disk rename(workfile:workfile2)
    *
    * Defined variables
    *
    d CmdString s 256
    d CmdLength s 15 5
    *
    * Delete Work file incase it exists
    *

    c/Exec Sql
    c+ DELETE FROM qtemp/somefile
    c/End-Exec
    *
    * Create Work file in Qtemp
    *
    c/Exec Sql
    c+ CREATE TABLE QTEMP/SOMEFILE (
    c+ Filename Char (10) ,
    c+ Library Char (10) ,
    c+ Owner Char (10) ,
    c+ Text Char (50) ,
    c+ FileType Char (01)
    c+ )
    c/End-Exec

    *
    * File Description
    *

    c/Exec Sql
    c+ LABEL ON TABLE QTEMP/SOMEFILE IS 'this is a junk file'
    c/End-Exec


    *
    * Field examples only one field here TEXT and COLHDG
    *

    c/Exec Sql
    c+ LABEL ON COLUMN QTEMP/SOMEFILE (FileName TEXT IS 'Test text')
    c/End-Exec
    c/Exec Sql
    c+ LABEL ON COLUMN QTEMP/SOMEFILE(FileName IS 'Test column ')
    c/End-Exec

    c *start setll WORKFILE
    c read WORKFILE
    c dow not%eof(WORKFILE)
    *
    c/exec sql
    c+ INSERT INTO QTEMP/SOMEFILE VALUES(:DBXFIL, :DBXLIB, :DBXOWN,
    c+ :DBXTXT, :DBXTYP)
    c/end-exec
    *
    c read WORKFILE
    c enddo
    *
    c seton lr
    *


  • Thanks Arrow but dont i need a c-compiler for that?

    I wish the weekends were longer......Not sure if I will have time this weekend to mess round with this.

    Take care
    Jamie


  • 1st - The C compiler is bundled with RPG, COBOL. BASIC

    2nd - No, you don't need C-compiler, this is SQL. I usually run STRSQL or put it in a source member and run it with RUNSQLSTM.

    But put the C/ EXEC SQL wrappers around it, and you can run it from inside an RPG pgm.


  • I have never done that in SQL myself.. I have a CL shell I incorporated into my SQL interface, so I just do it that way. I did find the reference for doing it though. I'll attach it. Good luck making sense of it all. ^^'

    EDIT: Okay.. that's nasty looking.. and choice of attachments is limited... What's a good way to post something that big? There is a character limit on posts I belive, and I'm sure this one is over it.


  • Hey, you know what, i think you're question just gave me an idea what i'm missing. :)

    I was supposed to execute command string for the qtemp file and I forgot to include that. I'll see what happens tomorrow when I get back to work and will post here whatever happens.


  • Looks just like what I'm doing here! I wonder if you need to create the table to compile the program? How are you referring to the file in qtemp in your program? Is it only via SQL or are you doing an F-Spec and READ by chance?




    // create temporary tables in qtemp
    #createTables();



    ************************************************** ********************
    * procedure: #createTables *
    * purpose: create temporary tables in qtemp *
    ************************************************** ********************
    p #createTables b

    d #createTables pi


    * create table1
    c/exec sql
    c+ create table qtemp/epotable1 (
    c+ upc char(12 ),
    c+ voidDate decimal(8,0)
    c+ )
    c/end-exec

    * create table2
    c/exec sql
    c+ create table qtemp/epotable2 (
    c+ acct# char( 5 ),
    c+ upc char(12 ),
    c+ voidDate decimal(8,0),
    c+ status char( 1 ),
    c+ division char( 2 ),
    c+ season char( 1 ),
    c+ style char(12 ),
    c+ color char( 3 ),
    c+ size char( 3 ),
    c+ retail decimal(7,2),
    c+ price decimal(7,2),
    c+ po# char(22 ),
    c+ rcvDate decimal(8,0),
    c+ lastPrint decimal(8,0)
    c+ )
    c/end-exec

    p #createTables e


  • c/Exec Sql
    c+ CREATE TABLE QTEMP/TEMPRRD (
    c+ Name Char (20) ,
    c+ Address Char (40))
    c/End-Exec


    Ok, so this is only a small part of my program but basically this is my create statement for a temporary table named TEMPRRD. When I compile the program, the errors I get pretty much states that the file (TEMPRRD) does not exists and that the fields, naturally, does not exists as well. Based on the SQLRPGLE samples that I've seen, this create statement is what I only need to make a table on run-time.

    Any hint on what I'm missing here?


  • Parick,

    There really is no limit for us.. I know the server admin ;)


    In the future you need something changed just let me know...

    Thanks for the DOC I will try to make sense of it.

    Have a great weekend
    Jamie


    I tried to post it... this is the error I got: The text that you have entered is too long (83155 characters). Please shorten it to 40000 characters long.


  • I seldom imbed SQL, but add the C/+ wrapper around it.







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about creating a table from SQLRPGLE , Please add it free.