在 DSPF 中使用带有 MSGID 的动态文本

Having dynamic text with MSGID in DSPF

我正在修改一个交互式程序,使 DSPF 具有一个输出字段:

MSGERR        80A  O 24  2MSGID(&§MSGID FILE_MSG) 

我将一个 ID 传递给 MSGID,它运行良好。

现在我有这样一条消息:

VALUE CAN BE: &1, &2, &3

我需要用文本替换 &1、&2、&3。

现在的方法可以吗? 因为我不能直接在RPGLE上操作MSGERR,因为它是不可见的。

不,你不能。而不是使用 MSGID、ERRMSGID 等。我更喜欢消息子文件。它看起来像这样:

 A* ========================================================================
 A* Message Subfile
 A* ------------------------------------------------------------------------
 A          R MSGSFL                    SFL
 A                                      SFLMSGRCD(24)
 A            MSGKEY                    SFLMSGKEY
 A            PGMQ                      SFLPGMQ
 A* ------------------------------------------------------------------------
 A* Message Subfile - Control forrmat
 A* ------------------------------------------------------------------------
 A          R MSGCTL                    SFLCTL(MSGSFL)
 A                                      OVERLAY
 A                                      SFLINZ
 A                                      SFLPAG(1)
 A                                      SFLSIZ(2)
 A                                      SFLDSP SFLDSPCTL
 A  52
 AON52                                  SFLEND(*PLUS)
 A            PGMQ                      SFLPGMQ

要使用它,您需要将消息发送到程序消息队列,然后将 MSGCTL 编写为屏幕事务的一部分。所以如果你通常在你的屏幕上有一个名为 RECORD 的记录格式,你会这样做:

pgmq = <Program Name>;
write msgctl;
exfmt record;

程序消息队列中的任何消息都将显示在显示器第 24 行的单行子文件中。此子文件可滚动。

您将需要两个子过程来轻松完成这项工作,一个用于写入消息,另一个用于清除消息队列。我将我的名字命名为 ClearDspfMsg(pgmq)SendDspfMsg(pgmq: msgid: msgdata).

程序如下:

// ------------------------------------
// Clear Display File Messages
// Clears the messages in the display file message subfile
//
// Parameters:
//  pgmq        - Program message queue. This must be the same as the pgmq
//                specified in the display file.
// ------------------------------------
dcl-proc ClearDspfMsg Export;
  dcl-pi *n;
    pgmq           Char(10) const;
  end-pi;

  dcl-ds ec            LikeDs(errCode_t) Inz(*LikeDs);

  qmhrmvpm(pgmq: 0: '': '*ALL': ec);
  // TODO Provide error checking here
end-proc;

// ------------------------------------
// Send Message to Display File (MSGID)
// Sends a message to the display file message subfile
//
// Parameters:
//  pgmq        - Program message queue. This must be the same as the pgmq
//                specified in the display file.
//  messageId   - The message id of the message to be sent
//  messageData - Message data for replacement values in the message. Format
//                of the message data is defined by the message. This is
//                optional, if missing, blanks are used.
//  messageFile - The qualified name of the message file containing the
//                message. The first 10 characters is the messafe file name,
//                the second 10 characters is the library. This is optional,
//                if blank, CNVMSG in *LIBL is used.
// ------------------------------------
dcl-proc SendDspfMsg Export;
  dcl-pi *n;
    pgmq           Char(10) const;
    messageId      Char(7) const;
    messageData    Varchar(256) const options(*varsize: *nopass);
    messageFile    LikeDs(qualName_t) const options(*nopass);
  end-pi;

  dcl-ds msgf      LikeDs(qualName_t) Inz(*likeds);
  dcl-ds ec        LikeDs(errCode_t) Inz(*likeds);

  dcl-s msgData    Char(256) Inz('');

  if %parms() >= %parmnum(messageData);
    msgData = messageData;
  endif;
  if %parms() >= %parmnum(messageFile);
    msgf = messageFile;
  else;
    msgf.name = 'MSGF';  // This is your default message file
  endif;

  qmhsndpm(messageId: msgf: msgData: %size(msgData): '*INFO': pgmq: 0: '': ec);
  // TODO Provide error checking here
end-proc;

我有 qmhsndpmqmhrmvpm 的原型,但您可以很容易地在文档中查找这些原型和错误代码参数的格式。

调用SendDspfgMsg()发送消息,ClearDspfMsg()在交易开始时清除消息队列。 PGMQ 应该对所有这些部分具有相同的值,并且它会正常工作。

注意: 这不适用于 RPG,因为您无权访问子程序。如有必要,将您的程序转换为 RPGLE,它将正常运行。或者在那种情况下使用子例程而不是子程序。