ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Sql UDF issue

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

  • Sql UDF issue

    I have a service program procedure that returns the calling program using QMHRCVPM and QMHSNDPM apis. I am trying to wrap it in a udf and it is not working, always returns blank. Wondering if this for some reason does not work with SQL. I have tried quite a few different startcnt also tried converting them to integer in sql.

    Code:
    //UDF create
    create or replace function misjd/miscp_getcaller (startcnt
    integer)                                                  
    returns char(10)                                          
    language rpgle                                            
    no sql                                                    
    external name 'MISJD/MISCPR01(MISCP_GETCALLER)'           
    parameter style general                                   
    
    //procedure definition.
    Dcl-Proc MiscP_GetCaller Export;
             Dcl-Pi *n Char(10);
               StartCnt Int(10) Const;
             End-Pi;
    
    //this works.
    programname = miscp_getcaller(2);
    dsply programname;
    
    //But this does not
    Exec Sql
             Select Miscp_Getcaller(2)
               Into :Programname
               From Sysibm / Sysdummy1;
    
     dsply programname;

  • #2
    What does mscp_getcaller() do? How does it work? When you debug it, which part fails to work?

    Comment


    • #3
      Here is the code, the issue is the RCVM0200.Receiver is always a 'Q' value.

      Code:
      Dcl-Proc MiscP_GetCaller Export;
               Dcl-Pi *n Char(10);
                 StartCnt Int(10) Const;
               End-Pi;
      
               //
               // Receive Program Message API
               //
               Dcl-Pr QMHRCVPM ExtPgm('QMHRCVPM');
                 MsgInfo Char(32767) Options(*VarSize);
                 MsgInfoLen Int(10) Const;
                 Format Char(8) Const;
                 StackEntry Char(10) Const;
                 StackCount Int(10) Const;
                 MsgType Char(10) Const;
                 MsgKey Char(4) Const;
                 WaitTime Int(10) Const;
                 MsgAction Char(10) Const;
                 ErrorCode Char(8000) Options(*VarSize);
               End-Pr;
      
               //
               // Send Program Message API
               //
               Dcl-Pr QMHSNDPM ExtPgm('QMHSNDPM');
                 MessageID Char(7) Const;
                 QualMsgF Char(20) Const;
                 MsgData Char(32767) Const Options(*VarSize);
                 MsgDtaLen Int(10) Const;
                 MsgType Char(10) Const;
                 CallStkEnt Char(10) Const;
                 CallStkCnt Int(10) Const;
                 MessageKey Char(4);
                 ErrorCode Char(8000) Options(*VarSize);
               End-Pr;
      
               Dcl-Ds RCVM0200 Qualified;
                 Receiver Char(10) Pos(111);
               End-Ds;
      
               Dcl-Ds ErrorCode Qualified;
                 BytesProv Int(10) Inz(%size(ErrorCode));
                 BytesAvail Int(10) Inz(0);
               End-Ds;
      
               Dcl-S Found Ind;
               Dcl-S MsgKey Char(4);
               Dcl-S Stack_Entry Int(10);
      
               Found = *OFF;
      
               for stack_entry = StartCnt to 50;
      
                 QMHSNDPM( ''
                         : ''
                         : 'TEST'
                         : %len('TEST')
                         : '*RQS'
                         : '*'
                         : stack_entry
                         : MsgKey
                         : ErrorCode  );
      
                 if (ErrorCode.BytesAvail > 0);
                   return *blanks;
                 endif;
      
                 QMHRCVPM( RCVM0200
                         : %size(RCVM0200)
                         : 'RCVM0200'
                         : '*'
                         : stack_entry
                         : '*RQS'
                         : MsgKey
                         : 0
                         : '*REMOVE'
                         : ErrorCode );
      
                 if (ErrorCode.BytesAvail > 0);
                   return *blanks;
                 endif;
      
      
                 if (%subst(RCVM0200.Receiver:1:1) <> 'Q');
      
                   Found = *On;
                   leave;
                 endif;
      
               endfor;
      
               if (Found);
                 return RCVM0200.Receiver;
               else;
                 return *blanks;
               endif;
      
             End-Proc;

      Comment

      Working...
      X