这是源代码
Dcl-S dataString VarChar(1048576:4) Inz;
Dcl-DS Ds_ErrMsg Qualified;
ErrMsg VarChar(249); //22+1+21+1+200 = 245
//extra 4 bytes for VarChar? What sub-fields exactly?
date_iso VarChar(22) Inz('Error Date: ')
Overlay(ErrMsg);
*n Char(1) Inz(x'25') Overlay(ErrMsg:*Next);
id VarChar(21) Inz('Error ID. . . . : ')
Overlay(ErrMsg:*Next);
*n Char(1) Inz(x'25') Overlay(ErrMsg:*Next);
message VarChar(200) Inz('Error. . . . : ')
Overlay(ErrMsg:*Next);
End-Ds;
Ds_ErrMsg.date_iso += %Char(%Date);
Ds_ErrMsg.id += '100';
Ds_ErrMsg.message += 'No Response Received. ' +
'Call to test API ended in error.';
dataString = Ds_ErrMsg.ErrMsg;
*InLR = *On;
下面是输出
预期输出
Error Date: 2023-11-15
Error ID. : 100
Error . . : No Response Received. Call to test API ended in error.
另外,DS实际上有4个VARCHAR子字段,当声明大小为245时,我在编译过程中收到以下错误。
*RNF7303 30 001000 Subfield MESSAGE defined with keyword OVERLAY is too big;specification ignored.
这是有道理的,我需要添加 VARCHAR 的变量部分,因此每个变量子字段 2 个字节(2 个字节 * 4 个字段 = 8 个字节),因此新的大小应该是 245+8 = 253 个字节,即
VarChar(253)
,当给定 VarChar(249)
的大小时,程序也会编译。不知道这是如何运作的!
您有 4 个 varchar 字段,但其中 3 个与另一个重叠,因此字节大小为 245 + 6 = 251,这也是
errmsg
(249 + 2 = 251) 的大小
顺便说一句,
date_iso
的2个字节覆盖了errmsg
的2个字节,所以当你设置Ds_ErrMsg.date_iso += %Char(%Date);
时,你也设置了errmsg的
参见:
EVAL ds_errmsg:c
DS_ERRMSG:C =
....5...10...15...20...25...30...35...40...45...50...55...60
1 ' █Error Date: 2023-12-04█ █Error ID. . . . : 100█ áError. . '
61 '. . : No Response Received. Call to test API ended in error.'
121 ' '
181 ' '
241 ' '
我认为串联是一个更好的工具来完成你想做的事情。请参阅 %concat