cobol

How do you make spaces and dashes in COBOL


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?


Solution

  • 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 ...