MESSAGE 块让您根据函数调用的成功或失败来确定在函数调用之后如何继续下去,并让您为函数 的调用程序显示信息。Net.Data 使用以下消息块过程:
一个 MESSAGE 块由一系列消息语句组成,每个消息语句指定一个返回码值、信息正文和一个 要进行的操作。Net.Data 参考中的语言结构章中显示了 MESSAGE 块的语 法。
MESSAGE 块可具有全局或局部作用域。如果 MESSAGE 块是在 FUNCTION 块中定义的,则它的 作用域局部在该 FUNCTION 块中。 如果它是在最外层指定的,则 MESSAGE 块是全局作用域,并且对于 Net.Data 宏中执行的所有函数 调用都是活动的。 如果您定义多个全局 MESSAGE 块,则最后定义的块是活动的。
Net.Data 使用这些规则来处理来自一个函数调用的 RETURN_CODE 变量的值:
下例显示 Net.Data 宏的一部分,其中具有一个全局 MESSAGE 块和一个函数的 MESSAGE 块:
%{ 全局消息块 %} %MESSAGE { -100 : "Return code -100 message" : exit 100 : "Return code 100 message" : continue +default : { This is a long message that spans more than one line. You can use HTML tags, including links and forms, in this message. %} : continue %} %{ local message block inside a FUNCTION block %} %FUNCTION(DTW_REXX) my_function() { %EXEC { my_command.cmd %} %MESSAGE { -100 : "Return code -100 message" : exit 100 : "Return code 100 message" : continue -default : { This is a long message that spans more than one line. You can use HTML tags, including links and forms, in this message. %} : exit %}
如果 my_function() 返回 RETURN_CODE 值为 50,Net.Data 将以此 顺序处理错误:
当 Net.Data 找到一个匹配时,它向 Web 浏览器发送信息正文,并检查请求的操作。
当您指定了 continue 之后,Net.Data 继续处理 Net.Data 宏,然后才打印信息正 文。例如,一个宏调用 my_functions() 5 次并在用 MESSAGE 块处理期间发现错误 100,则程序的输出是这样的:
. . . 11 May 1997 $245.45 13 May 1997 $623.23 19 May 1997 $ 83.02 return code 100 message 22 May 1997 $ 42.67 Total: $994.37