ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Result sets not working in RPG

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

  • Result sets not working in RPG

    My RPG code...

    Code:
             EXEC SQL
               Declare userList CURSOR FOR
                 SELECT *
                  FROM HFCRSLTS1 hfcData
                  LEFT OUTER JOIN JOTSRSLTS1 JOTSData ON
                    hfcData.USER_ID = JOTSData.P9USRID
                  ORDER BY hfcData.LAST_NAME;
    
             EXEC SQL
               Open userList;
    
             EXEC SQL
               SET RESULT SETS WITH RETURN TO CALLER Cursor userList;
    
            *INLR = *on;
            return;
    I've also tried CLIENT instead of CALLER.

    My store procedure code...
    Code:
    Create Procedure PGMLIB.CF_PRODUCER_USR_ALL (OUT V_SQLERROR NUMERIC(10) )
        Language RPGLE 
        Parameter Style General 
        Reads SQL Data 
        Dynamic Result Sets 1 
        External name 'PGMLIB/CF_105U3'  
        Specific PGMLIB.CF_PRODUCER_USR_ALL;
    If I run the SQL portion of the SQL code alone it does return records. How ever when I call it from the RPG program nothing is returned. What am I missing?

  • #2
    Originally posted by Chris Bratvold View Post
    How ever when I call it from the RPG program nothing is returned.
    When you "call" it? ...Call what?

    Is that referring to calling the stored proc? Or does it refer to running the SQL itself inside the stored proc?

    How do you know nothing is returned? That is, what does the code look like that calls the stored proc?
    Tom

    There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

    Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

    Comment


    • #3
      can you check the SQLCOD & SQLSTATE after each SQL statement? sounds like there an issue happening somewhere prior to the SET RESULTS. just a WAG
      I'm not anti-social, I just don't like people -Tommy Holden

      Comment


      • #4
        Originally posted by tomliotta View Post

        When you "call" it? ...Call what?

        Is that referring to calling the stored proc? Or does it refer to running the SQL itself inside the stored proc?

        How do you know nothing is returned? That is, what does the code look like that calls the stored proc?
        When I say "it" I do mean the stored procedure or the RPG program directly.

        The reason I know nothing is returned is because while debugging the program (RDI) I see this in the job log after the EXEC SQL SET RESULT SET command runs. SQLCODE is zero after all SQL statements.

        Code:
        Message ID . . . . . . :   SQL7995       Severity . . . . . . . :   00      
        Message type . . . . . :   Completion                                        
        Date sent  . . . . . . :   05/04/17      Time sent  . . . . . . :   14:02:18
        
        Message . . . . :   0 result sets processed by the SET RESULT SETS statement.
        Cause . . . . . :   0 result sets were processed by the SET RESULTS SETS    
          statement, including 0 array result sets with 0 rows.
        Also, when I run the procedure from AQT the program returns "0" rows found.

        Finally, the query should return 2 records. I've inserted test logic to perform a fetch next request and data is being returned.

        Comment


        • #5
          I don't see anything obvious. What compile options did you use?

          Ringer

          Comment


          • #6
            Originally posted by CRinger400 View Post
            I don't see anything obvious. What compile options did you use?

            Ringer
            I did see that I was closing the cursor upon ending the module (change management compile defaults). I fixed that. It now closes when the activation group ends. However, it still doesn't work.

            Comment


            • #7
              Numerous possibilities, but not enough code nor info about environments that succeed or fail shown. Code should include at least the PR and compile options. The stored proc shows OUT parm V_SQLERROR and code shows no reference to it. The CREATE PROCEDURE statement uses SQL naming, but it's not clear how it's called since no CALL is shown. Without more RPG, it's not clear if SQL or system naming is in effect. The potential for multiple tables of the same names in different schemas is an example possibility.

              I'd start by making a CALL to the stored proc in STRSQL and then iNav's 'Run SQL Scripts'. By staying fully within IBM tools until reaching points of success, some inconsistencies might be easier to recognize.
              Tom

              There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

              Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

              Comment

              Working...
              X