我正在阅读 COBOL 程序文件,并且正在努力理解 STRING
命令在以下示例中的工作方式
STRING WK-NO-EMP-SGE
','
WK-DT-DEB-PER-FEU-TEM
','
WK-DT-FIN-PER-FEU-TEM
DELIMITED BY SIZE
INTO UUUUUU-CO-CLE-ERR-DB2
我对其作用有三种可能的理解:
- 代码将每个变量连接成
UUUUUU-CO-CLE-ERR-DB2
并用','
分隔每个值,最后一个变量按大小分隔; - 代码将每个变量连接成
UUUUUU-CO-CLE-ERR-DB2
并用','
分隔每个值,但所有值均按大小分隔(这意味着在这种情况下DELIMITED BY SIZE
适用于字符串命令中传递的所有值; - 或者每个变量由特定字符分隔,例如
WK-NO-EMP-SGE
将由','
、WK-DT 分隔-DEB-PER-FEU-TEM
by','
和WK-DT-FIN-PER-FEU-TEM
将被DELIMITED BY尺寸
。
我读的哪一本实际上是好的?
最佳答案
以下是 STRING 的语法图(来自企业 COBOL 语言引用):
现在您需要知道如何阅读它。
幸运的是,同一份文档告诉您如何:
How to read the syntax diagrams
Use the following description to read the syntax diagrams in this document:
. Read the syntax diagrams from left to right, from top to bottom, following the path of the line.
The >>--- symbol indicates the beginning of a syntax diagram.
The ---> symbol indicates that the syntax diagram is continued on the next line.
The >--- symbol indicates that the syntax diagram is continued from the previous line.
The --->< symbol indicates the end of a syntax diagram. Diagrams of syntactical units other than complete statements start with the >--- symbol and end with the ---> symbol.
. Required items appear on the horizontal line (the main path).
. Optional items appear below the main path.
. When you can choose from two or more items, they appear vertically, in a stack.
If you must choose one of the items, one item of the stack appears on the main path.
If choosing one of the items is optional, the entire stack appears below the main path.
. An arrow returning to the left above the main line indicates an item that can be repeated.
A repeat arrow above a stack indicates that you can make more than one choice from the stacked items, or repeat a single choice.
. Variables appear in italic lowercase letters (for example, parmx). They represent user-supplied names or values.
. If punctuation marks, parentheses, arithmetic operators, or other such symbols are shown, they must be entered as part of the syntax.
所有这一切都意味着,如果您坚持到底,您的数字 2 是正确的。
您可以使用分隔符(当您没有固定长度数据时)或仅使用大小。任何未明确分隔方式的项目均由下一个 DELIMITED BY
语句分隔。
使用 STRING 时需要注意的一件事(在您的情况下并不重要)是,如果数据短于目标,则目标字段不会被空格填充。对于可变长度数据,您需要在 STRING 执行之前将字段清除为空格。
关于cobol - STRING 动词的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30620709/