Unconfigured Ad Widget

Collapse

Announcement

Collapse
No announcement yet.

Placement of Dynamic "Declare/Prepare" Statements

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

  • Placement of Dynamic "Declare/Prepare" Statements

    And this is because the SQL precompiler executes before the RPG compiler. SQL compiler hasn't a clue about any subroutines, including *INZSR. It's good practice to put those declares up at the top of the C specs.

  • #2
    Placement of Dynamic "Declare/Prepare" Statements

    SQL compiler is very strict with order, in which your statement appears in your program. It is might be a good practice to put those into separate subroutines and use their names in your program, i.e. Declare BegSR c/Exec SQL c+ Declare cursor ... C/End Exec EndSR and so on. This way you'll have your SQL line up in a proper order and your program would be able to call them in any order.... I hope it make sense

    Comment


    • #3
      Placement of Dynamic "Declare/Prepare" Statements

      You can put the cursor declarations in the *INZSR. To do it, put any references to the cursors in subroutines that are physically coded after the *INZSR or whereever you declare the cursor. The physical order in the source is important, the SQL precompiler doesn't care about the subroutines and will simply look for the proper SQL statements in the proper physical order in the source. I do it all the time so that, just like you, the program looks cleaner.

      Comment


      • #4
        Placement of Dynamic "Declare/Prepare" Statements

        if you compile interactively, eg crtsqlrpgi qtemp/prg sourcefile etc.. you'll end up with a qtemp/qsqltemp1 source file that contains the complete generated source code. Taking a look at what the sql precompiler is actually doing really explains a lot about where and how statements must appear in the rpg source.

        Comment


        • #5
          Placement of Dynamic "Declare/Prepare" Statements

          I just started working with SQL in an RPG program. I created a program that has 4 different dynamic selections. Each based upon the results of the prior. So, I thought I could clean up my program by moving the cursor initialization statements "declare" and "prepare" into the *inzsr subroutine. Upon my astound, I recompiled my program and ended up with SQL errors that my cursors were no longer defined. Apparently, the SQL precompiler doesn’t recognize the *inzsr subroutine. I don’t remember ever reading anyone’s SQL article on this one. Ouch!!! I know IBM is going to give us free form SQL in 5.4. How about fixing this one!

          Comment


          • #6
            Placement of Dynamic "Declare/Prepare" Statements

            The DECLARE CURSOR statement must precede all statements that explicitly reference the cursor by name. The above statement was taken from the Notes section of the Declare Cursor documentation in the SQL Reference manual. I'm assuming that this is an SQL standard because I first ran into this requirement when using Informix in the early 90's, and this requirement was very well documented in the Informix manauls. When I started using embedded SQL with RPG I continued the same practice, and eventually saw the note that indicates that this placement is a requirement.

            Comment

            Working...
            X