STRING 动词的行为
Behavior of STRING verb
我正在阅读一个 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
将由 ','
分隔,而 WK-DT-FIN-PER-FEU-TEM
将然后是 DELIMITED BY SIZE
.
我读过的哪一本实际上是好书?
这是 STRING 的语法图(来自 Enterprise 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 需要注意的一点是,如果数据比目标短,则目标字段不会得到 space 填充,这对您的情况无关紧要。对于可变长度数据,您需要在 STRING 执行之前将字段清除为 space。
为了理解结果,必须掌握一个细微差别。如果有其他编程语言的经验,DELIMITED BY SIZE 可能会产生误导。
这三个变量中的每一个都有一个在 WORKING-STORAGE 中定义的大小。让我们假设它看起来像这样。
05 WK-NO-EMP-SGE PIC X(04).
05 WK-DT-DEB-PER-FEU-TEM PIC X(10).
05 WK-DT-FIN-PER-FEU-TEM PIC X(10).
如果变量的值是这样设置的:
MOVE 'BOB' TO WK-NO-EMP-SGE.
MOVE 'Q' TO WK-DT-DEB-PER-FEU-TEM.
MOVE 'D19EIEIO2B' TO WK-DT-FIN-PER-FEU-TEM.
然后人们可能期望 UUUUUU-CO-CLE-ERR-DB2 的值为:
BOB,Q,D19EIEIO2B
但实际上是:
BOB ,Q ,D19EIEIO2B
我正在阅读一个 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
将由','
分隔,而WK-DT-FIN-PER-FEU-TEM
将然后是DELIMITED BY SIZE
.
我读过的哪一本实际上是好书?
这是 STRING 的语法图(来自 Enterprise 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 需要注意的一点是,如果数据比目标短,则目标字段不会得到 space 填充,这对您的情况无关紧要。对于可变长度数据,您需要在 STRING 执行之前将字段清除为 space。
为了理解结果,必须掌握一个细微差别。如果有其他编程语言的经验,DELIMITED BY SIZE 可能会产生误导。
这三个变量中的每一个都有一个在 WORKING-STORAGE 中定义的大小。让我们假设它看起来像这样。
05 WK-NO-EMP-SGE PIC X(04).
05 WK-DT-DEB-PER-FEU-TEM PIC X(10).
05 WK-DT-FIN-PER-FEU-TEM PIC X(10).
如果变量的值是这样设置的:
MOVE 'BOB' TO WK-NO-EMP-SGE.
MOVE 'Q' TO WK-DT-DEB-PER-FEU-TEM.
MOVE 'D19EIEIO2B' TO WK-DT-FIN-PER-FEU-TEM.
然后人们可能期望 UUUUUU-CO-CLE-ERR-DB2 的值为:
BOB,Q,D19EIEIO2B
但实际上是:
BOB ,Q ,D19EIEIO2B