Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

format SSN

Status
Not open for further replies.

bwall76

Programmer
Feb 17, 2004
16
US
how do you format SSN to 999-999-9999 with hyphens?

PIC 999-999-9999.

Thanks
 
This is very simple text formatting that an absolute beginning COBOL programmer should know.

Code:
01  SSN-PRINT.
    04  SSN-FIRST     PIC 999.
    04                pic x value '-'.

I hope you can fill in the rest.
 
The way I do it:
Code:
  05  PLAIN-SSN     PIC X(09).
  05  FORMATTED-SSN PIC XXXBXXBXX.
  . . .
  MOVE PLAIN-SSN TO FORMATTED-SSN
  MOVE '-'       TO FORMATTED-SSN(4:1)
  MOVE '-'       TO FORMATTED-SSN(7:1)
 
Or you can use the dreaded CORR:
Code:
  05  PLAIN-SSN.    
      10  P1     PIC X(03).
      10  P2     PIC X(02).
      10  P3     PIC X(04).


  05  FORMATTED-SSN.
      10  P1     PIC X(03).
      10  F      PIC X(01) VALUE '-'.
      10  P2     PIC X(02).
      10  F      PIC X(01) VALUE '-'.
      10  P3     PIC X(04).
  . . .
      MOVE CORR PLAIN-SSN TO FORMATTED-SSN
If you're dealing w/lots of data this can save a bit of CPU time. The draw-back is that to reference the Px- fields you have to user qualifiers, e.g. "P1 OF FORMATTED-SSN". That can be cumbersome, but there are ways around it.



Regards, Jack.

"A problem well stated is a problem half solved" -- Charles F. Kettering
 
Similar to webrabbit, but numeric...

Code:
05 SSN PIC 9(9).
05 SSN-EDITED PIC 999B99B9999.

MOVE SSN TO SSN-EDITED
INSPECT SSN-EDITED REPLACING ALL SPACES BY "-".

"Code what you mean,
and mean what you code!
But by all means post your code!"

Razalas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top