NoC*_*nce 3 cobol gnucobol netcobol
除了特定的平台和编译器之外,假设您使用报告编写器模块在 COBOL 程序中定义了这一点:
01 CF-MM TYPE CONTROL FOOTING WS-MM.
02 LINE PLUS 1.
03 COLUMN 1 VALUE "* CF MONTH: ".
03 COLUMN PLUS 1 PIC 99 SOURCE WS-MM.
03 S-MM COLUMN PLUS 5 PIC S9(4)V99 SUM WS-TUTION-PAY.
03 VAL-NN COLUMN PLUS 5 PIC S9(4)V99 SOURCE S-MM.
<...>
PROCEDURE DIVISION.
DECLARATIVES.
SEC2 SECTION.
USE BEFORE REPORTING
CF-MM.
DISPLAY "SUM MM LEVEL:" S-MM
.
Run Code Online (Sandbox Code Playgroud)
此外,假设程序报告了 3 行,其中 SUM WS-TUTION-PAY 结果为 126。
SEC2 SECTION 中显示 S-MM 值的语句产生的值是多少?我猜应该是 126,但我显示的是 0。这可能是因为值 126 尚未移动到 S-MM,但我不确定。
S-MM 声明部分“应该”显示的值是多少
问: 当列与 COBOL REPORT WRITER 模块中的 SUM 子句一起使用时,您能否在 DECLARATIVES 部分中引用该列?
03 S-MM COLUMN PLUS 5 PIC S9(4)V99 SUM WS-TUTION-PAY.
Run Code Online (Sandbox Code Playgroud)
S-MM是子句data-name的一种格式entry-name。引用2002年COBOL标准,报表组描述条目,13.13.2语法规则:
7) 当在 GENERATE 语句、USE BEFORE REPORTING 语句中引用数据名时,应指定条目名子句的数据名格式,作为 SUM 计数器的限定符,在 SUM 子句的 UPON 短语中,或作为 SUM 子句中的操作数。数据名称不得以任何其他方式引用。
如果S-MM符合条件,则可以将其引用为“作为 SUM 计数器的限定符”。
[COBOL 74 和 85 标准规定,“Data-name-1 是可选的,但可以在任何条目中指定。但是,仅当条目定义总和计数器时才可以引用 Data-name-1。”]
我用于以下代码的编译器是 Micro Focus COBOL 85。
代码:
program-id. rw-test.
environment division.
input-output section.
select report-file assign "rpt.txt"
organization line sequential.
data division.
fd report-file
report is report-1.
working-storage section.
01 n comp pic 99 value 0.
01 test-table.
02 test-data.
03 pic 9999 value 1001.
03 pic 9999 value 1002.
03 pic 9999 value 1003.
03 pic 9999 value 2004.
03 pic 9999 value 2005.
03 pic 9999 value 2006.
02 test-entry redefines test-data pic 9999 occurs 6.
01 report-entry.
03 test-group pic 9.
03 test-value pic 999.
report section.
rd report-1
control is test-group.
01 rw-detail type de.
02 line plus 1.
03 grp column 1 pic 9 source test-group.
03 val column 4 pic zz9 source test-value.
01 rw-foot type cf test-group.
02 line plus 1.
03 column 1 pic x(6) value "- ---".
02 line plus 1.
03 column 1 pic 9 source test-group.
03 s-mm column 4 pic zz9 *> s.mm defined
sum test-value
reset test-group.
02 line plus 1 pic x value space.
procedure division.
declaratives.
decl-rpt section.
use before reporting rw-foot.
display s-mm. *> s.mm referenced
end declaratives.
main-line section.
open output report-file.
initiate report-1
perform varying n from 1 by 1
until n > 6
move test-entry (n) to report-entry
generate rw-detail
end-perform
terminate report-1
close report-file
stop run.
end program rw-test.
Run Code Online (Sandbox Code Playgroud)
报告:
1 1
1 2
1 3
- ---
1 6
2 4
2 5
2 6
- ---
2 15
Run Code Online (Sandbox Code Playgroud)
展示:
006
015
Run Code Online (Sandbox Code Playgroud)