1

I have an SQLCBLLE *MODULE that contains embedded sql.
This *MODULE is part of a *SRVPGM.

If I call this SQLCBLLE *MODULE from an SQLRPGLE pgm, I get a pointer error on the exec sql that does a select into :WS-MESSAGE. However, if I make the SQLCBLLE *MODULE a *PGM, the embedded sql works fine with no pointer error.

Here is the *MODULE source... (the commented out EXEC SQL is where the pointer error occurs in debug... though the funny thing is in debug if you eval :WS-MESSAGE it is initialized and referenceable as if it is a legit ready to go host variable so not sure exactly what this pointer error is referring to...?)

 PROCESS OPTIONS.                                             
 PROCESS NOMONOPRC.                                           
 IDENTIFICATION DIVISION.                                     
 PROGRAM-ID.  CBL00000M.                                      
**************************************************************
                                                              
**************************************************************
 ENVIRONMENT DIVISION.                                        
**************************************************************
 CONFIGURATION SECTION.                                       
 SPECIAL-NAMES.                                               
                                                              
**************************************************************
 DATA DIVISION.       
**************************************************************
 WORKING-STORAGE SECTION.                                     
 77  WS-MESSAGE          PIC X(50).                           
                                                              
 LINKAGE SECTION.                                             
 01 INCOMING-VALUE1          PIC X(5).                        
 01 OUTGOING-VALUE1          PIC X(50).                       
                                                              
     exec sql                                                 
       set option                                             
       commit = *NONE,                                        
       closqlcsr = *ENDMOD,                                   
       datfmt    = *ISO                                       
     end-exec. 

     exec sql                                                 
       include sqlca                                          
     end-exec.                                                
                                                              
**************************************************************
 PROCEDURE DIVISION USING INCOMING-VALUE1                     
                          OUTGOING-VALUE1.                    
**************************************************************
                                                              
*    exec sql                                                 
*        select "SQL row count from CBL00000M SQL: " concat   
*               char(count(*))                                
*        into :WS-MESSAGE                                     
*        from coreirst.rst00001t                              
*    end-exec.                                                
*    move ws-message to outgoing-value1.                      
     MOVE "SUCCESSFUL CALL TO CBL00000S/CBL00000m COBOL Proc"   
                           
 END PROGRAM CBL00000M.              

I tried call the *MODULE as a *PGM and that worked.

Adriaan
  • 17,741
  • 7
  • 42
  • 75
corei
  • 21
  • 1
  • 3
    Please add the code of the caller to your question, does it call with two parameters ? – nfgl Apr 11 '23 at 13:06
  • Can you try add the clause "EXEC SQL BEGIN DECLARE SECTION END-EXEC." before declaration of WS-MESSAGE and "EXEC SQL END DECLARE SECTION END-EXEC." after it ? – Massi FD Apr 11 '23 at 13:09

1 Answers1

0

I'm just spitballing here since I don't know all the ins and outs of it, but I do know that the first COBOL *PGM object in the call stack initializes a COBOL run time environment. So when you call the COBOL code as a *PGM object, it works fine. But, what happens when there is no COBOL program in the call stack when you call a COBOL procedure? Does that initialize a COBOL run time? Or is it looking for something that is just missing resulting in unexpected pointer errors.

Is there a specific reason you want COBOL in the mix?

Maybe the solution is to start with a COBOL program that just calls your RPG program.

Or just write the procedure in RPG with embedded SQL.

jmarkmurphy
  • 11,030
  • 31
  • 59
  • so I figured it out... if I move the Linkage Section (all 3 lines) to the bottom of the DATA DIVISION, no more pointer error. That solved it. – corei Apr 12 '23 at 12:31
  • That seems to be a bug in the precompiler as the documentation explicitly states that `INCLUDE SQLCA` can be located in the `WORKING-STORGE SECTION` or the `LINKAGE SECTION`, furthermore, the only requirement for `SET OPTION` is that it be the first SQL Statement. I would report this to IBM. – jmarkmurphy Apr 12 '23 at 19:33