ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Send program message

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

  • Send program message

    Hello,

    I am trying to send a message to a user when they call a program and it encounters an issue.

    In CLLE, if I do SNDPGMMSG, leave all values as they are and put some text in;
    Code:
    PGM                                   
    
    SNDPGMMSG  MSG('CODE400 is the best!')
    
    ENDPGM
    I get a white message popup at the bottom of my session;
    Code:
    Selection or command    
    ===>                    
    
    F3=Exit   F4=Prompt   F9
    F23=Set initial menu    
    [U][B]CODE400 is the best!  [/B][/U]
    However; I can't get this to do the same within an RPGLE program with a call to QMHSNDPM - the message appears in my job log, but not at the bottom of the screen;

    Code:
     * Send error message                                              
    D QMHSNDPM        Pr                   ExtPgm('QMHSNDPM')          
    D   #MsgID                       7a    Const                       
    D   #MsgFile                    20a    Const                       
    D   #MsgDta                  32767a    Const Options(*VarSize)     
    D   #MsgDtaLen                  10i 0  Const                       
    D   #MsgType                    10a    Const                       
    D   #StackEntry                 10a    Const                       
    D   #StackCount                 10i 0  Const                       
    D   #MsgKey                      4a                                
    D   ErrorCode                32767a    Options(*VarSize)           
    
    D ErrorCode       DS                                               
    D  #BytesProv                   10i 0  Inz(0)                      
    D  #BytesAvail                  10i 0  Inz(0)                      
    
     * Work fields                                                     
    D #MsgKey         S              4a                                
    D #MSG            C                   Const('CODE400 is the best!')
    
     * Main line code                             
       QMHSNDPM(' ':' ':#MSG :%Len(%Trim(#MSG))   
               :'*INFO':'*':0:#MsgKey: ErrorCode);
    
       *Inlr = *On;                               
       Return;
    I have tried the following message types; *INFO, *DIAG, *NOTIFY and also calls with a MSGID of CPF9897 and a message file of 'CPF9897': 'QCPFMSG *LIBL' - no luck

    Is it something to do with the fact the error message is generated in QMHSNDPM so when it returns to my program, the message is lost? Or is it something else? Is there a way to do it (write a CL and do it that way?)? What is the meaning of life?

    Cheers,
    Ryan


  • #2
    In your CL program, the message is being sent to the previous program in the call stack because the default for the TOPGMQ parm of the SNDPGMMSG command is *PRV. If you change that parameter to *SAME (meaning use the current call stack entry instead of the previous one), you would see the same behavior as the RPG program.

    Setting the Stack Count parameter of the API to 0 is the same as using *SAME in the CL program and you want to send the message to the previous program in the call stack. To do that, change the Stack Entry parameter to *PGMBDY instead of * and change the Stack Count to 1 which means send the message to the program 1 level up the call stack.

    Comment


    • #3
      Thanks Brian, worked a charm.

      Comment


      • #4
        Quick question; did you know the answer already, i.e. looked at it in the past/learnt about it or did you read something that helped you work it out?

        Comment


        • Brian Rusch
          Brian Rusch commented
          Editing a comment
          I knew the answer already from past experience working on programs/display files using message subfiles and passing messages between programs, although I'm sure there are several articles about message handling that you could search for.

        • RDKells
          RDKells commented
          Editing a comment
          Ah right ok, just needed a pointer in the right direction - I'll know what to look up the next time I don't see messages where I want them.

          Thanks again.

      • #5
        Hello, everyone.

        This will read as a stupid question.
        I need to do the same thing but to a different workstation.
        I want to have a program running in batch that sends status messages (Line 24) to a workstation.
        I can have parameters to set the workstation and the message queue or the stack pointer or whatever is needed...
        Any ideas?

        Thanks.

        Comment


        • #6
          Originally posted by ALSFelix View Post
          I need to do the same thing but to a different workstation.
          I want to have a program running in batch that sends status messages (Line 24) to a workstation.
          I can have parameters to set the workstation and the message queue or the stack pointer or whatever is needed...
          As far as I know, status messages must be sent from within the same job. However you could:

          1) Use STRWCH when the job starts to set up a "watch" on a given message queue.
          2) When a message appears on that queue, it can invoke a program you specify to the STRWCH command.
          3) That program could read the queue and send a status message.
          4) Then, all you need the batch job to do is send a message to the queue that you're "watching"

          Comment


          • #7
            Originally posted by Scott Klement View Post

            As far as I know, status messages must be sent from within the same job. However you could:

            1) Use STRWCH when the job starts to set up a "watch" on a given message queue.
            2) When a message appears on that queue, it can invoke a program you specify to the STRWCH command.
            3) That program could read the queue and send a status message.
            4) Then, all you need the batch job to do is send a message to the queue that you're "watching"


            That seems to be a possible good solution.
            I will try it and give you some feedback.

            Thanks a lot.

            Comment

            Working...
            X