I find the MOVE 0 TO WS-SEQ-NO method to be clearer as to your intent.
Something to keep in mind, there may be compile options that affect the truncation/rollover behavior you observe. For example, in IBM's Enterprise COBOL, if WS-SEQ-NO is defined as PIC 9(4) COMP then the compile option TRUNC(BIN) will cause truncation/rollover at 65535, while TRUNC(STD) will exhibit the behavior you're currently seeing.
I know COBOL from nothing, but my concerns would be that the data type used for WS-SEQ-NO might be different with a different implementation of COBOL, and could change size so that an automatic roll-over would no longer work. More importantly, the if statement makes it perfectly clear that this is what you intend and is not merely an accidental side effect.
If it works, it works. However, add comments to your program in working-storage and in the program's loop to say that you are expecting rollover to occur and that is the desired outcome. Us mortals won't know that next year when we are doing maintenance to your program and we will hunt you down.
发布评论
评论(5)
我更喜欢看到“Move 0 to WS-SEQ-NO”。依赖翻转可能无法在所有平台上按预期工作,而且它根本就不那么清晰。
请记住,您为您之后的人们编写源代码。他们应该看着它并清楚地看到“哦,重置计数器”。
I much prefer to see the "Move 0 to WS-SEQ-NO". Relying on rollover might not work as expected on all platforms, and it simply isn't as clear.
Remember, you write the source code for the humans that come after you. They should look at it and clearly see "oh, reset the counter".
我发现
MOVE 0 TO WS-SEQ-NO
方法更清楚地表达您的意图。需要记住的是,可能有一些编译选项会影响您观察到的截断/翻转行为。例如,在 IBM 的 Enterprise COBOL 中,如果定义了 WS-SEQ-NO作为 PIC 9(4) COMP 然后是编译选项 TRUNC(BIN) 将导致在 65535 处截断/翻转,而 TRUNC(STD) 将表现出您当前看到的行为。
I find the
MOVE 0 TO WS-SEQ-NO
method to be clearer as to your intent.Something to keep in mind, there may be compile options that affect the truncation/rollover behavior you observe. For example, in IBM's Enterprise COBOL, if WS-SEQ-NO is defined as PIC 9(4) COMP then the compile option TRUNC(BIN) will cause truncation/rollover at 65535, while TRUNC(STD) will exhibit the behavior you're currently seeing.
我会保留条件并以这种方式定义计数器。
如果您需要将计数器修改为
PIC 9(5)
,您不会忘记修改条件,因为您不必这样做。你只需要修改88级即可。
I would keep the condition and define the counter this way
If you need to modify your counter to
PIC 9(5)
, you won't forget to modify the condition because you won't have to.You'll only need to modify the level 88.
我对 COBOL 一无所知,但我担心的是,用于 WS-SEQ-NO 的数据类型可能与 COBOL 的不同实现不同,并且可能会更改大小,从而使自动翻转不再起作用。更重要的是,if 语句非常清楚地表明这就是您的意图,而不仅仅是偶然的副作用。
I know COBOL from nothing, but my concerns would be that the data type used for WS-SEQ-NO might be different with a different implementation of COBOL, and could change size so that an automatic roll-over would no longer work. More importantly, the if statement makes it perfectly clear that this is what you intend and is not merely an accidental side effect.
如果有效,那就有效。但是,请在工作存储和程序循环中向程序添加注释,以表明您期望发生翻转,这就是期望的结果。我们凡人不会知道,明年当我们对你们的程序进行维护时,我们会追捕你们。
If it works, it works. However, add comments to your program in working-storage and in the program's loop to say that you are expecting rollover to occur and that is the desired outcome. Us mortals won't know that next year when we are doing maintenance to your program and we will hunt you down.