Previous Topic: Uses of PPI

Next Topic: &PPI ALERT


Examples

These examples wait for requests to arrive on the PPI queue. Each request is then executed as a product command, and any messages received from the command are sent back through the PPI. The ID for the server is made up of CMD and the current domain ID; therefore, a different copy of this procedure could run on each product region in the system. If the procedure is stopped, requests are queued, and on the next invocation the queue is processed. To stop the server, you can either flush the procedure (interrupting the current request) or issue an INTQ command, putting the string STOP onto the procedure's dependent request queue.

Example 1:

The following example issues requests to the previous procedure. It shows how the communication takes place. Any program using the PPI (whether it is an NCL procedure on this or another region, or a program written in another language) can request information in the same way.

&IF &ZPPI NE YES &THEN +
    &ENDAFTER +
      &WRITE COLOR=RED DATA=PPI INTERFACE NOT AVAILABLE
&PPI DEFINE ID=CMD&ZOMID
&IF &RETCODE NE 0 &THEN +
   &ENDAFTER +
       &WRITE COLOR=RED DATA=INITIALIZE FAILED +
              RC=&RETCODE FDBK=&ZFDK
&DOUNTIL &RETCODE NE 0
   &PPI RECEIVE VARS=PPI* WAIT=NOTIFY
   &DOWHILE &RETCODE EQ 0     -* Process anything waiting
                              -* on the queue
      &WRITE COLOR=YELLOW LOG=YES TERM=YES +
             DATA=REQUEST RECEIVED FROM &PPISENDERID TO +
                  ISSUE COMMAND &PPI1 &PPI2 &PPI3 &PPI4 &PPI5 +
                  &PPI6 &PPI7 &PPI8 &PPI9
      &INTCMD &PPI1 &PPI2 &PPI3 &PPI4 &PPI5 &PPI6 &PPI7 +
              &PPI8 &PPI9
      &DOUNTIL &RETCODE NE 0 +
       INTREAD SET WAIT=5 TYPE=RESP
       &IF &ZFDBK = 0 &THEN +
        &PPI SEND TOID=&PPISENDERID DATA=&ZMTEXT
       &ELSE +
        &RETCODE 1
      &DOEND
      &IF &RETCODE NE 1 &THEN +
       &WRITE COLOR=RED DATA=PPI SEND TO +
        &ZPPISENDERID FAILED, RC=&RETCODE, FDBK=&ZFDBK
      &ELSE
        &PPI SEND TOID=&PPISENDERID DATA=END=CMD&ZDOMID
      &PPI RECEIVE VARS=PPI* WAIT=NOTIFY
   &DOEND
   &IF &RETCODE = 20 &THEN +  -* Wait for a request to
                              -* appear on queue
   &DO
      &DOUNTIL .&INTL1 EQ .N00101
       &INTREAD WAIT=YES TYPE=ANY VARS=INT*
       &IF .&ZINTYPE EQ .REQ AND .&INT1 EQ .STOP &THEN +
        &ENDAFTER +
         &WRITE COLOR=YELLOW +  
                DATA=STOP REQUEST FROM &ZMREQID ACCEPTED
      &DOEND
      &RETCODE 0
   &DOEND 
&DOEND 
&WRITE COLOR=RED +
       DATA=PROGRAM SERVER CMD&ZDOMID FAILED, RC=&RETCODE,+
            ZFDBK=&ZFDBK 
&END

Example 2:

This example sends the data passed on the EXEC or START command to the server shown in Example 1. The messages returned will then be written to the terminal.

&IF &ZPPI NE YES &THEN +
    &ENDAFTER +
       &WRITE COLOR=RED DATA=PPI NOT AVAILABLE ON THIS +
                             SYSTEM
&PP1 STATUS ID=CMD&ZDOMID
&IF &RETCODE NE 0 &THEN +
    &ENDAFTER +
       &WRITE COLOR=RED DATA=PROGRAM RECEIVER CMD&ZDOMID +
                             NOT AVAILABLE
&PPI DEFINE ID=*
&IF &RETCODE NE 0 &THEN +
    &ENDAFTER +
       &WRITE COLOR=RED DATA=DEFINE TO PPI FAILED
&WRITE COLOR=PINK DATA=SENDING COMMAND ”&ALLPARMS” TO +
                       SERVER CMD&ZDOMID
&PPI SEND TOID=CMD&ZDOMID DATA=&ALLPARMS
&DOUNTIL .&MSGLN1 EQ .END-CMD&ZDOMID OR &RETCODE NE 0
    &PPI RECEIVE WAIT=YES +
                 STRING=(MSGLN1,MSGLN2,MSGLN3,MSGLN4)
    &IF &RETCODE EQ 0 AND .&MSGLN1 NE .END-CMD&ZDOMID +
      &THEN &WRITE COLOR=TURQUOISE DATA=&MSGLN1 &MSGLN2 +
                                        &MSGLN3 &MSGLN4 
&DOEND 
&PPI DEACTIVATE MAXQUEUE=0       -* Prevent others queuing
                                 -* to this ID. 
&WRITE COLOR=PINK DATA=*** END OF MESSAGES *** 
&END