使用OCCURS和不同的编译器得到不同的结果 [英] Different results using OCCURS with different compilers
问题描述
我试图使用DISPLAY输出以下行,并在Visual Studio和Tutorialspoint COBOL编译器的Micro Focus COBOL中获得正确的结果,但是当使用IBM的Enterprise COBOL在z/OS Mainframe上运行它时,有些奇怪:/p>
I'm attempting to output the following row using DISPLAY and am getting the correct result in Micro Focus COBOL in Visual Studio and the Tutorialspoint COBOL compiler, but something strange when running it on a z/OS Mainframe using IBM's Enterprise COBOL:
01 W05-OUTPUT-ROW.
05 W05-OFFICE-NAME PIC X(13).
05 W05-BENEFIT-ROW OCCURS 5 TIMES.
10 PIC X(2) VALUE SPACES.
10 W05-B-TOTAL PIC ZZ,ZZ9.99 VALUE ZEROS.
05 PIC X(2) VALUE SPACES.
05 W05-OFFICE-TOTAL PIC ZZ,ZZ9.99 VALUE ZEROS.
在企业COBOL中,空格似乎被忽略了,并且即使两个版本的PERFORM VARYING和DISPLAY代码完全相同,也会添加一个额外的零填充列:
It appears in Enterprise COBOL that the spaces are being ignored, and is adding an extra zero-filled column even though the PERFORM VARYING and DISPLAY code is the exact same in both versions:
PERFORM VARYING W02-O-IDX FROM 1 BY 1
UNTIL W02-O-IDX > W12-OFFICE-COUNT
MOVE W02-OFFICE-NAME(W02-O-IDX) TO W05-OFFICE-NAME
PERFORM 310-CALC-TOTALS VARYING W02-B-IDX FROM 1 BY 1
UNTIL W02-B-IDX > W13-BENEFIT-COUNT
MOVE W02-O-TOTAL(W02-O-IDX) TO W05-OFFICE-TOTAL
DISPLAY W05-OUTPUT-ROW
END-PERFORM
W13-BENEFIT-COUNT为5,并且在程序中从未更改,因此第六栏对我来说还是个谜.
W13-BENEFIT-COUNT is 5 and never changes in the program, so the 6th column is a mystery to me.
正确的输出:
奇怪的输出:
根据要求,以下是W02-OFFICE-TABLE:
as requested, here is W02-OFFICE-TABLE:
01 W02-OFFICE-TABLE.
05 W02-OFFICE-ROW OCCURS 11 TIMES
ASCENDING KEY IS W02-OFFICE-NAME
INDEXED BY W02-O-IDX.
10 W02-OFFICE-CODE PIC X(6).
10 W02-OFFICE-NAME PIC X(13).
10 W02-BENEFIT-ROW OCCURS 5 TIMES
INDEXED BY W02-B-IDX.
15 W02-B-CODE PIC 9(1).
15 W02-B-TOTAL PIC 9(5)V99 VALUE ZERO.
10 W02-O-TOTAL PIC 9(5)V99 VALUE ZERO.
并且W12-OFFICE-COUNT始终为11,永不更改:
and W12-OFFICE-COUNT is always 11, never changes:
01 W12-OFFICE-COUNT PIC 99 VALUE 11.
推荐答案
对于将VALUE
与OCCURS
混合并将WS重新编码为
I'd be very hesitant about mixing VALUE
with OCCURS
and re-code the WS as
01 W05-OUTPUT-ROW.
05 W05-OFFICE-NAME PIC X(13).
05 W05-BENEFITS PIC X(55) VALUE SPACES.
05 FILLER REDEFINES W05-BENEFITS.
07 W05-BENEFIT-ROW OCCURS 5 TIMES.
10 FILLER PIC X(02).
10 W05-B-TOTAL PIC ZZ,ZZ9.99.
05 FILLER PIC X(02) VALUE SPACES.
05 W05-OFFICE-TOTAL PIC ZZ,ZZ9.99 VALUE ZEROS.
也许与缺少的字段名有关?
Perhaps it has something to do with the missing fieldname?
啊!邪恶的INDEXED
.我会将两个***-IDX变量都简化为99s.
Ah! evil INDEXED
. I'd make both ***-IDX variables simple 99s.
这篇关于使用OCCURS和不同的编译器得到不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!