ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

SQLRPGLE read result set, but only specifc columns?

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

  • SQLRPGLE read result set, but only specifc columns?

    I have an SQL stored procedure that returns a result set. (SQL external proc wraps an SQLRPGLE that does an "exec sql set result set")

    I want to get that data in an RPGLE program. I have found the ITJungle article on using sql ALLOCATE CURSOR in SQLRPGLE: https://www.itjungle.com/2010/08/25/fhg082510-story02/

    And that works. However, that fetches all the columns from the result set and I do not want all the columns. But I don't see a way of selecting only the columns I want? Is that possible?
    I can partially work around this by fetching into a DS that contains only the first x columns, and ensuring new columns are only added to the end, though that does mean I have to deal with an SQL 01503 warning.


    (I also found a possible IBMi bug, in that doing a bulk fetch "fetch from csr for x rows into :var", SQLER3 (number of rows returned) is 0 if x is greater than the number of available rows.)

  • #2
    You cannot select any columns in a result set nor sort the rows in a result set differently.
    The Cursor returning in the result set is defined in the stored procedure and in your RPG program you can only go through the complete result set.
    Why not defining a data structure for receiving all columns and then only use the columns you need?

    Why bother you return a result set and then register the procedure as stored procedure, instead of calling the RPG procedure directly and returning the result in an array data structure?

    Comment


    • #3
      The procedure is an existing procedure being called externally over JDBC, so trying to make use of what's already written.

      Comment

      Working...
      X