English 中文(简体)
COBOL公司
原标题:SUBSTRING for a String Literal in COBOL
  • 时间:2011-11-21 06:35:23
  •  标签:
  • cobol

在不使用临时变量的情况下,在COBOL中添加字面的分辨率是否有什么变化?

在以下法典中要说:

MOVE "HELLO" TO MY-VAR.
MOVE MY-VAR(1:3) TO SUB-STR.

Is there any way to do the same thing, but without MY-VAR?

EDIT: I did tried following code, but it s failed.

MOVE "HELLO"(1:3) TO SUB-STR   * COMPILE ERROR
最佳回答

You can accomplish what you are trying to do by type-laundering the literal through a function. You can then substring, or reference modify, the output of the function. Consider that calling reverse twice on the same data returns the original data.

Move function reverse                           
 ( function reverse( 
       abcdefg  
   )
 ) (3:1) to text-out

以上将产生一个排在案文的正文。

问题回答

Of course, the example code in your question does not make any sense, as why would you write "HELLO"(1:3) when you could just write "HEL".

因此,你必须想在参考变数领域使用变量(或2)。

如果你想要获得字面上的第一个N级特性,你可以通过在destination 项目上使用参考词典来这样做。 例如,如果您汇编并管理以下方案:

   IDENTIFICATION DIVISION.
   PROGRAM-ID. HELLO.
   DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 LEN          PIC 99 VALUE 8.
   01 SUB-STR      PIC X(80).
   PROCEDURE DIVISION.
       MOVE "HELLO WORLD" TO SUB-STR(1:LEN).
       DISPLAY SUB-STR.
       STOP RUN.

取得结果:

HELLO WO

不幸的是,这种方法只有在你想要字面描述的第一个N特性时才会奏效。

此外,在你开始之前,扼杀目的地必须是空洞的。 在上述方案中,如果您修改了<代码>SUB-Chap>/code>的定义:

01 SUB-STR      PIC X(80) VALUE "BLAH BLAH BLAH".

其后,方案的实施结果如下:

HELLO WOH BLAH

把“推进剂”变成一个不变的领域。

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 LITERAL-HELLO PIC X(5) VALUE  HELLO .
PROCEDURE DIVISION.
    DISPLAY LITERAL-HELLO(1:3).
    STOP RUN.




相关问题
architectures of COBOL and Java

Can anyone tell me the differnces in styles and architectures between these very differenct approaches please?

How to decrypt a string in cobol

i m looking for ways to decrypt a string in cobol that was encrypted in .net using RijndaelManaged. I have control of the algorithm so it doesn t need to be Rijdnael, but i just need to ensure that ...

How can duplicates be removed from a file using COBOL?

The input file have records as: 8712351,8712353,8712353,8712354,8712356,8712352,8712355 8712352,8712355 Using COBOL, I need to remove duplicates from the above file and write to an output file. I ...

热门标签