Submitted by Anonymous (not verified) on Fri, 07/07/2006 - 00:00
Forums

How do I use embedded SQL with IceBreak?

Bent Rønne

Sat, 07/08/2006 - 00:00

SQL programs can have another subtype besides RPGLE, the other is called SQLRPGLE. All you have to do is tell the precompiler that another programming language is being used, and override how the commitment control is being used. The first line of ASP code does that, it is called Compiler-directives:

   <%@ language="SQLRPGLE" options="COMMIT(*NONE)" %> 

The "options" parameter can override any additional parameters on the CRTBNDRPG and CRTSQLRPGI

Host variables are needed to hold the result of the SQL-query. This is a standard RPG definition.

   <%
 D*Name++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++++
 D MyCounter       s              4B 0
  D Now             s               Z
 /free
 %> 

The last thing is the actual SQL-statement. This is enclosed by /exec and /end-exec

   <%       
 /Exec SQL Select count(*)  , Current Timestamp
           into   :MyCounter, :Now
            from   Product
 /End-Exec
 %> 

Note, that colon in :MyCounter and :now is the
method to describe an RPG host variable when you are writing SQL-statements.

Finally, you are able to present the result in HTML like this:

  <p>The number of rows in table "Product" is <%= %char(MyCounter) %> and
 time is: <% = %char(now) %></p> 

The complete example looks like this. 

   <%@ language="SQLRPGLE" options="COMMIT(*NONE)" %>
  <%
 D*Name++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++++
 D MyCounter       s              4B 0
  D Now             s               Z
 /free
 %>
 <html>
  <h1>Using SQL</h1>
  <%       
 /Exec SQL Select count(*)  , Current Timestamp
           into  :MyCounter , :Now
           from product
 /End-Exec
 %>
 <p>The number of rows in table "product" is <%= %char(MyCounter) %> and
  time is: <% = %char(now) %></p>
  </html> 
  <%    
    return; 
 %>