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!

Seperating a phone number field

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have a field name in the input that holds phone numbers. Ex. 2176252115. How can I convert this into the out field with dashes? 217-625-2115. Can I use the unstring or is there another approach. Thx to all that respond.
 
use REDEFINES.
EX.
01 VARS.
05 TELNO PIC 9(10).
05 TELNO2 REDEFINES TELNO.
10 TNO1 PIC 9(3).
10 TNO2 PIC 9(3).
10 TNO3 PIC 9(4).

In your detail line :
01 DTL-LN.
05 D-TELNO PIC X(12).
05 D-TELNO2 REDEFINES D-TELNO.
10 D-TNO1 PIC X(3).
10 D-DASH1 PIC X.
10 D-TNO2 PIC X(3).
10 D-DASH2 PIC X.
10 D-TNO3 PIC X(4).

In your procedure :
MOVE TNO1 TO D-TNO1.
MOVE '-' TO D-DASH1.
MOVE TNO2 TO D-TNO2.
MOVE '-' TO D-DASH2.
MOVE TNO3 TO D-TNO3.

So, if you display D-TELNO. Your tel no. will now have a dash.

I hope this will help you.

Jimmy

 
Hi E2,

You could use insertion chars, then INSPECT REPLACING. I know it works w/mainframe COBOL; I'm pretty sure it's supported in other COBOL flavors. Give it a try, for ex:

Define a recving field:

You have a choice of 3 chars: "/ B 0". I'll use "/".

01 OLD-NBR PIC X(10) VALUE '2176252115'.
01 NEW-NBR PIC X(3)/X(3)/X(4).

MOVE OLD-NBR TO NEW-NBR
INSPECT NEW-NBR REPLACING ALL '/' BY '-'

That's all there is to it. It's a shame IBM never bothered to include a dash insertion char. I've run across more situations that required a dash than any of the others, including the /.

Anyway, after the move NEW-NBR contains '217/625/2115'; after the INSPECT it contains '217-625-2115'

HTH, Jack.

 
... and then there's reference modification:

Code:
01  OLD-NBR       PIC  X(10) VALUE '2176252115'.
01  NEW-NBR       PIC  X(13).

STRING OLD-NBR (1 : 3)
       '-'
       OLD-NBR (4 : 3)
       '-'
       OLD-NBR (7 : 4)
       DELIMITED BY SIZE
  INTO NEW-NBR.
--------
Regards,
Ronald.
 
Approaching the solution from my most to least favorite:

Code:
05  OLD-NBR.          
    10  D-TNO1    PIC X(3).
    10  D-TNO2    PIC X(3).
    10  D-TNO3    PIC X(4).

05  NEW-NBR.          
    10  D-TNO1    PIC X(3).
    10  FILLER    PIC X   VALUE ’-’.     
    10  D-TNO2    PIC X(3).
    10  FILLER    PIC X   VALUE ’-’.     
    10  D-TNO3    PIC X(4).

MOVE CORR OLD-NBR  TO  NEW-NBR

The disadvantage of this approach is that all references to OLD-NBR and NEW-NBR fields must be of the form flda OF NEW-NBR or flda OF OLD-NBR. IN may be substituted for OF, if desired.

This technique can help with re-arranging date fields when you may want to add a “/” and at the same time move the year digits from the beginning to the end of the field, or some such.

Jack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top