×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# String editing

## String editing

(OP)
I found that in Cobol there are alphanumeric strings and numeric strings. I wondered how to make a program where we have an input like "A30" and we want to multiply the number 30 by 11 to get output "A330".
Replies continue below

### RE: String editing

Define it as a group level with an alpha part and a numeric part.

Measurement is not management.

### RE: String editing

How can I code to reformat any one of these telephone # to a 10 byte number:

eg: (614) 123-4567   to 6141234567
614-123-4567    to 6141234567

### RE: String editing

can an "unstring" "STRING" or "Inspect" be used. There is knowing how many spaces will between the "-" or brackets...

### RE: String editing

No trivial solution comes to my mind for this.

It's hard to provide the best solution for your situation without more information, but a fairly general approach is to loop through the input field.  Test each byte for numeric and, if numeric, move it to the output field.  Something like:

#### CODE

01  WS-INPUT        PIC X(??).
01  WS-OUTPUT       PIC 9(10).
.
.
.
MOVE ZEROS          TO WS-OUTPUT
MOVE 1              TO IDX2
PERFORM VARYING IDX FROM 1 BY 1
UNTIL IDX > LENGTH OF (WS-INPUT) OR
IDX2 = 10
IF WS-INPUT(IDX:1) IS NUMERIC
MOVE WS-INPUT(IDX:1) TO WS-OUTPUT(IDX2:1)
END-IF
END-PERFORM
When using this approach, you will have to make sure you the input contains 10 digits (or more) or you have to deal with WS-OUTPUT not containing 10 valid digits on exit.

Regards.

Glenn

### RE: String editing

Here's one.  There's no sanity check on the number of digits but it seems to do the job.

#### CODE

IDENTIFICATION DIVISION.
PROGRAM-ID. FILTER01.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
DATA DIVISION.
WORKING-STORAGE SECTION.
01  PROCESSING-DATA.
04  INPUT-VALUE        PIC X(20).
04  TEMP-VALUE1        PIC X(20).
04  TEMP-VALUE2        PIC X(20).
04  POINTER-VALUE      PIC S9(4) BINARY.
04  OUT-VALUE          PIC X(20).
04  OUT-NUMBER         PIC 9(10).
04  OUT-NUM-TEXT REDEFINES OUT-NUMBER PIC X(10) JUST RIGHT.
04  OUT-BINARY         PIC S9(10) BINARY.
04  EOS-FLAG           PIC X.
04  DUMMY-CHAR         PIC X.
PROCEDURE DIVISION.
0000-MAIN SECTION.
DISPLAY "TESTING FILTER.  TYPE QUIT IN ALL CAPS TO END.".
PERFORM 1000-PROCESS UNTIL INPUT-VALUE = "QUIT".
GOBACK.

1000-PROCESS SECTION.
DISPLAY "ENTER PHONE NUMBER.".
MOVE SPACES TO INPUT-VALUE.
ACCEPT INPUT-VALUE.
INSPECT INPUT-VALUE CONVERTING "(-)"
TO "   ".
MOVE 1 TO POINTER-VALUE.
MOVE SPACES TO OUT-VALUE.
MOVE "N" TO EOS-FLAG.
PERFORM UNTIL POINTER-VALUE > 20
UNSTRING INPUT-VALUE DELIMITED BY ALL SPACES
INTO TEMP-VALUE1
WITH POINTER POINTER-VALUE
END-UNSTRING
MOVE SPACES TO TEMP-VALUE2
STRING OUT-VALUE DELIMITED BY SPACES
TEMP-VALUE1 DELIMITED BY SPACES
INTO TEMP-VALUE2
END-STRING
MOVE TEMP-VALUE2 TO OUT-VALUE
END-PERFORM.
UNSTRING OUT-VALUE DELIMITED BY SPACES
INTO OUT-NUM-TEXT
END-UNSTRING.
MOVE OUT-NUMBER TO OUT-BINARY.
DISPLAY "PHONE NUMBER IS: " OUT-BINARY.

Measurement is not management.

### RE: String editing

Thanks for help.. will try this...

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!