ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

RUNSQLSTM vs STRQMQRY vs Embedded SQL

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • RUNSQLSTM vs STRQMQRY vs Embedded SQL

    I am curious to find out what others prefer when they run a SQL statments in batch mode. To keep this discussion simple and straight forward, it needs to run on the iSeries (AS/400) as batch job. Any IBM supplied command or user created options are more then welcome.

    Anybody willing to give an opinion?
    Never trust a dog to watch your food.

  • #2
    Re: RUNSQLSTM vs STRQMQRY vs Embedded SQL

    Normally I will write an Embedded SQL program and will run it in batch using SBMJOB command and I have seen most of the people doing this.
    Thanks,
    Giri

    Comment


    • #3
      Re: RUNSQLSTM vs STRQMQRY vs Embedded SQL

      This is I do most of the time, but sometimes it seem simipler to create a source member and run the SQL statement using RUNSQLSTM. The plus side to this and maybe the downside as well. If the query needs to change, you just change the source member and you are done.
      Never trust a dog to watch your food.

      Comment


      • #4
        Re: RUNSQLSTM vs STRQMQRY vs Embedded SQL

        It really all depends on whether or not I need to include additional processing that SQL cannot do or might be complex and therefore time consuming for SQL.
        If the program fits the description above I will use Embedded SQl to achieve my goal.

        However, If I am populating a datawarehouse or building statistical files I lean more towards RUNSQLSTM. The downside is that complex(verbose) statements become difficult to read on the screen.

        I wish there was a solution that allowed me to store my SQL statements in a folder in the IFS. That way I wouldnt be limited to the width constraints and could write my queries using a free format style.
        Predictions are usually difficult, especially about the future. ~Yogi Berra

        Vertical Software Systems
        VSS.biz

        Comment


        • #5
          Re: RUNSQLSTM vs STRQMQRY vs Embedded SQL

          I have lately started using the db2 command in QSHELL to run some simple SQL commands in a CLP without having to key the SQL statements into a source file. I also like it because I can pass variables.

          Simple example:

          Code:
          PGM
          QSH        CMD('db2 ''create table yourlib.file1 as +     
                        (select * from yourlib.file2) with data''')  
          ENDPGM

          Example with variables:

          Code:
          PGM                                                      
          DCL        VAR(&FILE1) TYPE(*CHAR) LEN(10) VALUE('file1')
          DCL        VAR(&FILE) TYPE(*CHAR) LEN(10) VALUE('file2') 
          DCL        VAR(&QSHCMD) TYPE(*CHAR) LEN(100)             
          CHGVAR     VAR(&QSHCMD) VALUE('db2 ''''create table +    
                       yourlib.''||&FILE1||'' as (select * from +  
                       yourlib.''||&FILE2||'') with data)''''')    
          QSH        CMD(&QSHCMD)                                  
          ENDPGM
          I don't know if the syntax above is totally correct, I didn't compile it, I may have missed some quotes and stuff, but that is the general form.......


          Pete

          Comment


          • #6
            Re: RUNSQLSTM vs STRQMQRY vs Embedded SQL

            Pete, I am glad you put in your $1.00 worth of information. I don't know enough about QShell so I didn't even know you could this.

            I tested it and found out that you have to use the SQL naming convention. In other words, the library and file name have to be sperated by a "." and not a "/".
            Never trust a dog to watch your food.

            Comment


            • #7
              Re: RUNSQLSTM vs STRQMQRY vs Embedded SQL

              Something about Qshell
              ---------------------------------

              The AS/400 has a built-in command interpreter called QSH, which is capable of performing many useful "Unix" functions.

              To start a QShell session, you type qsh at the command line.

              You can use the QSH utility to a. Copy a tree structure.
              Code:
              For example, 'cp -r /qopt//somedir' recursively copies files from the 
              AS/400 built-in CD-ROM to directory/somedir and retains its tree structure. 
              
              b. Find a string in an IFS text file. For example, 'grep foo/mydir/*' 
              searches for string foo in all the files residing in directory/mydir. 
              
              c. Zip and unzip stream files.
              For example, 'jar cvf x.zip/mydir/*.*' zips all files from directory 
              mydir to a new zip file named x.zip. 
              
              d. Find files in the IFS using different criteria options and 
              optionally performing functions on those files.
              For example, find '/mydir -name test* -exec rm {} \;' 
              searches for files starting with "test" in directory mydir 
              (recursively) and deletes each file it finds. For more 
              information on QShell, visit the iSeries QShell page


              IBM QSHELL docs
              Thanks,
              Giri

              Comment


              • #8
                Re: RUNSQLSTM vs STRQMQRY vs Embedded SQL

                Does running on Linux server on i-series count? We've recently converted to using PHP--which runs a lot faster on Linux partition. Of course managing batch jobs is not quite as easy, but the batch SQL I run (at least executed from PHP) runs a whole lot faster that way (in Linux environment).

                Comment


                • #9
                  Re: RUNSQLSTM vs STRQMQRY vs Embedded SQL

                  It started out as a iSeries question, buy any solution to show the various ways to run SQL along with the positive and negative reasons of doing so is welcome.


                  The three ways in the thread title are the three primary ways I do it; mostly because there is no other option like a Linux in a LPAR using PHP.

                  The Qshell option was unqiue and I may have to use this one day.

                  I am still interested in various reasons why and how anybody runs SQL.
                  Never trust a dog to watch your food.

                  Comment


                  • #10
                    Re: RUNSQLSTM vs STRQMQRY vs Embedded SQL

                    I actually use the RUNSQLSTM, using a source member which is built on the fly when a user asks for some data via a display file.

                    Comment


                    • #11
                      Re: RUNSQLSTM vs STRQMQRY vs Embedded SQL

                      WOW...thanks for the blast from the past...over 4 year old thread??? anyway since we're here...i always convert to embedded SQL programs. the main reason is that with RUNSQLSTM it's too easy for someone to go into the member in edit mode, fat finger something and save it...then you're hosed. if it's a compiled program they not only have to clobber the source but they would also have to recompile the program in order to crap out my production data...

                      just my 2 coppers...
                      I'm not anti-social, I just don't like people -Tommy Holden

                      Comment


                      • #12
                        Re: RUNSQLSTM vs STRQMQRY vs Embedded SQL

                        I think half the people in this thread are dead now....

                        My Vote is SQL....
                        All my answers were extracted from the "Big Dummy's Guide to the As400"
                        and I take no responsibility for any of them.

                        www.code400.com

                        Comment


                        • #13
                          Re: RUNSQLSTM vs STRQMQRY vs Embedded SQL

                          Yes Tom that is very true. You do not want anyone fat fingering your code. The best place to build them on the fly is in the QTEMP library before you execute them.
                          I have one program that actually does this and two other programs that formats the file and sends it to a given destination.
                          Its all new development for me, so I had fun designing and writing it. I was actually creating a STRQMQRY style for a generic SQL command, just to find out there are many of them out there. Then I came across this thread. Now with EVI's which one of these would be the best to use to get the max performance from your box? I have some very large files that I will be dealing with soon and I do not want any of my programs to become the energizer bunny.

                          Comment


                          • #14
                            Re: RUNSQLSTM vs STRQMQRY vs Embedded SQL

                            Originally posted by Robert Lunger View Post
                            Yes Tom that is very true. You do not want anyone fat fingering your code. The best place to build them on the fly is in the QTEMP library before you execute them.
                            I have one program that actually does this and two other programs that formats the file and sends it to a given destination.
                            Its all new development for me, so I had fun designing and writing it. I was actually creating a STRQMQRY style for a generic SQL command, just to find out there are many of them out there. Then I came across this thread. Now with EVI's which one of these would be the best to use to get the max performance from your box? I have some very large files that I will be dealing with soon and I do not want any of my programs to become the energizer bunny.
                            yes i noticed you said you were building the script on the fly...which is infinitely better than using a "static" source member. however i prefer to use dynamic SQL to build the statement within the program vs. writing a script into a file but that's just my 2 coppers
                            I'm not anti-social, I just don't like people -Tommy Holden

                            Comment


                            • #15
                              Re: RUNSQLSTM vs STRQMQRY vs Embedded SQL

                              I would question which one will be better as performance wise ?? runsqlstm, strqmqry and dynamic cursor if we copy the data on certain condition??

                              provided it if Table is large (millions of data) like i hav source file whic has following query ..i have to make faste below statement
                              Code:
                              insert into ava                                             
                                (avsku, aviloc, avqoh)                                         
                                                                                               
                              select inumbr, istore,                                           
                               CASE                                                            
                                 When fcsku is null then                                       
                                 (ibhand-ibarqt-ibnsqt-ibhldq-ibphnd)                          
                                 When fcnqty <= 0 then                                         
                                 (ibhand-ibarqt-ibnsqt-ibhldq-ibphnd)                          
                                 When fcnqty > 0 then                                          
                                 (fcnqty - ibarqt)                                             
                               END as onhand                                                   
                                from dfm inner join invbal on fmsku=inumbr and fmiloc=istore
                                 Left outer join fcsbal on fmsku = fcsku and fmiloc = fcstor   
                              where fmiloc<>290 and                                            
                               CASE                                                            
                                 When fcsku  is null then                                      
                                 (ibhand-ibarqt-ibnsqt-ibhldq-ibphnd)                          
                                 When fcnqty <= 0 then      
                                 When fcnqty <= 0 then                                
                                 (ibhand-ibarqt-ibnsqt-ibhldq-ibphnd)                 
                                 When fcnqty > 0 then                                 
                                 (fcnqty - ibarqt)                                    
                               END   <> 0                                             
                              union                                                   
                              select fmsku, fmiloc, ffoh                              
                                from dfm inner join fflinvpf on fmsku=fnumbr       
                              where fmiloc=290 and ffoh<>0
                              Table description :

                              INVBAL (inventory balance ) unique key ..

                              INUMBR Sku Number 9 0 key
                              ISTORE Store 5 0 key
                              no of fields 112

                              AVA Inventory File(unique)

                              AVSKU SKU Number 9 0 key
                              AVILOC Inventory Location 5 0 key

                              DFM (unique)
                              FMSKU SKU Number 9 0 key
                              FMILOC Inventory Location 5 0 key

                              FCSbal is having same key ..

                              these files are having large data in it..(millions)

                              I wrote above statement but taking long time any suggestion to Improve performance of it???

                              Pramendra
                              Last edited by pramendra; June 18, 2010, 05:18 AM. Reason: fcsbal added..
                              Young people knows how to run fast but old people knows the way..

                              Comment

                              Working...
                              X