Send Program Message Using a Message ID

SndMsgID

The SndMsgID procedure sends a program message to the specified invocation/program.

The SndMsgID procedure uses a message ID to send a message.

msgKey    SndMsgID(
  szMsgID             7A   Const 
  szMsgFile          21A   Const OPTIONS(*OMIT : *NOPASS)
  szMsgData        1024A   Const OPTIONS(*OMIT : *NOPASS : *VARSIZE )
  nMsgDataLen        10I 0 Const OPTIONS(*OMIT : *NOPASS)
  szMsgType          10A   Const OPTIONS(*OMIT : *NOPASS : *VARSIZE )
  szToPgmQ           10A   Const OPTIONS(*OMIT : *NOPASS : *VARSIZE )
  nRelInvocation     10I 0 Const OPTIONS(*OMIT : *NOPASS)
)

See also: GetMsgText, GetMsgInfo

Parameters

szMsgID
[input Char(7) ]  A message ID to send to the target program queue.
szMsgFile  - DFT('QCPFMSG')
[input Char(21) ]  Any qualified message file. This parameter consists of two parts (1) in the first 10 positions, the name of the message file, and (2) in the second 10 positions, the name of the library containing the message file or *LIBL. For example:
 
 *...v....1....v....2
'QCPFMSG   *LIBL     '
 

An alternative syntax is also supported for this object name. The alternate syntax allows you to specify the object name similar to that of an OS/400 CL command, that is it may be qualified using qualified name syntax, as follows:

 *...v....1....v....2
'QSYS/QCPFMSG        '

In addition, you may specified either *OMIT (unquoted) or '*' (quoted asterisk) to indicate that this parameter's default value should be used.

 

szMsgData  [ optional ]
[input Char(1024) ]  The message data used by the message ID specified on the szMsgID parameter. Any message data up to 1024 bytes may be specified. This parameter is option and does not need to be specified. No value (i.e., ' ') or *OMIT are also valid. If this parameter is specified, then the nMsgDataLen must also be specified.
 
szMsgDataLen  [ optional ]
[input Int4 (10i0) ]  The length of the value specified on the szMsgData parameter. This value is required when szMsgData is specified, otherwise it may be zero, or *OMIT or unspecified.
 
szMsgType  [ optional ]
[input Char(10) ]  The type of message to send. If this parameter is specified, it must be either a quoted character string, named constant or a character field containing one of the following type codes:
Message Type Description
'*COMP' Completion message
'*DIAG' Diagnostic message
'*ESCAPE' Escape message
'*INFO' Informational message
'*INQ' Inquiry message (valid only when *EXT is specified for szToPgmQ
'*NOTIFY' Notification message
'*STATUS' Status message
'*' If a quoted asterisk is used, the default value for this parameter is used.
 
szToPgmQ  Default('*')
[input Char(10) ]  The program queue where the message is sent. If this parameter is not specified * (*SAME) is used. If specified, one of the following values must be specified:
 
To PgmQ Description
'*' The current program message queue
*SAME' Same as *
'*CTLBDY' Control boundary
'*EXT' External program message queue (used for *STATUS messages)
'*PRVPGM' Previous program message queue

NOTE: If you want SNDMSGID to work similar to the SNDPGMMSG CL command, use *PRVPGM instead of *PRV when sending messages.

'*PRV' '*PRVPRC' '*PRVPROC' Previous procedure message queue
 
nRelativeInvocation  Default(1)
[input Int4 (10i0) ]  The relative invocation of the target program queue. The default, if unspecified, is 1.

Return Value

The return value is the message key of the message once it is sent.

Remarks

     H BNDDIR('XTOOLS/RPGLIB')

      /COPY QCPYSRC,msg

     D OBJ             S             20A     Inz('CUSTMAST  QGPL')

  

     C                   if        NOT ChkObjExists(OBJ: '*FILE')

     C                   callp     SndMsgID('CPF9812' : '*' : OBJ : %size(OBJ) :

     C                                      '*DIAG' : '*PRVPGM')

     C                   endif

In this example the message text 'File CUSTMAST in library QGPL not found.' is sent as a diagnostic message to the previous program. Note that '*' is used for the second parameter (message file) instead of 'QSYS/QCPFMSG' or *OMIT.