cobol - STRING 动词的行为

标签 cobol mainframe

我正在阅读 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                   

我对其作用有三种可能的理解:

  1. 代码将每个变量连接成 UUUUUU-CO-CLE-ERR-DB2 并用 ',' 分隔每个值,最后一个变量按大小分隔;
  2. 代码将每个变量连接成 UUUUUU-CO-CLE-ERR-DB2 并用 ',' 分隔每个值,但所有值均按大小分隔(这意味着在这种情况下DELIMITED BY SIZE适用于字符串命令中传递的所有值;
  3. 或者每个变量由特定字符分隔,例如 WK-NO-EMP-SGE 将由 ','WK-DT 分隔-DEB-PER-FEU-TEM by ','WK-DT-FIN-PER-FEU-TEM 将被 DELIMITED BY尺寸

我读的哪一本实际上是好的?

最佳答案

以下是 STRING 的语法图(来自企业 COBOL 语言引用):

Syntax Diagram

现在您需要知道如何阅读它。

幸运的是,同一份文档告诉您如何:

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/

相关文章:

cobol - COBOL中识别程序调用子模块

mainframe - 使用 IEBCOPY 将成员复制到带有通配符的数据集

sql-server - 有没有办法从 z/OS 大型机访问 Sql 服务器并在 IBM 3270 终端仿真中得到结果?

db2 - 大型机 - 更改的文件名的扩展名后缀的名称是什么?

programming-languages - 适用于 Windows 的 Cobol 模拟器

compiler-errors - “Not a uniquely defined name”什么时候只有一个定义?

java - 使用 JRecord 读取大型机 comp-3 字段

java - 如何在 Java String 中存储 EBCDIC (IBM-1047) 编码文本而不破坏它?

用于 cobol 显示和解压缩数字字段的 Java 映射

syntax-highlighting - COBOL 源列的不同背景颜色