我尝试使用内在函数 upper-case 和 trim 来比较 COBOL 中的两个字段。
当我比较这两个字段而不将结果移动到新字段时,比较结果显示字段相等但实际上并不相等,例如在我的示例中为“Wert1”<>“wert1 x”。
为什么当我使用字段时比较可以按预期进行,而当我直接使用内部函数时却不行?
示例程序:
program-id. tintr.
data division.
working-storage section.
01 ws-feld1 pic x(10).
01 ws-feld2 pic x(10).
01 ws-feld3 pic x(10).
01 ws-feld4 pic x(10).
procedure division.
move "Wert1 " to ws-feld1
move "wert1 x" to ws-feld2
*
display "<" function upper-case(ws-feld1) ">"
display "<" function upper-case(ws-feld2) ">"
*
display "<" function trim(ws-feld1) ">"
display "<" function trim(ws-feld2) ">"
*
display "<" function upper-case
(function trim(ws-feld1)) ">"
display "<" function upper-case
(function trim (ws-feld2)) ">"
* Compare WS-Feld1/WS-Feld2
if ws-feld1 = ws-feld2
then
display " felder1-2 identical"
else
display " felder1-2 not identical"
end-if
* Compare Functions uppercase/Trim
if function upper-case
(function trim(ws-feld1))
=
function upper-case
(function trim(ws-feld2))
then
display " felder1-2/function identical"
else
display " felder1-2/function not identical"
end-if
* moving result of functions into field
move function upper-case
(function trim(ws-feld1))
to ws-feld3
move function upper-case
(function trim(ws-feld2))
to ws-feld4
* Compare WS-Feld3/WS-Feld4
if ws-feld3 = ws-feld4
then
display " felder3-4 identical"
else
display " felder3-4 not identical"
end-if
*
stop run.
*
结果如下:
<WERT1 >
<WERT1 X >
<Wert1>
<wert1 x>
<WERT1>
<WERT1 X>
felder1-2 not identical
felder1-2/function identical
felder3-4 not identical
没想到结果是“felder1-2/functionidentical”:
对于这种行为有什么解释吗?