如何在 COBOL 中创建空格和破折号

发布于 2024-10-05 16:46:17 字数 125 浏览 7 评论 0原文

我的 COBOL 作业遇到了一些麻烦。我必须编写一个程序来写出人们的姓名及其社会安全号码。基本上我有玩具让像 123456789 这样的数字显示为 123-45-6789,像 JSDOE 这样的名称显示为 JS DOE。有人可以帮我吗?

I am having a bit of trouble with my COBOL homework. I have to make a program that writes out the names of people and their social security numbers. Basically I have toy make a number like 123456789 show up like 123-45-6789 and a name like JSDOE show up like J S DOE. Can someone help me out?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

↘人皮目录ツ 2024-10-12 16:46:17

你应该做类似的事情。

01 toyNumber pic 9(9).

01 yourNumber.
   03 a pic x(3).
   03 b pic x(2).
   03 c pic x(4).

01 outNumber.
   03 a1     pic x(3).
   03 filler pic x    value "-".
   03 b1     pic x(2).
   03 filler pic x    value "-".
   03 c1     pic x(4).      

并在程序中:

   move 123456789 to toyNumber.
   ....
   move toyNumber to yourNumber.
   move a to a1.
   move b to b1.
   move c to c1.

   display outNumber.  

或者,如果您的作业允许,您可以使用“相应移动”。

希望这有帮助!

PS:名字的技巧是一样的......

You should do something like.

01 toyNumber pic 9(9).

01 yourNumber.
   03 a pic x(3).
   03 b pic x(2).
   03 c pic x(4).

01 outNumber.
   03 a1     pic x(3).
   03 filler pic x    value "-".
   03 b1     pic x(2).
   03 filler pic x    value "-".
   03 c1     pic x(4).      

and in the procedure:

   move 123456789 to toyNumber.
   ....
   move toyNumber to yourNumber.
   move a to a1.
   move b to b1.
   move c to c1.

   display outNumber.  

Or you may use "move corresponding" if you are allowed in your homework.

Hope this help!

PS: The trick for the name is the same ...

猫九 2024-10-12 16:46:17

科博尔!!

我是在很久之后才写这篇文章的。因此,请谨慎行事。像这样的事情可能会起作用:


01 SSN.
    03 SSN-FIRST         PIC X(03) VALUE SPACES.
    03 SSN-FDASH         PIC X     VALUE "-".
    03 SSN-MIDDLE        PIC X(02)   VALUE SPACES.
    03 SSN-MDASH         PIC X       VALUE "-".
    03 SSN-LAST          PIC X(04)   VALUE SPACES.

01 NAME.
    03 FNAME         PIC X(10)   VALUE SPACES.
    03 FDASH         PIC X     VALUE SPACES.
    03 FMIDDLE      PIC X(10)   VALUE SPACES.
    03 MDASH         PIC X     VALUE SPACES.
    03 FLAST      PIC X(10)   VALUE SPACES.


COBOL!!

I am writing this after a long time. So, apply caution. Something like this may work:


01 SSN.
    03 SSN-FIRST         PIC X(03) VALUE SPACES.
    03 SSN-FDASH         PIC X     VALUE "-".
    03 SSN-MIDDLE        PIC X(02)   VALUE SPACES.
    03 SSN-MDASH         PIC X       VALUE "-".
    03 SSN-LAST          PIC X(04)   VALUE SPACES.

01 NAME.
    03 FNAME         PIC X(10)   VALUE SPACES.
    03 FDASH         PIC X     VALUE SPACES.
    03 FMIDDLE      PIC X(10)   VALUE SPACES.
    03 MDASH         PIC X     VALUE SPACES.
    03 FLAST      PIC X(10)   VALUE SPACES.


小鸟爱天空丶 2024-10-12 16:46:17

更现代(不那么古老?)的方法:-

STRING SSNUMBER(1:3) DELIMITED BY SIZE
       '-'           DELIMITED BY SIZE
       SSNUMBER(4:5) DELIMITED BY SIZE
       '-'           DELIMITED BY SIZE
       SSNUMBER(6:9) DELIMITED BY SIZE
 INTO PRINTFIELD.

A more modern (less ancient?) approach :-

STRING SSNUMBER(1:3) DELIMITED BY SIZE
       '-'           DELIMITED BY SIZE
       SSNUMBER(4:5) DELIMITED BY SIZE
       '-'           DELIMITED BY SIZE
       SSNUMBER(6:9) DELIMITED BY SIZE
 INTO PRINTFIELD.
猫九 2024-10-12 16:46:17

接收数据项的PICTURE 中的B 将在MOVE 期间插入一个空格。对于名称,只需 MOVE 即可。对于数字,空格可以用连字符代替。

       data division.
       working-storage section.
       1 num-in pic 9(9) value 123456789.
       1 num-out pic 999B99B9999.
       1 name-in pic x(5) value "JSDOE".
       1 name-out pic XBXBXXX.
       procedure division.
           move num-in to num-out
           inspect num-out replacing all space by "-"
           move name-in to name-out
           display num-out
           display name-out
           stop run
           .

输出:

123-45-6789
J S DOE

A B in the PICTURE of the receiving data-item will insert a space during a MOVE. For the name, a MOVE is all that is required. For the number, the spaces may be replaced with hyphens.

       data division.
       working-storage section.
       1 num-in pic 9(9) value 123456789.
       1 num-out pic 999B99B9999.
       1 name-in pic x(5) value "JSDOE".
       1 name-out pic XBXBXXX.
       procedure division.
           move num-in to num-out
           inspect num-out replacing all space by "-"
           move name-in to name-out
           display num-out
           display name-out
           stop run
           .

Output:

123-45-6789
J S DOE
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文